Skip to content

Commit a51e9db

Browse files
committed
Add to_forall_expr
There was a cast operation for exists, but none for forall.
1 parent ea23bdd commit a51e9db

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

src/util/mathematical_expr.h

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ inline void validate_expr(const function_application_exprt &value)
257257
}
258258

259259
/// \brief A base class for quantifier expressions
260-
class quantifier_exprt : public binary_predicate_exprt
260+
class quantifier_exprt:public binary_predicate_exprt
261261
{
262262
public:
263263
quantifier_exprt(
@@ -297,9 +297,8 @@ class quantifier_exprt : public binary_predicate_exprt
297297
/// \return Object of type \ref quantifier_exprt
298298
inline const quantifier_exprt &to_quantifier_expr(const exprt &expr)
299299
{
300-
DATA_INVARIANT(
301-
expr.operands().size() == 2,
302-
"quantifier expressions must have two operands");
300+
DATA_INVARIANT(expr.operands().size()==2,
301+
"quantifier expressions must have two operands");
303302
DATA_INVARIANT(
304303
expr.op0().id() == ID_symbol, "quantified variable shall be a symbol");
305304
return static_cast<const quantifier_exprt &>(expr);
@@ -308,27 +307,26 @@ inline const quantifier_exprt &to_quantifier_expr(const exprt &expr)
308307
/// \copydoc to_quantifier_expr(const exprt &)
309308
inline quantifier_exprt &to_quantifier_expr(exprt &expr)
310309
{
311-
DATA_INVARIANT(
312-
expr.operands().size() == 2,
313-
"quantifier expressions must have two operands");
310+
DATA_INVARIANT(expr.operands().size()==2,
311+
"quantifier expressions must have two operands");
314312
DATA_INVARIANT(
315313
expr.op0().id() == ID_symbol, "quantified variable shall be a symbol");
316314
return static_cast<quantifier_exprt &>(expr);
317315
}
318316

319-
template <>
320-
inline bool can_cast_expr<quantifier_exprt>(const exprt &base)
317+
template<> inline bool can_cast_expr<quantifier_exprt>(const exprt &base)
321318
{
322319
return base.id() == ID_forall || base.id() == ID_exists;
323320
}
324321

325322
inline void validate_expr(const quantifier_exprt &value)
326323
{
327-
validate_operands(value, 2, "quantifier expressions must have two operands");
324+
validate_operands(value, 2,
325+
"quantifier expressions must have two operands");
328326
}
329327

330328
/// \brief A forall expression
331-
class forall_exprt : public quantifier_exprt
329+
class forall_exprt:public quantifier_exprt
332330
{
333331
public:
334332
forall_exprt(const symbol_exprt &_symbol, const exprt &_where)
@@ -337,8 +335,26 @@ class forall_exprt : public quantifier_exprt
337335
}
338336
};
339337

338+
inline const forall_exprt &to_forall_expr(const exprt &expr)
339+
{
340+
PRECONDITION(expr.id() == ID_forall);
341+
DATA_INVARIANT(
342+
expr.operands().size() == 2,
343+
"forall expressions have exactly two operands");
344+
return static_cast<const forall_exprt &>(expr);
345+
}
346+
347+
inline forall_exprt &to_forall_expr(exprt &expr)
348+
{
349+
PRECONDITION(expr.id() == ID_forall);
350+
DATA_INVARIANT(
351+
expr.operands().size() == 2,
352+
"forall expressions have exactly two operands");
353+
return static_cast<forall_exprt &>(expr);
354+
}
355+
340356
/// \brief An exists expression
341-
class exists_exprt : public quantifier_exprt
357+
class exists_exprt:public quantifier_exprt
342358
{
343359
public:
344360
exists_exprt(const symbol_exprt &_symbol, const exprt &_where)

0 commit comments

Comments
 (0)