[cfe-commits] r40764 - in /cfe/trunk: AST/Expr.cpp Sema/SemaExpr.cpp include/clang/AST/Type.h
Chris Lattner
sabre at nondot.org
Thu Aug 2 15:33:50 PDT 2007
Author: lattner
Date: Thu Aug 2 17:33:49 2007
New Revision: 40764
URL: http://llvm.org/viewvc/llvm-project?rev=40764&view=rev
Log:
rename some helpers, have them return the idx of the field being accessed.
Modified:
cfe/trunk/AST/Expr.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/Type.h
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=40764&r1=40763&r2=40764&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Thu Aug 2 17:33:49 2007
@@ -589,10 +589,10 @@
// 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;
}
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=40764&r1=40763&r2=40764&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Thu Aug 2 17:33:49 2007
@@ -352,12 +352,19 @@
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
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=40764&r1=40763&r2=40764&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Thu Aug 2 17:33:49 2007
@@ -517,27 +517,41 @@
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;
More information about the cfe-commits
mailing list