@@ -424,7 +424,7 @@ namespace {
424
424
425
425
void printRec (Decl *D) { D->dump (OS, Indent + 2 ); }
426
426
void printRec (Expr *E) { E->print (OS, Indent + 2 ); }
427
- void printRec (Stmt *S) { S->print (OS, Indent + 2 ); }
427
+ void printRec (Stmt *S, const ASTContext& Ctx ) { S->print (OS, &Ctx , Indent + 2 ); }
428
428
void printRec (TypeRepr *T);
429
429
void printRec (const Pattern *P) {
430
430
PrintPattern (OS, Indent+2 ).visit (const_cast <Pattern *>(P));
@@ -552,7 +552,7 @@ namespace {
552
552
553
553
void printRec (Decl *D) { PrintDecl (OS, Indent + 2 ).visit (D); }
554
554
void printRec (Expr *E) { E->print (OS, Indent+2 ); }
555
- void printRec (Stmt *S) { S->print (OS, Indent+2 ); }
555
+ void printRec (Stmt *S, const ASTContext& Ctx ) { S->print (OS, &Ctx , Indent+2 ); }
556
556
void printRec (Pattern *P) { PrintPattern (OS, Indent+2 ).visit (P); }
557
557
void printRec (TypeRepr *T);
558
558
@@ -1037,7 +1037,7 @@ namespace {
1037
1037
}
1038
1038
if (auto Body = D->getBody (/* canSynthesize=*/ false )) {
1039
1039
OS << ' \n ' ;
1040
- printRec (Body);
1040
+ printRec (Body, D-> getASTContext () );
1041
1041
}
1042
1042
}
1043
1043
@@ -1084,12 +1084,12 @@ namespace {
1084
1084
printCommon (TLCD, " top_level_code_decl" );
1085
1085
if (TLCD->getBody ()) {
1086
1086
OS << " \n " ;
1087
- printRec (TLCD->getBody ());
1087
+ printRec (TLCD->getBody (), static_cast <Decl *>(TLCD)-> getASTContext () );
1088
1088
}
1089
1089
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1090
1090
}
1091
1091
1092
- void printASTNodes (const ArrayRef<ASTNode> &Elements, StringRef Name) {
1092
+ void printASTNodes (const ArrayRef<ASTNode> &Elements, const ASTContext &Ctx, StringRef Name) {
1093
1093
OS.indent (Indent);
1094
1094
PrintWithColorRAII (OS, ParenthesisColor) << " (" ;
1095
1095
PrintWithColorRAII (OS, ASTNodeColor) << Name;
@@ -1098,7 +1098,7 @@ namespace {
1098
1098
if (auto *SubExpr = Elt.dyn_cast <Expr*>())
1099
1099
printRec (SubExpr);
1100
1100
else if (auto *SubStmt = Elt.dyn_cast <Stmt*>())
1101
- printRec (SubStmt);
1101
+ printRec (SubStmt, Ctx );
1102
1102
else
1103
1103
printRec (Elt.get <Decl*>());
1104
1104
}
@@ -1121,7 +1121,7 @@ namespace {
1121
1121
1122
1122
OS << ' \n ' ;
1123
1123
Indent += 2 ;
1124
- printASTNodes (Clause.Elements , " elements" );
1124
+ printASTNodes (Clause.Elements , ICD-> getASTContext (), " elements" );
1125
1125
Indent -= 2 ;
1126
1126
}
1127
1127
@@ -1368,9 +1368,11 @@ namespace {
1368
1368
class PrintStmt : public StmtVisitor <PrintStmt> {
1369
1369
public:
1370
1370
raw_ostream &OS;
1371
+ const ASTContext *Ctx;
1371
1372
unsigned Indent;
1372
1373
1373
- PrintStmt (raw_ostream &os, unsigned indent) : OS(os), Indent(indent) {
1374
+ PrintStmt (raw_ostream &os, const ASTContext *ctx, unsigned indent)
1375
+ : OS(os), Ctx(ctx), Indent(indent) {
1374
1376
}
1375
1377
1376
1378
void printRec (Stmt *S) {
@@ -1437,20 +1439,28 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1437
1439
if (S->isImplicit ())
1438
1440
OS << " implicit" ;
1439
1441
1442
+ if (Ctx) {
1443
+ auto R = S->getSourceRange ();
1444
+ if (R.isValid ()) {
1445
+ PrintWithColorRAII (OS, RangeColor) << " range=" ;
1446
+ R.print (PrintWithColorRAII (OS, RangeColor).getOS (),
1447
+ Ctx->SourceMgr , /* PrintText=*/ false );
1448
+ }
1449
+ }
1450
+
1440
1451
if (S->TrailingSemiLoc .isValid ())
1441
1452
OS << " trailing_semi" ;
1442
1453
1443
1454
return OS;
1444
1455
}
1445
1456
1446
1457
void visitBraceStmt (BraceStmt *S) {
1447
- printASTNodes (S->getElements (), " brace_stmt" );
1458
+ printCommon (S, " brace_stmt" );
1459
+ printASTNodes (S->getElements ());
1460
+ PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1448
1461
}
1449
1462
1450
- void printASTNodes (const ArrayRef<ASTNode> &Elements, StringRef Name) {
1451
- OS.indent (Indent);
1452
- PrintWithColorRAII (OS, ParenthesisColor) << " (" ;
1453
- PrintWithColorRAII (OS, ASTNodeColor) << Name;
1463
+ void printASTNodes (const ArrayRef<ASTNode> &Elements) {
1454
1464
for (auto Elt : Elements) {
1455
1465
OS << ' \n ' ;
1456
1466
if (auto *SubExpr = Elt.dyn_cast <Expr*>())
@@ -1460,7 +1470,6 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1460
1470
else
1461
1471
printRec (Elt.get <Decl*>());
1462
1472
}
1463
- PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
1464
1473
}
1465
1474
1466
1475
void visitReturnStmt (ReturnStmt *S) {
@@ -1644,8 +1653,8 @@ void Stmt::dump() const {
1644
1653
llvm::errs () << ' \n ' ;
1645
1654
}
1646
1655
1647
- void Stmt::print (raw_ostream &OS, unsigned Indent) const {
1648
- PrintStmt (OS, Indent).visit (const_cast <Stmt*>(this ));
1656
+ void Stmt::print (raw_ostream &OS, const ASTContext *Ctx, unsigned Indent) const {
1657
+ PrintStmt (OS, Ctx, Indent).visit (const_cast <Stmt*>(this ));
1649
1658
}
1650
1659
1651
1660
// ===----------------------------------------------------------------------===//
@@ -1690,7 +1699,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
1690
1699
// / FIXME: This should use ExprWalker to print children.
1691
1700
1692
1701
void printRec (Decl *D) { D->dump (OS, Indent + 2 ); }
1693
- void printRec (Stmt *S) { S->print (OS, Indent + 2 ); }
1702
+ void printRec (Stmt *S, const ASTContext& Ctx ) { S->print (OS, &Ctx , Indent + 2 ); }
1694
1703
void printRec (const Pattern *P) {
1695
1704
PrintPattern (OS, Indent+2 ).visit (const_cast <Pattern *>(P));
1696
1705
}
@@ -2300,7 +2309,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
2300
2309
if (E->hasSingleExpressionBody ()) {
2301
2310
printRec (E->getSingleExpressionBody ());
2302
2311
} else {
2303
- printRec (E->getBody ());
2312
+ printRec (E->getBody (), E-> getASTContext () );
2304
2313
}
2305
2314
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
2306
2315
}
0 commit comments