@@ -15,7 +15,7 @@ Author: Peter Schrammel
1515#include < util/message.h>
1616#include < util/string2int.h>
1717
18- optionalt<unsigned > cover_basic_blockst::continuation_of_block (
18+ optionalt<std:: size_t > cover_basic_blockst::continuation_of_block (
1919 const goto_programt::const_targett &instruction,
2020 cover_basic_blockst::block_mapt &block_map)
2121{
@@ -32,7 +32,7 @@ optionalt<unsigned> cover_basic_blockst::continuation_of_block(
3232cover_basic_blockst::cover_basic_blockst (const goto_programt &_goto_program)
3333{
3434 bool next_is_target = true ;
35- unsigned current_block = 0 ;
35+ std:: size_t current_block = 0 ;
3636
3737 forall_goto_program_instructions (it, _goto_program)
3838 {
@@ -87,104 +87,36 @@ cover_basic_blockst::cover_basic_blockst(const goto_programt &_goto_program)
8787 update_covered_lines (block_info);
8888}
8989
90- unsigned cover_basic_blockst::block_of (goto_programt::const_targett t) const
90+ std:: size_t cover_basic_blockst::block_of (goto_programt::const_targett t) const
9191{
9292 const auto it = block_map.find (t);
9393 INVARIANT (it != block_map.end (), " instruction must be part of a block" );
9494 return it->second ;
9595}
9696
9797optionalt<goto_programt::const_targett>
98- cover_basic_blockst::instruction_of (unsigned block_nr) const
98+ cover_basic_blockst::instruction_of (const std:: size_t block_nr) const
9999{
100100 INVARIANT (block_nr < block_infos.size (), " block number out of range" );
101- return block_infos. at ( block_nr) .representative_inst ;
101+ return block_infos[ block_nr] .representative_inst ;
102102}
103103
104104const source_locationt &
105- cover_basic_blockst::source_location_of (unsigned block_nr) const
105+ cover_basic_blockst::source_location_of (const std:: size_t block_nr) const
106106{
107107 INVARIANT (block_nr < block_infos.size (), " block number out of range" );
108- return block_infos.at (block_nr).source_location ;
109- }
110-
111- void cover_basic_blockst::select_unique_java_bytecode_indices (
112- const goto_programt &goto_program,
113- message_handlert &message_handler)
114- {
115- messaget msg (message_handler);
116- std::set<unsigned > blocks_seen;
117- std::set<irep_idt> bytecode_indices_seen;
118-
119- forall_goto_program_instructions (it, goto_program)
120- {
121- const unsigned block_nr = block_of (it);
122- if (blocks_seen.find (block_nr) != blocks_seen.end ())
123- continue ;
124-
125- INVARIANT (block_nr < block_infos.size (), " block number out of range" );
126- block_infot &block_info = block_infos.at (block_nr);
127- if (!block_info.representative_inst )
128- {
129- if (!it->source_location .get_java_bytecode_index ().empty ())
130- {
131- // search for a representative
132- if (
133- bytecode_indices_seen
134- .insert (it->source_location .get_java_bytecode_index ())
135- .second )
136- {
137- block_info.representative_inst = it;
138- block_info.source_location = it->source_location ;
139- update_covered_lines (block_info);
140- blocks_seen.insert (block_nr);
141- msg.debug () << it->function << " block " << (block_nr + 1 )
142- << " : location " << it->location_number
143- << " , bytecode-index "
144- << it->source_location .get_java_bytecode_index ()
145- << " selected for instrumentation." << messaget::eom;
146- }
147- }
148- }
149- else if (it == *block_info.representative_inst )
150- {
151- // check the existing representative
152- if (!it->source_location .get_java_bytecode_index ().empty ())
153- {
154- if (
155- bytecode_indices_seen
156- .insert (it->source_location .get_java_bytecode_index ())
157- .second )
158- {
159- blocks_seen.insert (block_nr);
160- }
161- else
162- {
163- // clash, reset to search for a new one
164- block_info.representative_inst = {};
165- block_info.source_location = source_locationt::nil ();
166- msg.debug () << it->function << " block " << (block_nr + 1 )
167- << " , location " << it->location_number
168- << " : bytecode-index "
169- << it->source_location .get_java_bytecode_index ()
170- << " already instrumented."
171- << " Searching for alternative instruction"
172- << " to instrument." << messaget::eom;
173- }
174- }
175- }
176- }
108+ return block_infos[block_nr].source_location ;
177109}
178110
179111void cover_basic_blockst::report_block_anomalies (
180112 const goto_programt &goto_program,
181113 message_handlert &message_handler)
182114{
183115 messaget msg (message_handler);
184- std::set<unsigned > blocks_seen;
116+ std::set<std:: size_t > blocks_seen;
185117 forall_goto_program_instructions (it, goto_program)
186118 {
187- const unsigned block_nr = block_of (it);
119+ const std:: size_t block_nr = block_of (it);
188120 const block_infot &block_info = block_infos.at (block_nr);
189121
190122 if (
@@ -228,3 +160,48 @@ void cover_basic_blockst::update_covered_lines(block_infot &block_info)
228160 std::string covered_lines = format_number_range (line_list);
229161 block_info.source_location .set_basic_block_covered_lines (covered_lines);
230162}
163+
164+ cover_basic_blocks_javat::cover_basic_blocks_javat (
165+ const goto_programt &_goto_program)
166+ {
167+ forall_goto_program_instructions (it, _goto_program)
168+ {
169+ const auto &location = it->source_location ;
170+ const auto &bytecode_index = location.get_java_bytecode_index ();
171+ if (index_to_block.emplace (bytecode_index, block_infos.size ()).second )
172+ {
173+ block_infos.push_back (it);
174+ block_locations.push_back (location);
175+ block_locations.back ().set_basic_block_covered_lines (location.get_line ());
176+ }
177+ }
178+ }
179+
180+ std::size_t
181+ cover_basic_blocks_javat::block_of (goto_programt::const_targett t) const
182+ {
183+ const auto &bytecode_index = t->source_location .get_java_bytecode_index ();
184+ const auto it = index_to_block.find (bytecode_index);
185+ INVARIANT (it != index_to_block.end (), " instruction must be part of a block" );
186+ return it->second ;
187+ }
188+
189+ optionalt<goto_programt::const_targett>
190+ cover_basic_blocks_javat::instruction_of (const std::size_t block_nr) const
191+ {
192+ PRECONDITION (block_nr < block_infos.size ());
193+ return block_infos[block_nr];
194+ }
195+
196+ const source_locationt &
197+ cover_basic_blocks_javat::source_location_of (const std::size_t block_nr) const
198+ {
199+ PRECONDITION (block_nr < block_locations.size ());
200+ return block_locations[block_nr];
201+ }
202+
203+ void cover_basic_blocks_javat::output (std::ostream &out) const
204+ {
205+ for (std::size_t i = 0 ; i < block_locations.size (); ++i)
206+ out << block_locations[i] << " -> " << i << ' \n ' ;
207+ }
0 commit comments