Skip to content

Commit d93a021

Browse files
committed
Introduce complex_real_exprt and complex_imag_exprt
1 parent 2542d0d commit d93a021

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

src/util/std_expr.h

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,106 @@ inline void validate_expr(const complex_exprt &value)
17311731
}
17321732

17331733

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

17361836
/// \brief Split an expression into a base object and a (byte) offset

0 commit comments

Comments
 (0)