[cfe-commits] r47412 - in /cfe/trunk: Parse/AttributeList.cpp include/clang/Parse/AttributeList.h

Chris Lattner sabre at nondot.org
Wed Feb 20 15:14:48 PST 2008


Author: lattner
Date: Wed Feb 20 17:14:47 2008
New Revision: 47412

URL: http://llvm.org/viewvc/llvm-project?rev=47412&view=rev
Log:
add a method to AttributeList that converts an identifier to an enum.

Modified:
    cfe/trunk/Parse/AttributeList.cpp
    cfe/trunk/include/clang/Parse/AttributeList.h

Modified: cfe/trunk/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/AttributeList.cpp?rev=47412&r1=47411&r2=47412&view=diff

==============================================================================
--- cfe/trunk/Parse/AttributeList.cpp (original)
+++ cfe/trunk/Parse/AttributeList.cpp Wed Feb 20 17:14:47 2008
@@ -24,3 +24,48 @@
   for (unsigned i = 0; i != numargs; ++i)
     Args[i] = elist[i];
 }
+
+AttributeList::~AttributeList() {
+  if (Args) {
+    // FIXME: before we delete the vector, we need to make sure the Expr's 
+    // have been deleted. Since Action::ExprTy is "void", we are dependent
+    // on the actions module for actually freeing the memory. The specific
+    // hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType, 
+    // ParseField, ParseTag. Once these routines have freed the expression, 
+    // they should zero out the Args slot (to indicate the memory has been 
+    // freed). If any element of the vector is non-null, we should assert.
+    delete [] Args;
+  }
+  delete Next;
+}
+
+AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
+  const char *Str = Name->getName();
+  unsigned Len = Name->getLength();
+
+  // Normalize the attribute name, __foo__ becomes foo.
+  if (Len > 4 && Str[0] == '_' && Str[1] == '_' &&
+      Str[Len - 2] == '_' && Str[Len - 1] == '_') {
+    Str += 2;
+    Len -= 4;
+  }
+  
+  switch (Len) {
+  case 6: 
+    if (!memcmp(Str, "packed", 6)) return AT_packed;
+    break;
+  case 7:
+    if (!memcmp(Str, "aligned", 7)) return AT_aligned;
+    break;
+  case 11:   
+    if (!memcmp(Str, "vector_size", 11)) return AT_vector_size;
+    break;
+  case 13:
+    if (!memcmp(Str, "address_space", 13)) return AT_address_space;
+    break;
+  case 15:
+    if (!memcmp(Str, "ocu_vector_type", 15)) return AT_ocu_vector_type;
+    break;
+  }      
+  return UnknownAttribute;
+}

Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=47412&r1=47411&r2=47412&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Wed Feb 20 17:14:47 2008
@@ -18,7 +18,7 @@
 #include <cassert>
 
 namespace clang {
-
+  
 /// AttributeList - Represents GCC's __attribute__ declaration. There are
 /// 4 forms of this construct...they are:
 ///
@@ -39,24 +39,24 @@
   AttributeList(IdentifierInfo *AttrName, SourceLocation AttrLoc,
                 IdentifierInfo *ParmName, SourceLocation ParmLoc,
                 Action::ExprTy **args, unsigned numargs, AttributeList *Next);
-  ~AttributeList() {
-    if (Args) {
-      // FIXME: before we delete the vector, we need to make sure the Expr's 
-      // have been deleted. Since Action::ExprTy is "void", we are dependent
-      // on the actions module for actually freeing the memory. The specific
-      // hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType, 
-      // ParseField, ParseTag. Once these routines have freed the expression, 
-      // they should zero out the Args slot (to indicate the memory has been 
-      // freed). If any element of the vector is non-null, we should assert.
-      delete [] Args;
-    }
-    delete Next;
-  }
+  ~AttributeList();
+  
+  enum Kind {
+    UnknownAttribute,
+    AT_vector_size,
+    AT_ocu_vector_type,
+    AT_address_space,
+    AT_aligned,
+    AT_packed
+  };
   
   IdentifierInfo *getAttributeName() const { return AttrName; }
   SourceLocation getAttributeLoc() const { return AttrLoc; }
   IdentifierInfo *getParameterName() const { return ParmName; }
   
+  Kind getKind() const { return getKind(getAttributeName()); }
+  static Kind getKind(const IdentifierInfo *Name);
+  
   AttributeList *getNext() const { return Next; }
   void setNext(AttributeList *N) { Next = N; }
   





More information about the cfe-commits mailing list