Skip to content

Commit 14e3c35

Browse files
Extract convert_invokedynamic function
1 parent 939bb53 commit 14e3c35

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,34 +1238,12 @@ codet java_bytecode_convert_methodt::convert_instructions(
12381238
else if(statement=="invokedynamic")
12391239
{
12401240
// not used in Java
1241-
code_typet &code_type = to_code_type(arg0.type());
1242-
1243-
const optionalt<symbolt> &lambda_method_symbol = get_lambda_method_symbol(
1244-
lambda_method_handles,
1245-
code_type.get_int(ID_java_lambda_method_handle_index));
1246-
if(lambda_method_symbol.has_value())
1247-
debug() << "Converting invokedynamic for lambda: "
1248-
<< lambda_method_symbol.value().name << eom;
1249-
else
1250-
debug() << "Converting invokedynamic for lambda with unknown handle "
1251-
"type"
1252-
<< eom;
1253-
1254-
const code_typet::parameterst &parameters(code_type.parameters());
1255-
1256-
pop(parameters.size());
1257-
1258-
const typet &return_type=code_type.return_type();
1259-
1260-
if(return_type.id()!=ID_empty)
1241+
if(
1242+
const auto res = convert_invoke_dynamic(
1243+
lambda_method_handles, i_it->source_location, arg0))
12611244
{
12621245
results.resize(1);
1263-
results[0]=
1264-
zero_initializer(
1265-
return_type,
1266-
i_it->source_location,
1267-
namespacet(symbol_table),
1268-
get_message_handler());
1246+
results[0] = *res;
12691247
}
12701248
}
12711249
// replace calls to CProver.assume
@@ -2706,6 +2684,37 @@ codet java_bytecode_convert_methodt::convert_instructions(
27062684
return code;
27072685
}
27082686

2687+
optionalt<exprt> java_bytecode_convert_methodt::convert_invoke_dynamic(
2688+
const java_class_typet::java_lambda_method_handlest &lambda_method_handles,
2689+
const source_locationt &location,
2690+
const exprt &arg0)
2691+
{
2692+
const code_typet &code_type = to_code_type(arg0.type());
2693+
2694+
const optionalt<symbolt> &lambda_method_symbol = get_lambda_method_symbol(
2695+
lambda_method_handles,
2696+
code_type.get_int(ID_java_lambda_method_handle_index));
2697+
if(lambda_method_symbol.has_value())
2698+
debug() << "Converting invokedynamic for lambda: "
2699+
<< lambda_method_symbol.value().name << eom;
2700+
else
2701+
debug() << "Converting invokedynamic for lambda with unknown handle "
2702+
"type"
2703+
<< eom;
2704+
2705+
const code_typet::parameterst &parameters(code_type.parameters());
2706+
2707+
pop(parameters.size());
2708+
2709+
const typet &return_type = code_type.return_type();
2710+
2711+
if(return_type.id() == ID_empty)
2712+
return {};
2713+
2714+
return zero_initializer(
2715+
return_type, location, namespacet(symbol_table), get_message_handler());
2716+
}
2717+
27092718
void java_bytecode_convert_methodt::draw_edges_from_ret_to_jsr(
27102719
java_bytecode_convert_methodt::address_mapt &address_map,
27112720
const std::vector<unsigned int> &jsr_ret_targets,

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ class java_bytecode_convert_methodt:public messaget
285285
const std::vector<
286286
std::vector<java_bytecode_parse_treet::instructiont>::const_iterator>
287287
&ret_instructions) const;
288+
289+
optionalt<exprt> convert_invoke_dynamic(
290+
const java_class_typet::java_lambda_method_handlest &lambda_method_handles,
291+
const source_locationt &location,
292+
const exprt &arg0);
288293
};
289294

290295
#endif

0 commit comments

Comments
 (0)