@@ -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
33
// / \param depth number of pointers followed so far during initialisation
92
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=ns.follow (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
@@ -121,10 +71,10 @@ void symbol_factoryt::gen_nondet_init(
121
71
122
72
code_blockt non_null_inst;
123
73
124
- exprt init_expr = allocate_objects. allocate_automatic_local_object (
125
- non_null_inst, expr, subtype);
74
+ exprt init_expr =
75
+ allocate_objects. allocate_object ( non_null_inst, expr, subtype, lifetime );
126
76
127
- gen_nondet_init (non_null_inst, init_expr, depth + 1 , recursion_set);
77
+ gen_nondet_init (non_null_inst, init_expr, depth + 1 , recursion_set, true );
128
78
129
79
if (depth < object_factory_params.min_null_tree_depth )
130
80
{
@@ -164,12 +114,18 @@ void symbol_factoryt::gen_nondet_init(
164
114
for (const auto &component : struct_type.components ())
165
115
{
166
116
const typet &component_type = component.type ();
117
+
118
+ if (!assign_const && component_type.get_bool (ID_C_constant))
119
+ {
120
+ continue ;
121
+ }
122
+
167
123
const irep_idt name = component.get_name ();
168
124
169
125
member_exprt me (expr, name, component_type);
170
126
me.add_source_location () = loc;
171
127
172
- gen_nondet_init (assignments, me, depth, recursion_set);
128
+ gen_nondet_init (assignments, me, depth, recursion_set, assign_const );
173
129
}
174
130
}
175
131
else if (type.id () == ID_array)
@@ -220,14 +176,17 @@ void symbol_factoryt::gen_nondet_array_init(
220
176
// / \param loc: The location to assign to generated code
221
177
// / \param object_factory_parameters configuration parameters for the object
222
178
// / factory
179
+ // / \param lifetime: Lifetime of the allocated object (AUTOMATIC_LOCAL,
180
+ // / STATIC_GLOBAL, or DYNAMIC)
223
181
// / \return Returns the symbol_exprt for the symbol created
224
182
symbol_exprt c_nondet_symbol_factory (
225
183
code_blockt &init_code,
226
184
symbol_tablet &symbol_table,
227
185
const irep_idt base_name,
228
186
const typet &type,
229
187
const source_locationt &loc,
230
- const c_object_factory_parameterst &object_factory_parameters)
188
+ const c_object_factory_parameterst &object_factory_parameters,
189
+ const lifetimet lifetime)
231
190
{
232
191
irep_idt identifier=id2string (goto_functionst::entry_point ())+
233
192
" ::" +id2string (base_name);
@@ -246,7 +205,8 @@ symbol_exprt c_nondet_symbol_factory(
246
205
bool moving_symbol_failed=symbol_table.move (main_symbol, main_symbol_ptr);
247
206
CHECK_RETURN (!moving_symbol_failed);
248
207
249
- symbol_factoryt state (symbol_table, loc, object_factory_parameters);
208
+ symbol_factoryt state (symbol_table, loc, object_factory_parameters, lifetime);
209
+
250
210
code_blockt assignments;
251
211
state.gen_nondet_init (assignments, main_symbol_expr);
252
212
0 commit comments