]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: dump: Add AST debugging using the AST::Dump class
authorArthur Cohen <arthur.cohen@embecosm.com>
Mon, 29 Aug 2022 11:37:00 +0000 (13:37 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 31 Jan 2023 13:16:50 +0000 (14:16 +0100)
gcc/rust/ChangeLog:

* ast/rust-ast-dump.h: Add shorthand `AST::Dump::debug` function to
dump an AST node on `stderr`.

gcc/rust/ast/rust-ast-dump.h

index 4fa4db9265f0d5e4180f95456df69cbb745e2f84..955dbc0bebc4aa42afaee5208ada27d6cb732ab0 100644 (file)
@@ -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;