Index: include/clang/AST/ASTDumperUtils.h =================================================================== --- include/clang/AST/ASTDumperUtils.h +++ include/clang/AST/ASTDumperUtils.h @@ -109,6 +109,16 @@ std::string Prefix; public: + /// Add a child of the current node with a label. + /// Calls doAddChild without arguments + template void addChild(const char *label, Fn doAddChild) { + if (!label) + 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 @@ -63,6 +63,9 @@ template void dumpChild(Fn doDumpChild) { TreeStructure.addChild(doDumpChild); } + template void dumpChild(const char *label, Fn doDumpChild) { + TreeStructure.addChild(label, doDumpChild); + } public: ASTDumper(raw_ostream &OS, const CommandTraits *Traits, @@ -83,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 char *label = nullptr); // Utilities void dumpType(QualType T) { NodeDumper.dumpType(T); } @@ -1711,8 +1714,8 @@ // Stmt dumping methods. //===----------------------------------------------------------------------===// -void ASTDumper::dumpStmt(const Stmt *S) { - dumpChild([=] { +void ASTDumper::dumpStmt(const Stmt *S, const char *label) { + dumpChild(label, [=] { if (!S) { ColorScope Color(OS, ShowColors, NullColor); OS << "<<>>"; @@ -1978,10 +1981,7 @@ NodeDumper.dumpBareDeclRef(Field); } if (auto *Filler = ILE->getArrayFiller()) { - dumpChild([=] { - OS << "array filler"; - dumpStmt(Filler); - }); + dumpStmt(Filler, "array filler"); } }