Skip to content

Commit 2d056fd

Browse files
authored
Merge pull request #16679 from apple/revert-16473-ast-dump-source-ranges
Revert "Include source ranges for statements, declarations, and parameter lists in the AST dump"
2 parents cb6c8f0 + f20586b commit 2d056fd

15 files changed

+97
-126
lines changed

include/swift/AST/Stmt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class alignas(8) Stmt {
128128
LLVM_ATTRIBUTE_DEPRECATED(
129129
void dump() const LLVM_ATTRIBUTE_USED,
130130
"only for use within the debugger");
131-
void print(raw_ostream &OS, const ASTContext *Ctx = nullptr, unsigned Indent = 0) const;
131+
void print(raw_ostream &OS, unsigned Indent = 0) const;
132132

133133
// Only allow allocation of Exprs using the allocator in ASTContext
134134
// or by doing a placement new.

lib/AST/ASTDumper.cpp

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ namespace {
425425

426426
void printRec(Decl *D) { D->dump(OS, Indent + 2); }
427427
void printRec(Expr *E) { E->print(OS, Indent + 2); }
428-
void printRec(Stmt *S, const ASTContext &Ctx) { S->print(OS, &Ctx, Indent + 2); }
428+
void printRec(Stmt *S) { S->print(OS, Indent + 2); }
429429
void printRec(TypeRepr *T);
430430
void printRec(const Pattern *P) {
431431
PrintPattern(OS, Indent+2).visit(const_cast<Pattern *>(P));
@@ -553,7 +553,7 @@ namespace {
553553

554554
void printRec(Decl *D) { PrintDecl(OS, Indent + 2).visit(D); }
555555
void printRec(Expr *E) { E->print(OS, Indent+2); }
556-
void printRec(Stmt *S, const ASTContext &Ctx) { S->print(OS, &Ctx, Indent+2); }
556+
void printRec(Stmt *S) { S->print(OS, Indent+2); }
557557
void printRec(Pattern *P) { PrintPattern(OS, Indent+2).visit(P); }
558558
void printRec(TypeRepr *T);
559559

@@ -575,13 +575,6 @@ namespace {
575575
if (D->isImplicit())
576576
PrintWithColorRAII(OS, DeclModifierColor) << " implicit";
577577

578-
auto R = D->getSourceRange();
579-
if (R.isValid()) {
580-
PrintWithColorRAII(OS, RangeColor) << " range=";
581-
R.print(PrintWithColorRAII(OS, RangeColor).getOS(),
582-
D->getASTContext().SourceMgr, /*PrintText=*/false);
583-
}
584-
585578
if (D->TrailingSemiLoc.isValid())
586579
PrintWithColorRAII(OS, DeclModifierColor) << " trailing_semi";
587580
}
@@ -991,7 +984,7 @@ namespace {
991984
PrintWithColorRAII(OS, ParenthesisColor) << ')';
992985
}
993986

994-
void printParameterList(const ParameterList *params, const ASTContext *ctx = nullptr) {
987+
void printParameterList(const ParameterList *params) {
995988
OS.indent(Indent);
996989
PrintWithColorRAII(OS, ParenthesisColor) << '(';
997990
PrintWithColorRAII(OS, ParameterColor) << "parameter_list";
@@ -1000,19 +993,6 @@ namespace {
1000993
OS << '\n';
1001994
printParameter(P);
1002995
}
1003-
1004-
if (!ctx && params->size() != 0 && params->get(0))
1005-
ctx = &params->get(0)->getASTContext();
1006-
1007-
if (ctx) {
1008-
auto R = params->getSourceRange();
1009-
if (R.isValid()) {
1010-
PrintWithColorRAII(OS, RangeColor) << " range=";
1011-
R.print(PrintWithColorRAII(OS, RangeColor).getOS(),
1012-
ctx->SourceMgr, /*PrintText=*/false);
1013-
}
1014-
}
1015-
1016996
PrintWithColorRAII(OS, ParenthesisColor) << ')';
1017997
Indent -= 2;
1018998
}
@@ -1021,7 +1001,7 @@ namespace {
10211001
for (auto pl : D->getParameterLists()) {
10221002
OS << '\n';
10231003
Indent += 2;
1024-
printParameterList(pl, &D->getASTContext());
1004+
printParameterList(pl);
10251005
Indent -= 2;
10261006
}
10271007
if (auto FD = dyn_cast<FuncDecl>(D)) {
@@ -1038,7 +1018,7 @@ namespace {
10381018
}
10391019
if (auto Body = D->getBody(/*canSynthesize=*/false)) {
10401020
OS << '\n';
1041-
printRec(Body, D->getASTContext());
1021+
printRec(Body);
10421022
}
10431023
}
10441024

@@ -1085,12 +1065,12 @@ namespace {
10851065
printCommon(TLCD, "top_level_code_decl");
10861066
if (TLCD->getBody()) {
10871067
OS << "\n";
1088-
printRec(TLCD->getBody(), static_cast<Decl *>(TLCD)->getASTContext());
1068+
printRec(TLCD->getBody());
10891069
}
10901070
PrintWithColorRAII(OS, ParenthesisColor) << ')';
10911071
}
10921072

1093-
void printASTNodes(const ArrayRef<ASTNode> &Elements, const ASTContext &Ctx, StringRef Name) {
1073+
void printASTNodes(const ArrayRef<ASTNode> &Elements, StringRef Name) {
10941074
OS.indent(Indent);
10951075
PrintWithColorRAII(OS, ParenthesisColor) << "(";
10961076
PrintWithColorRAII(OS, ASTNodeColor) << Name;
@@ -1099,7 +1079,7 @@ namespace {
10991079
if (auto *SubExpr = Elt.dyn_cast<Expr*>())
11001080
printRec(SubExpr);
11011081
else if (auto *SubStmt = Elt.dyn_cast<Stmt*>())
1102-
printRec(SubStmt, Ctx);
1082+
printRec(SubStmt);
11031083
else
11041084
printRec(Elt.get<Decl*>());
11051085
}
@@ -1122,7 +1102,7 @@ namespace {
11221102

11231103
OS << '\n';
11241104
Indent += 2;
1125-
printASTNodes(Clause.Elements, ICD->getASTContext(), "elements");
1105+
printASTNodes(Clause.Elements, "elements");
11261106
Indent -= 2;
11271107
}
11281108

@@ -1369,11 +1349,9 @@ namespace {
13691349
class PrintStmt : public StmtVisitor<PrintStmt> {
13701350
public:
13711351
raw_ostream &OS;
1372-
const ASTContext *Ctx;
13731352
unsigned Indent;
13741353

1375-
PrintStmt(raw_ostream &os, const ASTContext *ctx, unsigned indent)
1376-
: OS(os), Ctx(ctx), Indent(indent) {
1354+
PrintStmt(raw_ostream &os, unsigned indent) : OS(os), Indent(indent) {
13771355
}
13781356

13791357
void printRec(Stmt *S) {
@@ -1440,28 +1418,20 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
14401418
if (S->isImplicit())
14411419
OS << " implicit";
14421420

1443-
if (Ctx) {
1444-
auto R = S->getSourceRange();
1445-
if (R.isValid()) {
1446-
PrintWithColorRAII(OS, RangeColor) << " range=";
1447-
R.print(PrintWithColorRAII(OS, RangeColor).getOS(),
1448-
Ctx->SourceMgr, /*PrintText=*/false);
1449-
}
1450-
}
1451-
14521421
if (S->TrailingSemiLoc.isValid())
14531422
OS << " trailing_semi";
14541423

14551424
return OS;
14561425
}
14571426

14581427
void visitBraceStmt(BraceStmt *S) {
1459-
printCommon(S, "brace_stmt");
1460-
printASTNodes(S->getElements());
1461-
PrintWithColorRAII(OS, ParenthesisColor) << ')';
1428+
printASTNodes(S->getElements(), "brace_stmt");
14621429
}
14631430

1464-
void printASTNodes(const ArrayRef<ASTNode> &Elements) {
1431+
void printASTNodes(const ArrayRef<ASTNode> &Elements, StringRef Name) {
1432+
OS.indent(Indent);
1433+
PrintWithColorRAII(OS, ParenthesisColor) << "(";
1434+
PrintWithColorRAII(OS, ASTNodeColor) << Name;
14651435
for (auto Elt : Elements) {
14661436
OS << '\n';
14671437
if (auto *SubExpr = Elt.dyn_cast<Expr*>())
@@ -1471,6 +1441,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
14711441
else
14721442
printRec(Elt.get<Decl*>());
14731443
}
1444+
PrintWithColorRAII(OS, ParenthesisColor) << ')';
14741445
}
14751446

14761447
void visitReturnStmt(ReturnStmt *S) {
@@ -1654,8 +1625,8 @@ void Stmt::dump() const {
16541625
llvm::errs() << '\n';
16551626
}
16561627

1657-
void Stmt::print(raw_ostream &OS, const ASTContext *Ctx, unsigned Indent) const {
1658-
PrintStmt(OS, Ctx, Indent).visit(const_cast<Stmt*>(this));
1628+
void Stmt::print(raw_ostream &OS, unsigned Indent) const {
1629+
PrintStmt(OS, Indent).visit(const_cast<Stmt*>(this));
16591630
}
16601631

16611632
//===----------------------------------------------------------------------===//
@@ -1700,7 +1671,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
17001671
/// FIXME: This should use ExprWalker to print children.
17011672

17021673
void printRec(Decl *D) { D->dump(OS, Indent + 2); }
1703-
void printRec(Stmt *S, const ASTContext &Ctx) { S->print(OS, &Ctx, Indent + 2); }
1674+
void printRec(Stmt *S) { S->print(OS, Indent + 2); }
17041675
void printRec(const Pattern *P) {
17051676
PrintPattern(OS, Indent+2).visit(const_cast<Pattern *>(P));
17061677
}
@@ -2303,14 +2274,14 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
23032274

23042275
if (E->getParameters()) {
23052276
OS << '\n';
2306-
PrintDecl(OS, Indent+2).printParameterList(E->getParameters(), &E->getASTContext());
2277+
PrintDecl(OS, Indent+2).printParameterList(E->getParameters());
23072278
}
23082279

23092280
OS << '\n';
23102281
if (E->hasSingleExpressionBody()) {
23112282
printRec(E->getSingleExpressionBody());
23122283
} else {
2313-
printRec(E->getBody(), E->getASTContext());
2284+
printRec(E->getBody());
23142285
}
23152286
PrintWithColorRAII(OS, ParenthesisColor) << ')';
23162287
}
@@ -2319,7 +2290,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
23192290

23202291
if (E->getParameters()) {
23212292
OS << '\n';
2322-
PrintDecl(OS, Indent+2).printParameterList(E->getParameters(), &E->getASTContext());
2293+
PrintDecl(OS, Indent+2).printParameterList(E->getParameters());
23232294
}
23242295

23252296
OS << '\n';

test/Driver/dump-parse.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: not %target-swift-frontend -dump-parse %s 2>&1 | %FileCheck %s
22
// RUN: not %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck %s -check-prefix=CHECK-AST
33

4-
// CHECK-LABEL: (func_decl{{.*}}"foo(_:)"
5-
// CHECK-AST-LABEL: (func_decl{{.*}}"foo(_:)"
4+
// CHECK-LABEL: (func_decl "foo(_:)"
5+
// CHECK-AST-LABEL: (func_decl "foo(_:)"
66
func foo(_ n: Int) -> Int {
77
// CHECK: (brace_stmt
88
// CHECK: (return_stmt
@@ -15,8 +15,8 @@ func foo(_ n: Int) -> Int {
1515
}
1616

1717
// -dump-parse should print an AST even though this code is invalid.
18-
// CHECK-LABEL: (func_decl{{.*}}"bar()"
19-
// CHECK-AST-LABEL: (func_decl{{.*}}"bar()"
18+
// CHECK-LABEL: (func_decl "bar()"
19+
// CHECK-AST-LABEL: (func_decl "bar()"
2020
func bar() {
2121
// CHECK: (brace_stmt
2222
// CHECK-NEXT: (unresolved_decl_ref_expr type='{{[^']+}}' name=foo
@@ -29,28 +29,28 @@ func bar() {
2929
foo foo foo
3030
}
3131

32-
// CHECK-LABEL: (enum_decl{{.*}}trailing_semi "TrailingSemi"
32+
// CHECK-LABEL: (enum_decl trailing_semi "TrailingSemi"
3333
enum TrailingSemi {
3434

35-
// CHECK-LABEL: (enum_case_decl{{.*}}trailing_semi
35+
// CHECK-LABEL: (enum_case_decl trailing_semi
3636
// CHECK-NOT: (enum_element_decl{{.*}}trailing_semi
37-
// CHECK: (enum_element_decl{{.*}}"A")
38-
// CHECK: (enum_element_decl{{.*}}"B")
37+
// CHECK: (enum_element_decl "A")
38+
// CHECK: (enum_element_decl "B")
3939
case A,B;
4040

41-
// CHECK-LABEL: (subscript_decl{{.*}}trailing_semi
42-
// CHECK-NOT: (func_decl{{.*}}trailing_semi 'anonname={{.*}}' getter_for=subscript(_:)
43-
// CHECK: (accessor_decl{{.*}}'anonname={{.*}}' getter_for=subscript(_:)
41+
// CHECK-LABEL: (subscript_decl trailing_semi
42+
// CHECK-NOT: (func_decl trailing_semi 'anonname={{.*}}' getter_for=subscript(_:)
43+
// CHECK: (accessor_decl 'anonname={{.*}}' getter_for=subscript(_:)
4444
subscript(x: Int) -> Int {
45-
// CHECK-LABEL: (pattern_binding_decl{{.*}}trailing_semi
46-
// CHECK-NOT: (var_decl{{.*}}trailing_semi "y"
47-
// CHECK: (var_decl{{.*}}"y"
45+
// CHECK-LABEL: (pattern_binding_decl trailing_semi
46+
// CHECK-NOT: (var_decl trailing_semi "y"
47+
// CHECK: (var_decl "y"
4848
var y = 1;
4949

5050
// CHECK-LABEL: (sequence_expr {{.*}} trailing_semi
5151
y += 1;
5252

53-
// CHECK-LABEL: (return_stmt{{.*}}trailing_semi
53+
// CHECK-LABEL: (return_stmt trailing_semi
5454
return y;
5555
};
5656
};

test/NameBinding/import-resolution-overload.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extension HasFooSub {
5555
var foo: Int { return 0 }
5656
}
5757

58-
// CHECK-LABEL: func_decl{{.*}}"testHasFooSub(_:)"
58+
// CHECK-LABEL: func_decl "testHasFooSub(_:)"
5959
func testHasFooSub(_ hfs: HasFooSub) -> Int {
6060
// CHECK: return_stmt
6161
// CHECK-NOT: func_decl
@@ -67,7 +67,7 @@ extension HasBar {
6767
var bar: Int { return 0 }
6868
}
6969

70-
// CHECK-LABEL: func_decl{{.*}}"testHasBar(_:)"
70+
// CHECK-LABEL: func_decl "testHasBar(_:)"
7171
func testHasBar(_ hb: HasBar) -> Int {
7272
// CHECK: return_stmt
7373
// CHECK-NOT: func_decl

test/Parse/if_expr.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck %s
22

3-
// CHECK: (func_decl{{.*}}"r13756261(_:_:)"
3+
// CHECK: (func_decl "r13756261(_:_:)"
44
func r13756261(_ x: Bool, _ y: Int) -> Int {
55
// CHECK: (if_expr
66
// CHECK: (call_expr
@@ -15,7 +15,7 @@ func r13756261(_ x: Bool, _ y: Int) -> Int {
1515
return (x) ? y : (x) ? y : (x) ? y : y
1616
}
1717

18-
// CHECK: (func_decl{{.*}}"r13756221(_:_:)"
18+
// CHECK: (func_decl "r13756221(_:_:)"
1919
func r13756221(_ x: Bool, _ y: Int) -> Int {
2020
// CHECK: (if_expr
2121
// CHECK: (call_expr
@@ -33,7 +33,7 @@ func r13756221(_ x: Bool, _ y: Int) -> Int {
3333
: y
3434
}
3535

36-
// CHECK: (func_decl{{.*}}"telescoping_if(_:_:)"
36+
// CHECK: (func_decl "telescoping_if(_:_:)"
3737
func telescoping_if(_ x: Bool, _ y: Int) -> Int {
3838
// CHECK: (if_expr
3939
// CHECK: (call_expr
@@ -69,7 +69,7 @@ func +>> (x: Bool, y: Bool) -> Bool {}
6969
func +<< (x: Bool, y: Bool) -> Bool {}
7070
func +== (x: Bool, y: Bool) -> Bool {}
7171

72-
// CHECK: (func_decl{{.*}}"prec_above(_:_:_:)"
72+
// CHECK: (func_decl "prec_above(_:_:_:)"
7373
func prec_above(_ x: Bool, _ y: Bool, _ z: Bool) -> Bool {
7474
// (x +>> y) ? (y +>> z) : ((x +>> y) ? (y +>> z) : (x +>> y))
7575
// CHECK: (if_expr
@@ -82,7 +82,7 @@ func prec_above(_ x: Bool, _ y: Bool, _ z: Bool) -> Bool {
8282
return x +>> y ? y +>> z : x +>> y ? y +>> z : x +>> y
8383
}
8484

85-
// CHECK: (func_decl{{.*}}"prec_below(_:_:_:)"
85+
// CHECK: (func_decl "prec_below(_:_:_:)"
8686
func prec_below(_ x: Bool, _ y: Bool, _ z: Bool) -> Bool {
8787
// The middle arm of the ternary is max-munched, so this is:
8888
// ((x +<< (y ? (y +<< z) : x)) +<< (y ? (y +<< z) : x)) +<< y
@@ -102,7 +102,7 @@ func prec_below(_ x: Bool, _ y: Bool, _ z: Bool) -> Bool {
102102
return x +<< y ? y +<< z : x +<< y ? y +<< z : x +<< y
103103
}
104104

105-
// CHECK: (func_decl{{.*}}"prec_equal(_:_:_:)"
105+
// CHECK: (func_decl "prec_equal(_:_:_:)"
106106
func prec_equal(_ x: Bool, _ y: Bool, _ z: Bool) -> Bool {
107107
// The middle arm of the ternary is max-munched, so this is:
108108
// x +== (y ? (y +== z) : (x +== (y ? (y +== z) : (x +== y))))

0 commit comments

Comments
 (0)