Skip to content

Commit 8f820ec

Browse files
committed
Replace fresh_java_symbol in object factory
We have access to an allocate_objectst instance that stores most of the information we need and also automatically takes care of variable declarations, so we don't have to worry about creating a code_declt after every new symbol creation.
1 parent 18da0b1 commit 8f820ec

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ void initialize_nondet_string_fields(
366366
const source_locationt &loc,
367367
const irep_idt &function_id,
368368
symbol_table_baset &symbol_table,
369-
bool printable)
369+
bool printable,
370+
allocate_objectst &allocate_objects)
370371
{
371372
PRECONDITION(
372373
java_string_library_preprocesst
@@ -402,11 +403,10 @@ void initialize_nondet_string_fields(
402403

403404
/// \todo Refactor with make_nondet_string_expr
404405
// length_expr = nondet(int);
405-
const symbolt length_sym = fresh_java_symbol(
406-
java_int_type(), "tmp_object_factory", loc, function_id, symbol_table);
407-
const symbol_exprt length_expr = length_sym.symbol_expr();
406+
const symbol_exprt length_expr =
407+
allocate_objects.allocate_automatic_local_object(
408+
java_int_type(), "tmp_object_factory");
408409
const side_effect_expr_nondett nondet_length(length_expr.type(), loc);
409-
code.add(code_declt(length_expr));
410410
code.add(code_assignt(length_expr, nondet_length));
411411

412412
// assume (length_expr >= min_nondet_string_length);
@@ -709,17 +709,14 @@ symbol_exprt java_object_factoryt::gen_nondet_subtype_pointer_init(
709709
size_t depth,
710710
const source_locationt &location)
711711
{
712-
symbolt new_symbol = fresh_java_symbol(
713-
replacement_pointer,
714-
"tmp_object_factory",
715-
location,
716-
object_factory_parameters.function_id,
717-
symbol_table);
712+
const symbol_exprt new_symbol_expr =
713+
allocate_objects.allocate_automatic_local_object(
714+
replacement_pointer, "tmp_object_factory");
718715

719716
// Generate a new object into this new symbol
720717
gen_nondet_init(
721718
assignments,
722-
new_symbol.symbol_expr(),
719+
new_symbol_expr,
723720
false, // is_sub
724721
"", // class_identifier
725722
false, // skip_classid
@@ -729,7 +726,7 @@ symbol_exprt java_object_factoryt::gen_nondet_subtype_pointer_init(
729726
update_in_placet::NO_UPDATE_IN_PLACE,
730727
location);
731728

732-
return new_symbol.symbol_expr();
729+
return new_symbol_expr;
733730
}
734731

735732
/// Creates an alternate_casest vector in which each item contains an
@@ -874,7 +871,8 @@ void java_object_factoryt::gen_nondet_struct_init(
874871
location,
875872
object_factory_parameters.function_id,
876873
symbol_table,
877-
object_factory_parameters.string_printable);
874+
object_factory_parameters.string_printable,
875+
allocate_objects);
878876
}
879877

880878
assignments.add(code_assignt(expr, *initial_object));

0 commit comments

Comments
 (0)