]> granicus.if.org Git - clang/commitdiff
rename some helpers, have them return the idx of the field being accessed.
authorChris Lattner <sabre@nondot.org>
Thu, 2 Aug 2007 22:33:49 +0000 (22:33 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 2 Aug 2007 22:33:49 +0000 (22:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40764 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
Sema/SemaExpr.cpp
include/clang/AST/Type.h

index cba95ca38df69a0c4d12b451c5c61b01df07e9d6..2df7612487ab759ca3b13b8e3b7ed256edbcf526 100644 (file)
@@ -589,10 +589,10 @@ OCUVectorComponent::ComponentType OCUVectorComponent::getComponentType() const {
   // derive the component type, no need to waste space.
   const char *compStr = Accessor.getName();
   
-  if (OCUVectorType::isPointAccessor(*compStr)) return Point;
-  if (OCUVectorType::isColorAccessor(*compStr)) return Color;
+  if (OCUVectorType::getPointAccessorIdx(*compStr) != -1) return Point;
+  if (OCUVectorType::getColorAccessorIdx(*compStr) != -1) return Color;
   
-  assert(OCUVectorType::isTextureAccessor(*compStr) &&
+  assert(OCUVectorType::getTextureAccessorIdx(*compStr) != -1 &&
          "getComponentType(): Illegal accessor");
   return Texture;
 }
index b0b1794da587f1db86b499e9094bebf8a3e78b82..1d69d7e139e009df8721d644b165b2f123f41d8f 100644 (file)
@@ -352,12 +352,19 @@ CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc,
     return QualType();
   }
   // The component names must come from the same set.
-  if (vecType->isPointAccessor(*compStr))
-   do { compStr++; } while (*compStr && vecType->isPointAccessor(*compStr));
-  else if (vecType->isColorAccessor(*compStr))
-   do { compStr++; } while (*compStr && vecType->isColorAccessor(*compStr));
-  else if (vecType->isTextureAccessor(*compStr))
-   do { compStr++; } while (*compStr && vecType->isTextureAccessor(*compStr));
+  if (vecType->getPointAccessorIdx(*compStr) != -1) {
+    do
+      compStr++;
+    while (*compStr && vecType->getPointAccessorIdx(*compStr) != -1);
+  } else if (vecType->getColorAccessorIdx(*compStr) != -1) {
+    do
+      compStr++;
+    while (*compStr && vecType->getColorAccessorIdx(*compStr) != -1);
+  } else if (vecType->getTextureAccessorIdx(*compStr) != -1) {
+    do 
+      compStr++;
+    while (*compStr && vecType->getTextureAccessorIdx(*compStr) != -1);
+  }
     
   if (*compStr) { 
     // We didn't get to the end of the string. This means the component names
index 29830c90a5df4f517d88d1e2aa91debe37115df6..9c169d553bbeb057689444883cb35506ace6ba80 100644 (file)
@@ -517,27 +517,41 @@ class OCUVectorType : public VectorType {
     VectorType(OCUVector, vecType, nElements, canonType) {} 
   friend class ASTContext;  // ASTContext creates these.
 public:
-  static bool isPointAccessor(const char c) {
-    return c == 'x' || c == 'y' || c == 'z' || c == 'w';
+  static int getPointAccessorIdx(char c) {
+    switch (c) {
+    default: return -1;
+    case 'x': return 0;
+    case 'y': return 1;
+    case 'z': return 2;
+    case 'w': return 3;
+    }
   }
-  static bool isColorAccessor(const char c) {
-    return c == 'r' || c == 'g' || c == 'b' || c == 'a';
+  static int getColorAccessorIdx(char c) {
+    switch (c) {
+    default: return -1;
+    case 'r': return 0;
+    case 'g': return 1;
+    case 'b': return 2;
+    case 'a': return 3;
+    }
   }
-  static bool isTextureAccessor(const char c) {
-    return c == 's' || c == 't' || c == 'p' || c == 'q';
-  };
-  bool isAccessorWithinNumElements(const char c) const {
-    switch (NumElements) {
-      default: assert(0 && "Illegal number of elements");
-      case 2: return c == 'x' || c == 'y' || 
-                     c == 'r' || c == 'g' ||
-                     c == 's' || c == 't';
-      case 3: return c == 'x' || c == 'y' || c == 'z' ||
-                     c == 'r' || c == 'g' || c == 'b' ||
-                     c == 's' || c == 't' || c == 'p';
-      case 4: return isPointAccessor(c) || isColorAccessor(c) || 
-                     isTextureAccessor(c);
+  static int getTextureAccessorIdx(char c) {
+    switch (c) {
+    default: return -1;
+    case 's': return 0;
+    case 't': return 1;
+    case 'p': return 2;
+    case 'q': return 3;
     }
+  };
+  bool isAccessorWithinNumElements(char c) const {
+    if (int idx = getPointAccessorIdx(c)+1)
+      return unsigned(idx-1) < NumElements;
+    if (int idx = getColorAccessorIdx(c)+1)
+      return unsigned(idx-1) < NumElements;
+    if (int idx = getTextureAccessorIdx(c)+1)
+      return unsigned(idx-1) < NumElements;
+    return false;
   }
   virtual void getAsStringInternal(std::string &InnerString) const;