@@ -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
/* ******************************************************************\
@@ -199,18 +196,14 @@ Function: coverage_goalst::is_existing_goal
199
196
bool coverage_goalst::is_existing_goal (source_locationt source_location) const
200
197
{
201
198
std::vector<source_locationt>::const_iterator it = existing_goals.begin ();
202
- while (it!= existing_goals. end () )
199
+ for ( const auto &existing_loc : existing_goals)
203
200
{
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;
201
+ if (source_location.get_file ()==existing_loc.get_file () &&
202
+ source_location.get_function ()==existing_loc.get_function () &&
203
+ source_location.get_line ()==existing_loc.get_line ())
204
+ return true ;
209
205
}
210
- if (it == existing_goals.end ())
211
- return true ;
212
- else
213
- return false ;
206
+ return false ;
214
207
}
215
208
216
209
/* ******************************************************************\
@@ -1228,46 +1221,51 @@ void instrument_cover_goals(
1228
1221
coverage_criteriont criterion,
1229
1222
bool function_only)
1230
1223
{
1231
- coverage_goalst goals; // empty already covered goals
1232
- instrument_cover_goals (symbol_table,goto_program,
1233
- criterion,goals,function_only,false );
1224
+ coverage_goalst goals; // empty already covered goals
1225
+ instrument_cover_goals (
1226
+ symbol_table,
1227
+ goto_program,
1228
+ criterion,
1229
+ goals,
1230
+ function_only,
1231
+ false );
1234
1232
}
1235
1233
1236
1234
/* ******************************************************************\
1237
1235
1238
- Function: consider_goals
1236
+ Function: program_is_trivial
1239
1237
1240
- Inputs:
1238
+ Inputs: Program `goto_program`
1241
1239
1242
- Outputs:
1240
+ Outputs: Returns true if trivial
1243
1241
1244
- Purpose:
1242
+ Purpose: Call a goto_program trivial unless it has:
1243
+ * Any declarations
1244
+ * At least 2 branches
1245
+ * At least 5 assignments
1245
1246
1246
1247
\*******************************************************************/
1247
1248
1248
- bool consider_goals (const goto_programt &goto_program)
1249
+ bool program_is_trivial (const goto_programt &goto_program)
1249
1250
{
1250
- bool result;
1251
- unsigned long count_assignments=0 , count_goto=0 , count_decl=0 ;
1252
-
1251
+ unsigned long count_assignments=0 , count_goto=0 ;
1253
1252
forall_goto_program_instructions (i_it, goto_program)
1254
1253
{
1255
1254
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;
1255
+ {
1256
+ if ((++count_goto)>=2 )
1257
+ return false ;
1258
+ }
1259
+ else if (i_it->is_assign ())
1260
+ {
1261
+ if ((++count_assignments)>=5 )
1262
+ return false ;
1263
+ }
1264
+ else if (i_it->is_decl ())
1265
+ return false ;
1261
1266
}
1262
1267
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;
1268
+ return true ;
1271
1269
}
1272
1270
1273
1271
/* ******************************************************************\
@@ -1290,8 +1288,8 @@ void instrument_cover_goals(
1290
1288
bool function_only,
1291
1289
bool ignore_trivial)
1292
1290
{
1293
- // exclude trivial coverage goals of a goto program
1294
- if (ignore_trivial && ! consider_goals (goto_program))
1291
+ // exclude trivial coverage goals of a goto program
1292
+ if (ignore_trivial && program_is_trivial (goto_program))
1295
1293
return ;
1296
1294
1297
1295
const namespacet ns (symbol_table);
@@ -1374,7 +1372,8 @@ void instrument_cover_goals(
1374
1372
source_location.get_file ()[0 ]!=' <' &&
1375
1373
cover_curr_function)
1376
1374
{
1377
- std::string comment=" function " +id2string (i_it->function )+" block " +b;
1375
+ std::string comment=
1376
+ " function " +id2string (i_it->function )+" block " +b;
1378
1377
const irep_idt function=i_it->function ;
1379
1378
goto_program.insert_before_swap (i_it);
1380
1379
i_it->make_assertion (false_exprt ());
@@ -1647,7 +1646,7 @@ void instrument_cover_goals(
1647
1646
Forall_goto_functions (f_it, goto_functions)
1648
1647
{
1649
1648
if (f_it->first ==ID__start ||
1650
- f_it->first ==CPROVER_PREFIX " initialize" )
1649
+ f_it->first ==( CPROVER_PREFIX " initialize" ) )
1651
1650
continue ;
1652
1651
1653
1652
instrument_cover_goals (
@@ -1678,7 +1677,7 @@ void instrument_cover_goals(
1678
1677
coverage_criteriont criterion,
1679
1678
bool function_only)
1680
1679
{
1681
- // empty set of existing goals
1680
+ // empty set of existing goals
1682
1681
coverage_goalst goals;
1683
1682
instrument_cover_goals (
1684
1683
symbol_table,
0 commit comments