CBMC
smt_responses.cpp
Go to the documentation of this file.
1 // Author: Diffblue Ltd.
2 
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 <solvers/smt2_incremental/smt_responses.def>
11 #undef RESPONSE_ID
12 
13 bool smt_responset::operator==(const smt_responset &other) const
14 {
15  return irept::operator==(other);
16 }
17 
18 bool smt_responset::operator!=(const smt_responset &other) const
19 {
20  return !(*this == other);
21 }
22 
23 #define RESPONSE_ID(the_id, the_base) \
24  template <> \
25  const smt_##the_id##_responset *the_base::cast<smt_##the_id##_responset>() \
26  const & \
27  { \
28  return id() == ID_smt_##the_id##_response \
29  ? static_cast<const smt_##the_id##_responset *>(this) \
30  : nullptr; \
31  }
32 #include <solvers/smt2_incremental/smt_responses.def> // NOLINT(build/include)
33 #undef RESPONSE_ID
34 
35 template <typename sub_classt>
36 const sub_classt *smt_responset::cast() const &
37 {
38  return nullptr;
39 }
40 
43 {
44  return irept::operator==(other);
45 }
46 
49 {
50  return !(*this == other);
51 }
52 
54  : smt_responset{ID_smt_success_response}
55 {
56 }
57 
59  : smt_check_sat_response_kindt{ID_smt_sat_response}
60 {
61 }
62 
64  : smt_check_sat_response_kindt{ID_smt_unsat_response}
65 {
66 }
67 
69  : smt_check_sat_response_kindt{ID_smt_unknown_response}
70 {
71 }
72 
73 template <typename derivedt>
75 {
76  static_assert(
77  std::is_base_of<irept, derivedt>::value &&
78  std::is_base_of<storert<derivedt>, derivedt>::value,
79  "Only irept based classes need to upcast smt_termt to store it.");
80 }
81 
82 template <typename derivedt>
84  smt_check_sat_response_kindt check_sat_response_kind)
85 {
86  return static_cast<irept &&>(std::move(check_sat_response_kind));
87 }
88 
89 template <typename derivedt>
92 {
93  return static_cast<const smt_check_sat_response_kindt &>(irep);
94 }
95 
98  : smt_responset{ID_smt_check_sat_response}
99 {
100  set(ID_value, upcast(std::move(kind)));
101 }
102 
104 {
105  return downcast(find(ID_value));
106 }
107 
109  smt_termt descriptor,
110  smt_termt value)
111 {
112  INVARIANT(
114  "SMT valuation pair must have matching sort for the descriptor and value.");
115  get_sub().push_back(upcast(std::move(descriptor)));
116  get_sub().push_back(upcast(std::move(value)));
117 }
118 
120  irep_idt descriptor,
121  const smt_termt &value)
123 {
124 }
125 
127 {
128  return downcast(get_sub().at(0));
129 }
130 
132 {
133  return downcast(get_sub().at(1));
134 }
135 
138 {
139  return irept::operator==(other);
140 }
141 
144 {
145  return !(*this == other);
146 }
147 
149  std::vector<valuation_pairt> pairs)
150  : smt_responset(ID_smt_get_value_response)
151 {
152  // SMT-LIB standard version 2.6 requires one or more pairs.
153  // See page 47, figure 3.9: Command responses.
154  INVARIANT(
155  !pairs.empty(), "Get value response must contain one or more pairs.");
156  for(auto &pair : pairs)
157  {
158  get_sub().push_back(std::move(pair));
159  }
160 }
161 
162 std::vector<
163  std::reference_wrapper<const smt_get_value_responset::valuation_pairt>>
165 {
166  return make_range(get_sub()).map([](const irept &pair) {
167  return std::cref(static_cast<const valuation_pairt &>(pair));
168  });
169 }
170 
172  : smt_responset{ID_smt_unsupported_response}
173 {
174 }
175 
177  : smt_responset{ID_smt_error_response}
178 {
179  set(ID_value, message);
180 }
181 
183 {
184  return get(ID_value);
185 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
smt_error_responset::smt_error_responset
smt_error_responset(irep_idt message)
Definition: smt_responses.cpp:176
smt_identifier_termt
Stores identifiers in unescaped and unquoted form.
Definition: smt_terms.h:91
smt_unsat_responset::smt_unsat_responset
smt_unsat_responset()
Definition: smt_responses.cpp:63
smt_check_sat_response_kindt::storert::storert
storert()
Definition: smt_responses.cpp:74
irept::find
const irept & find(const irep_idt &name) const
Definition: irep.cpp:106
smt_get_value_responset::valuation_pairt::descriptor
const smt_termt & descriptor() const
Definition: smt_responses.cpp:126
smt_check_sat_response_kindt::storert::upcast
static irept upcast(smt_check_sat_response_kindt check_sat_response_kind)
Definition: smt_responses.cpp:83
smt_termt
Definition: smt_terms.h:20
smt_unsupported_responset::smt_unsupported_responset
smt_unsupported_responset()
Definition: smt_responses.cpp:171
smt_check_sat_response_kindt::storert
Class for adding the ability to up and down cast smt_check_sat_response_kindt to and from irept.
Definition: smt_responses.h:56
smt_check_sat_response_kindt
Definition: smt_responses.h:34
smt_unknown_responset::smt_unknown_responset
smt_unknown_responset()
Definition: smt_responses.cpp:68
smt_responses.h
irept::get
const irep_idt & get(const irep_idt &name) const
Definition: irep.cpp:45
smt_get_value_responset::valuation_pairt::valuation_pairt
valuation_pairt()=delete
smt_check_sat_response_kindt::operator!=
bool operator!=(const smt_check_sat_response_kindt &) const
Definition: smt_responses.cpp:48
smt_responset
Definition: smt_responses.h:9
smt_get_value_responset::valuation_pairt::operator==
bool operator==(const valuation_pairt &) const
Definition: smt_responses.cpp:137
smt_get_value_responset::valuation_pairt::operator!=
bool operator!=(const valuation_pairt &) const
Definition: smt_responses.cpp:143
smt_termt::storert< valuation_pairt >::upcast
static irept upcast(smt_termt term)
Definition: smt_terms.h:65
smt_termt::get_sort
const smt_sortt & get_sort() const
Definition: smt_terms.cpp:35
smt_success_responset::smt_success_responset
smt_success_responset()
Definition: smt_responses.cpp:53
range.h
smt_check_sat_responset::smt_check_sat_responset
smt_check_sat_responset(smt_check_sat_response_kindt kind)
Definition: smt_responses.cpp:96
smt_termt::storert< smt_get_value_responset >::downcast
static const smt_termt & downcast(const irept &)
Definition: smt_terms.h:71
smt_error_responset::message
const irep_idt & message() const
Definition: smt_responses.cpp:182
irept::operator==
bool operator==(const irept &other) const
Definition: irep.cpp:146
smt_check_sat_response_kindt::operator==
bool operator==(const smt_check_sat_response_kindt &) const
Definition: smt_responses.cpp:42
smt_get_value_responset::smt_get_value_responset
smt_get_value_responset(std::vector< valuation_pairt > pairs)
Definition: smt_responses.cpp:148
smt_responset::operator==
bool operator==(const smt_responset &) const
Definition: smt_responses.cpp:13
smt_sat_responset::smt_sat_responset
smt_sat_responset()
Definition: smt_responses.cpp:58
smt_responset::operator!=
bool operator!=(const smt_responset &) const
Definition: smt_responses.cpp:18
irept::get_sub
subt & get_sub()
Definition: irep.h:456
smt_get_value_responset::valuation_pairt
Definition: smt_responses.h:100
irept
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition: irep.h:359
smt_get_value_responset::valuation_pairt::value
const smt_termt & value() const
Definition: smt_responses.cpp:131
smt_responset::cast
const sub_classt * cast() const &
Definition: smt_responses.cpp:36
make_range
ranget< iteratort > make_range(iteratort begin, iteratort end)
Definition: range.h:524
smt_check_sat_response_kindt::storert::downcast
static const smt_check_sat_response_kindt & downcast(const irept &)
Definition: smt_responses.cpp:91
validation_modet::INVARIANT
@ INVARIANT
smt_get_value_responset::pairs
std::vector< std::reference_wrapper< const valuation_pairt > > pairs() const
Definition: smt_responses.cpp:164
smt_check_sat_responset::kind
const smt_check_sat_response_kindt & kind() const
Definition: smt_responses.cpp:103