Skip to content

Commit dc3ff6c

Browse files
authored
Merge pull request swiftlang#19985 from vinivendra/ast-dump-cleanup
Cleans up calls to print/dump for the AST Dumper
2 parents 3be98d7 + e907534 commit dc3ff6c

File tree

11 files changed

+97
-115
lines changed

11 files changed

+97
-115
lines changed

include/swift/AST/Expr.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -536,22 +536,11 @@ class alignas(8) Expr {
536536
LLVM_ATTRIBUTE_DEPRECATED(
537537
void dump() const LLVM_ATTRIBUTE_USED,
538538
"only for use within the debugger");
539-
LLVM_ATTRIBUTE_DEPRECATED(
540-
void dump(llvm::function_ref<Type(const Expr *)> getType,
541-
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc)
542-
const LLVM_ATTRIBUTE_USED,
543-
"only for use within the debugger");
544-
LLVM_ATTRIBUTE_DEPRECATED(
545-
void dump(raw_ostream &OS, llvm::function_ref<Type(const Expr *)> getType,
546-
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc)
547-
const LLVM_ATTRIBUTE_USED,
548-
"only for use within the debugger");
549-
550-
void dump(raw_ostream &OS) const;
551-
void print(raw_ostream &OS, unsigned Indent = 0) const;
552-
void print(raw_ostream &OS, llvm::function_ref<Type(const Expr *)> getType,
553-
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc,
554-
unsigned Indent = 0) const;
539+
void dump(raw_ostream &OS, unsigned Indent = 0) const;
540+
void dump(raw_ostream &OS, llvm::function_ref<Type(const Expr *)> getType,
541+
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc,
542+
unsigned Indent = 0) const;
543+
555544
void print(ASTPrinter &Printer, const PrintOptions &Opts) const;
556545

557546
// Only allow allocation of Exprs using the allocator in ASTContext

include/swift/AST/Stmt.h

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

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

lib/AST/ASTDumper.cpp

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ namespace {
428428
}
429429

430430
void printRec(Decl *D) { D->dump(OS, Indent + 2); }
431-
void printRec(Expr *E) { E->print(OS, Indent + 2); }
432-
void printRec(Stmt *S, const ASTContext &Ctx) { S->print(OS, &Ctx, Indent + 2); }
431+
void printRec(Expr *E) { E->dump(OS, Indent + 2); }
432+
void printRec(Stmt *S, const ASTContext &Ctx) { S->dump(OS, &Ctx, Indent + 2); }
433433
void printRec(TypeRepr *T);
434434
void printRec(const Pattern *P) {
435435
PrintPattern(OS, Indent+2).visit(const_cast<Pattern *>(P));
@@ -556,8 +556,8 @@ namespace {
556556
}
557557

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

@@ -1385,7 +1385,7 @@ void Pattern::dump() const {
13851385
//===----------------------------------------------------------------------===//
13861386

13871387
namespace {
1388-
/// PrintStmt - Visitor implementation of Expr::print.
1388+
/// PrintStmt - Visitor implementation of Stmt::dump.
13891389
class PrintStmt : public StmtVisitor<PrintStmt> {
13901390
public:
13911391
raw_ostream &OS;
@@ -1406,7 +1406,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
14061406
}
14071407

14081408
void printRec(Decl *D) { D->dump(OS, Indent + 2); }
1409-
void printRec(Expr *E) { E->print(OS, Indent + 2); }
1409+
void printRec(Expr *E) { E->dump(OS, Indent + 2); }
14101410
void printRec(const Pattern *P) {
14111411
PrintPattern(OS, Indent+2).visit(const_cast<Pattern *>(P));
14121412
}
@@ -1630,7 +1630,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
16301630
}
16311631
if (auto *Guard = LabelItem.getGuardExpr()) {
16321632
OS << '\n';
1633-
Guard->print(OS, Indent+4);
1633+
Guard->dump(OS, Indent+4);
16341634
}
16351635
PrintWithColorRAII(OS, ParenthesisColor) << ')';
16361636
}
@@ -1679,11 +1679,11 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
16791679
} // end anonymous namespace
16801680

16811681
void Stmt::dump() const {
1682-
print(llvm::errs());
1682+
dump(llvm::errs());
16831683
llvm::errs() << '\n';
16841684
}
16851685

1686-
void Stmt::print(raw_ostream &OS, const ASTContext *Ctx, unsigned Indent) const {
1686+
void Stmt::dump(raw_ostream &OS, const ASTContext *Ctx, unsigned Indent) const {
16871687
PrintStmt(OS, Ctx, Indent).visit(const_cast<Stmt*>(this));
16881688
}
16891689

@@ -1692,7 +1692,7 @@ void Stmt::print(raw_ostream &OS, const ASTContext *Ctx, unsigned Indent) const
16921692
//===----------------------------------------------------------------------===//
16931693

16941694
namespace {
1695-
/// PrintExpr - Visitor implementation of Expr::print.
1695+
/// PrintExpr - Visitor implementation of Expr::dump.
16961696
class PrintExpr : public ExprVisitor<PrintExpr> {
16971697
public:
16981698
raw_ostream &OS;
@@ -1730,7 +1730,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
17301730
/// FIXME: This should use ExprWalker to print children.
17311731

17321732
void printRec(Decl *D) { D->dump(OS, Indent + 2); }
1733-
void printRec(Stmt *S, const ASTContext &Ctx) { S->print(OS, &Ctx, Indent + 2); }
1733+
void printRec(Stmt *S, const ASTContext &Ctx) { S->dump(OS, &Ctx, Indent + 2); }
17341734
void printRec(const Pattern *P) {
17351735
PrintPattern(OS, Indent+2).visit(const_cast<Pattern *>(P));
17361736
}
@@ -2594,7 +2594,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
25942594
OS << "subscript ";
25952595
printDeclRef(component.getDeclRef());
25962596
OS << '\n';
2597-
component.getIndexExpr()->print(OS, Indent + 4);
2597+
component.getIndexExpr()->dump(OS, Indent + 4);
25982598
OS.indent(Indent + 4);
25992599
break;
26002600

@@ -2607,7 +2607,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
26072607
case KeyPathExpr::Component::Kind::UnresolvedSubscript:
26082608
OS << "unresolved_subscript";
26092609
OS << '\n';
2610-
component.getIndexExpr()->print(OS, Indent + 4);
2610+
component.getIndexExpr()->dump(OS, Indent + 4);
26112611
OS.indent(Indent + 4);
26122612
break;
26132613
case KeyPathExpr::Component::Kind::Identity:
@@ -2648,61 +2648,32 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
26482648

26492649
} // end anonymous namespace
26502650

2651-
void Expr::dump(
2652-
raw_ostream &OS, llvm::function_ref<Type(const Expr *)> getTypeOfExpr,
2653-
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc) const {
2654-
if (auto ty = getTypeOfExpr(this)) {
2655-
llvm::SaveAndRestore<bool> X(
2656-
ty->getASTContext().LangOpts.DebugConstraintSolver, true);
2657-
print(OS, getTypeOfExpr, getTypeOfTypeLoc);
2658-
} else {
2659-
print(OS, getTypeOfExpr, getTypeOfTypeLoc);
2660-
}
2661-
OS << '\n';
2662-
}
2663-
2664-
void Expr::dump(raw_ostream &OS) const {
2665-
if (auto ty = getType()) {
2666-
llvm::SaveAndRestore<bool> X(ty->getASTContext().LangOpts.
2667-
DebugConstraintSolver, true);
2668-
print(OS);
2669-
} else {
2670-
print(OS);
2671-
}
2672-
OS << '\n';
2673-
}
2674-
26752651
void Expr::dump() const {
26762652
dump(llvm::errs());
2653+
llvm::errs() << "\n";
26772654
}
26782655

2679-
void Expr::dump(
2680-
llvm::function_ref<Type(const Expr *)> getTypeOfExpr,
2681-
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc) const {
2682-
dump(llvm::errs(), getTypeOfExpr, getTypeOfTypeLoc);
2683-
}
2684-
2685-
void Expr::print(raw_ostream &OS,
2656+
void Expr::dump(raw_ostream &OS,
26862657
llvm::function_ref<Type(const Expr *)> getTypeOfExpr,
26872658
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc,
26882659
unsigned Indent) const {
26892660
PrintExpr(OS, getTypeOfExpr, getTypeOfTypeLoc, Indent)
26902661
.visit(const_cast<Expr *>(this));
26912662
}
26922663

2693-
void Expr::print(raw_ostream &OS, unsigned Indent) const {
2664+
void Expr::dump(raw_ostream &OS, unsigned Indent) const {
26942665
auto getTypeOfExpr = [](const Expr *E) -> Type { return E->getType(); };
26952666
auto getTypeOfTypeLoc = [](const TypeLoc &TL) -> Type {
26962667
return TL.getType();
26972668
};
2698-
print(OS, getTypeOfExpr, getTypeOfTypeLoc, Indent);
2669+
dump(OS, getTypeOfExpr, getTypeOfTypeLoc, Indent);
26992670
}
27002671

27012672
void Expr::print(ASTPrinter &Printer, const PrintOptions &Opts) const {
27022673
// FIXME: Fully use the ASTPrinter.
27032674
llvm::SmallString<128> Str;
27042675
llvm::raw_svector_ostream OS(Str);
2705-
print(OS);
2676+
dump(OS);
27062677
Printer << OS.str();
27072678
}
27082679

@@ -2724,7 +2695,7 @@ class PrintTypeRepr : public TypeReprVisitor<PrintTypeRepr> {
27242695
}
27252696

27262697
void printRec(Decl *D) { D->dump(OS, Indent + 2); }
2727-
void printRec(Expr *E) { E->print(OS, Indent + 2); }
2698+
void printRec(Expr *E) { E->dump(OS, Indent + 2); }
27282699
void printRec(TypeRepr *T) { PrintTypeRepr(OS, Indent + 2).visit(T); }
27292700

27302701
raw_ostream &printCommon(const char *Name) {

0 commit comments

Comments
 (0)