@@ -310,17 +310,15 @@ void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName,
310
310
ConsumeToken ();
311
311
312
312
// Parse the non-empty comma-separated list of expressions.
313
- while ( 1 ) {
313
+ do {
314
314
ExprResult ArgExpr (ParseAssignmentExpression ());
315
315
if (ArgExpr.isInvalid ()) {
316
316
SkipUntil (tok::r_paren, StopAtSemi);
317
317
return ;
318
318
}
319
319
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));
324
322
}
325
323
326
324
SourceLocation RParen = Tok.getLocation ();
@@ -469,9 +467,7 @@ void Parser::ParseComplexMicrosoftDeclSpec(IdentifierInfo *Ident,
469
467
ConsumeToken ();
470
468
471
469
// Consume the '='.
472
- if (Tok.is (tok::equal)) {
473
- ConsumeToken ();
474
- } else {
470
+ if (!TryConsumeToken (tok::equal)) {
475
471
Diag (Tok.getLocation (), diag::err_ms_property_expected_equal)
476
472
<< KindStr;
477
473
break ;
@@ -993,33 +989,30 @@ void Parser::ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
993
989
return ;
994
990
}
995
991
IdentifierLoc *RelatedClass = ParseIdentifierLoc ();
996
- if (Tok. isNot (tok::comma)) {
992
+ if (! TryConsumeToken (tok::comma)) {
997
993
Diag (Tok, diag::err_expected_comma);
998
994
SkipUntil (tok::r_paren, StopAtSemi);
999
995
return ;
1000
996
}
1001
- ConsumeToken ();
1002
-
997
+
1003
998
// Parse optional class method name.
1004
999
IdentifierLoc *ClassMethod = 0 ;
1005
1000
if (Tok.is (tok::identifier)) {
1006
1001
ClassMethod = ParseIdentifierLoc ();
1007
- if (Tok. isNot (tok::colon)) {
1002
+ if (! TryConsumeToken (tok::colon)) {
1008
1003
Diag (Tok, diag::err_objcbridge_related_selector_name);
1009
1004
SkipUntil (tok::r_paren, StopAtSemi);
1010
1005
return ;
1011
1006
}
1012
- ConsumeToken ();
1013
1007
}
1014
- if (Tok. isNot (tok::comma)) {
1008
+ if (! TryConsumeToken (tok::comma)) {
1015
1009
if (Tok.is (tok::colon))
1016
1010
Diag (Tok, diag::err_objcbridge_related_selector_name);
1017
1011
else
1018
1012
Diag (Tok, diag::err_expected_comma);
1019
1013
SkipUntil (tok::r_paren, StopAtSemi);
1020
1014
return ;
1021
1015
}
1022
- ConsumeToken ();
1023
1016
1024
1017
// Parse optional instance method name.
1025
1018
IdentifierLoc *InstanceMethod = 0 ;
@@ -1255,9 +1248,9 @@ void Parser::ParseThreadSafetyAttribute(IdentifierInfo &AttrName,
1255
1248
} else {
1256
1249
ArgExprs.push_back (ArgExpr.release ());
1257
1250
}
1258
- if (Tok.isNot (tok::comma))
1251
+ // Eat the comma, move to the next argument
1252
+ if (!TryConsumeToken (tok::comma))
1259
1253
break ;
1260
- ConsumeToken (); // Eat the comma, move to the next argument
1261
1254
}
1262
1255
// Match the ')'.
1263
1256
if (ArgExprsOk && !T.consumeClose ()) {
@@ -1300,8 +1293,7 @@ void Parser::ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
1300
1293
1301
1294
bool LayoutCompatible = false ;
1302
1295
bool MustBeNull = false ;
1303
- while (Tok.is (tok::comma)) {
1304
- ConsumeToken ();
1296
+ while (TryConsumeToken (tok::comma)) {
1305
1297
if (Tok.isNot (tok::identifier)) {
1306
1298
Diag (Tok, diag::err_expected_ident);
1307
1299
T.skipToEnd ();
@@ -1597,8 +1589,7 @@ void Parser::SkipMalformedDecl() {
1597
1589
// This declaration isn't over yet. Keep skipping.
1598
1590
continue ;
1599
1591
}
1600
- if (Tok.is (tok::semi))
1601
- ConsumeToken ();
1592
+ TryConsumeToken (tok::semi);
1602
1593
return ;
1603
1594
1604
1595
case tok::l_square:
@@ -1741,9 +1732,8 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
1741
1732
// don't need to parse the container in advance.
1742
1733
if (FRI && (Tok.is (tok::colon) || isTokIdentifier_in ())) {
1743
1734
bool IsForRangeLoop = false ;
1744
- if (Tok. is (tok::colon)) {
1735
+ if (TryConsumeToken (tok::colon, FRI-> ColonLoc )) {
1745
1736
IsForRangeLoop = true ;
1746
- FRI->ColonLoc = ConsumeToken ();
1747
1737
if (Tok.is (tok::l_brace))
1748
1738
FRI->RangeExpr = ParseBraceInitializer ();
1749
1739
else
@@ -1770,9 +1760,8 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
1770
1760
1771
1761
// If we don't have a comma, it is either the end of the list (a ';') or an
1772
1762
// error, bail out.
1773
- while (Tok.is (tok::comma)) {
1774
- SourceLocation CommaLoc = ConsumeToken ();
1775
-
1763
+ SourceLocation CommaLoc;
1764
+ while (TryConsumeToken (tok::comma, CommaLoc)) {
1776
1765
if (Tok.isAtStartOfLine () && ExpectSemi && !MightBeDeclarator (Context)) {
1777
1766
// This comma was followed by a line-break and something which can't be
1778
1767
// the start of a declarator. The comma was probably a typo for a
@@ -1817,8 +1806,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
1817
1806
// Otherwise things are very confused and we skip to recover.
1818
1807
if (!isDeclarationSpecifier ()) {
1819
1808
SkipUntil (tok::r_brace, StopAtSemi | StopBeforeMatch);
1820
- if (Tok.is (tok::semi))
1821
- ConsumeToken ();
1809
+ TryConsumeToken (tok::semi);
1822
1810
}
1823
1811
}
1824
1812
@@ -2375,8 +2363,8 @@ ExprResult Parser::ParseAlignArgument(SourceLocation Start,
2375
2363
} else
2376
2364
ER = ParseConstantExpression ();
2377
2365
2378
- if (getLangOpts ().CPlusPlus11 && Tok. is (tok::ellipsis) )
2379
- EllipsisLoc = ConsumeToken ( );
2366
+ if (getLangOpts ().CPlusPlus11 )
2367
+ TryConsumeToken (tok::ellipsis, EllipsisLoc );
2380
2368
2381
2369
return ER;
2382
2370
}
@@ -3407,8 +3395,7 @@ ParseStructDeclaration(ParsingDeclSpec &DS, FieldCallback &Fields) {
3407
3395
ParseDeclarator (DeclaratorInfo.D );
3408
3396
}
3409
3397
3410
- if (Tok.is (tok::colon)) {
3411
- ConsumeToken ();
3398
+ if (TryConsumeToken (tok::colon)) {
3412
3399
ExprResult Res (ParseConstantExpression ());
3413
3400
if (Res.isInvalid ())
3414
3401
SkipUntil (tok::semi, StopBeforeMatch);
@@ -3424,12 +3411,9 @@ ParseStructDeclaration(ParsingDeclSpec &DS, FieldCallback &Fields) {
3424
3411
3425
3412
// If we don't have a comma, it is either the end of the list (a ';')
3426
3413
// or an error, bail out.
3427
- if (Tok. isNot (tok::comma))
3414
+ if (! TryConsumeToken (tok::comma, CommaLoc ))
3428
3415
return ;
3429
3416
3430
- // Consume the comma.
3431
- CommaLoc = ConsumeToken ();
3432
-
3433
3417
FirstDeclarator = false ;
3434
3418
}
3435
3419
}
0 commit comments