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