LLVM 20.0.0git
Public Member Functions | List of all members
llvm::StringSwitch< T, R > Class Template Reference

A switch()-like statement whose cases are string literals. More...

#include "llvm/ADT/StringSwitch.h"

Public Member Functions

 StringSwitch (StringRef S)
 
 StringSwitch (const StringSwitch &)=delete
 
void operator= (const StringSwitch &)=delete
 
void operator= (StringSwitch &&other)=delete
 
 StringSwitch (StringSwitch &&other)
 
 ~StringSwitch ()=default
 
StringSwitchCase (StringLiteral S, T Value)
 
StringSwitchEndsWith (StringLiteral S, T Value)
 
StringSwitchStartsWith (StringLiteral S, T Value)
 
StringSwitchCases (StringLiteral S0, StringLiteral S1, T Value)
 
StringSwitchCases (StringLiteral S0, StringLiteral S1, StringLiteral S2, T Value)
 
StringSwitchCases (StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, T Value)
 
StringSwitchCases (StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, T Value)
 
StringSwitchCases (StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, StringLiteral S5, T Value)
 
StringSwitchCases (StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, StringLiteral S5, StringLiteral S6, T Value)
 
StringSwitchCases (StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, StringLiteral S5, StringLiteral S6, StringLiteral S7, T Value)
 
StringSwitchCases (StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, StringLiteral S5, StringLiteral S6, StringLiteral S7, StringLiteral S8, T Value)
 
StringSwitchCases (StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, StringLiteral S5, StringLiteral S6, StringLiteral S7, StringLiteral S8, StringLiteral S9, T Value)
 
StringSwitchCaseLower (StringLiteral S, T Value)
 
StringSwitchEndsWithLower (StringLiteral S, T Value)
 
StringSwitchStartsWithLower (StringLiteral S, T Value)
 
StringSwitchCasesLower (StringLiteral S0, StringLiteral S1, T Value)
 
StringSwitchCasesLower (StringLiteral S0, StringLiteral S1, StringLiteral S2, T Value)
 
StringSwitchCasesLower (StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, T Value)
 
StringSwitchCasesLower (StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, T Value)
 
Default (T Value)
 
 operator R ()
 

Detailed Description

template<typename T, typename R = T>
class llvm::StringSwitch< T, R >

A switch()-like statement whose cases are string literals.

The StringSwitch class is a simple form of a switch() statement that determines whether the given string matches one of the given string literals. The template type parameter T is the type of the value that will be returned from the string-switch expression. For example, the following code switches on the name of a color in argv[i]:

Color color = StringSwitch<Color>(argv[i])
.Case("red", Red)
.Case("orange", Orange)
.Case("yellow", Yellow)
.Case("green", Green)
.Case("blue", Blue)
.Case("indigo", Indigo)
.Cases("violet", "purple", Violet)
.Default(UnknownColor);
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, T Value)
Definition: StringSwitch.h:90

Definition at line 44 of file StringSwitch.h.

Constructor & Destructor Documentation

◆ StringSwitch() [1/3]

template<typename T , typename R = T>
llvm::StringSwitch< T, R >::StringSwitch ( StringRef  S)
inlineexplicit

Definition at line 53 of file StringSwitch.h.

◆ StringSwitch() [2/3]

template<typename T , typename R = T>
llvm::StringSwitch< T, R >::StringSwitch ( const StringSwitch< T, R > &  )
delete

◆ StringSwitch() [3/3]

template<typename T , typename R = T>
llvm::StringSwitch< T, R >::StringSwitch ( StringSwitch< T, R > &&  other)
inline

Definition at line 63 of file StringSwitch.h.

◆ ~StringSwitch()

template<typename T , typename R = T>
llvm::StringSwitch< T, R >::~StringSwitch ( )
default

Member Function Documentation

◆ Case()

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::Case ( StringLiteral  S,
T  Value 
)
inline

Definition at line 69 of file StringSwitch.h.

