Skip to content

Commit 862d2a1

Browse files
authored
Merge pull request #7679 from tautschnig/cleanup/is_fresh
Decouple is_fresh from code_contractst
2 parents abad42b + 9777e00 commit 862d2a1

File tree

4 files changed

+51
-60
lines changed

4 files changed

+51
-60
lines changed

src/goto-instrument/contracts/contracts.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@ void code_contractst::apply_function_contract(
668668
// new program where all contract-derived instructions are added
669669
goto_programt new_program;
670670

671-
is_fresh_replacet is_fresh(*this, log, target_function);
671+
is_fresh_replacet is_fresh(
672+
goto_model, log.get_message_handler(), target_function);
672673
is_fresh.create_declarations();
673674
is_fresh.add_memory_map_decl(new_program);
674675

@@ -1072,16 +1073,6 @@ void code_contractst::apply_loop_contract(
10721073
}
10731074
}
10741075

1075-
symbol_tablet &code_contractst::get_symbol_table()
1076-
{
1077-
return symbol_table;
1078-
}
1079-
1080-
goto_functionst &code_contractst::get_goto_functions()
1081-
{
1082-
return goto_functions;
1083-
}
1084-
10851076
void code_contractst::check_frame_conditions_function(const irep_idt &function)
10861077
{
10871078
// Get the function object before instrumentation.
@@ -1302,7 +1293,8 @@ void code_contractst::add_contract_check(
13021293
instantiation_values.push_back(p);
13031294
}
13041295

1305-
is_fresh_enforcet visitor(*this, log, wrapper_function);
1296+
is_fresh_enforcet visitor(
1297+
goto_model, log.get_message_handler(), wrapper_function);
13061298
visitor.create_declarations();
13071299
visitor.add_memory_map_decl(check);
13081300

src/goto-instrument/contracts/contracts.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ class code_contractst
126126
exprt decreases_clause,
127127
const irep_idt &mode);
128128

129-
// for "helper" classes to update symbol table.
130-
symbol_tablet &get_symbol_table();
131-
goto_functionst &get_goto_functions();
132-
133129
std::unordered_map<goto_programt::const_targett, unsigned, const_target_hash>
134130
get_original_loop_number_map() const
135131
{

src/goto-instrument/contracts/memory_predicates.cpp

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Date: July 2021
2323
#include <ansi-c/ansi_c_language.h>
2424
#include <linking/static_lifetime_init.h>
2525

26-
#include "contracts.h"
2726
#include "instrument_spec_assigns.h"
2827
#include "utils.h"
2928

@@ -34,6 +33,8 @@ std::set<irep_idt> &functions_in_scope_visitort::function_calls()
3433

3534
void functions_in_scope_visitort::operator()(const goto_programt &prog)
3635
{
36+
messaget log{message_handler};
37+
3738
forall_goto_program_instructions(ins, prog)
3839
{
3940
if(ins->is_function_call())
@@ -163,12 +164,13 @@ void is_fresh_baset::add_memory_map_dead(goto_programt &program)
163164

164165
void is_fresh_baset::add_declarations(const std::string &decl_string)
165166
{
167+
messaget log{message_handler};
166168
log.debug() << "Creating declarations: \n" << decl_string << "\n";
167169

168170
std::istringstream iss(decl_string);
169171

170172
ansi_c_languaget ansi_c_language;
171-
ansi_c_language.set_message_handler(log.get_message_handler());
173+
ansi_c_language.set_message_handler(message_handler);
172174
configt::ansi_ct::preprocessort pp = config.ansi_c.preprocessor;
173175
config.ansi_c.preprocessor = configt::ansi_ct::preprocessort::NONE;
174176
ansi_c_language.parse(iss, "");
@@ -181,10 +183,10 @@ void is_fresh_baset::add_declarations(const std::string &decl_string)
181183
goto_functionst tmp_functions;
182184

183185
// Add the new functions into the goto functions table.
184-
parent.get_goto_functions().function_map[ensures_fn_name].copy_from(
186+
goto_model.goto_functions.function_map[ensures_fn_name].copy_from(
185187
tmp_functions.function_map[ensures_fn_name]);
186188

187-
parent.get_goto_functions().function_map[requires_fn_name].copy_from(
189+
goto_model.goto_functions.function_map[requires_fn_name].copy_from(
188190
tmp_functions.function_map[requires_fn_name]);
189191

190192
for(const auto &symbol_pair : tmp_symbol_table.symbols)
@@ -194,31 +196,31 @@ void is_fresh_baset::add_declarations(const std::string &decl_string)
194196
symbol_pair.first == ensures_fn_name ||
195197
symbol_pair.first == requires_fn_name || symbol_pair.first == "malloc")
196198
{
197-
this->parent.get_symbol_table().insert(symbol_pair.second);
199+
goto_model.symbol_table.insert(symbol_pair.second);
198200
}
199201
// Parameters are stored as scoped names in the symbol table.
200202
else if(
201203
(has_prefix(
202204
id2string(symbol_pair.first), id2string(ensures_fn_name) + "::") ||
203205
has_prefix(
204206
id2string(symbol_pair.first), id2string(requires_fn_name) + "::")) &&
205-
parent.get_symbol_table().add(symbol_pair.second))
207+
goto_model.symbol_table.add(symbol_pair.second))
206208
{
207209
UNREACHABLE;
208210
}
209211
}
210212

211-
if(parent.get_goto_functions().function_map.erase(INITIALIZE_FUNCTION) != 0)
213+
if(goto_model.goto_functions.function_map.erase(INITIALIZE_FUNCTION) != 0)
212214
{
213215
static_lifetime_init(
214-
parent.get_symbol_table(),
215-
parent.get_symbol_table().lookup_ref(INITIALIZE_FUNCTION).location);
216+
goto_model.symbol_table,
217+
goto_model.symbol_table.lookup_ref(INITIALIZE_FUNCTION).location);
216218
goto_convert(
217219
INITIALIZE_FUNCTION,
218-
parent.get_symbol_table(),
219-
parent.get_goto_functions(),
220+
goto_model.symbol_table,
221+
goto_model.goto_functions,
220222
log.get_message_handler());
221-
parent.get_goto_functions().update();
223+
goto_model.goto_functions.update();
222224
}
223225
}
224226

@@ -247,10 +249,10 @@ void is_fresh_baset::update_fn_call(
247249
/* Declarations for contract enforcement */
248250

249251
is_fresh_enforcet::is_fresh_enforcet(
250-
code_contractst &_parent,
251-
messaget _log,
252-
irep_idt _fun_id)
253-
: is_fresh_baset(_parent, _log, _fun_id)
252+
goto_modelt &goto_model,
253+
message_handlert &message_handler,
254+
const irep_idt &_fun_id)
255+
: is_fresh_baset(goto_model, message_handler, _fun_id)
254256
{
255257
std::stringstream ssreq, ssensure, ssmemmap;
256258
ssreq << CPROVER_PREFIX "enforce_requires_is_fresh";
@@ -262,20 +264,20 @@ is_fresh_enforcet::is_fresh_enforcet(
262264
ssmemmap << CPROVER_PREFIX "is_fresh_memory_map_" << fun_id;
263265
this->memmap_name = ssmemmap.str();
264266

265-
const auto &mode = parent.get_symbol_table().lookup_ref(_fun_id).mode;
267+
const auto &mode = goto_model.symbol_table.lookup_ref(_fun_id).mode;
266268
this->memmap_symbol = new_tmp_symbol(
267269
get_memmap_type(),
268270
source_locationt(),
269271
mode,
270-
parent.get_symbol_table(),
272+
goto_model.symbol_table,
271273
this->memmap_name,
272274
true);
273275
}
274276

275277
void is_fresh_enforcet::create_declarations()
276278
{
277279
// Check if symbols are already declared
278-
if(parent.get_symbol_table().lookup(requires_fn_name) != nullptr)
280+
if(goto_model.symbol_table.has_symbol(requires_fn_name))
279281
return;
280282

281283
std::ostringstream oss;
@@ -326,10 +328,10 @@ void is_fresh_enforcet::create_ensures_fn_call(goto_programt::targett &ins)
326328
}
327329

328330
is_fresh_replacet::is_fresh_replacet(
329-
code_contractst &_parent,
330-
messaget _log,
331-
irep_idt _fun_id)
332-
: is_fresh_baset(_parent, _log, _fun_id)
331+
goto_modelt &goto_model,
332+
message_handlert &message_handler,
333+
const irep_idt &_fun_id)
334+
: is_fresh_baset(goto_model, message_handler, _fun_id)
333335
{
334336
std::stringstream ssreq, ssensure, ssmemmap;
335337
ssreq << CPROVER_PREFIX "replace_requires_is_fresh";
@@ -341,21 +343,22 @@ is_fresh_replacet::is_fresh_replacet(
341343
ssmemmap << CPROVER_PREFIX "is_fresh_memory_map_" << fun_id;
342344
this->memmap_name = ssmemmap.str();
343345

344-
const auto &mode = parent.get_symbol_table().lookup_ref(_fun_id).mode;
346+
const auto &mode = goto_model.symbol_table.lookup_ref(_fun_id).mode;
345347
this->memmap_symbol = new_tmp_symbol(
346348
get_memmap_type(),
347349
source_locationt(),
348350
mode,
349-
parent.get_symbol_table(),
351+
goto_model.symbol_table,
350352
this->memmap_name,
351353
true);
352354
}
353355

354356
void is_fresh_replacet::create_declarations()
355357
{
356358
// Check if symbols are already declared
357-
if(parent.get_symbol_table().lookup(requires_fn_name) != nullptr)
359+
if(goto_model.symbol_table.has_symbol(requires_fn_name))
358360
return;
361+
359362
std::ostringstream oss;
360363
std::string cprover_prefix(CPROVER_PREFIX);
361364
oss << "static _Bool " << requires_fn_name

src/goto-instrument/contracts/memory_predicates.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ Date: July 2021
1414
#ifndef CPROVER_GOTO_INSTRUMENT_CONTRACTS_MEMORY_PREDICATES_H
1515
#define CPROVER_GOTO_INSTRUMENT_CONTRACTS_MEMORY_PREDICATES_H
1616

17-
#include <util/message.h>
1817
#include <util/symbol.h>
1918

2019
#include <goto-programs/goto_program.h>
2120

22-
class code_contractst;
2321
class goto_functionst;
22+
class goto_modelt;
23+
class message_handlert;
2424

2525
class is_fresh_baset
2626
{
2727
public:
2828
is_fresh_baset(
29-
code_contractst &_parent,
30-
messaget _log,
31-
const irep_idt _fun_id)
32-
: parent(_parent), log(_log), fun_id(_fun_id)
29+
goto_modelt &goto_model,
30+
message_handlert &message_handler,
31+
const irep_idt &_fun_id)
32+
: goto_model(goto_model), message_handler(message_handler), fun_id(_fun_id)
3333
{
3434
}
3535

@@ -51,9 +51,9 @@ class is_fresh_baset
5151
virtual void create_requires_fn_call(goto_programt::targett &target) = 0;
5252
virtual void create_ensures_fn_call(goto_programt::targett &target) = 0;
5353

54-
code_contractst &parent;
55-
messaget log;
56-
irep_idt fun_id;
54+
goto_modelt &goto_model;
55+
message_handlert &message_handler;
56+
const irep_idt &fun_id;
5757

5858
// written by the child classes.
5959
std::string memmap_name;
@@ -68,9 +68,9 @@ class is_fresh_enforcet : public is_fresh_baset
6868
{
6969
public:
7070
is_fresh_enforcet(
71-
code_contractst &_parent,
72-
messaget _log,
73-
const irep_idt _fun_id);
71+
goto_modelt &goto_model,
72+
message_handlert &message_handler,
73+
const irep_idt &_fun_id);
7474

7575
virtual void create_declarations();
7676

@@ -83,9 +83,9 @@ class is_fresh_replacet : public is_fresh_baset
8383
{
8484
public:
8585
is_fresh_replacet(
86-
code_contractst &_parent,
87-
messaget _log,
88-
const irep_idt _fun_id);
86+
goto_modelt &goto_model,
87+
message_handlert &message_handler,
88+
const irep_idt &_fun_id);
8989

9090
virtual void create_declarations();
9191

@@ -121,8 +121,8 @@ class functions_in_scope_visitort
121121
public:
122122
functions_in_scope_visitort(
123123
const goto_functionst &goto_functions,
124-
messaget &log)
125-
: goto_functions(goto_functions), log(log)
124+
message_handlert &message_handler)
125+
: goto_functions(goto_functions), message_handler(message_handler)
126126
{
127127
}
128128

@@ -133,7 +133,7 @@ class functions_in_scope_visitort
133133

134134
protected:
135135
const goto_functionst &goto_functions;
136-
messaget &log;
136+
message_handlert &message_handler;
137137
std::set<irep_idt> function_set;
138138
};
139139

0 commit comments

Comments
 (0)