[cfe-commits] r80683 - in /cfe/trunk/include/clang/Parse: AttributeList.h DeclSpec.h

Douglas Gregor dgregor at apple.com
Tue Sep 1 10:10:19 PDT 2009


Author: dgregor
Date: Tue Sep  1 12:10:19 2009
New Revision: 80683

URL: http://llvm.org/viewvc/llvm-project?rev=80683&view=rev
Log:
"The attached patch moves AttributeList::addAttributeList outside the
class so as to accomodate one or both parameters being NULL, " from Sean Hunt!

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

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

==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Tue Sep  1 12:10:19 2009
@@ -113,16 +113,6 @@
   
   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 @@
   }
 };
 
+/// 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

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

==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Tue Sep  1 12:10:19 2009
@@ -321,12 +321,7 @@
   /// 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 @@
   ///
   /// 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);





More information about the cfe-commits mailing list