@@ -25,51 +25,29 @@ Author: Diffblue Ltd.
2525
2626#include < goto-programs/goto_functions.h>
2727
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-
5828// / Creates a nondet for expr, including calling itself recursively to make
5929// / appropriate symbols to point to if expr is a pointer.
6030// / \param assignments: The code block to add code to
6131// / \param expr: The expression which we are generating a non-determinate value
6232// / for
6333// / \param depth number of pointers followed so far during initialisation
6434// / \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
6537void symbol_factoryt::gen_nondet_init (
6638 code_blockt &assignments,
6739 const exprt &expr,
6840 const std::size_t depth,
69- recursion_sett recursion_set)
41+ recursion_sett recursion_set,
42+ const bool assign_const)
7043{
7144 const typet &type=ns.follow (expr.type ());
7245
46+ if (!assign_const && expr.type ().get_bool (ID_C_constant))
47+ {
48+ return ;
49+ }
50+
7351 if (type.id ()==ID_pointer)
7452 {
7553 // dereferenced type
@@ -97,8 +75,8 @@ void symbol_factoryt::gen_nondet_init(
9775 allocate_objectst allocate_objects (
9876 ID_C, loc, loc.get_function (), symbol_table);
9977
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);
10280
10381 exprt init_expr;
10482 if (allocated.id ()==ID_address_of)
@@ -109,7 +87,7 @@ void symbol_factoryt::gen_nondet_init(
10987 {
11088 init_expr=dereference_exprt (allocated, allocated.type ().subtype ());
11189 }
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 );
11391
11492 if (depth < object_factory_params.min_null_tree_depth )
11593 {
@@ -149,12 +127,18 @@ void symbol_factoryt::gen_nondet_init(
149127 for (const auto &component : struct_type.components ())
150128 {
151129 const typet &component_type = component.type ();
130+
131+ if (!assign_const && component_type.get_bool (ID_C_constant))
132+ {
133+ continue ;
134+ }
135+
152136 const irep_idt name = component.get_name ();
153137
154138 member_exprt me (expr, name, component_type);
155139 me.add_source_location () = loc;
156140
157- gen_nondet_init (assignments, me, depth, recursion_set);
141+ gen_nondet_init (assignments, me, depth, recursion_set, assign_const );
158142 }
159143 }
160144 else
@@ -182,14 +166,17 @@ void symbol_factoryt::gen_nondet_init(
182166// / \param loc: The location to assign to generated code
183167// / \param object_factory_parameters configuration parameters for the object
184168// / factory
169+ // / \param allocation_type Indicates whether the new objects should be allocated
170+ // / locally, globally, or dynamically
185171// / \return Returns the symbol_exprt for the symbol created
186172symbol_exprt c_nondet_symbol_factory (
187173 code_blockt &init_code,
188174 symbol_tablet &symbol_table,
189175 const irep_idt base_name,
190176 const typet &type,
191177 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)
193180{
194181 irep_idt identifier=id2string (goto_functionst::entry_point ())+
195182 " ::" +id2string (base_name);
@@ -212,7 +199,12 @@ symbol_exprt c_nondet_symbol_factory(
212199 symbols_created.push_back (main_symbol_ptr);
213200
214201 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+
216208 code_blockt assignments;
217209 state.gen_nondet_init (assignments, main_symbol_expr);
218210
0 commit comments