CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
array_pool.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: String solver
4
5Author: Romain Brenguier, romain.brenguier@diffblue.com
6
7\*******************************************************************/
8
13
14#ifndef CPROVER_SOLVERS_STRINGS_ARRAY_POOL_H
15#define CPROVER_SOLVERS_STRINGS_ARRAY_POOL_H
16
17#include <util/std_expr.h>
18#include <util/string_expr.h>
19
22{
23public:
28 operator()(const irep_idt &prefix, const typet &type = bool_typet());
29
30private:
31 unsigned symbol_count = 0;
32
33#ifdef DEBUG
34public:
36 std::vector<symbol_exprt> created_symbols;
37#endif
38};
39
41class array_poolt final
42{
43public:
48
49 const std::unordered_map<exprt, array_string_exprt, irep_hash> &
51 {
52 return arrays_of_pointers;
53 }
54
65
71 std::optional<exprt> get_length_if_exists(const array_string_exprt &s) const;
72
73 void insert(const exprt &pointer_expr, const array_string_exprt &array);
74
76 array_string_exprt find(const exprt &pointer, const exprt &length);
77
78 const std::unordered_map<array_string_exprt, exprt, irep_hash> &
79 created_strings() const;
80
86 fresh_string(const typet &index_type, const typet &char_type);
87
88private:
95 std::unordered_map<exprt, array_string_exprt, irep_hash> arrays_of_pointers;
96
98 std::unordered_map<array_string_exprt, exprt, irep_hash> length_of_array;
99
102
104 const exprt &char_pointer,
105 const typet &char_array_type);
106};
107
112array_string_exprt of_argument(array_poolt &array_pool, const exprt &arg);
113
118array_string_exprt get_string_expr(array_poolt &array_pool, const exprt &expr);
119
120#endif // CPROVER_SOLVERS_STRINGS_ARRAY_POOL_H
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.
bitvector_typet char_type()
Definition c_types.cpp:106
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
Correspondance between arrays and pointers string representations.
Definition array_pool.h:42
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 ...
Definition array_pool.h:95
array_poolt(symbol_generatort &symbol_generator)
Definition array_pool.h:44
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.
Definition array_pool.h:98
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.
const std::unordered_map< exprt, array_string_exprt, irep_hash > & get_arrays_of_pointers() const
Definition array_pool.h:50
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.
Definition array_pool.h:101
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.
The Boolean type.
Definition std_types.h:36
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
Base class for all expressions.
Definition expr.h:56
Expression to hold a symbol (variable)
Definition std_expr.h:131
Generation of fresh symbols of a given type.
Definition array_pool.h:22
symbol_exprt operator()(const irep_idt &prefix, const typet &type=bool_typet())
Generate a new symbol expression of the given type with some prefix.
unsigned symbol_count
Definition array_pool.h:31
The type of an expression, extends irept.
Definition type.h:29
API to expression classes.
String expressions for the string solver.