[cfe-commits] r140794 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseDeclCXX.cpp test/Parser/cxx0x-attributes.cpp

Peter Collingbourne peter at pcc.me.uk
Thu Sep 29 11:04:06 PDT 2011


Author: pcc
Date: Thu Sep 29 13:04:05 2011
New Revision: 140794

URL: http://llvm.org/viewvc/llvm-project?rev=140794&view=rev
Log:
Add support for parsing an attribute-specifier-seq containing multiple
attribute-specifiers

Modified:
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/test/Parser/cxx0x-attributes.cpp

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=140794&r1=140793&r2=140794&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Sep 29 13:04:05 2011
@@ -1739,6 +1739,9 @@
     if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
       ParseCXX0XAttributes(attrs, endLoc);
   }
+
+  void ParseCXX0XAttributeSpecifier(ParsedAttributes &attrs,
+                                    SourceLocation *EndLoc = 0);
   void ParseCXX0XAttributes(ParsedAttributesWithRange &attrs,
                             SourceLocation *EndLoc = 0);
 

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=140794&r1=140793&r2=140794&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Thu Sep 29 13:04:05 2011
@@ -2556,8 +2556,8 @@
   Victim->TemplateScope = getCurScope()->getParent()->isTemplateParamScope();
 }
 
-/// ParseCXX0XAttributes - Parse a C++0x attribute-specifier. Currently only
-/// parses standard attributes.
+/// ParseCXX0XAttributeSpecifier - Parse a C++0x attribute-specifier. Currently
+/// only parses standard attributes.
 ///
 /// [C++0x] attribute-specifier:
 ///         '[' '[' attribute-list ']' ']'
@@ -2591,13 +2591,11 @@
 ///         '[' balanced-token-seq ']'
 ///         '{' balanced-token-seq '}'
 ///         any token but '(', ')', '[', ']', '{', or '}'
-void Parser::ParseCXX0XAttributes(ParsedAttributesWithRange &attrs,
-                                  SourceLocation *endLoc) {
+void Parser::ParseCXX0XAttributeSpecifier(ParsedAttributes &attrs,
+                                          SourceLocation *endLoc) {
   assert(Tok.is(tok::l_square) && NextToken().is(tok::l_square)
       && "Not a C++0x attribute list");
 
-  SourceLocation StartLoc = Tok.getLocation(), Loc;
-
   ConsumeBracket();
   ConsumeBracket();
 
@@ -2692,11 +2690,27 @@
 
   if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare))
     SkipUntil(tok::r_square, false);
-  Loc = Tok.getLocation();
+  if (endLoc)
+    *endLoc = Tok.getLocation();
   if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare))
     SkipUntil(tok::r_square, false);
+}
+
+/// ParseCXX0XAttributes - Parse a C++0x attribute-specifier-seq.
+///
+/// attribute-specifier-seq:
+///       attribute-specifier-seq[opt] attribute-specifier
+void Parser::ParseCXX0XAttributes(ParsedAttributesWithRange &attrs,
+                                  SourceLocation *endLoc) {
+  SourceLocation StartLoc = Tok.getLocation(), Loc;
+  if (!endLoc)
+    endLoc = &Loc;
+
+  do
+    ParseCXX0XAttributeSpecifier(attrs, endLoc);
+  while (isCXX0XAttributeSpecifier());
 
-  attrs.Range = SourceRange(StartLoc, Loc);
+  attrs.Range = SourceRange(StartLoc, *endLoc);
 }
 
 /// ParseCXX0XAlignArgument - Parse the argument to C++0x's [[align]]

Modified: cfe/trunk/test/Parser/cxx0x-attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-attributes.cpp?rev=140794&r1=140793&r2=140794&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx0x-attributes.cpp (original)
+++ cfe/trunk/test/Parser/cxx0x-attributes.cpp Thu Sep 29 13:04:05 2011
@@ -13,6 +13,7 @@
 class [[]] class_attr {};
 extern "C++" [[]] int extern_attr;
 template <typename T> [[]] void template_attr ();
+[[]] [[]] int [[]] [[]] multi_attr [[]] [[]];
 
 int comma_attr [[,]]; // expected-error {{expected identifier}}
 int scope_attr [[foo::]]; // expected-error {{expected identifier}}





More information about the cfe-commits mailing list