LLVM  14.0.0git
Public Types | Public Member Functions | List of all members
llvm::TypeSwitch< T, ResultT > Class Template Reference

This class implements a switch-like dispatch statement for a value of 'T' using dyn_cast functionality. More...

#include "llvm/ADT/TypeSwitch.h"

Inheritance diagram for llvm::TypeSwitch< T, ResultT >:
Inheritance graph
[legend]
Collaboration diagram for llvm::TypeSwitch< T, ResultT >:
Collaboration graph
[legend]

Public Types

using BaseT = detail::TypeSwitchBase< TypeSwitch< T, ResultT >, T >
 

Public Member Functions

 TypeSwitch (TypeSwitch &&other)=default
 
template<typename CaseT , typename CallableT >
TypeSwitch< T, ResultT > & Case (CallableT &&caseFn)
 Add a case on the given type. More...
 
template<typename CallableT >
LLVM_NODISCARD ResultT Default (CallableT &&defaultFn)
 As a default, invoke the given callable within the root value. More...
 
LLVM_NODISCARD ResultT Default (ResultT defaultResult)
 As a default, return the given value. More...
 
LLVM_NODISCARD operator ResultT ()
 
template<typename CaseT , typename CaseT2 , typename... CaseTs, typename CallableT >
LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_NODEBUG DerivedT & Case (CallableT &&caseFn)
 Invoke a case on the derived class with multiple case types. More...
 
template<typename CallableT >
DerivedT & Case (CallableT &&caseFn)
 Invoke a case on the derived class, inferring the type of the Case from the first input of the given callable. More...
 
- Public Member Functions inherited from llvm::detail::TypeSwitchBase< TypeSwitch< T, void >, T >
 TypeSwitchBase (const T &value)
 
 TypeSwitchBase (TypeSwitchBase &&other)
 
 TypeSwitchBase (const TypeSwitchBase &)=delete
 TypeSwitchBase is not copyable. More...
 
 ~TypeSwitchBase ()=default
 
void operator= (const TypeSwitchBase &)=delete
 
void operator= (TypeSwitchBase &&other)=delete
 
LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_NODEBUG TypeSwitch< T, void > & Case (CallableT &&caseFn)
 Invoke a case on the derived class with multiple case types. More...
 
TypeSwitch< T, void > & Case (CallableT &&caseFn)
 Invoke a case on the derived class, inferring the type of the Case from the first input of the given callable. More...
 

Additional Inherited Members

- Protected Types inherited from llvm::detail::TypeSwitchBase< TypeSwitch< T, void >, T >
using has_dyn_cast_t = decltype(std::declval< ValueT & >().template dyn_cast< CastT >())
 Trait to check whether ValueT provides a 'dyn_cast' method with type CastT. More...
 
- Static Protected Member Functions inherited from llvm::detail::TypeSwitchBase< TypeSwitch< T, void >, T >
static auto castValue (ValueT value, typename std::enable_if_t< is_detected< has_dyn_cast_t, ValueT, CastT >::value > *=nullptr)
 Attempt to dyn_cast the given value to CastT. More...
 
static auto castValue (ValueT value, typename std::enable_if_t< !is_detected< has_dyn_cast_t, ValueT, CastT >::value > *=nullptr)
 Attempt to dyn_cast the given value to CastT. More...
 
- Protected Attributes inherited from llvm::detail::TypeSwitchBase< TypeSwitch< T, void >, T >
const T value
 The root value we are switching on. More...
 

Detailed Description

template<typename T, typename ResultT = void>
class llvm::TypeSwitch< T, ResultT >

This class implements a switch-like dispatch statement for a value of 'T' using dyn_cast functionality.

Each Case<T> takes a callable to be invoked if the root value isa<T>, the callable is invoked with the result of dyn_cast<T>() as a parameter.

Example: Operation *op = ...; LogicalResult result = TypeSwitch<Operation *, LogicalResult>(op) .Case<ConstantOp>([](ConstantOp op) { ... }) .Default([](Operation *op) { ... });

Definition at line 106 of file TypeSwitch.h.

Member Typedef Documentation

◆ BaseT

template<typename T , typename ResultT = void>
using llvm::TypeSwitch< T, ResultT >::BaseT = detail::TypeSwitchBase<TypeSwitch<T, ResultT>, T>

Definition at line 108 of file TypeSwitch.h.

Constructor & Destructor Documentation

◆ TypeSwitch()

template<typename T , typename ResultT = void>
llvm::TypeSwitch< T, ResultT >::TypeSwitch ( TypeSwitch< T, ResultT > &&  other)
default

Member Function Documentation

◆ Case() [1/3]

template<typename T , typename ResultT = void>
template<typename CaseT , typename CaseT2 , typename... CaseTs, typename CallableT >
LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_NODEBUG DerivedT& llvm::detail::TypeSwitchBase< DerivedT, T >::Case ( typename CaseT  ,
typename CaseT2  ,
typename...  CaseTs,
typename CallableT   
)
inline

Invoke a case on the derived class with multiple case types.

Definition at line 43 of file TypeSwitch.h.

◆ Case() [2/3]

template<typename T , typename ResultT = void>
template<typename CallableT >
DerivedT& llvm::detail::TypeSwitchBase< DerivedT, T >::Case ( typename CallableT  )
inline

Invoke a case on the derived class, inferring the type of the Case from the first input of the given callable.

Note: This inference rules for this overload are very simple: strip pointers and references.

Definition at line 53 of file TypeSwitch.h.

◆ Case() [3/3]

template<typename T , typename ResultT = void>
template<typename CaseT , typename CallableT >
TypeSwitch<T, ResultT>& llvm::TypeSwitch< T, ResultT >::Case ( CallableT &&  caseFn)
inline

Add a case on the given type.

Definition at line 115 of file TypeSwitch.h.

References llvm::detail::TypeSwitchBase< TypeSwitch< T, void >, T >::value.

◆ Default() [1/2]

template<typename T , typename ResultT = void>
template<typename CallableT >
LLVM_NODISCARD ResultT llvm::TypeSwitch< T, ResultT >::Default ( CallableT &&  defaultFn)
inline

As a default, invoke the given callable within the root value.

Definition at line 127 of file TypeSwitch.h.

References move, and llvm::detail::TypeSwitchBase< TypeSwitch< T, void >, T >::value.

◆ Default() [2/2]

template<typename T , typename ResultT = void>
LLVM_NODISCARD ResultT llvm::TypeSwitch< T, ResultT >::Default ( ResultT  defaultResult)
inline

As a default, return the given value.

Definition at line 133 of file TypeSwitch.h.

References move.

◆ operator ResultT()

template<typename T , typename ResultT = void>
LLVM_NODISCARD llvm::TypeSwitch< T, ResultT >::operator ResultT ( )
inline

Definition at line 140 of file TypeSwitch.h.

References assert(), and move.


The documentation for this class was generated from the following file: