ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
std_types.h
Go to the documentation of this file.
1#ifndef CPROVER_STD_TYPES_H
2#define CPROVER_STD_TYPES_H
3
4#include <cassert>
7#include <util/irep/type.h>
8
9class bool_typet : public typet
10{
11public:
13 {
14 id(t_bool);
15 }
16};
17
18class empty_typet : public typet
19{
20public:
22 {
23 id(t_empty);
24 }
25};
26
27class symbol_typet : public typet
28{
29public:
31 {
32 }
33
38
43
44 const irep_idt &get_identifier() const
45 {
46 return get(a_identifier);
47 }
48};
49
60extern inline const symbol_typet &to_symbol_type(const typet &type)
61{
62 assert(type.id() == "symbol");
63 return static_cast<const symbol_typet &>(type);
64}
65
69extern inline symbol_typet &to_symbol_type(typet &type)
70{
71 assert(type.id() == "symbol");
72 return static_cast<symbol_typet &>(type);
73}
74
75// structs
76
78{
79public:
80 inline explicit struct_union_typet() = default;
81
82 inline explicit struct_union_typet(const irep_idt &_id) : typet(_id)
83 {
84 }
85
86 class componentt : public exprt
87 {
88 public:
90 {
91 }
92
93 inline componentt(const irep_idt &_name, const typet &_type)
95 {
96 set_name(_name);
97 type() = _type;
98 }
99
101 const irep_idt &_name,
102 const irep_idt &_pretty_name,
103 const typet &_type)
105 {
106 set_name(_name);
107 set_pretty_name(_pretty_name);
108 type() = _type;
109 }
110
111 const irep_idt &get_name() const
112 {
113 return get(a_name);
114 }
115
116 void set_name(const irep_idt &name)
117 {
118 return set(a_name, name);
119 }
120
121 inline const irep_idt &get_base_name() const
122 {
123 return get("base_name");
124 }
125
126 inline void set_base_name(const irep_idt &base_name)
127 {
128 return set("base_name", base_name);
129 }
130
131 inline const irep_idt &get_access() const
132 {
133 return get("access");
134 }
135
136 inline void set_access(const irep_idt &access)
137 {
138 return set("access", access);
139 }
140
141 inline const irep_idt &get_pretty_name() const
142 {
143 return get("pretty_name");
144 }
145
146 inline void set_pretty_name(const irep_idt &name)
147 {
148 return set("pretty_name", name);
149 }
150
151 inline bool get_anonymous() const
152 {
153 return get_bool("anonymous");
154 }
155
156 inline void set_anonymous(bool anonymous)
157 {
158 return set("anonymous", anonymous);
159 }
160
161 bool get_is_padding() const
162 {
163 return get_bool("is_padding");
164 }
165
166 void set_is_padding(bool is_padding)
167 {
168 return set("is_padding", is_padding);
169 }
170
172 {
173 return get_bool("is_unnamed_bitfield");
174 }
175
176 void set_is_unnamed_bitfield(bool is_unnamed_bitfield)
177 {
178 return set("is_unnamed_bitfield", is_unnamed_bitfield);
179 }
180 };
181
182 typedef std::vector<componentt> componentst;
183
184 const componentst &components() const
185 {
186 return (const componentst &)(find(a_components).get_sub());
187 }
188
190 {
191 return (componentst &)(add(a_components).get_sub());
192 }
193
195 {
197 }
198
199 const componentt &get_component(const irep_idt &component_name) const;
200
201 unsigned component_number(const irep_idt &component_name) const;
203
204 const componentst &methods() const
205 {
206 return (const componentst &)(find(a_methods).get_sub());
207 }
208
210 {
211 return (componentst &)(add(a_methods).get_sub());
212 }
213};
214
215extern inline const struct_union_typet &to_struct_union_type(const typet &type)
216{
217 assert(
218 type.id() == typet::t_struct || type.id() == typet::t_union ||
219 type.id() == typet::t_class || type.id() == typet::t_complex);
220 return static_cast<const struct_union_typet &>(type);
221}
222
224{
225 assert(
226 type.id() == typet::t_struct || type.id() == typet::t_union ||
227 type.id() == typet::t_class || type.id() == typet::t_complex);
228 return static_cast<struct_union_typet &>(type);
229}
230
232{
233public:
237
238 bool is_prefix_of(const struct_typet &other) const;
239};
240
241extern inline const struct_typet &to_struct_type(const typet &type)
242{
243 assert(
244 type.id() == typet::t_struct || type.id() == typet::t_union ||
245 type.id() == typet::t_class);
246 return static_cast<const struct_typet &>(type);
247}
248
249extern inline struct_typet &to_struct_type(typet &type)
250{
251 assert(
252 type.id() == typet::t_struct || type.id() == typet::t_union ||
253 type.id() == typet::t_class);
254 return static_cast<struct_typet &>(type);
255}
256
258{
259public:
263};
264
265extern inline const union_typet &to_union_type(const typet &type)
266{
267 assert(type.id() == typet::t_union);
268 return static_cast<const union_typet &>(type);
269}
270
271extern inline union_typet &to_union_type(typet &type)
272{
273 assert(type.id() == typet::t_union);
274 return static_cast<union_typet &>(type);
275}
276
277// functions
278
279class code_typet : public typet
280{
281public:
282 class argumentt;
283 typedef std::vector<argumentt> argumentst;
284
286 {
287 id(t_code);
288 }
289
290 code_typet(argumentst _parameters, typet _return_type) : typet(t_code)
291 {
292 arguments().swap(_parameters);
293 return_type().swap(_return_type);
294 }
295
296 class argumentt : public exprt
297 {
298 public:
300 {
301 }
302
304 {
305 }
306
307 const exprt &default_value() const
308 {
309 return find_expr("#default_value");
310 }
311
312 bool has_default_value() const
313 {
314 return default_value().is_not_nil();
315 }
316
318 {
319 return add_expr("#default_value");
320 }
321
326
328 {
330 }
331
333 {
334 return cmt_identifier();
335 }
336
337 const irep_idt &get_base_name() const
338 {
339 return cmt_base_name();
340 }
341 };
342
343 bool has_ellipsis() const
344 {
345 return find(a_arguments).ellipsis();
346 }
347
349 {
350 add(a_arguments).ellipsis(true);
351 }
352
353 const typet &return_type() const
354 {
355 return find_type("return_type");
356 }
357
359 {
360 return add_type("return_type");
361 }
362
363 const argumentst &arguments() const
364 {
365 return (const argumentst &)find(a_arguments).get_sub();
366 }
367
369 {
370 return (argumentst &)add(a_arguments).get_sub();
371 }
372
373 inline bool get_inlined() const
374 {
375 return get_bool("#inlined");
376 }
377
378 inline void set_inlined(bool value)
379 {
380 set("#inlined", value);
381 }
382};
383
384extern inline const code_typet &to_code_type(const typet &type)
385{
386 assert(type.id() == typet::t_code);
387 return static_cast<const code_typet &>(type);
388}
389
390extern inline code_typet &to_code_type(typet &type)
391{
392 assert(type.id() == typet::t_code);
393 return static_cast<code_typet &>(type);
394}
395
396class array_typet : public typet
397{
398public:
400 {
401 }
402
403 array_typet(const typet &_subtype) : typet(t_array)
404 {
405 subtype() = _subtype;
406 }
407
408 array_typet(const typet &_subtype, const exprt &_size) : typet(t_array)
409 {
410 subtype() = _subtype;
411 size() = _size;
412 }
413
414 const exprt &size() const
415 {
416 return (const exprt &)find(a_size);
417 }
418
420 {
421 return (exprt &)add(a_size);
422 }
423};
424
425extern inline const array_typet &to_array_type(const typet &type)
426{
427 assert(type.id() == typet::t_array);
428 return static_cast<const array_typet &>(type);
429}
430
431extern inline array_typet &to_array_type(typet &type)
432{
433 assert(type.id() == typet::t_array);
434 return static_cast<array_typet &>(type);
435}
436
437class pointer_typet : public typet
438{
439public:
441 {
442 id(t_pointer);
443 }
444
445 explicit pointer_typet(const typet &_subtype)
446 {
447 id(t_pointer);
448 subtype() = _subtype;
449 }
450};
451
460inline const pointer_typet &to_pointer_type(const typet &type)
461{
462 assert(type.id() == "pointer");
463 return static_cast<const pointer_typet &>(type);
464}
465
468{
469 assert(type.id() == "pointer");
470 return static_cast<pointer_typet &>(type);
471}
472
474{
475public:
477 {
478 set(t_reference, true);
479 }
480};
481
482bool is_reference(const typet &type);
483bool is_rvalue_reference(const typet &type);
484bool is_lvalue_or_rvalue_reference(const typet &type);
485
486class bv_typet : public typet
487{
488public:
490 {
491 id(t_bv);
492 }
493
494 explicit bv_typet(unsigned width)
495 {
496 id(t_bv);
498 }
499
500 unsigned get_width() const;
501
502 void set_width(unsigned width)
503 {
504 set(a_width, width);
505 }
506};
507
509{
510public:
512 {
514 }
515
516 explicit unsignedbv_typet(unsigned width)
517 {
520 }
521
522 BigInt smallest() const;
523 BigInt largest() const;
527};
528
539inline const unsignedbv_typet &to_unsignedbv_type(const typet &type)
540{
541 assert(type.id() == "unsignedbv");
542 return static_cast<const unsignedbv_typet &>(type);
543}
544
549{
550 assert(type.id() == "unsignedbv");
551 return static_cast<unsignedbv_typet &>(type);
552}
553
555{
556public:
558 {
559 id(t_signedbv);
560 }
561
562 explicit signedbv_typet(unsigned width)
563 {
564 id(t_signedbv);
566 }
567
568 BigInt smallest() const;
569 BigInt largest() const;
573};
574
585inline const signedbv_typet &to_signedbv_type(const typet &type)
586{
587 assert(type.id() == "signedbv");
588 return static_cast<const signedbv_typet &>(type);
589}
590
595{
596 assert(type.id() == "signedbv");
597 return static_cast<signedbv_typet &>(type);
598}
600{
601public:
603 {
604 id(t_fixedbv);
605 }
606
607 unsigned get_fraction_bits() const
608 {
609 return get_width() - get_integer_bits();
610 }
611
612 unsigned get_integer_bits() const;
613
614 void set_integer_bits(unsigned b)
615 {
617 }
618
620 {
621 assert(type.id() == t_fixedbv);
622 return static_cast<const fixedbv_typet &>(type);
623 }
624};
625
626const fixedbv_typet &to_fixedbv_type(const typet &type);
627
629{
630public:
632 {
633 id(t_floatbv);
634 }
635
636 unsigned get_e() const
637 {
638 return get_width() - get_f() - 1;
639 }
640
641 unsigned get_f() const;
642
643 void set_f(unsigned b)
644 {
645 set(a_f, b);
646 }
647
649 {
650 assert(type.id() == t_floatbv);
651 return static_cast<const floatbv_typet &>(type);
652 }
653};
654
655const floatbv_typet &to_floatbv_type(const typet &type);
656
658{
659public:
663
664 const typet &base_type() const
665 {
666 return subtype();
667 }
668
670 {
671 subtype() = base;
672 components().clear();
673 components().emplace_back("real", "real", base);
674 components().emplace_back("imag", "imag", base);
675 }
676
678 {
679 assert(type.id() == t_complex);
680 return static_cast<const complex_typet &>(type);
681 }
682};
683
684const complex_typet &to_complex_type(const typet &type);
685
694class vector_typet : public typet
695{
696public:
698 {
699 }
700
701 vector_typet(const typet &_subtype) : typet(t_vector)
702 {
703 subtype() = _subtype;
704 }
705
706 vector_typet(const typet &_subtype, const exprt &_size) : typet(t_vector)
707 {
708 subtype() = _subtype;
709 size() = _size;
710 }
711
712 const exprt &size() const
713 {
714 return (const exprt &)find(a_size);
715 }
716
718 {
719 return (exprt &)add(a_size);
720 }
721};
722
723inline const vector_typet &to_vector_type(const typet &type)
724{
725 assert(type.id() == typet::t_vector);
726 return static_cast<const vector_typet &>(type);
727}
728
729class intcap_typet : public typet
730{
731public:
733 {
734 }
735};
736
737class uintcap_typet : public typet
738{
739public:
741 {
742 }
743};
744
745class ptrmem_typet : public typet
746{
747public:
749 {
750 }
751};
752
753#endif
static const twodig_t base
Definition bigint.cpp:28
Definition bigint.hh:58
Definition std_types.h:397
array_typet(const typet &_subtype)
Definition std_types.h:403
array_typet()
Definition std_types.h:399
exprt & size()
Definition std_types.h:419
const exprt & size() const
Definition std_types.h:414
array_typet(const typet &_subtype, const exprt &_size)
Definition std_types.h:408
bool_typet()
Definition std_types.h:12
bv_typet(unsigned width)
Definition std_types.h:494
void set_width(unsigned width)
Definition std_types.h:502
unsigned get_width() const
Definition std_types.cpp:6
bv_typet()
Definition std_types.h:489
Definition std_types.h:297
argumentt()
Definition std_types.h:299
bool has_default_value() const
Definition std_types.h:312
argumentt(const typet &type)
Definition std_types.h:303
exprt & default_value()
Definition std_types.h:317
const exprt & default_value() const
Definition std_types.h:307
void set_identifier(const irep_idt &identifier)
Definition std_types.h:322
const irep_idt & get_base_name() const
Definition std_types.h:337
void set_base_name(const irep_idt &name)
Definition std_types.h:327
const irep_idt & get_identifier() const
Definition std_types.h:332
Definition std_types.h:280
typet & return_type()
Definition std_types.h:358
std::vector< argumentt > argumentst
Definition std_types.h:283
argumentst & arguments()
Definition std_types.h:368
code_typet(argumentst _parameters, typet _return_type)
Definition std_types.h:290
void set_inlined(bool value)
Definition std_types.h:378
bool get_inlined() const
Definition std_types.h:373
const typet & return_type() const
Definition std_types.h:353
code_typet()
Definition std_types.h:285
const argumentst & arguments() const
Definition std_types.h:363
bool has_ellipsis() const
Definition std_types.h:343
void make_ellipsis()
Definition std_types.h:348
Definition std_types.h:658
const typet & base_type() const
Definition std_types.h:664
void set_base_type(const typet &base)
Definition std_types.h:669
friend const complex_typet & to_complex_type(const typet &type)
Definition std_types.h:677
complex_typet()
Definition std_types.h:660
Definition std_expr.h:1082
empty_typet()
Definition std_types.h:21
Definition expr.h:34
const exprt & find_expr(const std::string &name) const
Definition expr.h:211
static irep_idt argument
Definition expr.h:262
exprt()=default
exprt & add_expr(const std::string &name)
Definition expr.h:206
Definition std_types.h:600
void set_integer_bits(unsigned b)
Definition std_types.h:614
friend const fixedbv_typet & to_fixedbv_type(const typet &type)
Definition std_types.h:619
unsigned get_integer_bits() const
Definition std_types.cpp:11
fixedbv_typet()
Definition std_types.h:602
unsigned get_fraction_bits() const
Definition std_types.h:607
Definition std_types.h:629
floatbv_typet()
Definition std_types.h:631
unsigned get_e() const
Definition std_types.h:636
void set_f(unsigned b)
Definition std_types.h:643
friend const floatbv_typet & to_floatbv_type(const typet &type)
Definition std_types.h:648
unsigned get_f() const
Definition std_types.cpp:18
intcap_typet()
Definition std_types.h:732
Definition irep_idt.h:12
bool get_bool(const irep_idt &name) const
Definition irep.cpp:142
const irep_idt & cmt_base_name() const
Definition irep.h:463
const irept & find(const irep_idt &name) const
Definition irep.cpp:167
static const irep_idt a_name
Definition irep.h:1287
const irep_idt & identifier() const
Definition irep.h:167
const irep_idt & get(const irep_idt &name) const
Definition irep.cpp:127
bool ellipsis() const
Definition irep.h:533
const irep_idt & base_name() const
Definition irep.h:237
void set(const irep_idt &name, const irep_idt &value)
Definition irep.h:141
static const irep_idt a_component
Definition irep.h:1306
const irep_idt & width() const
Definition irep.h:172
bool is_not_nil() const
Definition irep.h:50
const irep_idt & access() const
Definition irep.h:232
const irep_idt & cmt_identifier() const
Definition irep.h:473
subt & get_sub()
Definition irep.h:1242
typet & type()
Definition irep.h:153
const irep_idt & component_name() const
Definition irep.h:187
void swap(irept &irep)
Definition irep.h:1224
const irep_idt & id() const
Definition irep.h:109
irept & add(const irep_idt &name)
Definition irep.cpp:179
const irep_idt & name() const
Definition irep.h:182
Definition std_types.h:438
pointer_typet()
Definition std_types.h:440
pointer_typet(const typet &_subtype)
Definition std_types.h:445
ptrmem_typet()
Definition std_types.h:748
reference_typet()
Definition std_types.h:476
Definition std_types.h:555
signedbv_typet(unsigned width)
Definition std_types.h:562
BigInt largest() const
Definition std_types.cpp:111
signedbv_typet()
Definition std_types.h:557
constant_exprt zero_expr() const
Definition std_types.cpp:116
BigInt smallest() const
Definition std_types.cpp:106
constant_exprt largest_expr() const
Definition std_types.cpp:126
constant_exprt smallest_expr() const
Definition std_types.cpp:121
Definition std_types.h:232
bool is_prefix_of(const struct_typet &other) const
Definition std_types.cpp:65
struct_typet()
Definition std_types.h:234
const irep_idt & get_pretty_name() const
Definition std_types.h:141
componentt()
Definition std_types.h:89
bool get_anonymous() const
Definition std_types.h:151
void set_is_unnamed_bitfield(bool is_unnamed_bitfield)
Definition std_types.h:176
void set_pretty_name(const irep_idt &name)
Definition std_types.h:146
void set_anonymous(bool anonymous)
Definition std_types.h:156
void set_base_name(const irep_idt &base_name)
Definition std_types.h:126
bool get_is_unnamed_bitfield() const
Definition std_types.h:171
componentt(const irep_idt &_name, const typet &_type)
Definition std_types.h:93
const irep_idt & get_access() const
Definition std_types.h:131
componentt(const irep_idt &_name, const irep_idt &_pretty_name, const typet &_type)
Definition std_types.h:100
void set_is_padding(bool is_padding)
Definition std_types.h:166
const irep_idt & get_base_name() const
Definition std_types.h:121
bool get_is_padding() const
Definition std_types.h:161
void set_access(const irep_idt &access)
Definition std_types.h:136
const irep_idt & get_name() const
Definition std_types.h:111
void set_name(const irep_idt &name)
Definition std_types.h:116
Definition std_types.h:78
unsigned component_number(const irep_idt &component_name) const
Definition std_types.cpp:26
componentst & methods()
Definition std_types.h:209
const componentst & components() const
Definition std_types.h:184
struct_union_typet()=default
const componentst & methods() const
Definition std_types.h:204
struct_union_typet(const irep_idt &_id)
Definition std_types.h:82
const componentt & get_component(const irep_idt &component_name) const
Definition std_types.cpp:45
bool has_component(const irep_idt &component_name) const
Definition std_types.h:194
componentst & components()
Definition std_types.h:189
typet component_type(const irep_idt &component_name) const
Definition std_types.cpp:58
std::vector< componentt > componentst
Definition std_types.h:182
Definition std_types.h:28
symbol_typet()
Definition std_types.h:30
symbol_typet(const irep_idt &identifier)
Definition std_types.h:34
void set_identifier(const irep_idt &identifier)
Definition std_types.h:39
const irep_idt & get_identifier() const
Definition std_types.h:44
Definition type.h:9
const typet & find_type(const std::string &name) const
Definition type.h:66
static irep_idt t_bool
Definition type.h:90
static irep_idt a_integer_bits
Definition type.h:116
static irep_idt t_ptrmem
Definition type.h:106
static irep_idt t_intcap
Definition type.h:104
static irep_idt a_identifier
Definition type.h:108
static irep_idt t_struct
Definition type.h:94
static irep_idt t_reference
Definition type.h:100
static irep_idt t_vector
Definition type.h:102
static irep_idt t_union
Definition type.h:95
static irep_idt t_array
Definition type.h:98
const typet & subtype() const
Definition type.h:17
static irep_idt t_unsignedbv
Definition type.h:83
static irep_idt t_symbol
Definition type.h:92
static irep_idt t_fixedbv
Definition type.h:89
static irep_idt t_uintcap
Definition type.h:105
static irep_idt t_class
Definition type.h:96
static irep_idt a_arguments
Definition type.h:112
static irep_idt a_methods
Definition type.h:111
static irep_idt a_size
Definition type.h:114
static irep_idt t_complex
Definition type.h:87
static irep_idt a_width
Definition type.h:115
static irep_idt t_floatbv
Definition type.h:88
static irep_idt t_signedbv
Definition type.h:82
typet & add_type(const std::string &name)
Definition type.h:61
typet()=default
static irep_idt t_empty
Definition type.h:91
static irep_idt t_bv
Definition type.h:101
static irep_idt a_components
Definition type.h:110
static irep_idt t_code
Definition type.h:97
static irep_idt a_f
Definition type.h:117
static irep_idt t_pointer
Definition type.h:99
uintcap_typet()
Definition std_types.h:740
Definition std_types.h:258
union_typet()
Definition std_types.h:260
Definition std_types.h:509
BigInt largest() const
Definition std_types.cpp:136
unsignedbv_typet()
Definition std_types.h:511
unsignedbv_typet(unsigned width)
Definition std_types.h:516
constant_exprt largest_expr() const
Definition std_types.cpp:151
BigInt smallest() const
Definition std_types.cpp:131
constant_exprt zero_expr() const
Definition std_types.cpp:141
constant_exprt smallest_expr() const
Definition std_types.cpp:146
Definition toml.hpp:1531
This type maps the vectors.
Definition std_types.h:695
vector_typet()
Definition std_types.h:697
const exprt & size() const
Definition std_types.h:712
vector_typet(const typet &_subtype, const exprt &_size)
Definition std_types.h:706
vector_typet(const typet &_subtype)
Definition std_types.h:701
exprt & size()
Definition std_types.h:717
@ other
Definition converter_compare.cpp:887
const vector_typet & to_vector_type(const typet &type)
Definition std_types.h:723
const code_typet & to_code_type(const typet &type)
Definition std_types.h:384
bool is_lvalue_or_rvalue_reference(const typet &type)
Definition std_types.cpp:100
const union_typet & to_union_type(const typet &type)
Definition std_types.h:265
bool is_reference(const typet &type)
Definition std_types.cpp:90
const fixedbv_typet & to_fixedbv_type(const typet &type)
Definition std_types.h:619
const struct_typet & to_struct_type(const typet &type)
Definition std_types.h:241
bool is_rvalue_reference(const typet &type)
Definition std_types.cpp:95
const complex_typet & to_complex_type(const typet &type)
Definition std_types.h:677
const symbol_typet & to_symbol_type(const typet &type)
Cast a generic typet to a symbol_typet.
Definition std_types.h:60
const array_typet & to_array_type(const typet &type)
Definition std_types.h:425
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
Definition std_types.h:460
const struct_union_typet & to_struct_union_type(const typet &type)
Definition std_types.h:215
const floatbv_typet & to_floatbv_type(const typet &type)
Definition std_types.h:648
const unsignedbv_typet & to_unsignedbv_type(const typet &type)
Cast a generic typet to an unsignedbv_typet.
Definition std_types.h:539
const signedbv_typet & to_signedbv_type(const typet &type)
Cast a generic typet to a signedbv_typet.
Definition std_types.h:585