Skip to content

Add ASTNode.dump() methods #22686

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
Feb 18, 2019
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
9 changes: 9 additions & 0 deletions include/swift/AST/ASTNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include "llvm/ADT/PointerUnion.h"
#include "swift/AST/TypeAlignments.h"

namespace llvm {
class raw_ostream;
}

namespace swift {
class Expr;
class Stmt;
Expand Down Expand Up @@ -57,6 +61,11 @@ namespace swift {
FUNC(Expr)
FUNC(Decl)
#undef FUNC

LLVM_ATTRIBUTE_DEPRECATED(
void dump() const LLVM_ATTRIBUTE_USED,
"only for use within the debugger");
void dump(llvm::raw_ostream &OS, unsigned Indent = 0) const;

/// Whether the AST node is implicit.
bool isImplicit() const;
Expand Down
15 changes: 15 additions & 0 deletions lib/AST/ASTNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ void ASTNode::walk(ASTWalker &Walker) {
llvm_unreachable("unsupported AST node");
}

void ASTNode::dump(raw_ostream &OS, unsigned Indent) const {
if (auto S = dyn_cast<Stmt*>())
S->dump(OS, /*context=*/nullptr, Indent);
else if (auto E = dyn_cast<Expr*>())
E->dump(OS, Indent);
else if (auto D = dyn_cast<Decl*>())
D->dump(OS, Indent);
else
OS << "<null>";
}

void ASTNode::dump() const {
dump(llvm::errs());
}

#define FUNC(T) \
bool ASTNode::is##T(T##Kind Kind) const { \
if (!is<T*>()) \
Expand Down