Skip to content

Commit 984f262

Browse files
committed
[SyntaxParse] Improve ParsedRawSyntaxNode::dump()
1 parent 3818a16 commit 984f262

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

lib/Parse/ParsedRawSyntaxNode.cpp

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,37 +56,36 @@ void ParsedRawSyntaxNode::dump() const {
5656
}
5757

5858
void ParsedRawSyntaxNode::dump(llvm::raw_ostream &OS, unsigned Indent) const {
59-
auto indent = [&](unsigned Amount) {
60-
for (decltype(Amount) i = 0; i < Amount; ++i) {
61-
OS << ' ';
62-
}
63-
};
64-
65-
indent(Indent);
66-
67-
if (isNull()) {
68-
OS << "(<NULL>)";
69-
return;
70-
}
71-
59+
for (decltype(Indent) i = 0; i < Indent; ++i)
60+
OS << ' ';
7261
OS << '(';
73-
dumpSyntaxKind(OS, getKind());
74-
75-
if (isToken()) {
76-
dumpTokenKind(OS, getTokenKind());
7762

78-
} else {
79-
if (isRecorded()) {
80-
OS << " [recorded]";
81-
} else if (isDeferredLayout()) {
63+
switch (DK) {
64+
case DataKind::Null:
65+
OS << "<NULL>";
66+
break;
67+
case DataKind::Recorded:
68+
dumpSyntaxKind(OS, getKind());
69+
OS << " [recorded] ";
70+
if (isToken()) {
71+
dumpTokenKind(OS, getTokenKind());
72+
} else {
73+
OS << "<layout>";
74+
}
75+
break;
76+
case DataKind::DeferredLayout:
77+
dumpSyntaxKind(OS, getKind());
78+
OS << " [deferred]";
8279
for (const auto &child : getDeferredChildren()) {
8380
OS << "\n";
84-
child.dump(OS, Indent + 1);
81+
child.dump(OS, Indent + 2);
8582
}
86-
} else {
87-
assert(isDeferredToken());
88-
OS << " [deferred token]";
89-
}
83+
break;
84+
case DataKind::DeferredToken:
85+
dumpSyntaxKind(OS, getKind());
86+
OS << " [deferred] ";
87+
dumpTokenKind(OS, getTokenKind());
88+
break;
9089
}
9190
OS << ')';
9291
}

lib/Parse/SyntaxParsingContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ void SyntaxParsingContext::synthesize(tok Kind, SourceLoc Loc) {
319319
void SyntaxParsingContext::dumpStorage() const {
320320
llvm::errs() << "======================\n";
321321
for (auto Node : getStorage()) {
322-
Node.dump();
322+
Node.dump(llvm::errs());
323323
llvm::errs() << "\n--------------\n";
324324
}
325325
}

0 commit comments

Comments
 (0)