[SyntaxParse] Improve ParsedRawSyntaxNode::dump()

This commit is contained in:
Rintaro Ishizaki
2019-08-29 15:48:57 -07:00
parent 6fcbb40462
commit b8ced1406f
2 changed files with 23 additions and 26 deletions

View File

@@ -56,37 +56,34 @@ void ParsedRawSyntaxNode::dump() const {
}
void ParsedRawSyntaxNode::dump(llvm::raw_ostream &OS, unsigned Indent) const {
auto indent = [&](unsigned Amount) {
for (decltype(Amount) i = 0; i < Amount; ++i) {
OS << ' ';
}
};
indent(Indent);
if (isNull()) {
OS << "(<NULL>)";
return;
}
for (decltype(Indent) i = 0; i < Indent; ++i)
OS << ' ';
OS << '(';
dumpSyntaxKind(OS, getKind());
if (isToken()) {
dumpTokenKind(OS, getTokenKind());
} else {
if (isRecorded()) {
OS << " [recorded]";
} else if (isDeferredLayout()) {
switch (DK) {
case DataKind::Null:
OS << "<NULL>";
break;
case DataKind::Recorded:
OS << " [recorded] ";
if (isToken()) {
dumpTokenKind(OS, getTokenKind());
} else {
OS << "<layout>";
}
break;
case DataKind::DeferredLayout:
OS << " [deferred]";
for (const auto &child : getDeferredChildren()) {
OS << "\n";
child.dump(OS, Indent + 1);
child.dump(OS, Indent + 2);
}
} else {
assert(isDeferredToken());
OS << " [deferred token]";
}
break;
case DataKind::DeferredToken:
OS << " [deferred] ";
dumpTokenKind(OS, getTokenKind());
break;
}
OS << ')';
}