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);
93 return CasesImpl({S0,
S1},
Value);
96 [[deprecated(
"Pass cases in std::initializer_list instead")]]
99 return CasesImpl({S0,
S1, S2},
Value);
102 [[deprecated(
"Pass cases in std::initializer_list instead")]]
105 return CasesImpl({S0,
S1, S2, S3},
Value);
108 [[deprecated(
"Pass cases in std::initializer_list instead")]]
111 return CasesImpl({S0,
S1, S2, S3, S4},
Value);
114 [[deprecated(
"Pass cases in std::initializer_list instead")]]
118 return CasesImpl({S0,
S1, S2, S3, S4, S5},
Value);
121 [[deprecated(
"Pass cases in std::initializer_list instead")]]
125 return CasesImpl({S0,
S1, S2, S3, S4, S5, S6},
Value);
128 [[deprecated(
"Pass cases in std::initializer_list instead")]]
132 return CasesImpl({S0,
S1, S2, S3, S4, S5, S6, S7},
Value);
135 [[deprecated(
"Pass cases in std::initializer_list instead")]]
140 return CasesImpl({S0,
S1, S2, S3, S4, S5, S6, S7,
S8},
Value);
143 [[deprecated(
"Pass cases in std::initializer_list instead")]]
148 return CasesImpl({S0,
S1, S2, S3, S4, S5, S6, S7,
S8, S9},
Value);
153 CaseLowerImpl(S,
Value);
158 if (!Result && Str.ends_with_insensitive(S))
165 if (!Result && Str.starts_with_insensitive(S))
166 Result = std::move(
Value);
173 return CasesLowerImpl(CaseStrings,
Value);
176 [[deprecated(
"Pass cases in std::initializer_list instead")]]
178 return CasesLowerImpl({S0,
S1},
Value);
181 [[deprecated(
"Pass cases in std::initializer_list instead")]]
184 return CasesLowerImpl({S0,
S1, S2},
Value);
187 [[deprecated(
"Pass cases in std::initializer_list instead")]]
190 return CasesLowerImpl({S0,
S1, S2, S3},
Value);
193 [[deprecated(
"Pass cases in std::initializer_list instead")]]
196 return CasesLowerImpl({S0,
S1, S2, S3, S4},
Value);
201 return std::move(*Result);
207 const char *Message =
"Fell off the end of a string-switch") {
209 return std::move(*Result);
218 if (!Result && Str == S) {
219 Result = std::move(
Value);
227 bool CaseLowerImpl(StringLiteral S,
T &
Value) {
228 if (!Result && Str.equals_insensitive(S)) {
229 Result = std::move(
Value);
238 for (StringLiteral S :
Cases)
239 if (CaseImpl(S,
Value))
247 for (StringLiteral S :
Cases)
248 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