steveire updated this revision to Diff 177594.
steveire marked an inline comment as done.
steveire added a comment.

Update with new approach


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
  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
@@ -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); }
@@ -1697,8 +1701,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>>>";
@@ -1964,10 +1968,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,8 +109,16 @@
   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 with a label.
+  /// Calls doAddChild without arguments
+  template <typename Fn>
+  void addChild(const std::string &Label, Fn doAddChild) {
+    return addChild(doAddChild, Label);
+  }
+  /// Add a child of the current node with an optional label.
+  /// Calls doAddChild without arguments.
+  template <typename Fn>
+  void addChild(Fn doAddChild, const std::string &Label = "") {
     // If we're at the top level, there's nothing interesting to do; just
     // run the dumper.
     if (TopLevel) {
@@ -126,7 +134,7 @@
       return;
     }
 
-    auto dumpWithIndent = [this, doAddChild](bool isLastChild) {
+    auto dumpWithIndent = [this, doAddChild, Label](bool isLastChild) {
       // Print out the appropriate tree structure and work out the prefix for
       // children of this node. For instance:
       //
@@ -143,6 +151,10 @@
         OS << '\n';
         ColorScope Color(OS, ShowColors, IndentColor);
         OS << Prefix << (isLastChild ? '`' : '|') << '-';
+        if (!Label.empty()) {
+          OS << Label << ": ";
+        }
+
         this->Prefix.push_back(isLastChild ? ' ' : '|');
         this->Prefix.push_back(' ');
       }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to