From: Peter Collingbourne Date: Thu, 29 Sep 2011 18:04:05 +0000 (+0000) Subject: Add support for parsing an attribute-specifier-seq containing multiple X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3497fdfdb742f55d7b7ec8e22779fb08962b8441;p=clang Add support for parsing an attribute-specifier-seq containing multiple attribute-specifiers git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140794 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index afcfda0425..4d81abde98 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -1739,6 +1739,9 @@ private: if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) ParseCXX0XAttributes(attrs, endLoc); } + + void ParseCXX0XAttributeSpecifier(ParsedAttributes &attrs, + SourceLocation *EndLoc = 0); void ParseCXX0XAttributes(ParsedAttributesWithRange &attrs, SourceLocation *EndLoc = 0); diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 88e93a05b7..ab953dc9c8 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -2556,8 +2556,8 @@ void Parser::PopParsingClass(Sema::ParsingClassState state) { 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 @@ void Parser::PopParsingClass(Sema::ParsingClassState state) { /// '[' 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 @@ void Parser::ParseCXX0XAttributes(ParsedAttributesWithRange &attrs, 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]] diff --git a/test/Parser/cxx0x-attributes.cpp b/test/Parser/cxx0x-attributes.cpp index 75f23c657c..0b6413cfb2 100644 --- a/test/Parser/cxx0x-attributes.cpp +++ b/test/Parser/cxx0x-attributes.cpp @@ -13,6 +13,7 @@ void fn_attr () [[]]; class [[]] class_attr {}; extern "C++" [[]] int extern_attr; template [[]] void template_attr (); +[[]] [[]] int [[]] [[]] multi_attr [[]] [[]]; int comma_attr [[,]]; // expected-error {{expected identifier}} int scope_attr [[foo::]]; // expected-error {{expected identifier}}