13#ifndef LLVM_ADT_STRINGSWITCH_H
14#define LLVM_ADT_STRINGSWITCH_H
20#include <initializer_list>
44template<
typename T,
typename R = T>
51 std::optional<T> Result;
55 : Str(S), Result() { }
73 if (!Result && Str.ends_with(S)) {
74 Result = std::move(
Value);
80 if (!Result && Str.starts_with(S)) {
81 Result = std::move(
Value);
88 return CasesImpl(
Value, CaseStrings);
92 return CasesImpl(
Value, {S0,
S1});
97 return CasesImpl(
Value, {S0,
S1, S2});
102 return CasesImpl(
Value, {S0,
S1, S2, S3});
107 return CasesImpl(
Value, {S0,
S1, S2, S3, S4});
113 return CasesImpl(
Value, {S0,
S1, S2, S3, S4, S5});
119 return CasesImpl(
Value, {S0,
S1, S2, S3, S4, S5, S6});
125 return CasesImpl(
Value, {S0,
S1, S2, S3, S4, S5, S6, S7});
132 return CasesImpl(
Value, {S0,
S1, S2, S3, S4, S5, S6, S7,
S8});
139 return CasesImpl(
Value, {S0,
S1, S2, S3, S4, S5, S6, S7,
S8, S9});
144 CaseLowerImpl(
Value, S);
149 if (!Result && Str.ends_with_insensitive(S))
156 if (!Result && Str.starts_with_insensitive(S))
157 Result = std::move(
Value);
164 return CasesLowerImpl(
Value, CaseStrings);
168 return CasesLowerImpl(
Value, {S0,
S1});
173 return CasesLowerImpl(
Value, {S0,
S1, S2});
178 return CasesLowerImpl(
Value, {S0,
S1, S2, S3});
183 return CasesLowerImpl(
Value, {S0,
S1, S2, S3, S4});
188 return std::move(*Result);
194 const char *Message =
"Fell off the end of a string-switch") {
196 return std::move(*Result);
205 if (!Result && Str == S) {
206 Result = std::move(
Value);
214 bool CaseLowerImpl(
T &
Value, StringLiteral S) {
215 if (!Result && Str.equals_insensitive(S)) {
216 Result = std::move(
Value);
223 std::initializer_list<StringLiteral>
Cases) {
225 for (StringLiteral S :
Cases)
226 if (CaseImpl(
Value, S))
232 std::initializer_list<StringLiteral>
Cases) {
234 for (StringLiteral S :
Cases)
235 if (CaseLowerImpl(
Value, S))
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