[cfe-commits] r39640 - in /cfe/cfe/trunk: Parse/ParseDecl.cpp include/clang/Parse/DeclSpec.h

Steve Naroff snaroff at apple.com
Wed Jul 11 09:46:32 PDT 2007


Author: snaroff
Date: Wed Jul 11 11:46:32 2007
New Revision: 39640

URL: http://llvm.org/viewvc/llvm-project?rev=39640&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
Changed the name of DeclSpec.AddAttribute and Declarator.AddAttribute to
AddAttributes(). Also added some (much needed) comments. While documenting,
realized I could simplify & tighten up Declarator.AddAttributes...

Modified:
    cfe/cfe/trunk/Parse/ParseDecl.cpp
    cfe/cfe/trunk/include/clang/Parse/DeclSpec.h

Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=39640&r1=39639&r2=39640&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:46:32 2007
@@ -244,7 +244,7 @@
     
     // If attributes are present, parse them.
     if (Tok.getKind() == tok::kw___attribute)
-      D.AddAttribute(ParseAttributes());
+      D.AddAttributes(ParseAttributes());
     
     // Parse declarator '=' initializer.
     ExprResult Init;
@@ -397,7 +397,7 @@
     
     // GNU attributes support.
     case tok::kw___attribute:
-      DS.AddAttribute(ParseAttributes());
+      DS.AddAttributes(ParseAttributes());
       continue;
       
     // storage-class-specifier
@@ -680,7 +680,7 @@
       
       // If attributes exist after the declarator, parse them.
       if (Tok.getKind() == tok::kw___attribute)
-        DeclaratorInfo.AddAttribute(ParseAttributes());
+        DeclaratorInfo.AddAttributes(ParseAttributes());
       
       // Install the declarator into the current TagDecl.
       DeclTy *Field = Actions.ParseField(CurScope, TagDecl, SpecQualLoc,
@@ -700,7 +700,7 @@
       
       // Attributes are only allowed on the second declarator.
       if (Tok.getKind() == tok::kw___attribute)
-        DeclaratorInfo.AddAttribute(ParseAttributes());
+        DeclaratorInfo.AddAttributes(ParseAttributes());
     }
     
     if (Tok.getKind() == tok::semi) {
@@ -941,7 +941,7 @@
                                  getLang())*2;
       break;
     case tok::kw___attribute:
-      DS.AddAttribute(ParseAttributes());
+      DS.AddAttributes(ParseAttributes());
       continue; // do *not* consume the next token!
     }
     
@@ -1136,7 +1136,7 @@
     // direct-declarator: '(' attributes declarator ')'
     if (isGrouping) {
       if (Tok.getKind() == tok::kw___attribute)
-        D.AddAttribute(ParseAttributes());
+        D.AddAttributes(ParseAttributes());
       
       ParseDeclaratorInternal(D);
       // Match the ')'.
@@ -1252,7 +1252,7 @@
 
       // Parse GNU attributes, if present.
       if (Tok.getKind() == tok::kw___attribute)
-        ParmDecl.AddAttribute(ParseAttributes());
+        ParmDecl.AddAttributes(ParseAttributes());
       
       // Verify C99 6.7.5.3p2: The only SCS allowed is 'register'.
       // NOTE: we could trivially allow 'int foo(auto int X)' if we wanted.

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

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/DeclSpec.h Wed Jul 11 11:46:32 2007
@@ -222,10 +222,23 @@
   
   bool SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec);
   
-  /// attributes
-  void AddAttribute(AttributeList *alist) {
+  /// AddAttributes - contatenates two attribute lists. 
+  /// The GCC attribute syntax allows for the following:
+  ///
+  /// short __attribute__(( unused, deprecated )) 
+  /// int __attribute__(( may_alias, aligned(16) )) var;
+  ///
+  /// This declares 4 attributes using 2 lists. The following syntax is
+  /// also allowed and identical to the previous declaration.
+  ///
+  /// short __attribute__((unused)) __attribute__((deprecated)) 
+  /// int __attribute__((may_alias)) __attribute__((aligned(16))) var;
+  /// 
+  /// I don't believe this usage of attributes is common.
+  void AddAttributes(AttributeList *alist) {
     if (!alist)
       return; // we parsed __attribute__(()) or had a syntax error
+      
     if (AttrList) 
       alist->addAttributeList(AttrList); 
     AttrList = alist;
@@ -518,12 +531,16 @@
            DeclTypeInfo[0].Kind == DeclaratorChunk::Function;
   }
   
-  /// attributes
-  void AddAttribute(AttributeList *alist) { 
+  /// AddAttributes - simply adds the attribute list to the Declarator.
+  /// Unlike AddAttributes on DeclSpec, this routine should never have to
+  /// concatenate two lists. The following syntax adds 3 attributes to "var":
+  ///
+  /// short int var __attribute__((aligned(16),common,deprecated));
+  ///
+  void AddAttributes(AttributeList *alist) { 
     if (!alist)
       return; // we parsed __attribute__(()) or had a syntax error
-    if (AttrList) 
-      alist->addAttributeList(AttrList); 
+    assert((AttrList == 0) && "Declarator already has an attribute list");
     AttrList = alist;
   }
 };





More information about the cfe-commits mailing list