Go to the documentation of this file.
32 if(c ==
'$' || c ==
':' || c ==
'.')
40 std::size_t instruction_address)
42 return "java::lambda_synthetic_class$" +
65 if(index >= lambda_method_handles.size())
84 const auto &method_symbol = ns.
lookup(method_identifier);
85 const auto &declaring_class_symbol =
89 const auto &lambda_method_handles = class_type.lambda_method_handles();
90 auto lambda_handle_index =
91 dynamic_method_type.
get_int(ID_java_lambda_method_handle_index);
93 symbol_table, lambda_method_handles, lambda_handle_index);
112 return a->get_base_name() == b->get_base_name()
116 : a->get_base_name() < b->get_base_name();
138 static const irep_idt jlo =
"java::java.lang.Object";
141 if(jlo == interface_id)
147 if(interface.get_is_stub())
150 "produces a type that inherits the stub type " +
id2string(interface_id));
156 for(
const auto &base : interface.bases())
160 for(
const auto &base_method : base_methods)
162 if(base_method.second)
165 all_methods[base_method.first] =
true;
171 all_methods.emplace(base_method.first,
false);
177 for(
const auto &method : interface.methods())
179 static const irep_idt equals =
"equals";
180 static const irep_idt equals_descriptor =
"(Ljava/lang/Object;)Z";
181 static const irep_idt hashCode =
"hashCode";
182 static const irep_idt hashCode_descriptor =
"()I";
184 (method.get_base_name() == equals &&
185 method.get_descriptor() == equals_descriptor) ||
186 (method.get_base_name() == hashCode &&
187 method.get_descriptor() == hashCode_descriptor))
198 all_methods[&method] =
199 !ns.lookup(method.get_name()).type.get_bool(ID_C_abstract);
209 const int instruction_address,
221 for(
const auto &entry : all_methods)
225 if(method_and_descriptor_to_implement !=
nullptr)
228 "produces a type with at least two unimplemented methods");
230 method_and_descriptor_to_implement = entry.first;
234 if(!method_and_descriptor_to_implement)
237 "produces a type with no unimplemented methods");
239 return method_and_descriptor_to_implement;
243 log.
debug() <<
"ignoring invokedynamic at " << method_identifier
244 <<
" address " << instruction_address <<
" with type "
252 const irep_idt &synthetic_class_name,
262 synthetic_class_type.
set_name(synthetic_class_name);
266 synthetic_class_type.
add_base(base_tag);
267 synthetic_class_type.
add_base(functional_interface_tag);
273 const irep_idt base_field_name(
"@java.lang.Object");
274 base_field.set_name(base_field_name);
275 base_field.set_base_name(base_field_name);
276 base_field.set_pretty_name(base_field_name);
277 base_field.set_access(ID_private);
278 base_field.type() = base_tag;
279 synthetic_class_type.
components().emplace_back(std::move(base_field));
281 std::size_t field_idx = 0;
282 for(
const auto ¶m : dynamic_method_type.
parameters())
287 new_field.set_name(field_basename);
288 new_field.set_base_name(field_basename);
289 new_field.set_pretty_name(field_basename);
290 new_field.set_access(ID_private);
291 new_field.type() = param.type();
292 synthetic_class_type.
components().emplace_back(std::move(new_field));
304 const irep_idt &synthetic_class_name,
314 synthetic_methods[constructor_name] =
320 size_t field_idx = 0;
321 for(
auto ¶m : constructor_type.
parameters())
324 param.set_base_name(param_basename);
325 param.set_identifier(
336 constructor_type.
parameters().begin(), constructor_this_param);
346 const irep_idt &synthetic_class_name)
348 const std::string implemented_method_name =
350 id2string(method_to_implement.get_base_name()) +
":" +
362 implemented_method_type.parameters()[0].type() =
365 size_t field_idx = 0;
366 for(
auto ¶m : implemented_method_type.parameters())
370 param.set_base_name(param_basename);
371 param.set_identifier(
410 const messaget log{message_handler};
412 for(
const auto &instruction : instructions)
416 const auto &dynamic_method_type =
419 symbol_table, method_identifier, dynamic_method_type);
422 log.debug() <<
"ignoring invokedynamic at " << method_identifier
423 <<
" address " << instruction.address
431 functional_interface_tag,
435 if(!unimplemented_method)
437 log.debug() <<
"identified invokedynamic at " << method_identifier
438 <<
" address " << instruction.address <<
" for lambda: "
439 << lambda_handle->get_lambda_method_identifier()
441 const irep_idt synthetic_class_name =
444 synthetic_methods, synthetic_class_name, dynamic_method_type));
446 synthetic_methods, *unimplemented_method, synthetic_class_name));
448 synthetic_class_name,
450 functional_interface_tag,
451 dynamic_method_type));
464 const auto *existing_symbol = symbol_table.
lookup(identifier);
466 return *existing_symbol;
494 parameters.at(0).get_identifier(), parameters.at(0).type());
498 const irep_idt jlo(
"java::java.lang.Object");
510 jlo_constructor_type,
515 jlo_constructor_symbol.symbol_expr(),
517 result.
add(super_constructor_call);
520 auto field_iterator = std::next(class_type.
components().begin());
521 for(
const auto ¶meter : parameters)
525 param_symbol.
name = parameter.get_identifier();
526 param_symbol.
base_name = parameter.get_base_name();
527 param_symbol.
mode = ID_java;
528 param_symbol.
type = parameter.type();
529 symbol_table.
add(param_symbol);
531 if(parameter.get_this())
536 symbol_exprt(parameter.get_identifier(), parameter.type()));
537 result.
add(assign_field);
542 return std::move(result);
554 new_instance_var_symbol.
name = new_var_name;
555 new_instance_var_symbol.
base_name = basename;
556 new_instance_var_symbol.
mode = ID_java;
557 new_instance_var_symbol.
type = type;
558 bool add_failed = symbol_table.
add(new_instance_var_symbol);
563 return new_instance_var;
578 const symbolt &lambda_method_symbol,
585 method_type.get_bool(ID_constructor),
586 "REF_NewInvokeSpecial lambda must refer to a constructor");
587 const auto &created_type = method_type.parameters().at(0).type();
594 if(
const auto *static_init_symbol = symbol_table.
lookup(static_init_name))
602 "newinvokespecial_instance",
611 return new_instance_var;
631 const symbolt &function_symbol,
635 if(!method_type.has_this())
637 const irep_idt &declared_on_class_id =
641 const auto &this_symbol = symbol_table.
lookup_ref(declared_on_class_id);
648 const std::string &function_name =
id2string(function_symbol.
name);
649 const auto method_name_start_idx = function_name.rfind(
'.');
650 const irep_idt mangled_method_name =
651 function_name.substr(method_name_start_idx + 1);
655 declared_on_class_id,
690 const typet &required_type,
694 const std::string &role)
696 const typet &original_type = expr.
type();
700 if(original_is_pointer == required_is_pointer)
709 original_is_pointer ? required_type : original_type);
711 primitive_type_info !=
nullptr,
712 "A Java non-pointer type involved in a type disagreement should"
716 role + (original_is_pointer ?
"_unboxed" :
"_boxed");
719 function_id, fresh_local_name, required_type, symbol_table, code_block);
721 const irep_idt transform_function_id =
725 .value_or(primitive_type_info->unboxing_function_name)
726 : primitive_type_info->boxed_type_factory_method;
728 const symbolt &transform_function_symbol =
729 symbol_table.
lookup_ref(transform_function_id);
731 const typet &transform_function_param_type =
733 const exprt cast_expr =
741 return std::move(fresh_local);
749 const typet &required_type,
753 const std::string &role)
757 expr, required_type, code_block, symbol_table, function_id, role),
792 const auto ¶meters = function_type.parameters();
798 parameters.at(0).get_identifier(), parameters.at(0).type());
802 for(
const auto &field : class_type.
components())
804 if(field.get_name() ==
"@java.lang.Object")
806 lambda_method_args.push_back(
810 for(
const auto ¶meter : parameters)
814 param_symbol.
name = parameter.get_identifier();
815 param_symbol.
base_name = parameter.get_base_name();
816 param_symbol.
mode = ID_java;
817 param_symbol.
type = parameter.type();
818 symbol_table.
add(param_symbol);
820 if(parameter.get_this())
823 lambda_method_args.push_back(param_symbol.
symbol_expr());
828 class_type.
find(ID_java_lambda_method_handle));
830 const auto &lambda_method_symbol =
833 const auto is_constructor_lambda =
836 const auto use_virtual_dispatch =
840 if(is_constructor_lambda)
843 function_id, lambda_method_symbol, symbol_table, result);
846 lambda_method_args.insert(lambda_method_args.begin(), new_instance_var);
849 const auto &lambda_method_descriptor =
852 if(use_virtual_dispatch)
853 callee = lambda_method_descriptor;
855 callee = lambda_method_symbol.symbol_expr();
859 const auto &callee_parameters = callee_type.
parameters();
860 const auto &callee_return_type = callee_type.
return_type();
862 callee_parameters.size() == lambda_method_args.size(),
863 "should have args for every parameter");
864 for(
unsigned i = 0; i < callee_parameters.size(); ++i)
867 std::move(lambda_method_args[i]),
868 callee_parameters[i].type(),
875 if(function_type.return_type() !=
empty_typet() && !is_constructor_lambda)
878 function_id,
"return_value", callee_return_type, symbol_table, result);
882 function_type.return_type(),
894 if(is_constructor_lambda)
898 lambda_method_args.at(0), function_type.return_type())});
901 return std::move(result);
Class that provides messages with a built-in verbosity 'level'.
const irep_idt & get_identifier() const
const componentst & components() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
A codet representing sequential composition of program statements.
static exprt conditional_cast(const exprt &expr, const typet &type)
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
codet invokedynamic_synthetic_method(const irep_idt &function_id, symbol_table_baset &symbol_table, message_handlert &message_handler)
Create the body for the synthetic method implementing an invokedynamic method.
@ LAMBDA_VIRTUAL_METHOD_HANDLE
Virtual call to the given interface or method.
reference_typet java_reference_type(const typet &subtype)
void set_synthetic(bool synthetic)
marks class synthetic
void set_declaring_class(symbolt &symbol, const irep_idt &declaring_class)
Sets the identifier of the class which declared a given symbol to declaring_class.
The type of an expression, extends irept.
std::vector< parametert > parameterst
std::vector< instructiont > instructionst
const class_typet & to_class_type(const typet &type)
Cast a typet to a class_typet.
const irept & find(const irep_idt &name) const
typet type
Type of symbol.
Operator to dereference a pointer.
static optionalt< java_class_typet::java_lambda_method_handlet > lambda_method_handle(const symbol_tablet &symbol_table, const irep_idt &method_identifier, const java_method_typet &dynamic_method_type)
void set_identifier(const irep_idt &identifier)
void add_base(const struct_tag_typet &base)
Add a base class/struct.
static const methods_by_name_and_descriptort get_interface_methods(const irep_idt &interface_id, const namespacet &ns)
Find all methods defined by this method and its parent types, returned as a map from const java_class...
void create_invokedynamic_synthetic_classes(const irep_idt &method_identifier, const java_bytecode_parse_treet::methodt::instructionst &instructions, symbol_tablet &symbol_table, synthetic_methods_mapt &synthetic_methods, message_handlert &message_handler)
optionalt< irep_idt > declaring_class(const symbolt &symbol)
Gets the identifier of the class which declared a given symbol.
A goto_instruction_codet representing the declaration of a local variable.
@ INVOKEDYNAMIC_CAPTURE_CONSTRUCTOR
A generated constructor for a class capturing the parameters of an invokedynamic instruction.
@ INVOKEDYNAMIC_METHOD
A generated method for a class capturing the parameters of an invokedynamic instruction.
Base class for all expressions.
irep_idt base_name
Base (non-scoped) name.
A struct tag type, i.e., struct_typet with an identifier.
const std::string message
static symbol_exprt create_and_declare_local(const irep_idt &function_id, const irep_idt &basename, const typet &type, symbol_table_baset &symbol_table, code_blockt &method)
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Internally generated symbol table entry.
std::unordered_map< irep_idt, synthetic_method_typet > synthetic_methods_mapt
Maps method names on to a synthetic method kind.
Expression to hold a symbol (variable)
bool can_cast_type< pointer_typet >(const typet &type)
Check whether a reference to a typet is a pointer_typet.
irep_idt pretty_name
Language-specific display name.
An expression describing a method on a class.
Represents a lambda call to a method.
irep_idt strip_java_namespace_prefix(const irep_idt &to_strip)
Strip java:: prefix from given identifier.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
std::map< const java_class_typet::methodt *, bool, compare_base_name_and_descriptort > methods_by_name_and_descriptort
Map from method, indexed by name and descriptor but not defining class, onto defined-ness (i....
typet & type()
Return the type of the expression.
const java_method_typet & type() const
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
goto_instruction_codet representation of a function call statement.
Return type for get_boxed_type_info_by_name.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
irep_idt mode
Language mode.
struct_tag_typet & subtype()
no_unique_unimplemented_method_exceptiont(const std::string &s)
const std::string & id2string(const irep_idt &d)
void set_tag(const irep_idt &tag)
std::vector< java_lambda_method_handlet > java_lambda_method_handlest
void set_is_constructor()
void set(const irep_idt &name, const irep_idt &value)
The symbol table base class interface.
const java_reference_typet & to_java_reference_type(const typet &type)
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
@ LAMBDA_CONSTRUCTOR_HANDLE
Instantiate the needed type then call a constructor.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
static optionalt< irep_idt > get_unboxing_method(const pointer_typet &maybe_boxed_type)
If maybe_boxed_type is a boxed primitive return its unboxing method; otherwise return empty.
const reference_typet & to_reference_type(const typet &type)
Cast a typet to a reference_typet.
symbolt synthetic_class_symbol(const irep_idt &synthetic_class_name, const java_class_typet::java_lambda_method_handlet &lambda_method_handle, const struct_tag_typet &functional_interface_tag, const java_method_typet &dynamic_method_type)
A codet representing an assignment in the program.
void create_method_stub_symbol(const irep_idt &identifier, const irep_idt &base_name, const irep_idt &pretty_name, const typet &type, const irep_idt &declaring_class, symbol_table_baset &symbol_table, message_handlert &message_handler)
@ UNKNOWN_HANDLE
Can't be called.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
exprt::operandst argumentst
void add(const codet &code)
const parameterst & parameters() const
nonstd::optional< T > optionalt
static const java_class_typet::methodt * try_get_unique_unimplemented_method(const symbol_tablet &symbol_table, const struct_tag_typet &functional_interface_tag, const irep_idt &method_identifier, const int instruction_address, const messaget &log)
static std::string escape_symbol_special_chars(std::string input)
void set_base_name(const irep_idt &name)
exprt box_or_unbox_type_if_necessary(exprt expr, const typet &required_type, code_blockt &code_block, symbol_table_baset &symbol_table, const irep_idt &function_id, const std::string &role)
If expr needs (un)boxing to satisfy required_type, add the required symbols to symbol_table and code ...
codet invokedynamic_synthetic_constructor(const irep_idt &function_id, symbol_table_baset &symbol_table, message_handlert &message_handler)
Create invokedynamic synthetic constructor.
exprt adjust_type_if_necessary(exprt expr, const typet &required_type, code_blockt &code_block, symbol_table_baset &symbol_table, const irep_idt &function_id, const std::string &role)
Box or unbox expr as per box_or_unbox_type_if_necessary, then cast the result to required_type.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
Extract member of struct or union.
const componentst & components() const
const irep_idt & get_descriptor() const
Gets the method's descriptor – the mangled form of its type.
#define POSTCONDITION(CONDITION)
exprt make_function_expr(const symbolt &function_symbol, const symbol_tablet &symbol_table)
Produce a class_method_descriptor_exprt or symbol_exprt for function_symbol depending on whether virt...
goto_instruction_codet representation of a "return from a function" statement.
int operator()(const java_class_typet::methodt *a, const java_class_typet::methodt *b) const
const typet & base_type() const
The type of the data what we point to.
signed int get_int(const irep_idt &name) const
void set_name(const irep_idt &name)
Set the name of the struct, which can be used to look up its symbol in the symbol table.
Symbol table entry describing a data type.
irep_idt clinit_wrapper_name(const irep_idt &class_name)
Get the Java static initializer wrapper name for a given class (the wrapper checks if static initiali...
const irep_idt unboxing_function_name
Name of the function defined on the boxed type that returns the boxed value.
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
const typet & return_type() const
static symbolt constructor_symbol(synthetic_methods_mapt &synthetic_methods, const irep_idt &synthetic_class_name, java_method_typet constructor_type)
static const symbolt & get_or_create_method_symbol(const irep_idt &identifier, const irep_idt &base_name, const irep_idt &pretty_name, const typet &type, const irep_idt &declaring_class, symbol_table_baset &symbol_table, message_handlert &log)
const java_class_typet & to_java_class_type(const typet &type)
Symbol table entry of function parameter.
const java_boxed_type_infot * get_boxed_type_info_by_name(const irep_idt &type_name)
If type_name is a Java boxed type tag, return information about it, otherwise return null.
static symbol_exprt instantiate_new_object(const irep_idt &function_id, const symbolt &lambda_method_symbol, symbol_table_baset &symbol_table, code_blockt &result)
Instantiates an object suitable for calling a given constructor (but does not actually call it).
static optionalt< java_class_typet::java_lambda_method_handlet > get_lambda_method_handle(const symbol_table_baset &symbol_table, const java_class_typet::java_lambda_method_handlest &lambda_method_handles, const size_t index)
Retrieves the symbol of the lambda method associated with the given lambda method handle (bootstrap m...
const java_method_typet & to_java_method_type(const typet &type)
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
struct bytecode_infot const bytecode_info[]
static symbolt implemented_method_symbol(synthetic_methods_mapt &synthetic_methods, const java_class_typet::methodt &method_to_implement, const irep_idt &synthetic_class_name)
irep_idt lambda_synthetic_class_name(const irep_idt &method_identifier, std::size_t instruction_address)
const java_primitive_type_infot * get_java_primitive_type_info(const typet &maybe_primitive_type)
If primitive_type is a Java primitive type, return information about it, otherwise return null.
irep_idt name
The unique identifier.
An expression containing a side effect.
Data structure for representing an arbitrary statement in a program.