Skip to content

Commit e6af2e4

Browse files
committed
Add ASTNode.dump() methods
1 parent 0fe7e14 commit e6af2e4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

include/swift/AST/ASTNode.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include "llvm/ADT/PointerUnion.h"
2121
#include "swift/AST/TypeAlignments.h"
2222

23+
namespace llvm {
24+
class raw_ostream;
25+
}
26+
2327
namespace swift {
2428
class Expr;
2529
class Stmt;
@@ -57,6 +61,11 @@ namespace swift {
5761
FUNC(Expr)
5862
FUNC(Decl)
5963
#undef FUNC
64+
65+
LLVM_ATTRIBUTE_DEPRECATED(
66+
void dump() const LLVM_ATTRIBUTE_USED,
67+
"only for use within the debugger");
68+
void dump(llvm::raw_ostream &OS, unsigned Indent = 0) const;
6069

6170
/// Whether the AST node is implicit.
6271
bool isImplicit() const;

lib/AST/ASTNode.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ void ASTNode::walk(ASTWalker &Walker) {
7777
llvm_unreachable("unsupported AST node");
7878
}
7979

80+
void ASTNode::dump(raw_ostream &OS, unsigned Indent) const {
81+
if (auto S = dyn_cast<Stmt*>())
82+
S->dump(OS, /*context=*/nullptr, Indent);
83+
else if (auto E = dyn_cast<Expr*>())
84+
E->dump(OS, Indent);
85+
else if (auto D = dyn_cast<Decl*>())
86+
D->dump(OS, Indent);
87+
else
88+
OS << "<null>";
89+
}
90+
91+
void ASTNode::dump() const {
92+
dump(llvm::errs());
93+
}
94+
8095
#define FUNC(T) \
8196
bool ASTNode::is##T(T##Kind Kind) const { \
8297
if (!is<T*>()) \

0 commit comments

Comments
 (0)