diff options
author | Alp Toker <alp@nuanti.com> | 2014-01-05 03:27:11 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2014-01-05 03:27:11 +0000 |
commit | c33eba892dd9ab6a2b233a7ed3aded1a102be876 (patch) | |
tree | 6da8324fe54ba5ad76940c86fc7dad93ba32144e /lib | |
parent | 39be08d4687a047f4e5e7ec028e96ec1ee1d4e7c (diff) | |
download | clang-c33eba892dd9ab6a2b233a7ed3aded1a102be876.tar.gz |
Parse: Token consumption modernization and loop de-nesting
Cleanup only.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198539 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 83 | ||||
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 12 | ||||
-rw-r--r-- | lib/Parse/ParseExprCXX.cpp | 4 | ||||
-rw-r--r-- | lib/Parse/ParseTemplate.cpp | 8 | ||||
-rw-r--r-- | lib/Parse/Parser.cpp | 3 |
5 files changed, 51 insertions, 59 deletions
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 32f7a7a85d..277355cd40 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -132,45 +132,50 @@ void Parser::ParseGNUAttributes(ParsedAttributes &attrs, return; } // Parse the attribute-list. e.g. __attribute__(( weak, alias("__f") )) - while (Tok.is(tok::identifier) || isDeclarationSpecifier() || - Tok.is(tok::comma)) { - if (Tok.is(tok::comma)) { - // allows for empty/non-empty attributes. ((__vector_size__(16),,,,)) - ConsumeToken(); + while (true) { + // Allow empty/non-empty attributes. ((__vector_size__(16),,,,)) + if (TryConsumeToken(tok::comma)) continue; - } - // we have an identifier or declaration specifier (const, int, etc.) + + // Expect an identifier or declaration specifier (const, int, etc.) + if (Tok.isNot(tok::identifier) && !isDeclarationSpecifier()) + break; + IdentifierInfo *AttrName = Tok.getIdentifierInfo(); SourceLocation AttrNameLoc = ConsumeToken(); - if (Tok.is(tok::l_paren)) { - // handle "parameterized" attributes - if (LateAttrs && isAttributeLateParsed(*AttrName)) { - LateParsedAttribute *LA = - new LateParsedAttribute(this, *AttrName, AttrNameLoc); - LateAttrs->push_back(LA); - - // Attributes in a class are parsed at the end of the class, along - // with other late-parsed declarations. - if (!ClassStack.empty() && !LateAttrs->parseSoon()) - getCurrentClass().LateParsedDeclarations.push_back(LA); - - // consume everything up to and including the matching right parens - ConsumeAndStoreUntil(tok::r_paren, LA->Toks, true, false); - - Token Eof; - Eof.startToken(); - Eof.setLocation(Tok.getLocation()); - LA->Toks.push_back(Eof); - } else { - ParseGNUAttributeArgs(AttrName, AttrNameLoc, attrs, endLoc, - 0, SourceLocation(), AttributeList::AS_GNU); - } - } else { + if (Tok.isNot(tok::l_paren)) { attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0, 0, AttributeList::AS_GNU); + continue; + } + + // Handle "parameterized" attributes + if (!LateAttrs || !isAttributeLateParsed(*AttrName)) { + ParseGNUAttributeArgs(AttrName, AttrNameLoc, attrs, endLoc, 0, + SourceLocation(), AttributeList::AS_GNU); + continue; } + + // Handle attributes with arguments that require late parsing. + LateParsedAttribute *LA = + new LateParsedAttribute(this, *AttrName, AttrNameLoc); + LateAttrs->push_back(LA); + + // Attributes in a class are parsed at the end of the class, along + // with other late-parsed declarations. + if (!ClassStack.empty() && !LateAttrs->parseSoon()) + getCurrentClass().LateParsedDeclarations.push_back(LA); + + // consume everything up to and including the matching right parens + ConsumeAndStoreUntil(tok::r_paren, LA->Toks, true, false); + + Token Eof; + Eof.startToken(); + Eof.setLocation(Tok.getLocation()); + LA->Toks.push_back(Eof); } + if (ExpectAndConsume(tok::r_paren)) SkipUntil(tok::r_paren, StopAtSemi); SourceLocation Loc = Tok.getLocation(); @@ -491,17 +496,15 @@ void Parser::ParseComplexMicrosoftDeclSpec(IdentifierInfo *Ident, next_property_accessor: // Keep processing accessors until we run out. - if (Tok.is(tok::comma)) { - ConsumeAnyToken(); + if (TryConsumeToken(tok::comma)) continue; // If we run into the ')', stop without consuming it. - } else if (Tok.is(tok::r_paren)) { - break; - } else { - Diag(Tok.getLocation(), diag::err_ms_property_expected_comma_or_rparen); + if (Tok.is(tok::r_paren)) break; - } + + Diag(Tok.getLocation(), diag::err_ms_property_expected_comma_or_rparen); + break; } // Only add the property attribute if it was well-formed. @@ -1276,12 +1279,10 @@ void Parser::ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName, } IdentifierLoc *ArgumentKind = ParseIdentifierLoc(); - if (Tok.isNot(tok::comma)) { - Diag(Tok, diag::err_expected) << tok::comma; + if (ExpectAndConsume(tok::comma)) { T.skipToEnd(); return; } - ConsumeToken(); SourceRange MatchingCTypeRange; TypeResult MatchingCType = ParseTypeName(&MatchingCTypeRange); diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index d3283eb21b..76973aee4f 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -2365,12 +2365,10 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, // If we don't have a comma, it is either the end of the list (a ';') // or an error, bail out. - if (Tok.isNot(tok::comma)) + SourceLocation CommaLoc; + if (!TryConsumeToken(tok::comma, CommaLoc)) break; - // Consume the comma. - SourceLocation CommaLoc = ConsumeToken(); - if (Tok.isAtStartOfLine() && !MightBeDeclarator(Declarator::MemberContext)) { // This comma was followed by a line-break and something which can't be @@ -2439,8 +2437,7 @@ ExprResult Parser::ParseCXXMemberInitializer(Decl *D, bool IsFunction, EnterExpressionEvaluationContext Context(Actions, Sema::PotentiallyEvaluated, D); - if (Tok.is(tok::equal)) { - EqualLoc = ConsumeToken(); + if (TryConsumeToken(tok::equal, EqualLoc)) { if (Tok.is(tok::kw_delete)) { // In principle, an initializer of '= delete p;' is legal, but it will // never type-check. It's better to diagnose it as an ill-formed expression @@ -2868,8 +2865,7 @@ Parser::MemInitResult Parser::ParseMemInitializer(Decl *ConstructorDecl) { return true; SourceLocation EllipsisLoc; - if (Tok.is(tok::ellipsis)) - EllipsisLoc = ConsumeToken(); + TryConsumeToken(tok::ellipsis, EllipsisLoc); return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II, TemplateTypeTy, DS, IdLoc, diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index fe380e29d3..42e737004b 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -1008,10 +1008,8 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( // Parse 'mutable'[opt]. SourceLocation MutableLoc; - if (Tok.is(tok::kw_mutable)) { - MutableLoc = ConsumeToken(); + if (TryConsumeToken(tok::kw_mutable, MutableLoc)) DeclEndLoc = MutableLoc; - } // Parse exception-specification[opt]. ExceptionSpecificationType ESpecType = EST_None; diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index a5471f1294..e2a71c5e71 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -1023,11 +1023,9 @@ ParsedTemplateArgument Parser::ParseTemplateTemplateArgument() { UnqualifiedId Name; Name.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); ConsumeToken(); // the identifier - - // Parse the ellipsis. - if (Tok.is(tok::ellipsis)) - EllipsisLoc = ConsumeToken(); - + + TryConsumeToken(tok::ellipsis, EllipsisLoc); + // If the next token signals the end of a template argument, // then we have a dependent template name that could be a template // template argument. diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 54857164ef..1c20a47f17 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -1210,9 +1210,8 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { // NOTE: GCC just makes this an ext-warn. It's not clear what it does with // the declarations though. It's trivial to ignore them, really hard to do // anything else with them. - if (Tok.is(tok::semi)) { + if (TryConsumeToken(tok::semi)) { Diag(DSStart, diag::err_declaration_does_not_declare_param); - ConsumeToken(); continue; } |