From: Chris Lattner Date: Thu, 2 Aug 2007 22:33:49 +0000 (+0000) Subject: rename some helpers, have them return the idx of the field being accessed. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88dca0464804b8b26ae605f89784c927e8493ddd;p=clang rename some helpers, have them return the idx of the field being accessed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40764 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/Expr.cpp b/AST/Expr.cpp index cba95ca38d..2df7612487 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -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; } diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index b0b1794da5..1d69d7e139 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -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 diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 29830c90a5..9c169d553b 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -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;