@@ -409,6 +409,9 @@ namespace {
409
409
410
410
if (D->isImplicit ())
411
411
PrintWithColorRAII (OS, DeclModifierColor) << " implicit" ;
412
+
413
+ if (D->TrailingSemiLoc .isValid ())
414
+ PrintWithColorRAII (OS, DeclModifierColor) << " trailing_semi" ;
412
415
}
413
416
414
417
void printInherited (ArrayRef<TypeLoc> Inherited) {
@@ -1297,6 +1300,20 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1297
1300
}
1298
1301
}
1299
1302
1303
+ raw_ostream &printCommon (Stmt *S, const char *Name) {
1304
+ OS.indent (Indent);
1305
+ PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1306
+ PrintWithColorRAII (OS, StmtColor) << Name;
1307
+
1308
+ if (S->isImplicit ())
1309
+ OS << " implicit" ;
1310
+
1311
+ if (S->TrailingSemiLoc .isValid ())
1312
+ OS << " trailing_semi" ;
1313
+
1314
+ return OS;
1315
+ }
1316
+
1300
1317
void visitBraceStmt (BraceStmt *S) {
1301
1318
printASTNodes (S->getElements (), " brace_stmt" );
1302
1319
}
@@ -1318,9 +1335,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1318
1335
}
1319
1336
1320
1337
void visitReturnStmt (ReturnStmt *S) {
1321
- OS.indent (Indent);
1322
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1323
- PrintWithColorRAII (OS, StmtColor) << " return_stmt" ;
1338
+ printCommon (S, " return_stmt" );
1324
1339
if (S->hasResult ()) {
1325
1340
OS << ' \n ' ;
1326
1341
printRec (S->getResult ());
@@ -1329,19 +1344,15 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1329
1344
}
1330
1345
1331
1346
void visitDeferStmt (DeferStmt *S) {
1332
- OS.indent (Indent);
1333
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1334
- PrintWithColorRAII (OS, StmtColor) << " defer_stmt\n " ;
1347
+ printCommon (S, " defer_stmt" ) << ' \n ' ;
1335
1348
printRec (S->getTempDecl ());
1336
1349
OS << ' \n ' ;
1337
1350
printRec (S->getCallExpr ());
1338
1351
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1339
1352
}
1340
1353
1341
1354
void visitIfStmt (IfStmt *S) {
1342
- OS.indent (Indent);
1343
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1344
- PrintWithColorRAII (OS, StmtColor) << " if_stmt\n " ;
1355
+ printCommon (S, " if_stmt" ) << ' \n ' ;
1345
1356
for (auto elt : S->getCond ())
1346
1357
printRec (elt);
1347
1358
OS << ' \n ' ;
@@ -1354,9 +1365,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1354
1365
}
1355
1366
1356
1367
void visitGuardStmt (GuardStmt *S) {
1357
- OS.indent (Indent);
1358
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1359
- PrintWithColorRAII (OS, StmtColor) << " guard_stmt\n " ;
1368
+ printCommon (S, " guard_stmt" ) << ' \n ' ;
1360
1369
for (auto elt : S->getCond ())
1361
1370
printRec (elt);
1362
1371
OS << ' \n ' ;
@@ -1365,11 +1374,10 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1365
1374
}
1366
1375
1367
1376
void visitIfConfigStmt (IfConfigStmt *S) {
1368
- OS.indent (Indent);
1369
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1370
- PrintWithColorRAII (OS, StmtColor) << " #if_stmt\n " ;
1377
+ printCommon (S, " #if_stmt" );
1371
1378
Indent += 2 ;
1372
1379
for (auto &Clause : S->getClauses ()) {
1380
+ OS << ' \n ' ;
1373
1381
OS.indent (Indent);
1374
1382
if (Clause.Cond ) {
1375
1383
PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
@@ -1390,17 +1398,13 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1390
1398
}
1391
1399
1392
1400
void visitDoStmt (DoStmt *S) {
1393
- OS.indent (Indent);
1394
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1395
- PrintWithColorRAII (OS, StmtColor) << " do_stmt\n " ;
1401
+ printCommon (S, " do_stmt" ) << ' \n ' ;
1396
1402
printRec (S->getBody ());
1397
1403
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1398
1404
}
1399
1405
1400
1406
void visitWhileStmt (WhileStmt *S) {
1401
- OS.indent (Indent);
1402
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1403
- PrintWithColorRAII (OS, StmtColor) << " while_stmt\n " ;
1407
+ printCommon (S, " while_stmt" ) << ' \n ' ;
1404
1408
for (auto elt : S->getCond ())
1405
1409
printRec (elt);
1406
1410
OS << ' \n ' ;
@@ -1409,18 +1413,14 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1409
1413
}
1410
1414
1411
1415
void visitRepeatWhileStmt (RepeatWhileStmt *S) {
1412
- OS.indent (Indent);
1413
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1414
- PrintWithColorRAII (OS, StmtColor) << " do_while_stmt\n " ;
1416
+ printCommon (S, " repeat_while_stmt" ) << ' \n ' ;
1415
1417
printRec (S->getBody ());
1416
1418
OS << ' \n ' ;
1417
1419
printRec (S->getCond ());
1418
1420
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1419
1421
}
1420
1422
void visitForStmt (ForStmt *S) {
1421
- OS.indent (Indent);
1422
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1423
- PrintWithColorRAII (OS, StmtColor) << " for_stmt\n " ;
1423
+ printCommon (S, " for_stmt" ) << ' \n ' ;
1424
1424
if (!S->getInitializerVarDecls ().empty ()) {
1425
1425
for (auto D : S->getInitializerVarDecls ()) {
1426
1426
printRec (D);
@@ -1449,9 +1449,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1449
1449
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1450
1450
}
1451
1451
void visitForEachStmt (ForEachStmt *S) {
1452
- OS.indent (Indent);
1453
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1454
- OS << " for_each_stmt\n " ;
1452
+ printCommon (S, " for_each_stmt" ) << ' \n ' ;
1455
1453
printRec (S->getPattern ());
1456
1454
OS << ' \n ' ;
1457
1455
if (S->getWhere ()) {
@@ -1477,27 +1475,19 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1477
1475
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1478
1476
}
1479
1477
void visitBreakStmt (BreakStmt *S) {
1480
- OS.indent (Indent);
1481
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1482
- PrintWithColorRAII (OS, StmtColor) << " break_stmt" ;
1478
+ printCommon (S, " break_stmt" );
1483
1479
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1484
1480
}
1485
1481
void visitContinueStmt (ContinueStmt *S) {
1486
- OS.indent (Indent);
1487
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1488
- PrintWithColorRAII (OS, StmtColor) << " continue_stmt" ;
1482
+ printCommon (S, " continue_stmt" );
1489
1483
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1490
1484
}
1491
1485
void visitFallthroughStmt (FallthroughStmt *S) {
1492
- OS.indent (Indent);
1493
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1494
- PrintWithColorRAII (OS, StmtColor) << " fallthrough_stmt" ;
1486
+ printCommon (S, " fallthrough_stmt" );
1495
1487
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1496
1488
}
1497
1489
void visitSwitchStmt (SwitchStmt *S) {
1498
- OS.indent (Indent);
1499
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1500
- PrintWithColorRAII (OS, StmtColor) << " switch_stmt\n " ;
1490
+ printCommon (S, " switch_stmt" ) << ' \n ' ;
1501
1491
printRec (S->getSubjectExpr ());
1502
1492
for (CaseStmt *C : S->getCases ()) {
1503
1493
OS << ' \n ' ;
@@ -1506,9 +1496,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1506
1496
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1507
1497
}
1508
1498
void visitCaseStmt (CaseStmt *S) {
1509
- OS.indent (Indent);
1510
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1511
- PrintWithColorRAII (OS, StmtColor) << " case_stmt" ;
1499
+ printCommon (S, " case_stmt" );
1512
1500
for (const auto &LabelItem : S->getCaseLabelItems ()) {
1513
1501
OS << ' \n ' ;
1514
1502
OS.indent (Indent + 2 );
@@ -1529,24 +1517,18 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1529
1517
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1530
1518
}
1531
1519
void visitFailStmt (FailStmt *S) {
1532
- OS.indent (Indent);
1533
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1534
- PrintWithColorRAII (OS, StmtColor) << " fail_stmt" ;
1520
+ printCommon (S, " fail_stmt" );
1535
1521
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1536
1522
}
1537
1523
1538
1524
void visitThrowStmt (ThrowStmt *S) {
1539
- OS.indent (Indent);
1540
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1541
- PrintWithColorRAII (OS, StmtColor) << " throw_stmt\n " ;
1525
+ printCommon (S, " throw_stmt" ) << ' \n ' ;
1542
1526
printRec (S->getSubExpr ());
1543
1527
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1544
1528
}
1545
1529
1546
1530
void visitDoCatchStmt (DoCatchStmt *S) {
1547
- OS.indent (Indent);
1548
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1549
- PrintWithColorRAII (OS, StmtColor) << " do_catch_stmt\n " ;
1531
+ printCommon (S, " do_catch_stmt" ) << ' \n ' ;
1550
1532
printRec (S->getBody ());
1551
1533
OS << ' \n ' ;
1552
1534
Indent += 2 ;
@@ -1560,9 +1542,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1560
1542
}
1561
1543
}
1562
1544
void visitCatchStmt (CatchStmt *clause) {
1563
- OS.indent (Indent);
1564
- PrintWithColorRAII (OS, ParenthesisColor) << ' (' ;
1565
- PrintWithColorRAII (OS, StmtColor) << " catch\n " ;
1545
+ printCommon (clause, " catch" ) << ' \n ' ;
1566
1546
printRec (clause->getErrorPattern ());
1567
1547
if (auto guard = clause->getGuardExpr ()) {
1568
1548
OS << ' \n ' ;
@@ -1670,6 +1650,9 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
1670
1650
}
1671
1651
}
1672
1652
1653
+ if (E->TrailingSemiLoc .isValid ())
1654
+ OS << " trailing_semi" ;
1655
+
1673
1656
return OS;
1674
1657
}
1675
1658
0 commit comments