@@ -631,27 +631,18 @@ void code_contractst::replace_history_parameter(
631631 }
632632}
633633
634- std::pair<goto_programt, goto_programt>
635- code_contractst::create_ensures_instruction (
636- codet &expression,
637- source_locationt location,
638- const irep_idt &mode)
634+ void code_contractst::generate_history_variables_initialization (
635+ exprt &clause,
636+ const irep_idt &mode,
637+ goto_programt &program)
639638{
640639 std::map<exprt, exprt> parameter2history;
641640 goto_programt history;
642-
643641 // Find and replace "old" expression in the "expression" variable
644642 replace_history_parameter (
645- expression, parameter2history, location, mode, history, ID_old);
646-
647- // Create instructions corresponding to the ensures clause
648- goto_programt ensures_program;
649- converter.goto_convert (expression, ensures_program, mode);
650-
651- // return a pair containing:
652- // 1. instructions corresponding to the ensures clause
653- // 2. instructions related to initializing the history variables
654- return std::make_pair (std::move (ensures_program), std::move (history));
643+ clause, parameter2history, clause.source_location (), mode, history, ID_old);
644+ // Add all the history variable initialization instructions
645+ program.destructive_append (history);
655646}
656647
657648// / This function generates instructions for all contract constraint, i.e.,
@@ -835,26 +826,16 @@ void code_contractst::apply_function_contract(
835826 new_program);
836827 }
837828
838- // Gather all the instructions required to handle history variables
839- std::vector<exprt> instantiated_ensures_clauses;
829+ // Generate all the instructions required to initialize history variables
830+ exprt::operandst instantiated_ensures_clauses;
840831 for (auto clause : type.ensures ())
841832 {
842833 auto instantiated_clause =
843834 to_lambda_expr (clause).application (instantiation_values);
844835 instantiated_clause.add_source_location () = clause.source_location ();
845- std::map<exprt, exprt> parameter2history;
846- goto_programt history;
847- // Find and replace "old" expression in the "expression" variable
848- replace_history_parameter (
849- instantiated_clause,
850- parameter2history,
851- clause.source_location (),
852- mode,
853- history,
854- ID_old);
836+ generate_history_variables_initialization (
837+ instantiated_clause, mode, new_program);
855838 instantiated_ensures_clauses.push_back (instantiated_clause);
856- // Add all the history variable initialization instructions
857- new_program.destructive_append (history);
858839 }
859840
860841 // ASSIGNS clause should not refer to any quantified variables,
@@ -1504,26 +1485,16 @@ void code_contractst::add_contract_check(
15041485 _location);
15051486 }
15061487
1507- // Gather all the instructions required to handle history variables
1508- std::vector<exprt> instantiated_ensures_clauses;
1488+ // Generate all the instructions required to initialize history variables
1489+ exprt::operandst instantiated_ensures_clauses;
15091490 for (auto clause : code_type.ensures ())
15101491 {
15111492 auto instantiated_clause =
15121493 to_lambda_expr (clause).application (instantiation_values);
15131494 instantiated_clause.add_source_location () = clause.source_location ();
1514- std::map<exprt, exprt> parameter2history;
1515- goto_programt history;
1516- // Find and replace "old" expression in the "expression" variable
1517- replace_history_parameter (
1518- instantiated_clause,
1519- parameter2history,
1520- clause.source_location (),
1521- function_symbol.mode ,
1522- history,
1523- ID_old);
1495+ generate_history_variables_initialization (
1496+ instantiated_clause, function_symbol.mode , check);
15241497 instantiated_ensures_clauses.push_back (instantiated_clause);
1525- // Add all the history variable initialization instructions
1526- check.destructive_append (history);
15271498 }
15281499
15291500 // Translate requires_contract(ptr, contract) clauses to assumptions
0 commit comments