Skip to content

Commit 961b072

Browse files
committed
Pass object factory parameters through to object factories
1 parent 625cb49 commit 961b072

15 files changed

+89
-42
lines changed

jbmc/src/java_bytecode/java_object_factory_parameters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct java_object_factory_parameterst final : public object_factory_parameterst
1818
}
1919

2020
java_object_factory_parameterst(const optionst &options)
21-
: object_factory_paramterst(options)
21+
: object_factory_parameterst(options)
2222
{
2323
}
2424
};

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,6 +29,7 @@ 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
const symbolt &c_new_tmp_symbol(
3435
//symbol_tablet &symbol_table,
@@ -42,12 +43,14 @@ class symbol_factoryt
4243
std::vector<const symbolt *> &_symbols_created,
4344
symbol_tablet &_symbol_table,
4445
const source_locationt &loc,
45-
const bool _assume_non_null):
46-
symbols_created(_symbols_created),
46+
const bool _assume_non_null,
47+
const c_object_factory_parameterst &object_factory_params)
48+
: symbols_created(_symbols_created),
4749
symbol_table(_symbol_table),
4850
loc(loc),
4951
assume_non_null(_assume_non_null),
50-
ns(_symbol_table)
52+
ns(_symbol_table),
53+
object_factory_params(object_factory_params)
5154
{}
5255

5356
exprt allocate_object(
@@ -210,7 +213,8 @@ exprt c_nondet_symbol_factory(
210213
const irep_idt base_name,
211214
const typet &type,
212215
const source_locationt &loc,
213-
bool allow_null)
216+
bool allow_null,
217+
const c_object_factory_parameterst &object_factory_parameters)
214218
{
215219
irep_idt identifier=id2string(goto_functionst::entry_point())+
216220
"::"+id2string(base_name);
@@ -233,10 +237,7 @@ exprt c_nondet_symbol_factory(
233237
symbols_created.push_back(main_symbol_ptr);
234238

235239
symbol_factoryt state(
236-
symbols_created,
237-
symbol_table,
238-
loc,
239-
!allow_null);
240+
symbols_created, symbol_table, loc, !allow_null, object_factory_parameters);
240241
code_blockt assignments;
241242
state.gen_nondet_init(assignments, main_symbol_expr);
242243

src/ansi-c/c_nondet_symbol_factory.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ Author: Diffblue Ltd.
1515
#include <util/std_code.h>
1616
#include <util/symbol_table.h>
1717

18+
class c_object_factory_parameterst;
19+
1820
exprt c_nondet_symbol_factory(
1921
code_blockt &init_code,
2022
symbol_tablet &symbol_table,
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/goto-programs/rebuild_goto_start_function.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88

99
#include "rebuild_goto_start_function.h"
1010

11+
#include <ansi-c/c_object_factory_parameters.h>
12+
13+
#include <util/cmdline.h>
14+
#include <util/object_factory_parameters.h>
15+
#include <util/prefix.h>
1116
#include <util/symbol.h>
1217
#include <util/symbol_table.h>
13-
#include <util/prefix.h>
14-
#include <util/cmdline.h>
1518

1619
#include <langapi/mode.h>
1720
#include <langapi/language.h>

src/langapi/language.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ 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/object_factory_parameters.h>
22+
#include <util/std_types.h>
23+
#include <util/symbol.h>
2324

2425
#include <goto-programs/system_library_symbols.h>
2526

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

6969
// add external dependencies of a given module to set
7070

src/langapi/language_file.cpp

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

1111
#include <fstream>
1212

13+
#include <ansi-c/c_object_factory_parameters.h>
14+
15+
#include <util/object_factory_parameters.h>
16+
1317
#include "language.h"
1418

1519
language_filet::language_filet(const language_filet &rhs):
@@ -169,14 +173,19 @@ bool language_filest::generate_support_functions(
169173

170174
for(auto &file : file_map)
171175
{
172-
if(languages.insert(file.second.language->id()).second)
173-
if(file.second.language->generate_support_functions(symbol_table))
176+
auto &language = *file.second.language;
177+
178+
if(languages.insert(language.id()).second)
179+
{
180+
bool error = language.generate_support_functions(symbol_table);
181+
182+
if(error)
174183
return true;
184+
}
175185
}
176186

177187
return false;
178188
}
179-
180189
bool language_filest::final(symbol_table_baset &symbol_table)
181190
{
182191
std::set<std::string> languages;

0 commit comments

Comments
 (0)