Debian Codegraph @

gcc/rust/resolve/rust-finalize-imports-2.0.cc

raw
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-toplevel-name-resolver-2.0.h"
25
26 namespace Rust {
27 namespace Resolver2_0 {
28
29 void
30 GlobbingVisitor::go (AST::Module *module)
31 {
32 for (auto &i : module->get_items ())
33 visit (i);
34 }
35
36 void
37 GlobbingVisitor::visit (AST::Module &module)
38 {
39 if (module.get_visibility ().is_public ())
40 ctx.insert_globbed (module.get_name (), module.get_node_id (),
41 Namespace::Types);
42 }
43
44 void
45 GlobbingVisitor::visit (AST::MacroRulesDefinition &macro)
46 {
47 if (macro.get_visibility ().is_public ())
48 ctx.insert_globbed (macro.get_rule_name (), macro.get_node_id (),
49 Namespace::Macros);
50 }
51
52 void
53 GlobbingVisitor::visit (AST::Function &function)
54 {
55 if (function.get_visibility ().is_public ())
56 ctx.insert_globbed (function.get_function_name (), function.get_node_id (),
57 Namespace::Values);
58 }
59
60 void
61 GlobbingVisitor::visit (AST::StaticItem &static_item)
62 {
63 if (static_item.get_visibility ().is_public ())
64 ctx.insert_globbed (static_item.get_identifier (),
65 static_item.get_node_id (), Namespace::Values);
66 }
67
68 void
69 GlobbingVisitor::visit (AST::StructStruct &struct_item)
70 {
71 if (struct_item.get_visibility ().is_public ())
72 {
73 ctx.insert_globbed (struct_item.get_identifier (),
74 struct_item.get_node_id (), Namespace::Types);
75 if (struct_item.is_unit_struct ())
76 ctx.insert_globbed (struct_item.get_identifier (),
77 struct_item.get_node_id (), Namespace::Values);
78 }
79 }
80
81 void
82 GlobbingVisitor::visit (AST::TupleStruct &tuple_struct)
83 {
84 if (tuple_struct.get_visibility ().is_public ())
85 {
86 ctx.insert_globbed (tuple_struct.get_identifier (),
87 tuple_struct.get_node_id (), Namespace::Types);
88
89 ctx.insert_globbed (tuple_struct.get_identifier (),
90 tuple_struct.get_node_id (), Namespace::Values);
91 }
92 }
93
94 void
95 GlobbingVisitor::visit (AST::Enum &enum_item)
96 {
97 if (enum_item.get_visibility ().is_public ())
98 ctx.insert_globbed (enum_item.get_identifier (), enum_item.get_node_id (),
99 Namespace::Types);
100 }
101
102 void
103 GlobbingVisitor::visit (AST::Union &union_item)
104 {
105 if (union_item.get_visibility ().is_public ())
106 ctx.insert_globbed (union_item.get_identifier (), union_item.get_node_id (),
107 Namespace::Values);
108 }
109
110 void
111 GlobbingVisitor::visit (AST::ConstantItem &const_item)
112 {
113 if (const_item.get_visibility ().is_public ())
114 ctx.insert_globbed (const_item.get_identifier (), const_item.get_node_id (),
115 Namespace::Values);
116 }
117
118 void
119 GlobbingVisitor::visit (AST::ExternCrate &crate)
120 {}
121
122 void
123 GlobbingVisitor::visit (AST::UseDeclaration &use)
124 {
125 // Handle cycles ?
126 }
127
128 } // namespace Resolver2_0
129 } // namespace Rust