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 21 : GlobbingVisitor::go (AST::GlobContainer *container)
32 : {
33 21 : switch (container->get_glob_container_kind ())
34 : {
35 10 : case AST::GlobContainer::Kind::Module:
36 10 : visit_module_container (static_cast<AST::Module &> (*container));
37 10 : break;
38 1 : case AST::GlobContainer::Kind::Crate:
39 1 : visit_crate_container (static_cast<AST::Crate &> (*container));
40 1 : break;
41 10 : case AST::GlobContainer::Kind::Enum:
42 10 : visit_enum_container (static_cast<AST::Enum &> (*container));
43 10 : break;
44 0 : default:
45 0 : rust_unreachable ();
46 : }
47 21 : }
48 :
49 : void
50 1 : GlobbingVisitor::visit_crate_container (AST::Crate &crate)
51 : {
52 2 : for (auto &i : crate.items)
53 1 : visit (i);
54 1 : }
55 :
56 : void
57 10 : GlobbingVisitor::visit_module_container (AST::Module &module)
58 : {
59 26 : for (auto &i : module.get_items ())
60 16 : visit (i);
61 10 : }
62 :
63 : void
64 10 : GlobbingVisitor::visit_enum_container (AST::Enum &item)
65 : {
66 32 : for (auto &variant : item.get_variants ())
67 : {
68 35 : ctx.insert_globbed (variant->get_identifier (), variant->get_node_id (),
69 : Namespace::Types);
70 22 : if (variant->get_enum_item_kind () != AST::EnumItem::Kind::Struct)
71 35 : ctx.insert_globbed (variant->get_identifier (), variant->get_node_id (),
72 : Namespace::Values);
73 : }
74 10 : }
75 :
76 : void
77 5 : GlobbingVisitor::visit (AST::Module &module)
78 : {
79 6 : ctx.insert_globbed (module.get_name (), module.get_node_id (),
80 : Namespace::Types);
81 5 : }
82 :
83 : void
84 0 : GlobbingVisitor::visit (AST::MacroRulesDefinition ¯o)
85 : {
86 0 : ctx.insert_globbed (macro.get_rule_name (), macro.get_node_id (),
87 : Namespace::Macros);
88 0 : }
89 :
90 : void
91 10 : GlobbingVisitor::visit (AST::Function &function)
92 : {
93 15 : ctx.insert_globbed (function.get_function_name (), function.get_node_id (),
94 : Namespace::Values);
95 10 : }
96 :
97 : void
98 0 : GlobbingVisitor::visit (AST::StaticItem &static_item)
99 : {
100 0 : ctx.insert_globbed (static_item.get_identifier (), static_item.get_node_id (),
101 : Namespace::Values);
102 0 : }
103 :
104 : void
105 2 : GlobbingVisitor::visit (AST::StructStruct &struct_item)
106 : {
107 2 : ctx.insert_globbed (struct_item.get_identifier (), struct_item.get_node_id (),
108 : Namespace::Types);
109 2 : if (struct_item.is_unit_struct ())
110 2 : ctx.insert_globbed (struct_item.get_identifier (),
111 2 : struct_item.get_node_id (), Namespace::Values);
112 2 : }
113 :
114 : void
115 0 : GlobbingVisitor::visit (AST::TupleStruct &tuple_struct)
116 : {
117 0 : ctx.insert_globbed (tuple_struct.get_identifier (),
118 0 : tuple_struct.get_node_id (), Namespace::Types);
119 :
120 0 : ctx.insert_globbed (tuple_struct.get_identifier (),
121 0 : tuple_struct.get_node_id (), Namespace::Values);
122 0 : }
123 :
124 : void
125 0 : GlobbingVisitor::visit (AST::Enum &enum_item)
126 : {
127 0 : ctx.insert_globbed (enum_item.get_identifier (), enum_item.get_node_id (),
128 : Namespace::Types);
129 0 : }
130 :
131 : void
132 0 : GlobbingVisitor::visit (AST::Union &union_item)
133 : {
134 0 : ctx.insert_globbed (union_item.get_identifier (), union_item.get_node_id (),
135 : Namespace::Values);
136 0 : }
137 :
138 : void
139 0 : GlobbingVisitor::visit (AST::ConstantItem &const_item)
140 : {
141 0 : ctx.insert_globbed (const_item.get_identifier (), const_item.get_node_id (),
142 : Namespace::Values);
143 0 : }
144 :
145 : void
146 0 : GlobbingVisitor::visit (AST::ExternCrate &crate)
147 0 : {}
148 :
149 : void
150 0 : GlobbingVisitor::visit (AST::UseDeclaration &use)
151 : {
152 : // Handle cycles ?
153 0 : }
154 :
155 : } // namespace Resolver2_0
156 : } // namespace Rust
|