|
cprover
|
#include <java_string_library_preprocess.h>
Inheritance diagram for java_string_library_preprocesst:
Collaboration diagram for java_string_library_preprocesst:Public Member Functions | |
| java_string_library_preprocesst () | |
| void | initialize_known_type_table () |
| void | initialize_conversion_table () |
| fill maps with correspondence from java method names to conversion functions More... | |
| bool | implements_function (const irep_idt &function_id) const |
| void | get_all_function_names (std::unordered_set< irep_idt > &methods) const |
| codet | code_for_function (const symbolt &symbol, symbol_table_baset &symbol_table) |
| Should be called to provide code for string functions that are used in the code but for which no implementation is provided. More... | |
| codet | replace_character_call (code_function_callt call) |
| std::vector< irep_idt > | get_string_type_base_classes (const irep_idt &class_name) |
| Gets the base classes for known String and String-related types, or returns an empty list for other types. More... | |
| void | add_string_type (const irep_idt &class_name, symbol_tablet &symbol_table) |
| Add to the symbol table type declaration for a String-like Java class. More... | |
| bool | is_known_string_type (irep_idt class_name) |
| Check whether a class name is known as a string type. More... | |
Static Public Member Functions | |
| static bool | implements_java_char_sequence_pointer (const typet &type) |
| static bool | implements_java_char_sequence (const typet &type) |
Private Types | |
| typedef std::function< codet(const java_method_typet &, const source_locationt &, const irep_idt &, symbol_table_baset &)> | conversion_functiont |
| typedef std::unordered_map< irep_idt, irep_idt > | id_mapt |
Private Member Functions | |
| java_string_library_preprocesst (const java_string_library_preprocesst &)=delete | |
| code_blockt | make_float_to_string_code (const java_method_typet &type, const source_locationt &loc, const irep_idt &function_id, symbol_table_baset &symbol_table) |
| Provide code for the String.valueOf(F) function. More... | |
| code_blockt | make_string_format_code (const java_method_typet &type, const source_locationt &loc, const irep_idt &function_id, symbol_table_baset &symbol_table) |
| Used to provide code for the Java String.format function. More... | |
| code_blockt | make_copy_string_code (const java_method_typet &type, const source_locationt &loc, const irep_idt &function_id, symbol_table_baset &symbol_table) |
| Generates code for a function which copies a string object to a new string object. More... | |
| code_blockt | make_copy_constructor_code (const java_method_typet &type, const source_locationt &loc, const irep_idt &function_id, symbol_table_baset &symbol_table) |
| Generates code for a constructor of a string object from another string object. More... | |
| code_returnt | make_string_length_code (const java_method_typet &type, const source_locationt &loc, const irep_idt &function_id, symbol_table_baset &symbol_table) |
| Generates code for the String.length method. More... | |
| code_blockt | make_object_get_class_code (const java_method_typet &type, const source_locationt &loc, const irep_idt &function_id, symbol_table_baset &symbol_table) |
| Used to provide our own implementation of the java.lang.Object.getClass() function. More... | |
| exprt::operandst | process_parameters (const java_method_typet::parameterst ¶ms, const source_locationt &loc, symbol_table_baset &symbol_table, code_blockt &init_code) |
| calls string_refine_preprocesst::process_operands with a list of parameters. More... | |
| refined_string_exprt | convert_exprt_to_string_exprt (const exprt &deref, const source_locationt &loc, symbol_table_baset &symbol_table, code_blockt &init_code) |
| Creates a string_exprt from the input exprt representing a char sequence. More... | |
| exprt::operandst | process_operands (const exprt::operandst &operands, const source_locationt &loc, symbol_table_baset &symbol_table, code_blockt &init_code) |
for each expression that is of a type implementing strings, we declare a new cprover_string whose contents is deduced from the expression and replace the expression by this cprover_string in the output list; in the other case the expression is kept as is for the output list. More... | |
| exprt::operandst | process_equals_function_operands (const exprt::operandst &operands, const source_locationt &loc, symbol_table_baset &symbol_table, code_blockt &init_code) |
| Converts the operands of the equals function to string expressions and outputs these conversions. More... | |
| refined_string_exprt | replace_char_array (const exprt &array_pointer, const source_locationt &loc, symbol_table_baset &symbol_table, code_blockt &code) |
we declare a new cprover_string whose contents is deduced from the char array. More... | |
| symbol_exprt | fresh_string (const typet &type, const source_locationt &loc, symbol_table_baset &symbol_table) |
add a symbol with static lifetime and name containing cprover_string and given type More... | |
| symbol_exprt | fresh_array (const typet &type, const source_locationt &loc, symbol_tablet &symbol_table) |
add a symbol in the table with static lifetime and name containing cprover_string_array and given type More... | |
| refined_string_exprt | decl_string_expr (const source_locationt &loc, symbol_table_baset &symbol_table, code_blockt &code) |
| Add declaration of a refined string expr whose content and length are fresh symbols. More... | |
| refined_string_exprt | make_nondet_string_expr (const source_locationt &loc, const irep_idt &function_id, symbol_table_baset &symbol_table, code_blockt &code) |
| add symbols with prefix cprover_string_length and cprover_string_data and construct a string_expr from them. More... | |
| exprt | allocate_fresh_string (const typet &type, const source_locationt &loc, const irep_idt &function_id, symbol_table_baset &symbol_table, code_blockt &code) |
| declare a new String and allocate it More... | |
| codet | code_return_function_application (const irep_idt &function_name, const exprt::operandst &arguments, const typet &type, symbol_table_baset &symbol_table) |
| return the result of a function call More... | |
| refined_string_exprt | string_expr_of_function (const irep_idt &function_name, const exprt::operandst &arguments, const source_locationt &loc, symbol_table_baset &symbol_table, code_blockt &code) |
Create a refined_string_exprt str whose content and length are fresh symbols, calls the string primitive with name function_name. More... | |
| codet | code_assign_components_to_java_string (const exprt &lhs, const exprt &rhs_array, const exprt &rhs_length, const symbol_table_baset &symbol_table, bool is_constructor) |
| Produce code for an assignment of a string expr to a Java string. More... | |
| codet | code_assign_string_expr_to_java_string (const exprt &lhs, const refined_string_exprt &rhs, const symbol_table_baset &symbol_table, bool is_constructor) |
| Produce code for an assignemnt of a string expr to a Java string. More... | |
| void | code_assign_java_string_to_string_expr (const refined_string_exprt &lhs, const exprt &rhs, const source_locationt &loc, const symbol_table_baset &symbol_table, code_blockt &code) |
| refined_string_exprt | string_literal_to_string_expr (const std::string &s, const source_locationt &loc, symbol_table_baset &symbol_table, code_blockt &code) |
| Create a string expression whose value is given by a literal. More... | |
| code_blockt | make_function_from_call (const irep_idt &function_name, const java_method_typet &type, const source_locationt &loc, symbol_table_baset &symbol_table) |
| Provide code for a function that calls a function from the solver and simply returns it. More... | |
| code_blockt | make_init_function_from_call (const irep_idt &function_name, const java_method_typet &type, const source_locationt &loc, symbol_table_baset &symbol_table, bool is_constructor=true) |
| Generate the goto code for string initialization. More... | |
| code_blockt | make_assign_and_return_function_from_call (const irep_idt &function_name, const java_method_typet &type, const source_locationt &loc, symbol_table_baset &symbol_table) |
Call a cprover internal function, assign the result to object this and return it. More... | |
| code_blockt | make_assign_function_from_call (const irep_idt &function_name, const java_method_typet &type, const source_locationt &loc, symbol_table_baset &symbol_table) |
Call a cprover internal function and assign the result to object this. More... | |
| code_blockt | make_string_returning_function_from_call (const irep_idt &function_name, const java_method_typet &type, const source_locationt &loc, symbol_table_baset &symbol_table) |
| Provide code for a function that calls a function from the solver and return the string_expr result as a Java string. More... | |
| struct_exprt | make_argument_for_format (const exprt &argv, std::size_t index, const struct_typet &structured_type, const source_locationt &loc, const irep_idt &function_id, symbol_table_baset &symbol_table, code_blockt &code) |
| Helper for format function. More... | |
| optionalt< symbol_exprt > | get_primitive_value_of_object (const exprt &object, irep_idt type_name, const source_locationt &loc, symbol_table_baset &symbol_table, code_blockt &code) |
| Adds to the code an assignment of the form. More... | |
| dereference_exprt | get_object_at_index (const exprt &argv, std::size_t index) |
| Helper for format function. More... | |
Static Private Member Functions | |
| static bool | java_type_matches_tag (const typet &type, const std::string &tag) |
| static bool | is_java_string_pointer_type (const typet &type) |
| static bool | is_java_string_type (const typet &type) |
| static bool | is_java_string_builder_type (const typet &type) |
| static bool | is_java_string_builder_pointer_type (const typet &type) |
| static bool | is_java_string_buffer_type (const typet &type) |
| static bool | is_java_string_buffer_pointer_type (const typet &type) |
| static bool | is_java_char_sequence_type (const typet &type) |
| static bool | is_java_char_sequence_pointer_type (const typet &type) |
| static bool | is_java_char_array_type (const typet &type) |
| static bool | is_java_char_array_pointer_type (const typet &type) |
Private Attributes | |
| character_refine_preprocesst | character_preprocess |
| const typet | char_type |
| const typet | index_type |
| const refined_string_typet | refined_string_type |
| std::unordered_map< irep_idt, conversion_functiont > | conversion_table |
| id_mapt | cprover_equivalent_to_java_function |
| id_mapt | cprover_equivalent_to_java_string_returning_function |
| id_mapt | cprover_equivalent_to_java_constructor |
| id_mapt | cprover_equivalent_to_java_assign_and_return_function |
| id_mapt | cprover_equivalent_to_java_assign_function |
| const std::array< id_mapt *, 5 > | id_maps |
| std::unordered_set< irep_idt > | string_types |
Friends | |
| refined_string_exprt | convert_exprt_to_string_exprt_unit_test (java_string_library_preprocesst &preprocess, const exprt &deref, const source_locationt &loc, symbol_tablet &symbol_table, code_blockt &init_code) |
Additional Inherited Members |
Definition at line 35 of file java_string_library_preprocess.h.
|
private |
Definition at line 106 of file java_string_library_preprocess.h.
|
private |
Definition at line 108 of file java_string_library_preprocess.h.
|
inline |
Definition at line 38 of file java_string_library_preprocess.h.
|
privatedelete |
| void java_string_library_preprocesst::add_string_type | ( | const irep_idt & | class_name, |
| symbol_tablet & | symbol_table | ||
| ) |
Add to the symbol table type declaration for a String-like Java class.
| class_name | a name for the class such as "java.lang.String" |
| symbol_table | symbol table to which the class will be added |
Definition at line 208 of file java_string_library_preprocess.cpp.
|
private |
declare a new String and allocate it
| type | a type for string |
| loc | a location in the program |
| function_id | function the fresh string is created in |
| symbol_table | symbol table |
| code | code block to which allocation instruction will be added |
Definition at line 570 of file java_string_library_preprocess.cpp.
|
private |
Produce code for an assignment of a string expr to a Java string.
| lhs | expression representing the java string to assign to |
| rhs_array | pointer to the array to assign |
| rhs_length | length of the array to assign |
| symbol_table | symbol table |
| is_constructor | the assignment happens in the context of a constructor, so the whole object should be initialised, not just its length and data fields. |
Definition at line 828 of file java_string_library_preprocess.cpp.
|
private |
| lhs | a string expression | |
| rhs | an expression representing a java string | |
| loc | source location | |
| symbol_table | symbol table | |
| [out] | code | code block that gets appended the following code: lhs.length = rhs==null ? 0 : rhs->length lhs.data=rhs->data |
Definition at line 892 of file java_string_library_preprocess.cpp.
|
private |
Produce code for an assignemnt of a string expr to a Java string.
| lhs | an expression representing a java string |
| rhs | a string expression |
| symbol_table | symbol table |
| is_constructor | the assignment happens in the context of a constructor, so the whole object should be initialised, not just its length and data fields. |
Definition at line 873 of file java_string_library_preprocess.cpp.
| codet java_string_library_preprocesst::code_for_function | ( | const symbolt & | symbol, |
| symbol_table_baset & | symbol_table | ||
| ) |
Should be called to provide code for string functions that are used in the code but for which no implementation is provided.
| symbol | symbol of the function to provide code for |
| symbol_table | a symbol table |
Definition at line 1800 of file java_string_library_preprocess.cpp.
|
private |
return the result of a function call
| function_name | the name of the function |
| arguments | a list of arguments |
| type | the return type |
| symbol_table | a symbol table |
Definition at line 611 of file java_string_library_preprocess.cpp.
|
private |
Creates a string_exprt from the input exprt representing a char sequence.
| expr_to_process | an expression of a type which implements char sequence |
| loc | location in the source |
| symbol_table | symbol table |
| init_code | code block, in which declaration will be added: char *cprover_string_content; int cprover_string_length; cprover_string_length = a->length; cprover_string_content = a->data; |
Definition at line 301 of file java_string_library_preprocess.cpp.
|
private |
Add declaration of a refined string expr whose content and length are fresh symbols.
| loc | source location |
| symbol_table | the symbol table |
| code | [out] : code block to which the declaration is added |
Definition at line 499 of file java_string_library_preprocess.cpp.
|
private |
add a symbol in the table with static lifetime and name containing cprover_string_array and given type
| type | an array type |
| location | a location in the program |
| symbol_table | symbol table |
Definition at line 248 of file java_string_library_preprocess.cpp.
|
private |
add a symbol with static lifetime and name containing cprover_string and given type
| type | a type for refined strings |
| loc | a location in the program |
| symbol_table | symbol table |
Definition at line 482 of file java_string_library_preprocess.cpp.
| void java_string_library_preprocesst::get_all_function_names | ( | std::unordered_set< irep_idt > & | methods | ) | const |
Definition at line 1785 of file java_string_library_preprocess.cpp.
|
private |
Helper for format function.
Returns the expression:
which corresponds to the object at position index in argv.
| argv | reference to an array of references |
| index | index of the desired object |
index of argv. Definition at line 1293 of file java_string_library_preprocess.cpp.
|
private |
Adds to the code an assignment of the form.
and returns tmp_typename. In case the class corresponding to type_name is not available in symbol_table, the variable is declared but not assigned. Used to access the values of the arguments of String.format.
| object | an expression representing a reference to an object |
| type_name | name of the corresponding primitive type, this can be one of the following: ID_boolean, ID_char, ID_byte, ID_short, ID_int, ID_long, ID_float, ID_double, ID_void |
| loc | a location in the source |
| symbol_table | the symbol table |
| code | code block to which we are adding some assignments |
tmp_type_name where type_name is the given argument (ie. boolean, char etc.). Which represents the primitive value contained in the given object. Definition at line 1195 of file java_string_library_preprocess.cpp.
| std::vector< irep_idt > java_string_library_preprocesst::get_string_type_base_classes | ( | const irep_idt & | class_name | ) |
Gets the base classes for known String and String-related types, or returns an empty list for other types.
| class_name | class identifier, without "java::" prefix. |
Definition at line 182 of file java_string_library_preprocess.cpp.
| bool java_string_library_preprocesst::implements_function | ( | const irep_idt & | function_id | ) | const |
Definition at line 1761 of file java_string_library_preprocess.cpp.
|
inlinestatic |
Definition at line 70 of file java_string_library_preprocess.h.
|
inlinestatic |
Definition at line 63 of file java_string_library_preprocess.h.
| void java_string_library_preprocesst::initialize_conversion_table | ( | ) |
fill maps with correspondence from java method names to conversion functions
Definition at line 1857 of file java_string_library_preprocess.cpp.
| void java_string_library_preprocesst::initialize_known_type_table | ( | ) |
Definition at line 1848 of file java_string_library_preprocess.cpp.
|
staticprivate |
Definition at line 159 of file java_string_library_preprocess.cpp.
|
staticprivate |
| type | a type |
Definition at line 150 of file java_string_library_preprocess.cpp.
|
staticprivate |
| type | a type |
Definition at line 136 of file java_string_library_preprocess.cpp.
|
staticprivate |
| type | a type |
Definition at line 127 of file java_string_library_preprocess.cpp.
|
staticprivate |
| type | a type |
Definition at line 113 of file java_string_library_preprocess.cpp.
|
staticprivate |
| type | a type |
Definition at line 104 of file java_string_library_preprocess.cpp.
|
staticprivate |
| type | a type |
Definition at line 90 of file java_string_library_preprocess.cpp.
|
staticprivate |
| type | a type |
Definition at line 81 of file java_string_library_preprocess.cpp.
|
staticprivate |
| type | a type |
Definition at line 59 of file java_string_library_preprocess.cpp.
|
staticprivate |
| type | a type |
Definition at line 73 of file java_string_library_preprocess.cpp.
| bool java_string_library_preprocesst::is_known_string_type | ( | irep_idt | class_name | ) |
Check whether a class name is known as a string type.
| class_name | name of the class |
Definition at line 1842 of file java_string_library_preprocess.cpp.
|
staticprivate |
| type | a type |
| tag | a string |
Definition at line 51 of file java_string_library_preprocess.cpp.
|
private |
Helper for format function.
Adds code:
and returns arg_i_struct.
TODO: date_time and hash code are not implemented
| argv | reference to an array of references |
| index | index of the desired argument |
| structured_type | type for arguments of the internal format function |
| loc | a location in the source |
| function_id | function the generated expression will be used in |
| symbol_table | the symbol table |
| code | code block to which we are adding some assignments |
structured_type representing the possible values of the argument at position index of argv. Definition at line 1338 of file java_string_library_preprocess.cpp.
|
private |
Call a cprover internal function, assign the result to object this and return it.
| function_name | name of the function to be called |
| type | the type of the function call |
| loc | location in program |
| symbol_table | the symbol table to populate |
Definition at line 1138 of file java_string_library_preprocess.cpp.
|
private |
Call a cprover internal function and assign the result to object this.
| function_name | name of the function to be called |
| type | the type of the function call |
| loc | location in program |
| symbol_table | the symbol table to populate |
Definition at line 1163 of file java_string_library_preprocess.cpp.
|
private |
Generates code for a constructor of a string object from another string object.
| type | type of the function |
| loc | location in the source |
| function_id | unused |
| symbol_table | symbol table |
Definition at line 1701 of file java_string_library_preprocess.cpp.
|
private |
Generates code for a function which copies a string object to a new string object.
| type | type of the function |
| loc | location in the source |
| function_id | function the generated code will be added to |
| symbol_table | symbol table |
Definition at line 1658 of file java_string_library_preprocess.cpp.
|
private |
Provide code for the String.valueOf(F) function.
| type | type of the function call |
| loc | location in the program_invocation_name |
| function_id | function the generated code will be added to |
| symbol_table | symbol table |
Definition at line 955 of file java_string_library_preprocess.cpp.
|
private |
Provide code for a function that calls a function from the solver and simply returns it.
| function_name | name of the function to be called |
| type | type of the function |
| loc | location in the source |
| symbol_table | symbol table |
Definition at line 1584 of file java_string_library_preprocess.cpp.
|
private |
Generate the goto code for string initialization.
| function_name | name of the function to be called |
| type | the type of the function call |
| loc | location in program |
| symbol_table | the symbol table to populate |
| is_constructor | the function being made is a constructor, so the whole object should be initialised, not just its length and data fields. |
String.<init>(args) function: cprover_string_length = fun(arg).length;
cprover_string_array = fun(arg).data;
this->length = cprover_string_length;
this->data = cprover_string_array;
cprover_string = {.=cprover_string_length, .=cprover_string_array};
Definition at line 1096 of file java_string_library_preprocess.cpp.
|
private |
add symbols with prefix cprover_string_length and cprover_string_data and construct a string_expr from them.
| loc | a location in the program |
| function_id | name of the function containing the string |
| symbol_table | symbol table |
| code | code block to which allocation instruction will be added |
Definition at line 534 of file java_string_library_preprocess.cpp.
|
private |
Used to provide our own implementation of the java.lang.Object.getClass() function.
| type | type of the function called |
| loc | location in the source |
| function_id | function the generated code will be added to |
| symbol_table | the symbol table |
Definition at line 1504 of file java_string_library_preprocess.cpp.
|
private |
Used to provide code for the Java String.format function.
TODO: date_time and hash code are not implemented, and we set a limit of 10 arguments
| type | type of the function call |
| loc | location in the program_invocation_name |
| function_id | function the generated code will be used in |
| symbol_table | symbol table |
Definition at line 1444 of file java_string_library_preprocess.cpp.
|
private |
Generates code for the String.length method.
| type | type of the function |
| loc | location in the source |
| function_id | unused |
| symbol_table | symbol table |
Definition at line 1742 of file java_string_library_preprocess.cpp.
|
private |
Provide code for a function that calls a function from the solver and return the string_expr result as a Java string.
| function_name | name of the function to be called |
| type | type of the function |
| loc | location in the source |
| symbol_table | symbol table |
Definition at line 1614 of file java_string_library_preprocess.cpp.
|
private |
Converts the operands of the equals function to string expressions and outputs these conversions.
As a side effect of the conversions it adds some code to init_code.
| operands | a list of expressions |
| loc | location in the source |
| symbol_table | symbol table |
| init_code | code block, in which declaration of some arguments may be added |
Definition at line 356 of file java_string_library_preprocess.cpp.
|
private |
for each expression that is of a type implementing strings, we declare a new cprover_string whose contents is deduced from the expression and replace the expression by this cprover_string in the output list; in the other case the expression is kept as is for the output list.
Also does the same thing for char array references.
| operands | a list of expressions |
| loc | location in the source |
| symbol_table | symbol table |
| init_code | code block, in which declaration of some arguments may be added |
Definition at line 326 of file java_string_library_preprocess.cpp.
|
private |
calls string_refine_preprocesst::process_operands with a list of parameters.
| params | a list of function parameters |
| loc | location in the source |
| symbol_table | symbol table |
| init_code | code block, in which declaration of some arguments may be added |
Definition at line 271 of file java_string_library_preprocess.cpp.
|
private |
we declare a new cprover_string whose contents is deduced from the char array.
| array_pointer | an expression of type char array pointer |
| loc | location in the source |
| symbol_table | symbol table |
| code | code block, in which some assignments will be added |
Definition at line 446 of file java_string_library_preprocess.cpp.
|
inline |
Definition at line 54 of file java_string_library_preprocess.h.
|
private |
Create a refined_string_exprt str whose content and length are fresh symbols, calls the string primitive with name function_name.
In the arguments of the primitive str takes the place of the result and the following arguments are given by parameter `arguments.
| function_name | the name of the function | |
| arguments | arguments of the function | |
| loc | source location | |
| symbol_table | symbol table | |
| [out] | code | gets added the following code: int return_code; int str.length; char str.data[str.length] return_code = <function_name>(str.length, str.data, arguments) |
str Definition at line 780 of file java_string_library_preprocess.cpp.
|
private |
Create a string expression whose value is given by a literal.
| s | the literal to be assigned | |
| loc | location in the source | |
| symbol_table | symbol table | |
| [out] | code | gets added the following: tmp_string = "<s>" lhs = cprover_string_literal_func(tmp_string) |
Definition at line 938 of file java_string_library_preprocess.cpp.
|
friend |
|
private |
Definition at line 97 of file java_string_library_preprocess.h.
|
private |
Definition at line 95 of file java_string_library_preprocess.h.
|
private |
Definition at line 111 of file java_string_library_preprocess.h.
|
private |
Definition at line 127 of file java_string_library_preprocess.h.
|
private |
Definition at line 132 of file java_string_library_preprocess.h.
|
private |
Definition at line 123 of file java_string_library_preprocess.h.
|
private |
Definition at line 115 of file java_string_library_preprocess.h.
|
private |
Definition at line 119 of file java_string_library_preprocess.h.
|
private |
Definition at line 134 of file java_string_library_preprocess.h.
|
private |
Definition at line 98 of file java_string_library_preprocess.h.
|
private |
Definition at line 99 of file java_string_library_preprocess.h.
|
private |
Definition at line 146 of file java_string_library_preprocess.h.