Skip to content

Commit 713a2ab

Browse files
committed
Reformat and colorize KeyPathExpr AST dumps
1 parent 9cb896b commit 713a2ab

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,88 +2615,94 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
26152615
printCommon(E, "keypath_expr");
26162616
if (E->isObjC())
26172617
OS << " objc";
2618+
2619+
OS << '\n';
2620+
Indent += 2;
2621+
OS.indent(Indent);
2622+
PrintWithColorRAII(OS, ParenthesisColor) << '(';
2623+
PrintWithColorRAII(OS, ExprColor) << "components";
2624+
OS.indent(Indent + 2);
26182625
for (unsigned i : indices(E->getComponents())) {
26192626
auto &component = E->getComponents()[i];
26202627
OS << '\n';
26212628
OS.indent(Indent + 2);
2622-
OS << "(component=";
2629+
PrintWithColorRAII(OS, ParenthesisColor) << '(';
26232630
switch (component.getKind()) {
26242631
case KeyPathExpr::Component::Kind::Invalid:
2625-
OS << "invalid ";
2632+
PrintWithColorRAII(OS, ASTNodeColor) << "invalid";
26262633
break;
26272634

26282635
case KeyPathExpr::Component::Kind::OptionalChain:
2629-
OS << "optional_chain ";
2636+
PrintWithColorRAII(OS, ASTNodeColor) << "optional_chain";
26302637
break;
26312638

26322639
case KeyPathExpr::Component::Kind::OptionalForce:
2633-
OS << "optional_force ";
2640+
PrintWithColorRAII(OS, ASTNodeColor) << "optional_force";
26342641
break;
26352642

26362643
case KeyPathExpr::Component::Kind::OptionalWrap:
2637-
OS << "optional_wrap ";
2644+
PrintWithColorRAII(OS, ASTNodeColor) << "optional_wrap";
26382645
break;
26392646

26402647
case KeyPathExpr::Component::Kind::Property:
2641-
OS << "property ";
2648+
PrintWithColorRAII(OS, ASTNodeColor) << "property";
2649+
PrintWithColorRAII(OS, DeclColor) << " decl=";
26422650
printDeclRef(component.getDeclRef());
2643-
OS << " ";
26442651
break;
26452652

26462653
case KeyPathExpr::Component::Kind::Subscript:
2647-
OS << "subscript ";
2654+
PrintWithColorRAII(OS, ASTNodeColor) << "subscript";
2655+
PrintWithColorRAII(OS, DeclColor) << " decl='";
26482656
printDeclRef(component.getDeclRef());
2649-
OS << '\n';
2650-
Indent += 2;
2651-
printRec(component.getIndexExpr());
2652-
Indent -= 2;
2653-
OS.indent(Indent + 4);
2657+
PrintWithColorRAII(OS, DeclColor) << "'";
26542658
break;
26552659

26562660
case KeyPathExpr::Component::Kind::UnresolvedProperty:
2657-
OS << "unresolved_property ";
2658-
component.getUnresolvedDeclName().print(OS);
2659-
OS << " ";
2661+
PrintWithColorRAII(OS, ASTNodeColor) << "unresolved_property";
2662+
PrintWithColorRAII(OS, IdentifierColor)
2663+
<< " decl_name='" << component.getUnresolvedDeclName() << "'";
26602664
break;
26612665

26622666
case KeyPathExpr::Component::Kind::UnresolvedSubscript:
2663-
OS << "unresolved_subscript";
2664-
OS << '\n';
2665-
Indent += 2;
2666-
printRec(component.getIndexExpr());
2667-
Indent -= 2;
2668-
OS.indent(Indent + 4);
2667+
PrintWithColorRAII(OS, ASTNodeColor) << "unresolved_subscript";
2668+
printArgumentLabels(component.getSubscriptLabels());
26692669
break;
26702670
case KeyPathExpr::Component::Kind::Identity:
2671-
OS << "identity";
2672-
OS << '\n';
2671+
PrintWithColorRAII(OS, ASTNodeColor) << "identity";
26732672
break;
2673+
26742674
case KeyPathExpr::Component::Kind::TupleElement:
2675-
OS << "tuple_element ";
2676-
OS << "#" << component.getTupleIndex();
2677-
OS << " ";
2675+
PrintWithColorRAII(OS, ASTNodeColor) << "tuple_element ";
2676+
PrintWithColorRAII(OS, DiscriminatorColor)
2677+
<< "#" << component.getTupleIndex();
26782678
break;
26792679
}
2680-
OS << "type=";
2681-
GetTypeOfKeyPathComponent(E, i).print(OS);
2680+
PrintWithColorRAII(OS, TypeColor)
2681+
<< " type='" << GetTypeOfKeyPathComponent(E, i) << "'";
2682+
if (auto indexExpr = component.getIndexExpr()) {
2683+
OS << '\n';
2684+
Indent += 2;
2685+
printRec(indexExpr);
2686+
Indent -= 2;
2687+
}
26822688
PrintWithColorRAII(OS, ParenthesisColor) << ')';
26832689
}
2690+
2691+
PrintWithColorRAII(OS, ParenthesisColor) << ')';
2692+
Indent -= 2;
2693+
26842694
if (auto stringLiteral = E->getObjCStringLiteralExpr()) {
26852695
OS << '\n';
2686-
printRec(stringLiteral);
2696+
printRecLabeled(stringLiteral, "objc_string_literal");
26872697
}
26882698
if (!E->isObjC()) {
2689-
OS << "\n";
26902699
if (auto root = E->getParsedRoot()) {
2691-
printRec(root);
2692-
} else {
2693-
OS.indent(Indent + 2) << "<<null>>";
2700+
OS << "\n";
2701+
printRecLabeled(root, "parsed_root");
26942702
}
2695-
OS << "\n";
26962703
if (auto path = E->getParsedPath()) {
2697-
printRec(path);
2698-
} else {
2699-
OS.indent(Indent + 2) << "<<null>>";
2704+
OS << "\n";
2705+
printRecLabeled(path, "parsed_path");
27002706
}
27012707
}
27022708
PrintWithColorRAII(OS, ParenthesisColor) << ')';

0 commit comments

Comments
 (0)