Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions llvm/include/llvm/ADT/StringSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class StringSwitch {

// Case-sensitive case matchers
StringSwitch &Case(StringLiteral S, T Value) {
CaseImpl(Value, S);
CaseImpl(S, Value);
return *this;
}

Expand All @@ -86,68 +86,68 @@ class StringSwitch {

StringSwitch &Cases(std::initializer_list<StringLiteral> CaseStrings,
T Value) {
return CasesImpl(Value, CaseStrings);
return CasesImpl(CaseStrings, Value);
}

StringSwitch &Cases(StringLiteral S0, StringLiteral S1, T Value) {
return CasesImpl(Value, {S0, S1});
return CasesImpl({S0, S1}, Value);
}

StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
T Value) {
return CasesImpl(Value, {S0, S1, S2});
return CasesImpl({S0, S1, S2}, Value);
}

StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
StringLiteral S3, T Value) {
return CasesImpl(Value, {S0, S1, S2, S3});
return CasesImpl({S0, S1, S2, S3}, Value);
}

StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
StringLiteral S3, StringLiteral S4, T Value) {
return CasesImpl(Value, {S0, S1, S2, S3, S4});
return CasesImpl({S0, S1, S2, S3, S4}, Value);
}

[[deprecated("Pass cases in std::initializer_list instead")]]
StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
StringLiteral S3, StringLiteral S4, StringLiteral S5,
T Value) {
return CasesImpl(Value, {S0, S1, S2, S3, S4, S5});
return CasesImpl({S0, S1, S2, S3, S4, S5}, Value);
}

[[deprecated("Pass cases in std::initializer_list instead")]]
StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
StringLiteral S3, StringLiteral S4, StringLiteral S5,
StringLiteral S6, T Value) {
return CasesImpl(Value, {S0, S1, S2, S3, S4, S5, S6});
return CasesImpl({S0, S1, S2, S3, S4, S5, S6}, Value);
}

[[deprecated("Pass cases in std::initializer_list instead")]]
StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
StringLiteral S3, StringLiteral S4, StringLiteral S5,
StringLiteral S6, StringLiteral S7, T Value) {
return CasesImpl(Value, {S0, S1, S2, S3, S4, S5, S6, S7});
return CasesImpl({S0, S1, S2, S3, S4, S5, S6, S7}, Value);
}

[[deprecated("Pass cases in std::initializer_list instead")]]
StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
StringLiteral S3, StringLiteral S4, StringLiteral S5,
StringLiteral S6, StringLiteral S7, StringLiteral S8,
T Value) {
return CasesImpl(Value, {S0, S1, S2, S3, S4, S5, S6, S7, S8});
return CasesImpl({S0, S1, S2, S3, S4, S5, S6, S7, S8}, Value);
}

[[deprecated("Pass cases in std::initializer_list instead")]]
StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
StringLiteral S3, StringLiteral S4, StringLiteral S5,
StringLiteral S6, StringLiteral S7, StringLiteral S8,
StringLiteral S9, T Value) {
return CasesImpl(Value, {S0, S1, S2, S3, S4, S5, S6, S7, S8, S9});
return CasesImpl({S0, S1, S2, S3, S4, S5, S6, S7, S8, S9}, Value);
}

// Case-insensitive case matchers.
StringSwitch &CaseLower(StringLiteral S, T Value) {
CaseLowerImpl(Value, S);
CaseLowerImpl(S, Value);
return *this;
}

Expand All @@ -167,26 +167,26 @@ class StringSwitch {

StringSwitch &CasesLower(std::initializer_list<StringLiteral> CaseStrings,
T Value) {
return CasesLowerImpl(Value, CaseStrings);
return CasesLowerImpl(CaseStrings, Value);
}

StringSwitch &CasesLower(StringLiteral S0, StringLiteral S1, T Value) {
return CasesLowerImpl(Value, {S0, S1});
return CasesLowerImpl({S0, S1}, Value);
}

StringSwitch &CasesLower(StringLiteral S0, StringLiteral S1, StringLiteral S2,
T Value) {
return CasesLowerImpl(Value, {S0, S1, S2});
return CasesLowerImpl({S0, S1, S2}, Value);
}

StringSwitch &CasesLower(StringLiteral S0, StringLiteral S1, StringLiteral S2,
StringLiteral S3, T Value) {
return CasesLowerImpl(Value, {S0, S1, S2, S3});
return CasesLowerImpl({S0, S1, S2, S3}, Value);
}

StringSwitch &CasesLower(StringLiteral S0, StringLiteral S1, StringLiteral S2,
StringLiteral S3, StringLiteral S4, T Value) {
return CasesLowerImpl(Value, {S0, S1, S2, S3, S4});
return CasesLowerImpl({S0, S1, S2, S3, S4}, Value);
}

[[nodiscard]] R Default(T Value) {
Expand All @@ -207,7 +207,7 @@ class StringSwitch {

private:
// Returns true when `Str` matches the `S` argument, and stores the result.
bool CaseImpl(T &Value, StringLiteral S) {
bool CaseImpl(StringLiteral S, T &Value) {
if (!Result && Str == S) {
Result = std::move(Value);
return true;
Expand All @@ -217,28 +217,28 @@ class StringSwitch {

// Returns true when `Str` matches the `S` argument (case-insensitive), and
// stores the result.
bool CaseLowerImpl(T &Value, StringLiteral S) {
bool CaseLowerImpl(StringLiteral S, T &Value) {
if (!Result && Str.equals_insensitive(S)) {
Result = std::move(Value);
return true;
}
return false;
}

StringSwitch &CasesImpl(T &Value,
std::initializer_list<StringLiteral> Cases) {
StringSwitch &CasesImpl(std::initializer_list<StringLiteral> Cases,
T &Value) {
// Stop matching after the string is found.
for (StringLiteral S : Cases)
if (CaseImpl(Value, S))
if (CaseImpl(S, Value))
break;
return *this;
}

StringSwitch &CasesLowerImpl(T &Value,
std::initializer_list<StringLiteral> Cases) {
StringSwitch &CasesLowerImpl(std::initializer_list<StringLiteral> Cases,
T &Value) {
// Stop matching after the string is found.
for (StringLiteral S : Cases)
if (CaseLowerImpl(Value, S))
if (CaseLowerImpl(S, Value))
break;
return *this;
}
Expand Down