From: Ryutaro Okada <[email protected]>

gcc/rust/ChangeLog:

        * expand/rust-expand-visitor.cc (builtin_derive_item): Collect derived 
nodes.
        (derive_item): Collect derived nodes.
        * util/rust-hir-map.cc (Mappings::add_derived_nodes): Add derived set 
to collect derived
        nodes.
        (Mappings::is_derived_node): Add derived set to collect derived nodes.
        * util/rust-hir-map.h: Add derived set to collect derived nodes.

Signed-off-by: Ryutaro Okada <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/rust-GCC/gccrs/commit/24b43f559edddda4d8e156aff9e1809d1a77380f
 gcc/rust/expand/rust-expand-visitor.cc |  8 +++++++-
 gcc/rust/util/rust-hir-map.cc          | 12 ++++++++++++
 gcc/rust/util/rust-hir-map.h           |  5 +++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/expand/rust-expand-visitor.cc 
b/gcc/rust/expand/rust-expand-visitor.cc
index 4593cc3f9..6e98a5c37 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -18,6 +18,7 @@
 
 #include "rust-expand-visitor.h"
 #include "rust-ast-fragment.h"
+#include "rust-hir-map.h"
 #include "rust-item.h"
 #include "rust-proc-macro.h"
 #include "rust-attributes.h"
@@ -48,7 +49,10 @@ static std::vector<std::unique_ptr<AST::Item>>
 builtin_derive_item (AST::Item &item, const AST::Attribute &derive,
                     BuiltinMacro to_derive)
 {
-  return AST::DeriveVisitor::derive (item, derive, to_derive);
+  auto items = AST::DeriveVisitor::derive (item, derive, to_derive);
+  for (auto &item : items)
+    Analysis::Mappings::get ().add_derived_node (item->get_node_id ());
+  return items;
 }
 
 static std::vector<std::unique_ptr<AST::Item>>
@@ -64,6 +68,8 @@ derive_item (AST::Item &item, AST::SimplePath &to_derive,
          switch (node.get_kind ())
            {
            case AST::SingleASTNode::Kind::Item:
+             Analysis::Mappings::get ().add_derived_node (
+               node.get_item ()->get_node_id ());
              result.push_back (node.take_item ());
              break;
            default:
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 1587c7ee7..a6d323e36 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -1358,5 +1358,17 @@ Mappings::lookup_captures (NodeId closure)
     return cap->second;
 }
 
+void
+Mappings::add_derived_node (NodeId node_id)
+{
+  derived_nodes.insert (node_id);
+}
+
+bool
+Mappings::is_derived_node (NodeId node_id)
+{
+  return derived_nodes.find (node_id) != derived_nodes.end ();
+}
+
 } // namespace Analysis
 } // namespace Rust
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 8a284cb93..60066d6cd 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -350,6 +350,9 @@ public:
   void add_capture (NodeId closure, NodeId definition);
   tl::optional<std::vector<NodeId>> lookup_captures (NodeId closure);
 
+  void add_derived_node (NodeId node_id);
+  bool is_derived_node (NodeId node_id);
+
 private:
   Mappings ();
 
@@ -443,6 +446,8 @@ private:
 
   // Closure AST NodeId -> vector of Definition node ids
   std::unordered_map<NodeId, std::vector<NodeId>> captures;
+
+  std::set<NodeId> derived_nodes;
 };
 
 } // namespace Analysis

base-commit: ba5fdd9b42311bd79856adf9961f4d4dda421b04
-- 
2.51.2

Reply via email to