Skip to content

Commit 61d03da

Browse files
Extract convert_ifnull function
1 parent b4f6d04 commit 61d03da

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+18-10
Original file line numberDiff line numberDiff line change
@@ -1610,16 +1610,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
16101610
mp_integer number;
16111611
bool ret=to_integer(to_constant_expr(arg0), number);
16121612
INVARIANT(!ret, "ifnull argument should be an integer");
1613-
code_ifthenelset code_branch;
1614-
const typecast_exprt lhs(op[0], java_reference_type(empty_typet()));
1615-
const exprt rhs(null_pointer_exprt(to_pointer_type(lhs.type())));
1616-
code_branch.cond()=binary_relation_exprt(lhs, ID_equal, rhs);
1617-
code_branch.then_case()=code_gotot(label(integer2string(number)));
1618-
code_branch.then_case().add_source_location()=
1619-
address_map.at(integer2unsigned(number)).source->source_location;
1620-
code_branch.add_source_location()=i_it->source_location;
1621-
1622-
c=code_branch;
1613+
c = convert_ifnull(address_map, op, number, i_it->source_location);
16231614
}
16241615
else if(statement=="iinc")
16251616
{
@@ -2552,6 +2543,23 @@ codet java_bytecode_convert_methodt::convert_instructions(
25522543
return code;
25532544
}
25542545

2546+
codet java_bytecode_convert_methodt::convert_ifnull(
2547+
const java_bytecode_convert_methodt::address_mapt &address_map,
2548+
const exprt::operandst &op,
2549+
const mp_integer &number,
2550+
const source_locationt &location) const
2551+
{
2552+
code_ifthenelset code_branch;
2553+
const typecast_exprt lhs(op[0], java_reference_type(empty_typet()));
2554+
const exprt rhs(null_pointer_exprt(to_pointer_type(lhs.type())));
2555+
code_branch.cond() = binary_relation_exprt(lhs, ID_equal, rhs);
2556+
code_branch.then_case() = code_gotot(label(integer2string(number)));
2557+
code_branch.then_case().add_source_location() =
2558+
address_map.at(integer2unsigned(number)).source->source_location;
2559+
code_branch.add_source_location() = location;
2560+
return code_branch;
2561+
}
2562+
25552563
codet java_bytecode_convert_methodt::convert_ifnonull(
25562564
const java_bytecode_convert_methodt::address_mapt &address_map,
25572565
const exprt::operandst &op,

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

+6
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ class java_bytecode_convert_methodt:public messaget
356356
const mp_integer &number,
357357
const source_locationt &location) const;
358358

359+
codet convert_ifnull(
360+
const java_bytecode_convert_methodt::address_mapt &address_map,
361+
const exprt::operandst &op,
362+
const mp_integer &number,
363+
const source_locationt &location) const;
364+
359365
codet convert_ifnull(
360366
java_bytecode_convert_methodt::address_mapt &address_map,
361367
const exprt::operandst &op,

0 commit comments

Comments
 (0)