26 const std::string src,
27 const std::string class_name_prefix,
28 const char opening_bracket,
29 const char closing_bracket);
100 static const auto result =
111 std::string subtype_str;
115 case 'b': subtype_str=
"byte";
break;
116 case 'f': subtype_str=
"float";
break;
117 case 'd': subtype_str=
"double";
break;
118 case 'i': subtype_str=
"int";
break;
119 case 'c': subtype_str=
"char";
break;
120 case 's': subtype_str=
"short";
break;
121 case 'z': subtype_str=
"boolean";
break;
122 case 'v': subtype_str=
"void";
break;
123 case 'j': subtype_str=
"long";
break;
124 case 'l': subtype_str=
"long";
break;
125 case 'a': subtype_str=
"reference";
break;
128 std::cout <<
"Unrecognised subtype str: " << subtype << std::endl;
133 irep_idt class_name=
"array["+subtype_str+
"]";
136 struct_tag_type.
set(ID_C_base_name, class_name);
148 "Symbol should have array tag");
149 return array_symbol.
find_type(ID_element_type);
158 "Symbol should have array tag");
159 return array_symbol.
add_type(ID_element_type);
171 const auto &subtype_struct_tag =
188 std::pair<typet, std::size_t>
191 std::size_t array_dimensions = 0;
192 typet underlying_type;
201 return {underlying_type, array_dimensions};
285 if(new_type==expr.
type())
301 const std::string &type_arguments,
302 const std::string &class_name_prefix)
306 PRECONDITION(type_arguments[type_arguments.size() - 1] ==
'>');
311 std::vector<typet> type_arguments_types =
319 type_arguments_types.begin(),
320 type_arguments_types.end(),
325 is_reference(type),
"All generic type arguments should be references");
326 return to_reference_type(type);
336 std::string class_name = src;
337 std::size_t f_pos = class_name.find(
'<', 1);
339 while(f_pos != std::string::npos)
342 if(e_pos == std::string::npos)
345 "Failed to find generic signature closing delimiter (or recursive "
351 class_name.erase(f_pos, e_pos - f_pos + 1);
354 f_pos = class_name.find(
'<', f_pos + 1);
371 std::string class_name = src.substr(1, src.size() - 2);
375 std::replace(class_name.begin(), class_name.end(),
'.',
'$');
376 std::replace(class_name.begin(), class_name.end(),
'/',
'.');
393 const std::string src,
394 const std::string class_name_prefix,
395 const char opening_bracket,
396 const char closing_bracket)
400 std::vector<typet> type_list;
401 for(
const std::string &raw_type :
405 INVARIANT(new_type.has_value(),
"Failed to parse type");
406 type_list.push_back(std::move(*new_type));
420 const std::string src,
421 const char opening_bracket,
422 const char closing_bracket)
430 std::vector<std::string> type_list;
431 for(std::size_t i = 1; i < src.size() - 1; i++)
434 while(i < src.size())
444 else if(src[i] ==
'[')
448 else if(src[i] ==
'T')
449 i = src.find(
';', i);
458 std::string sub_str = src.substr(start, i - start + 1);
459 type_list.emplace_back(sub_str);
480 std::string identifier =
"java::" + container_class;
482 struct_tag_type.
set(ID_C_base_name, container_class);
484 std::size_t f_pos = src.find(
'<', 1);
485 if(f_pos != std::string::npos)
492 if(e_pos == std::string::npos)
494 "Parsing type with unmatched generic bracket: " + src);
497 result, src.substr(f_pos, e_pos - f_pos + 1), class_name_prefix);
500 f_pos = src.find(
'<', e_pos + 1);
501 }
while(f_pos != std::string::npos);
502 return std::move(result);
517 const std::string src,
518 size_t starting_point)
521 size_t next_semi_colon = src.find(
';', starting_point);
523 next_semi_colon != std::string::npos,
524 "There must be a semi-colon somewhere in the input");
525 size_t next_angle_bracket = src.find(
'<', starting_point);
527 while(next_angle_bracket < next_semi_colon)
532 end_bracket != std::string::npos,
"Must find matching angle bracket");
534 next_semi_colon = src.find(
';', end_bracket + 1);
535 next_angle_bracket = src.find(
'<', end_bracket + 1);
538 return next_semi_colon;
562 const std::string &src,
563 const std::string &class_name_prefix)
593 if(closing_generic==std::string::npos)
596 "Failed to find generic signature closing delimiter");
603 const size_t colon_pos = src.find(
':');
604 if(colon_pos != std::string::npos && colon_pos < closing_generic)
607 "Cannot currently parse bounds on generic types");
611 src.substr(closing_generic + 1, std::string::npos), class_name_prefix);
618 method_type.has_value() && method_type->id() == ID_code,
619 "This should correspond to method signatures only");
625 std::size_t e_pos=src.rfind(
')');
626 if(e_pos==std::string::npos)
630 std::string(src, e_pos + 1, std::string::npos), class_name_prefix);
632 std::vector<typet> param_types =
640 std::back_inserter(parameters),
641 [](
const typet &type) { return java_method_typet::parametert(type); });
652 char subtype_letter=src[1];
654 src.substr(1, std::string::npos), class_name_prefix);
655 if(subtype_letter==
'L' ||
656 subtype_letter==
'[' ||
660 if(subtype_letter ==
'a')
681 INVARIANT(src[src.size()-1]==
';',
"Generic type name must end on ';'.");
683 irep_idt type_var_name(class_name_prefix+
"::"+src.substr(1, src.size()-2));
699 std::cout << class_name_prefix << std::endl;
724 else if(
id==ID_unsignedbv)
726 else if(
id==ID_floatbv)
734 else if(
id==ID_c_bool)
750 const std::string &class_name,
751 const std::string &src)
757 src[0]==
'<' && signature_end!=std::string::npos,
758 "Class signature has unexpected format");
759 std::string signature(src.substr(1, signature_end-1));
761 if(signature.find(
";:")!=std::string::npos)
766 std::vector<typet> types;
767 size_t var_sep=signature.find(
';');
768 while(var_sep!=std::string::npos)
770 size_t bound_sep=signature.find(
':');
771 INVARIANT(bound_sep!=std::string::npos,
"No bound for type variable.");
775 if(signature[bound_sep + 1] ==
':')
778 signature[bound_sep + 2] !=
':',
"Unknown bound for type variable.");
782 std::string type_var_name(
783 "java::"+class_name+
"::"+signature.substr(0, bound_sep));
784 std::string bound_type(signature.substr(bound_sep+1, var_sep-bound_sep));
792 types.push_back(type_var_type);
793 signature=signature.substr(var_sep+1, std::string::npos);
794 var_sep=signature.find(
';');
802 std::string result=src;
803 for(std::string::iterator it=result.begin(); it!=result.end(); it++)
811 if(!
id.empty() &&
id[0]==
'[')
815 std::string class_name=id;
818 irep_idt identifier=
"java::"+class_name;
820 struct_tag_type.
set(ID_C_base_name, class_name);
822 return struct_tag_type;
840 bool correct_num_components =
843 if(!correct_num_components)
850 if(base_class_component.
get_name() !=
"@java.lang.Object")
855 if(length_component.
get_name() !=
"length")
862 if(data_component.
get_name() !=
"data")
864 if(data_component.
type().
id() != ID_pointer)
872 array_element_type_component.
get_name() !=
897 bool arrays_with_same_element_type =
true;
899 type1.
id() == ID_pointer && type2.
id() == ID_pointer &&
903 const auto &subtype_symbol1 =
905 const auto &subtype_symbol2 =
908 subtype_symbol1.get_identifier() == subtype_symbol2.get_identifier() &&
911 const typet &array_element_type1 =
913 const typet &array_element_type2 =
916 arrays_with_same_element_type =
920 return (type1 == type2 && arrays_with_same_element_type);
923 std::vector<java_generic_parametert>
926 std::vector<java_generic_parametert> generic_parameters;
931 generic_parameters.insert(
932 generic_parameters.end(),
940 generic_parameters.insert(
941 generic_parameters.end(),
945 return generic_parameters;
950 std::set<irep_idt> &refs)
960 else if(t.
id() == ID_pointer)
967 else if(t.
id() == ID_code)
976 else if(t.
id() == ID_struct_tag)
979 const irep_idt class_name(struct_tag_type.get_identifier());
997 const std::string &signature,
998 std::set<irep_idt> &refs)
1003 if(signature[0] ==
'<')
1008 for(
const auto &t : types)
1013 else if(signature.find(
'*') == std::string::npos)
1015 auto type_from_string =
1034 std::set<irep_idt> &refs)
1050 const std::string &base_ref,
1051 const std::string &class_name_prefix)
1054 set(ID_C_java_generic_symbol,
true);
1061 "identifier of " + type.
pretty() +
"\n and identifier of type " +
1063 "\ncreated by java_type_from_string for " + base_ref +
1064 " should be equal");
1078 const auto &type_variable = type.
get_name();
1080 for(std::size_t i = 0; i < generics.size(); ++i)
1082 auto param = type_try_dynamic_cast<java_generic_parametert>(generics[i]);
1083 if(param && param->get_name() == type_variable)
1115 const auto &struct_tag_type =
1117 const irep_idt &
id = struct_tag_type.get_identifier();
1133 std::ostringstream result;
1137 for(
const auto &p : method_type.
parameters())
1151 return result.str();
static abstract_object_pointert transform(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns)
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
const signedbv_typet & to_signedbv_type(const typet &type)
Cast a typet to a signedbv_typet.
reference_typet reference_type(const typet &subtype)
std::size_t get_width() const
const typet & return_type() const
const parameterst & parameters() const
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
bool starts_with(const char *s) const
equivalent of as_string().starts_with(s)
Base class for all expressions.
typet & type()
Return the type of the expression.
Fixed-width bit-vector with IEEE floating-point interpretation.
static ieee_float_spect single_precision()
class floatbv_typet to_type() const
static ieee_float_spect double_precision()
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
void set(const irep_idt &name, const irep_idt &value)
const irep_idt & id() const
Class to hold a class with generics, extends the java class type with a vector of java generic type p...
const generic_typest & generic_types() const
Reference that points to a java_generic_parameter_tagt.
const irep_idt get_name() const
java_generic_struct_tag_typet(const struct_tag_typet &type)
const generic_typest & generic_types() const
std::optional< size_t > generic_type_index(const java_generic_parametert &type) const
Check if this symbol has the given generic type.
Reference that points to a java_generic_struct_tag_typet.
const generic_type_argumentst & generic_type_arguments() const
Type to hold a Java class that is implicitly generic, e.g., an inner class of a generic outer class o...
const implicit_generic_typest & implicit_generic_types() const
std::vector< parametert > parameterst
This is a specialization of reference_typet.
Extract member of struct or union.
const typet & base_type() const
The type of the data what we point to.
Fixed-width bit-vector with two's complement interpretation.
A struct tag type, i.e., struct_typet with an identifier.
Structure type, corresponds to C style structs.
const irep_idt & get_name() const
const componentst & components() const
const irep_idt & get_identifier() const
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
typet & add_type(const irep_idt &name)
const typet & find_type(const irep_idt &name) const
Fixed-width bit-vector with unsigned binary interpretation.
An exception that is raised for unsupported class signature.
const std::string & id2string(const irep_idt &d)
signedbv_typet java_int_type()
bool is_java_array_type(const typet &type)
Checks whether the given type is an array pointer type.
bool is_valid_java_array(const struct_typet &type)
Programmatic documentation of the structure of a Java array (of either primitives or references) type...
typet java_type_from_char(char t)
Constructs a type indicated by the given character:
void get_dependencies_from_generic_parameters(const std::string &signature, std::set< irep_idt > &refs)
Collect information about generic type parameters from a given signature.
std::string erase_type_arguments(const std::string &src)
Take a signature string and remove everything in angle brackets allowing for the type to be parsed no...
java_reference_typet java_reference_array_type(const struct_tag_typet &subtype)
empty_typet java_void_type()
std::string pretty_java_type(const typet &type)
char java_char_from_type(const typet &type)
bool equal_java_types(const typet &type1, const typet &type2)
Compares the types, including checking element types if both types are arrays.
std::vector< std::string > parse_raw_list_types(const std::string src, const char opening_bracket, const char closing_bracket)
Given a substring of a descriptor or signature that contains one or more types parse out the individu...
void get_dependencies_from_generic_parameters_rec(const typet &t, std::set< irep_idt > &refs)
struct_tag_typet java_classname(const std::string &id)
const typet & java_array_element_type(const struct_tag_typet &array_symbol)
Return a const reference to the element type of a given java array type.
signedbv_typet java_byte_type()
std::string pretty_signature(const java_method_typet &method_type)
typet java_bytecode_promotion(const typet &type)
Java does not support byte/short return types. These are always promoted.
java_reference_typet java_array_type(const char subtype)
Construct an array pointer type.
size_t find_closing_semi_colon_for_reference_type(const std::string src, size_t starting_point)
Finds the closing semi-colon ending a ClassTypeSignature that starts at starting_point.
std::pair< typet, std::size_t > java_array_dimension_and_element_type(const struct_tag_typet &type)
Returns the underlying element type and array dimensionality of Java struct type.
signedbv_typet java_short_type()
std::vector< typet > parse_list_types(const std::string src, const std::string class_name_prefix, const char opening_bracket, const char closing_bracket)
Given a substring of a descriptor or signature that contains one or more types parse out the individu...
std::optional< typet > java_type_from_string(const std::string &src, const std::string &class_name_prefix)
Transforms a string representation of a Java type into an internal type representation thereof.
static std::string slash_to_dot(const std::string &src)
floatbv_typet java_double_type()
reference_typet java_reference_type(const typet &subtype)
void add_generic_type_information(java_generic_typet &generic_type, const std::string &type_arguments, const std::string &class_name_prefix)
Take a list of generic type arguments and parse them into the generic type.
floatbv_typet java_float_type()
std::vector< java_generic_parametert > get_all_generic_parameters(const typet &type)
c_bool_typet java_boolean_type()
std::vector< typet > java_generic_type_from_string(const std::string &class_name, const std::string &src)
Converts the content of a generic class type into a vector of Java types, that is each type variable ...
unsignedbv_typet java_char_type()
exprt get_array_element_type_field(const exprt &pointer)
std::string gather_full_class_name(const std::string &src)
Returns the full class name, skipping over the generics.
bool is_java_array_tag(const irep_idt &tag)
See above.
signedbv_typet java_long_type()
reference_typet build_class_name(const std::string &src, const std::string &class_name_prefix)
For parsing a class type reference.
exprt get_array_dimension_field(const exprt &pointer)
java_reference_typet java_lang_object_type()
bool is_multidim_java_array_type(const typet &type)
Checks whether the given type is a multi-dimensional array pointer type, i.e., a pointer to an array ...
const java_class_typet & to_java_class_type(const typet &type)
const java_reference_typet & to_java_reference_type(const typet &type)
#define JAVA_REFERENCE_ARRAY_CLASSID
bool is_java_generic_type(const typet &type)
const java_method_typet & to_java_method_type(const typet &type)
const java_generic_class_typet & to_java_generic_class_type(const java_class_typet &type)
bool is_java_generic_class_type(const typet &type)
bool is_java_implicitly_generic_class_type(const typet &type)
const java_generic_typet & to_java_generic_type(const typet &type)
#define JAVA_ARRAY_ELEMENT_CLASSID_FIELD_NAME
#define JAVA_ARRAY_DIMENSION_FIELD_NAME
const java_implicitly_generic_class_typet & to_java_implicitly_generic_class_type(const java_class_typet &type)
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 strip_java_namespace_prefix(const irep_idt &to_strip)
Strip java:: prefix from given identifier.
bool can_cast_type< pointer_typet >(const typet &type)
Check whether a reference to a typet is a pointer_typet.
bool is_reference(const typet &type)
Returns true if the type is a reference.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const reference_typet & to_reference_type(const typet &type)
Cast a typet to a reference_typet.
#define CHECK_RETURN(CONDITION)
#define UNREACHABLE
This should be used to mark dead code.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
API to expression classes.
bool can_cast_type< struct_tag_typet >(const typet &type)
Check whether a reference to a typet is a struct_tag_typet.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
void replace(const union_find_replacet &replace_map, string_not_contains_constraintt &constraint)