From: Pierre-Emmanuel Patry <[email protected]>

A crate is not a visitable and thus cannot be used with the debug
function. Until it is made visitable this commit provides a function
to dump the content of a crate.

gcc/rust/ChangeLog:

        * ast/rust-ast-dump.cc (debug): Add debug function which calls debug
        on every crate field.
        * ast/rust-ast-dump.h (debug): Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/dda673d7a57cbe3f392b6458004177416ac6b6b2

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4425

 gcc/rust/ast/rust-ast-dump.cc | 13 +++++++++++++
 gcc/rust/ast/rust-ast-dump.h  |  1 +
 2 files changed, 14 insertions(+)

diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index a30e85ed0..e813ea9d7 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -105,3 +105,16 @@ debug (Rust::AST::Visitable &v)
 {
   Rust::AST::Dump::debug (v);
 }
+
+void
+debug (Rust::AST::Crate &crate)
+{
+  for (auto &inner_attr : crate.get_inner_attrs ())
+    {
+      debug (inner_attr);
+    }
+  for (auto &item : crate.items)
+    {
+      debug (*item);
+    }
+}
diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
index 497f84aae..cb281de8e 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -143,5 +143,6 @@ private:
 
 // In the global namespace to make it easier to call from debugger
 void debug (Rust::AST::Visitable &v);
+void debug (Rust::AST::Crate &v);
 
 #endif // !RUST_AST_DUMP_H
-- 
2.53.0

Reply via email to