@@ -51,7 +51,6 @@ exprt get_size(const typet &type, const namespacet &ns, messaget &log)
5151
5252void code_contractst::check_apply_loop_contracts (
5353 goto_functionst::goto_functiont &goto_function,
54- const irep_idt &function_name,
5554 const local_may_aliast &local_may_alias,
5655 const goto_programt::targett loop_head,
5756 const loopt &loop,
@@ -161,12 +160,10 @@ void code_contractst::check_apply_loop_contracts(
161160 for (const auto &clause : decreases_clause.operands ())
162161 {
163162 old_temporary_variables.push_back (
164- new_tmp_symbol (
165- clause.type (), loop_head->source_location , function_name, mode)
163+ new_tmp_symbol (clause.type (), loop_head->source_location , mode)
166164 .symbol_expr ());
167165 new_temporary_variables.push_back (
168- new_tmp_symbol (
169- clause.type (), loop_head->source_location , function_name, mode)
166+ new_tmp_symbol (clause.type (), loop_head->source_location , mode)
170167 .symbol_expr ());
171168 }
172169
@@ -396,14 +393,12 @@ void code_contractst::replace_old_parameter(
396393 exprt &expr,
397394 std::map<exprt, exprt> ¶meter2history,
398395 source_locationt location,
399- const irep_idt &function,
400396 const irep_idt &mode,
401397 goto_programt &history)
402398{
403399 for (auto &op : expr.operands ())
404400 {
405- replace_old_parameter (
406- op, parameter2history, location, function, mode, history);
401+ replace_old_parameter (op, parameter2history, location, mode, history);
407402 }
408403
409404 if (expr.id () == ID_old)
@@ -425,8 +420,7 @@ void code_contractst::replace_old_parameter(
425420 // 1. Create a temporary symbol expression that represents the
426421 // history variable
427422 symbol_exprt tmp_symbol =
428- new_tmp_symbol (dereference_expr.type (), location, function, mode)
429- .symbol_expr ();
423+ new_tmp_symbol (dereference_expr.type (), location, mode).symbol_expr ();
430424
431425 // 2. Associate the above temporary variable to it's corresponding
432426 // expression
@@ -458,15 +452,13 @@ std::pair<goto_programt, goto_programt>
458452code_contractst::create_ensures_instruction (
459453 codet &expression,
460454 source_locationt location,
461- const irep_idt &function,
462455 const irep_idt &mode)
463456{
464457 std::map<exprt, exprt> parameter2history;
465458 goto_programt history;
466459
467460 // Find and replace "old" expression in the "expression" variable
468- replace_old_parameter (
469- expression, parameter2history, location, function, mode, history);
461+ replace_old_parameter (expression, parameter2history, location, mode, history);
470462
471463 // Create instructions corresponding to the ensures clause
472464 goto_programt ensures_program;
@@ -479,7 +471,6 @@ code_contractst::create_ensures_instruction(
479471}
480472
481473bool code_contractst::apply_function_contract (
482- const irep_idt &function_id,
483474 goto_programt &goto_program,
484475 goto_programt::targett target)
485476{
@@ -603,7 +594,6 @@ bool code_contractst::apply_function_contract(
603594 ensures_pair = create_ensures_instruction (
604595 assumption,
605596 ensures.source_location (),
606- function,
607597 symbol_table.lookup_ref (function).mode );
608598
609599 // add all the history variable initialization instructions
@@ -617,9 +607,9 @@ bool code_contractst::apply_function_contract(
617607 // in the assigns clause.
618608 if (assigns.is_not_nil ())
619609 {
620- assigns_clauset assigns_cause (assigns, *this , function_id , log);
610+ assigns_clauset assigns_cause (assigns, *this , function , log);
621611 goto_programt assigns_havoc = assigns_cause.havoc_code (
622- function_symbol.location , function_id , function_symbol.mode );
612+ function_symbol.location , function , function_symbol.mode );
623613
624614 // Insert the non-deterministic assignment immediately before the call site.
625615 std::size_t lines_to_iterate = assigns_havoc.instructions .size ();
@@ -644,7 +634,7 @@ bool code_contractst::apply_function_contract(
644634}
645635
646636void code_contractst::apply_loop_contract (
647- const irep_idt &function_name ,
637+ const irep_idt &function ,
648638 goto_functionst::goto_functiont &goto_function)
649639{
650640 local_may_aliast local_may_alias (goto_function);
@@ -656,23 +646,21 @@ void code_contractst::apply_loop_contract(
656646 {
657647 check_apply_loop_contracts (
658648 goto_function,
659- function_name,
660649 local_may_alias,
661650 loop.first ,
662651 loop.second ,
663- symbol_table.lookup_ref (function_name ).mode );
652+ symbol_table.lookup_ref (function ).mode );
664653 }
665654}
666655
667656const symbolt &code_contractst::new_tmp_symbol (
668657 const typet &type,
669658 const source_locationt &source_location,
670- const irep_idt &function_id,
671659 const irep_idt &mode)
672660{
673661 return get_fresh_aux_symbol (
674662 type,
675- id2string (function_id ) + " ::tmp_cc" ,
663+ id2string (source_location. get_function () ) + " ::tmp_cc" ,
676664 " tmp_cc" ,
677665 source_location,
678666 mode,
@@ -731,7 +719,6 @@ void code_contractst::instrument_call_statement(
731719 goto_programt::instructionst::iterator &instruction_iterator,
732720 goto_programt &program,
733721 exprt &assigns,
734- const irep_idt &function_id,
735722 std::set<irep_idt> &freely_assignable_symbols,
736723 assigns_clauset &assigns_clause)
737724{
@@ -827,7 +814,7 @@ void code_contractst::instrument_call_statement(
827814
828815 // check compatibility of assigns clause with the called function
829816 assigns_clauset called_assigns_clause (
830- called_assigns, *this , function_id , log);
817+ called_assigns, *this , called_name , log);
831818 exprt compatible =
832819 assigns_clause.compatible_expression (called_assigns_clause);
833820 goto_programt alias_assertion;
@@ -992,7 +979,6 @@ void code_contractst::check_frame_conditions(
992979 instruction_it,
993980 program,
994981 assigns_expr,
995- target.name ,
996982 freely_assignable_symbols,
997983 assigns);
998984 }
@@ -1073,13 +1059,13 @@ bool code_contractst::enforce_contract(const irep_idt &function)
10731059}
10741060
10751061void code_contractst::add_contract_check (
1076- const irep_idt &wrapper_fun ,
1077- const irep_idt &mangled_fun ,
1062+ const irep_idt &wrapper_function ,
1063+ const irep_idt &mangled_function ,
10781064 goto_programt &dest)
10791065{
10801066 PRECONDITION (!dest.instructions .empty ());
10811067
1082- const symbolt &function_symbol = ns.lookup (mangled_fun );
1068+ const symbolt &function_symbol = ns.lookup (mangled_function );
10831069 const auto &code_type = to_code_with_contract_type (function_symbol.type );
10841070
10851071 exprt assigns = code_type.assigns ();
@@ -1123,7 +1109,6 @@ void code_contractst::add_contract_check(
11231109 symbol_exprt r = new_tmp_symbol (
11241110 code_type.return_type (),
11251111 skip->source_location ,
1126- wrapper_fun,
11271112 function_symbol.mode )
11281113 .symbol_expr ();
11291114 check.add (goto_programt::make_decl (r, skip->source_location ));
@@ -1137,7 +1122,7 @@ void code_contractst::add_contract_check(
11371122
11381123 // decl parameter1 ...
11391124 goto_functionst::function_mapt::iterator f_it =
1140- goto_functions.function_map .find (mangled_fun );
1125+ goto_functions.function_map .find (mangled_function );
11411126 PRECONDITION (f_it != goto_functions.function_map .end ());
11421127
11431128 const goto_functionst::goto_functiont &gf = f_it->second ;
@@ -1148,7 +1133,6 @@ void code_contractst::add_contract_check(
11481133 symbol_exprt p = new_tmp_symbol (
11491134 parameter_symbol.type ,
11501135 skip->source_location ,
1151- wrapper_fun,
11521136 parameter_symbol.mode )
11531137 .symbol_expr ();
11541138 check.add (goto_programt::make_decl (p, skip->source_location ));
@@ -1160,7 +1144,7 @@ void code_contractst::add_contract_check(
11601144 common_replace.insert (parameter_symbol.symbol_expr (), p);
11611145 }
11621146
1163- is_fresh_enforcet visitor (*this , log, wrapper_fun );
1147+ is_fresh_enforcet visitor (*this , log, wrapper_function );
11641148 visitor.create_declarations ();
11651149
11661150 // Generate: assume(requires)
@@ -1197,7 +1181,7 @@ void code_contractst::add_contract_check(
11971181 auto assertion = code_assertt (ensures);
11981182 assertion.add_source_location () = ensures.source_location ();
11991183 ensures_pair = create_ensures_instruction (
1200- assertion, ensures.source_location (), wrapper_fun, function_symbol.mode );
1184+ assertion, ensures.source_location (), function_symbol.mode );
12011185 ensures_pair.first .instructions .back ().source_location .set_comment (
12021186 " Check ensures clause" );
12031187 ensures_pair.first .instructions .back ().source_location .set_property_class (
@@ -1208,7 +1192,7 @@ void code_contractst::add_contract_check(
12081192 check.destructive_append (ensures_pair.second );
12091193 }
12101194
1211- // ret=mangled_fun (parameter1, ...)
1195+ // ret=mangled_function (parameter1, ...)
12121196 check.add (goto_programt::make_function_call (call, skip->source_location ));
12131197
12141198 // Generate: assert(ensures)
@@ -1227,15 +1211,14 @@ void code_contractst::add_contract_check(
12271211 dest.destructive_insert (dest.instructions .begin (), check);
12281212}
12291213
1230- bool code_contractst::replace_calls (
1231- const std::set<std::string> &funs_to_replace)
1214+ bool code_contractst::replace_calls (const std::set<std::string> &functions)
12321215{
12331216 bool fail = false ;
1234- for (const auto &fun : funs_to_replace )
1217+ for (const auto &function : functions )
12351218 {
1236- if (!has_contract (fun ))
1219+ if (!has_contract (function ))
12371220 {
1238- log.error () << " Function '" << fun
1221+ log.error () << " Function '" << function
12391222 << " ' does not have a contract; "
12401223 " not replacing calls with contract."
12411224 << messaget::eom;
@@ -1256,17 +1239,14 @@ bool code_contractst::replace_calls(
12561239 if (call.function ().id () != ID_symbol)
12571240 continue ;
12581241
1259- const irep_idt &function_name =
1242+ const irep_idt &called_function =
12601243 to_symbol_expr (call.function ()).get_identifier ();
12611244 auto found = std::find (
1262- funs_to_replace.begin (),
1263- funs_to_replace.end (),
1264- id2string (function_name));
1265- if (found == funs_to_replace.end ())
1245+ functions.begin (), functions.end (), id2string (called_function));
1246+ if (found == functions.end ())
12661247 continue ;
12671248
1268- fail |= apply_function_contract (
1269- function_name, goto_function.second .body , ins);
1249+ fail |= apply_function_contract (goto_function.second .body , ins);
12701250 }
12711251 }
12721252 }
@@ -1290,52 +1270,51 @@ void code_contractst::apply_loop_contracts()
12901270
12911271bool code_contractst::replace_calls ()
12921272{
1293- std::set<std::string> funs_to_replace ;
1273+ std::set<std::string> functions ;
12941274 for (auto &goto_function : goto_functions.function_map )
12951275 {
12961276 if (has_contract (goto_function.first ))
1297- funs_to_replace .insert (id2string (goto_function.first ));
1277+ functions .insert (id2string (goto_function.first ));
12981278 }
1299- return replace_calls (funs_to_replace );
1279+ return replace_calls (functions );
13001280}
13011281
13021282bool code_contractst::enforce_contracts ()
13031283{
1304- std::set<std::string> funs_to_enforce ;
1284+ std::set<std::string> functions ;
13051285 for (auto &goto_function : goto_functions.function_map )
13061286 {
13071287 if (has_contract (goto_function.first ))
1308- funs_to_enforce .insert (id2string (goto_function.first ));
1288+ functions .insert (id2string (goto_function.first ));
13091289 }
1310- return enforce_contracts (funs_to_enforce );
1290+ return enforce_contracts (functions );
13111291}
13121292
1313- bool code_contractst::enforce_contracts (
1314- const std::set<std::string> &funs_to_enforce)
1293+ bool code_contractst::enforce_contracts (const std::set<std::string> &functions)
13151294{
13161295 bool fail = false ;
1317- for (const auto &fun : funs_to_enforce )
1296+ for (const auto &function : functions )
13181297 {
1319- auto goto_function = goto_functions.function_map .find (fun );
1298+ auto goto_function = goto_functions.function_map .find (function );
13201299 if (goto_function == goto_functions.function_map .end ())
13211300 {
13221301 fail = true ;
1323- log.error () << " Could not find function '" << fun
1302+ log.error () << " Could not find function '" << function
13241303 << " ' in goto-program; not enforcing contracts."
13251304 << messaget::eom;
13261305 continue ;
13271306 }
13281307
1329- if (!has_contract (fun ))
1308+ if (!has_contract (function ))
13301309 {
13311310 fail = true ;
1332- log.error () << " Could not find any contracts within function '" << fun
1333- << " '; nothing to enforce." << messaget::eom;
1311+ log.error () << " Could not find any contracts within function '"
1312+ << function << " '; nothing to enforce." << messaget::eom;
13341313 continue ;
13351314 }
13361315
13371316 if (!fail)
1338- fail = enforce_contract (fun );
1317+ fail = enforce_contract (function );
13391318 }
13401319 return fail;
13411320}
0 commit comments