@@ -112,59 +112,56 @@ Function: coverage_goalst::get_coverage
112112
113113\*******************************************************************/
114114
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)
117119{
118120 jsont json;
119- coverage_goalst goals;
120121 source_locationt source_location;
121122
122123 // check coverage file
123- if (parse_json (coverage , message_handler, json))
124+ if (parse_json (coverage_file , message_handler, json))
124125 {
125126 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"
127128 << messaget::eom;
128- exit ( 6 ) ;
129+ return true ;
129130 }
130131
131132 // make sure that we have an array of elements
132133 if (!json.is_array ())
133134 {
134135 messaget message (message_handler);
135- message.error () << " expecting an array in the " << coverage
136+ message.error () << " expecting an array in the " << coverage_file
136137 << " file, but got "
137138 << json << messaget::eom;
138- exit ( 6 ) ;
139+ return true ;
139140 }
140141
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 )
146143 {
147144 // get the file of each existing goal
148- file=(*it) [" file" ].value ;
145+ irep_idt file=goal [" file" ].value ;
149146 source_location.set_file (file);
150147
151148 // get the function of each existing goal
152- function=(*it) [" function" ].value ;
149+ irep_idt function=goal [" function" ].value ;
153150 source_location.set_function (function);
154151
155152 // get the lines array
156- if ((*it) [" lines" ].is_array ())
153+ if (goal [" lines" ].is_array ())
157154 {
158- for (const jsont & entry : (*it) [" lines" ].array )
155+ for (const auto &line_json : goal [" lines" ].array )
159156 {
160157 // get the line of each existing goal
161- line=entry [" number" ].value ;
158+ irep_idt line=line_json [" number" ].value ;
162159 source_location.set_line (line);
163160 goals.add_goal (source_location);
164161 }
165162 }
166163 }
167- return goals ;
164+ return false ;
168165}
169166
170167/* ******************************************************************\
@@ -198,19 +195,14 @@ Function: coverage_goalst::is_existing_goal
198195
199196bool coverage_goalst::is_existing_goal (source_locationt source_location) const
200197{
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)
203199 {
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 ;
209204 }
210- if (it == existing_goals.end ())
211- return true ;
212- else
213- return false ;
205+ return false ;
214206}
215207
216208/* ******************************************************************\
@@ -1228,46 +1220,51 @@ void instrument_cover_goals(
12281220 coverage_criteriont criterion,
12291221 bool function_only)
12301222{
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 );
12341231}
12351232
12361233/* ******************************************************************\
12371234
1238- Function: consider_goals
1235+ Function: program_is_trivial
12391236
1240- Inputs:
1237+ Inputs: Program `goto_program`
12411238
1242- Outputs:
1239+ Outputs: Returns true if trivial
12431240
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
12451245
12461246\*******************************************************************/
12471247
1248- bool consider_goals (const goto_programt &goto_program)
1248+ bool program_is_trivial (const goto_programt &goto_program)
12491249{
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 ;
12531251 forall_goto_program_instructions (i_it, goto_program)
12541252 {
12551253 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 ;
12611265 }
12621266
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 ;
12711268}
12721269
12731270/* ******************************************************************\
@@ -1290,8 +1287,8 @@ void instrument_cover_goals(
12901287 bool function_only,
12911288 bool ignore_trivial)
12921289{
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))
12951292 return ;
12961293
12971294 const namespacet ns (symbol_table);
@@ -1369,12 +1366,13 @@ void instrument_cover_goals(
13691366 basic_blocks.source_location_map [block_nr];
13701367
13711368 // check whether the current goal already exists
1372- if (goals.is_existing_goal (source_location) &&
1369+ if (! goals.is_existing_goal (source_location) &&
13731370 !source_location.get_file ().empty () &&
13741371 source_location.get_file ()[0 ]!=' <' &&
13751372 cover_curr_function)
13761373 {
1377- std::string comment=" function " +id2string (i_it->function )+" block " +b;
1374+ std::string comment=
1375+ " function " +id2string (i_it->function )+" block " +b;
13781376 const irep_idt function=i_it->function ;
13791377 goto_program.insert_before_swap (i_it);
13801378 i_it->make_assertion (false_exprt ());
@@ -1647,7 +1645,7 @@ void instrument_cover_goals(
16471645 Forall_goto_functions (f_it, goto_functions)
16481646 {
16491647 if (f_it->first ==ID__start ||
1650- f_it->first ==CPROVER_PREFIX " initialize" )
1648+ f_it->first ==( CPROVER_PREFIX " initialize" ) )
16511649 continue ;
16521650
16531651 instrument_cover_goals (
@@ -1678,7 +1676,7 @@ void instrument_cover_goals(
16781676 coverage_criteriont criterion,
16791677 bool function_only)
16801678{
1681- // empty set of existing goals
1679+ // empty set of existing goals
16821680 coverage_goalst goals;
16831681 instrument_cover_goals (
16841682 symbol_table,
0 commit comments