32 : array_pool(fresh_symbol), ns(ns)
46 const std::vector<string_constraintt> &
52 const std::vector<string_not_contains_constraintt> &
58 const std::vector<symbol_exprt> &
64 const std::vector<symbol_exprt> &
70 const std::set<array_string_exprt> &
95 std::ostringstream buf;
96 buf <<
"string_refinement#" << prefix <<
"#" << ++
symbol_count;
179 const exprt &char_pointer,
180 const typet &char_array_type)
185 char_array_type.
subtype().
id() == ID_unsignedbv ||
186 char_array_type.
subtype().
id() == ID_signedbv);
188 if(char_pointer.
id() == ID_if)
203 const bool is_constant_array =
204 char_pointer.
id() == ID_address_of &&
206 char_pointer.
op0().
op0().
id() == ID_array;
207 if(is_constant_array)
212 const std::string symbol_name =
"char_array_" +
id2string(char_pointer.
id());
213 const auto array_sym =
215 const auto insert_result =
221 const exprt &pointer_expr,
229 array_expr.
length() = pair.first->second;
235 it_bool.second,
"should not associate two arrays to the same pointer");
313 const std::string &char_set)
318 const char &low_char = char_set[0];
319 const char &high_char = char_set[2];
323 const exprt chr = s[qvar];
352 const exprt &end = args.size() >= 5 ? args[4] : s.
length();
369 const exprt &pointer,
383 return find(string_argument.op1(), string_argument.op0());
398 if(
id == ID_cprover_associate_array_to_pointer_func)
400 else if(
id == ID_cprover_associate_length_to_array_func)
416 if(
id==ID_cprover_char_literal_func)
418 else if(
id==ID_cprover_string_length_func)
420 else if(
id==ID_cprover_string_equal_func)
422 else if(
id==ID_cprover_string_equals_ignore_case_func)
424 else if(
id==ID_cprover_string_is_empty_func)
426 else if(
id==ID_cprover_string_char_at_func)
428 else if(
id==ID_cprover_string_is_prefix_func)
430 else if(
id==ID_cprover_string_is_suffix_func)
432 else if(
id==ID_cprover_string_startswith_func)
434 else if(
id==ID_cprover_string_endswith_func)
436 else if(
id==ID_cprover_string_contains_func)
438 else if(
id==ID_cprover_string_hash_code_func)
440 else if(
id==ID_cprover_string_index_of_func)
442 else if(
id==ID_cprover_string_last_index_of_func)
444 else if(
id==ID_cprover_string_parse_int_func)
446 else if(
id==ID_cprover_string_code_point_at_func)
448 else if(
id==ID_cprover_string_code_point_before_func)
450 else if(
id==ID_cprover_string_code_point_count_func)
452 else if(
id==ID_cprover_string_offset_by_code_point_func)
454 else if(
id==ID_cprover_string_compare_to_func)
456 else if(
id==ID_cprover_string_literal_func)
458 else if(
id==ID_cprover_string_concat_func)
460 else if(
id==ID_cprover_string_concat_char_func)
462 else if(
id==ID_cprover_string_concat_code_point_func)
464 else if(
id==ID_cprover_string_insert_func)
466 else if(
id==ID_cprover_string_insert_int_func)
468 else if(
id==ID_cprover_string_insert_long_func)
470 else if(
id==ID_cprover_string_insert_bool_func)
472 else if(
id==ID_cprover_string_insert_char_func)
474 else if(
id==ID_cprover_string_insert_double_func)
476 else if(
id==ID_cprover_string_insert_float_func)
478 else if(
id==ID_cprover_string_substring_func)
480 else if(
id==ID_cprover_string_trim_func)
482 else if(
id==ID_cprover_string_to_lower_case_func)
484 else if(
id==ID_cprover_string_to_upper_case_func)
486 else if(
id==ID_cprover_string_char_set_func)
488 else if(
id==ID_cprover_string_empty_string_func)
490 else if(
id==ID_cprover_string_copy_func)
492 else if(
id==ID_cprover_string_of_int_func)
494 else if(
id==ID_cprover_string_of_int_hex_func)
496 else if(
id==ID_cprover_string_of_float_func)
498 else if(
id==ID_cprover_string_of_float_scientific_notation_func)
500 else if(
id==ID_cprover_string_of_double_func)
502 else if(
id==ID_cprover_string_of_long_func)
504 else if(
id==ID_cprover_string_of_bool_func)
506 else if(
id==ID_cprover_string_of_char_func)
508 else if(
id==ID_cprover_string_set_length_func)
510 else if(
id==ID_cprover_string_delete_func)
512 else if(
id==ID_cprover_string_delete_char_at_func)
514 else if(
id==ID_cprover_string_replace_func)
516 else if(
id==ID_cprover_string_intern_func)
518 else if(
id==ID_cprover_string_format_func)
520 else if(
id == ID_cprover_string_constrain_characters_func)
525 "string_constraint_generator::function_application: unknown symbol :");
542 const auto &args=f.arguments();
548 const exprt count = args.size() == 3 ? str.
length() : args[4];
549 return add_axioms_for_substring(res, str, offset,
plus_exprt(offset, count));
582 const exprt &arg=args[0];
585 if(arg.operands().size()==1 &&
586 arg.op0().operands().size()==1 &&
587 arg.op0().op0().operands().size()==2 &&
588 arg.op0().op0().op0().id()==ID_string_constant)
const if_exprt & to_if_expr(const exprt &expr)
Cast a generic exprt to an if_exprt.
exprt add_axioms_for_compare_to(const function_application_exprt &f)
Lexicographic comparison of two strings.
The type of an expression.
exprt add_axioms_for_insert(const array_string_exprt &res, const array_string_exprt &s1, const array_string_exprt &s2, const exprt &offset)
Add axioms ensuring the result res corresponds to s1 where we inserted s2 at position offset...
Generates string constraints to link results from string functions with their arguments.
std::vector< string_not_contains_constraintt > not_contains_constraints
const std::set< array_string_exprt > & get_created_strings() const
Set of strings that have been created by the generator.
exprt sum_overflows(const plus_exprt &sum)
exprt add_axioms_for_code_point_at(const function_application_exprt &f)
add axioms corresponding to the String.codePointAt java function
A generic base class for relations, i.e., binary predicates.
const std::string & id2string(const irep_idt &d)
application of (mathematical) function
const std::vector< string_constraintt > & get_constraints() const
static irep_idt get_function_name(const function_application_exprt &expr)
exprt add_axioms_from_literal(const function_application_exprt &f)
String corresponding to an internal cprover string.
const signedbv_typet get_return_code_type()
exprt add_axioms_from_int(const function_application_exprt &f)
Convert an integer to a string.
exprt add_axioms_for_empty_string(const function_application_exprt &f)
Add axioms to say that the returned string expression is empty.
exprt add_axioms_for_equals(const function_application_exprt &f)
Equality of the content of two strings.
const exprt & content() const
exprt add_axioms_for_length(const function_application_exprt &f)
Length of a string.
exprt add_axioms_for_insert_float(const function_application_exprt &f)
Add axioms corresponding to the StringBuilder.insert(F) java function.
const std::vector< exprt > & get_lemmas() const
Axioms are of three kinds: universally quantified string constraint, not contains string constraints ...
const irep_idt & get_identifier() const
exprt minimum(const exprt &a, const exprt &b)
const irep_idt & get_value() const
std::unordered_map< exprt, array_string_exprt, irep_hash > arrays_of_pointers
exprt add_axioms_for_contains(const function_application_exprt &f)
Test whether a string contains another.
exprt add_axioms_for_code_point_count(const function_application_exprt &f)
Add axioms corresponding the String.codePointCount java function.
exprt add_axioms_for_offset_by_code_point(const function_application_exprt &f)
Add axioms corresponding the String.offsetByCodePointCount java function.
symbol_exprt fresh_univ_index(const irep_idt &prefix, const typet &type)
generate an index symbol to be used as an universaly quantified variable
exprt associate_array_to_pointer(const function_application_exprt &f)
Associate a char array to a char pointer.
exprt get_length(const array_string_exprt &s) const
Associate an actual finite length to infinite arrays.
The trinary if-then-else operator.
std::vector< symbol_exprt > boolean_symbols
exprt associate_length_to_array(const function_application_exprt &f)
Associate an integer length to a char array.
exprt add_axioms_from_long(const function_application_exprt &f)
Add axioms corresponding to the String.valueOf(J) java function.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast a generic exprt to an address_of_exprt.
const std::vector< string_not_contains_constraintt > & get_not_contains_constraints() const
A constant literal expression.
#define CHECK_RETURN(CONDITION)
exprt add_axioms_for_is_empty(const function_application_exprt &f)
Add axioms stating that the returned value is true exactly when the argument string is empty...
exprt add_axioms_for_trim(const function_application_exprt &f)
Remove leading and trailing whitespaces.
exprt add_axioms_for_index_of(const array_string_exprt &str, const exprt &c, const exprt &from_index)
Add axioms stating that the returned value is the index within haystack (str) of the first occurrence...
void clear_constraints()
Clear all constraints and lemmas.
#define INVARIANT(CONDITION, REASON)
const std::vector< symbol_exprt > & get_boolean_symbols() const
Boolean symbols for the results of some string functions.
exprt add_axioms_for_function_application(const function_application_exprt &expr)
strings contained in this call are converted to objects of type string_exprt, through adding axioms...
exprt add_axioms_from_int_hex(const array_string_exprt &res, const exprt &i)
Add axioms stating that the string res corresponds to the integer argument written in hexadecimal...
exprt add_axioms_from_double(const function_application_exprt &f)
Add axioms corresponding to the String.valueOf(D) java function.
symbol_exprt fresh_boolean(const irep_idt &prefix)
generate a Boolean symbol which is existentially quantified
const irep_idt & id() const
exprt add_axioms_from_float_scientific_notation(const array_string_exprt &res, const exprt &f)
Add axioms to write the float in scientific notation.
const ssa_exprt & to_ssa_expr(const exprt &expr)
Cast a generic exprt to an ssa_exprt.
An expression denoting infinity.
array_string_exprt find(const exprt &pointer, const exprt &length)
Creates a new array if the pointer is not pointing to an array.
DEPRECATED("use instrument_cover_goals(goto_programt &goto_program," "const cover_instrumenterst &instrumenters," "message_handlert &message_handler, const irep_idt mode) instead") void instrument_cover_goals(const symbol_tablet &symbol_table
Instruments goto program for a given coverage criterion.
exprt add_axioms_for_hash_code(const function_application_exprt &f)
Value that is identical for strings with the same content.
exprt add_axioms_for_delete_char_at(const function_application_exprt &expr)
add axioms corresponding to the StringBuilder.deleteCharAt java function
exprt::operandst argumentst
std::vector< symbol_exprt > index_symbols
symbol_exprt add_axioms_for_intern(const function_application_exprt &f)
Add axioms corresponding to the String.intern java function.
exprt add_axioms_for_replace(const function_application_exprt &f)
Replace a character by another in a string.
exprt add_axioms_for_parse_int(const function_application_exprt &f)
Integer value represented by a string.
nonstd::optional< T > optionalt
exprt add_axioms_for_is_suffix(const function_application_exprt &f, bool swap_arguments=false)
Test if the target is a suffix of the string.
refined_string_exprt & to_string_expr(exprt &expr)
#define PRECONDITION(CONDITION)
exprt add_axioms_for_set_length(const function_application_exprt &f)
Reduce or extend a string to have the given length.
exprt add_axioms_for_equals_ignore_case(const function_application_exprt &f)
Equality of the content ignoring case of characters.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast a generic exprt to a symbol_exprt.
exprt add_axioms_for_char_literal(const function_application_exprt &f)
add axioms stating that the returned value is equal to the argument
symbol_exprt operator()(const irep_idt &prefix, const typet &type=bool_typet())
generate a new symbol expression of the given type with some prefix
bitvector_typet index_type()
auto expr_checked_cast(TExpr &base) -> typename detail::expr_dynamic_cast_return_typet< T, TExpr >::type
Cast a reference to a generic exprt to a specific derived class.
array_string_exprt make_char_array_for_char_pointer(const exprt &char_pointer, const typet &char_array_type)
exprt add_axioms_for_char_set(const function_application_exprt &f)
Set a character to a specific value at an index of the string.
array_string_exprt of_argument(const exprt &arg)
Converts a struct containing a length and pointer to an array.
exprt add_axioms_for_insert_double(const function_application_exprt &f)
add axioms corresponding to the StringBuilder.insert(D) java function
exprt add_axioms_for_insert_int(const function_application_exprt &f)
add axioms corresponding to the StringBuilder.insert(I) java function
Various predicates over pointers in programs.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast a generic exprt to a constant_exprt.
symbol_exprt & function()
void insert(const exprt &pointer_expr, array_string_exprt &array)
static constant_exprt constant_char(int i, const typet &char_type)
generate constant character expression with character type.
symbol_exprt fresh_exist_index(const irep_idt &prefix, const typet &type)
generate an index symbol which is existentially quantified
string_constraint_generatort(const namespacet &ns)
exprt add_axioms_for_copy(const function_application_exprt &f)
add axioms to say that the returned string expression is equal to the argument of the function applic...
exprt add_axioms_for_char_at(const function_application_exprt &f)
Character at a given position.
const string_constantt & to_string_constant(const exprt &expr)
exprt add_axioms_for_delete(const array_string_exprt &res, const array_string_exprt &str, const exprt &start, const exprt &end)
Add axioms stating that res corresponds to the input str where we removed characters between the posi...
exprt add_axioms_for_substring(const array_string_exprt &res, const array_string_exprt &str, const exprt &start, const exprt &end)
Add axioms ensuring that res corresponds to the substring of str between indexes ‘start’ = max(st...
void add_constraint_on_characters(const array_string_exprt &s, const exprt &start, const exprt &end, const std::string &char_set)
Add constraint on characters of a string.
const array_typet & to_array_type(const typet &type)
Cast a generic typet to an array_typet.
Base class for all expressions.
bool is_refined_string_type(const typet &type)
optionalt< exprt > make_array_pointer_association(const function_application_exprt &expr)
Associate array to pointer, and array to length.
exprt add_axioms_for_is_prefix(const array_string_exprt &prefix, const array_string_exprt &str, const exprt &offset)
Add axioms stating that the returned expression is true exactly when the offset is greater or equal t...
exprt add_axioms_from_bool(const function_application_exprt &f)
Add axioms corresponding to the String.valueOf(Z) java function.
exprt add_axioms_for_string_of_float(const function_application_exprt &f)
String representation of a float value.
irep_idt get_object_name() const
exprt add_axioms_for_format(const function_application_exprt &f)
Formatted string using a format string and list of arguments.
std::set< array_string_exprt > created_strings
bool is_ssa_expr(const exprt &expr)
const exprt & length() const
#define string_refinement_invariantt(reason)
Universally quantified string constraint
exprt add_axioms_for_to_lower_case(const function_application_exprt &f)
Conversion of a string to lower case.
exprt add_axioms_for_code_point_before(const function_application_exprt &f)
add axioms corresponding to the String.codePointBefore java function
std::vector< exprt > lemmas
exprt add_axioms_for_constrain_characters(const function_application_exprt &f)
Add axioms to ensure all characters of a string belong to a given set.
Expression to hold a symbol (variable)
const char * c_str() const
exprt add_axioms_for_insert_bool(const function_application_exprt &f)
add axioms corresponding to the StringBuilder.insert(Z) java function
const array_string_exprt & char_array_of_pointer(const exprt &pointer, const exprt &length)
Adds creates a new array if it does not already exists.
const typet & subtype() const
const irep_idt & get_value() const
#define DATA_INVARIANT(CONDITION, REASON)
std::vector< string_constraintt > constraints
std::unordered_map< array_string_exprt, symbol_exprt, irep_hash > length_of_array
array_string_exprt fresh_string(const typet &index_type, const typet &char_type)
construct a string expression whose length and content are new variables
exprt add_axioms_for_concat_char(const array_string_exprt &res, const array_string_exprt &s1, const exprt &c)
Add axioms enforcing that res is the concatenation of s1 with character c.
exprt add_axioms_from_char(const function_application_exprt &f)
Conversion from char to string.
const std::vector< symbol_exprt > & get_index_symbols() const
Symbols used in existential quantifications.
struct constructor from list of elements
const index_exprt & to_index_expr(const exprt &expr)
Cast a generic exprt to an index_exprt.
bitvector_typet char_type()
exprt add_axioms_for_concat(const array_string_exprt &res, const array_string_exprt &s1, const array_string_exprt &s2)
Add axioms enforcing that res is equal to the concatenation of s1 and s2.
exprt add_axioms_for_concat_code_point(const function_application_exprt &f)
Add axioms corresponding to the StringBuilder.appendCodePoint(I) function.
array_string_exprt get_string_expr(const exprt &expr)
casts an expression to a string expression, or fetches the actual string_exprt in the case of a symbo...
exprt maximum(const exprt &a, const exprt &b)
void add_lemma(const exprt &)
exprt add_axioms_for_insert_char(const function_application_exprt &f)
Add axioms corresponding to the StringBuilder.insert(C) java function.
array_string_exprt & to_array_string_expr(exprt &expr)
exprt add_axioms_for_last_index_of(const array_string_exprt &str, const exprt &c, const exprt &from_index)
Add axioms stating that the returned value is the index within haystack (str) of the last occurrence ...
symbol_generatort & fresh_symbol
exprt add_axioms_for_to_upper_case(const function_application_exprt &f)
Conversion of a string to upper case.
symbol_generatort fresh_symbol
exprt axiom_for_is_positive_index(const exprt &x)
expression true exactly when the index is positive