From c47cae71d32fa580572a5284e677590ed7cd9509 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Mon, 28 Aug 2023 16:40:12 +0200 Subject: gccrs: late: Setup builtin types properly, change Rib API gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Start using Rib::Definition for shadowable information. * resolve/rust-late-name-resolver-2.0.cc (next_node_id): New. (next_hir_id): New. (Late::setup_builtin_types): Improve builtin type setup. * resolve/rust-rib.cc (Rib::Definition::Definition): New constructor. (Rib::Definition::Shadowable): Likewise. (Rib::Definition::NonShadowable): Likewise. (Rib::Rib): Fix general constructor. (Rib::insert): Use Definition class. (Rib::get): Likewise. * resolve/rust-rib.h: New Definition class, new prototypes. --- gcc/rust/resolve/rust-forever-stack.hxx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'gcc/rust/resolve/rust-forever-stack.hxx') diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index 0aa9943..a2fdce9 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -100,9 +100,9 @@ ForeverStack::pop () } static tl::expected -insert_inner (Rib &rib, std::string name, NodeId node, bool can_shadow) +insert_inner (Rib &rib, std::string name, Rib::Definition definition) { - return rib.insert (name, node, can_shadow); + return rib.insert (name, definition); } template @@ -115,7 +115,8 @@ ForeverStack::insert (Identifier name, NodeId node) // pass, we might end up in a situation where it is okay to re-add new names. // Do we just ignore that here? Do we keep track of if the Rib is new or not? // should our cursor have info on the current node like "is it newly pushed"? - return insert_inner (innermost_rib, name.as_string (), node, false); + return insert_inner (innermost_rib, name.as_string (), + Rib::Definition::NonShadowable (node)); } template @@ -126,7 +127,8 @@ ForeverStack::insert_at_root (Identifier name, NodeId node) // inserting in the root of the crate is never a shadowing operation, even for // macros - return insert_inner (root_rib, name.as_string (), node, false); + return insert_inner (root_rib, name.as_string (), + Rib::Definition::NonShadowable (node)); } // Specialization for Macros and Labels - where we are allowed to shadow @@ -135,14 +137,16 @@ template <> inline tl::expected ForeverStack::insert (Identifier name, NodeId node) { - return insert_inner (peek (), name.as_string (), node, true); + return insert_inner (peek (), name.as_string (), + Rib::Definition::Shadowable (node)); } template <> inline tl::expected ForeverStack::insert (Identifier name, NodeId node) { - return insert_inner (peek (), name.as_string (), node, true); + return insert_inner (peek (), name.as_string (), + Rib::Definition::Shadowable (node)); } template @@ -455,10 +459,10 @@ template tl::optional::Node &, std::string>> ForeverStack::dfs (ForeverStack::Node &starting_point, NodeId to_find) { - auto &values = starting_point.rib.get_values (); + auto values = starting_point.rib.get_values (); for (auto &kv : values) - if (kv.second == to_find) + if (kv.second.id == to_find) return {{starting_point, kv.first}}; for (auto &child : starting_point.children) @@ -568,7 +572,7 @@ ForeverStack::stream_rib (std::stringstream &stream, const Rib &rib, stream << next << "rib: {\n"; for (const auto &kv : rib.get_values ()) - stream << next_next << kv.first << ": " << kv.second << "\n"; + stream << next_next << kv.first << ": " << kv.second.id << "\n"; stream << next << "},\n"; } -- cgit v1.1