@@ -25,51 +25,29 @@ Author: Diffblue Ltd.
25
25
26
26
#include < goto-programs/goto_functions.h>
27
27
28
- class symbol_factoryt
29
- {
30
- std::vector<const symbolt *> &symbols_created;
31
- symbol_tablet &symbol_table;
32
- const source_locationt &loc;
33
- namespacet ns;
34
- const c_object_factory_parameterst &object_factory_params;
35
-
36
- typedef std::set<irep_idt> recursion_sett;
37
-
38
- public:
39
- symbol_factoryt (
40
- std::vector<const symbolt *> &_symbols_created,
41
- symbol_tablet &_symbol_table,
42
- const source_locationt &loc,
43
- const c_object_factory_parameterst &object_factory_params)
44
- : symbols_created(_symbols_created),
45
- symbol_table (_symbol_table),
46
- loc(loc),
47
- ns(_symbol_table),
48
- object_factory_params(object_factory_params)
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
-
58
28
// / Creates a nondet for expr, including calling itself recursively to make
59
29
// / appropriate symbols to point to if expr is a pointer.
60
30
// / \param assignments: The code block to add code to
61
31
// / \param expr: The expression which we are generating a non-determinate value
62
32
// / for
63
33
// / \param depth number of pointers followed so far during initialisation
64
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
65
37
void symbol_factoryt::gen_nondet_init (
66
38
code_blockt &assignments,
67
39
const exprt &expr,
68
40
const std::size_t depth,
69
- recursion_sett recursion_set)
41
+ recursion_sett recursion_set,
42
+ const bool assign_const)
70
43
{
71
44
const typet &type=ns.follow (expr.type ());
72
45
46
+ if (!assign_const && expr.type ().get_bool (ID_C_constant))
47
+ {
48
+ return ;
49
+ }
50
+
73
51
if (type.id ()==ID_pointer)
74
52
{
75
53
// dereferenced type
@@ -97,8 +75,8 @@ void symbol_factoryt::gen_nondet_init(
97
75
allocate_objectst allocate_objects (
98
76
ID_C, loc, loc.get_function (), symbol_table);
99
77
100
- exprt allocated = allocate_objects.allocate_non_dynamic_object (
101
- non_null_inst, expr, subtype, false , symbols_created);
78
+ exprt allocated = allocate_objects.allocate_object (
79
+ non_null_inst, expr, subtype, allocation_type , symbols_created);
102
80
103
81
exprt init_expr;
104
82
if (allocated.id ()==ID_address_of)
@@ -109,7 +87,7 @@ void symbol_factoryt::gen_nondet_init(
109
87
{
110
88
init_expr=dereference_exprt (allocated, allocated.type ().subtype ());
111
89
}
112
- gen_nondet_init (non_null_inst, init_expr, depth + 1 , recursion_set);
90
+ gen_nondet_init (non_null_inst, init_expr, depth + 1 , recursion_set, true );
113
91
114
92
if (depth < object_factory_params.min_null_tree_depth )
115
93
{
@@ -149,12 +127,18 @@ void symbol_factoryt::gen_nondet_init(
149
127
for (const auto &component : struct_type.components ())
150
128
{
151
129
const typet &component_type = component.type ();
130
+
131
+ if (!assign_const && component_type.get_bool (ID_C_constant))
132
+ {
133
+ continue ;
134
+ }
135
+
152
136
const irep_idt name = component.get_name ();
153
137
154
138
member_exprt me (expr, name, component_type);
155
139
me.add_source_location () = loc;
156
140
157
- gen_nondet_init (assignments, me, depth, recursion_set);
141
+ gen_nondet_init (assignments, me, depth, recursion_set, assign_const );
158
142
}
159
143
}
160
144
else
@@ -182,14 +166,17 @@ void symbol_factoryt::gen_nondet_init(
182
166
// / \param loc: The location to assign to generated code
183
167
// / \param object_factory_parameters configuration parameters for the object
184
168
// / factory
169
+ // / \param allocation_type Indicates whether the new objects should be allocated
170
+ // / locally, globally, or dynamically
185
171
// / \return Returns the symbol_exprt for the symbol created
186
172
symbol_exprt c_nondet_symbol_factory (
187
173
code_blockt &init_code,
188
174
symbol_tablet &symbol_table,
189
175
const irep_idt base_name,
190
176
const typet &type,
191
177
const source_locationt &loc,
192
- const c_object_factory_parameterst &object_factory_parameters)
178
+ const c_object_factory_parameterst &object_factory_parameters,
179
+ const allocation_typet allocation_type)
193
180
{
194
181
irep_idt identifier=id2string (goto_functionst::entry_point ())+
195
182
" ::" +id2string (base_name);
@@ -212,7 +199,12 @@ symbol_exprt c_nondet_symbol_factory(
212
199
symbols_created.push_back (main_symbol_ptr);
213
200
214
201
symbol_factoryt state (
215
- symbols_created, symbol_table, loc, object_factory_parameters);
202
+ symbols_created,
203
+ symbol_table,
204
+ loc,
205
+ object_factory_parameters,
206
+ allocation_type);
207
+
216
208
code_blockt assignments;
217
209
state.gen_nondet_init (assignments, main_symbol_expr);
218
210
0 commit comments