Skip to content

Commit b1e3da1

Browse files
committed
[NFC] Dump an ASTScopeImpl’s parent nodes
1 parent c503f04 commit b1e3da1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

include/swift/AST/ASTScope.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,15 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
250250

251251
void printRange(llvm::raw_ostream &out) const;
252252

253+
void printParents(llvm::raw_ostream &out) const;
254+
253255
protected:
254256
virtual void printSpecifics(llvm::raw_ostream &out) const {}
255257
virtual NullablePtr<const void> addressForPrinting() const;
256258

257259
public:
258260
SWIFT_DEBUG_DUMP;
261+
SWIFT_DEBUG_DUMPER(dumpParents());
259262

260263
void dumpOneScopeMapLocation(std::pair<unsigned, unsigned> lineColumn);
261264

lib/AST/ASTScopePrinting.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ using namespace ast_scope;
4040

4141
void ASTScopeImpl::dump() const { print(llvm::errs(), 0, false); }
4242

43+
void ASTScopeImpl::dumpParents() const { printParents(llvm::errs()); }
44+
4345
void ASTScopeImpl::dumpOneScopeMapLocation(
4446
std::pair<unsigned, unsigned> lineColumn) {
4547
auto bufferID = getSourceFile()->getBufferID();
@@ -124,6 +126,21 @@ void ASTScopeImpl::printRange(llvm::raw_ostream &out) const {
124126
printSourceRange(out, range, getSourceManager());
125127
}
126128

129+
void ASTScopeImpl::printParents(llvm::raw_ostream &out) const {
130+
SmallVector<const ASTScopeImpl *, 8> nodes;
131+
const ASTScopeImpl *cursor = this;
132+
do {
133+
nodes.push_back(cursor);
134+
cursor = cursor->getParent().getPtrOrNull();
135+
} while (cursor);
136+
137+
std::reverse(nodes.begin(), nodes.end());
138+
139+
for (auto i : indices(nodes)) {
140+
nodes[i]->print(out, i, /*lastChild=*/true, /*printChildren=*/false);
141+
}
142+
}
143+
127144
#pragma mark printSpecifics
128145

129146

0 commit comments

Comments
 (0)