LLVM 19.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]

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.
 
template<typename CallableT >
ResultT Default (CallableT &&defaultFn)
 As a default, invoke the given callable within the root value.
 
ResultT Default (ResultT defaultResult)
 As a default, return the given value.
 
 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.
 
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.
 
- Public Member Functions inherited from llvm::detail::TypeSwitchBase< DerivedT, T >
 TypeSwitchBase (const T &value)
 
 TypeSwitchBase (TypeSwitchBase &&other)
 
 ~TypeSwitchBase ()=default
 
 TypeSwitchBase (const TypeSwitchBase &)=delete
 TypeSwitchBase is not copyable.
 
void operator= (const TypeSwitchBase &)=delete
 
void operator= (TypeSwitchBase &&other)=delete
 
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.
 
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.
 

Additional Inherited Members

- Protected Types inherited from llvm::detail::TypeSwitchBase< DerivedT, T >
template<typename ValueT , typename CastT >
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.
 
- Static Protected Member Functions inherited from llvm::detail::TypeSwitchBase< DerivedT, T >
template<typename CastT , typename ValueT >
static decltype(auto) castValue (ValueT &&value, std::enable_if_t< is_detected< has_dyn_cast_t, ValueT, CastT >::value > *=nullptr)
 Attempt to dyn_cast the given value to CastT.
 
template<typename CastT , typename ValueT >
static decltype(auto) castValue (ValueT &&value, std::enable_if_t<!is_detected< has_dyn_cast_t, ValueT, CastT >::value > *=nullptr)
 Attempt to dyn_cast the given value to CastT.
 
- Protected Attributes inherited from llvm::detail::TypeSwitchBase< DerivedT, T >
const T value
 The root value we are switching on.
 

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 107 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 109 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 ( CallableT &&  caseFn)
inline

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

Definition at line 44 of file TypeSwitch.h.

◆ Case() [2/3]

template<typename T , typename ResultT = void>
template<typename CallableT >
DerivedT & llvm::detail::TypeSwitchBase< DerivedT, T >::Case ( CallableT &&  caseFn)
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 54 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 116 of file TypeSwitch.h.

References llvm::detail::TypeSwitchBase< DerivedT, T >::value.

Referenced by llvm::VPTypeAnalysis::inferScalarType().

◆ Default() [1/2]

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

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

Definition at line 128 of file TypeSwitch.h.

References llvm::detail::TypeSwitchBase< DerivedT, T >::value.

◆ Default() [2/2]

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

As a default, return the given value.

Definition at line 134 of file TypeSwitch.h.

◆ operator ResultT()

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

Definition at line 140 of file TypeSwitch.h.

References assert().


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