From 9a64b915537ae5d13819e5e122735f4020d93905 Mon Sep 17 00:00:00 2001 From: jjasmine Date: Wed, 8 May 2024 09:47:47 -0700 Subject: [PATCH] MacroInvoc Refactor Remove get_macro_node_id in favor of get_node_id in MacroInvocation Add ExteralItem node_id constructor to avoid extra get_node_id() gcc/rust/ChangeLog: * ast/rust-macro.h: Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. * util/rust-hir-map.cc (Mappings::insert_macro_invocation): Likewise. (Mappings::lookup_macro_invocation): Likewise. (Mappings::insert_bang_proc_macro_invocation): Likewise. (Mappings::lookup_bang_proc_macro_invocation): Likewise. --- gcc/rust/ast/rust-macro.h | 13 +++++-------- gcc/rust/resolve/rust-early-name-resolver.cc | 2 +- gcc/rust/util/rust-hir-map.cc | 12 ++++++------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 5300b59f5d3a..8d2cb26ea1ba 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -672,18 +672,13 @@ class MacroInvocation : public TypeNoBounds, outer_attrs = std::move (new_attrs); } - NodeId get_node_id () const override final - { - return ExprWithoutBlock::get_node_id (); - } + NodeId get_node_id () const override final { return node_id; } AST::Kind get_ast_kind () const override { return AST::Kind::MACRO_INVOCATION; } - NodeId get_macro_node_id () const { return node_id; } - MacroInvocData &get_invoc_data () { return invoc_data; } bool has_semicolon () const { return is_semi_coloned; } @@ -719,8 +714,10 @@ class MacroInvocation : public TypeNoBounds, MacroInvocData invoc_data, std::vector outer_attrs, location_t locus, bool is_semi_coloned, std::vector> &&pending_eager_invocs) - : TraitItem (locus), outer_attrs (std::move (outer_attrs)), locus (locus), - node_id (Analysis::Mappings::get ().get_next_node_id ()), + : TraitItem (locus), + ExternalItem (Analysis::Mappings::get ().get_next_node_id ()), + outer_attrs (std::move (outer_attrs)), locus (locus), + node_id (ExternalItem::get_node_id ()), invoc_data (std::move (invoc_data)), is_semi_coloned (is_semi_coloned), kind (kind), builtin_kind (builtin_kind), pending_eager_invocs (std::move (pending_eager_invocs)) diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc index 83b6576fe69a..e61d162e7ad9 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.cc +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -466,7 +466,7 @@ EarlyNameResolver::visit (AST::MacroInvocation &invoc) NodeId resolved_node = UNKNOWN_NODEID; NodeId source_node = UNKNOWN_NODEID; if (has_semicolon) - source_node = invoc.get_macro_node_id (); + source_node = invoc.get_node_id (); else source_node = invoc.get_node_id (); auto seg diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 8b09d9d318e0..75a48b40c70d 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -913,17 +913,17 @@ void Mappings::insert_macro_invocation (AST::MacroInvocation &invoc, AST::MacroRulesDefinition *def) { - auto it = macroInvocations.find (invoc.get_macro_node_id ()); + auto it = macroInvocations.find (invoc.get_node_id ()); rust_assert (it == macroInvocations.end ()); - macroInvocations[invoc.get_macro_node_id ()] = def; + macroInvocations[invoc.get_node_id ()] = def; } bool Mappings::lookup_macro_invocation (AST::MacroInvocation &invoc, AST::MacroRulesDefinition **def) { - auto it = macroInvocations.find (invoc.get_macro_node_id ()); + auto it = macroInvocations.find (invoc.get_node_id ()); if (it == macroInvocations.end ()) return false; @@ -1084,16 +1084,16 @@ void Mappings::insert_bang_proc_macro_invocation (AST::MacroInvocation &invoc, BangProcMacro def) { - auto it = procmacroBangInvocations.find (invoc.get_macro_node_id ()); + auto it = procmacroBangInvocations.find (invoc.get_node_id ()); rust_assert (it == procmacroBangInvocations.end ()); - procmacroBangInvocations[invoc.get_macro_node_id ()] = def; + procmacroBangInvocations[invoc.get_node_id ()] = def; } tl::optional Mappings::lookup_bang_proc_macro_invocation (AST::MacroInvocation &invoc) { - auto it = procmacroBangInvocations.find (invoc.get_macro_node_id ()); + auto it = procmacroBangInvocations.find (invoc.get_node_id ()); if (it == procmacroBangInvocations.end ()) return tl::nullopt;