// 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;
}
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
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;