@@ -1742,4 +1742,74 @@ inline zero_extend_exprt &to_zero_extend_expr(exprt &expr)
1742
1742
return static_cast <zero_extend_exprt &>(expr);
1743
1743
}
1744
1744
1745
+ // / \brief A Boolean expression returning true iff the given
1746
+ // / operand consists of exactly one '1' and '0' otherwise.
1747
+ class onehot_exprt : public unary_predicate_exprt
1748
+ {
1749
+ public:
1750
+ explicit onehot_exprt (exprt _op)
1751
+ : unary_predicate_exprt(ID_onehot, std::move(_op))
1752
+ {
1753
+ }
1754
+
1755
+ // / lowering to extractbit
1756
+ exprt lower () const ;
1757
+ };
1758
+
1759
+ // / \brief Cast an exprt to a \ref onehot_exprt
1760
+ // /
1761
+ // / \a expr must be known to be \ref onehot_exprt.
1762
+ // /
1763
+ // / \param expr: Source expression
1764
+ // / \return Object of type \ref onehot_exprt
1765
+ inline const onehot_exprt &to_onehot_expr (const exprt &expr)
1766
+ {
1767
+ PRECONDITION (expr.id () == ID_onehot);
1768
+ onehot_exprt::check (expr);
1769
+ return static_cast <const onehot_exprt &>(expr);
1770
+ }
1771
+
1772
+ // / \copydoc to_onehot_expr(const exprt &)
1773
+ inline onehot_exprt &to_onehot_expr (exprt &expr)
1774
+ {
1775
+ PRECONDITION (expr.id () == ID_onehot);
1776
+ onehot_exprt::check (expr);
1777
+ return static_cast <onehot_exprt &>(expr);
1778
+ }
1779
+
1780
+ // / \brief A Boolean expression returning true iff the given
1781
+ // / operand consists of exactly one '0' and '1' otherwise.
1782
+ class onehot0_exprt : public unary_predicate_exprt
1783
+ {
1784
+ public:
1785
+ explicit onehot0_exprt (exprt _op)
1786
+ : unary_predicate_exprt(ID_onehot0, std::move(_op))
1787
+ {
1788
+ }
1789
+
1790
+ // / lowering to extractbit
1791
+ exprt lower () const ;
1792
+ };
1793
+
1794
+ // / \brief Cast an exprt to a \ref onehot0_exprt
1795
+ // /
1796
+ // / \a expr must be known to be \ref onehot0_exprt.
1797
+ // /
1798
+ // / \param expr: Source expression
1799
+ // / \return Object of type \ref onehot0_exprt
1800
+ inline const onehot0_exprt &to_onehot0_expr (const exprt &expr)
1801
+ {
1802
+ PRECONDITION (expr.id () == ID_onehot0);
1803
+ onehot0_exprt::check (expr);
1804
+ return static_cast <const onehot0_exprt &>(expr);
1805
+ }
1806
+
1807
+ // / \copydoc to_onehot0_expr(const exprt &)
1808
+ inline onehot0_exprt &to_onehot0_expr (exprt &expr)
1809
+ {
1810
+ PRECONDITION (expr.id () == ID_onehot0);
1811
+ onehot0_exprt::check (expr);
1812
+ return static_cast <onehot0_exprt &>(expr);
1813
+ }
1814
+
1745
1815
#endif // CPROVER_UTIL_BITVECTOR_EXPR_H
0 commit comments