Skip to content

Commit b03eb7a

Browse files
authored
Merge pull request #3746 from diffblue/gen_struct_init_override
java_object_factory: use optional for override_type
2 parents a31ffb6 + c68cbfe commit b03eb7a

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ class java_object_factoryt
116116
irep_idt class_identifier,
117117
bool skip_classid,
118118
lifetimet lifetime,
119-
bool override_,
120-
const typet &override_type,
119+
const optionalt<typet> &override_type,
121120
size_t depth,
122121
update_in_placet,
123122
const source_locationt &location);
@@ -295,8 +294,7 @@ void java_object_factoryt::gen_pointer_target_init(
295294
"", // class_identifier
296295
false, // skip_classid
297296
lifetime,
298-
false, // override
299-
typet(), // override type immaterial
297+
{}, // no override type
300298
depth + 1,
301299
update_in_place,
302300
location);
@@ -763,8 +761,7 @@ symbol_exprt java_object_factoryt::gen_nondet_subtype_pointer_init(
763761
"", // class_identifier
764762
false, // skip_classid
765763
lifetime,
766-
false, // override
767-
typet(), // override_type
764+
{}, // no override_type
768765
depth,
769766
update_in_placet::NO_UPDATE_IN_PLACE,
770767
location);
@@ -968,8 +965,7 @@ void java_object_factoryt::gen_nondet_struct_init(
968965
class_identifier,
969966
false, // skip_classid
970967
lifetime,
971-
false, // override
972-
typet(), // override_type
968+
{}, // no override_type
973969
depth,
974970
substruct_in_place,
975971
location);
@@ -1007,15 +1003,14 @@ void java_object_factoryt::gen_nondet_struct_init(
10071003
/// \param lifetime:
10081004
/// Lifetime of the allocated objects (AUTOMATIC_LOCAL, STATIC_GLOBAL, or
10091005
/// DYNAMIC)
1010-
/// \param override_:
1011-
/// If true, initialize with `override_type` instead of `expr.type()`. Used at
1012-
/// the moment for reference arrays, which are implemented as void* arrays but
1013-
/// should be init'd as their true type with appropriate casts.
10141006
/// \param depth:
10151007
/// Number of times that a pointer has been dereferenced from the root of the
10161008
/// object tree that we are initializing.
10171009
/// \param override_type:
1018-
/// Override type per above.
1010+
/// If not empty, initialize with `override_type` instead of `expr.type()`.
1011+
/// Used at the moment for reference arrays, which are implemented as
1012+
/// void* arrays but should be init'd as their true type with appropriate
1013+
/// casts.
10191014
/// \param update_in_place:
10201015
/// NO_UPDATE_IN_PLACE: initialize `expr` from scratch
10211016
/// MAY_UPDATE_IN_PLACE: generate a runtime nondet branch between the NO_
@@ -1030,15 +1025,13 @@ void java_object_factoryt::gen_nondet_init(
10301025
irep_idt class_identifier,
10311026
bool skip_classid,
10321027
lifetimet lifetime,
1033-
bool override_,
1034-
const typet &override_type,
1028+
const optionalt<typet> &override_type,
10351029
size_t depth,
10361030
update_in_placet update_in_place,
10371031
const source_locationt &location)
10381032
{
1039-
const typet &type=
1040-
override_ ? ns.follow(override_type) : ns.follow(expr.type());
1041-
1033+
const typet &type = override_type.has_value() ? ns.follow(*override_type)
1034+
: ns.follow(expr.type());
10421035

10431036
if(type.id()==ID_pointer)
10441037
{
@@ -1074,7 +1067,8 @@ void java_object_factoryt::gen_nondet_init(
10741067
generic_parameter_specialization_map);
10751068
if(is_sub)
10761069
{
1077-
const typet &symbol = override_ ? override_type : expr.type();
1070+
const typet &symbol =
1071+
override_type.has_value() ? *override_type : expr.type();
10781072
PRECONDITION(symbol.id() == ID_struct_tag);
10791073
generic_parameter_specialization_map_keys.insert_pairs_for_symbol(
10801074
to_struct_tag_type(symbol), struct_type);
@@ -1146,8 +1140,7 @@ const symbol_exprt java_object_factoryt::gen_nondet_int_init(
11461140
irep_idt(),
11471141
false, // skip_classid
11481142
lifetimet::AUTOMATIC_LOCAL, // immaterial, type is primitive
1149-
false, // override
1150-
typet(), // override type is immaterial
1143+
{}, // no override type
11511144
0, // depth is immaterial, always non-null
11521145
update_in_placet::NO_UPDATE_IN_PLACE,
11531146
location);
@@ -1369,8 +1362,7 @@ void java_object_factoryt::array_loop_init_code(
13691362
false, // skip_classid
13701363
// These are variable in number, so use dynamic allocator:
13711364
lifetimet::DYNAMIC,
1372-
true, // override
1373-
element_type,
1365+
element_type, // override
13741366
depth,
13751367
child_update_in_place,
13761368
location);
@@ -1555,9 +1547,8 @@ exprt object_factory(
15551547
"", // class_identifier
15561548
false, // skip_classid
15571549
lifetime,
1558-
false, // override
1559-
typet(), // override_type is immaterial
1560-
1, // initial depth
1550+
{}, // no override_type
1551+
1, // initial depth
15611552
update_in_placet::NO_UPDATE_IN_PLACE,
15621553
loc);
15631554

@@ -1627,9 +1618,8 @@ void gen_nondet_init(
16271618
"", // class_identifier
16281619
skip_classid,
16291620
lifetime,
1630-
false, // override
1631-
typet(), // override_type is immaterial
1632-
1, // initial depth
1621+
{}, // no override_type
1622+
1, // initial depth
16331623
update_in_place,
16341624
loc);
16351625

0 commit comments

Comments
 (0)