|
| 1 | +// Author: Diffblue Ltd. |
| 2 | + |
| 3 | +#include <solvers/smt2_incremental/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 <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 | + |
| 41 | +bool smt_check_sat_response_kindt:: |
| 42 | +operator==(const smt_check_sat_response_kindt &other) const |
| 43 | +{ |
| 44 | + return irept::operator==(other); |
| 45 | +} |
| 46 | + |
| 47 | +bool smt_check_sat_response_kindt:: |
| 48 | +operator!=(const smt_check_sat_response_kindt &other) const |
| 49 | +{ |
| 50 | + return !(*this == other); |
| 51 | +} |
| 52 | + |
| 53 | +smt_success_responset::smt_success_responset() |
| 54 | + : smt_responset{ID_smt_success_response} |
| 55 | +{ |
| 56 | +} |
| 57 | + |
| 58 | +smt_sat_responset::smt_sat_responset() |
| 59 | + : smt_check_sat_response_kindt{ID_smt_sat_response} |
| 60 | +{ |
| 61 | +} |
| 62 | + |
| 63 | +smt_unsat_responset::smt_unsat_responset() |
| 64 | + : smt_check_sat_response_kindt{ID_smt_unsat_response} |
| 65 | +{ |
| 66 | +} |
| 67 | + |
| 68 | +smt_unknown_responset::smt_unknown_responset() |
| 69 | + : smt_check_sat_response_kindt{ID_smt_unknown_response} |
| 70 | +{ |
| 71 | +} |
| 72 | + |
| 73 | +template <typename derivedt> |
| 74 | +smt_check_sat_response_kindt::storert<derivedt>::storert() |
| 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> |
| 83 | +irept smt_check_sat_response_kindt::storert<derivedt>::upcast( |
| 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> |
| 90 | +const smt_check_sat_response_kindt & |
| 91 | +smt_check_sat_response_kindt::storert<derivedt>::downcast(const irept &irep) |
| 92 | +{ |
| 93 | + return static_cast<const smt_check_sat_response_kindt &>(irep); |
| 94 | +} |
| 95 | + |
| 96 | +smt_check_sat_responset::smt_check_sat_responset( |
| 97 | + smt_check_sat_response_kindt kind) |
| 98 | + : smt_responset{ID_smt_check_sat_response} |
| 99 | +{ |
| 100 | + set(ID_value, upcast(std::move(kind))); |
| 101 | +} |
| 102 | + |
| 103 | +const smt_check_sat_response_kindt &smt_check_sat_responset::kind() const |
| 104 | +{ |
| 105 | + return downcast(find(ID_value)); |
| 106 | +} |
| 107 | + |
| 108 | +smt_get_value_responset::valuation_pairt::valuation_pairt( |
| 109 | + smt_termt descriptor, |
| 110 | + smt_termt value) |
| 111 | +{ |
| 112 | + get_sub().push_back(upcast(std::move(descriptor))); |
| 113 | + get_sub().push_back(upcast(std::move(value))); |
| 114 | +} |
| 115 | + |
| 116 | +const smt_termt &smt_get_value_responset::valuation_pairt::descriptor() const |
| 117 | +{ |
| 118 | + return downcast(get_sub().at(0)); |
| 119 | +} |
| 120 | + |
| 121 | +const smt_termt &smt_get_value_responset::valuation_pairt::value() const |
| 122 | +{ |
| 123 | + return downcast(get_sub().at(1)); |
| 124 | +} |
| 125 | + |
| 126 | +bool smt_get_value_responset::valuation_pairt:: |
| 127 | +operator==(const smt_get_value_responset::valuation_pairt &other) const |
| 128 | +{ |
| 129 | + return irept::operator==(other); |
| 130 | +} |
| 131 | + |
| 132 | +bool smt_get_value_responset::valuation_pairt:: |
| 133 | +operator!=(const smt_get_value_responset::valuation_pairt &other) const |
| 134 | +{ |
| 135 | + return !(*this == other); |
| 136 | +} |
| 137 | + |
| 138 | +smt_get_value_responset::smt_get_value_responset( |
| 139 | + std::vector<valuation_pairt> pairs) |
| 140 | + : smt_responset(ID_smt_get_value_response) |
| 141 | +{ |
| 142 | + // SMT-LIB standard version 2.6 requires one or more pairs. |
| 143 | + // See page 47, figure 3.9: Command responses. |
| 144 | + INVARIANT( |
| 145 | + !pairs.empty(), "Get value response must contain one or more pairs."); |
| 146 | + for(auto &pair : pairs) |
| 147 | + { |
| 148 | + get_sub().push_back(std::move(pair)); |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +std::vector< |
| 153 | + std::reference_wrapper<const smt_get_value_responset::valuation_pairt>> |
| 154 | +smt_get_value_responset::pairs() const |
| 155 | +{ |
| 156 | + return make_range(get_sub()).map([](const irept &pair) { |
| 157 | + return std::cref(static_cast<const valuation_pairt &>(pair)); |
| 158 | + }); |
| 159 | +} |
| 160 | + |
| 161 | +smt_unsupported_responset::smt_unsupported_responset() |
| 162 | + : smt_responset{ID_smt_unsupported_response} |
| 163 | +{ |
| 164 | +} |
| 165 | + |
| 166 | +smt_error_responset::smt_error_responset(irep_idt message) |
| 167 | + : smt_responset{ID_smt_error_response} |
| 168 | +{ |
| 169 | + set(ID_value, message); |
| 170 | +} |
| 171 | + |
| 172 | +const irep_idt &smt_error_responset::message() const |
| 173 | +{ |
| 174 | + return get(ID_value); |
| 175 | +} |
0 commit comments