]> granicus.if.org Git - clang/commitdiff
Add support for encoding a OCUVectorComponent into a single integer.
authorChris Lattner <sabre@nondot.org>
Thu, 2 Aug 2007 23:36:59 +0000 (23:36 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 2 Aug 2007 23:36:59 +0000 (23:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40768 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 2df7612487ab759ca3b13b8e3b7ed256edbcf526..9b5fc78d741a728211686e4358bc25272c5c1d01 100644 (file)
@@ -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;
+}
+
index 1b5dbe74763037d96b7e06f5b76d40545a2d14af..c2f147b2def12be15234bb43e922b53b5438aeae 100644 (file)
@@ -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);
   }
index 9c169d553bbeb057689444883cb35506ace6ba80..008b914960272c4b3ef2e88837d3d7eb46935740 100644 (file)
@@ -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;
   }