steveire updated this revision to Diff 180935. steveire added a comment. Nits
Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55488/new/ https://reviews.llvm.org/D55488 Files: include/clang/AST/TextNodeDumper.h lib/AST/ASTDumper.cpp test/AST/ast-dump-stmt.cpp
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:3, col:15> col:5 us 'U [3]' cinit // CHECK-NEXT: `-InitListExpr {{.+}} <col:13, col:15> 'U [3]' -// CHECK-NEXT: |-array filler -// CHECK-NEXT: | `-InitListExpr {{.+}} <col:15> 'U' field Field {{.+}} 'i' 'int' +// CHECK-NEXT: |-array_filler: InitListExpr {{.+}} <col:15> 'U' field Field {{.+}} 'i' 'int' // CHECK-NEXT: `-InitListExpr {{.+}} <col:14> 'U' field Field {{.+}} 'i' 'int' // CHECK-NEXT: `-IntegerLiteral {{.+}} <col:14> 'int' 1 } Index: lib/AST/ASTDumper.cpp =================================================================== --- lib/AST/ASTDumper.cpp +++ lib/AST/ASTDumper.cpp @@ -61,6 +61,9 @@ template<typename Fn> void dumpChild(Fn doDumpChild) { NodeDumper.addChild(doDumpChild); } + template <typename Fn> void dumpChild(StringRef Label, Fn doDumpChild) { + NodeDumper.addChild(Label, doDumpChild); + } public: ASTDumper(raw_ostream &OS, const CommandTraits *Traits, @@ -80,7 +83,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 +1688,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 << "<<<NULL>>>"; @@ -1957,10 +1960,7 @@ NodeDumper.dumpBareDeclRef(Field); } if (auto *Filler = ILE->getArrayFiller()) { - dumpChild([=] { - OS << "array filler"; - dumpStmt(Filler); - }); + dumpStmt(Filler, "array_filler"); } } Index: include/clang/AST/TextNodeDumper.h =================================================================== --- include/clang/AST/TextNodeDumper.h +++ include/clang/AST/TextNodeDumper.h @@ -27,7 +27,7 @@ const bool ShowColors; /// Pending[i] is an action to dump an entity at level i. - llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending; + llvm::SmallVector<std::function<void(bool IsLastChild)>, 32> Pending; /// Indicates whether we're at the top level. bool TopLevel = true; @@ -39,13 +39,19 @@ std::string Prefix; public: - /// Add a child of the current node. Calls doAddChild without arguments - template <typename Fn> void addChild(Fn doAddChild) { + /// Add a child of the current node. Calls DoAddChild without arguments. + template <typename Fn> void addChild(Fn DoAddChild) { + return addChild("", DoAddChild); + } + + /// Add a child of the current node with an optional label. + /// Calls DoAddChild without arguments. + template <typename Fn> 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) { TopLevel = false; - doAddChild(); + DoAddChild(); while (!Pending.empty()) { Pending.back()(true); Pending.pop_back(); @@ -56,7 +62,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 deferred 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: // @@ -72,15 +81,18 @@ { OS << '\n'; ColorScope Color(OS, ShowColors, IndentColor); - OS << Prefix << (isLastChild ? '`' : '|') << '-'; - this->Prefix.push_back(isLastChild ? ' ' : '|'); + OS << Prefix << (IsLastChild ? '`' : '|') << '-'; + if (!LabelStr.empty()) + OS << LabelStr << ": "; + + this->Prefix.push_back(IsLastChild ? ' ' : '|'); this->Prefix.push_back(' '); } FirstChild = true; unsigned Depth = Pending.size(); - doAddChild(); + DoAddChild(); // If any children are left, they're the last at their nesting level. // Dump those ones out now. @@ -94,10 +106,10 @@ }; if (FirstChild) { - Pending.push_back(std::move(dumpWithIndent)); + Pending.push_back(std::move(DumpWithIndent)); } else { Pending.back()(false); - Pending.back() = std::move(dumpWithIndent); + Pending.back() = std::move(DumpWithIndent); } FirstChild = false; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits