Skip to content

Commit 7e75c43

Browse files
committed
Make all methods of dfcc_utilst static
This class has no state, there is no need to instantiate it. Also remove functions from the interface that are only used by one of the members, and remove those that are not used at all.
1 parent 889a84b commit 7e75c43

26 files changed

+475
-538
lines changed

src/goto-instrument/contracts/dynamic-frames/dfcc.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,20 @@ dfcct::dfcct(
188188
to_exclude_from_nondet_static(to_exclude_from_nondet_static),
189189
message_handler(message_handler),
190190
log(message_handler),
191-
utils(goto_model, message_handler),
192-
library(goto_model, utils, message_handler),
191+
library(goto_model, message_handler),
193192
ns(goto_model.symbol_table),
194-
spec_functions(goto_model, message_handler, utils, library),
195-
contract_clauses_codegen(goto_model, message_handler, utils, library),
193+
spec_functions(goto_model, message_handler, library),
194+
contract_clauses_codegen(goto_model, message_handler, library),
196195
instrument(
197196
goto_model,
198197
message_handler,
199-
utils,
200198
library,
201199
spec_functions,
202200
contract_clauses_codegen),
203-
memory_predicates(goto_model, utils, library, instrument, message_handler),
201+
memory_predicates(goto_model, library, instrument, message_handler),
204202
contract_handler(
205203
goto_model,
206204
message_handler,
207-
utils,
208205
library,
209206
instrument,
210207
memory_predicates,
@@ -213,7 +210,6 @@ dfcct::dfcct(
213210
swap_and_wrap(
214211
goto_model,
215212
message_handler,
216-
utils,
217213
library,
218214
instrument,
219215
spec_functions,
@@ -227,15 +223,15 @@ void dfcct::check_transform_goto_model_preconditions()
227223
{
228224
// check that harness function exists
229225
PRECONDITION_WITH_DIAGNOSTICS(
230-
utils.function_symbol_with_body_exists(harness_id),
226+
dfcc_utilst::function_symbol_with_body_exists(goto_model, harness_id),
231227
"Harness function '" + id2string(harness_id) +
232228
"' either not found or has no body");
233229

234230
if(to_check.has_value())
235231
{
236232
auto pair = to_check.value();
237233
PRECONDITION_WITH_DIAGNOSTICS(
238-
utils.function_symbol_with_body_exists(pair.first),
234+
dfcc_utilst::function_symbol_with_body_exists(goto_model, pair.first),
239235
"Function to check '" + id2string(pair.first) +
240236
"' either not found or has no body");
241237

@@ -268,7 +264,7 @@ void dfcct::check_transform_goto_model_preconditions()
268264
// for functions to replace with contracts we don't require the replaced
269265
// function to have a body because only the contract is actually used
270266
PRECONDITION_WITH_DIAGNOSTICS(
271-
utils.function_symbol_exists(pair.first),
267+
dfcc_utilst::function_symbol_exists(goto_model, pair.first),
272268
"Function to replace '" + id2string(pair.first) + "' not found");
273269

274270
// triggers signature compatibility checking
@@ -454,7 +450,7 @@ void dfcct::wrap_discovered_function_pointer_contracts()
454450
{
455451
// we need to swap it with itself
456452
PRECONDITION_WITH_DIAGNOSTICS(
457-
utils.function_symbol_exists(str),
453+
dfcc_utilst::function_symbol_exists(goto_model, str),
458454
"Function pointer contract '" + str + "' not found.");
459455

460456
// triggers signature compatibility checking
@@ -581,7 +577,7 @@ void dfcct::reinitialize_model()
581577
goto_model.symbol_table.symbols.find(goto_functionst::entry_point()));
582578
// regenerate the CPROVER start function
583579
generate_ansi_c_start_function(
584-
utils.get_function_symbol(harness_id),
580+
dfcc_utilst::get_function_symbol(goto_model.symbol_table, harness_id),
585581
goto_model.symbol_table,
586582
message_handler,
587583
c_object_factory_parameterst(options));

src/goto-instrument/contracts/dynamic-frames/dfcc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ Author: Remi Delmas, [email protected]
4141
#include "dfcc_loop_contract_mode.h"
4242
#include "dfcc_spec_functions.h"
4343
#include "dfcc_swap_and_wrap.h"
44-
#include "dfcc_utils.h"
4544

4645
#include <map>
4746
#include <set>
@@ -217,7 +216,6 @@ class dfcct
217216

218217
// Singletons that hold the global state of the program transformation
219218
// (caches etc.)
220-
dfcc_utilst utils;
221219
dfcc_libraryt library;
222220
namespacet ns;
223221
dfcc_spec_functionst spec_functions;

src/goto-instrument/contracts/dynamic-frames/dfcc_cfg_info.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,8 @@ static dfcc_loop_infot gen_dfcc_loop_info(
436436
dirtyt &dirty,
437437
local_may_aliast &local_may_alias,
438438
message_handlert &message_handler,
439-
dfcc_utilst &utils,
440439
dfcc_libraryt &library,
441-
symbol_tablet &symbol_table)
440+
symbol_table_baset &symbol_table)
442441
{
443442
std::unordered_set<irep_idt> loop_locals =
444443
gen_loop_locals_set(loop_nesting_graph, loop_id);
@@ -472,7 +471,8 @@ static dfcc_loop_infot gen_dfcc_loop_info(
472471

473472
auto &loop = loop_nesting_graph[loop_id];
474473
const auto cbmc_loop_number = loop.latch->loop_number;
475-
const auto &language_mode = utils.get_function_symbol(function_id).mode;
474+
const auto &language_mode =
475+
dfcc_utilst::get_function_symbol(symbol_table, function_id).mode;
476476

477477
// Generate "write set" variable
478478
const auto &write_set_var =
@@ -515,9 +515,8 @@ dfcc_cfg_infot::dfcc_cfg_infot(
515515
goto_functiont &goto_function,
516516
const exprt &top_level_write_set,
517517
const dfcc_loop_contract_modet loop_contract_mode,
518-
symbol_tablet &symbol_table,
518+
symbol_table_baset &symbol_table,
519519
message_handlert &message_handler,
520-
dfcc_utilst &utils,
521520
dfcc_libraryt &library)
522521
: function_id(function_id),
523522
goto_function(goto_function),
@@ -581,7 +580,6 @@ dfcc_cfg_infot::dfcc_cfg_infot(
581580
dirty,
582581
local_may_alias,
583582
message_handler,
584-
utils,
585583
library,
586584
symbol_table)});
587585

src/goto-instrument/contracts/dynamic-frames/dfcc_cfg_info.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Date: March 2023
2929
#include <set>
3030
#include <unordered_set>
3131

32-
class dfcc_utilst;
3332
class dfcc_libraryt;
3433
class goto_functiont;
3534
class message_handlert;
@@ -240,9 +239,8 @@ class dfcc_cfg_infot
240239
goto_functiont &goto_function,
241240
const exprt &top_level_write_set,
242241
const dfcc_loop_contract_modet loop_contract_mode,
243-
symbol_tablet &symbol_table,
242+
symbol_table_baset &symbol_table,
244243
message_handlert &message_handler,
245-
dfcc_utilst &utils,
246244
dfcc_libraryt &library);
247245

248246
void output(std::ostream &out) const;

src/goto-instrument/contracts/dynamic-frames/dfcc_contract_clauses_codegen.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ Date: February 2023
3030
dfcc_contract_clauses_codegent::dfcc_contract_clauses_codegent(
3131
goto_modelt &goto_model,
3232
message_handlert &message_handler,
33-
dfcc_utilst &utils,
3433
dfcc_libraryt &library)
3534
: goto_model(goto_model),
3635
message_handler(message_handler),
3736
log(message_handler),
38-
utils(utils),
3937
library(library),
4038
ns(goto_model.symbol_table)
4139
{
@@ -233,7 +231,9 @@ void dfcc_contract_clauses_codegent::encode_freeable_target(
233231
{
234232
// A plain `target` becomes `CALL __CPROVER_freeable(target);`
235233
code_function_callt code_function_call(
236-
utils.get_function_symbol(CPROVER_PREFIX "freeable").symbol_expr());
234+
dfcc_utilst::get_function_symbol(
235+
goto_model.symbol_table, CPROVER_PREFIX "freeable")
236+
.symbol_expr());
237237
auto &arguments = code_function_call.arguments();
238238
arguments.emplace_back(target);
239239

@@ -258,12 +258,14 @@ void dfcc_contract_clauses_codegent::inline_and_check_warnings(
258258
std::set<irep_idt> recursive_call;
259259
std::set<irep_idt> not_enough_arguments;
260260

261-
utils.inline_program(
261+
dfcc_utilst::inline_program(
262+
goto_model,
262263
goto_program,
263264
no_body,
264265
recursive_call,
265266
missing_function,
266-
not_enough_arguments);
267+
not_enough_arguments,
268+
message_handler);
267269

268270
// check that the only no body / missing functions are the cprover builtins
269271
for(const auto &id : no_body)

src/goto-instrument/contracts/dynamic-frames/dfcc_contract_clauses_codegen.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Date: February 2023
2828
class goto_modelt;
2929
class message_handlert;
3030
class dfcc_libraryt;
31-
class dfcc_utilst;
3231
class code_with_contract_typet;
3332
class conditional_target_group_exprt;
3433

@@ -39,12 +38,10 @@ class dfcc_contract_clauses_codegent
3938
public:
4039
/// \param goto_model GOTO model being transformed
4140
/// \param message_handler Used debug/warning/error messages
42-
/// \param utils Utility class for dynamic frames
4341
/// \param library The contracts instrumentation library
4442
dfcc_contract_clauses_codegent(
4543
goto_modelt &goto_model,
4644
message_handlert &message_handler,
47-
dfcc_utilst &utils,
4845
dfcc_libraryt &library);
4946

5047
/// \brief Generates instructions encoding the \p assigns_clause targets and
@@ -81,7 +78,6 @@ class dfcc_contract_clauses_codegent
8178
goto_modelt &goto_model;
8279
message_handlert &message_handler;
8380
messaget log;
84-
dfcc_utilst &utils;
8581
dfcc_libraryt &library;
8682
namespacet ns;
8783

src/goto-instrument/contracts/dynamic-frames/dfcc_contract_functions.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ Date: August 2022
2626
#include "dfcc_instrument.h"
2727
#include "dfcc_library.h"
2828
#include "dfcc_spec_functions.h"
29-
#include "dfcc_utils.h"
3029

3130
dfcc_contract_functionst::dfcc_contract_functionst(
3231
const symbolt &pure_contract_symbol,
3332
goto_modelt &goto_model,
3433
message_handlert &message_handler,
35-
dfcc_utilst &utils,
3634
dfcc_libraryt &library,
3735
dfcc_spec_functionst &spec_functions,
3836
dfcc_contract_clauses_codegent &contract_clauses_codegen,
@@ -48,7 +46,6 @@ dfcc_contract_functionst::dfcc_contract_functionst(
4846
goto_model(goto_model),
4947
message_handler(message_handler),
5048
log(message_handler),
51-
utils(utils),
5249
library(library),
5350
spec_functions(spec_functions),
5451
contract_clauses_codegen(contract_clauses_codegen),
@@ -122,8 +119,11 @@ const std::size_t dfcc_contract_functionst::get_nof_frees_targets() const
122119

123120
void dfcc_contract_functionst::gen_spec_assigns_function()
124121
{
125-
const auto &spec_function_symbol = utils.clone_and_rename_function(
126-
pure_contract_symbol.name, spec_assigns_function_id, empty_typet());
122+
const auto &spec_function_symbol = dfcc_utilst::clone_and_rename_function(
123+
goto_model,
124+
pure_contract_symbol.name,
125+
spec_assigns_function_id,
126+
empty_typet());
127127

128128
const auto &spec_function_id = spec_function_symbol.name;
129129

@@ -171,8 +171,11 @@ void dfcc_contract_functionst::gen_spec_frees_function()
171171
const auto &code_with_contract =
172172
to_code_with_contract_type(pure_contract_symbol.type);
173173

174-
auto &spec_function_symbol = utils.clone_and_rename_function(
175-
pure_contract_symbol.name, spec_frees_function_id, empty_typet());
174+
auto &spec_function_symbol = dfcc_utilst::clone_and_rename_function(
175+
goto_model,
176+
pure_contract_symbol.name,
177+
spec_frees_function_id,
178+
empty_typet());
176179

177180
const auto &spec_function_id = spec_function_symbol.name;
178181

src/goto-instrument/contracts/dynamic-frames/dfcc_contract_functions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Date: August 2022
2828
class goto_modelt;
2929
class message_handlert;
3030
class dfcc_libraryt;
31-
class dfcc_utilst;
3231
class dfcc_instrumentt;
3332
class dfcc_spec_functionst;
3433
class dfcc_contract_clauses_codegent;
@@ -68,7 +67,6 @@ class dfcc_contract_functionst
6867
/// \param pure_contract_symbol the contract to generate code from
6968
/// \param goto_model goto model being transformed
7069
/// \param message_handler used debug/warning/error messages
71-
/// \param utils utility class for dynamic frames
7270
/// \param library the contracts instrumentation library
7371
/// \param spec_functions provides translation methods for assignable set
7472
/// \param contract_clauses_codegen provides GOTO code generation methods
@@ -78,7 +76,6 @@ class dfcc_contract_functionst
7876
const symbolt &pure_contract_symbol,
7977
goto_modelt &goto_model,
8078
message_handlert &message_handler,
81-
dfcc_utilst &utils,
8279
dfcc_libraryt &library,
8380
dfcc_spec_functionst &spec_functions,
8481
dfcc_contract_clauses_codegent &contract_clauses_codegen,
@@ -126,7 +123,6 @@ class dfcc_contract_functionst
126123
goto_modelt &goto_model;
127124
message_handlert &message_handler;
128125
messaget log;
129-
dfcc_utilst &utils;
130126
dfcc_libraryt &library;
131127
dfcc_spec_functionst &spec_functions;
132128
dfcc_contract_clauses_codegent &contract_clauses_codegen;

src/goto-instrument/contracts/dynamic-frames/dfcc_contract_handler.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Date: August 2022
3030
#include "dfcc_instrument.h"
3131
#include "dfcc_library.h"
3232
#include "dfcc_spec_functions.h"
33-
#include "dfcc_utils.h"
3433
#include "dfcc_wrapper_program.h"
3534

3635
std::map<irep_idt, dfcc_contract_functionst>
@@ -39,7 +38,6 @@ std::map<irep_idt, dfcc_contract_functionst>
3938
dfcc_contract_handlert::dfcc_contract_handlert(
4039
goto_modelt &goto_model,
4140
message_handlert &message_handler,
42-
dfcc_utilst &utils,
4341
dfcc_libraryt &library,
4442
dfcc_instrumentt &instrument,
4543
dfcc_lift_memory_predicatest &memory_predicates,
@@ -48,7 +46,6 @@ dfcc_contract_handlert::dfcc_contract_handlert(
4846
: goto_model(goto_model),
4947
message_handler(message_handler),
5048
log(message_handler),
51-
utils(utils),
5249
library(library),
5350
instrument(instrument),
5451
memory_predicates(memory_predicates),
@@ -75,7 +72,6 @@ dfcc_contract_handlert::get_contract_functions(const irep_idt &contract_id)
7572
get_pure_contract_symbol(contract_id),
7673
goto_model,
7774
message_handler,
78-
utils,
7975
library,
8076
spec_functions,
8177
contract_clauses_codegen,
@@ -100,13 +96,12 @@ void dfcc_contract_handlert::add_contract_instructions(
10096
{
10197
dfcc_wrapper_programt(
10298
contract_mode,
103-
utils.get_function_symbol(wrapper_id),
104-
utils.get_function_symbol(wrapped_id),
99+
dfcc_utilst::get_function_symbol(goto_model.symbol_table, wrapper_id),
100+
dfcc_utilst::get_function_symbol(goto_model.symbol_table, wrapped_id),
105101
get_contract_functions(contract_id),
106102
wrapper_write_set_symbol,
107103
goto_model,
108104
message_handler,
109-
utils,
110105
library,
111106
instrument,
112107
memory_predicates)
@@ -124,7 +119,8 @@ const symbolt &dfcc_contract_handlert::get_pure_contract_symbol(
124119
if(function_id_opt.has_value())
125120
{
126121
auto function_id = function_id_opt.value();
127-
const auto &function_symbol = utils.get_function_symbol(function_id);
122+
const auto &function_symbol =
123+
dfcc_utilst::get_function_symbol(goto_model.symbol_table, function_id);
128124
check_signature_compat(
129125
function_id,
130126
to_code_type(function_symbol.type),
@@ -145,7 +141,8 @@ const symbolt &dfcc_contract_handlert::get_pure_contract_symbol(
145141
"to derive a default contract");
146142

147143
auto function_id = function_id_opt.value();
148-
const auto &function_symbol = utils.get_function_symbol(function_id);
144+
const auto &function_symbol =
145+
dfcc_utilst::get_function_symbol(goto_model.symbol_table, function_id);
149146

150147
log.warning() << "Contract '" << contract_id
151148
<< "' not found, deriving empty pure contract '"

src/goto-instrument/contracts/dynamic-frames/dfcc_contract_handler.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Date: August 2022
2727
class goto_modelt;
2828
class message_handlert;
2929
class dfcc_libraryt;
30-
class dfcc_utilst;
3130
class dfcc_instrumentt;
3231
class dfcc_lift_memory_predicatest;
3332
class dfcc_spec_functionst;
@@ -69,7 +68,6 @@ class dfcc_contract_handlert
6968
dfcc_contract_handlert(
7069
goto_modelt &goto_model,
7170
message_handlert &message_handler,
72-
dfcc_utilst &utils,
7371
dfcc_libraryt &library,
7472
dfcc_instrumentt &instrument,
7573
dfcc_lift_memory_predicatest &memory_predicates,
@@ -119,7 +117,6 @@ class dfcc_contract_handlert
119117
goto_modelt &goto_model;
120118
message_handlert &message_handler;
121119
messaget log;
122-
dfcc_utilst &utils;
123120
dfcc_libraryt &library;
124121
dfcc_instrumentt &instrument;
125122
dfcc_lift_memory_predicatest &memory_predicates;

0 commit comments

Comments
 (0)