Skip to content

Commit 9860129

Browse files
committed
Minor refactor and cleanup on code contracts
We can maintain a `protected` `goto_convertt` field in our class, which would be reusable, rather than trying to instantiate an object for each codet -> goto_programt transformation.
1 parent 0b4a3e8 commit 9860129

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

src/goto-instrument/code_contracts.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,6 @@ static void check_apply_invariants(
158158
loop_end->set_condition(boolean_negate(loop_end->get_condition()));
159159
}
160160

161-
void code_contractst::convert_to_goto(
162-
const codet &code,
163-
const irep_idt &mode,
164-
goto_programt &program)
165-
{
166-
goto_convertt converter(symbol_table, log.get_message_handler());
167-
converter.goto_convert(code, program, mode);
168-
}
169-
170161
bool code_contractst::has_contract(const irep_idt fun_name)
171162
{
172163
const symbolt &function_symbol = ns.lookup(fun_name);
@@ -322,7 +313,7 @@ code_contractst::create_ensures_instruction(
322313

323314
// Create instructions corresponding to the ensures clause
324315
goto_programt ensures_program;
325-
convert_to_goto(expression, mode, ensures_program);
316+
converter.goto_convert(expression, ensures_program, mode);
326317

327318
// return a pair containing:
328319
// 1. instructions corresponding to the ensures clause
@@ -424,10 +415,10 @@ bool code_contractst::apply_function_contract(
424415
if(requires.is_not_nil())
425416
{
426417
goto_programt assertion;
427-
convert_to_goto(
418+
converter.goto_convert(
428419
code_assertt(requires),
429-
symbol_table.lookup_ref(function).mode,
430-
assertion);
420+
assertion,
421+
symbol_table.lookup_ref(function).mode);
431422
auto lines_to_iterate = assertion.instructions.size();
432423
goto_program.insert_before_swap(target, assertion);
433424
std::advance(target, lines_to_iterate);
@@ -966,8 +957,8 @@ void code_contractst::add_contract_check(
966957
replace(requires_cond);
967958

968959
goto_programt assumption;
969-
convert_to_goto(
970-
code_assumet(requires_cond), function_symbol.mode, assumption);
960+
converter.goto_convert(
961+
code_assumet(requires_cond), assumption, function_symbol.mode);
971962
check.destructive_append(assumption);
972963
}
973964

src/goto-instrument/code_contracts.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Date: February 2016
1919
#include <string>
2020
#include <unordered_set>
2121

22+
#include <goto-programs/goto_convert_class.h>
2223
#include <goto-programs/goto_functions.h>
2324
#include <goto-programs/goto_model.h>
2425

@@ -36,8 +37,9 @@ class code_contractst
3637
: ns(goto_model.symbol_table),
3738
symbol_table(goto_model.symbol_table),
3839
goto_functions(goto_model.goto_functions),
39-
temporary_counter(0),
40-
log(log)
40+
log(log),
41+
converter(symbol_table, log.get_message_handler())
42+
4143
{
4244
}
4345

@@ -95,20 +97,14 @@ class code_contractst
9597
symbol_tablet &symbol_table;
9698
goto_functionst &goto_functions;
9799

98-
unsigned temporary_counter;
99100
messaget &log;
101+
goto_convertt converter;
100102

101103
std::unordered_set<irep_idt> summarized;
102104

103105
/// \brief Enforce contract of a single function
104106
bool enforce_contract(const std::string &);
105107

106-
/// \brief Create goto instructions based on code and add them to program.
107-
void convert_to_goto(
108-
const codet &code,
109-
const irep_idt &mode,
110-
goto_programt &program);
111-
112108
/// Insert assertion statements into the goto program to ensure that
113109
/// assigned memory is within the assignable memory frame.
114110
bool add_pointer_checks(const std::string &);

0 commit comments

Comments
 (0)