13#ifndef LLVM_ADT_STRINGSWITCH_H
14#define LLVM_ADT_STRINGSWITCH_H
21#include <initializer_list>
45template<
typename T,
typename R = T>
52 std::optional<T> Result;
56 : Str(S), Result() { }
74 if (!Result && Str.ends_with(S)) {
75 Result = std::move(
Value);
81 if (!Result && Str.starts_with(S)) {
82 Result = std::move(
Value);
89 return CasesImpl(CaseStrings,
Value);
92 [[deprecated(
"Pass cases in std::initializer_list instead")]]
94 return CasesImpl({S0,
S1},
Value);
97 [[deprecated(
"Pass cases in std::initializer_list instead")]]
100 return CasesImpl({S0,
S1, S2},
Value);
103 [[deprecated(
"Pass cases in std::initializer_list instead")]]
106 return CasesImpl({S0,
S1, S2, S3},
Value);
109 [[deprecated(
"Pass cases in std::initializer_list instead")]]
112 return CasesImpl({S0,
S1, S2, S3, S4},
Value);
115 [[deprecated(
"Pass cases in std::initializer_list instead")]]
119 return CasesImpl({S0,
S1, S2, S3, S4, S5},
Value);
122 [[deprecated(
"Pass cases in std::initializer_list instead")]]
126 return CasesImpl({S0,
S1, S2, S3, S4, S5, S6},
Value);
129 [[deprecated(
"Pass cases in std::initializer_list instead")]]
133 return CasesImpl({S0,
S1, S2, S3, S4, S5, S6, S7},
Value);
136 [[deprecated(
"Pass cases in std::initializer_list instead")]]
141 return CasesImpl({S0,
S1, S2, S3, S4, S5, S6, S7,
S8},
Value);
144 [[deprecated(
"Pass cases in std::initializer_list instead")]]
149 return CasesImpl({S0,
S1, S2, S3, S4, S5, S6, S7,
S8, S9},
Value);
154 CaseLowerImpl(S,
Value);
159 if (!Result && Str.ends_with_insensitive(S))
166 if (!Result && Str.starts_with_insensitive(S))
167 Result = std::move(
Value);
174 return CasesLowerImpl(CaseStrings,
Value);
177 [[deprecated(
"Pass cases in std::initializer_list instead")]]
179 return CasesLowerImpl({S0,
S1},
Value);
182 [[deprecated(
"Pass cases in std::initializer_list instead")]]
185 return CasesLowerImpl({S0,
S1, S2},
Value);
188 [[deprecated(
"Pass cases in std::initializer_list instead")]]
191 return CasesLowerImpl({S0,
S1, S2, S3},
Value);
194 [[deprecated(
"Pass cases in std::initializer_list instead")]]
197 return CasesLowerImpl({S0,
S1, S2, S3, S4},
Value);
202 return std::move(*Result);
208 const char *Message =
"Fell off the end of a string-switch") {
210 return std::move(*Result);
219 if (!Result && Str == S) {
220 Result = std::move(
Value);
228 bool CaseLowerImpl(StringLiteral S,
T &
Value) {
229 if (!Result && Str.equals_insensitive(S)) {
230 Result = std::move(
Value);
239 for (StringLiteral S :
Cases)
240 if (CaseImpl(S,
Value))
248 for (StringLiteral S :
Cases)
249 if (CaseLowerImpl(S,
Value))
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringRef - Represent a constant reference to a string, i.e.
StringSwitch & CasesLower(StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, T Value)
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, StringLiteral S5, T Value)
StringSwitch & EndsWithLower(StringLiteral S, T Value)
StringSwitch & StartsWithLower(StringLiteral S, T Value)
StringSwitch & CaseLower(StringLiteral S, T Value)
StringSwitch & Case(StringLiteral S, T Value)
StringSwitch & CasesLower(StringLiteral S0, StringLiteral S1, T Value)
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, T Value)
void operator=(StringSwitch &&)=delete
void operator=(const StringSwitch &)=delete
StringSwitch & CasesLower(StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, T Value)
R DefaultUnreachable(const char *Message="Fell off the end of a string-switch")
Declare default as unreachable, making sure that all cases were handled.
StringSwitch & CasesLower(std::initializer_list< StringLiteral > CaseStrings, T Value)
StringSwitch & StartsWith(StringLiteral S, T Value)
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, StringLiteral S5, StringLiteral S6, StringLiteral S7, StringLiteral S8, T Value)
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, T Value)
StringSwitch(const StringSwitch &)=delete
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, T Value)
StringSwitch & EndsWith(StringLiteral S, T Value)
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, StringLiteral S5, StringLiteral S6, StringLiteral S7, T Value)
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, StringLiteral S5, StringLiteral S6, T Value)
StringSwitch(StringSwitch &&)=default
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2, T Value)
StringSwitch & Cases(std::initializer_list< StringLiteral > CaseStrings, T Value)
StringSwitch(StringRef S)
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2, StringLiteral S3, StringLiteral S4, StringLiteral S5, StringLiteral S6, StringLiteral S7, StringLiteral S8, StringLiteral S9, T Value)
StringSwitch & CasesLower(StringLiteral S0, StringLiteral S1, StringLiteral S2, T Value)
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value