@@ -15,7 +15,7 @@ Author: Peter Schrammel
15
15
#include < util/message.h>
16
16
#include < util/string2int.h>
17
17
18
- optionalt<unsigned > cover_basic_blockst::continuation_of_block (
18
+ optionalt<std:: size_t > cover_basic_blockst::continuation_of_block (
19
19
const goto_programt::const_targett &instruction,
20
20
cover_basic_blockst::block_mapt &block_map)
21
21
{
@@ -32,7 +32,7 @@ optionalt<unsigned> cover_basic_blockst::continuation_of_block(
32
32
cover_basic_blockst::cover_basic_blockst (const goto_programt &_goto_program)
33
33
{
34
34
bool next_is_target = true ;
35
- unsigned current_block = 0 ;
35
+ std:: size_t current_block = 0 ;
36
36
37
37
forall_goto_program_instructions (it, _goto_program)
38
38
{
@@ -87,104 +87,36 @@ cover_basic_blockst::cover_basic_blockst(const goto_programt &_goto_program)
87
87
update_covered_lines (block_info);
88
88
}
89
89
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
91
91
{
92
92
const auto it = block_map.find (t);
93
93
INVARIANT (it != block_map.end (), " instruction must be part of a block" );
94
94
return it->second ;
95
95
}
96
96
97
97
optionalt<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
99
99
{
100
100
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 ;
102
102
}
103
103
104
104
const 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
106
106
{
107
107
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 ;
177
109
}
178
110
179
111
void cover_basic_blockst::report_block_anomalies (
180
112
const goto_programt &goto_program,
181
113
message_handlert &message_handler)
182
114
{
183
115
messaget msg (message_handler);
184
- std::set<unsigned > blocks_seen;
116
+ std::set<std:: size_t > blocks_seen;
185
117
forall_goto_program_instructions (it, goto_program)
186
118
{
187
- const unsigned block_nr = block_of (it);
119
+ const std:: size_t block_nr = block_of (it);
188
120
const block_infot &block_info = block_infos.at (block_nr);
189
121
190
122
if (
@@ -228,3 +160,48 @@ void cover_basic_blockst::update_covered_lines(block_infot &block_info)
228
160
std::string covered_lines = format_number_range (line_list);
229
161
block_info.source_location .set_basic_block_covered_lines (covered_lines);
230
162
}
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