r197537 - Move some more test-and-consumes over to TryConsumeToken()
Alp Toker
alp at nuanti.com
Tue Dec 17 15:29:36 PST 2013
Author: alp
Date: Tue Dec 17 17:29:36 2013
New Revision: 197537
URL: http://llvm.org/viewvc/llvm-project?rev=197537&view=rev
Log:
Move some more test-and-consumes over to TryConsumeToken()
Modified:
cfe/trunk/lib/Parse/ParseDecl.cpp
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=197537&r1=197536&r2=197537&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Dec 17 17:29:36 2013
@@ -310,17 +310,15 @@ void Parser::ParseGNUAttributeArgs(Ident
ConsumeToken();
// Parse the non-empty comma-separated list of expressions.
- while (1) {
+ do {
ExprResult ArgExpr(ParseAssignmentExpression());
if (ArgExpr.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
return;
}
ArgExprs.push_back(ArgExpr.release());
- if (Tok.isNot(tok::comma))
- break;
- ConsumeToken(); // Eat the comma, move to the next argument
- }
+ // Eat the comma, move to the next argument
+ } while (TryConsumeToken(tok::comma));
}
SourceLocation RParen = Tok.getLocation();
@@ -469,9 +467,7 @@ void Parser::ParseComplexMicrosoftDeclSp
ConsumeToken();
// Consume the '='.
- if (Tok.is(tok::equal)) {
- ConsumeToken();
- } else {
+ if (!TryConsumeToken(tok::equal)) {
Diag(Tok.getLocation(), diag::err_ms_property_expected_equal)
<< KindStr;
break;
@@ -993,25 +989,23 @@ void Parser::ParseObjCBridgeRelatedAttri
return;
}
IdentifierLoc *RelatedClass = ParseIdentifierLoc();
- if (Tok.isNot(tok::comma)) {
+ if (!TryConsumeToken(tok::comma)) {
Diag(Tok, diag::err_expected_comma);
SkipUntil(tok::r_paren, StopAtSemi);
return;
}
- ConsumeToken();
-
+
// Parse optional class method name.
IdentifierLoc *ClassMethod = 0;
if (Tok.is(tok::identifier)) {
ClassMethod = ParseIdentifierLoc();
- if (Tok.isNot(tok::colon)) {
+ if (!TryConsumeToken(tok::colon)) {
Diag(Tok, diag::err_objcbridge_related_selector_name);
SkipUntil(tok::r_paren, StopAtSemi);
return;
}
- ConsumeToken();
}
- if (Tok.isNot(tok::comma)) {
+ if (!TryConsumeToken(tok::comma)) {
if (Tok.is(tok::colon))
Diag(Tok, diag::err_objcbridge_related_selector_name);
else
@@ -1019,7 +1013,6 @@ void Parser::ParseObjCBridgeRelatedAttri
SkipUntil(tok::r_paren, StopAtSemi);
return;
}
- ConsumeToken();
// Parse optional instance method name.
IdentifierLoc *InstanceMethod = 0;
@@ -1255,9 +1248,9 @@ void Parser::ParseThreadSafetyAttribute(
} else {
ArgExprs.push_back(ArgExpr.release());
}
- if (Tok.isNot(tok::comma))
+ // Eat the comma, move to the next argument
+ if (!TryConsumeToken(tok::comma))
break;
- ConsumeToken(); // Eat the comma, move to the next argument
}
// Match the ')'.
if (ArgExprsOk && !T.consumeClose()) {
@@ -1300,8 +1293,7 @@ void Parser::ParseTypeTagForDatatypeAttr
bool LayoutCompatible = false;
bool MustBeNull = false;
- while (Tok.is(tok::comma)) {
- ConsumeToken();
+ while (TryConsumeToken(tok::comma)) {
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident);
T.skipToEnd();
@@ -1597,8 +1589,7 @@ void Parser::SkipMalformedDecl() {
// This declaration isn't over yet. Keep skipping.
continue;
}
- if (Tok.is(tok::semi))
- ConsumeToken();
+ TryConsumeToken(tok::semi);
return;
case tok::l_square:
@@ -1741,9 +1732,8 @@ Parser::DeclGroupPtrTy Parser::ParseDecl
// don't need to parse the container in advance.
if (FRI && (Tok.is(tok::colon) || isTokIdentifier_in())) {
bool IsForRangeLoop = false;
- if (Tok.is(tok::colon)) {
+ if (TryConsumeToken(tok::colon, FRI->ColonLoc)) {
IsForRangeLoop = true;
- FRI->ColonLoc = ConsumeToken();
if (Tok.is(tok::l_brace))
FRI->RangeExpr = ParseBraceInitializer();
else
@@ -1770,9 +1760,8 @@ Parser::DeclGroupPtrTy Parser::ParseDecl
// If we don't have a comma, it is either the end of the list (a ';') or an
// error, bail out.
- while (Tok.is(tok::comma)) {
- SourceLocation CommaLoc = ConsumeToken();
-
+ SourceLocation CommaLoc;
+ while (TryConsumeToken(tok::comma, CommaLoc)) {
if (Tok.isAtStartOfLine() && ExpectSemi && !MightBeDeclarator(Context)) {
// This comma was followed by a line-break and something which can't be
// the start of a declarator. The comma was probably a typo for a
@@ -1817,8 +1806,7 @@ Parser::DeclGroupPtrTy Parser::ParseDecl
// Otherwise things are very confused and we skip to recover.
if (!isDeclarationSpecifier()) {
SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
- if (Tok.is(tok::semi))
- ConsumeToken();
+ TryConsumeToken(tok::semi);
}
}
@@ -2375,8 +2363,8 @@ ExprResult Parser::ParseAlignArgument(So
} else
ER = ParseConstantExpression();
- if (getLangOpts().CPlusPlus11 && Tok.is(tok::ellipsis))
- EllipsisLoc = ConsumeToken();
+ if (getLangOpts().CPlusPlus11)
+ TryConsumeToken(tok::ellipsis, EllipsisLoc);
return ER;
}
@@ -3407,8 +3395,7 @@ ParseStructDeclaration(ParsingDeclSpec &
ParseDeclarator(DeclaratorInfo.D);
}
- if (Tok.is(tok::colon)) {
- ConsumeToken();
+ if (TryConsumeToken(tok::colon)) {
ExprResult Res(ParseConstantExpression());
if (Res.isInvalid())
SkipUntil(tok::semi, StopBeforeMatch);
@@ -3424,12 +3411,9 @@ ParseStructDeclaration(ParsingDeclSpec &
// 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))
+ if (!TryConsumeToken(tok::comma, CommaLoc))
return;
- // Consume the comma.
- CommaLoc = ConsumeToken();
-
FirstDeclarator = false;
}
}
More information about the cfe-commits
mailing list