[cfe-commits] r40768 - in /cfe/trunk: AST/Expr.cpp include/clang/AST/Expr.h include/clang/AST/Type.h

Chris Lattner sabre at nondot.org
Thu Aug 2 16:36:59 PDT 2007


Author: lattner
Date: Thu Aug  2 18:36:59 2007
New Revision: 40768

URL: http://llvm.org/viewvc/llvm-project?rev=40768&view=rev
Log:
Add support for encoding a OCUVectorComponent into a single integer.

Modified:
    cfe/trunk/AST/Expr.cpp
    cfe/trunk/include/clang/AST/Expr.h
    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=40768&r1=40767&r2=40768&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Thu Aug  2 18:36:59 2007
@@ -611,3 +611,20 @@
   }
   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;
+}
+

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=40768&r1=40767&r2=40768&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu Aug  2 18:36:59 2007
@@ -494,6 +494,18 @@
   /// 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);
   }

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=40768&r1=40767&r2=40768&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Thu Aug  2 18:36:59 2007
@@ -544,12 +544,15 @@
     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;
   }





More information about the cfe-commits mailing list