diff mbox series

[024/125] gccrs: extern-types: Declare external types in name resolver.

Message ID 20240801145809.366388-26-arthur.cohen@embecosm.com
State New
Headers show
Series [001/125] Rust: Make 'tree'-level 'MAIN_NAME_P' work | expand

Commit Message

Arthur Cohen Aug. 1, 2024, 2:56 p.m. UTC
gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-implitem.h: Declare external types as new
	types.
---
 gcc/rust/resolve/rust-ast-resolve-implitem.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h
index fabc25817f5..4f4d2893f83 100644
--- a/gcc/rust/resolve/rust-ast-resolve-implitem.h
+++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h
@@ -228,6 +228,25 @@  public:
     mappings->insert_module_child_item (current_module, decl);
   }
 
+  void visit (AST::ExternalTypeItem &type) override
+  {
+    auto decl = CanonicalPath::new_seg (type.get_node_id (),
+					type.get_identifier ().as_string ());
+    auto path = prefix.append (decl);
+
+    resolver->get_type_scope ().insert (
+      path, type.get_node_id (), type.get_locus (), false, Rib::ItemType::Type,
+      [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
+	rich_location r (line_table, type.get_locus ());
+	r.add_range (locus);
+
+	rust_error_at (r, "redefined multiple times");
+      });
+
+    NodeId current_module = resolver->peek_current_module_scope ();
+    mappings->insert_module_child_item (current_module, decl);
+  }
+
 private:
   ResolveToplevelExternItem (const CanonicalPath &prefix)
     : ResolverBase (), prefix (prefix)