Referenced by llvm::AArch64StringToVectorLayout(), llvm::ARMCondCodeFromString(), llvm::ARMVectorCondCodeFromString(), llvm::StringSwitch< T, R >::Cases(), llvm::classifyEHPersonality(), llvm::ELF::convertArchNameToEMachine(), llvm::convertStrToExceptionBehavior(), llvm::convertStrToRoundingMode(), llvm::TargetOptions::FramePointerIsReserved(), llvm::ARM::getArchSynonym(), llvm::Triple::getArchTypeForLLVMName(), llvm::DIFile::getChecksumKind(), llvm::Hexagon::getCpu(), llvm::Hexagon_MC::GetELFFlags(), llvm::DICompileUnit::getEmissionKind(), llvm::ARMAsmBackendELF::getFixupKind(), llvm::AVRAsmBackend::getFixupKind(), llvm::LoongArchAsmBackend::getFixupKind(), llvm::MipsAsmBackend::getFixupKind(), llvm::RISCVAsmBackend::getFixupKind(), getFPPredicateFromMD(), llvm::ARM::getFPUSynonym(), llvm::sys::detail::getHostCPUNameForARM(), llvm::sys::detail::getHostCPUNameForPowerPC(), llvm::sys::detail::getHostCPUNameForRISCV(), getHWDivSynonym(), getIdentifierKind(), llvm::object::getImageKind(), llvm::M68kTargetLowering::getInlineAsmMemConstraint(), getIntPredicateFromMD(), llvm::mca::RISCVLMULInstrument::getLMUL(), llvm::getMachineType(), llvm::dwarf::getMacinfo(), getMClassFlagsMask(), getMetadataKeywordKind(), llvm::DICompileUnit::getNameTableKind(), llvm::object::getOffloadKind(), llvm::dwarf::getOperationEncoding(), llvm::MachO::getPlatformFromName(), llvm::RISCVTargetLowering::getRegForInlineAsmConstraint(), llvm::SITargetLowering::getRegisterByName(), llvm::AVRTargetLowering::getRegisterByName(), llvm::HexagonTargetLowering::getRegisterByName(), llvm::LanaiTargetLowering::getRegisterByName(), llvm::MipsTargetLowering::getRegisterByName(), llvm::PPCTargetLowering::getRegisterByName(), llvm::SparcTargetLowering::getRegisterByName(), llvm::SystemZTargetLowering::getRegisterByName(), llvm::VETargetLowering::getRegisterByName(), llvm::X86TargetLowering::getRegisterByName(), llvm::mca::RISCVSEWInstrument::getSEW(), llvm::pdb::PDBSymbolCompiland::getSourceFileFullPath(), getSpecialRegForName(), llvm::LoongArchABI::getTargetABI(), llvm::RISCVABI::getTargetABI(), llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::getValueKind(), llvm::MCSymbolRefExpr::getVariantKindForName(), llvm::LoongArchMCExpr::getVariantKindForName(), llvm::RISCVMCExpr::getVariantKindForName(), llvm::VFABI::getVFParamKindFromString(), llvm::yaml::ScalarTraits< IFSBitWidthType >::input(), llvm::yaml::ScalarTraits< IFSEndiannessType >::input(), llvm::yaml::ScalarTraits< SwiftVersion >::input(), isSMEABIRoutineCall(), isSpecialLLVMGlobalArrayToSkip(), llvm::object::Lexer::lex(), llvm::object::COFFObjectFile::mapDebugSectionName(), llvm::object::MachOObjectFile::mapDebugSectionName(), llvm::object::XCOFFObjectFile::mapDebugSectionName(), matchMatrixRegName(), matchMatrixTileListRegName(), MatchNeonVectorRegName(), matchSVEDataVectorRegName(), matchSVEPredicateAsCounterRegName(), matchSVEPredicateVectorRegName(), MCAttrForString(), llvm::PPC::normalizeCPUName(), llvm::HexagonMCInstrInfo::packetSize(), parseAMDGPUAtomicOptimizerStrategy(), parseArch(), llvm::WebAssembly::parseBlockType(), parseConstraintCode(), llvm::parseDenormalFPAttributeComponent(), llvm::MachO::TextAPIWriter::parseFileType(), llvm::remarks::parseFormat(), llvm::WebAssembly::parseMVT(), parseNamePrefix(), parseOptLevel(), parsePredicateConstraint(), parseReducedGprConstraint(), llvm::remarks::YAMLRemarkParser::parseType(), llvm::SparcMCExpr::parseVariantKind(), llvm::VEMCExpr::parseVariantKind(), parseVendor(), llvm::SymbolRemappingReader::read(), shouldUpgradeNVPTXBF16Intrinsic(), llvm::LPAC::stringToLanaiAluCode(), llvm::RISCVFPRndMode::stringToRoundingMode(), llvm::stringToVEFCondCode(), llvm::stringToVEICondCode(), llvm::stringToVERD(), upgradeArmOrAarch64IntrinsicFunction(), upgradeIntrinsicFunction1(), and upgradeX86IntrinsicFunction().

