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

Chris Lattner sabre at nondot.org
Wed Feb 20 14:04:11 PST 2008


Author: lattner
Date: Wed Feb 20 16:04:11 2008
New Revision: 47405

URL: http://llvm.org/viewvc/llvm-project?rev=47405&view=rev
Log:
add some code that will be used to remove processed attrs from
declspec, it is currently nonfunctional though.

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

Modified: cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaType.cpp?rev=47405&r1=47404&r2=47405&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/trunk/Sema/SemaType.cpp Wed Feb 20 16:04:11 2008
@@ -21,7 +21,7 @@
 
 /// ConvertDeclSpecToType - Convert the specified declspec to the appropriate
 /// type object.  This returns null on error.
-static QualType ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) {
+static QualType ConvertDeclSpecToType(DeclSpec &DS, ASTContext &Ctx) {
   // FIXME: Should move the logic from DeclSpec::Finish to here for validity
   // checking.
   QualType Result;
@@ -140,6 +140,35 @@
   assert(DS.getTypeSpecComplex() != DeclSpec::TSC_imaginary &&
          "FIXME: imaginary types not supported yet!");
   
+  // See if there are any attributes on the declspec that apply to the type (as
+  // opposed to the decl).
+  if (!DS.getAttributes())
+    return Result;
+  
+  // Scan through and apply attributes to this type where it makes sense.  Some
+  // attributes (such as __address_space__, __vector_size__, etc) apply to the
+  // declspec, but others can be present in the decl spec even though they apply
+  // to the decl.  Here we apply and delete attributes that apply to the
+  // declspec and leave the others alone.
+  llvm::SmallVector<AttributeList *, 8> LeftOverAttrs;
+  AttributeList *AL = DS.getAttributes();
+  while (AL) {
+    AttributeList *ThisAttr = AL;
+    AL = AL->getNext();
+    
+    LeftOverAttrs.push_back(ThisAttr);
+  }
+  
+  // Rechain any attributes that haven't been deleted to the DeclSpec.
+  AttributeList *List = 0;
+  for (unsigned i = 0, e = LeftOverAttrs.size(); i != e; ++i) {
+    LeftOverAttrs[i]->setNext(List);
+    List = LeftOverAttrs[i];
+  }
+  
+  DS.clearAttributes();
+  DS.AddAttributes(List);
+  //DS.setAttributes(List);
   return Result;
 }
 

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

==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Wed Feb 20 16:04:11 2008
@@ -50,8 +50,7 @@
       // freed). If any element of the vector is non-null, we should assert.
       delete [] Args;
     }
-    if (Next)
-      delete Next;
+    delete Next;
   }
   
   IdentifierInfo *getAttributeName() const { return AttrName; }





More information about the cfe-commits mailing list