Skip to content

Commit ea48112

Browse files
committed
Simplify handling of expression matching and clarify comment in else branch
1 parent 614eaef commit ea48112

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

src/solvers/flattening/boolbv_quantifier.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ get_quantifier_var_max(const exprt &var_expr, const exprt &quantifier_expr)
137137
}
138138
else
139139
{
140-
// If we are here, we came across a (simplified?) expression that was
141-
// not anticipated - normally this would be a bug, but if you made
142-
// changes to the simplifier (as an example), you would need to add an
143-
// else-if branch that handles that type above.
140+
// If you need special handling for a particular expression type (say,
141+
// after changes to the simplifier) you need to make sure that you add
142+
// an `else if` branch above, otherwise the expression will get skipped
143+
// and the constraints will not propagate correctly.
144144
continue;
145145
}
146146
}

src/util/simplify_expr_boolean.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ simplify_exprt::resultt<> simplify_exprt::simplify_boolean(const exprt &expr)
153153
mp_integer higher;
154154
};
155155
boundst bounds;
156-
bool structure_matched = false;
157156

158157
// Before we do anything else, we need to "pattern match" against the
159158
// expression and make sure that it has the structure we're looking for.
@@ -215,24 +214,18 @@ simplify_exprt::resultt<> simplify_exprt::simplify_boolean(const exprt &expr)
215214
};
216215

217216
// We need to match both operands, at the particular sequence we expect.
218-
structure_matched |= match_first_operand(new_operands[0]);
219-
structure_matched &= match_second_operand(new_operands[1]);
217+
bool structure_matched = match_first_operand(new_operands[0]) &&
218+
match_second_operand(new_operands[1]);
220219

221220
if(structure_matched && bounds.lower == bounds.higher)
222221
{
223-
// Go through the expression again and convert >= operand into ==
224-
for(const auto &op : new_operands)
225-
{
226-
if(
227-
const auto ge_expr =
228-
expr_try_dynamic_cast<greater_than_or_equal_exprt>(op))
229-
{
230-
equal_exprt new_expr{ge_expr->lhs(), ge_expr->rhs()};
231-
return changed(new_expr);
232-
}
233-
else
234-
continue;
235-
}
222+
// If we are here, we have matched the structure we expected, so we can
223+
// make some reasonable assumptions about where certain info we need is
224+
// located at.
225+
const auto ge_expr =
226+
expr_dynamic_cast<greater_than_or_equal_exprt>(new_operands[0]);
227+
equal_exprt new_expr{ge_expr.lhs(), ge_expr.rhs()};
228+
return changed(new_expr);
236229
}
237230
}
238231

0 commit comments

Comments
 (0)