diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc index 8aef313af7a1e..5ac076a1fb934 100644 --- a/gcc/rust/resolve/rust-ast-resolve.cc +++ b/gcc/rust/resolve/rust-ast-resolve.cc @@ -54,6 +54,7 @@ Resolver::Resolver () name_scope (Scope (mappings->get_current_crate ())), type_scope (Scope (mappings->get_current_crate ())), label_scope (Scope (mappings->get_current_crate ())), + macro_scope (Scope (mappings->get_current_crate ())), global_type_node_id (UNKNOWN_NODEID), unit_ty_node_id (UNKNOWN_NODEID) { generate_builtins (); @@ -93,6 +94,13 @@ Resolver::push_new_label_rib (Rib *r) label_ribs[r->get_node_id ()] = r; } +void +Resolver::push_new_macro_rib (Rib *r) +{ + rust_assert (label_ribs.find (r->get_node_id ()) == label_ribs.end ()); + macro_ribs[r->get_node_id ()] = r; +} + bool Resolver::find_name_rib (NodeId id, Rib **rib) { @@ -115,6 +123,17 @@ Resolver::find_type_rib (NodeId id, Rib **rib) return true; } +bool +Resolver::find_macro_rib (NodeId id, Rib **rib) +{ + auto it = macro_ribs.find (id); + if (it == macro_ribs.end ()) + return false; + + *rib = it->second; + return true; +} + void Resolver::insert_builtin_types (Rib *r) { @@ -281,6 +300,27 @@ Resolver::lookup_resolved_label (NodeId refId, NodeId *defId) return true; } +void +Resolver::insert_resolved_macro (NodeId refId, NodeId defId) +{ + auto it = resolved_macros.find (refId); + rust_assert (it == resolved_macros.end ()); + + resolved_labels[refId] = defId; + get_label_scope ().append_reference_for_def (refId, defId); +} + +bool +Resolver::lookup_resolved_macro (NodeId refId, NodeId *defId) +{ + auto it = resolved_macros.find (refId); + if (it == resolved_macros.end ()) + return false; + + *defId = it->second; + return true; +} + // NameResolution NameResolution * diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index 199b0f98bd895..208448036d904 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -274,10 +274,12 @@ class Resolver void push_new_name_rib (Rib *r); void push_new_type_rib (Rib *r); void push_new_label_rib (Rib *r); + void push_new_macro_rib (Rib *r); bool find_name_rib (NodeId id, Rib **rib); bool find_type_rib (NodeId id, Rib **rib); bool find_label_rib (NodeId id, Rib **rib); + bool find_macro_rib (NodeId id, Rib **rib); void insert_new_definition (NodeId id, Definition def); bool lookup_definition (NodeId id, Definition *def); @@ -291,10 +293,14 @@ class Resolver void insert_resolved_label (NodeId refId, NodeId defId); bool lookup_resolved_label (NodeId refId, NodeId *defId); + void insert_resolved_macro (NodeId refId, NodeId defId); + bool lookup_resolved_macro (NodeId refId, NodeId *defId); + // proxy for scoping Scope &get_name_scope () { return name_scope; } Scope &get_type_scope () { return type_scope; } Scope &get_label_scope () { return label_scope; } + Scope &get_macro_scope () { return macro_scope; } NodeId get_global_type_node_id () { return global_type_node_id; } @@ -371,6 +377,7 @@ class Resolver Scope name_scope; Scope type_scope; Scope label_scope; + Scope macro_scope; NodeId global_type_node_id; NodeId unit_ty_node_id; @@ -379,6 +386,7 @@ class Resolver std::map name_ribs; std::map type_ribs; std::map label_ribs; + std::map macro_ribs; // map any Node to its Definition // ie any name or type usage @@ -395,6 +403,7 @@ class Resolver std::map resolved_names; std::map resolved_types; std::map resolved_labels; + std::map resolved_macros; // map of resolved names mutability flag std::map decl_mutability;