@@ -112,59 +112,56 @@ Function: coverage_goalst::get_coverage
112
112
113
113
\*******************************************************************/
114
114
115
- coverage_goalst coverage_goalst::get_coverage_goals (const std::string &coverage,
116
- message_handlert &message_handler)
115
+ bool coverage_goalst::get_coverage_goals (
116
+ const std::string &coverage_file,
117
+ message_handlert &message_handler,
118
+ coverage_goalst &goals)
117
119
{
118
120
jsont json;
119
- coverage_goalst goals;
120
121
source_locationt source_location;
121
122
122
123
// check coverage file
123
- if (parse_json (coverage , message_handler, json))
124
+ if (parse_json (coverage_file , message_handler, json))
124
125
{
125
126
messaget message (message_handler);
126
- message.error () << coverage << " file is not a valid json file"
127
+ message.error () << coverage_file << " file is not a valid json file"
127
128
<< messaget::eom;
128
- exit ( 6 ) ;
129
+ return true ;
129
130
}
130
131
131
132
// make sure that we have an array of elements
132
133
if (!json.is_array ())
133
134
{
134
135
messaget message (message_handler);
135
- message.error () << " expecting an array in the " << coverage
136
+ message.error () << " expecting an array in the " << coverage_file
136
137
<< " file, but got "
137
138
<< json << messaget::eom;
138
- exit ( 6 ) ;
139
+ return true ;
139
140
}
140
141
141
- irep_idt file, function, line;
142
- for (jsont::arrayt::const_iterator
143
- it=json.array .begin ();
144
- it!=json.array .end ();
145
- it++)
142
+ for (const auto &goal : json.array )
146
143
{
147
144
// get the file of each existing goal
148
- file=(*it) [" file" ].value ;
145
+ irep_idt file=goal [" file" ].value ;
149
146
source_location.set_file (file);
150
147
151
148
// get the function of each existing goal
152
- function=(*it) [" function" ].value ;
149
+ irep_idt function=goal [" function" ].value ;
153
150
source_location.set_function (function);
154
151
155
152
// get the lines array
156
- if ((*it) [" lines" ].is_array ())
153
+ if (goal [" lines" ].is_array ())
157
154
{
158
- for (const jsont & entry : (*it) [" lines" ].array )
155
+ for (const auto &line_json : goal [" lines" ].array )
159
156
{
160
157
// get the line of each existing goal
161
- line=entry [" number" ].value ;
158
+ irep_idt line=line_json [" number" ].value ;
162
159
source_location.set_line (line);
163
160
goals.add_goal (source_location);
164
161
}
165
162
}
166
163
}
167
- return goals ;
164
+ return false ;
168
165
}
169
166
170
167
/* ******************************************************************\
@@ -198,19 +195,14 @@ Function: coverage_goalst::is_existing_goal
198
195
199
196
bool coverage_goalst::is_existing_goal (source_locationt source_location) const
200
197
{
201
- std::vector<source_locationt>::const_iterator it = existing_goals.begin ();
202
- while (it!=existing_goals.end ())
198
+ for (const auto &existing_loc : existing_goals)
203
199
{
204
- if (!source_location.get_file ().compare (it->get_file ()) &&
205
- !source_location.get_function ().compare (it->get_function ()) &&
206
- !source_location.get_line ().compare (it->get_line ()))
207
- break ;
208
- ++it;
200
+ if (source_location.get_file ()==existing_loc.get_file () &&
201
+ source_location.get_function ()==existing_loc.get_function () &&
202
+ source_location.get_line ()==existing_loc.get_line ())
203
+ return true ;
209
204
}
210
- if (it == existing_goals.end ())
211
- return true ;
212
- else
213
- return false ;
205
+ return false ;
214
206
}
215
207
216
208
/* ******************************************************************\
@@ -1228,46 +1220,51 @@ void instrument_cover_goals(
1228
1220
coverage_criteriont criterion,
1229
1221
bool function_only)
1230
1222
{
1231
- coverage_goalst goals; // empty already covered goals
1232
- instrument_cover_goals (symbol_table,goto_program,
1233
- criterion,goals,function_only,false );
1223
+ coverage_goalst goals; // empty already covered goals
1224
+ instrument_cover_goals (
1225
+ symbol_table,
1226
+ goto_program,
1227
+ criterion,
1228
+ goals,
1229
+ function_only,
1230
+ false );
1234
1231
}
1235
1232
1236
1233
/* ******************************************************************\
1237
1234
1238
- Function: consider_goals
1235
+ Function: program_is_trivial
1239
1236
1240
- Inputs:
1237
+ Inputs: Program `goto_program`
1241
1238
1242
- Outputs:
1239
+ Outputs: Returns true if trivial
1243
1240
1244
- Purpose:
1241
+ Purpose: Call a goto_program trivial unless it has:
1242
+ * Any declarations
1243
+ * At least 2 branches
1244
+ * At least 5 assignments
1245
1245
1246
1246
\*******************************************************************/
1247
1247
1248
- bool consider_goals (const goto_programt &goto_program)
1248
+ bool program_is_trivial (const goto_programt &goto_program)
1249
1249
{
1250
- bool result;
1251
- unsigned long count_assignments=0 , count_goto=0 , count_decl=0 ;
1252
-
1250
+ unsigned long count_assignments=0 , count_goto=0 ;
1253
1251
forall_goto_program_instructions (i_it, goto_program)
1254
1252
{
1255
1253
if (i_it->is_goto ())
1256
- ++count_goto;
1257
- else if (i_it->is_assign ())
1258
- ++count_assignments;
1259
- else if (i_it->is_decl ())
1260
- ++count_decl;
1254
+ {
1255
+ if ((++count_goto)>=2 )
1256
+ return false ;
1257
+ }
1258
+ else if (i_it->is_assign ())
1259
+ {
1260
+ if ((++count_assignments)>=5 )
1261
+ return false ;
1262
+ }
1263
+ else if (i_it->is_decl ())
1264
+ return false ;
1261
1265
}
1262
1266
1263
- // check whether this is a constructor/destructor or a get/set (pattern)
1264
- if (!count_goto && !count_assignments && !count_decl)
1265
- result=false ;
1266
- else
1267
- result = !((count_decl==0 ) && (count_goto<=1 ) &&
1268
- (count_assignments>0 && count_assignments<5 ));
1269
-
1270
- return result;
1267
+ return true ;
1271
1268
}
1272
1269
1273
1270
/* ******************************************************************\
@@ -1290,8 +1287,8 @@ void instrument_cover_goals(
1290
1287
bool function_only,
1291
1288
bool ignore_trivial)
1292
1289
{
1293
- // exclude trivial coverage goals of a goto program
1294
- if (ignore_trivial && ! consider_goals (goto_program))
1290
+ // exclude trivial coverage goals of a goto program
1291
+ if (ignore_trivial && program_is_trivial (goto_program))
1295
1292
return ;
1296
1293
1297
1294
const namespacet ns (symbol_table);
@@ -1369,12 +1366,13 @@ void instrument_cover_goals(
1369
1366
basic_blocks.source_location_map [block_nr];
1370
1367
1371
1368
// check whether the current goal already exists
1372
- if (goals.is_existing_goal (source_location) &&
1369
+ if (! goals.is_existing_goal (source_location) &&
1373
1370
!source_location.get_file ().empty () &&
1374
1371
source_location.get_file ()[0 ]!=' <' &&
1375
1372
cover_curr_function)
1376
1373
{
1377
- std::string comment=" function " +id2string (i_it->function )+" block " +b;
1374
+ std::string comment=
1375
+ " function " +id2string (i_it->function )+" block " +b;
1378
1376
const irep_idt function=i_it->function ;
1379
1377
goto_program.insert_before_swap (i_it);
1380
1378
i_it->make_assertion (false_exprt ());
@@ -1647,7 +1645,7 @@ void instrument_cover_goals(
1647
1645
Forall_goto_functions (f_it, goto_functions)
1648
1646
{
1649
1647
if (f_it->first ==ID__start ||
1650
- f_it->first ==CPROVER_PREFIX " initialize" )
1648
+ f_it->first ==( CPROVER_PREFIX " initialize" ) )
1651
1649
continue ;
1652
1650
1653
1651
instrument_cover_goals (
@@ -1678,7 +1676,7 @@ void instrument_cover_goals(
1678
1676
coverage_criteriont criterion,
1679
1677
bool function_only)
1680
1678
{
1681
- // empty set of existing goals
1679
+ // empty set of existing goals
1682
1680
coverage_goalst goals;
1683
1681
instrument_cover_goals (
1684
1682
symbol_table,
0 commit comments