@@ -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/* ******************************************************************\
@@ -199,18 +196,14 @@ Function: coverage_goalst::is_existing_goal
199196bool coverage_goalst::is_existing_goal (source_locationt source_location) const
200197{
201198 std::vector<source_locationt>::const_iterator it = existing_goals.begin ();
202- while (it!= existing_goals. end () )
199+ for ( const auto &existing_loc : existing_goals)
203200 {
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 ;
209205 }
210- if (it == existing_goals.end ())
211- return true ;
212- else
213- return false ;
206+ return false ;
214207}
215208
216209/* ******************************************************************\
@@ -1228,46 +1221,51 @@ void instrument_cover_goals(
12281221 coverage_criteriont criterion,
12291222 bool function_only)
12301223{
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 );
12341232}
12351233
12361234/* ******************************************************************\
12371235
1238- Function: consider_goals
1236+ Function: program_is_trivial
12391237
1240- Inputs:
1238+ Inputs: Program `goto_program`
12411239
1242- Outputs:
1240+ Outputs: Returns true if trivial
12431241
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
12451246
12461247\*******************************************************************/
12471248
1248- bool consider_goals (const goto_programt &goto_program)
1249+ bool program_is_trivial (const goto_programt &goto_program)
12491250{
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 ;
12531252 forall_goto_program_instructions (i_it, goto_program)
12541253 {
12551254 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 ;
12611266 }
12621267
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 ;
12711269}
12721270
12731271/* ******************************************************************\
@@ -1290,8 +1288,8 @@ void instrument_cover_goals(
12901288 bool function_only,
12911289 bool ignore_trivial)
12921290{
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))
12951293 return ;
12961294
12971295 const namespacet ns (symbol_table);
@@ -1374,7 +1372,8 @@ void instrument_cover_goals(
13741372 source_location.get_file ()[0 ]!=' <' &&
13751373 cover_curr_function)
13761374 {
1377- std::string comment=" function " +id2string (i_it->function )+" block " +b;
1375+ std::string comment=
1376+ " function " +id2string (i_it->function )+" block " +b;
13781377 const irep_idt function=i_it->function ;
13791378 goto_program.insert_before_swap (i_it);
13801379 i_it->make_assertion (false_exprt ());
@@ -1647,7 +1646,7 @@ void instrument_cover_goals(
16471646 Forall_goto_functions (f_it, goto_functions)
16481647 {
16491648 if (f_it->first ==ID__start ||
1650- f_it->first ==CPROVER_PREFIX " initialize" )
1649+ f_it->first ==( CPROVER_PREFIX " initialize" ) )
16511650 continue ;
16521651
16531652 instrument_cover_goals (
@@ -1678,7 +1677,7 @@ void instrument_cover_goals(
16781677 coverage_criteriont criterion,
16791678 bool function_only)
16801679{
1681- // empty set of existing goals
1680+ // empty set of existing goals
16821681 coverage_goalst goals;
16831682 instrument_cover_goals (
16841683 symbol_table,
0 commit comments