@@ -1306,6 +1306,7 @@ class AnnotatingParser {
1306
1306
if (Tok->is (TT_TableGenMultiLineString))
1307
1307
return true ;
1308
1308
auto *Prev = Tok->getPreviousNonComment ();
1309
+ auto *Next = Tok->getNextNonComment ();
1309
1310
switch (bool IsIf = false ; Tok->Tok .getKind ()) {
1310
1311
case tok::plus:
1311
1312
case tok::minus:
@@ -1435,10 +1436,10 @@ class AnnotatingParser {
1435
1436
if (Prev->isAccessSpecifierKeyword ())
1436
1437
Line.Type = LT_AccessModifier;
1437
1438
}
1438
- } else if (canBeObjCSelectorComponent (*Prev) && Tok-> Next &&
1439
- (Tok-> Next ->isOneOf (tok::r_paren, tok::comma) ||
1440
- (canBeObjCSelectorComponent (*Tok-> Next ) && Tok-> Next ->Next &&
1441
- Tok-> Next ->Next ->is (tok::colon)))) {
1439
+ } else if (canBeObjCSelectorComponent (*Prev) && Next &&
1440
+ (Next->isOneOf (tok::r_paren, tok::comma) ||
1441
+ (canBeObjCSelectorComponent (*Next) && Next->Next &&
1442
+ Next->Next ->is (tok::colon)))) {
1442
1443
// This handles a special macro in ObjC code where selectors including
1443
1444
// the colon are passed as macro arguments.
1444
1445
Tok->setType (TT_ObjCMethodExpr);
@@ -1476,10 +1477,8 @@ class AnnotatingParser {
1476
1477
case tok::kw_for:
1477
1478
if (Style.isJavaScript ()) {
1478
1479
// x.for and {for: ...}
1479
- if ((Prev && Prev->is (tok::period)) ||
1480
- (Tok->Next && Tok->Next ->is (tok::colon))) {
1480
+ if ((Prev && Prev->is (tok::period)) || (Next && Next->is (tok::colon)))
1481
1481
break ;
1482
- }
1483
1482
// JS' for await ( ...
1484
1483
if (CurrentToken && CurrentToken->is (Keywords.kw_await ))
1485
1484
next ();
@@ -1690,9 +1689,9 @@ class AnnotatingParser {
1690
1689
CurrentToken->Previous ->setType (TT_OverloadedOperator);
1691
1690
break ;
1692
1691
case tok::question:
1693
- if (Style.isJavaScript () && Tok-> Next &&
1694
- Tok-> Next ->isOneOf (tok::semi, tok::comma, tok::colon, tok::r_paren,
1695
- tok::r_brace, tok::r_square)) {
1692
+ if (Style.isJavaScript () && Next &&
1693
+ Next->isOneOf (tok::semi, tok::comma, tok::colon, tok::r_paren,
1694
+ tok::r_brace, tok::r_square)) {
1696
1695
// Question marks before semicolons, colons, etc. indicate optional
1697
1696
// types (fields, parameters), e.g.
1698
1697
// function(x?: string, y?) {...}
@@ -1709,8 +1708,7 @@ class AnnotatingParser {
1709
1708
if (Style.isCSharp ()) {
1710
1709
// `Type?)`, `Type?>`, `Type? name;`, and `Type? name =` can only be
1711
1710
// nullable types.
1712
- if (const auto *Next = Tok->getNextNonComment ();
1713
- Next && (Next->isOneOf (tok::r_paren, tok::greater) ||
1711
+ if (Next && (Next->isOneOf (tok::r_paren, tok::greater) ||
1714
1712
Next->startsSequence (tok::identifier, tok::semi) ||
1715
1713
Next->startsSequence (tok::identifier, tok::equal))) {
1716
1714
Tok->setType (TT_CSharpNullable);
@@ -1723,10 +1721,8 @@ class AnnotatingParser {
1723
1721
// cond ? id : "B";
1724
1722
// cond ? cond2 ? "A" : "B" : "C";
1725
1723
if (!Contexts.back ().IsExpression && Line.MustBeDeclaration &&
1726
- (!Tok->Next ||
1727
- !Tok->Next ->isOneOf (tok::identifier, tok::string_literal) ||
1728
- !Tok->Next ->Next ||
1729
- !Tok->Next ->Next ->isOneOf (tok::colon, tok::question))) {
1724
+ (!Next || !Next->isOneOf (tok::identifier, tok::string_literal) ||
1725
+ !Next->Next || !Next->Next ->isOneOf (tok::colon, tok::question))) {
1730
1726
Tok->setType (TT_CSharpNullable);
1731
1727
break ;
1732
1728
}
@@ -1773,20 +1769,19 @@ class AnnotatingParser {
1773
1769
Keywords.kw___has_include_next )) {
1774
1770
parseHasInclude ();
1775
1771
}
1776
- if (Style.isCSharp () && Tok-> is (Keywords. kw_where ) && Tok-> Next &&
1777
- Tok->Next ->isNot (tok::l_paren)) {
1778
- Tok->setType (TT_CSharpGenericTypeConstraint);
1779
- parseCSharpGenericTypeConstraint ();
1780
- if (!Prev)
1781
- Line.IsContinuation = true ;
1782
- }
1783
- if (Style.isTableGen ()) {
1772
+ if (Style.isCSharp ()) {
1773
+ if ( Tok->is (Keywords. kw_where ) && Next && Next->isNot (tok::l_paren)) {
1774
+ Tok->setType (TT_CSharpGenericTypeConstraint);
1775
+ parseCSharpGenericTypeConstraint ();
1776
+ if (!Prev)
1777
+ Line.IsContinuation = true ;
1778
+ }
1779
+ } else if (Style.isTableGen ()) {
1784
1780
if (Tok->is (Keywords.kw_assert )) {
1785
1781
if (!parseTableGenValue ())
1786
1782
return false ;
1787
1783
} else if (Tok->isOneOf (Keywords.kw_def , Keywords.kw_defm ) &&
1788
- (!Tok->Next ||
1789
- !Tok->Next ->isOneOf (tok::colon, tok::l_brace))) {
1784
+ (!Next || !Next->isOneOf (tok::colon, tok::l_brace))) {
1790
1785
// The case NameValue appears.
1791
1786
if (!parseTableGenValue (true ))
1792
1787
return false ;
0 commit comments