Skip to content

Commit 63d9f50

Browse files
committed
Remove duplicate helper function in object factory
Calls to java_object_factoryt::gen_nondet_int_init can be replaced with equivalent calls to generate_nondet_int from nondet.h.
1 parent eeb9f22 commit 63d9f50

File tree

1 file changed

+10
-62
lines changed

1 file changed

+10
-62
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,6 @@ class java_object_factoryt
160160
size_t depth,
161161
const source_locationt &location);
162162

163-
const symbol_exprt gen_nondet_int_init(
164-
code_blockt &assignments,
165-
const std::string &basename_prefix,
166-
const exprt &min_length_expr,
167-
const exprt &max_length_expr,
168-
const source_locationt &location);
169-
170163
void gen_method_call_if_present(
171164
code_blockt &assignments,
172165
const exprt &instance_expr,
@@ -1103,53 +1096,6 @@ void java_object_factoryt::declare_created_symbols(code_blockt &init_code)
11031096
allocate_objects.declare_created_symbols(init_code);
11041097
}
11051098

1106-
/// Nondeterministically initializes an int i in the range min <= i <= max,
1107-
/// where min is the integer represented by `min_value_expr` and max is the
1108-
/// integer represented by `max_value_expr`.
1109-
/// \param [out] assignments: A code block that the initializing assignments
1110-
/// will be appended to.
1111-
/// \param basename_prefix: Used for naming the newly created symbol.
1112-
/// \param min_value_expr: Represents the minimum value for the integer.
1113-
/// \param max_value_expr: Represents the maximum value for the integer.
1114-
/// \param location: Source location associated with nondet-initialization.
1115-
/// \return A symbol expression for the resulting integer.
1116-
const symbol_exprt java_object_factoryt::gen_nondet_int_init(
1117-
code_blockt &assignments,
1118-
const std::string &basename_prefix,
1119-
const exprt &min_value_expr,
1120-
const exprt &max_value_expr,
1121-
const source_locationt &location)
1122-
{
1123-
PRECONDITION(min_value_expr.type() == max_value_expr.type());
1124-
1125-
const symbol_exprt &int_symbol_expr =
1126-
allocate_objects.allocate_automatic_local_object(
1127-
min_value_expr.type(), basename_prefix);
1128-
1129-
// Nondet-initialize it
1130-
gen_nondet_init(
1131-
assignments,
1132-
int_symbol_expr,
1133-
false, // is_sub
1134-
irep_idt(),
1135-
false, // skip_classid
1136-
lifetimet::AUTOMATIC_LOCAL, // immaterial, type is primitive
1137-
{}, // no override type
1138-
0, // depth is immaterial, always non-null
1139-
update_in_placet::NO_UPDATE_IN_PLACE,
1140-
location);
1141-
1142-
// Insert assumptions to bound its value
1143-
const auto min_assume_expr =
1144-
binary_relation_exprt(int_symbol_expr, ID_ge, min_value_expr);
1145-
const auto max_assume_expr =
1146-
binary_relation_exprt(int_symbol_expr, ID_le, max_value_expr);
1147-
assignments.add(code_assumet(min_assume_expr));
1148-
assignments.add(code_assumet(max_assume_expr));
1149-
1150-
return int_symbol_expr;
1151-
}
1152-
11531099
/// Allocates a fresh array and emits an assignment writing to \p lhs the
11541100
/// address of the new array. Single-use at the moment, but useful to keep as a
11551101
/// separate function for downstream branches.
@@ -1172,12 +1118,13 @@ void java_object_factoryt::allocate_nondet_length_array(
11721118
const typet &element_type,
11731119
const source_locationt &location)
11741120
{
1175-
const auto &length_sym_expr = gen_nondet_int_init(
1176-
assignments,
1177-
"nondet_array_length",
1121+
const auto &length_sym_expr = generate_nondet_int(
11781122
from_integer(0, java_int_type()),
11791123
max_length_expr,
1180-
location);
1124+
"nondet_array_length",
1125+
location,
1126+
allocate_objects,
1127+
assignments);
11811128

11821129
side_effect_exprt java_new_array(ID_java_new_array, lhs.type(), loc);
11831130
java_new_array.copy_to_operands(length_sym_expr);
@@ -1476,12 +1423,13 @@ bool java_object_factoryt::gen_nondet_enum_init(
14761423
const member_exprt enum_array_expr =
14771424
member_exprt(deref_expr, "data", comps[2].type());
14781425

1479-
const symbol_exprt &index_expr = gen_nondet_int_init(
1480-
assignments,
1481-
"enum_index_init",
1426+
const symbol_exprt &index_expr = generate_nondet_int(
14821427
from_integer(0, java_int_type()),
14831428
minus_exprt(length_expr, from_integer(1, java_int_type())),
1484-
location);
1429+
"enum_index_init",
1430+
location,
1431+
allocate_objects,
1432+
assignments);
14851433

14861434
// Generate statement using pointer arithmetic to access array element:
14871435
// expr = (expr.type())*(enum_array_expr + index_expr);

0 commit comments

Comments
 (0)