CBMC
Loading...
Searching...
No Matches
smt_terms.h
Go to the documentation of this file.
1// Author: Diffblue Ltd.
2
3#ifndef CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_TERMS_H
4#define CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_TERMS_H
5
6#include <util/irep.h>
7
9
10#include "smt_index.h"
11#include "smt_sorts.h"
12
13#include <functional>
14#include <utility>
15
16class BigInt; // IWYU pragma: keep
18
20class smt_termt : protected irept, private smt_sortt::storert<smt_termt>
21{
22public:
23 // smt_termt does not support the notion of an empty / null state. Use
24 // std::optional<smt_termt> instead if an empty term is required.
25 smt_termt() = delete;
26
27 using irept::pretty;
28
29 bool operator==(const smt_termt &) const;
30 bool operator!=(const smt_termt &) const;
31
32 const smt_sortt &get_sort() const;
33
36
42 template <typename derivedt>
43 class storert
44 {
45 protected:
47 static irept upcast(smt_termt term);
48 static const smt_termt &downcast(const irept &);
49 };
50
51protected:
53};
54
55template <typename derivedt>
57{
58 static_assert(
59 std::is_base_of<irept, derivedt>::value &&
60 std::is_base_of<storert<derivedt>, derivedt>::value,
61 "Only irept based classes need to upcast smt_termt to store it.");
62}
63
64template <typename derivedt>
66{
67 return static_cast<irept &&>(std::move(term));
68}
69
70template <typename derivedt>
72{
73 return static_cast<const smt_termt &>(irep);
74}
75
77{
78public:
79 explicit smt_bool_literal_termt(bool value);
80 bool value() const;
81};
82
92 private smt_indext::storert<smt_identifier_termt>
93{
94public:
110 smt_sortt sort,
111 std::vector<smt_indext> indices = {});
112 irep_idt identifier() const;
113 std::vector<std::reference_wrapper<const smt_indext>> indices() const;
114};
115
117{
118public:
120 smt_bit_vector_constant_termt(const mp_integer &value, std::size_t bit_width);
121 mp_integer value() const;
122
123 // This deliberately hides smt_termt::get_sort, because bit_vector terms
124 // always have bit_vector sorts. The same sort data is returned for both
125 // functions either way. Therefore this hiding is benign if the kind of sort
126 // is not important and useful for avoiding casts if the term is a known
127 // smt_bit_vector_constant_termt at compile time and the `bit_width()` is
128 // needed.
129 const smt_bit_vector_sortt &get_sort() const;
130};
131
133{
134private:
140 std::vector<smt_termt> arguments);
141
142 // This is used to detect if \p functiont has an `indicies` member function.
143 // It will resolve to std::true_type if it does or std::false type otherwise.
144 template <class functiont, class = void>
145 struct has_indicest : std::false_type
146 {
147 };
148
149 template <class functiont>
151 functiont,
152 std::void_t<decltype(std::declval<functiont>().indices())>> : std::true_type
153 {
154 };
155
158 template <class functiont>
159 static std::vector<smt_indext> indices(const functiont &function)
160 {
162 return function.indices();
163 else
164 return {};
165 }
166
167public:
169 std::vector<std::reference_wrapper<const smt_termt>> arguments() const;
170
171 template <typename functiont>
173 {
174 private:
176
177 public:
178 template <typename... function_type_argument_typest>
180 : function{std::forward<function_type_argument_typest>(arguments)...}
181 {
182 }
183
184 template <typename... argument_typest>
187 {
188 function.validate(arguments...);
189 auto return_sort = function.return_sort(arguments...);
192 function.identifier(), std::move(return_sort), indices(function)},
193 {std::forward<argument_typest>(arguments)...}};
194 }
195
196 template <typename... argument_typest>
199 {
200 const auto validation_errors = function.validation_errors(arguments...);
201 if(!validation_errors.empty())
202 return response_or_errort<smt_termt>{validation_errors};
203 auto return_sort = function.return_sort(arguments...);
206 function.identifier(), std::move(return_sort), indices(function)},
207 {std::forward<argument_typest>(arguments)...}}};
208 }
209 };
210};
211
213{
214public:
216 std::vector<smt_identifier_termt> bound_variables,
218 std::vector<std::reference_wrapper<const smt_identifier_termt>>
219 bound_variables() const;
220 const smt_termt &predicate() const;
221};
222
224{
225public:
227 std::vector<smt_identifier_termt> bound_variables,
229 std::vector<std::reference_wrapper<const smt_identifier_termt>>
230 bound_variables() const;
231 const smt_termt &predicate() const;
232};
233
235{
236public:
237#define TERM_ID(the_id) virtual void visit(const smt_##the_id##_termt &) = 0;
238#include "smt_terms.def"
239#undef TERM_ID
240};
241
242#endif // CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_TERMS_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
ait()
Definition ai.h:565
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition irep.h:364
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
Definition irep.cpp:482
const smt_bit_vector_sortt & get_sort() const
const smt_termt & predicate() const
std::vector< std::reference_wrapper< const smt_identifier_termt > > bound_variables() const
const smt_termt & predicate() const
std::vector< std::reference_wrapper< const smt_identifier_termt > > bound_variables() const
factoryt(function_type_argument_typest &&...arguments) noexcept
Definition smt_terms.h:179
response_or_errort< smt_termt > validation(argument_typest &&...arguments) const
Definition smt_terms.h:198
smt_function_application_termt operator()(argument_typest &&...arguments) const
Definition smt_terms.h:186
const smt_identifier_termt & function_identifier() const
static std::vector< smt_indext > indices(const functiont &function)
Returns function.indices() if functiont has an indices member function or returns an empty collection...
Definition smt_terms.h:159
std::vector< std::reference_wrapper< const smt_termt > > arguments() const
Stores identifiers in unescaped and unquoted form.
Definition smt_terms.h:93
irep_idt identifier() const
Definition smt_terms.cpp:81
std::vector< std::reference_wrapper< const smt_indext > > indices() const
Definition smt_terms.cpp:87
Class for adding the ability to up and down cast smt_indext to and from irept.
Definition smt_index.h:37
Class for adding the ability to up and down cast smt_sortt to and from irept.
Definition smt_sorts.h:39
Class for adding the ability to up and down cast smt_termt to and from irept.
Definition smt_terms.h:44
static irept upcast(smt_termt term)
Definition smt_terms.h:65
static const smt_termt & downcast(const irept &)
Definition smt_terms.h:71
const smt_sortt & get_sort() const
Definition smt_terms.cpp:36
bool operator==(const smt_termt &) const
Definition smt_terms.cpp:26
void accept(smt_term_const_downcast_visitort &) const
smt_termt()=delete
bool operator!=(const smt_termt &) const
Definition smt_terms.cpp:31
STL namespace.
Data structure for smt sorts.
BigInt mp_integer
Definition smt_terms.h:17