CBMC
array_pool.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: String solver
4 
5 Author: 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 
21 class symbol_generatort final
22 {
23 public:
28  operator()(const irep_idt &prefix, const typet &type = bool_typet());
29 
30 private:
31  unsigned symbol_count = 0;
32 
33 #ifdef DEBUG
34 public:
36  std::vector<symbol_exprt> created_symbols;
37 #endif
38 };
39 
41 class array_poolt final
42 {
43 public:
44  explicit array_poolt(symbol_generatort &symbol_generator)
45  : fresh_symbol(symbol_generator)
46  {
47  }
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 
88 private:
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 
112 array_string_exprt of_argument(array_poolt &array_pool, const exprt &arg);
113 
118 array_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.
Definition: array_pool.cpp:193
array_string_exprt get_string_expr(array_poolt &array_pool, const exprt &expr)
Fetch the string_exprt corresponding to the given refined_string_exprt.
Definition: array_pool.cpp:199
bitvector_typet char_type()
Definition: c_types.cpp:106
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
const std::unordered_map< exprt, array_string_exprt, irep_hash > & get_arrays_of_pointers() const
Definition: array_pool.h:50
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...
Definition: array_pool.cpp:48
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.
Definition: array_pool.cpp:74
exprt get_or_create_length(const array_string_exprt &s)
Get the length of an array_string_exprt from the array_pool.
Definition: array_pool.cpp:26
void insert(const exprt &pointer_expr, const array_string_exprt &array)
Definition: array_pool.cpp:160
array_string_exprt fresh_string(const typet &index_type, const typet &char_type)
Construct a string expression whose length and content are new variables.
Definition: array_pool.cpp:57
array_string_exprt find(const exprt &pointer, const exprt &length)
Creates a new array if the pointer is not pointing to an array.
Definition: array_pool.cpp:184
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.
Definition: array_pool.cpp:179
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.
Definition: array_pool.cpp:14
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.