Skip to content

Commit 7d4f30f

Browse files
authored
Merge pull request #4441 from antlechner/antonia/refactor-gen-method-call
Remove unnecessary helper function that adds a function call to a code block
2 parents 13712c4 + 1c63865 commit 7d4f30f

File tree

2 files changed

+9
-40
lines changed

2 files changed

+9
-40
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ class java_object_factoryt
147147
size_t depth,
148148
const source_locationt &location);
149149

150-
void gen_method_call_if_present(
151-
code_blockt &assignments,
152-
const exprt &instance_expr,
153-
const irep_idt &method_name);
154-
155150
void array_primitive_init_code(
156151
code_blockt &assignments,
157152
const exprt &init_array_expr,
@@ -582,7 +577,8 @@ void java_object_factoryt::gen_nondet_pointer_init(
582577
{
583578
const irep_idt &class_name = class_type->get_name();
584579
const irep_idt class_clinit = clinit_wrapper_name(class_name);
585-
gen_method_call_if_present(assignments, expr, class_clinit);
580+
if(const auto clinit_func = symbol_table.lookup(class_clinit))
581+
assignments.add(code_function_callt{clinit_func->symbol_expr()});
586582
}
587583
}
588584

@@ -948,7 +944,9 @@ void java_object_factoryt::gen_nondet_struct_init(
948944

949945
const irep_idt init_method_name =
950946
"java::" + id2string(struct_tag) + ".cproverNondetInitialize:()V";
951-
gen_method_call_if_present(assignments, expr, init_method_name);
947+
if(const auto init_func = symbol_table.lookup(init_method_name))
948+
assignments.add(
949+
code_function_callt{init_func->symbol_expr(), {address_of_exprt{expr}}});
952950
}
953951

954952
/// Initializes a primitive-typed or reference-typed object tree rooted at
@@ -1623,24 +1621,3 @@ void gen_nondet_init(
16231621
update_in_place,
16241622
log);
16251623
}
1626-
1627-
/// Adds a call for the given method to the end of `assignments` if the method
1628-
/// exists in the symbol table. Does nothing if the method does not exist.
1629-
/// \param assignments: A code block that the method call will be appended to.
1630-
/// \param instance_expr: The instance to call the method on. This argument is
1631-
/// ignored if the method is static.
1632-
/// \param method_name: The name of the method to be called.
1633-
void java_object_factoryt::gen_method_call_if_present(
1634-
code_blockt &assignments,
1635-
const exprt &instance_expr,
1636-
const irep_idt &method_name)
1637-
{
1638-
if(const auto func = symbol_table.lookup(method_name))
1639-
{
1640-
const java_method_typet &type = to_java_method_type(func->type);
1641-
code_function_callt fun_call(func->symbol_expr());
1642-
if(type.has_this())
1643-
fun_call.arguments().push_back(address_of_exprt(instance_expr));
1644-
assignments.add(fun_call);
1645-
}
1646-
}

jbmc/src/java_bytecode/java_static_initializers.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,13 @@ static void clinit_wrapper_do_recursive_calls(
210210
{
211211
const auto base_name = base.type().get_identifier();
212212
irep_idt base_init_routine = clinit_wrapper_name(base_name);
213-
auto findit = symbol_table.symbols.find(base_init_routine);
214-
if(findit == symbol_table.symbols.end())
215-
continue;
216-
217-
const code_function_callt call_base(findit->second.symbol_expr());
218-
init_body.add(call_base);
213+
if(const auto base_init_func = symbol_table.lookup(base_init_routine))
214+
init_body.add(code_function_callt{base_init_func->symbol_expr()});
219215
}
220216

221217
const irep_idt &real_clinit_name = clinit_function_name(class_name);
222-
auto find_sym_it = symbol_table.symbols.find(real_clinit_name);
223-
if(find_sym_it != symbol_table.symbols.end())
224-
{
225-
const code_function_callt call_real_init(find_sym_it->second.symbol_expr());
226-
init_body.add(call_real_init);
227-
}
218+
if(const auto clinit_func = symbol_table.lookup(real_clinit_name))
219+
init_body.add(code_function_callt{clinit_func->symbol_expr()});
228220

229221
// If nondet-static option is given, add a standard nondet initialization for
230222
// each non-final static field of this class. Note this is the same invocation

0 commit comments

Comments
 (0)