Skip to content

Commit 97259cc

Browse files
committed
Pass object factory parameters through to object factories
1 parent 62ca8cf commit 97259cc

11 files changed

+72
-33
lines changed

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ Author: Daniel Kroening, [email protected]
2222
exprt::operandst build_function_environment(
2323
const code_typet::parameterst &parameters,
2424
code_blockt &init_code,
25-
symbol_tablet &symbol_table)
25+
symbol_tablet &symbol_table,
26+
const c_object_factory_parameterst &object_factory_parameters)
2627
{
2728
exprt::operandst main_arguments;
2829
main_arguments.resize(parameters.size());
@@ -35,14 +36,14 @@ exprt::operandst build_function_environment(
3536
const irep_idt base_name=p.get_base_name().empty()?
3637
("argument#"+std::to_string(param_number)):p.get_base_name();
3738

38-
main_arguments[param_number]=
39-
c_nondet_symbol_factory(
40-
init_code,
41-
symbol_table,
42-
base_name,
43-
p.type(),
44-
p.source_location(),
45-
true);
39+
main_arguments[param_number] = c_nondet_symbol_factory(
40+
init_code,
41+
symbol_table,
42+
base_name,
43+
p.type(),
44+
p.source_location(),
45+
true,
46+
object_factory_parameters);
4647
}
4748

4849
return main_arguments;
@@ -111,7 +112,8 @@ void record_function_outputs(
111112

112113
bool ansi_c_entry_point(
113114
symbol_tablet &symbol_table,
114-
message_handlert &message_handler)
115+
message_handlert &message_handler,
116+
const c_object_factory_parameterst &object_factory_parameters)
115117
{
116118
// check if entry point is already there
117119
if(symbol_table.symbols.find(goto_functionst::entry_point())!=
@@ -179,21 +181,24 @@ bool ansi_c_entry_point(
179181

180182
static_lifetime_init(symbol_table, symbol.location);
181183

182-
return generate_ansi_c_start_function(symbol, symbol_table, message_handler);
184+
return generate_ansi_c_start_function(
185+
symbol, symbol_table, message_handler, object_factory_parameters);
183186
}
184187

185-
186188
/// Generate a _start function for a specific function
187189
/// \param symbol: The symbol for the function that should be
188190
/// used as the entry point
189191
/// \param symbol_table: The symbol table for the program. The new _start
190192
/// function symbol will be added to this table
191193
/// \param message_handler: The message handler
194+
/// \param object_factory_parameters configuration parameters for the object
195+
/// factory
192196
/// \return Returns false if the _start method was generated correctly
193197
bool generate_ansi_c_start_function(
194198
const symbolt &symbol,
195199
symbol_tablet &symbol_table,
196-
message_handlert &message_handler)
200+
message_handlert &message_handler,
201+
const c_object_factory_parameterst &object_factory_parameters)
197202
{
198203
PRECONDITION(!symbol.value.is_nil());
199204
code_blockt init_code;
@@ -423,11 +428,8 @@ bool generate_ansi_c_start_function(
423428
else
424429
{
425430
// produce nondet arguments
426-
call_main.arguments()=
427-
build_function_environment(
428-
parameters,
429-
init_code,
430-
symbol_table);
431+
call_main.arguments() = build_function_environment(
432+
parameters, init_code, symbol_table, object_factory_parameters);
431433
}
432434

433435
init_code.add(std::move(call_main));

src/ansi-c/ansi_c_entry_point.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ Author: Daniel Kroening, [email protected]
1010
#ifndef CPROVER_ANSI_C_ANSI_C_ENTRY_POINT_H
1111
#define CPROVER_ANSI_C_ANSI_C_ENTRY_POINT_H
1212

13-
#include <util/symbol_table.h>
13+
#include <ansi-c/c_object_factory_parameters.h>
1414
#include <util/message.h>
15+
#include <util/symbol_table.h>
1516

1617
bool ansi_c_entry_point(
1718
symbol_tablet &symbol_table,
18-
message_handlert &message_handler);
19+
message_handlert &message_handler,
20+
const c_object_factory_parameterst &object_factory_parameters);
1921

2022
bool generate_ansi_c_start_function(
2123
const symbolt &symbol,
2224
symbol_tablet &symbol_table,
23-
message_handlert &message_handler);
25+
message_handlert &message_handler,
26+
const c_object_factory_parameterst &object_factory_parameters);
2427

2528
#endif // CPROVER_ANSI_C_ANSI_C_ENTRY_POINT_H

src/ansi-c/ansi_c_language.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ bool ansi_c_languaget::generate_support_functions(
137137
// function body parsing, or else generate-stubs moved to the
138138
// final phase.
139139
generate_opaque_method_stubs(symbol_table);
140+
140141
// This creates __CPROVER_start and __CPROVER_initialize:
141-
return ansi_c_entry_point(symbol_table, get_message_handler());
142+
return ansi_c_entry_point(
143+
symbol_table, get_message_handler(), object_factory_params);
142144
}
143145

144146
void ansi_c_languaget::show_parse(std::ostream &out)

src/ansi-c/ansi_c_language.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717
#include <langapi/language.h>
1818

1919
#include "ansi_c_parse_tree.h"
20+
#include "c_object_factory_parameters.h"
2021

2122
// clang-format off
2223
#define OPT_ANSI_C_LANGUAGE \
@@ -33,6 +34,11 @@ Author: Daniel Kroening, [email protected]
3334
class ansi_c_languaget:public languaget
3435
{
3536
public:
37+
void set_language_options(const optionst &options) override
38+
{
39+
object_factory_params.set(options);
40+
}
41+
3642
bool preprocess(
3743
std::istream &instream,
3844
const std::string &path,
@@ -87,6 +93,8 @@ class ansi_c_languaget:public languaget
8793
protected:
8894
ansi_c_parse_treet parse_tree;
8995
std::string parse_path;
96+
97+
c_object_factory_parameterst object_factory_params;
9098
};
9199

92100
std::unique_ptr<languaget> new_ansi_c_language();

src/ansi-c/c_nondet_symbol_factory.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@ class symbol_factoryt
2929
const source_locationt &loc;
3030
const bool assume_non_null;
3131
namespacet ns;
32+
const c_object_factory_parameterst &object_factory_params;
3233

3334
public:
3435
symbol_factoryt(
3536
std::vector<const symbolt *> &_symbols_created,
3637
symbol_tablet &_symbol_table,
3738
const source_locationt &loc,
38-
const bool _assume_non_null):
39-
symbols_created(_symbols_created),
39+
const bool _assume_non_null,
40+
const c_object_factory_parameterst &object_factory_params)
41+
: symbols_created(_symbols_created),
4042
symbol_table(_symbol_table),
4143
loc(loc),
4244
assume_non_null(_assume_non_null),
43-
ns(_symbol_table)
45+
ns(_symbol_table),
46+
object_factory_params(object_factory_params)
4447
{}
4548

4649
exprt allocate_object(
@@ -179,14 +182,17 @@ void symbol_factoryt::gen_nondet_init(
179182
/// \param type: The type for the symbol created
180183
/// \param loc: The location to assign to generated code
181184
/// \param allow_null: Whether to allow a null value when type is a pointer
185+
/// \param object_factory_parameters configuration parameters for the object
186+
/// factory
182187
/// \return Returns the symbol_exprt for the symbol created
183188
symbol_exprt c_nondet_symbol_factory(
184189
code_blockt &init_code,
185190
symbol_tablet &symbol_table,
186191
const irep_idt base_name,
187192
const typet &type,
188193
const source_locationt &loc,
189-
bool allow_null)
194+
bool allow_null,
195+
const c_object_factory_parameterst &object_factory_parameters)
190196
{
191197
irep_idt identifier=id2string(goto_functionst::entry_point())+
192198
"::"+id2string(base_name);
@@ -209,10 +215,7 @@ symbol_exprt c_nondet_symbol_factory(
209215
symbols_created.push_back(main_symbol_ptr);
210216

211217
symbol_factoryt state(
212-
symbols_created,
213-
symbol_table,
214-
loc,
215-
!allow_null);
218+
symbols_created, symbol_table, loc, !allow_null, object_factory_parameters);
216219
code_blockt assignments;
217220
state.gen_nondet_init(assignments, main_symbol_expr);
218221

src/ansi-c/c_nondet_symbol_factory.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Author: Diffblue Ltd.
1212
#ifndef CPROVER_ANSI_C_C_NONDET_SYMBOL_FACTORY_H
1313
#define CPROVER_ANSI_C_C_NONDET_SYMBOL_FACTORY_H
1414

15+
#include "c_object_factory_parameters.h"
16+
1517
#include <util/std_code.h>
1618
#include <util/symbol_table.h>
1719

@@ -21,6 +23,7 @@ symbol_exprt c_nondet_symbol_factory(
2123
const irep_idt base_name,
2224
const typet &type,
2325
const source_locationt &,
24-
bool allow_null);
26+
bool allow_null,
27+
const c_object_factory_parameterst &object_factory_parameters);
2528

2629
#endif // CPROVER_ANSI_C_C_NONDET_SYMBOL_FACTORY_H

src/cpp/cpp_language.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ bool cpp_languaget::typecheck(
137137
bool cpp_languaget::generate_support_functions(
138138
symbol_tablet &symbol_table)
139139
{
140-
return ansi_c_entry_point(symbol_table, get_message_handler());
140+
return ansi_c_entry_point(
141+
symbol_table, get_message_handler(), object_factory_params);
141142
}
142143

143144
void cpp_languaget::show_parse(std::ostream &out)

src/cpp/cpp_language.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <memory>
1616

17+
#include <ansi-c/c_object_factory_parameters.h>
18+
1719
#include <util/make_unique.h> // unique_ptr
1820

1921
#include <langapi/language.h>
@@ -23,6 +25,11 @@ Author: Daniel Kroening, [email protected]
2325
class cpp_languaget:public languaget
2426
{
2527
public:
28+
void set_language_options(const optionst &options) override
29+
{
30+
object_factory_params.set(options);
31+
}
32+
2633
bool preprocess(
2734
std::istream &instream,
2835
const std::string &path,
@@ -88,6 +95,8 @@ class cpp_languaget:public languaget
8895
cpp_parse_treet cpp_parse_tree;
8996
std::string parse_path;
9097

98+
c_object_factory_parameterst object_factory_params;
99+
91100
void show_parse(std::ostream &out, const cpp_itemt &item);
92101

93102
std::string main_symbol()

src/goto-cc/compile.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,12 @@ bool compilet::link()
368368
goto_model.goto_functions.function_map.erase(
369369
goto_functionst::entry_point());
370370

371-
if(ansi_c_entry_point(goto_model.symbol_table, get_message_handler()))
371+
const bool error = ansi_c_entry_point(
372+
goto_model.symbol_table,
373+
get_message_handler(),
374+
c_object_factory_parameterst());
375+
376+
if(error)
372377
return true;
373378

374379
// entry_point may (should) add some more functions.

src/goto-programs/initialize_goto_model.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717
#include <util/cmdline.h>
1818
#include <util/config.h>
1919
#include <util/message.h>
20+
#include <util/object_factory_parameters.h>
2021
#include <util/unicode.h>
2122

2223
#include <langapi/mode.h>

src/langapi/language_file.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include <fstream>
1212

13+
#include <util/object_factory_parameters.h>
14+
1315
#include "language.h"
1416

1517
language_filet::language_filet(const language_filet &rhs):

0 commit comments

Comments
 (0)