#include <java_string_library_preprocess.h>
+ Collaboration diagram for java_string_library_preprocesst:
fill maps with correspondence from java method names to conversion functions
Should be called to provide code for string functions that are used in the code but for which no implementation is provided.
Gets the base classes for known String and String-related types, or returns an empty list for other types.
Add to the symbol table type declaration for a String-like Java class.
Check whether a class name is known as a string type.
Static Public Member Functions
Provide code for the String.valueOf(F) function.
Generates code for a function which copies a string object to a new string object.
Generates code for a constructor of a string object from another string object.
Generates code for the String.length method.
calls string_refine_preprocesst::process_operands with a list of parameters.
Creates a string_exprt from the input exprt representing a char sequence.
for each expression that is of a type implementing strings, we declare a new cprover_string whose contents is deduced from the expression, replace the expression by this cprover_string in the output list, and add an assumption that the object is not null; in the other case the expression is kept as is for the output list.
we declare a new cprover_string whose contents is deduced from the char array.
add a symbol with static lifetime and name containing cprover_string and given type
Add declaration of a refined string expr whose content and length are fresh symbols.
add symbols with prefix cprover_string_length and cprover_string_data and construct a string_expr from them.
declare a new String and allocate it
return the result of a function call
Create a
refined_string_exprt str whose content and length are fresh symbols, calls the string primitive with name
function_id.
Produce code for an assignment of a string expr to a Java string.
Produce code for an assignemnt of a string expr to a Java string.
Create a string expression whose value is given by a literal.
Provide code for a function that calls a function from the solver and simply returns it.
Generate the goto code for string initialization.
Call a cprover internal function, assign the result to object this and return it.
Call a cprover internal function and assign the result to object this.
Provide code for a function that calls a function from the solver and return the string_expr result as a Java string.
Static Private Member Functions
Detailed Description
Member Typedef Documentation
◆ conversion_functiont
◆ id_mapt
Constructor & Destructor Documentation
◆ java_string_library_preprocesst() [1/2]
java_string_library_preprocesst::java_string_library_preprocesst
(
)
inline
◆ java_string_library_preprocesst() [2/2]
Member Function Documentation
◆ add_string_type()
Add to the symbol table type declaration for a String-like Java class.
- Parameters
-
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 220 of file java_string_library_preprocess.cpp.
◆ allocate_fresh_string()
exprt java_string_library_preprocesst::allocate_fresh_string
(
const typet &
type,
)
private
declare a new String and allocate it
- Parameters
-
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
- Returns
- a new string
Definition at line 549 of file java_string_library_preprocess.cpp.
◆ code_assign_components_to_java_string()
codet java_string_library_preprocesst::code_assign_components_to_java_string
(
const exprt &
lhs,
)
private
Produce code for an assignment of a string expr to a Java string.
- Parameters
-
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.
- Returns
- return the following code:
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition at line 797 of file java_string_library_preprocess.cpp.
◆ code_assign_java_string_to_string_expr()
- Parameters
-
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 859 of file java_string_library_preprocess.cpp.
◆ code_assign_string_expr_to_java_string()
codet java_string_library_preprocesst::code_assign_string_expr_to_java_string
(
const exprt &
lhs,
)
private
Produce code for an assignemnt of a string expr to a Java string.
- Parameters
-
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.
- Returns
- return the following code:
lhs = { {
Object}, length=rhs.length, data=rhs.data }
Definition at line 840 of file java_string_library_preprocess.cpp.
◆ code_for_function()
Should be called to provide code for string functions that are used in the code but for which no implementation is provided.
- Parameters
-
symbol symbol of the function to provide code for
symbol_table a symbol table
message_handler a message handler
- Returns
- Code for the body of the String functions if they are part of the supported String functions, nil_exprt otherwise.
Definition at line 1462 of file java_string_library_preprocess.cpp.
◆ code_return_function_application()
codet java_string_library_preprocesst::code_return_function_application
(
const irep_idt &
function_id,
)
private
return the result of a function call
- Parameters
-
function_id the name of the function
arguments a list of arguments
type the return type
symbol_table a symbol table
- Returns
- the following code:
Definition at line 599 of file java_string_library_preprocess.cpp.
◆ convert_exprt_to_string_exprt()
Creates a string_exprt from the input exprt representing a char sequence.
- Parameters
-
expr_to_process an expression of a type which implements char sequence
loc location in the source
symbol_table symbol table
function_id name of the function in which the code will be added
init_code code block, in which declaration will be added:
- Returns
- the processed operand: {content=cprover_string_content, length=cprover_string_length}
Definition at line 309 of file java_string_library_preprocess.cpp.
◆ decl_string_expr()
Add declaration of a refined string expr whose content and length are fresh symbols.
- Parameters
-
loc source location
function_id name of the function in which the string is defined
symbol_table the symbol table
[out] code code block to which the declaration is added
- Returns
- refined string expr with fresh content and length symbols
Definition at line 487 of file java_string_library_preprocess.cpp.
◆ fresh_string()
add a symbol with static lifetime and name containing cprover_string and given type
- Parameters
-
type a type for refined strings
loc a location in the program
function_id name of the function in which the code will be added
symbol_table symbol table
- Returns
- a new symbol
Definition at line 468 of file java_string_library_preprocess.cpp.
◆ get_all_function_names()
void java_string_library_preprocesst::get_all_function_names
(
std::unordered_set<
irep_idt > &
methods )
const
◆ get_string_type_base_classes()
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.
- Parameters
-
class_name class identifier, without "java::" prefix.
- Returns
- a list of base classes, again without "java::" prefix.
Definition at line 187 of file java_string_library_preprocess.cpp.
◆ implements_function()
bool java_string_library_preprocesst::implements_function
(
const irep_idt &
function_id )
const
◆ implements_java_char_sequence()
◆ implements_java_char_sequence_pointer()
static bool java_string_library_preprocesst::implements_java_char_sequence_pointer
(
const typet &
type )
inlinestatic
◆ initialize_conversion_table()
void java_string_library_preprocesst::initialize_conversion_table
(
)
◆ initialize_known_type_table()
void java_string_library_preprocesst::initialize_known_type_table
(
)
◆ is_java_char_array_pointer_type()
bool java_string_library_preprocesst::is_java_char_array_pointer_type
(
const typet &
type )
staticprivate
◆ is_java_char_array_type()
bool java_string_library_preprocesst::is_java_char_array_type
(
const typet &
type )
staticprivate
◆ is_java_char_sequence_pointer_type()
bool java_string_library_preprocesst::is_java_char_sequence_pointer_type
(
const typet &
type )
staticprivate
◆ is_java_char_sequence_type()
bool java_string_library_preprocesst::is_java_char_sequence_type
(
const typet &
type )
staticprivate
◆ is_java_string_buffer_pointer_type()
bool java_string_library_preprocesst::is_java_string_buffer_pointer_type
(
const typet &
type )
staticprivate
◆ is_java_string_buffer_type()
bool java_string_library_preprocesst::is_java_string_buffer_type
(
const typet &
type )
staticprivate
◆ is_java_string_builder_pointer_type()
bool java_string_library_preprocesst::is_java_string_builder_pointer_type
(
const typet &
type )
staticprivate
◆ is_java_string_builder_type()
bool java_string_library_preprocesst::is_java_string_builder_type
(
const typet &
type )
staticprivate
◆ is_java_string_pointer_type()
bool java_string_library_preprocesst::is_java_string_pointer_type
(
const typet &
type )
staticprivate
◆ is_java_string_type()
bool java_string_library_preprocesst::is_java_string_type
(
const typet &
type )
staticprivate
◆ is_known_string_type()
bool java_string_library_preprocesst::is_known_string_type
(
irep_idt
class_name )
Check whether a class name is known as a string type.
- Parameters
-
class_name name of the class
- Returns
- True if the type is one that is known to our preprocessing, false otherwise
Definition at line 1505 of file java_string_library_preprocess.cpp.
◆ java_type_matches_tag()
bool java_string_library_preprocesst::java_type_matches_tag
(
const typet &
type,
)
staticprivate
- Parameters
-
type a type
tag a string
- Returns
- Boolean telling whether the type is a struct with the given tag or a symbolic type with the tag prefixed by "java::"
Definition at line 56 of file java_string_library_preprocess.cpp.
◆ make_assign_and_return_function_from_call()
Call a cprover internal function, assign the result to object this and return it.
- Parameters
-
function_id 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
- Returns
- Code calling function with the given function name.
Definition at line 1122 of file java_string_library_preprocess.cpp.
◆ make_assign_function_from_call()
Call a cprover internal function and assign the result to object this.
- Parameters
-
function_id 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
- Returns
- Code assigning result of a call to the function with given function name.
Definition at line 1147 of file java_string_library_preprocess.cpp.
◆ make_class_identifier_code()
Used to provide our own implementation of the CProver.classIdentifier() function.
- Parameters
-
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
message_handler a message handler
- Returns
- Code corresponding to
Definition at line 1171 of file java_string_library_preprocess.cpp.
◆ make_copy_constructor_code()
Generates code for a constructor of a string object from another string object.
- Parameters
-
type type of the function
loc location in the source
function_id name of the function (used for variable naming) where the generated code ends up.
symbol_table symbol table
message_handler a message handler
- Returns
- Code corresponding to:
Definition at line 1356 of file java_string_library_preprocess.cpp.
◆ make_copy_string_code()
Generates code for a function which copies a string object to a new string object.
- Parameters
-
type type of the function
loc location in the source
function_id function the generated code will be added to
symbol_table symbol table
message_handler a message handler
- Returns
- Code corresponding to:
str = new String
return str
Definition at line 1306 of file java_string_library_preprocess.cpp.
◆ make_float_to_string_code()
Provide code for the String.valueOf(F) function.
- Parameters
-
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
message_handler a message handler
- Returns
- Code corresponding to the Java conversion of floats to strings.
Definition at line 917 of file java_string_library_preprocess.cpp.
◆ make_function_from_call()
Provide code for a function that calls a function from the solver and simply returns it.
- Parameters
-
function_id name of the function to be called
type type of the function
loc location in the source
symbol_table symbol table
- Returns
- Code corresponding to:
Definition at line 1231 of file java_string_library_preprocess.cpp.
◆ make_init_function_from_call()
Generate the goto code for string initialization.
- Parameters
-
function_id 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.
- Returns
- code for the
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 1078 of file java_string_library_preprocess.cpp.
◆ make_nondet_string_expr()
add symbols with prefix cprover_string_length and cprover_string_data and construct a string_expr from them.
- Parameters
-
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
- Returns
- a new string_expr
Definition at line 512 of file java_string_library_preprocess.cpp.
◆ make_string_length_code()
Generates code for the String.length method.
- Parameters
-
type type of the function
loc location in the source
function_id unused
symbol_table symbol table
message_handler a message handler
- Returns
- Code corresponding to:
Definition at line 1401 of file java_string_library_preprocess.cpp.
◆ make_string_returning_function_from_call()
Provide code for a function that calls a function from the solver and return the string_expr result as a Java string.
- Parameters
-
function_id name of the function to be called
type type of the function
loc location in the source
symbol_table symbol table
- Returns
- Code corresponding to:
string = new String
return string
Definition at line 1261 of file java_string_library_preprocess.cpp.
◆ process_operands()
for each expression that is of a type implementing strings, we declare a new cprover_string whose contents is deduced from the expression, replace the expression by this cprover_string in the output list, and add an assumption that the object is not null; in the other case the expression is kept as is for the output list.
Also does the same thing for char array references.
- Parameters
-
operands a list of expressions
loc location in the source
function_id name of the function in which the code will be added
symbol_table symbol table
init_code code block, in which declaration of some arguments may be added
- Returns
- a list of expressions
Definition at line 337 of file java_string_library_preprocess.cpp.
◆ process_parameters()
calls string_refine_preprocesst::process_operands with a list of parameters.
- Parameters
-
params a list of function parameters
loc location in the source
function_id name of the function in which the code will be added
symbol_table symbol table
init_code code block, in which declaration of some arguments may be added
- Returns
- a list of expressions
Definition at line 280 of file java_string_library_preprocess.cpp.
◆ replace_char_array()
we declare a new cprover_string whose contents is deduced from the char array.
- Parameters
-
array_pointer an expression of type char array pointer
loc location in the source
function_id name of the function in which the string is defined
symbol_table symbol table
code code block, in which some assignments will be added
- Returns
- a string expression
Definition at line 431 of file java_string_library_preprocess.cpp.
◆ replace_character_call()
◆ string_expr_of_function()
Create a refined_string_exprt str whose content and length are fresh symbols, calls the string primitive with name function_id.
In the arguments of the primitive str takes the place of the result and the following arguments are given by parameter arguments. \param function_id: the name of the function \param arguments: arguments of the function \param loc: source location \param symbol_table: symbol table \param [out] code: gets added the following code: @icode int return_code; int str.length; char str.data[str.length] return_code = <function_id>(str.length, str.data, arguments) @endicode \return refined string expressionstr`
Definition at line 750 of file java_string_library_preprocess.cpp.
◆ string_literal_to_string_expr()
Create a string expression whose value is given by a literal.
- Parameters
-
s the literal to be assigned
loc location in the source
symbol_table symbol table
[out] code gets added the following:
- Returns
- a new refined string
Definition at line 896 of file java_string_library_preprocess.cpp.
Friends And Related Symbol Documentation
◆ convert_exprt_to_string_exprt_unit_test
Member Data Documentation
◆ char_type
const typet java_string_library_preprocesst::char_type
private
◆ character_preprocess
◆ conversion_table
◆ cprover_equivalent_to_java_assign_and_return_function
id_mapt java_string_library_preprocesst::cprover_equivalent_to_java_assign_and_return_function
private
◆ cprover_equivalent_to_java_assign_function
id_mapt java_string_library_preprocesst::cprover_equivalent_to_java_assign_function
private
◆ cprover_equivalent_to_java_constructor
id_mapt java_string_library_preprocesst::cprover_equivalent_to_java_constructor
private
◆ cprover_equivalent_to_java_function
id_mapt java_string_library_preprocesst::cprover_equivalent_to_java_function
private
◆ cprover_equivalent_to_java_string_returning_function
id_mapt java_string_library_preprocesst::cprover_equivalent_to_java_string_returning_function
private
◆ id_maps
const std::array<
id_mapt *, 5> java_string_library_preprocesst::id_maps
private
Initial value:= std::array<id_mapt *, 5>
{
{
}
}
id_mapt cprover_equivalent_to_java_string_returning_function
id_mapt cprover_equivalent_to_java_assign_and_return_function
id_mapt cprover_equivalent_to_java_function
id_mapt cprover_equivalent_to_java_constructor
id_mapt cprover_equivalent_to_java_assign_function
Definition at line 140 of file java_string_library_preprocess.h.
◆ index_type
const typet java_string_library_preprocesst::index_type
private
◆ refined_string_type
◆ string_types
std::unordered_set<
irep_idt> java_string_library_preprocesst::string_types
private
The documentation for this class was generated from the following files: