CBMC
arrays.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Theory of Arrays with Extensionality
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_SOLVERS_FLATTENING_ARRAYS_H
13 #define CPROVER_SOLVERS_FLATTENING_ARRAYS_H
14 
15 #include <list>
16 #include <set>
17 #include <unordered_set>
18 
19 #include <util/union_find.h>
20 
21 #include "equality.h"
22 
24 class array_exprt;
25 class array_of_exprt;
26 class equal_exprt;
27 class if_exprt;
28 class index_exprt;
29 class with_exprt;
30 class update_exprt;
31 
32 class arrayst:public equalityt
33 {
34 public:
35  arrayst(
36  const namespacet &_ns,
37  propt &_prop,
39  bool get_array_constraints = false);
40 
41  void finish_eager_conversion() override
42  {
47  }
48 
49  // NOLINTNEXTLINE(readability/identifiers)
50  typedef equalityt SUB;
51 
53  void record_array_index(const index_exprt &expr);
54 
55 protected:
56  const namespacet &ns;
59 
61  {
63  }
64 
66  {
69  };
70 
71  // the list of all equalities between arrays
72  // references to objects in this container need to be stable as
73  // elements are added while references are held
74  typedef std::list<array_equalityt> array_equalitiest;
76 
77  // this is used to find the clusters of arrays being compared
79 
80  // this tracks the array indicies for each array
81  typedef std::set<exprt> index_sett;
82  // references to values in this container need to be stable as
83  // elements are added while references are held
84  typedef std::map<std::size_t, index_sett> index_mapt;
86 
87  // adds array constraints lazily
88  enum class lazy_typet
89  {
91  ARRAY_WITH,
92  ARRAY_IF,
93  ARRAY_OF,
97  ARRAY_LET
98  };
99 
101  {
104 
105  lazy_constraintt(lazy_typet _type, const exprt &_lazy)
106  {
107  type = _type;
108  lazy = _lazy;
109  }
110  };
111 
115  std::list<lazy_constraintt> lazy_array_constraints;
116  void add_array_constraint(const lazy_constraintt &lazy, bool refine = true);
117  std::map<exprt, bool> expr_map;
118 
119  enum class constraint_typet
120  {
122  ARRAY_WITH,
123  ARRAY_IF,
124  ARRAY_OF,
129  ARRAY_LET
130  };
131 
132  typedef std::map<constraint_typet, size_t> array_constraint_countt;
135  std::string enum_to_string(constraint_typet);
136 
137  // adds all the constraints eagerly
138  void add_array_constraints();
141  const index_sett &index_set, const array_equalityt &array_equality);
143  const index_sett &index_set, const exprt &expr);
145  const index_sett &index_set, const if_exprt &exprt);
147  const index_sett &index_set, const with_exprt &expr);
149  const index_sett &index_set, const update_exprt &expr);
151  const index_sett &index_set, const array_of_exprt &exprt);
153  const index_sett &index_set,
154  const array_exprt &exprt);
156  const index_sett &index_set,
157  const array_comprehension_exprt &expr);
158 
159  void update_index_map(bool update_all);
160  void update_index_map(std::size_t i);
161  std::set<std::size_t> update_indices;
162  void collect_arrays(const exprt &a);
163  void collect_indices();
164  void collect_indices(const exprt &a);
165  std::unordered_set<irep_idt> array_comprehension_args;
166 
167  virtual bool is_unbounded_array(const typet &type) const=0;
168  // (maybe this function should be partially moved here from boolbv)
169 };
170 
171 #endif // CPROVER_SOLVERS_FLATTENING_ARRAYS_H
Expression to define a mapping from an argument (index) to elements.
Definition: std_expr.h:3423
Array constructor from list of elements.
Definition: std_expr.h:1621
Array constructor from single element.
Definition: std_expr.h:1558
Definition: arrays.h:33
std::list< lazy_constraintt > lazy_array_constraints
Definition: arrays.h:115
std::unordered_set< irep_idt > array_comprehension_args
Definition: arrays.h:165
index_mapt index_map
Definition: arrays.h:85
void add_array_constraints_equality(const index_sett &index_set, const array_equalityt &array_equality)
Definition: arrays.cpp:441
std::set< std::size_t > update_indices
Definition: arrays.h:161
const namespacet & ns
Definition: arrays.h:56
void add_array_constraints_array_of(const index_sett &index_set, const array_of_exprt &exprt)
Definition: arrays.cpp:709
void add_array_Ackermann_constraints()
Definition: arrays.cpp:330
bool lazy_arrays
Definition: arrays.h:112
void collect_indices()
Definition: arrays.cpp:83
void add_array_constraints_update(const index_sett &index_set, const update_exprt &expr)
Definition: arrays.cpp:652
void collect_arrays(const exprt &a)
Definition: arrays.cpp:131
message_handlert & message_handler
Definition: arrays.h:58
union_find< exprt, irep_hash > arrays
Definition: arrays.h:78
literalt record_array_equality(const equal_exprt &expr)
Definition: arrays.cpp:55
void add_array_constraints_array_constant(const index_sett &index_set, const array_exprt &exprt)
Definition: arrays.cpp:734
std::list< array_equalityt > array_equalitiest
Definition: arrays.h:74
arrayst(const namespacet &_ns, propt &_prop, message_handlert &message_handler, bool get_array_constraints=false)
Definition: arrays.cpp:29
constraint_typet
Definition: arrays.h:120
std::map< exprt, bool > expr_map
Definition: arrays.h:117
equalityt SUB
Definition: arrays.h:50
void add_array_constraints_if(const index_sett &index_set, const if_exprt &exprt)
Definition: arrays.cpp:839
void finish_eager_conversion() override
Definition: arrays.h:41
std::string enum_to_string(constraint_typet)
Definition: arrays.cpp:891
bool get_array_constraints
Definition: arrays.h:114
virtual void finish_eager_conversion_arrays()
Definition: arrays.h:60
void add_array_constraints()
Definition: arrays.cpp:280
void add_array_constraints_comprehension(const index_sett &index_set, const array_comprehension_exprt &expr)
Definition: arrays.cpp:815
virtual bool is_unbounded_array(const typet &type) const =0
void record_array_index(const index_exprt &expr)
Definition: arrays.cpp:45
array_equalitiest array_equalities
Definition: arrays.h:75
lazy_typet
Definition: arrays.h:89
std::map< constraint_typet, size_t > array_constraint_countt
Definition: arrays.h:132
std::set< exprt > index_sett
Definition: arrays.h:81
void add_array_constraint(const lazy_constraintt &lazy, bool refine=true)
adds array constraints (refine=true...lazily for the refinement loop)
Definition: arrays.cpp:255
array_constraint_countt array_constraint_count
Definition: arrays.h:133
void add_array_constraints_with(const index_sett &index_set, const with_exprt &expr)
Definition: arrays.cpp:573
bool incremental_cache
Definition: arrays.h:113
std::map< std::size_t, index_sett > index_mapt
Definition: arrays.h:84
void display_array_constraint_count()
Definition: arrays.cpp:918
void update_index_map(bool update_all)
Definition: arrays.cpp:407
messaget log
Definition: arrays.h:57
Equality.
Definition: std_expr.h:1366
void finish_eager_conversion() override
Definition: equality.h:31
Base class for all expressions.
Definition: expr.h:56
The trinary if-then-else operator.
Definition: std_expr.h:2380
Array index operator.
Definition: std_expr.h:1470
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:154
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
TO_BE_DOCUMENTED.
Definition: prop.h:25
The type of an expression, extends irept.
Definition: type.h:29
Operator to update elements in structs and arrays.
Definition: std_expr.h:2665
Operator to update elements in structs and arrays.
Definition: std_expr.h:2481
auto lazy(funt fun) -> lazyt< decltype(fun())>
Delay the computation of fun to the next time the force method is called.
Definition: lazy.h:49
lazy_constraintt(lazy_typet _type, const exprt &_lazy)
Definition: arrays.h:105