@@ -3543,4 +3543,77 @@ inline bool can_cast_expr<class_method_descriptor_exprt>(const exprt &base)
35433543 return base.id () == ID_virtual_function;
35443544}
35453545
3546+ // / \brief Expression that introduces a new symbol that is equal to the operand.
3547+ // / This expression corresponds to the SMT-LIB2 feature 'named term'.
3548+ // / The symbol is not bound, i.e., visible outside of this expression.
3549+ // / The expression roughly corresponds to Python's "walrus operator", but
3550+ // / is not a side effect.
3551+ class named_term_exprt : public binary_exprt
3552+ {
3553+ public:
3554+ explicit named_term_exprt (symbol_exprt symbol, exprt value)
3555+ : binary_exprt(
3556+ std::move (symbol),
3557+ ID_named_term,
3558+ value, // not moved, for type
3559+ value.type())
3560+ {
3561+ PRECONDITION (symbol.type () == type ());
3562+ }
3563+
3564+ const symbol_exprt &symbol () const
3565+ {
3566+ return static_cast <const symbol_exprt &>(op0 ());
3567+ }
3568+
3569+ symbol_exprt &symbol ()
3570+ {
3571+ return static_cast <symbol_exprt &>(op0 ());
3572+ }
3573+
3574+ const exprt &value () const
3575+ {
3576+ return op1 ();
3577+ }
3578+
3579+ exprt &value ()
3580+ {
3581+ return op1 ();
3582+ }
3583+ };
3584+
3585+ template <>
3586+ inline bool can_cast_expr<named_term_exprt>(const exprt &base)
3587+ {
3588+ return base.id () == ID_named_term;
3589+ }
3590+
3591+ inline void validate_expr (const named_term_exprt &value)
3592+ {
3593+ validate_operands (value, 2 , " 'named term' must have two operands" );
3594+ }
3595+
3596+ // / \brief Cast an exprt to a \ref named_term_exprt
3597+ // /
3598+ // / \a expr must be known to be \ref named_term_exprt.
3599+ // /
3600+ // / \param expr: Source expression
3601+ // / \return Object of type \ref named_term_exprt
3602+ inline const named_term_exprt &to_named_term_expr (const exprt &expr)
3603+ {
3604+ PRECONDITION (expr.id () == ID_named_term);
3605+ const named_term_exprt &ret = static_cast <const named_term_exprt &>(expr);
3606+ validate_expr (ret);
3607+ return ret;
3608+ }
3609+
3610+ // / \copydoc to_array_comprehension_expr(const exprt &)
3611+ inline named_term_exprt &to_named_term_expr (exprt &expr)
3612+ {
3613+ PRECONDITION (expr.id () == ID_named_term);
3614+ named_term_exprt &ret = static_cast <named_term_exprt &>(expr);
3615+ validate_expr (ret);
3616+ return ret;
3617+ }
3618+
35463619#endif // CPROVER_UTIL_STD_EXPR_H
0 commit comments