16 std::ostringstream buf;
17 buf <<
"string_refinement#" << prefix <<
"#" << ++
symbol_count;
21 created_symbols.push_back(result);
28 if(
const auto &if_expr = expr_try_dynamic_cast<if_exprt>((
exprt)s))
38 if(emplace_result.second)
40 emplace_result.first->second =
44 return emplace_result.first->second;
52 return find_result->second;
75 const exprt &char_pointer,
76 const typet &char_array_type)
81 to_array_type(char_array_type).element_type().
id() == ID_unsignedbv ||
82 to_array_type(char_array_type).element_type().
id() == ID_signedbv);
84 if(char_pointer.
id() == ID_if)
104 const bool is_constant_array =
105 char_pointer.
id() == ID_address_of &&
110 if(is_constant_array)
115 const std::string symbol_name =
"char_array_" +
id2string(char_pointer.
id());
116 const auto array_sym =
118 const auto insert_result =
137 std::unordered_map<array_string_exprt, exprt, irep_hash> &length_of_array,
141 array_expr.
id() != ID_if,
142 "attempt_assign_length_from_type does not handle if exprts");
147 const exprt &size_to_assign =
150 : symbol_generator(
"string_length", array_expr.
length_type());
152 const auto emplace_result =
153 length_of_array.emplace(array_expr, size_to_assign);
155 emplace_result.second,
156 "attempt_assign_length_from_type should only be called when no entry"
157 "for the array_string_exprt exists in the length_of_array map");
161 const exprt &pointer_expr,
168 it_bool.second,
"should not associate two arrays to the same pointer");
178 const std::unordered_map<array_string_exprt, exprt, irep_hash> &
195 const auto string_argument = expr_checked_cast<struct_exprt>(arg);
196 return array_pool.
find(string_argument.op1(), string_argument.op0());
static void attempt_assign_length_from_type(const array_string_exprt &array_expr, std::unordered_map< array_string_exprt, exprt, irep_hash > &length_of_array, symbol_generatort &symbol_generator)
Given an array_string_exprt, get the size of the underlying array.
array_string_exprt of_argument(array_poolt &array_pool, const exprt &arg)
Converts a struct containing a length and pointer to an array.
array_string_exprt get_string_expr(array_poolt &array_pool, const exprt &expr)
Fetch the string_exprt corresponding to the given refined_string_exprt.
Associates arrays and length to pointers, so that the string refinement can transform builtin functio...
bitvector_typet char_type()
Operator to return the address of an object.
Correspondance between arrays and pointers string representations.
std::unordered_map< exprt, array_string_exprt, irep_hash > arrays_of_pointers
Associate arrays to char pointers Invariant: Each array_string_exprt in this map has a corresponding ...
std::optional< exprt > get_length_if_exists(const array_string_exprt &s) const
As opposed to get_length(), do not create a new symbol if the length of the array_string_exprt does n...
std::unordered_map< array_string_exprt, exprt, irep_hash > length_of_array
Associate length to arrays of infinite size.
array_string_exprt make_char_array_for_char_pointer(const exprt &char_pointer, const typet &char_array_type)
Helper function for find.
exprt get_or_create_length(const array_string_exprt &s)
Get the length of an array_string_exprt from the array_pool.
void insert(const exprt &pointer_expr, const array_string_exprt &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.
array_string_exprt find(const exprt &pointer, const exprt &length)
Creates a new array if the pointer is not pointing to an array.
symbol_generatort & fresh_symbol
Generate fresh symbols.
const std::unordered_map< array_string_exprt, exprt, irep_hash > & created_strings() const
Return a map mapping all array_string_exprt of the array_pool to their length.
const typet & length_type() const
const exprt & size() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
typet & type()
Return the type of the expression.
The trinary if-then-else operator.
An expression denoting infinity.
const irep_idt & id() const
const typet & base_type() const
The type of the data what we point to.
const exprt & length() const
const exprt & content() const
Expression to hold a symbol (variable)
Generation of fresh symbols of a given type.
symbol_exprt operator()(const irep_idt &prefix, const typet &type=bool_typet())
Generate a new symbol expression of the given type with some prefix.
The type of an expression, extends irept.
const std::string & id2string(const irep_idt &d)
API to expression classes for Pointers.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
bool is_refined_string_type(const typet &type)
#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'.
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
array_string_exprt & to_array_string_expr(exprt &expr)
refined_string_exprt & to_string_expr(exprt &expr)