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 28 : GlobbingVisitor::go (AST::GlobContainer *container)
32 : {
33 28 : switch (container->get_glob_container_kind ())
34 : {
35 14 : case AST::GlobContainer::Kind::Module:
36 14 : visit_module_container (static_cast<AST::Module &> (*container));
37 14 : break;
38 2 : case AST::GlobContainer::Kind::Crate:
39 2 : visit_crate_container (static_cast<AST::Crate &> (*container));
40 2 : break;
41 12 : case AST::GlobContainer::Kind::Enum:
42 12 : visit_enum_container (static_cast<AST::Enum &> (*container));
43 12 : break;
44 0 : default:
45 0 : rust_unreachable ();
46 : }
47 28 : }
48 :
49 : void
50 2 : GlobbingVisitor::visit_crate_container (AST::Crate &crate)
51 : {
52 4 : for (auto &i : crate.items)
53 2 : visit (i);
54 2 : }
55 :
56 : void
57 14 : GlobbingVisitor::visit_module_container (AST::Module &module)
58 : {
59 38 : for (auto &i : module.get_items ())
60 24 : visit (i);
61 14 : }
62 :
63 : void
64 12 : GlobbingVisitor::visit_enum_container (AST::Enum &item)
65 : {
66 40 : for (auto &variant : item.get_variants ())
67 : {
68 44 : ctx.insert_globbed (variant->get_identifier (), variant->get_node_id (),
69 : Namespace::Types);
70 28 : if (variant->get_enum_item_kind () != AST::EnumItem::Kind::Struct)
71 44 : ctx.insert_globbed (variant->get_identifier (), variant->get_node_id (),
72 : Namespace::Values);
73 : }
74 12 : }
75 :
76 : void
77 8 : GlobbingVisitor::visit (AST::Module &module)
78 : {
79 12 : ctx.insert_globbed (module.get_name (), module.get_node_id (),
80 : Namespace::Types);
81 8 : }
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 4 : GlobbingVisitor::visit (AST::StructStruct &struct_item)
106 : {
107 5 : ctx.insert_globbed (struct_item.get_identifier (), struct_item.get_node_id (),
108 : Namespace::Types);
109 4 : if (struct_item.is_unit_struct ())
110 5 : ctx.insert_globbed (struct_item.get_identifier (),
111 4 : struct_item.get_node_id (), Namespace::Values);
112 4 : }
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::TypeAlias &type)
147 : {
148 0 : ctx.insert_globbed (type.get_new_type_name (), type.get_node_id (),
149 : Namespace::Types);
150 0 : }
151 :
152 : void
153 2 : GlobbingVisitor::visit (AST::Trait &trait)
154 : {
155 3 : ctx.insert_globbed (trait.get_identifier (), trait.get_node_id (),
156 : Namespace::Types);
157 2 : }
158 :
159 : void
160 0 : GlobbingVisitor::visit (AST::InherentImpl &impl)
161 0 : {}
162 :
163 : void
164 2 : GlobbingVisitor::visit (AST::TraitImpl &impl)
165 2 : {}
166 :
167 : void
168 0 : GlobbingVisitor::visit (AST::ExternCrate &crate)
169 0 : {}
170 :
171 : void
172 0 : GlobbingVisitor::visit (AST::UseDeclaration &use)
173 : {
174 : // Handle cycles ?
175 0 : }
176 :
177 : } // namespace Resolver2_0
178 : } // namespace Rust
|