◆ CaseLower()

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::CaseLower ( StringLiteral  S,
T  Value 
)
inline

Definition at line 142 of file StringSwitch.h.

Referenced by llvm::StringSwitch< T, R >::CasesLower().

◆ Cases() [1/9]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::Cases ( StringLiteral  S0,
StringLiteral  S1,
StringLiteral  S2,
StringLiteral  S3,
StringLiteral  S4,
StringLiteral  S5,
StringLiteral  S6,
StringLiteral  S7,
StringLiteral  S8,
StringLiteral  S9,
T  Value 
)
inline

◆ Cases() [2/9]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::Cases ( StringLiteral  S0,
StringLiteral  S1,
StringLiteral  S2,
StringLiteral  S3,
StringLiteral  S4,
StringLiteral  S5,
StringLiteral  S6,
StringLiteral  S7,
StringLiteral  S8,
T  Value 
)
inline

◆ Cases() [3/9]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::Cases ( StringLiteral  S0,
StringLiteral  S1,
StringLiteral  S2,
StringLiteral  S3,
StringLiteral  S4,
StringLiteral  S5,
StringLiteral  S6,
StringLiteral  S7,
T  Value 
)
inline

◆ Cases() [4/9]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::Cases ( StringLiteral  S0,
StringLiteral  S1,
StringLiteral  S2,
StringLiteral  S3,
StringLiteral  S4,
StringLiteral  S5,
StringLiteral  S6,
T  Value 
)
inline

◆ Cases() [5/9]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::Cases ( StringLiteral  S0,
StringLiteral  S1,
StringLiteral  S2,
StringLiteral  S3,
StringLiteral  S4,
StringLiteral  S5,
T  Value 
)
inline

◆ Cases() [6/9]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::Cases ( StringLiteral  S0,
StringLiteral  S1,
StringLiteral  S2,
StringLiteral  S3,
StringLiteral  S4,
T  Value 
)
inline

◆ Cases() [7/9]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::Cases ( StringLiteral  S0,
StringLiteral  S1,
StringLiteral  S2,
StringLiteral  S3,
T  Value 
)
inline

◆ Cases() [8/9]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::Cases ( StringLiteral  S0,
StringLiteral  S1,
StringLiteral  S2,
T  Value 
)
inline

◆ Cases() [9/9]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::Cases ( StringLiteral  S0,
StringLiteral  S1,
T  Value 
)
inline

◆ CasesLower() [1/4]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::CasesLower ( StringLiteral  S0,
StringLiteral  S1,
StringLiteral  S2,
StringLiteral  S3,
StringLiteral  S4,
T  Value 
)
inline

◆ CasesLower() [2/4]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::CasesLower ( StringLiteral  S0,
StringLiteral  S1,
StringLiteral  S2,
StringLiteral  S3,
T  Value 
)
inline

◆ CasesLower() [3/4]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::CasesLower ( StringLiteral  S0,
StringLiteral  S1,
StringLiteral  S2,
T  Value 
)
inline

◆ CasesLower() [4/4]

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::CasesLower ( StringLiteral  S0,
StringLiteral  S1,
T  Value 
)
inline

