diff options
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-implitem.h | 53 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.h | 49 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-toplevel.h | 8 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve.cc | 4 |
4 files changed, 114 insertions, 0 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h index 2b3a09a..6437be2 100644 --- a/gcc/rust/resolve/rust-ast-resolve-implitem.h +++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h @@ -201,6 +201,59 @@ private: const CanonicalPath &prefix; }; +class ResolveToplevelExternItem : public ResolverBase +{ + using Rust::Resolver::ResolverBase::visit; + +public: + static void go (AST::ExternalItem *item, + const CanonicalPath &prefix = CanonicalPath::create_empty ()) + { + ResolveToplevelExternItem resolver (prefix); + item->accept_vis (resolver); + }; + + void visit (AST::ExternalFunctionItem &function) override + { + auto path + = prefix.append (CanonicalPath::new_seg (function.get_node_id (), + function.get_identifier ())); + resolver->get_name_scope ().insert ( + path, function.get_node_id (), function.get_locus (), false, + [&] (const CanonicalPath &, NodeId, Location locus) -> void { + RichLocation r (function.get_locus ()); + r.add_range (locus); + rust_error_at (r, "redefined multiple times"); + }); + resolver->insert_new_definition (function.get_node_id (), + Definition{function.get_node_id (), + function.get_node_id ()}); + } + + void visit (AST::ExternalStaticItem &item) override + { + auto path = prefix.append ( + CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ())); + resolver->get_name_scope ().insert ( + path, item.get_node_id (), item.get_locus (), false, + [&] (const CanonicalPath &, NodeId, Location locus) -> void { + RichLocation r (item.get_locus ()); + r.add_range (locus); + rust_error_at (r, "redefined multiple times"); + }); + resolver->insert_new_definition (item.get_node_id (), + Definition{item.get_node_id (), + item.get_node_id ()}); + } + +private: + ResolveToplevelExternItem (const CanonicalPath &prefix) + : ResolverBase (UNKNOWN_NODEID), prefix (prefix) + {} + + const CanonicalPath &prefix; +}; + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h index 0714f5d..ccf3872 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.h +++ b/gcc/rust/resolve/rust-ast-resolve-item.h @@ -521,10 +521,19 @@ public: resolver->get_name_scope ().pop (); } + void visit (AST::ExternBlock &extern_block) override + { + for (auto &item : extern_block.get_extern_items ()) + { + resolve_extern_item (item.get ()); + } + } + protected: void resolve_impl_item (AST::TraitImplItem *item, const CanonicalPath &self); void resolve_impl_item (AST::InherentImplItem *item, const CanonicalPath &self); + void resolve_extern_item (AST::ExternalItem *item); ResolveItem () : ResolverBase (UNKNOWN_NODEID) {} }; @@ -572,6 +581,46 @@ private: const CanonicalPath &self; }; +class ResolveExternItem : public ResolverBase +{ + using Rust::Resolver::ResolverBase::visit; + +public: + static void go (AST::ExternalItem *item) + { + ResolveExternItem resolver; + item->accept_vis (resolver); + }; + + void visit (AST::ExternalFunctionItem &function) override + { + if (function.has_generics ()) + { + for (auto &generic : function.get_generic_params ()) + ResolveGenericParam::go (generic.get (), function.get_node_id ()); + } + + if (function.has_return_type ()) + ResolveType::go (function.get_return_type ().get (), + function.get_node_id ()); + + // we make a new scope so the names of parameters are resolved and shadowed + // correctly + for (auto ¶m : function.get_function_params ()) + { + ResolveType::go (param.get_type ().get (), param.get_node_id ()); + } + } + + void visit (AST::ExternalStaticItem &item) override + { + ResolveType::go (item.get_type ().get (), item.get_node_id ()); + } + +private: + ResolveExternItem () : ResolverBase (UNKNOWN_NODEID) {} +}; // namespace Resolver + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index 9abbb18..a042f5c 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -191,6 +191,14 @@ public: ResolveTopLevelTraitItems::go (item.get (), path); } + void visit (AST::ExternBlock &extern_block) override + { + for (auto &item : extern_block.get_extern_items ()) + { + ResolveToplevelExternItem::go (item.get (), prefix); + } + } + private: ResolveTopLevel (const CanonicalPath &prefix) : ResolverBase (UNKNOWN_NODEID), prefix (prefix) diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc index 18047db..9cc833f 100644 --- a/gcc/rust/resolve/rust-ast-resolve.cc +++ b/gcc/rust/resolve/rust-ast-resolve.cc @@ -635,5 +635,9 @@ ResolveItem::resolve_impl_item (AST::InherentImplItem *item, ResolveImplItems::go (item, self); } +void +ResolveItem::resolve_extern_item (AST::ExternalItem *item) +{} + } // namespace Resolver } // namespace Rust |