steveire updated this revision to Diff 177419. steveire added a comment. Use std::string
Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55488/new/ https://reviews.llvm.org/D55488 Files: include/clang/AST/ASTDumperUtils.h lib/AST/ASTDumper.cpp Index: lib/AST/ASTDumper.cpp =================================================================== --- lib/AST/ASTDumper.cpp +++ lib/AST/ASTDumper.cpp @@ -62,6 +62,10 @@ template<typename Fn> void dumpChild(Fn doDumpChild) { TreeStructure.addChild(doDumpChild); } + template <typename Fn> + 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 << "<<<NULL>>>"; @@ -1952,10 +1956,7 @@ NodeDumper.dumpBareDeclRef(Field); } if (auto *Filler = ILE->getArrayFiller()) { - dumpChild([=] { - OS << "array filler"; - dumpStmt(Filler); - }); + dumpStmt(Filler, "array filler"); } } 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 <typename Fn> + 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 <typename Fn> 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<typename Fn> void dumpChild(Fn doDumpChild) { TreeStructure.addChild(doDumpChild); } + template <typename Fn> + 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 << "<<<NULL>>>"; @@ -1952,10 +1956,7 @@ NodeDumper.dumpBareDeclRef(Field); } if (auto *Filler = ILE->getArrayFiller()) { - dumpChild([=] { - OS << "array filler"; - dumpStmt(Filler); - }); + dumpStmt(Filler, "array filler"); } } 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 <typename Fn> + 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 <typename Fn> void addChild(Fn doAddChild) { // If we're at the top level, there's nothing interesting to do; just
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits