|
9 | 9 | #include "boolbv.h"
|
10 | 10 |
|
11 | 11 | #include <util/arith_tools.h>
|
| 12 | +#include <util/expr_util.h> |
12 | 13 | #include <util/invariant.h>
|
13 | 14 | #include <util/optional.h>
|
14 | 15 | #include <util/replace_expr.h>
|
15 | 16 | #include <util/simplify_expr.h>
|
16 | 17 |
|
17 | 18 | /// A method to detect equivalence between experts that can contain typecast
|
18 |
| -bool expr_eq(const exprt &expr1, const exprt &expr2) |
| 19 | +static bool expr_eq(const exprt &expr1, const exprt &expr2) |
19 | 20 | {
|
20 |
| - exprt e1=expr1, e2=expr2; |
21 |
| - if(expr1.id()==ID_typecast) |
22 |
| - e1=expr1.op0(); |
23 |
| - if(expr2.id()==ID_typecast) |
24 |
| - e2=expr2.op0(); |
25 |
| - return e1==e2; |
| 21 | + return skip_typecast(expr1) == skip_typecast(expr2); |
26 | 22 | }
|
27 | 23 |
|
28 | 24 | /// To obtain the min value for the quantifier variable of the specified
|
29 | 25 | /// forall/exists operator. The min variable is in the form of "!(var_expr >
|
30 | 26 | /// constant)".
|
31 |
| -exprt get_quantifier_var_min( |
| 27 | +static exprt get_quantifier_var_min( |
32 | 28 | const exprt &var_expr,
|
33 | 29 | const exprt &quantifier_expr)
|
34 | 30 | {
|
@@ -75,7 +71,7 @@ exprt get_quantifier_var_min(
|
75 | 71 |
|
76 | 72 | /// To obtain the max value for the quantifier variable of the specified
|
77 | 73 | /// forall/exists operator.
|
78 |
| -exprt get_quantifier_var_max( |
| 74 | +static exprt get_quantifier_var_max( |
79 | 75 | const exprt &var_expr,
|
80 | 76 | const exprt &quantifier_expr)
|
81 | 77 | {
|
@@ -132,27 +128,25 @@ exprt get_quantifier_var_max(
|
132 | 128 | return res;
|
133 | 129 | }
|
134 | 130 |
|
135 |
| -optionalt<exprt> |
| 131 | +static optionalt<exprt> |
136 | 132 | instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns)
|
137 | 133 | {
|
138 |
| - PRECONDITION(expr.id() == ID_forall || expr.id() == ID_exists); |
139 |
| - |
140 | 134 | const symbol_exprt &var_expr = expr.symbol();
|
141 | 135 |
|
142 | 136 | /**
|
143 | 137 | * We need to rewrite the forall/exists quantifier into
|
144 | 138 | * an OR/AND expr.
|
145 | 139 | **/
|
146 | 140 |
|
147 |
| - const exprt &re = simplify_expr(expr.where(), ns); |
| 141 | + const exprt re = simplify_expr(expr.where(), ns); |
148 | 142 |
|
149 | 143 | if(re.is_true() || re.is_false())
|
150 | 144 | {
|
151 | 145 | return re;
|
152 | 146 | }
|
153 | 147 |
|
154 |
| - const exprt &min_i = get_quantifier_var_min(var_expr, re); |
155 |
| - const exprt &max_i = get_quantifier_var_max(var_expr, re); |
| 148 | + const exprt min_i = get_quantifier_var_min(var_expr, re); |
| 149 | + const exprt max_i = get_quantifier_var_max(var_expr, re); |
156 | 150 |
|
157 | 151 | if(min_i.is_false() || max_i.is_false())
|
158 | 152 | return nullopt;
|
@@ -183,42 +177,29 @@ instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns)
|
183 | 177 | }
|
184 | 178 |
|
185 | 179 | UNREACHABLE;
|
186 |
| - return nullopt; |
187 | 180 | }
|
188 | 181 |
|
189 | 182 | literalt boolbvt::convert_quantifier(const quantifier_exprt &src)
|
190 | 183 | {
|
191 | 184 | PRECONDITION(src.id() == ID_forall || src.id() == ID_exists);
|
192 | 185 |
|
193 |
| - quantifier_exprt expr(src); |
194 |
| - const auto res = instantiate_quantifier(expr, ns); |
195 |
| - |
196 |
| - if(!res) |
197 |
| - { |
198 |
| - return SUB::convert_rest(src); |
199 |
| - } |
| 186 | + const auto res = instantiate_quantifier(src, ns); |
200 | 187 |
|
201 |
| - quantifiert quantifier; |
202 |
| - quantifier.expr = *res; |
203 |
| - quantifier_list.push_back(quantifier); |
| 188 | + if(res) |
| 189 | + return convert_bool(*res); |
204 | 190 |
|
205 |
| - literalt l=prop.new_variable(); |
206 |
| - quantifier_list.back().l=l; |
| 191 | + // we failed to instantiate here, need to pass to post-processing |
| 192 | + quantifier_list.emplace_back(quantifiert(src, prop.new_variable())); |
207 | 193 |
|
208 |
| - return l; |
| 194 | + return quantifier_list.back().l; |
209 | 195 | }
|
210 | 196 |
|
211 | 197 | void boolbvt::post_process_quantifiers()
|
212 | 198 | {
|
213 |
| - std::set<exprt> instances; |
214 |
| - |
215 | 199 | if(quantifier_list.empty())
|
216 | 200 | return;
|
217 | 201 |
|
218 |
| - for(auto it=quantifier_list.begin(); |
219 |
| - it!=quantifier_list.end(); |
220 |
| - ++it) |
221 |
| - { |
222 |
| - prop.set_equal(convert_bool(it->expr), it->l); |
223 |
| - } |
| 202 | + // we do not yet have any elaborate post-processing |
| 203 | + for(const auto &q : quantifier_list) |
| 204 | + conversion_failed(q.expr); |
224 | 205 | }
|
0 commit comments