Index: include/clang/AST/ASTDumperUtils.h =================================================================== --- include/clang/AST/ASTDumperUtils.h +++ include/clang/AST/ASTDumperUtils.h @@ -109,6 +109,17 @@ std::string Prefix; public: + /// Add a child of the current node with a label. + /// Calls doAddChild without arguments + template + void addChild(const std::string &label, Fn doAddChild) { + if (label.empty()) + return addChild(doAddChild); + addChild([=] { + OS << label; + addChild(doAddChild); + }); + } /// Add a child of the current node. Calls doAddChild without arguments template void addChild(Fn doAddChild) { // If we're at the top level, there's nothing interesting to do; just Index: lib/AST/ASTDumper.cpp =================================================================== --- lib/AST/ASTDumper.cpp +++ lib/AST/ASTDumper.cpp @@ -62,6 +62,10 @@ template void dumpChild(Fn doDumpChild) { TreeStructure.addChild(doDumpChild); } + template + void dumpChild(const std::string &label, Fn doDumpChild) { + TreeStructure.addChild(label, doDumpChild); + } public: ASTDumper(raw_ostream &OS, const CommandTraits *Traits, @@ -82,7 +86,7 @@ void setDeserialize(bool D) { Deserialize = D; } void dumpDecl(const Decl *D); - void dumpStmt(const Stmt *S); + void dumpStmt(const Stmt *S, const std::string &label = {}); // Utilities void dumpType(QualType T) { NodeDumper.dumpType(T); } @@ -1685,8 +1689,8 @@ // Stmt dumping methods. //===----------------------------------------------------------------------===// -void ASTDumper::dumpStmt(const Stmt *S) { - dumpChild([=] { +void ASTDumper::dumpStmt(const Stmt *S, const std::string &label) { + dumpChild(label, [=] { if (!S) { ColorScope Color(OS, ShowColors, NullColor); OS << "<<>>"; @@ -1952,10 +1956,7 @@ NodeDumper.dumpBareDeclRef(Field); } if (auto *Filler = ILE->getArrayFiller()) { - dumpChild([=] { - OS << "array filler"; - dumpStmt(Filler); - }); + dumpStmt(Filler, "array filler"); } }