ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
smt_sort.h
Go to the documentation of this file.
1#ifndef SOLVERS_SMT_SMT_SORT_H_
2#define SOLVERS_SMT_SMT_SORT_H_
3
4#include <irep2/irep2_type.h>
5
24
35
36class smt_sort;
37typedef const smt_sort *smt_sortt;
38
40{
41public:
46
48 : id(i), data_width(0), secondary_width(0), range_sort(nullptr)
49 {
50 assert(id != SMT_SORT_ARRAY);
51 }
52
54 : id(i),
55 data_width(0),
56 secondary_width(0),
57 range_sort(nullptr),
58 tupletype(type)
59 {
60 assert(i == SMT_SORT_STRUCT);
61 }
62
63 smt_sort(smt_sort_kind i, std::size_t width)
64 : id(i), data_width(width), secondary_width(0), range_sort(nullptr)
65 {
66 assert(id >= SMT_SORT_BV || id <= SMT_SORT_FIXEDBV);
67 }
68
69 smt_sort(smt_sort_kind i, std::size_t width, std::size_t sigwidth)
70 : id(i), data_width(width), secondary_width(sigwidth), range_sort(nullptr)
71 {
72 assert(id == SMT_SORT_BVFP || id == SMT_SORT_FPBV);
73 }
74
75 smt_sort(smt_sort_kind i, std::size_t dom_width, smt_sortt range_sort)
76 : id(i), data_width(dom_width), secondary_width(0), range_sort(range_sort)
77 {
78 assert(id == SMT_SORT_ARRAY);
79 }
80
83 const type2tc &type,
84 std::size_t dom_width,
85 smt_sortt range_sort)
86 : id(i),
87 data_width(dom_width),
88 secondary_width(0),
89 range_sort(range_sort),
90 tupletype(type)
91 {
92 assert(i == SMT_SORT_ARRAY);
93 }
94
95 size_t get_data_width() const
96 {
97 if (id == SMT_SORT_ARRAY)
98 return data_width * range_sort->data_width;
99 return data_width;
100 }
101
102 size_t get_domain_width() const
103 {
104 assert(id == SMT_SORT_ARRAY);
105 return data_width;
106 }
107
109 {
110 assert(id == SMT_SORT_ARRAY);
111 assert(range_sort != nullptr);
112 return range_sort;
113 }
114
116 {
117 assert(id == SMT_SORT_BVFP || id == SMT_SORT_FPBV);
118 return secondary_width;
119 }
120
121 size_t get_exponent_width() const
122 {
123 assert(id == SMT_SORT_BVFP || id == SMT_SORT_FPBV);
124 std::size_t exp_top = get_data_width() - 2;
125 std::size_t exp_bot = get_significand_width() - 2;
126 return (exp_top - exp_bot);
127 }
128
129 const type2tc &get_tuple_type() const
130 {
131 assert(!is_nil_type(tupletype));
132 return tupletype;
133 }
134
135 virtual ~smt_sort() = default;
136
137private:
142 size_t data_width;
143
147 size_t secondary_width;
148
152 smt_sortt range_sort;
153
158 const type2tc tupletype;
159};
160
161template <typename solver_sort>
163{
164public:
165 solver_smt_sort(smt_sort_kind i, solver_sort _s) : smt_sort(i), s(_s)
166 {
167 }
168
169 solver_smt_sort(smt_sort_kind i, solver_sort _s, const type2tc &_tupletype)
170 : smt_sort(i, _tupletype), s(_s)
171 {
172 }
173
174 solver_smt_sort(smt_sort_kind i, solver_sort _s, unsigned int w)
175 : smt_sort(i, w), s(_s)
176 {
177 }
178
181 solver_sort _s,
182 unsigned int w,
183 unsigned int sw)
184 : smt_sort(i, w, sw), s(_s)
185 {
186 }
187
190 solver_sort _s,
191 std::size_t dw,
192 const smt_sort *_rangesort)
193 : smt_sort(i, dw, _rangesort), s(_s)
194 {
195 }
196
199 solver_sort _s,
200 const type2tc &type,
201 std::size_t width,
202 smt_sortt range_sort)
203 : smt_sort(i, type, width, range_sort), s(_s)
204 {
205 }
206
207 ~solver_smt_sort() override = default;
208
209 solver_sort s;
210};
211
212#ifdef NDEBUG
213# define dynamic_cast static_cast
214#endif
215template <typename T>
217{
218 const solver_smt_sort<T> *r = dynamic_cast<const solver_smt_sort<T> *>(s);
219 assert(r);
220 return r;
221}
222#ifdef dynamic_cast
223# undef dynamic_cast
224#endif
225
226#endif /* SOLVERS_SMT_SMT_SORT_H_ */
Definition smt_sort.h:40
smt_sort(smt_sort_kind i)
Definition smt_sort.h:47
smt_sort(smt_sort_kind i, std::size_t width, std::size_t sigwidth)
Definition smt_sort.h:69
smt_sort(smt_sort_kind i, const type2tc &type, std::size_t dom_width, smt_sortt range_sort)
Definition smt_sort.h:81
smt_sort(smt_sort_kind i, const type2tc &type)
Definition smt_sort.h:53
size_t get_exponent_width() const
Definition smt_sort.h:121
smt_sort(smt_sort_kind i, std::size_t dom_width, smt_sortt range_sort)
Definition smt_sort.h:75
size_t get_significand_width() const
Definition smt_sort.h:115
const type2tc & get_tuple_type() const
Definition smt_sort.h:129
smt_sort_kind id
Identifies what /kind/ of sort this is.
Definition smt_sort.h:45
smt_sortt get_range_sort() const
Definition smt_sort.h:108
size_t get_domain_width() const
Definition smt_sort.h:102
size_t get_data_width() const
Definition smt_sort.h:95
virtual ~smt_sort()=default
smt_sort(smt_sort_kind i, std::size_t width)
Definition smt_sort.h:63
Definition smt_sort.h:163
solver_smt_sort(smt_sort_kind i, solver_sort _s, std::size_t dw, const smt_sort *_rangesort)
Definition smt_sort.h:188
~solver_smt_sort() override=default
solver_smt_sort(smt_sort_kind i, solver_sort _s, unsigned int w, unsigned int sw)
Definition smt_sort.h:179
solver_smt_sort(smt_sort_kind i, solver_sort _s, const type2tc &_tupletype)
Definition smt_sort.h:169
solver_sort s
Definition smt_sort.h:209
solver_smt_sort(smt_sort_kind i, solver_sort _s)
Definition smt_sort.h:165
solver_smt_sort(smt_sort_kind i, solver_sort _s, const type2tc &type, std::size_t width, smt_sortt range_sort)
Definition smt_sort.h:197
solver_smt_sort(smt_sort_kind i, solver_sort _s, unsigned int w)
Definition smt_sort.h:174
irep_container< type2t > type2tc
Definition irep2.h:430
bool is_nil_type(const type2tc &t)
Definition irep2.h:937
smt_sort_kind
Identifier for SMT sort kinds Each different kind of sort (i.e., arrays, bv's, bools,...
Definition smt_sort.h:11
@ SMT_SORT_FPBV_RM
Definition smt_sort.h:22
@ SMT_SORT_FIXEDBV
Definition smt_sort.h:15
@ SMT_SORT_FPBV
Definition smt_sort.h:20
@ SMT_SORT_BVFP
Definition smt_sort.h:19
@ SMT_SORT_STRUCT
Definition smt_sort.h:18
@ SMT_SORT_ARRAY
Definition smt_sort.h:16
@ SMT_SORT_REAL
Definition smt_sort.h:13
@ SMT_SORT_INT
Definition smt_sort.h:12
@ SMT_SORT_BOOL
Definition smt_sort.h:17
@ SMT_SORT_BVFP_RM
Definition smt_sort.h:21
@ SMT_SORT_BV
Definition smt_sort.h:14
const smt_sort * smt_sortt
Definition smt_sort.h:37
const solver_smt_sort< T > * to_solver_smt_sort(smt_sortt s)
Definition smt_sort.h:216