Skip to content

Revert "Include source ranges for statements, declarations, and parameter lists in the AST dump" #16679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/Stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class alignas(8) Stmt {
LLVM_ATTRIBUTE_DEPRECATED(
void dump() const LLVM_ATTRIBUTE_USED,
"only for use within the debugger");
void print(raw_ostream &OS, const ASTContext *Ctx = nullptr, unsigned Indent = 0) const;
void print(raw_ostream &OS, unsigned Indent = 0) const;

// Only allow allocation of Exprs using the allocator in ASTContext
// or by doing a placement new.
Expand Down
73 changes: 22 additions & 51 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ namespace {

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

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

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

auto R = D->getSourceRange();
if (R.isValid()) {
PrintWithColorRAII(OS, RangeColor) << " range=";
R.print(PrintWithColorRAII(OS, RangeColor).getOS(),
D->getASTContext().SourceMgr, /*PrintText=*/false);
}

if (D->TrailingSemiLoc.isValid())
PrintWithColorRAII(OS, DeclModifierColor) << " trailing_semi";
}
Expand Down Expand Up @@ -991,7 +984,7 @@ namespace {
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}

void printParameterList(const ParameterList *params, const ASTContext *ctx = nullptr) {
void printParameterList(const ParameterList *params) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, ParameterColor) << "parameter_list";
Expand All @@ -1000,19 +993,6 @@ namespace {
OS << '\n';
printParameter(P);
}

if (!ctx && params->size() != 0 && params->get(0))
ctx = &params->get(0)->getASTContext();

if (ctx) {
auto R = params->getSourceRange();
if (R.isValid()) {
PrintWithColorRAII(OS, RangeColor) << " range=";
R.print(PrintWithColorRAII(OS, RangeColor).getOS(),
ctx->SourceMgr, /*PrintText=*/false);
}
}

