From 32a4659c5e405771dc8c83568b30efefc77a2031 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Fri, 21 Oct 2022 12:54:52 +0100 Subject: gccrs: Refactor name resolver to take a Rib::ItemType This allows us to track the type of declaration that is stored within a Rib. gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Add Rib argument. (ResolveExpr::resolve_closure_param): Likewise. * resolve/rust-ast-resolve-implitem.h: Likewise. * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise. (ResolveItem::visit): Likewise. * resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Likewise. * resolve/rust-ast-resolve-pattern.h: Likewise. * resolve/rust-ast-resolve-stmt.h: Likewise. * resolve/rust-ast-resolve-toplevel.h: Likewise. * resolve/rust-ast-resolve-type.h: Likewise. * resolve/rust-name-resolver.cc (Rib::lookup_decl_type): Likewise. (Scope::insert): Likewise. (Resolver::insert_builtin_types): Likewise. * resolve/rust-name-resolver.h: Likewise. --- gcc/rust/resolve/rust-ast-resolve-toplevel.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'gcc/rust/resolve/rust-ast-resolve-toplevel.h') diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index 4cc5101..d751318 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -57,6 +57,7 @@ public: resolver->get_name_scope ().insert ( path, module.get_node_id (), module.get_locus (), false, + Rib::ItemType::Module, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (module.get_locus ()); r.add_range (locus); @@ -85,6 +86,7 @@ public: resolver->get_type_scope ().insert ( path, alias.get_node_id (), alias.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (alias.get_locus ()); r.add_range (locus); @@ -105,6 +107,7 @@ public: resolver->get_type_scope ().insert ( path, struct_decl.get_node_id (), struct_decl.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (struct_decl.get_locus ()); r.add_range (locus); @@ -125,6 +128,7 @@ public: resolver->get_type_scope ().insert ( path, enum_decl.get_node_id (), enum_decl.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (enum_decl.get_locus ()); r.add_range (locus); @@ -147,7 +151,7 @@ public: auto cpath = canonical_prefix.append (decl); resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, + path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); @@ -165,7 +169,7 @@ public: auto cpath = canonical_prefix.append (decl); resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, + path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); @@ -183,7 +187,7 @@ public: auto cpath = canonical_prefix.append (decl); resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, + path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); @@ -201,7 +205,7 @@ public: auto cpath = canonical_prefix.append (decl); resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, + path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); @@ -220,6 +224,7 @@ public: resolver->get_type_scope ().insert ( path, struct_decl.get_node_id (), struct_decl.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (struct_decl.get_locus ()); r.add_range (locus); @@ -240,6 +245,7 @@ public: resolver->get_type_scope ().insert ( path, union_decl.get_node_id (), union_decl.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (union_decl.get_locus ()); r.add_range (locus); @@ -259,7 +265,7 @@ public: auto cpath = canonical_prefix.append (decl); resolver->get_name_scope ().insert ( - path, var.get_node_id (), var.get_locus (), false, + path, var.get_node_id (), var.get_locus (), false, Rib::ItemType::Static, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (var.get_locus ()); r.add_range (locus); @@ -280,6 +286,7 @@ public: resolver->get_name_scope ().insert ( path, constant.get_node_id (), constant.get_locus (), false, + Rib::ItemType::Const, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (constant.get_locus ()); r.add_range (locus); @@ -300,6 +307,7 @@ public: resolver->get_name_scope ().insert ( path, function.get_node_id (), function.get_locus (), false, + Rib::ItemType::Function, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (function.get_locus ()); r.add_range (locus); @@ -343,6 +351,7 @@ public: resolver->get_name_scope ().insert ( impl_prefix, impl_block.get_node_id (), impl_block.get_locus (), false, + Rib::ItemType::TraitImpl, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (impl_block.get_locus ()); r.add_range (locus); @@ -362,6 +371,7 @@ public: resolver->get_type_scope ().insert ( path, trait.get_node_id (), trait.get_locus (), false, + Rib::ItemType::Trait, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (trait.get_locus ()); r.add_range (locus); @@ -437,6 +447,7 @@ public: resolver->get_type_scope ().insert ( decl, resolved_crate, extern_crate.get_locus (), false, + Rib::ItemType::ExternCrate, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (extern_crate.get_locus ()); r.add_range (locus); -- cgit v1.1