[committed,037/103] gccrs: ast: Module: unloaded module and inner attributes

Message ID 20230221120230.596966-38-arthur.cohen@embecosm.com
State Unresolved
Headers
Series [committed,001/103] gccrs: Fix missing dead code analysis ICE on local enum definition |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Arthur Cohen Feb. 21, 2023, 12:01 p.m. UTC
  From: Jakub Dupak <dev@jakubdupak.com>

gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Properly handle unloaded modules.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
---
 gcc/rust/ast/rust-ast-dump.cc | 41 +++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 9 deletions(-)
  

Patch

diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index 1e7a235932d..a12c3922c47 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -810,21 +810,44 @@  Dump::visit (Method &method)
 void
 Dump::visit (Module &module)
 {
-  emit_visibility (module.get_visibility ());
-  stream << "mod " << module.get_name () << " {\n";
+  //  Syntax:
+  //	mod IDENTIFIER ;
+  //     | mod IDENTIFIER {
+  //	  InnerAttribute*
+  //	  Item*
+  //	}
 
-  indentation.increment ();
+  emit_visibility (module.get_visibility ());
+  stream << "mod " << module.get_name ();
 
-  for (auto &item : module.get_items ())
+  if (module.get_kind () == Module::UNLOADED)
     {
-      stream << indentation;
-      item->accept_vis (*this);
-      stream << '\n';
+      stream << ";\n";
     }
+  else /* Module::LOADED */
+    {
+      stream << " {\n";
 
-  indentation.decrement ();
+      indentation.increment ();
 
-  stream << indentation << "}\n";
+      for (auto &item : module.get_inner_attrs ())
+	{
+	  stream << indentation;
+	  emit_attrib (item);
+	  stream << '\n';
+	}
+
+      for (auto &item : module.get_items ())
+	{
+	  stream << indentation;
+	  item->accept_vis (*this);
+	  stream << '\n';
+	}
+
+      indentation.decrement ();
+
+      stream << indentation << "}\n";
+    }
 }
 
 void