CBMC
smt_sorts.cpp
Go to the documentation of this file.
1 // Author: Diffblue Ltd.
2 
3 #include "smt_sorts.h"
4 
5 #include <util/invariant.h>
6 
7 // Define the irep_idts for sorts.
8 #define SORT_ID(the_id) \
9  const irep_idt ID_smt_##the_id##_sort{"smt_" #the_id "_sort"};
10 #include "smt_sorts.def"
11 
12 #undef SORT_ID
13 
14 #define SORT_ID(the_id) \
15  template <> \
16  const smt_##the_id##_sortt *smt_sortt::cast<smt_##the_id##_sortt>() const & \
17  { \
18  return id() == ID_smt_##the_id##_sort \
19  ? static_cast<const smt_##the_id##_sortt *>(this) \
20  : nullptr; \
21  }
22 #include "smt_sorts.def" // NOLINT(build/include)
23 #undef SORT_ID
24 
25 #define SORT_ID(the_id) \
26  template <> \
27  std::optional<smt_##the_id##_sortt> smt_sortt::cast<smt_##the_id##_sortt>() \
28  && \
29  { \
30  if(id() == ID_smt_##the_id##_sort) \
31  return {std::move(*static_cast<const smt_##the_id##_sortt *>(this))}; \
32  else \
33  return {}; \
34  }
35 #include "smt_sorts.def" // NOLINT(build/include)
36 #undef SORT_ID
37 
38 bool smt_sortt::operator==(const smt_sortt &other) const
39 {
40  return irept::operator==(other);
41 }
42 
43 bool smt_sortt::operator!=(const smt_sortt &other) const
44 {
45  return !(*this == other);
46 }
47 
49 {
50 }
51 
52 smt_bit_vector_sortt::smt_bit_vector_sortt(const std::size_t bit_width)
53  : smt_sortt{ID_smt_bit_vector_sort}
54 {
55  INVARIANT(
56  bit_width > 0,
57  "The definition of SMT2 bit vector theory requires the number of "
58  "bits to be greater than 0.");
59  set_size_t(ID_width, bit_width);
60 }
61 
63 {
64  return get_size_t(ID_width);
65 }
66 
68  const smt_sortt &index_sort,
69  const smt_sortt &element_sort)
70  : smt_sortt{ID_smt_array_sort}
71 {
72  add(ID_index, index_sort);
73  add(ID_value, element_sort);
74 }
75 
77 {
78  return static_cast<const smt_sortt &>(find(ID_index));
79 }
80 
82 {
83  return static_cast<const smt_sortt &>(find(ID_value));
84 }
85 
86 template <typename visitort>
87 void accept(const smt_sortt &sort, const irep_idt &id, visitort &&visitor)
88 {
89 #define SORT_ID(the_id) \
90  if(id == ID_smt_##the_id##_sort) \
91  return visitor.visit(static_cast<const smt_##the_id##_sortt &>(sort));
92 #include "smt_sorts.def"
93 #undef SORT_ID
95 }
96 
98 {
99  ::accept(*this, id(), visitor);
100 }
101 
103 {
104  ::accept(*this, id(), std::move(visitor));
105 }
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
bool operator==(const irept &other) const
Definition: irep.cpp:133
std::size_t get_size_t(const irep_idt &name) const
Definition: irep.cpp:67
const irept & find(const irep_idt &name) const
Definition: irep.cpp:93
void set_size_t(const irep_idt &name, const std::size_t value)
Definition: irep.cpp:82
irept & add(const irep_idt &name)
Definition: irep.cpp:103
const smt_sortt & element_sort() const
Definition: smt_sorts.cpp:81
const smt_sortt & index_sort() const
Definition: smt_sorts.cpp:76
smt_array_sortt(const smt_sortt &index_sort, const smt_sortt &element_sort)
Definition: smt_sorts.cpp:67
std::size_t bit_width() const
Definition: smt_sorts.cpp:62
smt_bit_vector_sortt(std::size_t bit_width)
Definition: smt_sorts.cpp:52
bool operator==(const smt_sortt &) const
Definition: smt_sorts.cpp:38
bool operator!=(const smt_sortt &) const
Definition: smt_sorts.cpp:43
void accept(smt_sort_const_downcast_visitort &) const
Definition: smt_sorts.cpp:97
void accept(const smt_sortt &sort, const irep_idt &id, visitort &&visitor)
Definition: smt_sorts.cpp:87
Data structure for smt sorts.
#define UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:525