Skip to content

Commit b4f6d04

Browse files
Extract convert_if_nonull function
1 parent 0e911d4 commit b4f6d04

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+18-10
Original file line numberDiff line numberDiff line change
@@ -1602,16 +1602,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
16021602
mp_integer number;
16031603
bool ret=to_integer(to_constant_expr(arg0), number);
16041604
INVARIANT(!ret, "ifnonnull argument should be an integer");
1605-
code_ifthenelset code_branch;
1606-
const typecast_exprt lhs(op[0], java_reference_type(empty_typet()));
1607-
const exprt rhs(null_pointer_exprt(to_pointer_type(lhs.type())));
1608-
code_branch.cond()=binary_relation_exprt(lhs, ID_notequal, rhs);
1609-
code_branch.then_case()=code_gotot(label(integer2string(number)));
1610-
code_branch.then_case().add_source_location()=
1611-
address_map.at(integer2unsigned(number)).source->source_location;
1612-
code_branch.add_source_location()=i_it->source_location;
1613-
1614-
c=code_branch;
1605+
c = convert_ifnonull(address_map, op, number, i_it->source_location);
16151606
}
16161607
else if(statement==patternt("ifnull"))
16171608
{
@@ -2561,6 +2552,23 @@ codet java_bytecode_convert_methodt::convert_instructions(
25612552
return code;
25622553
}
25632554

2555+
codet java_bytecode_convert_methodt::convert_ifnonull(
2556+
const java_bytecode_convert_methodt::address_mapt &address_map,
2557+
const exprt::operandst &op,
2558+
const mp_integer &number,
2559+
const source_locationt &location) const
2560+
{
2561+
code_ifthenelset code_branch;
2562+
const typecast_exprt lhs(op[0], java_reference_type(empty_typet()));
2563+
const exprt rhs(null_pointer_exprt(to_pointer_type(lhs.type())));
2564+
code_branch.cond() = binary_relation_exprt(lhs, ID_notequal, rhs);
2565+
code_branch.then_case() = code_gotot(label(integer2string(number)));
2566+
code_branch.then_case().add_source_location() =
2567+
address_map.at(integer2unsigned(number)).source->source_location;
2568+
code_branch.add_source_location() = location;
2569+
return code_branch;
2570+
}
2571+
25642572
codet java_bytecode_convert_methodt::convert_if(
25652573
const java_bytecode_convert_methodt::address_mapt &address_map,
25662574
const exprt::operandst &op,

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

+12
Original file line numberDiff line numberDiff line change
@@ -349,5 +349,17 @@ class java_bytecode_convert_methodt:public messaget
349349
const irep_idt &id,
350350
const mp_integer &number,
351351
const source_locationt &location) const;
352+
353+
codet convert_ifnonull(
354+
const java_bytecode_convert_methodt::address_mapt &address_map,
355+
const exprt::operandst &op,
356+
const mp_integer &number,
357+
const source_locationt &location) const;
358+
359+
codet convert_ifnull(
360+
java_bytecode_convert_methodt::address_mapt &address_map,
361+
const exprt::operandst &op,
362+
const mp_integer &number,
363+
const source_locationt &location);
352364
};
353365
#endif

0 commit comments

Comments
 (0)