Skip to content

Commit 8e2033a

Browse files
committed
Make all methods of dfcc_utilst static
This class has no state, there is no need to instantiate it.
1 parent bb72e44 commit 8e2033a

22 files changed

+392
-360
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,22 +185,19 @@ dfcct::dfcct(
185185
to_exclude_from_nondet_static(to_exclude_from_nondet_static),
186186
message_handler(message_handler),
187187
log(message_handler),
188-
utils(goto_model, message_handler),
189-
library(goto_model, utils, message_handler),
188+
library(goto_model, message_handler),
190189
ns(goto_model.symbol_table),
191-
instrument(goto_model, message_handler, utils, library),
192-
memory_predicates(goto_model, utils, library, instrument, message_handler),
193-
spec_functions(goto_model, message_handler, utils, library, instrument),
190+
instrument(goto_model, message_handler, library),
191+
memory_predicates(goto_model, library, instrument, message_handler),
192+
spec_functions(goto_model, message_handler, library, instrument),
194193
contract_clauses_codegen(
195194
goto_model,
196195
message_handler,
197-
utils,
198196
library,
199197
spec_functions),
200198
contract_handler(
201199
goto_model,
202200
message_handler,
203-
utils,
204201
library,
205202
instrument,
206203
memory_predicates,
@@ -209,7 +206,6 @@ dfcct::dfcct(
209206
swap_and_wrap(
210207
goto_model,
211208
message_handler,
212-
utils,
213209
library,
214210
instrument,
215211
spec_functions,
@@ -223,15 +219,15 @@ void dfcct::check_transform_goto_model_preconditions()
223219
{
224220
// check that harness function exists
225221
PRECONDITION_WITH_DIAGNOSTICS(
226-
utils.function_symbol_with_body_exists(harness_id),
222+
dfcc_utilst::function_symbol_with_body_exists(goto_model, harness_id),
227223
"Harness function '" + id2string(harness_id) +
228224
"' either not found or has no body");
229225

230226
if(to_check.has_value())
231227
{
232228
auto pair = to_check.value();
233229
PRECONDITION_WITH_DIAGNOSTICS(
234-
utils.function_symbol_with_body_exists(pair.first),
230+
dfcc_utilst::function_symbol_with_body_exists(goto_model, pair.first),
235231
"Function to check '" + id2string(pair.first) +
236232
"' either not found or has no body");
237233

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

270266
// triggers signature compatibility checking
@@ -449,7 +445,7 @@ void dfcct::wrap_discovered_function_pointer_contracts()
449445
{
450446
// we need to swap it with itself
451447
PRECONDITION_WITH_DIAGNOSTICS(
452-
utils.function_symbol_exists(str),
448+
dfcc_utilst::function_symbol_exists(goto_model, str),
453449
"Function pointer contract '" + str + "' not found.");
454450

455451
// triggers signature compatibility checking
@@ -559,7 +555,7 @@ void dfcct::reinitialize_model()
559555
goto_model.symbol_table.symbols.find(goto_functionst::entry_point()));
560556
// regenerate the CPROVER start function
561557
generate_ansi_c_start_function(
562-
utils.get_function_symbol(harness_id),
558+
dfcc_utilst::get_function_symbol(goto_model.symbol_table, harness_id),
563559
goto_model.symbol_table,
564560
message_handler,
565561
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
@@ -40,7 +40,6 @@ Author: Remi Delmas, [email protected]
4040
#include "dfcc_lift_memory_predicates.h"
4141
#include "dfcc_spec_functions.h"
4242
#include "dfcc_swap_and_wrap.h"
43-
#include "dfcc_utils.h"
4443

4544
#include <map>
4645
#include <set>
@@ -212,7 +211,6 @@ class dfcct
212211

213212
// Singletons that hold the global state of the program transformation
214213
// (caches etc.)
215-
dfcc_utilst utils;
216214
dfcc_libraryt library;
217215
namespacet ns;
218216
dfcc_instrumentt instrument;

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
@@ -29,13 +29,11 @@ Date: February 2023
2929
dfcc_contract_clauses_codegent::dfcc_contract_clauses_codegent(
3030
goto_modelt &goto_model,
3131
message_handlert &message_handler,
32-
dfcc_utilst &utils,
3332
dfcc_libraryt &library,
3433
dfcc_spec_functionst &spec_functions)
3534
: goto_model(goto_model),
3635
message_handler(message_handler),
3736
log(message_handler),
38-
utils(utils),
3937
library(library),
4038
spec_functions(spec_functions),
4139
ns(goto_model.symbol_table)
@@ -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 & 3 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 dfcc_spec_functionst;
3332
class code_with_contract_typet;
3433
class conditional_target_group_exprt;
@@ -45,7 +44,6 @@ class dfcc_contract_clauses_codegent
4544
dfcc_contract_clauses_codegent(
4645
goto_modelt &goto_model,
4746
message_handlert &message_handler,
48-
dfcc_utilst &utils,
4947
dfcc_libraryt &library,
5048
dfcc_spec_functionst &spec_functions);
5149

@@ -83,7 +81,6 @@ class dfcc_contract_clauses_codegent
8381
goto_modelt &goto_model;
8482
message_handlert &message_handler;
8583
messaget log;
86-
dfcc_utilst &utils;
8784
dfcc_libraryt &library;
8885
dfcc_spec_functionst &spec_functions;
8986
namespacet ns;

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ Date: August 2022
2525
#include "dfcc_contract_clauses_codegen.h"
2626
#include "dfcc_library.h"
2727
#include "dfcc_spec_functions.h"
28-
#include "dfcc_utils.h"
2928

3029
dfcc_contract_functionst::dfcc_contract_functionst(
3130
const symbolt &pure_contract_symbol,
3231
goto_modelt &goto_model,
3332
message_handlert &message_handler,
34-
dfcc_utilst &utils,
3533
dfcc_libraryt &library,
3634
dfcc_spec_functionst &spec_functions,
3735
dfcc_contract_clauses_codegent &contract_clauses_codegen)
@@ -46,7 +44,6 @@ dfcc_contract_functionst::dfcc_contract_functionst(
4644
goto_model(goto_model),
4745
message_handler(message_handler),
4846
log(message_handler),
49-
utils(utils),
5047
library(library),
5148
spec_functions(spec_functions),
5249
contract_clauses_codegen(contract_clauses_codegen),
@@ -97,8 +94,11 @@ const std::size_t dfcc_contract_functionst::get_nof_frees_targets() const
9794

9895
void dfcc_contract_functionst::gen_spec_assigns_function()
9996
{
100-
const auto &spec_function_symbol = utils.clone_and_rename_function(
101-
pure_contract_symbol.name, spec_assigns_function_id, empty_typet());
97+
const auto &spec_function_symbol = dfcc_utilst::clone_and_rename_function(
98+
goto_model,
99+
pure_contract_symbol.name,
100+
spec_assigns_function_id,
101+
empty_typet());
102102

103103
const auto &spec_function_id = spec_function_symbol.name;
104104

@@ -146,8 +146,11 @@ void dfcc_contract_functionst::gen_spec_frees_function()
146146
const auto &code_with_contract =
147147
to_code_with_contract_type(pure_contract_symbol.type);
148148

149-
auto &spec_function_symbol = utils.clone_and_rename_function(
150-
pure_contract_symbol.name, spec_frees_function_id, empty_typet());
149+
auto &spec_function_symbol = dfcc_utilst::clone_and_rename_function(
150+
goto_model,
151+
pure_contract_symbol.name,
152+
spec_frees_function_id,
153+
empty_typet());
151154

152155
const auto &spec_function_id = spec_function_symbol.name;
153156

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

Lines changed: 0 additions & 3 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_spec_functionst;
3332
class dfcc_contract_clauses_codegent;
3433
class code_with_contract_typet;
@@ -74,7 +73,6 @@ class dfcc_contract_functionst
7473
const symbolt &pure_contract_symbol,
7574
goto_modelt &goto_model,
7675
message_handlert &message_handler,
77-
dfcc_utilst &utils,
7876
dfcc_libraryt &library,
7977
dfcc_spec_functionst &spec_functions,
8078
dfcc_contract_clauses_codegent &contract_clauses_codegen);
@@ -116,7 +114,6 @@ class dfcc_contract_functionst
116114
goto_modelt &goto_model;
117115
message_handlert &message_handler;
118116
messaget log;
119-
dfcc_utilst &utils;
120117
dfcc_libraryt &library;
121118
dfcc_spec_functionst &spec_functions;
122119
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
@@ -31,7 +31,6 @@ Date: August 2022
3131
#include "dfcc_instrument.h"
3232
#include "dfcc_library.h"
3333
#include "dfcc_spec_functions.h"
34-
#include "dfcc_utils.h"
3534
#include "dfcc_wrapper_program.h"
3635

3736
std::map<irep_idt, dfcc_contract_functionst>
@@ -40,7 +39,6 @@ std::map<irep_idt, dfcc_contract_functionst>
4039
dfcc_contract_handlert::dfcc_contract_handlert(
4140
goto_modelt &goto_model,
4241
message_handlert &message_handler,
43-
dfcc_utilst &utils,
4442
dfcc_libraryt &library,
4543
dfcc_instrumentt &instrument,
4644
dfcc_lift_memory_predicatest &memory_predicates,
@@ -49,7 +47,6 @@ dfcc_contract_handlert::dfcc_contract_handlert(
4947
: goto_model(goto_model),
5048
message_handler(message_handler),
5149
log(message_handler),
52-
utils(utils),
5350
library(library),
5451
instrument(instrument),
5552
memory_predicates(memory_predicates),
@@ -76,7 +73,6 @@ dfcc_contract_handlert::get_contract_functions(const irep_idt &contract_id)
7673
get_pure_contract_symbol(contract_id),
7774
goto_model,
7875
message_handler,
79-
utils,
8076
library,
8177
spec_functions,
8278
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)