Skip to content

Commit 9ae9ba7

Browse files
committed
Add derived set to collect derived nodes.
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 <1015ryu88@gmail.com>
1 parent 8a0cd69 commit 9ae9ba7

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

gcc/rust/expand/rust-expand-visitor.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "rust-expand-visitor.h"
2020
#include "rust-ast-fragment.h"
21+
#include "rust-hir-map.h"
2122
#include "rust-proc-macro.h"
2223
#include "rust-attributes.h"
2324
#include "rust-ast.h"
@@ -47,7 +48,10 @@ static std::vector<std::unique_ptr<AST::Item>>
4748
builtin_derive_item (AST::Item &item, const AST::Attribute &derive,
4849
BuiltinMacro to_derive)
4950
{
50-
return AST::DeriveVisitor::derive (item, derive, to_derive);
51+
auto items = AST::DeriveVisitor::derive (item, derive, to_derive);
52+
for (auto &item : items)
53+
Analysis::Mappings::get ().add_derived_nodes (item->get_node_id ());
54+
return items;
5155
}
5256

5357
static std::vector<std::unique_ptr<AST::Item>>
@@ -63,6 +67,8 @@ derive_item (AST::Item &item, AST::SimplePath &to_derive,
6367
switch (node.get_kind ())
6468
{
6569
case AST::SingleASTNode::ITEM:
70+
Analysis::Mappings::get ().add_derived_nodes (
71+
node.get_item ()->get_node_id ());
6672
result.push_back (node.take_item ());
6773
break;
6874
default:

gcc/rust/util/rust-hir-map.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,5 +1358,17 @@ Mappings::lookup_captures (NodeId closure)
13581358
return cap->second;
13591359
}
13601360

1361+
void
1362+
Mappings::add_derived_nodes (NodeId node_id)
1363+
{
1364+
derived_nodes.insert (node_id);
1365+
}
1366+
1367+
bool
1368+
Mappings::is_derived_node (NodeId node_id)
1369+
{
1370+
return derived_nodes.find (node_id) != derived_nodes.end ();
1371+
}
1372+
13611373
} // namespace Analysis
13621374
} // namespace Rust

gcc/rust/util/rust-hir-map.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ class Mappings
350350
void add_capture (NodeId closure, NodeId definition);
351351
tl::optional<std::vector<NodeId>> lookup_captures (NodeId closure);
352352

353+
void add_derived_nodes (NodeId node_id);
354+
bool is_derived_node (NodeId node_id);
355+
353356
private:
354357
Mappings ();
355358

@@ -443,6 +446,8 @@ class Mappings
443446

444447
// Closure AST NodeId -> vector of Definition node ids
445448
std::unordered_map<NodeId, std::vector<NodeId>> captures;
449+
450+
std::set<NodeId> derived_nodes;
446451
};
447452

448453
} // namespace Analysis

0 commit comments

Comments
 (0)