OSDN Git Service

Add StringSwitch::Cases functions that takes 6 to 10 arguments.
authorRui Ueyama <ruiu@google.com>
Fri, 23 Sep 2016 22:10:06 +0000 (22:10 +0000)
committerRui Ueyama <ruiu@google.com>
Fri, 23 Sep 2016 22:10:06 +0000 (22:10 +0000)
Differential Revision: https://reviews.llvm.org/D24882

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282305 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/StringSwitch.h

index bd200fc..044cccd 100644 (file)
@@ -75,7 +75,6 @@ public:
         (std::memcmp(S, Str.data(), N-1) == 0)) {
       Result = &Value;
     }
-
     return *this;
   }
 
@@ -86,7 +85,6 @@ public:
         std::memcmp(S, Str.data() + Str.size() + 1 - N, N-1) == 0) {
       Result = &Value;
     }
-
     return *this;
   }
 
@@ -97,75 +95,97 @@ public:
         std::memcmp(S, Str.data(), N-1) == 0) {
       Result = &Value;
     }
-
     return *this;
   }
 
   template<unsigned N0, unsigned N1>
   LLVM_ATTRIBUTE_ALWAYS_INLINE
-  StringSwitchCases(const char (&S0)[N0], const char (&S1)[N1],
+  StringSwitch &Cases(const char (&S0)[N0], const char (&S1)[N1],
                       const T& Value) {
-    if (!Result && (
-        (N0-1 == Str.size() && std::memcmp(S0, Str.data(), N0-1) == 0) ||
-        (N1-1 == Str.size() && std::memcmp(S1, Str.data(), N1-1) == 0))) {
-      Result = &Value;
-    }
-
-    return *this;
+    return Case(S0, Value).Case(S1, Value);
   }
 
   template<unsigned N0, unsigned N1, unsigned N2>
   LLVM_ATTRIBUTE_ALWAYS_INLINE
-  StringSwitchCases(const char (&S0)[N0], const char (&S1)[N1],
+  StringSwitch &Cases(const char (&S0)[N0], const char (&S1)[N1],
                       const char (&S2)[N2], const T& Value) {
-    if (!Result && (
-        (N0-1 == Str.size() && std::memcmp(S0, Str.data(), N0-1) == 0) ||
-        (N1-1 == Str.size() && std::memcmp(S1, Str.data(), N1-1) == 0) ||
-        (N2-1 == Str.size() && std::memcmp(S2, Str.data(), N2-1) == 0))) {
-      Result = &Value;
-    }
-
-    return *this;
+    return Case(S0, Value).Cases(S1, S2, Value);
   }
 
   template<unsigned N0, unsigned N1, unsigned N2, unsigned N3>
   LLVM_ATTRIBUTE_ALWAYS_INLINE
-  StringSwitchCases(const char (&S0)[N0], const char (&S1)[N1],
+  StringSwitch &Cases(const char (&S0)[N0], const char (&S1)[N1],
                       const char (&S2)[N2], const char (&S3)[N3],
                       const T& Value) {
-    if (!Result && (
-        (N0-1 == Str.size() && std::memcmp(S0, Str.data(), N0-1) == 0) ||
-        (N1-1 == Str.size() && std::memcmp(S1, Str.data(), N1-1) == 0) ||
-        (N2-1 == Str.size() && std::memcmp(S2, Str.data(), N2-1) == 0) ||
-        (N3-1 == Str.size() && std::memcmp(S3, Str.data(), N3-1) == 0))) {
-      Result = &Value;
-    }
-
-    return *this;
+    return Case(S0, Value).Cases(S1, S2, S3, Value);
   }
 
   template<unsigned N0, unsigned N1, unsigned N2, unsigned N3, unsigned N4>
   LLVM_ATTRIBUTE_ALWAYS_INLINE
-  StringSwitchCases(const char (&S0)[N0], const char (&S1)[N1],
+  StringSwitch &Cases(const char (&S0)[N0], const char (&S1)[N1],
                       const char (&S2)[N2], const char (&S3)[N3],
                       const char (&S4)[N4], const T& Value) {
-    if (!Result && (
-        (N0-1 == Str.size() && std::memcmp(S0, Str.data(), N0-1) == 0) ||
-        (N1-1 == Str.size() && std::memcmp(S1, Str.data(), N1-1) == 0) ||
-        (N2-1 == Str.size() && std::memcmp(S2, Str.data(), N2-1) == 0) ||
-        (N3-1 == Str.size() && std::memcmp(S3, Str.data(), N3-1) == 0) ||
-        (N4-1 == Str.size() && std::memcmp(S4, Str.data(), N4-1) == 0))) {
-      Result = &Value;
-    }
+    return Case(S0, Value).Cases(S1, S2, S3, S4, Value);
+  }
 
-    return *this;
+  template <unsigned N0, unsigned N1, unsigned N2, unsigned N3, unsigned N4,
+            unsigned N5>
+  LLVM_ATTRIBUTE_ALWAYS_INLINE
+  StringSwitch &Cases(const char (&S0)[N0], const char (&S1)[N1],
+                      const char (&S2)[N2], const char (&S3)[N3],
+                      const char (&S4)[N4], const char (&S5)[N5],
+                      const T &Value) {
+    return Case(S0, Value).Cases(S1, S2, S3, S4, S5, Value);
+  }
+
+  template <unsigned N0, unsigned N1, unsigned N2, unsigned N3, unsigned N4,
+            unsigned N5, unsigned N6>
+  LLVM_ATTRIBUTE_ALWAYS_INLINE
+  StringSwitch &Cases(const char (&S0)[N0], const char (&S1)[N1],
+                      const char (&S2)[N2], const char (&S3)[N3],
+                      const char (&S4)[N4], const char (&S5)[N5],
+                      const char (&S6)[N6], const T &Value) {
+    return Case(S0, Value).Cases(S1, S2, S3, S4, S5, S6, Value);
+  }
+
+  template <unsigned N0, unsigned N1, unsigned N2, unsigned N3, unsigned N4,
+            unsigned N5, unsigned N6, unsigned N7>
+  LLVM_ATTRIBUTE_ALWAYS_INLINE
+  StringSwitch &Cases(const char (&S0)[N0], const char (&S1)[N1],
+                      const char (&S2)[N2], const char (&S3)[N3],
+                      const char (&S4)[N4], const char (&S5)[N5],
+                      const char (&S6)[N6], const char (&S7)[N7],
+                      const T &Value) {
+    return Case(S0, Value).Cases(S1, S2, S3, S4, S5, S6, S7, Value);
+  }
+
+  template <unsigned N0, unsigned N1, unsigned N2, unsigned N3, unsigned N4,
+            unsigned N5, unsigned N6, unsigned N7, unsigned N8>
+  LLVM_ATTRIBUTE_ALWAYS_INLINE
+  StringSwitch &Cases(const char (&S0)[N0], const char (&S1)[N1],
+                      const char (&S2)[N2], const char (&S3)[N3],
+                      const char (&S4)[N4], const char (&S5)[N5],
+                      const char (&S6)[N6], const char (&S7)[N7],
+                      const char (&S8)[N8], const T &Value) {
+    return Case(S0, Value).Cases(S1, S2, S3, S4, S5, S6, S7, S8, Value);
+  }
+
+  template <unsigned N0, unsigned N1, unsigned N2, unsigned N3, unsigned N4,
+            unsigned N5, unsigned N6, unsigned N7, unsigned N8, unsigned N9>
+  LLVM_ATTRIBUTE_ALWAYS_INLINE
+  StringSwitch &Cases(const char (&S0)[N0], const char (&S1)[N1],
+                      const char (&S2)[N2], const char (&S3)[N3],
+                      const char (&S4)[N4], const char (&S5)[N5],
+                      const char (&S6)[N6], const char (&S7)[N7],
+                      const char (&S8)[N8], const char (&S9)[N9],
+                      const T &Value) {
+    return Case(S0, Value).Cases(S1, S2, S3, S4, S5, S6, S7, S8, S9, Value);
   }
 
   LLVM_ATTRIBUTE_ALWAYS_INLINE
   R Default(const T& Value) const {
     if (Result)
       return *Result;
-
     return Value;
   }