Skip to content

Commit 0184c36

Browse files
authored
Merge pull request #4432 from antlechner/antonia/object-factory-location
Remove two unnecessary fields from the Java object factory
2 parents 963b9af + dea4be5 commit 0184c36

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ Author: Daniel Kroening, kroening@kroening.com
2424

2525
class java_object_factoryt
2626
{
27-
/// The source location for new statements emitted during the operation of the
28-
/// methods in this class.
29-
const source_locationt &loc;
30-
3127
const java_object_factory_parameterst object_factory_parameters;
3228

3329
/// This is employed in conjunction with the depth above. Every time the
@@ -49,9 +45,6 @@ class java_object_factoryt
4945
/// The symbol table.
5046
symbol_table_baset &symbol_table;
5147

52-
/// A namespace built from exclusively one symbol table - the one above.
53-
namespacet ns;
54-
5548
/// Resolves pointer types potentially using some heuristics, for example
5649
/// to replace pointers to interface types with pointers to concrete
5750
/// implementations.
@@ -85,10 +78,8 @@ class java_object_factoryt
8578
symbol_table_baset &_symbol_table,
8679
const select_pointer_typet &pointer_type_selector,
8780
message_handlert &log)
88-
: loc(loc),
89-
object_factory_parameters(_object_factory_parameters),
81+
: object_factory_parameters(_object_factory_parameters),
9082
symbol_table(_symbol_table),
91-
ns(_symbol_table),
9283
pointer_type_selector(pointer_type_selector),
9384
allocate_objects(
9485
ID_java,
@@ -233,6 +224,7 @@ void java_object_factoryt::gen_pointer_target_init(
233224
PRECONDITION(expr.type().id() == ID_pointer);
234225
PRECONDITION(update_in_place != update_in_placet::MAY_UPDATE_IN_PLACE);
235226

227+
const namespacet ns(symbol_table);
236228
const typet &followed_target_type = ns.follow(target_type);
237229

238230
if(followed_target_type.id() == ID_struct)
@@ -495,6 +487,7 @@ void java_object_factoryt::gen_nondet_pointer_init(
495487
const source_locationt &location)
496488
{
497489
PRECONDITION(expr.type().id()==ID_pointer);
490+
const namespacet ns(symbol_table);
498491
const pointer_typet &replacement_pointer_type =
499492
pointer_type_selector.convert_pointer_type(
500493
pointer_type, generic_parameter_specialization_map, ns);
@@ -555,7 +548,7 @@ void java_object_factoryt::gen_nondet_pointer_init(
555548
if(update_in_place==update_in_placet::NO_UPDATE_IN_PLACE)
556549
{
557550
assignments.add(
558-
code_assignt{expr, null_pointer_exprt{pointer_type}, loc});
551+
code_assignt{expr, null_pointer_exprt{pointer_type}, location});
559552
}
560553
// Otherwise leave it as it is.
561554
return;
@@ -634,7 +627,8 @@ void java_object_factoryt::gen_nondet_pointer_init(
634627
update_in_placet::NO_UPDATE_IN_PLACE,
635628
location);
636629

637-
const code_assignt set_null_inst{expr, null_pointer_exprt{pointer_type}, loc};
630+
const code_assignt set_null_inst{
631+
expr, null_pointer_exprt{pointer_type}, location};
638632

639633
const bool allow_null = depth > object_factory_parameters.min_null_tree_depth;
640634

@@ -804,6 +798,7 @@ void java_object_factoryt::gen_nondet_struct_init(
804798
const update_in_placet &update_in_place,
805799
const source_locationt &location)
806800
{
801+
const namespacet ns(symbol_table);
807802
PRECONDITION(ns.follow(expr.type()).id()==ID_struct);
808803
PRECONDITION(struct_type.id()==ID_struct);
809804

@@ -852,7 +847,7 @@ void java_object_factoryt::gen_nondet_struct_init(
852847
cases,
853848
java_int_type(),
854849
ID_java,
855-
loc,
850+
location,
856851
symbol_table));
857852
}
858853
else
@@ -880,7 +875,7 @@ void java_object_factoryt::gen_nondet_struct_init(
880875
assignments,
881876
object_factory_parameters.min_nondet_string_length,
882877
object_factory_parameters.max_nondet_string_length,
883-
loc,
878+
location,
884879
object_factory_parameters.function_id,
885880
symbol_table,
886881
object_factory_parameters.string_printable);
@@ -910,7 +905,7 @@ void java_object_factoryt::gen_nondet_struct_init(
910905
if(update_in_place == update_in_placet::MUST_UPDATE_IN_PLACE)
911906
continue;
912907
code_assignt code(me, from_integer(0, me.type()));
913-
code.add_source_location() = loc;
908+
code.add_source_location() = location;
914909
assignments.add(code);
915910
}
916911
else if(skip_special_string_fields && (name == "length" || name == "data"))
@@ -1004,6 +999,7 @@ void java_object_factoryt::gen_nondet_init(
1004999
const source_locationt &location)
10051000
{
10061001
const typet &type = override_type.has_value() ? *override_type : expr.type();
1002+
const namespacet ns(symbol_table);
10071003
const typet &followed_type = ns.follow(type);
10081004

10091005
if(type.id()==ID_pointer)
@@ -1063,10 +1059,11 @@ void java_object_factoryt::gen_nondet_init(
10631059
{
10641060
// types different from pointer or structure:
10651061
// bool, int, float, byte, char, ...
1066-
exprt rhs = type.id() == ID_c_bool ? get_nondet_bool(type, loc)
1067-
: side_effect_expr_nondett(type, loc);
1062+
exprt rhs = type.id() == ID_c_bool
1063+
? get_nondet_bool(type, location)
1064+
: side_effect_expr_nondett(type, location);
10681065
code_assignt assign(expr, rhs);
1069-
assign.add_source_location()=loc;
1066+
assign.add_source_location() = location;
10701067

10711068
assignments.add(assign);
10721069
}
@@ -1112,12 +1109,12 @@ void java_object_factoryt::allocate_nondet_length_array(
11121109
allocate_objects,
11131110
assignments);
11141111

1115-
side_effect_exprt java_new_array(ID_java_new_array, lhs.type(), loc);
1112+
side_effect_exprt java_new_array(ID_java_new_array, lhs.type(), location);
11161113
java_new_array.copy_to_operands(length_sym_expr);
11171114
java_new_array.set(ID_length_upper_bound, max_length_expr);
11181115
java_new_array.type().subtype().set(ID_element_type, element_type);
11191116
code_assignt assign(lhs, java_new_array);
1120-
assign.add_source_location() = loc;
1117+
assign.add_source_location() = location;
11211118
assignments.add(assign);
11221119
}
11231120

@@ -1158,7 +1155,7 @@ void java_object_factoryt::array_primitive_init_code(
11581155
assignments.statements().back().add_source_location() = location;
11591156

11601157
// *array_data_init = NONDET(TYPE [max_length_expr]);
1161-
side_effect_expr_nondett nondet_data(array_type, loc);
1158+
side_effect_expr_nondett nondet_data(array_type, location);
11621159
const dereference_exprt data_pointer_deref(
11631160
tmp_finite_array_pointer, array_type);
11641161
assignments.add(code_assignt(data_pointer_deref, std::move(nondet_data)));
@@ -1221,7 +1218,7 @@ void java_object_factoryt::array_loop_init_code(
12211218
init_array_expr.type(), "array_data_init");
12221219

12231220
code_assignt data_assign(array_init_symexpr, init_array_expr);
1224-
data_assign.add_source_location()=loc;
1221+
data_assign.add_source_location() = location;
12251222
assignments.add(data_assign);
12261223

12271224
const symbol_exprt &counter_expr =
@@ -1307,6 +1304,7 @@ void java_object_factoryt::gen_nondet_array_init(
13071304
PRECONDITION(expr.type().subtype().id() == ID_struct_tag);
13081305
PRECONDITION(update_in_place != update_in_placet::MAY_UPDATE_IN_PLACE);
13091306

1307+
const namespacet ns(symbol_table);
13101308
const typet &type = ns.follow(expr.type().subtype());
13111309
const struct_typet &struct_type = to_struct_type(type);
13121310
const typet &element_type =
@@ -1389,7 +1387,7 @@ bool java_object_factoryt::gen_nondet_enum_init(
13891387
{
13901388
const irep_idt &class_name = java_class_type.get_name();
13911389
const irep_idt values_name = id2string(class_name) + ".$VALUES";
1392-
if(!ns.get_symbol_table().has_symbol(values_name))
1390+
if(!symbol_table.has_symbol(values_name))
13931391
{
13941392
log.warning() << values_name
13951393
<< " is missing, so the corresponding Enum "
@@ -1398,6 +1396,7 @@ bool java_object_factoryt::gen_nondet_enum_init(
13981396
return false;
13991397
}
14001398

1399+
const namespacet ns(symbol_table);
14011400
const symbolt &values = ns.lookup(values_name);
14021401

14031402
// Access members (length and data) of $VALUES array

0 commit comments

Comments
 (0)