Definition at line 163 of file StringSwitch.h.

References llvm::StringSwitch< T, R >::CaseLower(), and S1.

Referenced by llvm::StringSwitch< T, R >::CasesLower().

◆ Default()

template<typename T , typename R = T>
R llvm::StringSwitch< T, R >::Default ( T  Value)
inline

Definition at line 182 of file StringSwitch.h.

Referenced by llvm::AArch64StringToVectorLayout(), llvm::ARMCondCodeFromString(), llvm::ARMVectorCondCodeFromString(), llvm::classifyEHPersonality(), llvm::ELF::convertArchNameToEMachine(), llvm::ELF::convertNameToOSABI(), llvm::convertStrToExceptionBehavior(), llvm::convertStrToRoundingMode(), llvm::MachO::Target::create(), llvm::MachO::getArchitectureFromName(), llvm::ARM::getArchSynonym(), llvm::Triple::getArchTypeForLLVMName(), llvm::dwarf::getAttributeEncoding(), llvm::Attribute::getAttrKindFromName(), llvm::dwarf::getCallingConvention(), llvm::DIFile::getChecksumKind(), llvm::Hexagon::getCpu(), llvm::CSKY::getDefaultExtensions(), llvm::ARM::getDefaultExtensions(), llvm::ARM::getDefaultFPU(), llvm::DICompileUnit::getEmissionKind(), llvm::ARMAsmBackendELF::getFixupKind(), llvm::AVRAsmBackend::getFixupKind(), llvm::LoongArchAsmBackend::getFixupKind(), llvm::MipsAsmBackend::getFixupKind(), llvm::RISCVAsmBackend::getFixupKind(), llvm::DINode::getFlag(), llvm::DISubprogram::getFlag(), getFPPredicateFromMD(), llvm::ARM::getFPUSynonym(), llvm::sys::detail::getHostCPUNameForARM(), llvm::sys::detail::getHostCPUNameForPowerPC(), llvm::sys::detail::getHostCPUNameForRISCV(), getHWDivSynonym(), getIdentifierKind(), llvm::object::getImageKind(), llvm::M68kTargetLowering::getInlineAsmMemConstraint(), getIntPredicateFromMD(), llvm::dwarf::getLanguage(), getLlvmUserOperationEncoding(), llvm::getMachineType(), llvm::dwarf::getMacinfo(), llvm::dwarf::getMacro(), getMClassFlagsMask(), getMetadataKeywordKind(), llvm::DICompileUnit::getNameTableKind(), llvm::object::getOffloadKind(), llvm::omp::getOpenMPContextTraitPropertyForSelector(), llvm::omp::getOpenMPContextTraitSelectorKind(), llvm::omp::getOpenMPContextTraitSetKind(), llvm::dwarf::getOperationEncoding(), llvm::MachO::getPlatformFromName(), llvm::RISCVTargetLowering::getRegForInlineAsmConstraint(), llvm::SITargetLowering::getRegisterByName(), llvm::AVRTargetLowering::getRegisterByName(), llvm::HexagonTargetLowering::getRegisterByName(), llvm::LanaiTargetLowering::getRegisterByName(), llvm::MipsTargetLowering::getRegisterByName(), llvm::PPCTargetLowering::getRegisterByName(), llvm::SparcTargetLowering::getRegisterByName(), llvm::SystemZTargetLowering::getRegisterByName(), llvm::VETargetLowering::getRegisterByName(), llvm::X86TargetLowering::getRegisterByName(), llvm::pdb::PDBSymbolCompiland::getSourceFileFullPath(), getSpecialRegForName(), llvm::dwarf::getTag(), llvm::LoongArchABI::getTargetABI(), llvm::RISCVABI::getTargetABI(), llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::getValueKind(), llvm::MCSymbolRefExpr::getVariantKindForName(), llvm::LoongArchMCExpr::getVariantKindForName(), llvm::RISCVMCExpr::getVariantKindForName(), llvm::XtensaMCExpr::getVariantKindForName(), llvm::VFABI::getVFParamKindFromString(), llvm::dwarf::getVirtuality(), llvm::yaml::ScalarTraits< IFSBitWidthType >::input(), llvm::yaml::ScalarTraits< IFSEndiannessType >::input(), llvm::yaml::ScalarTraits< SwiftVersion >::input(), llvm::mca::RISCVLMULInstrument::isDataValid(), llvm::mca::RISCVSEWInstrument::isDataValid(), llvm::Attribute::isExistingAttribute(), isSMEABIRoutineCall(), isSpecialLLVMGlobalArrayForStaticInit(), isSpecialLLVMGlobalArrayToSkip(), isValidInsnFormat(), llvm::object::Lexer::lex(), llvm::remarks::magicToFormat(), llvm::object::COFFObjectFile::mapDebugSectionName(), llvm::object::MachOObjectFile::mapDebugSectionName(), llvm::object::XCOFFObjectFile::mapDebugSectionName(), llvm::object::MachOObjectFile::mapReflectionSectionNameToEnumValue(), matchMatrixRegName(), matchMatrixTileListRegName(), MatchNeonVectorRegName(), matchSVEDataVectorRegName(), matchSVEPredicateAsCounterRegName(), matchSVEPredicateVectorRegName(), MaybePredicatedInst(), MCAttrForString(), llvm::PPC::normalizeCPUName(), llvm::HexagonMCInstrInfo::packetSize(), parseAMDGPUAtomicOptimizerStrategy(), parseArch(), llvm::ARM::parseArchISA(), llvm::WebAssembly::parseBlockType(), parseConstraintCode(), llvm::parseDenormalFPAttributeComponent(), parseEnvironment(), llvm::MachO::TextAPIWriter::parseFileType(), parseFormat(), llvm::remarks::parseFormat(), llvm::WebAssembly::parseMVT(), parseNamePrefix(), parseOptLevel(), parseOS(), llvm::dxbc::parsePartType(), parsePredicateConstraint(), parseReducedGprConstraint(), parseSubArch(), parseThunkName(), llvm::remarks::YAMLRemarkParser::parseType(), llvm::SparcMCExpr::parseVariantKind(), llvm::VEMCExpr::parseVariantKind(), parseVendor(), llvm::SymbolRemappingReader::read(), shouldUpgradeNVPTXBF16Intrinsic(), SizeForSuffix(), llvm::LPAC::stringToLanaiAluCode(), llvm::RISCVFPRndMode::stringToRoundingMode(), llvm::stringToVEFCondCode(), llvm::stringToVEICondCode(), llvm::stringToVERD(), llvm::LPCC::suffixToLanaiCondCode(), llvm::Triple::Triple(), upgradeArmOrAarch64IntrinsicFunction(), llvm::UpgradeIntrinsicCall(), upgradeIntrinsicFunction1(), and upgradeX86IntrinsicFunction().

◆ EndsWith()

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::EndsWith ( StringLiteral  S,
T  Value 
)
inline

◆ EndsWithLower()

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::EndsWithLower ( StringLiteral  S,
T  Value 
)
inline

Definition at line 149 of file StringSwitch.h.

◆ operator R()

template<typename T , typename R = T>
llvm::StringSwitch< T, R >::operator R ( )
inline

Definition at line 188 of file StringSwitch.h.

References assert().

◆ operator=() [1/2]

template<typename T , typename R = T>
void llvm::StringSwitch< T, R >::operator= ( const StringSwitch< T, R > &  )
delete

◆ operator=() [2/2]

template<typename T , typename R = T>
void llvm::StringSwitch< T, R >::operator= ( StringSwitch< T, R > &&  other)
delete

◆ StartsWith()

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::StartsWith ( StringLiteral  S,
T  Value 
)
inline

◆ StartsWithLower()

template<typename T , typename R = T>
StringSwitch & llvm::StringSwitch< T, R >::StartsWithLower ( StringLiteral  S,
T  Value 
)
inline

Definition at line 156 of file StringSwitch.h.


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