@@ -1730,6 +1730,99 @@ inline void validate_expr(const complex_exprt &value)
1730
1730
validate_operands (value, 2 , " Complex constructor must have two operands" );
1731
1731
}
1732
1732
1733
+ // / \brief Real part of the expression describing a complex number.
1734
+ class complex_real_exprt : public unary_exprt
1735
+ {
1736
+ public:
1737
+ explicit complex_real_exprt (const exprt &op)
1738
+ : unary_exprt(ID_complex_real, op, to_complex_type(op.type()).subtype())
1739
+ {
1740
+ }
1741
+ };
1742
+
1743
+ // / \brief Cast an exprt to a \ref complex_real_exprt
1744
+ // /
1745
+ // / \a expr must be known to be a \ref complex_real_exprt.
1746
+ // /
1747
+ // / \param expr: Source expression
1748
+ // / \return Object of type \ref complex_real_exprt
1749
+ inline const complex_real_exprt &to_complex_real_expr (const exprt &expr)
1750
+ {
1751
+ PRECONDITION (expr.id () == ID_complex_real);
1752
+ DATA_INVARIANT (
1753
+ expr.operands ().size () == 1 ,
1754
+ " real part retrieval operation must have one operand" );
1755
+ return static_cast <const complex_real_exprt &>(expr);
1756
+ }
1757
+
1758
+ // / \copydoc to_complex_real_expr(const exprt &)
1759
+ inline complex_real_exprt &to_complex_real_expr (exprt &expr)
1760
+ {
1761
+ PRECONDITION (expr.id () == ID_complex_real);
1762
+ DATA_INVARIANT (
1763
+ expr.operands ().size () == 1 ,
1764
+ " real part retrieval operation must have one operand" );
1765
+ return static_cast <complex_real_exprt &>(expr);
1766
+ }
1767
+
1768
+ template <>
1769
+ inline bool can_cast_expr<complex_real_exprt>(const exprt &base)
1770
+ {
1771
+ return base.id () == ID_complex_real;
1772
+ }
1773
+
1774
+ inline void validate_expr (const complex_real_exprt &expr)
1775
+ {
1776
+ validate_operands (
1777
+ expr, 1 , " real part retrieval operation must have one operand" );
1778
+ }
1779
+
1780
+ // / \brief Imaginary part of the expression describing a complex number.
1781
+ class complex_imag_exprt : public unary_exprt
1782
+ {
1783
+ public:
1784
+ explicit complex_imag_exprt (const exprt &op)
1785
+ : unary_exprt(ID_complex_imag, op, to_complex_type(op.type()).subtype())
1786
+ {
1787
+ }
1788
+ };
1789
+
1790
+ // / \brief Cast an exprt to a \ref complex_imag_exprt
1791
+ // /
1792
+ // / \a expr must be known to be a \ref complex_imag_exprt.
1793
+ // /
1794
+ // / \param expr: Source expression
1795
+ // / \return Object of type \ref complex_imag_exprt
1796
+ inline const complex_imag_exprt &to_complex_imag_expr (const exprt &expr)
1797
+ {
1798
+ PRECONDITION (expr.id () == ID_complex_imag);
1799
+ DATA_INVARIANT (
1800
+ expr.operands ().size () == 1 ,
1801
+ " imaginary part retrieval operation must have one operand" );
1802
+ return static_cast <const complex_imag_exprt &>(expr);
1803
+ }
1804
+
1805
+ // / \copydoc to_complex_imag_expr(const exprt &)
1806
+ inline complex_imag_exprt &to_complex_imag_expr (exprt &expr)
1807
+ {
1808
+ PRECONDITION (expr.id () == ID_complex_imag);
1809
+ DATA_INVARIANT (
1810
+ expr.operands ().size () == 1 ,
1811
+ " imaginary part retrieval operation must have one operand" );
1812
+ return static_cast <complex_imag_exprt &>(expr);
1813
+ }
1814
+
1815
+ template <>
1816
+ inline bool can_cast_expr<complex_imag_exprt>(const exprt &base)
1817
+ {
1818
+ return base.id () == ID_complex_imag;
1819
+ }
1820
+
1821
+ inline void validate_expr (const complex_imag_exprt &expr)
1822
+ {
1823
+ validate_operands (
1824
+ expr, 1 , " imaginary part retrieval operation must have one operand" );
1825
+ }
1733
1826
1734
1827
class namespacet ;
1735
1828
0 commit comments