Skip to content

Commit 6c18a03

Browse files
committed
[NFC] Add ClangNode::dump()
1 parent 443e091 commit 6c18a03

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

include/swift/AST/ClangNode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_CLANGNODE_H
1414
#define SWIFT_CLANGNODE_H
1515

16+
#include "swift/Basic/Debug.h"
1617
#include "llvm/ADT/PointerUnion.h"
1718

1819
namespace clang {
@@ -98,6 +99,8 @@ class ClangNode {
9899
clang::SourceLocation getLocation() const;
99100
clang::SourceRange getSourceRange() const;
100101

102+
SWIFT_DEBUG_DUMP;
103+
101104
void *getOpaqueValue() const { return Ptr.getOpaqueValue(); }
102105
static inline ClangNode getFromOpaqueValue(void *VP) {
103106
ClangNode N;

lib/AST/Decl.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ const clang::Module *ClangNode::getClangModule() const {
116116
return nullptr;
117117
}
118118

119+
void ClangNode::dump() const {
120+
if (auto D = getAsDecl())
121+
D->dump();
122+
else if (auto M = getAsMacro())
123+
M->dump();
124+
else if (auto M = getAsModule())
125+
M->dump();
126+
else
127+
llvm::errs() << "ClangNode contains nullptr\n";
128+
}
129+
119130
// Only allow allocation of Decls using the allocator in ASTContext.
120131
void *Decl::operator new(size_t Bytes, const ASTContext &C,
121132
unsigned Alignment) {

0 commit comments

Comments
 (0)