[PATCH] D55488: Add utility for dumping a label with child nodes

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 9 06:08:21 PST 2018


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55488.177419.patch
Type: text/x-patch
Size: 2199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181209/24a9fc42/attachment-0001.bin>


More information about the cfe-commits mailing list