@@ -303,6 +303,27 @@ code_typet member_type_lazy(
303
303
return to_code_type (member_type_from_descriptor);
304
304
}
305
305
306
+ // / Retrieves the symbol of the lambda method associated with the given
307
+ // / lambda method handle (bootstrap method).
308
+ // / \param lambda_method_handles Vector of lambda method handles (bootstrap
309
+ // / methods) of the class where the lambda is called
310
+ // / \param index Index of the lambda method handle in the vector
311
+ // / \return Symbol of the lambda method if the method handle does not have an
312
+ // / unknown type
313
+ optionalt<symbolt> java_bytecode_convert_methodt::get_lambda_method_symbol (
314
+ const java_class_typet::java_lambda_method_handlest &lambda_method_handles,
315
+ const irep_idt &index)
316
+ {
317
+ const symbol_exprt &lambda_method_handle =
318
+ lambda_method_handles.at (std::stoi (id2string (index)));
319
+ // If the lambda method handle has an unknown type, it does not refer to
320
+ // any symbol (it is a symbol expression with empty identifier)
321
+ if (!lambda_method_handle.get_identifier ().empty ())
322
+ return symbol_table.lookup_ref (lambda_method_handle.get_identifier ());
323
+ else
324
+ return {};
325
+ }
326
+
306
327
// / This creates a method symbol in the symtab, but doesn't actually perform
307
328
// / method conversion just yet. The caller should call
308
329
// / java_bytecode_convert_method later to give the symbol/method a body.
@@ -552,7 +573,11 @@ void java_bytecode_convert_methodt::convert(
552
573
current_method=method_symbol.name ;
553
574
method_has_this=code_type.has_this ();
554
575
if ((!m.is_abstract ) && (!m.is_native ))
555
- method_symbol.value =convert_instructions (m, code_type, method_symbol.name );
576
+ method_symbol.value = convert_instructions (
577
+ m,
578
+ code_type,
579
+ method_symbol.name ,
580
+ to_java_class_type (class_symbol.type ).lambda_method_handles ());
556
581
}
557
582
558
583
const bytecode_infot &java_bytecode_convert_methodt::get_bytecode_info (
@@ -923,7 +948,8 @@ static unsigned get_bytecode_type_width(const typet &ty)
923
948
codet java_bytecode_convert_methodt::convert_instructions (
924
949
const methodt &method,
925
950
const code_typet &method_type,
926
- const irep_idt &method_name)
951
+ const irep_idt &method_name,
952
+ const java_class_typet::java_lambda_method_handlest &lambda_method_handles)
927
953
{
928
954
const instructionst &instructions=method.instructions ;
929
955
@@ -1208,7 +1234,19 @@ codet java_bytecode_convert_methodt::convert_instructions(
1208
1234
else if (statement==" invokedynamic" )
1209
1235
{
1210
1236
// not used in Java
1211
- code_typet &code_type=to_code_type (arg0.type ());
1237
+ code_typet &code_type = to_code_type (arg0.type ());
1238
+
1239
+ const optionalt<symbolt> &lambda_method_symbol = get_lambda_method_symbol (
1240
+ lambda_method_handles,
1241
+ code_type.get (ID_java_lambda_method_handle_index));
1242
+ if (lambda_method_symbol.has_value ())
1243
+ debug () << " Converting invokedynamic for lambda: "
1244
+ << lambda_method_symbol.value ().name << eom;
1245
+ else
1246
+ debug () << " Converting invokedynamic for lambda with unknown handle "
1247
+ " type"
1248
+ << eom;
1249
+
1212
1250
const code_typet::parameterst ¶meters (code_type.parameters ());
1213
1251
1214
1252
pop (parameters.size ());
0 commit comments