From 38d8b98803ac354dba15578d65ea99a83dead046 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 20 Feb 2008 22:04:11 +0000 Subject: [PATCH] add some code that will be used to remove processed attrs from declspec, it is currently nonfunctional though. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47405 91177308-0d34-0410-b5e6-96231b3b80d8 --- Sema/SemaType.cpp | 31 ++++++++++++++++++++++++++++- include/clang/Parse/AttributeList.h | 3 +-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Sema/SemaType.cpp b/Sema/SemaType.cpp index 7e0a0f025b..e0d7eb5ee9 100644 --- a/Sema/SemaType.cpp +++ b/Sema/SemaType.cpp @@ -21,7 +21,7 @@ using namespace clang; /// 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 @@ static QualType ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) { 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 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; } diff --git a/include/clang/Parse/AttributeList.h b/include/clang/Parse/AttributeList.h index cc3f52ac5f..231a214f49 100644 --- a/include/clang/Parse/AttributeList.h +++ b/include/clang/Parse/AttributeList.h @@ -50,8 +50,7 @@ public: // 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; }