Skip to content

Commit 00cc4b1

Browse files
authored
Merge pull request #1897 from diffblue/quantifier_exprt
added a base class for forall_exprt and exists_exprt
2 parents 8897709 + fd513a6 commit 00cc4b1

File tree

1 file changed

+48
-23
lines changed

1 file changed

+48
-23
lines changed

src/util/std_expr.h

+48-23
Original file line numberDiff line numberDiff line change
@@ -4744,13 +4744,12 @@ inline void validate_expr(const let_exprt &value)
47444744
validate_operands(value, 3, "Let must have three operands");
47454745
}
47464746

4747-
4748-
/*! \brief A forall expression
4747+
/*! \brief A base class for quantifier expressions
47494748
*/
4750-
class forall_exprt:public binary_exprt
4749+
class quantifier_exprt:public binary_predicate_exprt
47514750
{
47524751
public:
4753-
forall_exprt():binary_exprt(ID_forall)
4752+
explicit quantifier_exprt(const irep_idt &_id):binary_predicate_exprt(_id)
47544753
{
47554754
op0()=symbol_exprt();
47564755
}
@@ -4776,34 +4775,60 @@ class forall_exprt:public binary_exprt
47764775
}
47774776
};
47784777

4779-
/*! \brief An exists expression
4778+
/*! \brief Cast a generic exprt to a \ref quantifier_exprt
4779+
*
4780+
* This is an unchecked conversion. \a expr must be known to be \ref
4781+
* quantifier_exprt.
4782+
*
4783+
* \param expr Source expression
4784+
* \return Object of type \ref quantifier_exprt
4785+
*
4786+
* \ingroup gr_std_expr
47804787
*/
4781-
class exists_exprt:public binary_exprt
4788+
inline const quantifier_exprt &to_quantifier_expr(const exprt &expr)
47824789
{
4783-
public:
4784-
exists_exprt():binary_exprt(ID_exists)
4785-
{
4786-
op0()=symbol_exprt();
4787-
}
4790+
DATA_INVARIANT(expr.operands().size()==2,
4791+
"quantifier expressions must have two operands");
4792+
return static_cast<const quantifier_exprt &>(expr);
4793+
}
47884794

4789-
symbol_exprt &symbol()
4790-
{
4791-
return static_cast<symbol_exprt &>(op0());
4792-
}
4795+
/*! \copydoc to_quantifier_expr(const exprt &)
4796+
* \ingroup gr_std_expr
4797+
*/
4798+
inline quantifier_exprt &to_quantifier_expr(exprt &expr)
4799+
{
4800+
DATA_INVARIANT(expr.operands().size()==2,
4801+
"quantifier expressions must have two operands");
4802+
return static_cast<quantifier_exprt &>(expr);
4803+
}
47934804

4794-
const symbol_exprt &symbol() const
4795-
{
4796-
return static_cast<const symbol_exprt &>(op0());
4797-
}
4805+
template<> inline bool can_cast_expr<quantifier_exprt>(const exprt &base)
4806+
{
4807+
return true;
4808+
}
4809+
inline void validate_expr(const quantifier_exprt &value)
4810+
{
4811+
validate_operands(value, 2,
4812+
"quantifier expressions must have two operands");
4813+
}
47984814

4799-
exprt &where()
4815+
/*! \brief A forall expression
4816+
*/
4817+
class forall_exprt:public quantifier_exprt
4818+
{
4819+
public:
4820+
forall_exprt():quantifier_exprt(ID_forall)
48004821
{
4801-
return op1();
48024822
}
4823+
};
48034824

4804-
const exprt &where() const
4825+
/*! \brief An exists expression
4826+
*/
4827+
class exists_exprt:public quantifier_exprt
4828+
{
4829+
public:
4830+
exists_exprt():quantifier_exprt(ID_exists)
48054831
{
4806-
return op1();
48074832
}
48084833
};
48094834

0 commit comments

Comments
 (0)