diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-09-01 17:10:19 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-09-01 17:10:19 +0000 |
commit | ac25503714ba1a384d4f1cae05b84bc785eb5fad (patch) | |
tree | 7b9fa676ea1227d97ccb21dcc88f26f8232d9daa | |
parent | d2e1eb064cfb8d361ea1dd4f6253a4e20f24d88d (diff) |
"The attached patch moves AttributeList::addAttributeList outside the
class so as to accomodate one or both parameters being NULL, " from Sean Hunt!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80683 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Parse/AttributeList.h | 28 | ||||
-rw-r--r-- | include/clang/Parse/DeclSpec.h | 14 |
2 files changed, 20 insertions, 22 deletions
diff --git a/include/clang/Parse/AttributeList.h b/include/clang/Parse/AttributeList.h index e699d170cf..6f987eefd0 100644 --- a/include/clang/Parse/AttributeList.h +++ b/include/clang/Parse/AttributeList.h @@ -113,16 +113,6 @@ public: AttributeList *getNext() const { return Next; } void setNext(AttributeList *N) { Next = N; } - - void addAttributeList(AttributeList *alist) { - assert((alist != 0) && "addAttributeList(): alist is null"); - AttributeList *next = this, *prev; - do { - prev = next; - next = next->getNext(); - } while (next); - prev->setNext(alist); - } /// getNumArgs - Return the number of actual arguments to this attribute. unsigned getNumArgs() const { return NumArgs; } @@ -172,6 +162,24 @@ public: } }; +/// addAttributeLists - Add two AttributeLists together +/// The right-hand list is appended to the left-hand list, if any +/// A pointer to the joined list is returned. +/// Note: the lists are not left unmodified. +inline AttributeList* addAttributeLists (AttributeList *Left, + AttributeList *Right) { + if (!Left) + return Right; + + AttributeList *next = Left, *prev; + do { + prev = next; + next = next->getNext(); + } while (next); + prev->setNext(Right); + return Left; +} + } // end namespace clang #endif diff --git a/include/clang/Parse/DeclSpec.h b/include/clang/Parse/DeclSpec.h index 9d8a6f0798..3bedec4e4d 100644 --- a/include/clang/Parse/DeclSpec.h +++ b/include/clang/Parse/DeclSpec.h @@ -321,12 +321,7 @@ public: /// int __attribute__((may_alias)) __attribute__((aligned(16))) var; /// void AddAttributes(AttributeList *alist) { - if (!alist) - return; // we parsed __attribute__(()) or had a syntax error - - if (AttrList) - alist->addAttributeList(AttrList); - AttrList = alist; + AttrList = addAttributeLists(AttrList, alist); } void SetAttributes(AttributeList *AL) { AttrList = AL; } const AttributeList *getAttributes() const { return AttrList; } @@ -1067,12 +1062,7 @@ public: /// /// Also extends the range of the declarator. void AddAttributes(AttributeList *alist, SourceLocation LastLoc) { - if (!alist) - return; // we parsed __attribute__(()) or had a syntax error - - if (AttrList) - alist->addAttributeList(AttrList); - AttrList = alist; + AttrList = addAttributeLists(AttrList, alist); if (!LastLoc.isInvalid()) SetRangeEnd(LastLoc); |