|
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( |
32 |
| - const exprt &var_expr, |
33 |
| - const exprt &quantifier_expr) |
| 27 | +static exprt |
| 28 | +get_quantifier_var_min(const exprt &var_expr, const exprt &quantifier_expr) |
34 | 29 | {
|
35 | 30 | PRECONDITION(quantifier_expr.id() == ID_or || quantifier_expr.id() == ID_and);
|
36 | 31 |
|
@@ -75,9 +70,8 @@ exprt get_quantifier_var_min(
|
75 | 70 |
|
76 | 71 | /// To obtain the max value for the quantifier variable of the specified
|
77 | 72 | /// forall/exists operator.
|
78 |
| -exprt get_quantifier_var_max( |
79 |
| - const exprt &var_expr, |
80 |
| - const exprt &quantifier_expr) |
| 73 | +static exprt |
| 74 | +get_quantifier_var_max(const exprt &var_expr, const exprt &quantifier_expr) |
81 | 75 | {
|
82 | 76 | PRECONDITION(quantifier_expr.id() == ID_or || quantifier_expr.id() == ID_and);
|
83 | 77 | exprt res = false_exprt();
|
@@ -132,27 +126,25 @@ exprt get_quantifier_var_max(
|
132 | 126 | return res;
|
133 | 127 | }
|
134 | 128 |
|
135 |
| -optionalt<exprt> |
| 129 | +static optionalt<exprt> |
136 | 130 | instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns)
|
137 | 131 | {
|
138 |
| - PRECONDITION(expr.id() == ID_forall || expr.id() == ID_exists); |
139 |
| - |
140 | 132 | const symbol_exprt &var_expr = expr.symbol();
|
141 | 133 |
|
142 | 134 | /**
|
143 | 135 | * We need to rewrite the forall/exists quantifier into
|
144 | 136 | * an OR/AND expr.
|
145 | 137 | **/
|
146 | 138 |
|
147 |
| - const exprt &re = simplify_expr(expr.where(), ns); |
| 139 | + const exprt re = simplify_expr(expr.where(), ns); |
148 | 140 |
|
149 | 141 | if(re.is_true() || re.is_false())
|
150 | 142 | {
|
151 | 143 | return re;
|
152 | 144 | }
|
153 | 145 |
|
154 |
| - const exprt &min_i = get_quantifier_var_min(var_expr, re); |
155 |
| - const exprt &max_i = get_quantifier_var_max(var_expr, re); |
| 146 | + const exprt min_i = get_quantifier_var_min(var_expr, re); |
| 147 | + const exprt max_i = get_quantifier_var_max(var_expr, re); |
156 | 148 |
|
157 | 149 | if(min_i.is_false() || max_i.is_false())
|
158 | 150 | return nullopt;
|
@@ -183,42 +175,29 @@ instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns)
|
183 | 175 | }
|
184 | 176 |
|
185 | 177 | UNREACHABLE;
|
186 |
| - return nullopt; |
187 | 178 | }
|
188 | 179 |
|
189 | 180 | literalt boolbvt::convert_quantifier(const quantifier_exprt &src)
|
190 | 181 | {
|
191 | 182 | PRECONDITION(src.id() == ID_forall || src.id() == ID_exists);
|
192 | 183 |
|
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 |
| - } |
| 184 | + const auto res = instantiate_quantifier(src, ns); |
200 | 185 |
|
201 |
| - quantifiert quantifier; |
202 |
| - quantifier.expr = *res; |
203 |
| - quantifier_list.push_back(quantifier); |
| 186 | + if(res) |
| 187 | + return convert_bool(*res); |
204 | 188 |
|
205 |
| - literalt l=prop.new_variable(); |
206 |
| - quantifier_list.back().l=l; |
| 189 | + // we failed to instantiate here, need to pass to post-processing |
| 190 | + quantifier_list.emplace_back(quantifiert(src, prop.new_variable())); |
207 | 191 |
|
208 |
| - return l; |
| 192 | + return quantifier_list.back().l; |
209 | 193 | }
|
210 | 194 |
|
211 | 195 | void boolbvt::post_process_quantifiers()
|
212 | 196 | {
|
213 |
| - std::set<exprt> instances; |
214 |
| - |
215 | 197 | if(quantifier_list.empty())
|
216 | 198 | return;
|
217 | 199 |
|
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 |
| - } |
| 200 | + // we do not yet have any elaborate post-processing |
| 201 | + for(const auto &q : quantifier_list) |
| 202 | + conversion_failed(q.expr); |
224 | 203 | }
|
0 commit comments