@@ -25,79 +25,29 @@ Author: Diffblue Ltd.
25
25
26
26
#include < goto-programs/goto_functions.h>
27
27
28
- class symbol_factoryt
29
- {
30
- symbol_tablet &symbol_table;
31
- const source_locationt &loc;
32
- namespacet ns;
33
- const c_object_factory_parameterst &object_factory_params;
34
-
35
- allocate_objectst allocate_objects;
36
-
37
- typedef std::set<irep_idt> recursion_sett;
38
-
39
- public:
40
- symbol_factoryt (
41
- symbol_tablet &_symbol_table,
42
- const source_locationt &loc,
43
- const c_object_factory_parameterst &object_factory_params)
44
- : symbol_table(_symbol_table),
45
- loc (loc),
46
- ns(_symbol_table),
47
- object_factory_params(object_factory_params),
48
- allocate_objects(ID_C, loc, loc.get_function(), symbol_table)
49
- {}
50
-
51
- void gen_nondet_init (
52
- code_blockt &assignments,
53
- const exprt &expr,
54
- const std::size_t depth = 0 ,
55
- recursion_sett recursion_set = recursion_sett());
56
-
57
- void add_created_symbol (const symbolt *symbol_ptr)
58
- {
59
- allocate_objects.add_created_symbol (symbol_ptr);
60
- }
61
-
62
- void declare_created_symbols (code_blockt &init_code)
63
- {
64
- allocate_objects.declare_created_symbols (init_code);
65
- }
66
-
67
- void mark_created_symbols_as_input (code_blockt &init_code)
68
- {
69
- allocate_objects.mark_created_symbols_as_input (init_code);
70
- }
71
-
72
- private:
73
- // / Generate initialisation code for each array element
74
- // / \param assignments: The code block to add code to
75
- // / \param expr: An expression of array type
76
- // / \param depth: The struct recursion depth
77
- // / \param recursion_set: The struct recursion set
78
- // / \see gen_nondet_init For the meaning of the last 2 parameters
79
- void gen_nondet_array_init (
80
- code_blockt &assignments,
81
- const exprt &expr,
82
- std::size_t depth,
83
- const recursion_sett &recursion_set);
84
- };
85
-
86
28
// / Creates a nondet for expr, including calling itself recursively to make
87
29
// / appropriate symbols to point to if expr is a pointer.
88
30
// / \param assignments: The code block to add code to
89
31
// / \param expr: The expression which we are generating a non-determinate value
90
32
// / for
91
- // / \param depth: number of pointers followed so far during initialisation
92
- // / \param recursion_set: names of structs seen so far on current pointer chain
33
+ // / \param depth number of pointers followed so far during initialisation
34
+ // / \param recursion_set names of structs seen so far on current pointer chain
35
+ // / \param assign_const Indicates whether const objects should be nondet
36
+ // / initialized
93
37
void symbol_factoryt::gen_nondet_init (
94
38
code_blockt &assignments,
95
39
const exprt &expr,
96
40
const std::size_t depth,
97
- recursion_sett recursion_set)
41
+ recursion_sett recursion_set,
42
+ const bool assign_const)
98
43
{
99
44
const typet &type = expr.type ();
100
45
46
+ if (!assign_const && expr.type ().get_bool (ID_C_constant))
47
+ {
48
+ return ;
49
+ }
50
+
101
51
if (type.id ()==ID_pointer)
102
52
{
103
53
// dereferenced type
@@ -120,10 +70,10 @@ void symbol_factoryt::gen_nondet_init(
120
70
121
71
code_blockt non_null_inst;
122
72
123
- exprt init_expr = allocate_objects. allocate_automatic_local_object (
124
- non_null_inst, expr, subtype);
73
+ exprt init_expr =
74
+ allocate_objects. allocate_object ( non_null_inst, expr, subtype, lifetime );
125
75
126
- gen_nondet_init (non_null_inst, init_expr, depth + 1 , recursion_set);
76
+ gen_nondet_init (non_null_inst, init_expr, depth + 1 , recursion_set, true );
127
77
128
78
if (depth < object_factory_params.min_null_tree_depth )
129
79
{
@@ -165,12 +115,18 @@ void symbol_factoryt::gen_nondet_init(
165
115
for (const auto &component : struct_type.components ())
166
116
{
167
117
const typet &component_type = component.type ();
118
+
119
+ if (!assign_const && component_type.get_bool (ID_C_constant))
120
+ {
121
+ continue ;
122
+ }
123
+
168
124
const irep_idt name = component.get_name ();
169
125
170
126
member_exprt me (expr, name, component_type);
171
127
me.add_source_location () = loc;
172
128
173
- gen_nondet_init (assignments, me, depth, recursion_set);
129
+ gen_nondet_init (assignments, me, depth, recursion_set, assign_const );
174
130
}
175
131
}
176
132
else if (type.id () == ID_array)
@@ -221,14 +177,17 @@ void symbol_factoryt::gen_nondet_array_init(
221
177
// / \param loc: The location to assign to generated code
222
178
// / \param object_factory_parameters: configuration parameters for the object
223
179
// / factory
180
+ // / \param lifetime: Lifetime of the allocated object (AUTOMATIC_LOCAL,
181
+ // / STATIC_GLOBAL, or DYNAMIC)
224
182
// / \return Returns the symbol_exprt for the symbol created
225
183
symbol_exprt c_nondet_symbol_factory (
226
184
code_blockt &init_code,
227
185
symbol_tablet &symbol_table,
228
186
const irep_idt base_name,
229
187
const typet &type,
230
188
const source_locationt &loc,
231
- const c_object_factory_parameterst &object_factory_parameters)
189
+ const c_object_factory_parameterst &object_factory_parameters,
190
+ const lifetimet lifetime)
232
191
{
233
192
irep_idt identifier=id2string (goto_functionst::entry_point ())+
234
193
" ::" +id2string (base_name);
@@ -247,7 +206,8 @@ symbol_exprt c_nondet_symbol_factory(
247
206
bool moving_symbol_failed=symbol_table.move (main_symbol, main_symbol_ptr);
248
207
CHECK_RETURN (!moving_symbol_failed);
249
208
250
- symbol_factoryt state (symbol_table, loc, object_factory_parameters);
209
+ symbol_factoryt state (symbol_table, loc, object_factory_parameters, lifetime);
210
+
251
211
code_blockt assignments;
252
212
state.gen_nondet_init (assignments, main_symbol_expr);
253
213
0 commit comments