Skip to content

Commit 61f948a

Browse files
author
Daniel Kroening
committed
use optionalt in get_quantifier_var_max/min
This is better signalling for the 'does not apply' case, and better typing (constant_exprt instead of exprt) in case the a min/max is found.
1 parent 9643ec2 commit 61f948a

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

src/solvers/flattening/boolbv_quantifier.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ static bool expr_eq(const exprt &expr1, const exprt &expr2)
2424
/// To obtain the min value for the quantifier variable of the specified
2525
/// forall/exists operator. The min variable is in the form of "!(var_expr >
2626
/// constant)".
27-
static exprt
27+
static optionalt<constant_exprt>
2828
get_quantifier_var_min(const exprt &var_expr, const exprt &quantifier_expr)
2929
{
30-
PRECONDITION(quantifier_expr.id() == ID_or || quantifier_expr.id() == ID_and);
31-
32-
exprt res = false_exprt();
3330
if(quantifier_expr.id()==ID_or)
3431
{
3532
/**
@@ -45,11 +42,11 @@ get_quantifier_var_min(const exprt &var_expr, const exprt &quantifier_expr)
4542
continue;
4643
if(expr_eq(var_expr, y.op0()) && y.op1().id()==ID_constant)
4744
{
48-
return y.op1();
45+
return to_constant_expr(y.op1());
4946
}
5047
}
5148
}
52-
else
49+
else if(quantifier_expr.id() == ID_and)
5350
{
5451
/**
5552
* The min variable
@@ -61,20 +58,19 @@ get_quantifier_var_min(const exprt &var_expr, const exprt &quantifier_expr)
6158
continue;
6259
if(expr_eq(var_expr, x.op0()) && x.op1().id()==ID_constant)
6360
{
64-
return x.op1();
61+
return to_constant_expr(x.op1());
6562
}
6663
}
6764
}
68-
return res;
65+
66+
return {};
6967
}
7068

7169
/// To obtain the max value for the quantifier variable of the specified
7270
/// forall/exists operator.
73-
static exprt
71+
static optionalt<constant_exprt>
7472
get_quantifier_var_max(const exprt &var_expr, const exprt &quantifier_expr)
7573
{
76-
PRECONDITION(quantifier_expr.id() == ID_or || quantifier_expr.id() == ID_and);
77-
exprt res = false_exprt();
7874
if(quantifier_expr.id()==ID_or)
7975
{
8076
/**
@@ -97,8 +93,7 @@ get_quantifier_var_max(const exprt &var_expr, const exprt &quantifier_expr)
9793
* maximum index as specified in the original code.
9894
**/
9995
over_i-=1;
100-
res=from_integer(over_i, x.op1().type());
101-
return res;
96+
return from_integer(over_i, x.op1().type());
10297
}
10398
}
10499
}
@@ -120,12 +115,12 @@ get_quantifier_var_max(const exprt &var_expr, const exprt &quantifier_expr)
120115
const constant_exprt &over_expr = to_constant_expr(y.op1());
121116
mp_integer over_i = numeric_cast_v<mp_integer>(over_expr);
122117
over_i-=1;
123-
res=from_integer(over_i, y.op1().type());
124-
return res;
118+
return from_integer(over_i, y.op1().type());
125119
}
126120
}
127121
}
128-
return res;
122+
123+
return {};
129124
}
130125

131126
static optionalt<exprt>
@@ -145,14 +140,14 @@ instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns)
145140
return re;
146141
}
147142

148-
const exprt min_i = get_quantifier_var_min(var_expr, re);
149-
const exprt max_i = get_quantifier_var_max(var_expr, re);
143+
const auto min_i = get_quantifier_var_min(var_expr, re);
144+
const auto max_i = get_quantifier_var_max(var_expr, re);
150145

151-
if(min_i.is_false() || max_i.is_false())
146+
if(!min_i.has_value() || !max_i.has_value())
152147
return nullopt;
153148

154-
mp_integer lb = numeric_cast_v<mp_integer>(to_constant_expr(min_i));
155-
mp_integer ub = numeric_cast_v<mp_integer>(to_constant_expr(max_i));
149+
mp_integer lb = numeric_cast_v<mp_integer>(min_i.value());
150+
mp_integer ub = numeric_cast_v<mp_integer>(max_i.value());
156151

157152
if(lb>ub)
158153
return nullopt;

0 commit comments

Comments
 (0)