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];
353 const exprt &end = args.size() >= 5 ? args[4] : s.
length();
370 const exprt &pointer,
384 return find(string_argument.op1(), string_argument.op0());
399 if(
id == ID_cprover_associate_array_to_pointer_func)
401 else if(
id == ID_cprover_associate_length_to_array_func)
417 if(
id==ID_cprover_char_literal_func)
419 else if(
id==ID_cprover_string_length_func)
421 else if(
id==ID_cprover_string_equal_func)
423 else if(
id==ID_cprover_string_equals_ignore_case_func)
425 else if(
id==ID_cprover_string_is_empty_func)
427 else if(
id==ID_cprover_string_char_at_func)
429 else if(
id==ID_cprover_string_is_prefix_func)
431 else if(
id==ID_cprover_string_is_suffix_func)
433 else if(
id==ID_cprover_string_startswith_func)
435 else if(
id==ID_cprover_string_endswith_func)
437 else if(
id==ID_cprover_string_contains_func)
439 else if(
id==ID_cprover_string_hash_code_func)
441 else if(
id==ID_cprover_string_index_of_func)
443 else if(
id==ID_cprover_string_last_index_of_func)
445 else if(
id==ID_cprover_string_parse_int_func)
447 else if(
id==ID_cprover_string_code_point_at_func)
449 else if(
id==ID_cprover_string_code_point_before_func)
451 else if(
id==ID_cprover_string_code_point_count_func)
453 else if(
id==ID_cprover_string_offset_by_code_point_func)
455 else if(
id==ID_cprover_string_compare_to_func)
457 else if(
id==ID_cprover_string_literal_func)
459 else if(
id==ID_cprover_string_concat_code_point_func)
461 else if(
id==ID_cprover_string_insert_func)
463 else if(
id==ID_cprover_string_insert_int_func)
465 else if(
id==ID_cprover_string_insert_long_func)
467 else if(
id==ID_cprover_string_insert_bool_func)
469 else if(
id==ID_cprover_string_insert_char_func)
471 else if(
id==ID_cprover_string_insert_double_func)
473 else if(
id==ID_cprover_string_insert_float_func)
475 else if(
id==ID_cprover_string_substring_func)
477 else if(
id==ID_cprover_string_trim_func)
479 else if(
id==ID_cprover_string_empty_string_func)
481 else if(
id==ID_cprover_string_copy_func)
483 else if(
id==ID_cprover_string_of_int_hex_func)
485 else if(
id==ID_cprover_string_of_float_func)
487 else if(
id==ID_cprover_string_of_float_scientific_notation_func)
489 else if(
id==ID_cprover_string_of_double_func)
491 else if(
id==ID_cprover_string_of_long_func)
493 else if(
id==ID_cprover_string_of_bool_func)
495 else if(
id==ID_cprover_string_of_char_func)
497 else if(
id==ID_cprover_string_set_length_func)
499 else if(
id==ID_cprover_string_delete_func)
501 else if(
id==ID_cprover_string_delete_char_at_func)
503 else if(
id==ID_cprover_string_replace_func)
505 else if(
id==ID_cprover_string_intern_func)
507 else if(
id==ID_cprover_string_format_func)
509 else if(
id == ID_cprover_string_constrain_characters_func)
514 "string_constraint_generator::function_application: unknown symbol :");
531 const auto &args=f.arguments();
537 const exprt count = args.size() == 3 ? str.
length() : args[4];
538 return add_axioms_for_substring(res, str, offset,
plus_exprt(offset, count));
571 const exprt &arg=args[0];
574 if(arg.operands().size()==1 &&
575 arg.op0().operands().size()==1 &&
576 arg.op0().op0().operands().size()==2 &&
577 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_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)
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.
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.
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
array_string_exprt make_char_array_for_char_pointer(const exprt &char_pointer, const typet &char_array_type)
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_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
exprt zero_if_negative(const exprt &expr)
Returns a non-negative version of the argument.
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_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_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
symbol_generatort fresh_symbol
exprt axiom_for_is_positive_index(const exprt &x)
expression true exactly when the index is positive