@@ -480,6 +480,10 @@ bool UnwrappedLineParser::parseLevel(bool HasOpeningBrace,
480
480
unsigned StatementCount = 0 ;
481
481
bool SwitchLabelEncountered = false ;
482
482
do {
483
+ if (FormatTok->getType () == TT_AttributeMacro) {
484
+ nextToken ();
485
+ continue ;
486
+ }
483
487
tok::TokenKind kind = FormatTok->Tok .getKind ();
484
488
if (FormatTok->getType () == TT_MacroBlockBegin)
485
489
kind = tok::l_brace;
@@ -569,6 +573,8 @@ bool UnwrappedLineParser::parseLevel(bool HasOpeningBrace,
569
573
parseCSharpAttribute ();
570
574
break ;
571
575
}
576
+ if (handleCppAttributes ())
577
+ break ;
572
578
LLVM_FALLTHROUGH;
573
579
default :
574
580
ParseDefault ();
@@ -1390,9 +1396,11 @@ void UnwrappedLineParser::parseStructuralElement(IfStmtKind *IfKind,
1390
1396
// e.g. "default void f() {}" in a Java interface.
1391
1397
break ;
1392
1398
case tok::kw_case:
1393
- if (Style.isJavaScript () && Line->MustBeDeclaration )
1399
+ if (Style.isJavaScript () && Line->MustBeDeclaration ) {
1394
1400
// 'case: string' field declaration.
1401
+ nextToken ();
1395
1402
break ;
1403
+ }
1396
1404
parseCaseLabel ();
1397
1405
return ;
1398
1406
case tok::kw_try:
@@ -1813,6 +1821,12 @@ void UnwrappedLineParser::parseStructuralElement(IfStmtKind *IfKind,
1813
1821
case tok::kw_new:
1814
1822
parseNew ();
1815
1823
break ;
1824
+ case tok::kw_case:
1825
+ if (Style.isJavaScript () && Line->MustBeDeclaration )
1826
+ // 'case: string' field declaration.
1827
+ break ;
1828
+ parseCaseLabel ();
1829
+ break ;
1816
1830
default :
1817
1831
nextToken ();
1818
1832
break ;
@@ -2376,17 +2390,24 @@ static void markOptionalBraces(FormatToken *LeftBrace) {
2376
2390
RightBrace->Optional = true ;
2377
2391
}
2378
2392
2393
+ void UnwrappedLineParser::handleAttributes () {
2394
+ // Handle AttributeMacro, e.g. `if (x) UNLIKELY`.
2395
+ if (FormatTok->is (TT_AttributeMacro))
2396
+ nextToken ();
2397
+ handleCppAttributes ();
2398
+ }
2399
+
2400
+ bool UnwrappedLineParser::handleCppAttributes () {
2401
+ // Handle [[likely]] / [[unlikely]] attributes.
2402
+ if (FormatTok->is (tok::l_square) && tryToParseSimpleAttribute ()) {
2403
+ parseSquare ();
2404
+ return true ;
2405
+ }
2406
+ return false ;
2407
+ }
2408
+
2379
2409
FormatToken *UnwrappedLineParser::parseIfThenElse (IfStmtKind *IfKind,
2380
2410
bool KeepBraces) {
2381
- auto HandleAttributes = [this ]() {
2382
- // Handle AttributeMacro, e.g. `if (x) UNLIKELY`.
2383
- if (FormatTok->is (TT_AttributeMacro))
2384
- nextToken ();
2385
- // Handle [[likely]] / [[unlikely]] attributes.
2386
- if (FormatTok->is (tok::l_square) && tryToParseSimpleAttribute ())
2387
- parseSquare ();
2388
- };
2389
-
2390
2411
assert (FormatTok->is (tok::kw_if) && " 'if' expected" );
2391
2412
nextToken ();
2392
2413
if (FormatTok->is (tok::exclaim))
@@ -2399,7 +2420,7 @@ FormatToken *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
2399
2420
if (FormatTok->is (tok::l_paren))
2400
2421
parseParens ();
2401
2422
}
2402
- HandleAttributes ();
2423
+ handleAttributes ();
2403
2424
2404
2425
bool NeedsUnwrappedLine = false ;
2405
2426
keepAncestorBraces ();
@@ -2436,7 +2457,7 @@ FormatToken *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
2436
2457
Kind = IfStmtKind::IfElse;
2437
2458
}
2438
2459
nextToken ();
2439
- HandleAttributes ();
2460
+ handleAttributes ();
2440
2461
if (FormatTok->is (tok::l_brace)) {
2441
2462
ElseLeftBrace = FormatTok;
2442
2463
CompoundStatementIndenter Indenter (this , Style, Line->Level );
0 commit comments