Index: include/clang/AST/TextNodeDumper.h =================================================================== --- include/clang/AST/TextNodeDumper.h +++ include/clang/AST/TextNodeDumper.h @@ -39,8 +39,16 @@ std::string Prefix; public: - /// Add a child of the current node. Calls doAddChild without arguments - template void addChild(Fn doAddChild) { + /// Add a child of the current node. + /// Calls doAddChild without arguments + template + void addChild(Fn doAddChild) { + return addChild("", doAddChild); + } + /// Add a child of the current node with an optional label. + /// Calls doAddChild without arguments. + template + void addChild(StringRef Label, Fn doAddChild) { // If we're at the top level, there's nothing interesting to do; just // run the dumper. if (TopLevel) { @@ -56,7 +64,10 @@ return; } - auto dumpWithIndent = [this, doAddChild](bool isLastChild) { + // We need to capture an owning-string in the lambda because the lambda + // is invoked in a deffered manner. + std::string LabelStr = Label; + auto dumpWithIndent = [this, doAddChild, LabelStr](bool isLastChild) { // Print out the appropriate tree structure and work out the prefix for // children of this node. For instance: // @@ -73,6 +84,10 @@ OS << '\n'; ColorScope Color(OS, ShowColors, IndentColor); OS << Prefix << (isLastChild ? '`' : '|') << '-'; + if (!LabelStr.empty()) { + OS << LabelStr << ": "; + } + this->Prefix.push_back(isLastChild ? ' ' : '|'); this->Prefix.push_back(' '); } Index: lib/AST/ASTDumper.cpp =================================================================== --- lib/AST/ASTDumper.cpp +++ lib/AST/ASTDumper.cpp @@ -61,6 +61,10 @@ template void dumpChild(Fn doDumpChild) { NodeDumper.addChild(doDumpChild); } + template + void dumpChild(StringRef Label, Fn doDumpChild) { + NodeDumper.addChild(Label, doDumpChild); + } public: ASTDumper(raw_ostream &OS, const CommandTraits *Traits, @@ -80,7 +84,7 @@ void setDeserialize(bool D) { Deserialize = D; } void dumpDecl(const Decl *D); - void dumpStmt(const Stmt *S); + void dumpStmt(const Stmt *S, StringRef 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, StringRef Label) { + dumpChild(Label, [=] { if (!S) { ColorScope Color(OS, ShowColors, NullColor); OS << "<<>>"; @@ -1957,10 +1961,7 @@ NodeDumper.dumpBareDeclRef(Field); } if (auto *Filler = ILE->getArrayFiller()) { - dumpChild([=] { - OS << "array filler"; - dumpStmt(Filler); - }); + dumpStmt(Filler, "array_filler"); } } Index: test/AST/ast-dump-stmt.cpp =================================================================== --- test/AST/ast-dump-stmt.cpp +++ test/AST/ast-dump-stmt.cpp @@ -91,8 +91,7 @@ U us[3] = {1}; // CHECK: VarDecl {{.+}} col:5 us 'U [3]' cinit // CHECK-NEXT: `-InitListExpr {{.+}} 'U [3]' -// CHECK-NEXT: |-array filler -// CHECK-NEXT: | `-InitListExpr {{.+}} 'U' field Field {{.+}} 'i' 'int' +// CHECK-NEXT: |-array_filler: InitListExpr {{.+}} 'U' field Field {{.+}} 'i' 'int' // CHECK-NEXT: `-InitListExpr {{.+}} 'U' field Field {{.+}} 'i' 'int' // CHECK-NEXT: `-IntegerLiteral {{.+}} 'int' 1 }