@@ -1306,6 +1306,7 @@ class AnnotatingParser {
13061306 if (Tok->is (TT_TableGenMultiLineString))
13071307 return true ;
13081308 auto *Prev = Tok->getPreviousNonComment ();
1309+ auto *Next = Tok->getNextNonComment ();
13091310 switch (bool IsIf = false ; Tok->Tok .getKind ()) {
13101311 case tok::plus:
13111312 case tok::minus:
@@ -1435,10 +1436,10 @@ class AnnotatingParser {
14351436 if (Prev->isAccessSpecifierKeyword ())
14361437 Line.Type = LT_AccessModifier;
14371438 }
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)))) {
14421443 // This handles a special macro in ObjC code where selectors including
14431444 // the colon are passed as macro arguments.
14441445 Tok->setType (TT_ObjCMethodExpr);
@@ -1476,10 +1477,8 @@ class AnnotatingParser {
14761477 case tok::kw_for:
14771478 if (Style.isJavaScript ()) {
14781479 // 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)))
14811481 break ;
1482- }
14831482 // JS' for await ( ...
14841483 if (CurrentToken && CurrentToken->is (Keywords.kw_await ))
14851484 next ();
@@ -1690,9 +1689,9 @@ class AnnotatingParser {
16901689 CurrentToken->Previous ->setType (TT_OverloadedOperator);
16911690 break ;
16921691 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)) {
16961695 // Question marks before semicolons, colons, etc. indicate optional
16971696 // types (fields, parameters), e.g.
16981697 // function(x?: string, y?) {...}
@@ -1709,8 +1708,7 @@ class AnnotatingParser {
17091708 if (Style.isCSharp ()) {
17101709 // `Type?)`, `Type?>`, `Type? name;`, and `Type? name =` can only be
17111710 // 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) ||
17141712 Next->startsSequence (tok::identifier, tok::semi) ||
17151713 Next->startsSequence (tok::identifier, tok::equal))) {
17161714 Tok->setType (TT_CSharpNullable);
@@ -1723,10 +1721,8 @@ class AnnotatingParser {
17231721 // cond ? id : "B";
17241722 // cond ? cond2 ? "A" : "B" : "C";
17251723 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))) {
17301726 Tok->setType (TT_CSharpNullable);
17311727 break ;
17321728 }
@@ -1773,20 +1769,19 @@ class AnnotatingParser {
17731769 Keywords.kw___has_include_next )) {
17741770 parseHasInclude ();
17751771 }
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 ()) {
17841780 if (Tok->is (Keywords.kw_assert )) {
17851781 if (!parseTableGenValue ())
17861782 return false ;
17871783 } 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))) {
17901785 // The case NameValue appears.
17911786 if (!parseTableGenValue (true ))
17921787 return false ;
0 commit comments