diff options
Diffstat (limited to 'lib/Parse')
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 5 | ||||
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 37 | ||||
-rw-r--r-- | lib/Parse/ParseExprCXX.cpp | 1 | ||||
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 3 | ||||
-rw-r--r-- | lib/Parse/Parser.cpp | 12 |
5 files changed, 32 insertions, 26 deletions
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index cb013e77f1..8bfdffc865 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -38,13 +38,16 @@ using namespace clang; TypeResult Parser::ParseTypeName(SourceRange *Range, Declarator::TheContext Context, AccessSpecifier AS, - Decl **OwnedType) { + Decl **OwnedType, + ParsedAttributes *Attrs) { DeclSpecContext DSC = getDeclSpecContextFromDeclaratorContext(Context); if (DSC == DSC_normal) DSC = DSC_type_specifier; // Parse the common declaration-specifiers piece. DeclSpec DS(AttrFactory); + if (Attrs) + DS.addAttributes(Attrs->getList()); ParseSpecifierQualifierList(DS, AS, DSC); if (OwnedType) *OwnedType = DS.isTypeSpecOwned() ? DS.getRepAsDecl() : 0; diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 4d428ceea1..22f5863e5f 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -451,24 +451,21 @@ Decl *Parser::ParseUsingDeclaration(unsigned Context, Decl **OwnedType) { CXXScopeSpec SS; SourceLocation TypenameLoc; - bool IsTypeName; - ParsedAttributesWithRange attrs(AttrFactory); + bool IsTypeName = false; + ParsedAttributesWithRange Attrs(AttrFactory); // FIXME: Simply skip the attributes and diagnose, don't bother parsing them. - MaybeParseCXX11Attributes(attrs); - ProhibitAttributes(attrs); - attrs.clear(); - attrs.Range = SourceRange(); + MaybeParseCXX11Attributes(Attrs); + ProhibitAttributes(Attrs); + Attrs.clear(); + Attrs.Range = SourceRange(); // Ignore optional 'typename'. // FIXME: This is wrong; we should parse this as a typename-specifier. if (Tok.is(tok::kw_typename)) { - TypenameLoc = Tok.getLocation(); - ConsumeToken(); + TypenameLoc = ConsumeToken(); IsTypeName = true; } - else - IsTypeName = false; // Parse nested-name-specifier. ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); @@ -495,14 +492,13 @@ Decl *Parser::ParseUsingDeclaration(unsigned Context, return 0; } - MaybeParseCXX11Attributes(attrs); + MaybeParseCXX11Attributes(Attrs); // Maybe this is an alias-declaration. bool IsAliasDecl = Tok.is(tok::equal); TypeResult TypeAlias; if (IsAliasDecl) { - // TODO: Attribute support. C++0x attributes may appear before the equals. - // Where can GNU attributes appear? + // TODO: Can GNU attributes appear here? ConsumeToken(); Diag(Tok.getLocation(), getLangOpts().CPlusPlus11 ? @@ -547,20 +543,21 @@ Decl *Parser::ParseUsingDeclaration(unsigned Context, TypeAlias = ParseTypeName(0, TemplateInfo.Kind ? Declarator::AliasTemplateContext : - Declarator::AliasDeclContext, AS, OwnedType); + Declarator::AliasDeclContext, AS, OwnedType, + &Attrs); } else { // C++11 attributes are not allowed on a using-declaration, but GNU ones // are. - ProhibitAttributes(attrs); + ProhibitAttributes(Attrs); // Parse (optional) attributes (most likely GNU strong-using extension). - MaybeParseGNUAttributes(attrs); + MaybeParseGNUAttributes(Attrs); } // Eat ';'. DeclEnd = Tok.getLocation(); ExpectAndConsume(tok::semi, diag::err_expected_semi_after, - !attrs.empty() ? "attributes list" : + !Attrs.empty() ? "attributes list" : IsAliasDecl ? "alias declaration" : "using declaration", tok::semi); @@ -592,13 +589,13 @@ Decl *Parser::ParseUsingDeclaration(unsigned Context, MultiTemplateParamsArg TemplateParamsArg( TemplateParams ? TemplateParams->data() : 0, TemplateParams ? TemplateParams->size() : 0); - // FIXME: Propagate attributes. return Actions.ActOnAliasDeclaration(getCurScope(), AS, TemplateParamsArg, - UsingLoc, Name, TypeAlias); + UsingLoc, Name, Attrs.getList(), + TypeAlias); } return Actions.ActOnUsingDeclaration(getCurScope(), AS, true, UsingLoc, SS, - Name, attrs.getList(), + Name, Attrs.getList(), IsTypeName, TypenameLoc); } diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 613b0bec5d..0a1111e358 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -1383,6 +1383,7 @@ bool Parser::ParseCXXCondition(ExprResult &ExprOut, // type-specifier-seq DeclSpec DS(AttrFactory); + DS.takeAttributesFrom(attrs); ParseSpecifierQualifierList(DS); // declarator diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 4c8bd6fe56..a77c03459f 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -1385,9 +1385,6 @@ StmtResult Parser::ParseForStatement(SourceLocation *TrailingElseLoc) { if (!C99orCXXorObjC) // Use of C99-style for loops in C90 mode? Diag(Tok, diag::ext_c99_variable_decl_in_for_loop); - ParsedAttributesWithRange attrs(AttrFactory); - MaybeParseCXX11Attributes(attrs); - // In C++0x, "for (T NS:a" might not be a typo for :: bool MightBeForRangeStmt = getLangOpts().CPlusPlus; ColonProtectionRAIIObject ColonProtection(*this, MightBeForRangeStmt); diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 1a667daab7..2d8d5b1322 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -566,7 +566,6 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result) { /// external-declaration: [C99 6.9], declaration: [C++ dcl.dcl] /// function-definition /// declaration -/// [C++0x] empty-declaration /// [GNU] asm-definition /// [GNU] __extension__ external-declaration /// [OBJC] objc-class-definition @@ -578,8 +577,10 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result) { /// [C++] linkage-specification /// [GNU] asm-definition: /// simple-asm-expr ';' +/// [C++11] empty-declaration +/// [C++11] attribute-declaration /// -/// [C++0x] empty-declaration: +/// [C++11] empty-declaration: /// ';' /// /// [C++0x/GNU] 'extern' 'template' declaration @@ -624,6 +625,13 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, HandlePragmaOpenCLExtension(); return DeclGroupPtrTy(); case tok::semi: + // Either a C++11 empty-declaration or attribute-declaration. + if (attrs.Range.isValid()) { + // FIXME: Add an AST representation for this. + Actions.ActOnAttributeDeclaration(attrs.getList()); + return DeclGroupPtrTy(); + } + ConsumeExtraSemi(OutsideFunction); // TODO: Invoke action for top-level semicolon. return DeclGroupPtrTy(); |