@@ -1306,14 +1306,15 @@ class AnnotatingParser {
1306
1306
// Multi-line string itself is a single annotated token.
1307
1307
if (Tok->is (TT_TableGenMultiLineString))
1308
1308
return true ;
1309
+ auto *Prev = Tok->getPreviousNonComment ();
1309
1310
switch (bool IsIf = false ; Tok->Tok .getKind ()) {
1310
1311
case tok::plus:
1311
1312
case tok::minus:
1312
- if (!Tok-> getPreviousNonComment () && Line.MustBeDeclaration )
1313
+ if (!Prev && Line.MustBeDeclaration )
1313
1314
Tok->setType (TT_ObjCMethodSpecifier);
1314
1315
break ;
1315
1316
case tok::colon:
1316
- if (!Tok-> Previous )
1317
+ if (!Prev )
1317
1318
return false ;
1318
1319
// Goto labels and case labels are already identified in
1319
1320
// UnwrappedLineParser.
@@ -1346,8 +1347,7 @@ class AnnotatingParser {
1346
1347
} else if (Style .isVerilog () && Tok->isNot (TT_BinaryOperator)) {
1347
1348
// The distribution weight operators are labeled
1348
1349
// TT_BinaryOperator by the lexer.
1349
- if (Keywords.isVerilogEnd (*Tok->Previous ) ||
1350
- Keywords.isVerilogBegin (*Tok->Previous )) {
1350
+ if (Keywords.isVerilogEnd (*Prev) || Keywords.isVerilogBegin (*Prev)) {
1351
1351
Tok->setType (TT_VerilogBlockLabelColon);
1352
1352
} else if (Contexts.back ().ContextKind == tok::l_square) {
1353
1353
Tok->setType (TT_BitFieldColon);
@@ -1371,50 +1371,43 @@ class AnnotatingParser {
1371
1371
Tok->setType (TT_InlineASMColon);
1372
1372
} else if (Contexts.back ().ColonIsDictLiteral || Style .isProto ()) {
1373
1373
Tok->setType (TT_DictLiteral);
1374
- if (Style .isTextProto ()) {
1375
- if (FormatToken *Previous = Tok->getPreviousNonComment ())
1376
- Previous->setType (TT_SelectorName);
1377
- }
1374
+ if (Prev && Style .isTextProto ())
1375
+ Prev->setType (TT_SelectorName);
1378
1376
} else if (Contexts.back ().ColonIsObjCMethodExpr ||
1379
1377
Line.startsWith (TT_ObjCMethodSpecifier)) {
1380
1378
Tok->setType (TT_ObjCMethodExpr);
1381
- const FormatToken *BeforePrevious = Tok-> Previous ->Previous ;
1379
+ const auto *PrevPrev = Prev ->Previous ;
1382
1380
// Ensure we tag all identifiers in method declarations as
1383
1381
// TT_SelectorName.
1384
1382
bool UnknownIdentifierInMethodDeclaration =
1385
1383
Line.startsWith (TT_ObjCMethodSpecifier) &&
1386
- Tok-> Previous -> is (tok::identifier) && Tok-> Previous ->is (TT_Unknown);
1387
- if (!BeforePrevious ||
1384
+ Prev-> is (tok::identifier) && Prev ->is (TT_Unknown);
1385
+ if (!PrevPrev ||
1388
1386
// FIXME(bug 36976): ObjC return types shouldn't use TT_CastRParen.
1389
- !(BeforePrevious->is (TT_CastRParen) ||
1390
- (BeforePrevious->is (TT_ObjCMethodExpr) &&
1391
- BeforePrevious->is (tok::colon))) ||
1392
- BeforePrevious->is (tok::r_square) ||
1387
+ !(PrevPrev->is (TT_CastRParen) ||
1388
+ (PrevPrev->is (TT_ObjCMethodExpr) && PrevPrev->is (tok::colon))) ||
1389
+ PrevPrev->is (tok::r_square) ||
1393
1390
Contexts.back ().LongestObjCSelectorName == 0 ||
1394
1391
UnknownIdentifierInMethodDeclaration) {
1395
- Tok->Previous ->setType (TT_SelectorName);
1396
- if (!Contexts.back ().FirstObjCSelectorName ) {
1397
- Contexts.back ().FirstObjCSelectorName = Tok->Previous ;
1398
- } else if (Tok->Previous ->ColumnWidth >
1399
- Contexts.back ().LongestObjCSelectorName ) {
1400
- Contexts.back ().LongestObjCSelectorName =
1401
- Tok->Previous ->ColumnWidth ;
1402
- }
1403
- Tok->Previous ->ParameterIndex =
1392
+ Prev->setType (TT_SelectorName);
1393
+ if (!Contexts.back ().FirstObjCSelectorName )
1394
+ Contexts.back ().FirstObjCSelectorName = Prev;
1395
+ else if (Prev->ColumnWidth > Contexts.back ().LongestObjCSelectorName )
1396
+ Contexts.back ().LongestObjCSelectorName = Prev->ColumnWidth ;
1397
+ Prev->ParameterIndex =
1404
1398
Contexts.back ().FirstObjCSelectorName ->ObjCSelectorNameParts ;
1405
1399
++Contexts.back ().FirstObjCSelectorName ->ObjCSelectorNameParts ;
1406
1400
}
1407
1401
} else if (Contexts.back ().ColonIsForRangeExpr ) {
1408
1402
Tok->setType (TT_RangeBasedForLoopColon);
1409
- for (auto *Prev = Tok-> Previous ;
1410
- Prev && !Prev ->isOneOf (tok::semi, tok::l_paren);
1411
- Prev = Prev ->Previous ) {
1412
- if (Prev ->isPointerOrReference ())
1413
- Prev ->setFinalizedType (TT_PointerOrReference);
1403
+ for (auto *Token = Prev ;
1404
+ Token && !Token ->isOneOf (tok::semi, tok::l_paren);
1405
+ Token = Token ->Previous ) {
1406
+ if (Token ->isPointerOrReference ())
1407
+ Token ->setFinalizedType (TT_PointerOrReference);
1414
1408
}
1415
1409
} else if (Contexts.back ().ContextType == Context::C11GenericSelection) {
1416
1410
Tok->setType (TT_GenericSelectionColon);
1417
- auto *Prev = Tok->getPreviousNonComment ();
1418
1411
assert (Prev);
1419
1412
if (Prev->isPointerOrReference ())
1420
1413
Prev->setFinalizedType (TT_PointerOrReference);
@@ -1424,7 +1417,6 @@ class AnnotatingParser {
1424
1417
!Line.getFirstNonComment ()->isOneOf (tok::kw_enum, tok::kw_case,
1425
1418
tok::kw_default) &&
1426
1419
!Line.startsWith (tok::kw_typedef, tok::kw_enum)) {
1427
- FormatToken *Prev = Tok->getPreviousNonComment ();
1428
1420
if (!Prev)
1429
1421
break ;
1430
1422
if (Prev->isOneOf (tok::r_paren, tok::kw_noexcept) ||
@@ -1442,7 +1434,7 @@ class AnnotatingParser {
1442
1434
if (Prev->isAccessSpecifierKeyword ())
1443
1435
Line.Type = LT_AccessModifier;
1444
1436
}
1445
- } else if (canBeObjCSelectorComponent (*Tok-> Previous ) && Tok->Next &&
1437
+ } else if (canBeObjCSelectorComponent (*Prev ) && Tok->Next &&
1446
1438
(Tok->Next ->isOneOf (tok::r_paren, tok::comma) ||
1447
1439
(canBeObjCSelectorComponent (*Tok->Next ) && Tok->Next ->Next &&
1448
1440
Tok->Next ->Next ->is (tok::colon)))) {
@@ -1483,7 +1475,7 @@ class AnnotatingParser {
1483
1475
case tok::kw_for:
1484
1476
if (Style .isJavaScript ()) {
1485
1477
// x.for and {for: ...}
1486
- if ((Tok-> Previous && Tok-> Previous ->is (tok::period)) ||
1478
+ if ((Prev && Prev ->is (tok::period)) ||
1487
1479
(Tok->Next && Tok->Next ->is (tok::colon))) {
1488
1480
break ;
1489
1481
}
@@ -1505,11 +1497,10 @@ class AnnotatingParser {
1505
1497
// marks the first l_paren as a OverloadedOperatorLParen. Here, we make
1506
1498
// the first two parens OverloadedOperators and the second l_paren an
1507
1499
// OverloadedOperatorLParen.
1508
- if (Tok->Previous && Tok->Previous ->is (tok::r_paren) &&
1509
- Tok->Previous ->MatchingParen &&
1510
- Tok->Previous ->MatchingParen ->is (TT_OverloadedOperatorLParen)) {
1511
- Tok->Previous ->setType (TT_OverloadedOperator);
1512
- Tok->Previous ->MatchingParen ->setType (TT_OverloadedOperator);
1500
+ if (Prev && Prev->is (tok::r_paren) && Prev->MatchingParen &&
1501
+ Prev->MatchingParen ->is (TT_OverloadedOperatorLParen)) {
1502
+ Prev->setType (TT_OverloadedOperator);
1503
+ Prev->MatchingParen ->setType (TT_OverloadedOperator);
1513
1504
Tok->setType (TT_OverloadedOperatorLParen);
1514
1505
}
1515
1506
@@ -1520,7 +1511,6 @@ class AnnotatingParser {
1520
1511
// function is only responsible for the definition, not the
1521
1512
// instantiation.
1522
1513
auto IsInstancePort = [&]() {
1523
- const FormatToken *Prev = Tok->getPreviousNonComment ();
1524
1514
const FormatToken *PrevPrev;
1525
1515
// In the following example all 4 left parentheses will be treated as
1526
1516
// 'TT_VerilogInstancePortLParen'.
@@ -1566,11 +1556,10 @@ class AnnotatingParser {
1566
1556
!Contexts.back ().IsExpression && !Line.startsWith (TT_ObjCProperty) &&
1567
1557
!Line.startsWith (tok::l_paren) &&
1568
1558
!Tok->isOneOf (TT_TypeDeclarationParen, TT_RequiresExpressionLParen)) {
1569
- if (const auto *Previous = Tok->Previous ;
1570
- !Previous ||
1571
- (!Previous->isAttribute () &&
1572
- !Previous->isOneOf (TT_RequiresClause, TT_LeadingJavaAnnotation,
1573
- TT_BinaryOperator))) {
1559
+ if (!Prev ||
1560
+ (!Prev->isAttribute () &&
1561
+ !Prev->isOneOf (TT_RequiresClause, TT_LeadingJavaAnnotation,
1562
+ TT_BinaryOperator))) {
1574
1563
Line.MightBeFunctionDecl = true ;
1575
1564
Tok->MightBeFunctionDeclParen = true ;
1576
1565
}
@@ -1587,9 +1576,8 @@ class AnnotatingParser {
1587
1576
if (Tok->is (TT_RequiresExpressionLBrace))
1588
1577
Line.Type = LT_RequiresExpression;
1589
1578
} else if (Style .isTextProto ()) {
1590
- FormatToken *Previous = Tok->getPreviousNonComment ();
1591
- if (Previous && Previous->isNot (TT_DictLiteral))
1592
- Previous->setType (TT_SelectorName);
1579
+ if (Prev && Prev->isNot (TT_DictLiteral))
1580
+ Prev->setType (TT_SelectorName);
1593
1581
}
1594
1582
Scopes.push_back (getScopeType (*Tok));
1595
1583
if (!parseBrace ())
@@ -1604,12 +1592,11 @@ class AnnotatingParser {
1604
1592
// msg: < item: data >
1605
1593
// In TT_TextProto, map<key, value> does not occur.
1606
1594
if (Style .isTextProto () ||
1607
- (Style .Language == FormatStyle::LK_Proto && Tok-> Previous &&
1608
- Tok-> Previous ->isOneOf (TT_SelectorName, TT_DictLiteral))) {
1595
+ (Style .Language == FormatStyle::LK_Proto && Prev &&
1596
+ Prev ->isOneOf (TT_SelectorName, TT_DictLiteral))) {
1609
1597
Tok->setType (TT_DictLiteral);
1610
- FormatToken *Previous = Tok->getPreviousNonComment ();
1611
- if (Previous && Previous->isNot (TT_DictLiteral))
1612
- Previous->setType (TT_SelectorName);
1598
+ if (Prev && Prev->isNot (TT_DictLiteral))
1599
+ Prev->setType (TT_SelectorName);
1613
1600
}
1614
1601
if (Style .isTableGen ())
1615
1602
Tok->setType (TT_TemplateOpener);
@@ -1628,13 +1615,13 @@ class AnnotatingParser {
1628
1615
if (!Scopes.empty ())
1629
1616
Scopes.pop_back ();
1630
1617
// Lines can start with '}'.
1631
- if (Tok-> Previous )
1618
+ if (Prev )
1632
1619
return false ;
1633
1620
break ;
1634
1621
case tok::greater:
1635
1622
if (!Style .isTextProto () && Tok->is (TT_Unknown))
1636
1623
Tok->setType (TT_BinaryOperator);
1637
- if (Tok-> Previous && Tok-> Previous ->is (TT_TemplateCloser))
1624
+ if (Prev && Prev ->is (TT_TemplateCloser))
1638
1625
Tok->SpacesRequiredBefore = 1 ;
1639
1626
break ;
1640
1627
case tok::kw_operator:
@@ -1789,7 +1776,7 @@ class AnnotatingParser {
1789
1776
Tok->Next ->isNot (tok::l_paren)) {
1790
1777
Tok->setType (TT_CSharpGenericTypeConstraint);
1791
1778
parseCSharpGenericTypeConstraint ();
1792
- if (!Tok-> getPreviousNonComment () )
1779
+ if (!Prev )
1793
1780
Line.IsContinuation = true ;
1794
1781
}
1795
1782
if (Style .isTableGen ()) {
@@ -1806,10 +1793,8 @@ class AnnotatingParser {
1806
1793
}
1807
1794
break ;
1808
1795
case tok::arrow:
1809
- if (Tok->isNot (TT_LambdaArrow) && Tok->Previous &&
1810
- Tok->Previous ->is (tok::kw_noexcept)) {
1796
+ if (Tok->isNot (TT_LambdaArrow) && Prev && Prev->is (tok::kw_noexcept))
1811
1797
Tok->setType (TT_TrailingReturnArrow);
1812
- }
1813
1798
break ;
1814
1799
case tok::equal:
1815
1800
// In TableGen, there must be a value after "=";
0 commit comments