PrintWithColorRAII(OS, ParenthesisColor) << ')';
Indent -= 2;
}
Expand All @@ -1021,7 +1001,7 @@ namespace {
for (auto pl : D->getParameterLists()) {
OS << '\n';
Indent += 2;
printParameterList(pl, &D->getASTContext());
printParameterList(pl);
Indent -= 2;
}
if (auto FD = dyn_cast<FuncDecl>(D)) {
Expand All @@ -1038,7 +1018,7 @@ namespace {
}
if (auto Body = D->getBody(/*canSynthesize=*/false)) {
OS << '\n';
printRec(Body, D->getASTContext());
printRec(Body);
}
}

Expand Down Expand Up @@ -1085,12 +1065,12 @@ namespace {
printCommon(TLCD, "top_level_code_decl");
if (TLCD->getBody()) {
OS << "\n";
printRec(TLCD->getBody(), static_cast<Decl *>(TLCD)->getASTContext());
printRec(TLCD->getBody());
}
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}

void printASTNodes(const ArrayRef<ASTNode> &Elements, const ASTContext &Ctx, StringRef Name) {
void printASTNodes(const ArrayRef<ASTNode> &Elements, StringRef Name) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << "(";
PrintWithColorRAII(OS, ASTNodeColor) << Name;
Expand All @@ -1099,7 +1079,7 @@ namespace {
if (auto *SubExpr = Elt.dyn_cast<Expr*>())
printRec(SubExpr);
else if (auto *SubStmt = Elt.dyn_cast<Stmt*>())
printRec(SubStmt, Ctx);
printRec(SubStmt);
else
printRec(Elt.get<Decl*>());
}
Expand All @@ -1122,7 +1102,7 @@ namespace {

OS << '\n';
Indent += 2;
printASTNodes(Clause.Elements, ICD->getASTContext(), "elements");
printASTNodes(Clause.Elements, "elements");
Indent -= 2;
}

Expand Down Expand Up @@ -1369,11 +1349,9 @@ namespace {
class PrintStmt : public StmtVisitor<PrintStmt> {
public:
raw_ostream &OS;
const ASTContext *Ctx;
unsigned Indent;

PrintStmt(raw_ostream &os, const ASTContext *ctx, unsigned indent)
: OS(os), Ctx(ctx), Indent(indent) {
PrintStmt(raw_ostream &os, unsigned indent) : OS(os), Indent(indent) {
}

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

if (Ctx) {
auto R = S->getSourceRange();
if (R.isValid()) {
PrintWithColorRAII(OS, RangeColor) << " range=";
R.print(PrintWithColorRAII(OS, RangeColor).getOS(),
Ctx->SourceMgr, /*PrintText=*/false);
}
}

if (S->TrailingSemiLoc.isValid())
OS << " trailing_semi";

return OS;
}

void visitBraceStmt(BraceStmt *S) {
printCommon(S, "brace_stmt");
printASTNodes(S->getElements());
PrintWithColorRAII(OS, ParenthesisColor) << ')';
printASTNodes(S->getElements(), "brace_stmt");
}

void printASTNodes(const ArrayRef<ASTNode> &Elements) {
void printASTNodes(const ArrayRef<ASTNode> &Elements, StringRef Name) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << "(";
PrintWithColorRAII(OS, ASTNodeColor) << Name;
for (auto Elt : Elements) {
OS << '\n';
if (auto *SubExpr = Elt.dyn_cast<Expr*>())
Expand All @@ -1471,6 +1441,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
else
printRec(Elt.get<Decl*>());
}
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}

void visitReturnStmt(ReturnStmt *S) {
Expand Down Expand Up @@ -1654,8 +1625,8 @@ void Stmt::dump() const {
llvm::errs() << '\n';
}

void Stmt::print(raw_ostream &OS, const ASTContext *Ctx, unsigned Indent) const {
PrintStmt(OS, Ctx, Indent).visit(const_cast<Stmt*>(this));
void Stmt::print(raw_ostream &OS, unsigned Indent) const {
PrintStmt(OS, Indent).visit(const_cast<Stmt*>(this));
}

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

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

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

OS << '\n';
if (E->hasSingleExpressionBody()) {
printRec(E->getSingleExpressionBody());
} else {
printRec(E->getBody(), E->getASTContext());
printRec(E->getBody());
}
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}
Expand All @@ -2319,7 +2290,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {

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

OS << '\n';
Expand Down
30 changes: 15 additions & 15 deletions test/Driver/dump-parse.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// RUN: not %target-swift-frontend -dump-parse %s 2>&1 | %FileCheck %s
// RUN: not %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck %s -check-prefix=CHECK-AST

// CHECK-LABEL: (func_decl{{.*}}"foo(_:)"
// CHECK-AST-LABEL: (func_decl{{.*}}"foo(_:)"
// CHECK-LABEL: (func_decl "foo(_:)"
// CHECK-AST-LABEL: (func_decl "foo(_:)"
func foo(_ n: Int) -> Int {
// CHECK: (brace_stmt
// CHECK: (return_stmt
Expand All @@ -15,8 +15,8 @@ func foo(_ n: Int) -> Int {
}

// -dump-parse should print an AST even though this code is invalid.
// CHECK-LABEL: (func_decl{{.*}}"bar()"
// CHECK-AST-LABEL: (func_decl{{.*}}"bar()"
// CHECK-LABEL: (func_decl "bar()"
// CHECK-AST-LABEL: (func_decl "bar()"
func bar() {
// CHECK: (brace_stmt
// CHECK-NEXT: (unresolved_decl_ref_expr type='{{[^']+}}' name=foo
Expand All @@ -29,28 +29,28 @@ func bar() {
foo foo foo
}

// CHECK-LABEL: (enum_decl{{.*}}trailing_semi "TrailingSemi"
// CHECK-LABEL: (enum_decl trailing_semi "TrailingSemi"
enum TrailingSemi {

// CHECK-LABEL: (enum_case_decl{{.*}}trailing_semi
// CHECK-LABEL: (enum_case_decl trailing_semi
// CHECK-NOT: (enum_element_decl{{.*}}trailing_semi
// CHECK: (enum_element_decl{{.*}}"A")
// CHECK: (enum_element_decl{{.*}}"B")
// CHECK: (enum_element_decl "A")
// CHECK: (enum_element_decl "B")
case A,B;

// CHECK-LABEL: (subscript_decl{{.*}}trailing_semi
// CHECK-NOT: (func_decl{{.*}}trailing_semi 'anonname={{.*}}' getter_for=subscript(_:)
// CHECK: (accessor_decl{{.*}}'anonname={{.*}}' getter_for=subscript(_:)
// CHECK-LABEL: (subscript_decl trailing_semi
// CHECK-NOT: (func_decl trailing_semi 'anonname={{.*}}' getter_for=subscript(_:)
// CHECK: (accessor_decl 'anonname={{.*}}' getter_for=subscript(_:)
subscript(x: Int) -> Int {
// CHECK-LABEL: (pattern_binding_decl{{.*}}trailing_semi
// CHECK-NOT: (var_decl{{.*}}trailing_semi "y"
// CHECK: (var_decl{{.*}}"y"
// CHECK-LABEL: (pattern_binding_decl trailing_semi
// CHECK-NOT: (var_decl trailing_semi "y"
// CHECK: (var_decl "y"
var y = 1;

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

// CHECK-LABEL: (return_stmt{{.*}}trailing_semi
// CHECK-LABEL: (return_stmt trailing_semi
return y;
};
};
Expand Down
4 changes: 2 additions & 2 deletions test/NameBinding/import-resolution-overload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension HasFooSub {
var foo: Int { return 0 }
}

// CHECK-LABEL: func_decl{{.*}}"testHasFooSub(_:)"
// CHECK-LABEL: func_decl "testHasFooSub(_:)"
func testHasFooSub(_ hfs: HasFooSub) -> Int {
// CHECK: return_stmt
// CHECK-NOT: func_decl
Expand All @@ -67,7 +67,7 @@ extension HasBar {
var bar: Int { return 0 }
}

// CHECK-LABEL: func_decl{{.*}}"testHasBar(_:)"
// CHECK-LABEL: func_decl "testHasBar(_:)"
func testHasBar(_ hb: HasBar) -> Int {
// CHECK: return_stmt
// CHECK-NOT: func_decl
Expand Down
12 changes: 6 additions & 6 deletions test/Parse/if_expr.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck %s

// CHECK: (func_decl{{.*}}"r13756261(_:_:)"
// CHECK: (func_decl "r13756261(_:_:)"
func r13756261(_ x: Bool, _ y: Int) -> Int {
// CHECK: (if_expr
// CHECK: (call_expr
Expand All @@ -15,7 +15,7 @@ func r13756261(_ x: Bool, _ y: Int) -> Int {
return (x) ? y : (x) ? y : (x) ? y : y
}

// CHECK: (func_decl{{.*}}"r13756221(_:_:)"
// CHECK: (func_decl "r13756221(_:_:)"
func r13756221(_ x: Bool, _ y: Int) -> Int {
// CHECK: (if_expr
// CHECK: (call_expr
Expand All @@ -33,7 +33,7 @@ func r13756221(_ x: Bool, _ y: Int) -> Int {
: y
}

// CHECK: (func_decl{{.*}}"telescoping_if(_:_:)"
// CHECK: (func_decl "telescoping_if(_:_:)"
func telescoping_if(_ x: Bool, _ y: Int) -> Int {
// CHECK: (if_expr
// CHECK: (call_expr
Expand Down Expand Up @@ -69,7 +69,7 @@ func +>> (x: Bool, y: Bool) -> Bool {}
func +<< (x: Bool, y: Bool) -> Bool {}
func +== (x: Bool, y: Bool) -> Bool {}

// CHECK: (func_decl{{.*}}"prec_above(_:_:_:)"
// CHECK: (func_decl "prec_above(_:_:_:)"
func prec_above(_ x: Bool, _ y: Bool, _ z: Bool) -> Bool {
// (x +>> y) ? (y +>> z) : ((x +>> y) ? (y +>> z) : (x +>> y))
// CHECK: (if_expr
Expand All @@ -82,7 +82,7 @@ func prec_above(_ x: Bool, _ y: Bool, _ z: Bool) -> Bool {
return x +>> y ? y +>> z : x +>> y ? y +>> z : x +>> y
}

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

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