Line data Source code
1 : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
5 : // GCC is free software; you can redistribute it and/or modify it under
6 : // the terms of the GNU General Public License as published by the Free
7 : // Software Foundation; either version 3, or (at your option) any later
8 : // version.
9 :
10 : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : // for more details.
14 :
15 : // You should have received a copy of the GNU General Public License
16 : // along with GCC; see the file COPYING3. If not see
17 : // <http://www.gnu.org/licenses/>.
18 :
19 : #include "rust-finalize-imports-2.0.h"
20 : #include "rust-default-resolver.h"
21 : #include "rust-hir-map.h"
22 : #include "rust-name-resolution-context.h"
23 : #include "rust-rib.h"
24 : #include "rust-system.h"
25 : #include "rust-toplevel-name-resolver-2.0.h"
26 :
27 : namespace Rust {
28 : namespace Resolver2_0 {
29 :
30 : void
31 12118 : GlobbingVisitor::go (AST::GlobContainer *container)
32 : {
33 12118 : switch (container->get_glob_container_kind ())
34 : {
35 11857 : case AST::GlobContainer::Kind::Module:
36 11857 : visit_container (static_cast<AST::Module &> (*container).get_node_id ());
37 11857 : break;
38 4 : case AST::GlobContainer::Kind::Crate:
39 4 : visit_container (static_cast<AST::Crate &> (*container).get_node_id ());
40 4 : break;
41 257 : case AST::GlobContainer::Kind::Enum:
42 257 : visit_container (static_cast<AST::Enum &> (*container).get_node_id ());
43 257 : break;
44 0 : default:
45 0 : rust_unreachable ();
46 : }
47 12118 : }
48 :
49 : template <typename T>
50 : void
51 48472 : GlobbingVisitor::visit_container (T &stack, NodeId nodeid)
52 : {
53 48472 : auto rib = stack.dfs_rib (stack.root, nodeid);
54 48472 : if (rib.has_value ())
55 48472 : glob_definitions (stack.peek (), rib.value ());
56 48472 : }
57 :
58 : void
59 12118 : GlobbingVisitor::visit_container (NodeId nodeid)
60 : {
61 12118 : visit_container (ctx.values, nodeid);
62 12118 : visit_container (ctx.types, nodeid);
63 12118 : visit_container (ctx.macros, nodeid);
64 12118 : visit_container (ctx.labels, nodeid);
65 12118 : }
66 :
67 : void
68 48472 : GlobbingVisitor::glob_definitions (Rib &dst, Rib &src)
69 : {
70 4939930 : for (auto &ent : src.get_values ())
71 4891458 : dirty |= dst.insert_globbed (ent.first, ent.second);
72 48472 : }
73 :
74 : } // namespace Resolver2_0
75 : } // namespace Rust
|