r198935 - TryConsume parser cleanups
Alp Toker
alp at nuanti.com
Fri Jan 10 03:19:30 PST 2014
Author: alp
Date: Fri Jan 10 05:19:30 2014
New Revision: 198935
URL: http://llvm.org/viewvc/llvm-project?rev=198935&view=rev
Log:
TryConsume parser cleanups
Also move some comments into the block they were meant to describe.
Modified:
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=198935&r1=198934&r2=198935&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Jan 10 05:19:30 2014
@@ -870,10 +870,7 @@ void Parser::ParseAvailabilityAttribute(
<< Keyword << SourceRange(UnavailableLoc);
}
UnavailableLoc = KeywordLoc;
-
- if (TryConsumeToken(tok::comma))
- continue;
- break;
+ continue;
}
if (Tok.isNot(tok::equal)) {
@@ -927,11 +924,7 @@ void Parser::ParseAvailabilityAttribute(
<< Keyword << VersionRange;
}
- if (Tok.isNot(tok::comma))
- break;
-
- ConsumeToken();
- } while (true);
+ } while (TryConsumeToken(tok::comma));
// Closing ')'.
if (T.consumeClose())
@@ -1000,8 +993,7 @@ void Parser::ParseObjCBridgeRelatedAttri
return;
}
IdentifierLoc *RelatedClass = ParseIdentifierLoc();
- if (!TryConsumeToken(tok::comma)) {
- Diag(Tok, diag::err_expected) << tok::comma;
+ if (ExpectAndConsume(tok::comma)) {
SkipUntil(tok::r_paren, StopAtSemi);
return;
}
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=198935&r1=198934&r2=198935&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Fri Jan 10 05:19:30 2014
@@ -465,10 +465,8 @@ Decl *Parser::ParseUsingDeclaration(unsi
// Ignore optional 'typename'.
// FIXME: This is wrong; we should parse this as a typename-specifier.
- if (Tok.is(tok::kw_typename)) {
- TypenameLoc = ConsumeToken();
+ if (TryConsumeToken(tok::kw_typename, TypenameLoc))
HasTypenameKeyword = true;
- }
// Parse nested-name-specifier.
IdentifierInfo *LastII = 0;
@@ -1675,10 +1673,8 @@ void Parser::ParseBaseClause(Decl *Class
// If the next token is a comma, consume it and keep reading
// base-specifiers.
- if (Tok.isNot(tok::comma)) break;
-
- // Consume the comma.
- ConsumeToken();
+ if (!TryConsumeToken(tok::comma))
+ break;
}
// Attach the base specifiers
@@ -1704,10 +1700,8 @@ Parser::BaseResult Parser::ParseBaseSpec
MaybeParseCXX11Attributes(Attributes);
// Parse the 'virtual' keyword.
- if (Tok.is(tok::kw_virtual)) {
- ConsumeToken();
+ if (TryConsumeToken(tok::kw_virtual))
IsVirtual = true;
- }
CheckMisplacedCXX11Attribute(Attributes, StartLoc);
@@ -1744,9 +1738,8 @@ Parser::BaseResult Parser::ParseBaseSpec
// actually part of the base-specifier-list grammar productions, but we
// parse it here for convenience.
SourceLocation EllipsisLoc;
- if (Tok.is(tok::ellipsis))
- EllipsisLoc = ConsumeToken();
-
+ TryConsumeToken(tok::ellipsis, EllipsisLoc);
+
// Find the complete source range for the base-specifier.
SourceRange Range(StartLoc, EndLocation);
@@ -2098,8 +2091,7 @@ void Parser::ParseCXXClassMemberDeclarat
if (!DeclaratorInfo.hasName()) {
// If so, skip until the semi-colon or a }.
SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
- if (Tok.is(tok::semi))
- ConsumeToken();
+ TryConsumeToken(tok::semi);
return;
}
@@ -2205,8 +2197,7 @@ void Parser::ParseCXXClassMemberDeclarat
// declarator pure-specifier[opt]
// declarator brace-or-equal-initializer[opt]
// identifier[opt] ':' constant-expression
- if (Tok.is(tok::colon)) {
- ConsumeToken();
+ if (TryConsumeToken(tok::colon)) {
BitfieldSize = ParseConstantExpression();
if (BitfieldSize.isInvalid())
SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch);
@@ -2866,8 +2857,7 @@ Parser::MemInitResult Parser::ParseMemIn
T.consumeClose();
SourceLocation EllipsisLoc;
- if (Tok.is(tok::ellipsis))
- EllipsisLoc = ConsumeToken();
+ TryConsumeToken(tok::ellipsis, EllipsisLoc);
return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II,
TemplateTypeTy, DS, IdLoc,
@@ -3022,10 +3012,8 @@ ExceptionSpecificationType Parser::Parse
Exceptions.push_back(Res.get());
Ranges.push_back(Range);
}
-
- if (Tok.is(tok::comma))
- ConsumeToken();
- else
+
+ if (!TryConsumeToken(tok::comma))
break;
}
@@ -3219,10 +3207,8 @@ void Parser::ParseCXX11AttributeSpecifie
while (Tok.isNot(tok::r_square)) {
// attribute not present
- if (Tok.is(tok::comma)) {
- ConsumeToken();
+ if (TryConsumeToken(tok::comma))
continue;
- }
SourceLocation ScopeLoc, AttrLoc;
IdentifierInfo *ScopeName = 0, *AttrName = 0;
@@ -3233,9 +3219,7 @@ void Parser::ParseCXX11AttributeSpecifie
break;
// scoped attribute
- if (Tok.is(tok::coloncolon)) {
- ConsumeToken();
-
+ if (TryConsumeToken(tok::coloncolon)) {
ScopeName = AttrName;
ScopeLoc = AttrLoc;
@@ -3278,12 +3262,9 @@ void Parser::ParseCXX11AttributeSpecifie
AttrLoc),
ScopeName, ScopeLoc, 0, 0, AttributeList::AS_CXX11);
- if (Tok.is(tok::ellipsis)) {
- ConsumeToken();
-
+ if (TryConsumeToken(tok::ellipsis))
Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis)
<< AttrName->getName();
- }
}
if (ExpectAndConsume(tok::r_square))
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=198935&r1=198934&r2=198935&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Fri Jan 10 05:19:30 2014
@@ -348,9 +348,7 @@ Retry:
}
// If we reached this code, the statement must end in a semicolon.
- if (Tok.is(tok::semi)) {
- ConsumeToken();
- } else if (!Res.isInvalid()) {
+ if (!TryConsumeToken(tok::semi) && !Res.isInvalid()) {
// If the result was valid, then we do want to diagnose this. Use
// ExpectAndConsume to emit the diagnostic, even though we know it won't
// succeed.
@@ -636,8 +634,8 @@ StmtResult Parser::ParseCaseStatement(bo
ColonProtection.restore();
if (TryConsumeToken(tok::colon, ColonLoc)) {
- // Treat "case blah;" as a typo for "case blah:".
} else if (TryConsumeToken(tok::semi, ColonLoc)) {
+ // Treat "case blah;" as a typo for "case blah:".
Diag(ColonLoc, diag::err_expected_after)
<< "'case'" << tok::colon
<< FixItHint::CreateReplacement(ColonLoc, ":");
@@ -711,8 +709,8 @@ StmtResult Parser::ParseDefaultStatement
SourceLocation ColonLoc;
if (TryConsumeToken(tok::colon, ColonLoc)) {
- // Treat "default;" as a typo for "default:".
} else if (TryConsumeToken(tok::semi, ColonLoc)) {
+ // Treat "default;" as a typo for "default:".
Diag(ColonLoc, diag::err_expected_after)
<< "'default'" << tok::colon
<< FixItHint::CreateReplacement(ColonLoc, ":");
@@ -2355,8 +2353,8 @@ StmtResult Parser::ParseAsmStatement(boo
Clobbers.push_back(Clobber.release());
- if (Tok.isNot(tok::comma)) break;
- ConsumeToken();
+ if (!TryConsumeToken(tok::comma))
+ break;
}
}
}
@@ -2432,8 +2430,8 @@ bool Parser::ParseAsmOperandsOpt(SmallVe
}
Exprs.push_back(Res.release());
// Eat the comma and continue parsing if it exists.
- if (Tok.isNot(tok::comma)) return false;
- ConsumeToken();
+ if (!TryConsumeToken(tok::comma))
+ return false;
}
}
Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=198935&r1=198934&r2=198935&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Fri Jan 10 05:19:30 2014
@@ -320,9 +320,8 @@ Parser::TPResult Parser::TryParseInitDec
return TPResult::True();
}
- if (Tok.isNot(tok::comma))
+ if (!TryConsumeToken(tok::comma))
break;
- ConsumeToken(); // the comma.
}
return TPResult::Ambiguous();
@@ -595,13 +594,10 @@ Parser::isCXX11AttributeSpecifier(bool D
}
}
- if (Tok.is(tok::ellipsis))
- ConsumeToken();
+ TryConsumeToken(tok::ellipsis);
- if (Tok.isNot(tok::comma))
+ if (!TryConsumeToken(tok::comma))
break;
-
- ConsumeToken();
}
// An attribute must end ']]'.
@@ -1724,9 +1720,8 @@ Parser::TryParseParameterDeclarationClau
return TPResult::False();
}
- if (Tok.isNot(tok::comma))
+ if (!TryConsumeToken(tok::comma))
break;
- ConsumeToken(); // the comma.
}
return TPResult::Ambiguous();
More information about the cfe-commits
mailing list