Skip to content

Commit b0e3df0

Browse files
committed
Cleanup boolbv quantifier instantiation
1) Do not take references of temporaries. 2) No need to involve post_processing, instantiated expressions can be converted immediately. 3) Use skip_typecast rather than local, partial typecast skipping. 4) No need for redundant precondition checks. 5) Mark file-local procedures static.
1 parent c442889 commit b0e3df0

File tree

2 files changed

+14
-58
lines changed

2 files changed

+14
-58
lines changed

src/solvers/flattening/boolbv.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class boolbvt:public arrayst
6161

6262
void post_process() override
6363
{
64-
post_process_quantifiers();
6564
functions.post_process();
6665
SUB::post_process();
6766
}
@@ -234,19 +233,6 @@ class boolbvt:public arrayst
234233
// unbounded arrays
235234
bool is_unbounded_array(const typet &type) const override;
236235

237-
// quantifier instantiations
238-
class quantifiert
239-
{
240-
public:
241-
exprt expr;
242-
literalt l;
243-
};
244-
245-
typedef std::list<quantifiert> quantifier_listt;
246-
quantifier_listt quantifier_list;
247-
248-
void post_process_quantifiers();
249-
250236
typedef std::vector<std::size_t> offset_mapt;
251237
offset_mapt build_offset_map(const struct_typet &src);
252238

src/solvers/flattening/boolbv_quantifier.cpp

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,22 @@ Author: Daniel Kroening, [email protected]
99
#include "boolbv.h"
1010

1111
#include <util/arith_tools.h>
12+
#include <util/expr_util.h>
1213
#include <util/invariant.h>
1314
#include <util/optional.h>
1415
#include <util/replace_expr.h>
1516
#include <util/simplify_expr.h>
1617

1718
/// 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)
1920
{
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);
2622
}
2723

2824
/// To obtain the min value for the quantifier variable of the specified
2925
/// forall/exists operator. The min variable is in the form of "!(var_expr >
3026
/// constant)".
31-
exprt get_quantifier_var_min(
27+
static exprt get_quantifier_var_min(
3228
const exprt &var_expr,
3329
const exprt &quantifier_expr)
3430
{
@@ -75,7 +71,7 @@ exprt get_quantifier_var_min(
7571

7672
/// To obtain the max value for the quantifier variable of the specified
7773
/// forall/exists operator.
78-
exprt get_quantifier_var_max(
74+
static exprt get_quantifier_var_max(
7975
const exprt &var_expr,
8076
const exprt &quantifier_expr)
8177
{
@@ -132,27 +128,25 @@ exprt get_quantifier_var_max(
132128
return res;
133129
}
134130

135-
optionalt<exprt>
131+
static optionalt<exprt>
136132
instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns)
137133
{
138-
PRECONDITION(expr.id() == ID_forall || expr.id() == ID_exists);
139-
140134
const symbol_exprt &var_expr = expr.symbol();
141135

142136
/**
143137
* We need to rewrite the forall/exists quantifier into
144138
* an OR/AND expr.
145139
**/
146140

147-
const exprt &re = simplify_expr(expr.where(), ns);
141+
const exprt re = simplify_expr(expr.where(), ns);
148142

149143
if(re.is_true() || re.is_false())
150144
{
151145
return re;
152146
}
153147

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);
156150

157151
if(min_i.is_false() || max_i.is_false())
158152
return nullopt;
@@ -183,42 +177,18 @@ instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns)
183177
}
184178

185179
UNREACHABLE;
186-
return nullopt;
187180
}
188181

189182
literalt boolbvt::convert_quantifier(const quantifier_exprt &src)
190183
{
191184
PRECONDITION(src.id() == ID_forall || src.id() == ID_exists);
192185

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-
}
200-
201-
quantifiert quantifier;
202-
quantifier.expr = *res;
203-
quantifier_list.push_back(quantifier);
204-
205-
literalt l=prop.new_variable();
206-
quantifier_list.back().l=l;
186+
const auto res = instantiate_quantifier(src, ns);
207187

208-
return l;
209-
}
210-
211-
void boolbvt::post_process_quantifiers()
212-
{
213-
std::set<exprt> instances;
214-
215-
if(quantifier_list.empty())
216-
return;
217-
218-
for(auto it=quantifier_list.begin();
219-
it!=quantifier_list.end();
220-
++it)
188+
if(res)
221189
{
222-
prop.set_equal(convert_bool(it->expr), it->l);
190+
return convert_bool(*res);
223191
}
192+
else
193+
return SUB::convert_rest(src);
224194
}

0 commit comments

Comments
 (0)