Go to the documentation of this file.
20 #include <unordered_set>
24 if(type.
id() != ID_struct)
33 if(t.
id()==ID_pointer)
36 const std::size_t bitwidth = t.
get_size_t(ID_width);
42 "all types constructed in java_types.cpp encode JVM types "
43 "with these bit widths");
45 return bitwidth == 64 ? 2u : 1u;
80 new_symbol.
type=class_type;
81 new_symbol.
mode=ID_java;
84 std::pair<symbolt &, bool> res=symbol_table.
insert(std::move(new_symbol));
90 "stub class symbol " <<
117 const std::string &friendly_name,
121 std::string qualified_name=
"java::"+friendly_name;
122 if(friendly_name.rfind(
':')==std::string::npos)
124 std::string prefix=qualified_name+
':';
125 std::set<irep_idt> matches;
127 for(
const auto &s : symbol_table.
symbols)
129 s.second.type.id()==ID_code)
130 matches.insert(s.first);
134 error=
"'"+friendly_name+
"' not found";
137 else if(matches.size()>1)
139 std::ostringstream message;
140 message <<
"'"+friendly_name+
"' is ambiguous between:";
143 for(
const auto &s : matches)
144 message <<
"\n " <<
id2string(s).substr(6);
151 return *matches.begin();
156 auto findit=symbol_table.
symbols.find(qualified_name);
157 if(findit==symbol_table.
symbols.end())
159 error=
"'"+friendly_name+
"' not found";
162 else if(findit->second.type.id()!=ID_code)
164 error=
"'"+friendly_name+
"' not a function";
169 return findit->first;
178 result.
set(ID_java_member_access,
true);
196 const std::string &src,
205 size_t c_pos=open_pos+1;
206 const size_t end_pos=src.size()-1;
209 while(c_pos<=end_pos)
211 if(src[c_pos] == open_char)
213 else if(src[c_pos] == close_char)
222 depth<=(src.size()-open_pos),
224 "\' found in signature to parse.");
227 return std::string::npos;
262 func_symbol.
mode=ID_java;
263 func_symbol.
name=function_name;
264 func_symbol.
type=type;
265 symbol_table.
add(func_symbol);
282 std::string fun_name=
id2string(function_name);
296 const std::string to_strip_str=
id2string(to_strip);
297 const std::string prefix=
"java::";
300 return to_strip_str.substr(prefix.size(), std::string::npos);
310 std::string result(fqn_java_type);
311 const std::string java_cbmc_string(
"java::");
313 if(
has_prefix(fqn_java_type, java_cbmc_string))
314 result = fqn_java_type.substr(java_cbmc_string.length());
317 const std::string java_lang_string(
"java.lang.");
319 result = result.substr(java_lang_string.length());
340 bool include_interfaces)
343 symbol_table, class_hierarchy);
345 component_resolver(component_class_id, component_name, include_interfaces);
355 return resolved_component;
358 const symbolt &component_symbol=
363 access = component_symbol.
type.
get(ID_C_access);
365 if(access==ID_public || access==ID_protected)
368 return resolved_component;
373 if(access==ID_default)
375 const std::string &class_package=
377 const std::string &component_package=
381 if(component_package == class_package)
382 return resolved_component;
387 if(access==ID_private)
412 static const irep_idt in =
"java::java.lang.System.in";
413 static const irep_idt out =
"java::java.lang.System.out";
414 static const irep_idt err =
"java::java.lang.System.err";
415 return symbolid == in || symbolid == out || symbolid == err;
Class that provides messages with a built-in verbosity 'level'.
const componentst & components() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
#define PRECONDITION(CONDITION)
Non-graph-based representation of the class hierarchy.
bool is_valid() const
Use to check if this inherited_componentt has been fully constructed.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
bool is_java_string_literal_id(const irep_idt &id)
The type of an expression, extends irept.
dereference_exprt checked_dereference(const exprt &expr, const typet &type)
Dereference an expression and flag it for a null-pointer check.
typet type
Type of symbol.
Operator to dereference a pointer.
const std::string java_class_to_package(const std::string &canonical_classname)
bool java_is_array_type(const typet &type)
void generate_class_stub(const irep_idt &class_name, symbol_table_baset &symbol_table, message_handlert &message_handler, const struct_union_typet::componentst &componentst)
Base class for all expressions.
std::vector< componentt > componentst
bool is_java_array_tag(const irep_idt &tag)
See above.
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
irep_idt get_full_component_identifier() const
Get the full name of this function.
irep_idt base_name
Base (non-scoped) name.
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Internally generated symbol table entry.
Expression to hold a symbol (variable)
#define UNREACHABLE
This should be used to mark dead code.
std::string trim_from_last_delimiter(const std::string &s, const char delim)
irep_idt pretty_name
Language-specific display name.
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.
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.
irep_idt mode
Language mode.
const std::string & id2string(const irep_idt &d)
void set_tag(const irep_idt &tag)
resolve_inherited_componentt::inherited_componentt get_inherited_component(const irep_idt &component_class_id, const irep_idt &component_name, 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.
The symbol table base class interface.
void merge(const source_locationt &from)
Set all unset source-location fields in this object to their values in 'from'.
void declare_function(irep_idt function_name, const typet &type, symbol_table_baset &symbol_table)
Declare a function with the given name and type.
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.
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...
bool is_non_null_library_global(const irep_idt &symbolid)
Check if a symbol is a well-known non-null global.
Application of (mathematical) function.
const irep_idt & id() const
std::vector< exprt > operandst
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 ...
const std::unordered_set< std::string > cprover_methods_to_ignore
Methods belonging to the class org.cprover.CProver that should be ignored (not converted),...
const parameterst & parameters() const
irep_idt get_class_identifier() const
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
void merge_source_location_rec(exprt &expr, const source_locationt &source_location)
Attaches a source location to an expression and all of its subexpressions.
Structure type, corresponds to C style structs.
unsigned java_method_parameter_slots(const java_method_typet &t)
Returns the the number of JVM local variables (slots) used by the JVM to pass, upon call,...
std::size_t get_size_t(const irep_namet &name) const
const irep_idt & get(const irep_namet &name) const
void set_is_stub(const bool &is_stub)
void set(const irep_namet &name, const irep_idt &value)
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.
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
void java_root_class(symbolt &class_symbol)
Create components to an object of the root class (usually java.lang.Object) Specifically,...
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
bool has_prefix(const std::string &s, const std::string &prefix)
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....
source_locationt & add_source_location()
mstreamt & warning() const
#define JAVA_STRING_LITERAL_PREFIX
irep_idt name
The unique identifier.
static irep_idt get_tag(const typet &type)