Loading...
Searching...
No Matches
expr_cast.h File Reference
Templated functions to cast to specific exprt-derived classes.
More...
#include <typeinfo>
#include <type_traits>
#include <functional>
#include "invariant.h"
#include "expr.h"
+ Include dependency graph for expr_cast.h:
+ This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Check whether a reference to a generic
exprt is of a specific derived class.
Check whether a reference to a generic
typet is of a specific derived class.
Called after casting.
Try to cast a reference to a generic exprt to a specific derived class.
Try to cast a generic exprt to a specific derived class.
Try to cast a reference to a generic typet to a specific derived class.
Try to cast a generic typet to a specific derived class.
Cast a reference to a generic exprt to a specific derived class.
Cast a reference to a generic exprt to a specific derived class.
Cast a reference to a generic typet to a specific derived class and checks that the type could be converted.
Detailed Description
Templated functions to cast to specific exprt-derived classes.
Definition in file expr_cast.h.
Function Documentation
◆ can_cast_expr()
Check whether a reference to a generic exprt is of a specific derived class.
Implement template specializations of this function to enable casting
- Template Parameters
-
T The exprt-derived class to check for
- Parameters
-
base Reference to a generic
exprt
- Returns
- true if base is of type T
◆ can_cast_type()
Check whether a reference to a generic typet is of a specific derived class.
Implement template specializations of this function to enable casting
- Template Parameters
-
T The typet-derived class to check for
- Parameters
-
base Reference to a generic
typet
- Returns
- true if base is of type T
◆ expr_checked_cast()
Cast a reference to a generic exprt to a specific derived class.
Also assert that the expression has the expected type.
- Template Parameters
-
T The reference or const reference type to TUnderlying to cast to
TExpr The original type to cast from, either exprt or const exprt
- Parameters
-
base Reference to a generic
exprt
- Returns
- Reference to object of type T
- Exceptions
-
std::bad_cast If base is not an instance of TUnderlying
- Remarks
- If CBMC assertions (PRECONDITION) are set to abort then this will abort rather than throw if base is not an instance of TUnderlying
Definition at line 227 of file expr_cast.h.
◆ expr_dynamic_cast()
Cast a reference to a generic exprt to a specific derived class.
- Template Parameters
-
T The reference or const reference type to TUnderlying to cast to
TExpr The original type to cast from, either exprt or const exprt
- Parameters
-
base Reference to a generic
exprt
- Returns
- Reference to object of type T
- Exceptions
-
std::bad_cast If base is not an instance of TUnderlying
Definition at line 207 of file expr_cast.h.
◆ expr_try_dynamic_cast() [1/2]
std::optional< T > expr_try_dynamic_cast
(
TExpr &&
base )
Try to cast a generic exprt to a specific derived class.
- Template Parameters
-
T The type to cast the base param to.
TType The original type to cast from, must be a exprt rvalue.
- Parameters
-
base A generic
exprt rvalue.
- Returns
- Cast value in an std::optional<T> or empty if base is not an instance of T.
Definition at line 107 of file expr_cast.h.
◆ expr_try_dynamic_cast() [2/2]
Try to cast a reference to a generic exprt to a specific derived class.
- Template Parameters
-
T The reference or const reference type to TUnderlying to cast to
TExpr The original type to cast from, either exprt or const exprt
- Parameters
-
base Reference to a generic
exprt
- Returns
- Ptr to object of type TUnderlying or nullptr if base is not an instance of TUnderlying
Definition at line 81 of file expr_cast.h.
◆ type_checked_cast()
Cast a reference to a generic typet to a specific derived class and checks that the type could be converted.
- Template Parameters
-
T The reference or const reference type to TUnderlying to cast to
TType The original type to cast from, either typet or const typet
- Parameters
-
base Reference to a generic
typet
- Returns
- Reference to object of type T
Definition at line 242 of file expr_cast.h.
◆ type_try_dynamic_cast() [1/2]
std::optional< T > type_try_dynamic_cast
(
TType &&
base )
Try to cast a generic typet to a specific derived class.
- Template Parameters
-
T The type to cast the base param to.
TType The original type to cast from, must be a typet rvalue.
- Parameters
-
base A generic
typet rvalue.
- Returns
- Cast value in an std::optional<T> or empty if base is not an instance of T.
Definition at line 159 of file expr_cast.h.
◆ type_try_dynamic_cast() [2/2]
Try to cast a reference to a generic typet to a specific derived class.
- Template Parameters
-
T The reference or const reference type to TUnderlying to cast to
TType The original type to cast from, either typet or const typet
- Parameters
-
base Reference to a generic
typet
- Returns
- Ptr to object of type TUnderlying or nullptr if base is not an instance of TUnderlying
Definition at line 135 of file expr_cast.h.
◆ validate_expr()
Called after casting.
Provides a point to assert on the structure of the expr. By default, this is a no-op, but you can provide an overload to validate particular types. Should always succeed unless the program has entered an invalid state. We validate objects at cast time as that is when these checks have been used historically, but it would be reasonable to validate objects in this way at any time.
Definition at line 49 of file expr_cast.h.
◆ validate_operands()