[gcc/devel/rust/master] dump: Add AST debugging using the AST::Dump class

Thomas Schwinge tschwinge@gcc.gnu.org
Wed Aug 31 10:41:15 GMT 2022


https://gcc.gnu.org/g:2bf4f17d1ff0dbfd5c21776f45094d518f01cd49

commit 2bf4f17d1ff0dbfd5c21776f45094d518f01cd49
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Mon Aug 29 13:37:00 2022 +0200

    dump: Add AST debugging using the AST::Dump class

Diff:
---
 gcc/rust/ast/rust-ast-dump.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
index 7dd38fe5e5b..a72bd4d1ff5 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -52,6 +52,22 @@ public:
   void go (AST::Crate &crate);
   void go (AST::Item &item);
 
+  /**
+   * Use the AST Dump as a debugging tool
+   */
+  template <typename T> static void debug (T &instance)
+  {
+    auto dump = Dump (std::cerr);
+
+    std::cerr << '\n';
+    instance.accept_vis (dump);
+    std::cerr << '\n';
+  }
+  template <typename T> static void debug (std::unique_ptr<T> &instance)
+  {
+    debug (*instance);
+  }
+
 private:
   std::ostream &stream;
   Indent indentation;


More information about the Gcc-cvs mailing list