21 #include <unordered_set> 25 if(type.
id() != ID_struct)
34 if(t.
id()==ID_pointer)
45 "all types constructed in java_types.cpp encode JVM types " 46 "with these bit widths");
48 return bitwidth==64 ? 2 : 1;
75 class_type.
set(ID_base_name, class_name);
77 class_type.
set(ID_incomplete_class,
true);
84 class_type.
set(ID_name, new_symbol.
name);
85 new_symbol.
type=class_type;
86 new_symbol.
mode=ID_java;
89 std::pair<symbolt &, bool> res=symbol_table.
insert(std::move(new_symbol));
95 "stub class symbol " <<
122 const std::string &friendly_name,
126 std::string qualified_name=
"java::"+friendly_name;
127 if(friendly_name.rfind(
':')==std::string::npos)
129 std::string prefix=qualified_name+
':';
130 std::set<irep_idt> matches;
132 for(
const auto &s : symbol_table.
symbols)
134 s.second.type.id()==ID_code)
135 matches.insert(s.first);
139 error=
"'"+friendly_name+
"' not found";
142 else if(matches.size()>1)
144 std::ostringstream message;
145 message <<
"'"+friendly_name+
"' is ambiguous between:";
148 for(
const auto &s : matches)
149 message <<
"\n " <<
id2string(s).substr(6);
156 return *matches.begin();
161 auto findit=symbol_table.
symbols.find(qualified_name);
162 if(findit==symbol_table.
symbols.end())
164 error=
"'"+friendly_name+
"' not found";
167 else if(findit->second.type.id()!=ID_code)
169 error=
"'"+friendly_name+
"' not a function";
174 return findit->first;
183 result.
set(ID_java_member_access,
true);
201 const std::string &src,
210 size_t c_pos=open_pos+1;
211 const size_t end_pos=src.size()-1;
214 while(c_pos<=end_pos)
216 if(src[c_pos] == open_char)
218 else if(src[c_pos] == close_char)
227 depth<=(src.size()-open_pos),
229 "\' found in signature to parse.");
232 return std::string::npos;
250 components.push_back(component);
267 func_symbol.
mode=ID_java;
268 func_symbol.
name=function_name;
269 func_symbol.
type=type;
270 symbol_table.
add(func_symbol);
287 std::string fun_name=
id2string(function_name);
303 const std::string to_strip_str=
id2string(to_strip);
304 const std::string prefix=
"java::";
307 return to_strip_str.substr(prefix.size(), std::string::npos);
317 std::string result(fqn_java_type);
318 const std::string java_cbmc_string(
"java::");
320 if(
has_prefix(fqn_java_type, java_cbmc_string))
321 result = fqn_java_type.substr(java_cbmc_string.length());
324 const std::string java_lang_string(
"java.lang.");
326 result = result.substr(java_lang_string.length());
351 bool include_interfaces)
354 symbol_table, class_hierarchy);
356 component_resolver(component_class_id, component_name, include_interfaces);
366 return resolved_component;
369 const symbolt &component_symbol=
374 access = component_symbol.
type.
get(ID_C_access);
376 if(access==ID_public || access==ID_protected)
379 return resolved_component;
384 if(access==ID_default)
386 const std::string &class_package=
388 const std::string &component_package=
392 if(component_package == class_package)
393 return resolved_component;
398 if(access==ID_private)
423 static const std::unordered_set<irep_idt> non_null_globals = {
424 "java::java.lang.System.out",
425 "java::java.lang.System.err",
426 "java::java.lang.System.in"};
427 return non_null_globals.count(symbolid);
The type of an expression.
irep_idt name
The unique identifier.
#define JAVA_STRING_LITERAL_PREFIX
const std::string & id2string(const irep_idt &d)
dereference_exprt checked_dereference(const exprt &expr, const typet &type)
Dereference an expression and flag it for a null-pointer check.
application of (mathematical) function
void java_root_class(symbolt &class_symbol)
irep_idt mode
Language mode.
bool is_java_string_literal_id(const irep_idt &id)
bool java_is_array_type(const typet &type)
const std::string java_class_to_package(const std::string &canonical_classname)
irep_idt get_tag(const typet &type)
bool is_valid() const
Use to check if this inherited_componentt has been fully constructed.
std::vector< componentt > componentst
irep_idt pretty_name
Language-specific display name.
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
void generate_class_stub(const irep_idt &class_name, symbol_table_baset &symbol_table, message_handlert &message_handler, const struct_union_typet::componentst &componentst)
static mstreamt & eom(mstreamt &m)
bool is_java_array_tag(const irep_idt &tag)
See above.
#define INVARIANT(CONDITION, REASON)
unsigned java_method_parameter_slots(const code_typet &t)
Returns the the number of JVM local variables (slots) used by the JVM to pass, upon call...
mstreamt & warning() const
size_t find_closing_delimiter(const std::string &src, size_t open_pos, char open_char, char close_char)
Finds the corresponding closing delimiter to the given opening delimiter.
void merge(const source_locationt &from)
Set all unset source-location fields in this object to their values in 'from'.
const irep_idt & id() const
irep_idt strip_java_namespace_prefix(const irep_idt &to_strip)
Strip java:: prefix from given identifier.
exprt make_function_application(const irep_idt &function_name, const exprt::operandst &arguments, const typet &type, symbol_table_baset &symbol_table)
Create a function application expression.
Operator to dereference a pointer.
void java_add_components_to_class(symbolt &class_symbol, const struct_union_typet::componentst &components_to_add)
Add the components in components_to_add to the class denoted by class symbol.
const irep_idt & get(const irep_namet &name) const
Internally generated symbol table entryThis is a symbol generated as part of translation to or modifi...
#define PRECONDITION(CONDITION)
void set_tag(const irep_idt &tag)
bool has_prefix(const std::string &s, const std::string &prefix)
const std::unordered_set< std::string > cprover_methods_to_ignore
Methods belonging to the class org.cprover.CProver that should be ignored (not converted), leaving the driver program to stub them if it wishes.
unsigned java_local_variable_slots(const typet &t)
Returns the number of JVM local variables (slots) taken by a local variable that, when translated to ...
irep_idt resolve_friendly_method_name(const std::string &friendly_name, const symbol_table_baset &symbol_table, std::string &error)
Resolves a user-friendly method name (like packagename.Class.method) into an internal name (like java...
void declare_function(irep_idt function_name, const typet &type, symbol_table_baset &symbol_table)
Declare a function with the given name and type.
const struct_typet & to_struct_type(const typet &type)
Cast a generic typet to a struct_typet.
bool is_non_null_library_global(const irep_idt &symbolid)
Check if a symbol is a well-known non-null global.
std::vector< exprt > operandst
typet type
Type of symbol.
void merge_source_location_rec(exprt &expr, const source_locationt &source_location)
Attaches a source location to an expression and all of its subexpressions.
std::string trim_from_last_delimiter(const std::string &s, const char delim)
Base class for all expressions.
irep_idt get_class_identifier() const
const parameterst & parameters() const
irep_idt base_name
Base (non-scoped) name.
The symbol table base class interface.
std::string to_string(const string_constraintt &expr)
Used for debug printing.
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
unsigned int get_unsigned_int(const irep_namet &name) const
source_locationt & add_source_location()
Expression to hold a symbol (variable)
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
goto_programt coverage_criteriont message_handlert & message_handler
resolve_inherited_componentt::inherited_componentt get_inherited_component(const irep_idt &component_class_id, const irep_idt &component_name, const irep_idt &user_class_id, const symbol_tablet &symbol_table, const class_hierarchyt &class_hierarchy, bool include_interfaces)
Finds an inherited component (method or field), taking component visibility into account.
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
std::string pretty_print_java_type(const std::string &fqn_java_type)
Strip the package name from a java type, for the type to be pretty printed (java::java.lang.Integer -> Integer).
irep_idt get_full_component_identifier() const
Get the full name of this function.
void set(const irep_namet &name, const irep_idt &value)