CBMC
smt_responses.cpp
Go to the documentation of this file.
1 // Author: Diffblue Ltd.
2 
3 #include "smt_responses.h"
4 
5 #include <util/range.h>
6 
7 // Define the irep_idts for responses.
8 #define RESPONSE_ID(the_id, the_base) \
9  const irep_idt ID_smt_##the_id##_response{"smt_" #the_id "_response"};
10 #include "smt_responses.def"
11 
12 #undef RESPONSE_ID
13 
14 bool smt_responset::operator==(const smt_responset &other) const
15 {
16  return irept::operator==(other);
17 }
18 
19 bool smt_responset::operator!=(const smt_responset &other) const
20 {
21  return !(*this == other);
22 }
23 
24 #define RESPONSE_ID(the_id, the_base) \
25  template <> \
26  const smt_##the_id##_responset *the_base::cast<smt_##the_id##_responset>() \
27  const & \
28  { \
29  return id() == ID_smt_##the_id##_response \
30  ? static_cast<const smt_##the_id##_responset *>(this) \
31  : nullptr; \
32  }
33 #include "smt_responses.def" // NOLINT(build/include)
34 #undef RESPONSE_ID
35 
36 template <typename sub_classt>
37 const sub_classt *smt_responset::cast() const &
38 {
39  return nullptr;
40 }
41 
43  const smt_check_sat_response_kindt &other) const
44 {
45  return irept::operator==(other);
46 }
47 
49  const smt_check_sat_response_kindt &other) const
50 {
51  return !(*this == other);
52 }
53 
55  : smt_responset{ID_smt_success_response}
56 {
57 }
58 
60  : smt_check_sat_response_kindt{ID_smt_sat_response}
61 {
62 }
63 
65  : smt_check_sat_response_kindt{ID_smt_unsat_response}
66 {
67 }
68 
70  : smt_check_sat_response_kindt{ID_smt_unknown_response}
71 {
72 }
73 
74 template <typename derivedt>
76 {
77  static_assert(
78  std::is_base_of<irept, derivedt>::value &&
79  std::is_base_of<storert<derivedt>, derivedt>::value,
80  "Only irept based classes need to upcast smt_termt to store it.");
81 }
82 
83 template <typename derivedt>
85  smt_check_sat_response_kindt check_sat_response_kind)
86 {
87  return static_cast<irept &&>(std::move(check_sat_response_kind));
88 }
89 
90 template <typename derivedt>
93 {
94  return static_cast<const smt_check_sat_response_kindt &>(irep);
95 }
96 
99  : smt_responset{ID_smt_check_sat_response}
100 {
101  set(ID_value, upcast(std::move(kind)));
102 }
103 
105 {
106  return downcast(find(ID_value));
107 }
108 
110  smt_termt descriptor,
111  smt_termt value)
112 {
113  INVARIANT(
115  "SMT valuation pair must have matching sort for the descriptor and value.");
116  get_sub().push_back(upcast(std::move(descriptor)));
117  get_sub().push_back(upcast(std::move(value)));
118 }
119 
121  irep_idt descriptor,
122  const smt_termt &value)
123  : valuation_pairt(smt_identifier_termt{descriptor, value.get_sort()}, value)
124 {
125 }
126 
128 {
129  return downcast(get_sub().at(0));
130 }
131 
133 {
134  return downcast(get_sub().at(1));
135 }
136 
138  const smt_get_value_responset::valuation_pairt &other) const
139 {
140  return irept::operator==(other);
141 }
142 
144  const smt_get_value_responset::valuation_pairt &other) const
145 {
146  return !(*this == other);
147 }
148 
150  std::vector<valuation_pairt> pairs)
151  : smt_responset(ID_smt_get_value_response)
152 {
153  // SMT-LIB standard version 2.6 requires one or more pairs.
154  // See page 47, figure 3.9: Command responses.
155  INVARIANT(
156  !pairs.empty(), "Get value response must contain one or more pairs.");
157  for(auto &pair : pairs)
158  {
159  get_sub().push_back(std::move(pair));
160  }
161 }
162 
163 std::vector<
164  std::reference_wrapper<const smt_get_value_responset::valuation_pairt>>
166 {
167  return make_range(get_sub()).map([](const irept &pair) {
168  return std::cref(static_cast<const valuation_pairt &>(pair));
169  });
170 }
171 
173  : smt_responset{ID_smt_unsupported_response}
174 {
175 }
176 
178  : smt_responset{ID_smt_error_response}
179 {
180  set(ID_value, message);
181 }
182 
184 {
185  return get(ID_value);
186 }
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
bool operator==(const irept &other) const
Definition: irep.cpp:133
subt & get_sub()
Definition: irep.h:448
const irept & find(const irep_idt &name) const
Definition: irep.cpp:93
const irep_idt & get(const irep_idt &name) const
Definition: irep.cpp:44
void set(const irep_idt &name, const irep_idt &value)
Definition: irep.h:412
Class for adding the ability to up and down cast smt_check_sat_response_kindt to and from irept.
Definition: smt_responses.h:58
static irept upcast(smt_check_sat_response_kindt check_sat_response_kind)
static const smt_check_sat_response_kindt & downcast(const irept &)
bool operator==(const smt_check_sat_response_kindt &) const
bool operator!=(const smt_check_sat_response_kindt &) const
smt_check_sat_responset(smt_check_sat_response_kindt kind)
const smt_check_sat_response_kindt & kind() const
const irep_idt & message() const
smt_error_responset(irep_idt message)
bool operator==(const valuation_pairt &) const
bool operator!=(const valuation_pairt &) const
smt_get_value_responset(std::vector< valuation_pairt > pairs)
std::vector< std::reference_wrapper< const valuation_pairt > > pairs() const
Stores identifiers in unescaped and unquoted form.
Definition: smt_terms.h:93
const sub_classt * cast() const &
bool operator!=(const smt_responset &) const
bool operator==(const smt_responset &) const
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
Ranges: pair of begin and end iterators, which can be initialized from containers,...
ranget< iteratort > make_range(iteratort begin, iteratort end)
Definition: range.h:522