Skip to content

Commit 33da430

Browse files
committed
Pass object factory parameters through to object factories
1 parent 48d03c8 commit 33da430

13 files changed

+80
-39
lines changed

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 18 additions & 17 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,7 +181,8 @@ bool ansi_c_entry_point(
179181

180182
static_lifetime_init(symbol_table, symbol.location, message_handler);
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

185188

@@ -193,7 +196,8 @@ bool ansi_c_entry_point(
193196
bool generate_ansi_c_start_function(
194197
const symbolt &symbol,
195198
symbol_tablet &symbol_table,
196-
message_handlert &message_handler)
199+
message_handlert &message_handler,
200+
const c_object_factory_parameterst &object_factory_parameters)
197201
{
198202
PRECONDITION(!symbol.value.is_nil());
199203
code_blockt init_code;
@@ -423,11 +427,8 @@ bool generate_ansi_c_start_function(
423427
else
424428
{
425429
// produce nondet arguments
426-
call_main.arguments()=
427-
build_function_environment(
428-
parameters,
429-
init_code,
430-
symbol_table);
430+
call_main.arguments() = build_function_environment(
431+
parameters, init_code, symbol_table, object_factory_parameters);
431432
}
432433

433434
init_code.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,10 +17,16 @@ 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
class ansi_c_languaget:public languaget
2223
{
2324
public:
25+
void set_language_options(const optionst &options)
26+
{
27+
object_factory_params.set(options);
28+
}
29+
2430
bool preprocess(
2531
std::istream &instream,
2632
const std::string &path,
@@ -75,6 +81,8 @@ class ansi_c_languaget:public languaget
7581
protected:
7682
ansi_c_parse_treet parse_tree;
7783
std::string parse_path;
84+
85+
c_object_factory_parameterst object_factory_params;
7886
};
7987

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

src/ansi-c/c_nondet_symbol_factory.cpp

Lines changed: 9 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(
@@ -186,7 +189,8 @@ exprt c_nondet_symbol_factory(
186189
const irep_idt base_name,
187190
const typet &type,
188191
const source_locationt &loc,
189-
bool allow_null)
192+
bool allow_null,
193+
const c_object_factory_parameterst &object_factory_parameters)
190194
{
191195
irep_idt identifier=id2string(goto_functionst::entry_point())+
192196
"::"+id2string(base_name);
@@ -209,10 +213,7 @@ exprt c_nondet_symbol_factory(
209213
symbols_created.push_back(main_symbol_ptr);
210214

211215
symbol_factoryt state(
212-
symbols_created,
213-
symbol_table,
214-
loc,
215-
!allow_null);
216+
symbols_created, symbol_table, loc, !allow_null, object_factory_parameters);
216217
code_blockt assignments;
217218
state.gen_nondet_init(assignments, main_symbol_expr);
218219

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 @@ 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)
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/goto-programs/initialize_goto_model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
1616

1717
class cmdlinet;
1818
class message_handlert;
19+
class object_factory_parameterst;
1920
class optionst;
2021

2122
goto_modelt initialize_goto_model(

src/langapi/language.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Author: Daniel Kroening, [email protected]
1717
#include <string>
1818
#include <memory> // unique_ptr
1919

20-
#include <util/symbol.h>
21-
#include <util/std_types.h>
2220
#include <util/message.h>
21+
#include <util/std_types.h>
22+
#include <util/symbol.h>
2323

2424
#include <goto-programs/system_library_symbols.h>
2525

@@ -63,8 +63,7 @@ class languaget:public messaget
6363
/// complete. Functions introduced here are visible to lazy loading and
6464
/// can influence its decisions (e.g. picking the types of input parameters
6565
/// and globals), whereas anything introduced during `final` cannot.
66-
virtual bool generate_support_functions(
67-
symbol_tablet &symbol_table)=0;
66+
virtual bool generate_support_functions(symbol_tablet &symbol_table) = 0;
6867

6968
// add external dependencies of a given module to set
7069

src/langapi/language_file.cpp

Lines changed: 10 additions & 3 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):
@@ -169,14 +171,19 @@ bool language_filest::generate_support_functions(
169171

170172
for(auto &file : file_map)
171173
{
172-
if(languages.insert(file.second.language->id()).second)
173-
if(file.second.language->generate_support_functions(symbol_table))
174+
auto &language = *file.second.language;
175+
176+
if(languages.insert(language.id()).second)
177+
{
178+
bool error = language.generate_support_functions(symbol_table);
179+
180+
if(error)
174181
return true;
182+
}
175183
}
176184

177185
return false;
178186
}
179-
180187
bool language_filest::final(symbol_table_baset &symbol_table)
181188
{
182189
std::set<std::string> languages;

0 commit comments

Comments
 (0)