@@ -15,6 +15,20 @@ 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 (
19
+ const goto_programt::const_targett &instruction,
20
+ cover_basic_blockst::block_mapt &block_map)
21
+ {
22
+ if (instruction->incoming_edges .size () != 1 )
23
+ return {};
24
+
25
+ const goto_programt::targett in_t = *instruction->incoming_edges .cbegin ();
26
+ if (in_t ->is_goto () && !in_t ->is_backwards_goto () && in_t ->guard .is_true ())
27
+ return block_map[in_t ];
28
+
29
+ return {};
30
+ }
31
+
18
32
cover_basic_blockst::cover_basic_blockst (const goto_programt &_goto_program)
19
33
{
20
34
bool next_is_target = true ;
@@ -25,25 +39,13 @@ cover_basic_blockst::cover_basic_blockst(const goto_programt &_goto_program)
25
39
// Is it a potential beginning of a block?
26
40
if (next_is_target || it->is_target ())
27
41
{
28
- // We keep the block number if this potential block
29
- // is a continuation of a previous block through
30
- // unconditional forward gotos; otherwise we increase the
31
- // block number.
32
- bool increase_block_nr = true ;
33
- if (it->incoming_edges .size () == 1 )
42
+ if (auto block_number = continuation_of_block (it, block_map))
34
43
{
35
- goto_programt::targett in_t = *it->incoming_edges .begin ();
36
- if (
37
- in_t ->is_goto () && !in_t ->is_backwards_goto () &&
38
- in_t ->guard .is_true ())
39
- {
40
- current_block = block_map[in_t ];
41
- increase_block_nr = false ;
42
- }
44
+ current_block = *block_number;
43
45
}
44
- if (increase_block_nr)
46
+ else
45
47
{
46
- block_infos.push_back ( block_infot () );
48
+ block_infos.emplace_back ( );
47
49
block_infos.back ().representative_inst = it;
48
50
block_infos.back ().source_location = source_locationt::nil ();
49
51
current_block = block_infos.size () - 1 ;
@@ -87,12 +89,12 @@ cover_basic_blockst::cover_basic_blockst(const goto_programt &_goto_program)
87
89
88
90
unsigned cover_basic_blockst::block_of (goto_programt::const_targett t) const
89
91
{
90
- block_mapt::const_iterator it = block_map.find (t);
92
+ const auto it = block_map.find (t);
91
93
INVARIANT (it != block_map.end (), " instruction must be part of a block" );
92
94
return it->second ;
93
95
}
94
96
95
- goto_programt::const_targett
97
+ optionalt< goto_programt::const_targett>
96
98
cover_basic_blockst::instruction_of (unsigned block_nr) const
97
99
{
98
100
INVARIANT (block_nr < block_infos.size (), " block number out of range" );
@@ -116,13 +118,13 @@ void cover_basic_blockst::select_unique_java_bytecode_indices(
116
118
117
119
forall_goto_program_instructions (it, goto_program)
118
120
{
119
- unsigned block_nr = block_of (it);
121
+ const unsigned block_nr = block_of (it);
120
122
if (blocks_seen.find (block_nr) != blocks_seen.end ())
121
123
continue ;
122
124
123
125
INVARIANT (block_nr < block_infos.size (), " block number out of range" );
124
126
block_infot &block_info = block_infos.at (block_nr);
125
- if (block_info.representative_inst == goto_program. instructions . end () )
127
+ if (! block_info.representative_inst )
126
128
{
127
129
if (!it->source_location .get_java_bytecode_index ().empty ())
128
130
{
@@ -144,7 +146,7 @@ void cover_basic_blockst::select_unique_java_bytecode_indices(
144
146
}
145
147
}
146
148
}
147
- else if (it == block_info.representative_inst )
149
+ else if (it == * block_info.representative_inst )
148
150
{
149
151
// check the existing representative
150
152
if (!it->source_location .get_java_bytecode_index ().empty ())
@@ -159,7 +161,7 @@ void cover_basic_blockst::select_unique_java_bytecode_indices(
159
161
else
160
162
{
161
163
// clash, reset to search for a new one
162
- block_info.representative_inst = goto_program. instructions . end () ;
164
+ block_info.representative_inst = {} ;
163
165
block_info.source_location = source_locationt::nil ();
164
166
msg.debug () << it->function << " block " << (block_nr + 1 )
165
167
<< " , location " << it->location_number
@@ -182,7 +184,7 @@ void cover_basic_blockst::report_block_anomalies(
182
184
std::set<unsigned > blocks_seen;
183
185
forall_goto_program_instructions (it, goto_program)
184
186
{
185
- unsigned block_nr = block_of (it);
187
+ const unsigned block_nr = block_of (it);
186
188
const block_infot &block_info = block_infos.at (block_nr);
187
189
188
190
if (
@@ -223,7 +225,6 @@ void cover_basic_blockst::update_covered_lines(block_infot &block_info)
223
225
INVARIANT (!cover_set.empty (), " covered lines set must not be empty" );
224
226
std::vector<unsigned > line_list (cover_set.begin (), cover_set.end ());
225
227
226
- format_number_ranget format_lines;
227
- std::string covered_lines = format_lines (line_list);
228
+ std::string covered_lines = format_number_range (line_list);
228
229
block_info.source_location .set_basic_block_covered_lines (covered_lines);
229
230
}
0 commit comments