Skip to content

Commit 8fbec67

Browse files
committed
Move some more test-and-consumes over to TryConsumeToken()
llvm-svn: 197537
1 parent febb8d2 commit 8fbec67

File tree

1 file changed

+20
-36
lines changed

1 file changed

+20
-36
lines changed

clang/lib/Parse/ParseDecl.cpp

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,15 @@ void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName,
310310
ConsumeToken();
311311

312312
// Parse the non-empty comma-separated list of expressions.
313-
while (1) {
313+
do {
314314
ExprResult ArgExpr(ParseAssignmentExpression());
315315
if (ArgExpr.isInvalid()) {
316316
SkipUntil(tok::r_paren, StopAtSemi);
317317
return;
318318
}
319319
ArgExprs.push_back(ArgExpr.release());
320-
if (Tok.isNot(tok::comma))
321-
break;
322-
ConsumeToken(); // Eat the comma, move to the next argument
323-
}
320+
// Eat the comma, move to the next argument
321+
} while (TryConsumeToken(tok::comma));
324322
}
325323

326324
SourceLocation RParen = Tok.getLocation();
@@ -469,9 +467,7 @@ void Parser::ParseComplexMicrosoftDeclSpec(IdentifierInfo *Ident,
469467
ConsumeToken();
470468

471469
// Consume the '='.
472-
if (Tok.is(tok::equal)) {
473-
ConsumeToken();
474-
} else {
470+
if (!TryConsumeToken(tok::equal)) {
475471
Diag(Tok.getLocation(), diag::err_ms_property_expected_equal)
476472
<< KindStr;
477473
break;
@@ -993,33 +989,30 @@ void Parser::ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
993989
return;
994990
}
995991
IdentifierLoc *RelatedClass = ParseIdentifierLoc();
996-
if (Tok.isNot(tok::comma)) {
992+
if (!TryConsumeToken(tok::comma)) {
997993
Diag(Tok, diag::err_expected_comma);
998994
SkipUntil(tok::r_paren, StopAtSemi);
999995
return;
1000996
}
1001-
ConsumeToken();
1002-
997+
1003998
// Parse optional class method name.
1004999
IdentifierLoc *ClassMethod = 0;
10051000
if (Tok.is(tok::identifier)) {
10061001
ClassMethod = ParseIdentifierLoc();
1007-
if (Tok.isNot(tok::colon)) {
1002+
if (!TryConsumeToken(tok::colon)) {
10081003
Diag(Tok, diag::err_objcbridge_related_selector_name);
10091004
SkipUntil(tok::r_paren, StopAtSemi);
10101005
return;
10111006
}
1012-
ConsumeToken();
10131007
}
1014-
if (Tok.isNot(tok::comma)) {
1008+
if (!TryConsumeToken(tok::comma)) {
10151009
if (Tok.is(tok::colon))
10161010
Diag(Tok, diag::err_objcbridge_related_selector_name);
10171011
else
10181012
Diag(Tok, diag::err_expected_comma);
10191013
SkipUntil(tok::r_paren, StopAtSemi);
10201014
return;
10211015
}
1022-
ConsumeToken();
10231016

10241017
// Parse optional instance method name.
10251018
IdentifierLoc *InstanceMethod = 0;
@@ -1255,9 +1248,9 @@ void Parser::ParseThreadSafetyAttribute(IdentifierInfo &AttrName,
12551248
} else {
12561249
ArgExprs.push_back(ArgExpr.release());
12571250
}
1258-
if (Tok.isNot(tok::comma))
1251+
// Eat the comma, move to the next argument
1252+
if (!TryConsumeToken(tok::comma))
12591253
break;
1260-
ConsumeToken(); // Eat the comma, move to the next argument
12611254
}
12621255
// Match the ')'.
12631256
if (ArgExprsOk && !T.consumeClose()) {
@@ -1300,8 +1293,7 @@ void Parser::ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
13001293

13011294
bool LayoutCompatible = false;
13021295
bool MustBeNull = false;
1303-
while (Tok.is(tok::comma)) {
1304-
ConsumeToken();
1296+
while (TryConsumeToken(tok::comma)) {
13051297
if (Tok.isNot(tok::identifier)) {
13061298
Diag(Tok, diag::err_expected_ident);
13071299
T.skipToEnd();
@@ -1597,8 +1589,7 @@ void Parser::SkipMalformedDecl() {
15971589
// This declaration isn't over yet. Keep skipping.
15981590
continue;
15991591
}
1600-
if (Tok.is(tok::semi))
1601-
ConsumeToken();
1592+
TryConsumeToken(tok::semi);
16021593
return;
16031594

16041595
case tok::l_square:
@@ -1741,9 +1732,8 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
17411732
// don't need to parse the container in advance.
17421733
if (FRI && (Tok.is(tok::colon) || isTokIdentifier_in())) {
17431734
bool IsForRangeLoop = false;
1744-
if (Tok.is(tok::colon)) {
1735+
if (TryConsumeToken(tok::colon, FRI->ColonLoc)) {
17451736
IsForRangeLoop = true;
1746-
FRI->ColonLoc = ConsumeToken();
17471737
if (Tok.is(tok::l_brace))
17481738
FRI->RangeExpr = ParseBraceInitializer();
17491739
else
@@ -1770,9 +1760,8 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
17701760

17711761
// If we don't have a comma, it is either the end of the list (a ';') or an
17721762
// error, bail out.
1773-
while (Tok.is(tok::comma)) {
1774-
SourceLocation CommaLoc = ConsumeToken();
1775-
1763+
SourceLocation CommaLoc;
1764+
while (TryConsumeToken(tok::comma, CommaLoc)) {
17761765
if (Tok.isAtStartOfLine() && ExpectSemi && !MightBeDeclarator(Context)) {
17771766
// This comma was followed by a line-break and something which can't be
17781767
// the start of a declarator. The comma was probably a typo for a
@@ -1817,8 +1806,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
18171806
// Otherwise things are very confused and we skip to recover.
18181807
if (!isDeclarationSpecifier()) {
18191808
SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
1820-
if (Tok.is(tok::semi))
1821-
ConsumeToken();
1809+
TryConsumeToken(tok::semi);
18221810
}
18231811
}
18241812

@@ -2375,8 +2363,8 @@ ExprResult Parser::ParseAlignArgument(SourceLocation Start,
23752363
} else
23762364
ER = ParseConstantExpression();
23772365

2378-
if (getLangOpts().CPlusPlus11 && Tok.is(tok::ellipsis))
2379-
EllipsisLoc = ConsumeToken();
2366+
if (getLangOpts().CPlusPlus11)
2367+
TryConsumeToken(tok::ellipsis, EllipsisLoc);
23802368

23812369
return ER;
23822370
}
@@ -3407,8 +3395,7 @@ ParseStructDeclaration(ParsingDeclSpec &DS, FieldCallback &Fields) {
34073395
ParseDeclarator(DeclaratorInfo.D);
34083396
}
34093397

3410-
if (Tok.is(tok::colon)) {
3411-
ConsumeToken();
3398+
if (TryConsumeToken(tok::colon)) {
34123399
ExprResult Res(ParseConstantExpression());
34133400
if (Res.isInvalid())
34143401
SkipUntil(tok::semi, StopBeforeMatch);
@@ -3424,12 +3411,9 @@ ParseStructDeclaration(ParsingDeclSpec &DS, FieldCallback &Fields) {
34243411

34253412
// If we don't have a comma, it is either the end of the list (a ';')
34263413
// or an error, bail out.
3427-
if (Tok.isNot(tok::comma))
3414+
if (!TryConsumeToken(tok::comma, CommaLoc))
34283415
return;
34293416

3430-
// Consume the comma.
3431-
CommaLoc = ConsumeToken();
3432-
34333417
FirstDeclarator = false;
34343418
}
34353419
}

0 commit comments

Comments
 (0)