diff options
author | Chris Lattner <sabre@nondot.org> | 2007-08-02 23:36:59 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-08-02 23:36:59 +0000 |
commit | b8f849da3cedee2f61ad98389115ddd04e439d60 (patch) | |
tree | 338d3a02ffab86e7dd2bf826e257c0a6719069b6 | |
parent | f13ebf03b744386649c869014a6b4cf657144ebd (diff) |
Add support for encoding a OCUVectorComponent into a single integer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40768 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | AST/Expr.cpp | 17 | ||||
-rw-r--r-- | include/clang/AST/Expr.h | 12 | ||||
-rw-r--r-- | include/clang/AST/Type.h | 13 |
3 files changed, 37 insertions, 5 deletions
diff --git a/AST/Expr.cpp b/AST/Expr.cpp index 2df7612487..9b5fc78d74 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -611,3 +611,20 @@ bool OCUVectorComponent::containsDuplicateComponents() const { } return false; } + +/// getEncodedElementAccess - We encode fields with two bits per component. +unsigned OCUVectorComponent::getEncodedElementAccess() const { + const char *compStr = Accessor.getName(); + unsigned length = strlen(compStr); + + unsigned Result = 0; + + while (length--) { + Result <<= 2; + int Idx = OCUVectorType::getAccessorIdx(compStr[length]); + assert(Idx != -1 && "Invalid accessor letter"); + Result |= Idx; + } + return Result; +} + diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 1b5dbe7476..c2f147b2de 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -494,6 +494,18 @@ public: /// repeated. bool containsDuplicateComponents() const; + /// getEncodedElementAccess - Encode the elements accessed into a bit vector. + /// The encoding currently uses 2-bit bitfields, but clients should use the + /// accessors below to access them. + /// + unsigned getEncodedElementAccess() const; + + /// getAccessedFieldNo - Given an encoded value and a result number, return + /// the input field number being accessed. + static unsigned getAccessedFieldNo(unsigned Idx, unsigned EncodedVal) { + return (EncodedVal >> (Idx*2)) & 3; + } + virtual SourceRange getSourceRange() const { return SourceRange(getBase()->getLocStart(), AccessorLoc); } diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 9c169d553b..008b914960 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -544,12 +544,15 @@ public: case 'q': return 3; } }; + + static int getAccessorIdx(char c) { + if (int idx = getPointAccessorIdx(c)+1) return idx-1; + if (int idx = getColorAccessorIdx(c)+1) return idx-1; + return getTextureAccessorIdx(c); + } + 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) + if (int idx = getAccessorIdx(c)+1) return unsigned(idx-1) < NumElements; return false; } |