Skip to content

Commit 3c49d89

Browse files
committed
Remove unnecessary namespacet field from object factory
ns was supposed to always contain a pointer to symbol_table. This kind of class invariant is unnecessary. It is better to just work with the symbol table if possible, and construct a namespacet from it whenever we need it. This way the namespacet can always be declared const and we can easily see which functions make use of it.
1 parent ae5f31a commit 3c49d89

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ class java_object_factoryt
4545
/// The symbol table.
4646
symbol_table_baset &symbol_table;
4747

48-
/// A namespace built from exclusively one symbol table - the one above.
49-
namespacet ns;
50-
5148
/// Resolves pointer types potentially using some heuristics, for example
5249
/// to replace pointers to interface types with pointers to concrete
5350
/// implementations.
@@ -83,7 +80,6 @@ class java_object_factoryt
8380
message_handlert &log)
8481
: object_factory_parameters(_object_factory_parameters),
8582
symbol_table(_symbol_table),
86-
ns(_symbol_table),
8783
pointer_type_selector(pointer_type_selector),
8884
allocate_objects(
8985
ID_java,
@@ -228,6 +224,7 @@ void java_object_factoryt::gen_pointer_target_init(
228224
PRECONDITION(expr.type().id() == ID_pointer);
229225
PRECONDITION(update_in_place != update_in_placet::MAY_UPDATE_IN_PLACE);
230226

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

233230
if(followed_target_type.id() == ID_struct)
@@ -490,6 +487,7 @@ void java_object_factoryt::gen_nondet_pointer_init(
490487
const source_locationt &location)
491488
{
492489
PRECONDITION(expr.type().id()==ID_pointer);
490+
const namespacet ns(symbol_table);
493491
const pointer_typet &replacement_pointer_type =
494492
pointer_type_selector.convert_pointer_type(
495493
pointer_type, generic_parameter_specialization_map, ns);
@@ -800,6 +798,7 @@ void java_object_factoryt::gen_nondet_struct_init(
800798
const update_in_placet &update_in_place,
801799
const source_locationt &location)
802800
{
801+
const namespacet ns(symbol_table);
803802
PRECONDITION(ns.follow(expr.type()).id()==ID_struct);
804803
PRECONDITION(struct_type.id()==ID_struct);
805804

@@ -1000,6 +999,7 @@ void java_object_factoryt::gen_nondet_init(
1000999
const source_locationt &location)
10011000
{
10021001
const typet &type = override_type.has_value() ? *override_type : expr.type();
1002+
const namespacet ns(symbol_table);
10031003
const typet &followed_type = ns.follow(type);
10041004

10051005
if(type.id()==ID_pointer)
@@ -1304,6 +1304,7 @@ void java_object_factoryt::gen_nondet_array_init(
13041304
PRECONDITION(expr.type().subtype().id() == ID_struct_tag);
13051305
PRECONDITION(update_in_place != update_in_placet::MAY_UPDATE_IN_PLACE);
13061306

1307+
const namespacet ns(symbol_table);
13071308
const typet &type = ns.follow(expr.type().subtype());
13081309
const struct_typet &struct_type = to_struct_type(type);
13091310
const typet &element_type =
@@ -1386,7 +1387,7 @@ bool java_object_factoryt::gen_nondet_enum_init(
13861387
{
13871388
const irep_idt &class_name = java_class_type.get_name();
13881389
const irep_idt values_name = id2string(class_name) + ".$VALUES";
1389-
if(!ns.get_symbol_table().has_symbol(values_name))
1390+
if(symbol_table.has_symbol(values_name))
13901391
{
13911392
log.warning() << values_name
13921393
<< " is missing, so the corresponding Enum "
@@ -1395,6 +1396,7 @@ bool java_object_factoryt::gen_nondet_enum_init(
13951396
return false;
13961397
}
13971398

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

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

0 commit comments

Comments
 (0)