Branch data Line data Source code
1 : : // Copyright (C) 2020-2025 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-default-resolver.h"
20 : : #include "rust-ast-full.h"
21 : : #include "rust-ast-visitor.h"
22 : : #include "rust-item.h"
23 : :
24 : : namespace Rust {
25 : : namespace Resolver2_0 {
26 : :
27 : : void
28 : 17694 : DefaultResolver::visit (AST::BlockExpr &expr)
29 : : {
30 : : // extracting the lambda from the `scoped` call otherwise the code looks like
31 : : // a hot turd thanks to our .clang-format
32 : :
33 : 17694 : auto inner_fn = [this, &expr] () { AST::DefaultASTVisitor::visit (expr); };
34 : :
35 : 17694 : ctx.scoped (Rib::Kind::Normal, expr.get_node_id (), inner_fn);
36 : 17693 : }
37 : :
38 : : void
39 : 1502 : DefaultResolver::visit (AST::Module &module)
40 : : {
41 : 1502 : auto item_fn = [this, &module] () { AST::DefaultASTVisitor::visit (module); };
42 : :
43 : 3004 : ctx.scoped (Rib::Kind::Module, module.get_node_id (), item_fn,
44 : 3004 : module.get_name ());
45 : 1502 : }
46 : :
47 : : void
48 : 16294 : DefaultResolver::visit (AST::Function &function)
49 : : {
50 : 16294 : auto def_fn
51 : 16294 : = [this, &function] () { AST::DefaultASTVisitor::visit (function); };
52 : :
53 : 16294 : ctx.scoped (Rib::Kind::Function, function.get_node_id (), def_fn);
54 : 16293 : }
55 : :
56 : : void
57 : 16 : DefaultResolver::visit (AST::ForLoopExpr &expr)
58 : : {
59 : 16 : ctx.scoped (Rib::Kind::Normal, expr.get_node_id (),
60 : 48 : [this, &expr] () { AST::DefaultASTVisitor::visit (expr); });
61 : 16 : }
62 : :
63 : : void
64 : 3193 : DefaultResolver::visit (AST::Trait &trait)
65 : : {
66 : 3193 : auto inner_fn = [this, &trait] () { AST::DefaultASTVisitor::visit (trait); };
67 : :
68 : 6386 : ctx.scoped (Rib::Kind::TraitOrImpl, trait.get_node_id (), inner_fn,
69 : 6386 : trait.get_identifier () /* FIXME: Is that valid?*/);
70 : 3193 : }
71 : :
72 : : void
73 : 568 : DefaultResolver::visit (AST::InherentImpl &impl)
74 : : {
75 : 568 : auto inner_fn = [this, &impl] () { AST::DefaultASTVisitor::visit (impl); };
76 : :
77 : 568 : ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
78 : 568 : }
79 : :
80 : : void
81 : 2039 : DefaultResolver::visit (AST::TraitImpl &impl)
82 : : {
83 : 2039 : auto inner_fn = [this, &impl] () { AST::DefaultASTVisitor::visit (impl); };
84 : :
85 : 2039 : ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
86 : 2039 : }
87 : :
88 : : void
89 : 664 : DefaultResolver::visit (AST::StructStruct &type)
90 : : {
91 : 664 : auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
92 : :
93 : 664 : ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
94 : 1992 : inner_fn, type.get_struct_name ());
95 : 664 : }
96 : :
97 : : void
98 : 846 : DefaultResolver::visit (AST::TupleStruct &type)
99 : : {
100 : 846 : auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
101 : :
102 : 846 : ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
103 : 2536 : inner_fn, type.get_struct_name ());
104 : 845 : }
105 : :
106 : : void
107 : 572 : DefaultResolver::visit (AST::Enum &type)
108 : : {
109 : 572 : auto variant_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
110 : :
111 : 1144 : ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
112 : 1716 : variant_fn, type.get_identifier ());
113 : 572 : }
114 : :
115 : : void
116 : 93 : DefaultResolver::visit (AST::Union &type)
117 : : {
118 : 93 : auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
119 : :
120 : 186 : ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
121 : 279 : inner_fn, type.get_identifier ());
122 : 93 : }
123 : :
124 : : void
125 : 1456 : DefaultResolver::visit (AST::TypeAlias &type)
126 : : {
127 : 1456 : auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
128 : :
129 : 2912 : ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
130 : 4368 : inner_fn, type.get_new_type_name ());
131 : 1456 : }
132 : :
133 : : void
134 : 22 : DefaultResolver::visit (AST::ClosureExprInner &expr)
135 : : {
136 : 22 : if (expr.is_marked_for_strip ())
137 : : return;
138 : :
139 : 22 : AST::DefaultASTVisitor::visit (expr);
140 : : }
141 : :
142 : : void
143 : 8 : DefaultResolver::visit (AST::ClosureExprInnerTyped &expr)
144 : : {
145 : 8 : if (expr.is_marked_for_strip ())
146 : : return;
147 : :
148 : 8 : AST::DefaultASTVisitor::visit (expr);
149 : : }
150 : :
151 : : void
152 : 322 : DefaultResolver::visit (AST::MatchExpr &expr)
153 : : {
154 : 322 : if (expr.is_marked_for_strip ())
155 : : return;
156 : :
157 : 322 : AST::DefaultASTVisitor::visit (expr);
158 : : }
159 : :
160 : : void
161 : 556 : DefaultResolver::visit (AST::ConstantItem &item)
162 : : {
163 : 556 : if (item.has_expr ())
164 : : {
165 : 546 : auto expr_vis
166 : 546 : = [this, &item] () { AST::DefaultASTVisitor::visit (item); };
167 : :
168 : : // FIXME: Why do we need a Rib here?
169 : 546 : ctx.scoped (Rib::Kind::ConstantItem, item.get_node_id (), expr_vis);
170 : : }
171 : 556 : }
172 : :
173 : : void
174 : 92 : DefaultResolver::visit (AST::StaticItem &item)
175 : : {
176 : 92 : auto expr_vis = [this, &item] () { AST::DefaultASTVisitor::visit (item); };
177 : :
178 : : // FIXME: Why do we need a Rib here?
179 : 92 : ctx.scoped (Rib::Kind::ConstantItem, item.get_node_id (), expr_vis);
180 : 92 : }
181 : :
182 : : void
183 : 6763 : DefaultResolver::visit (AST::TypeParam ¶m)
184 : : {
185 : 6763 : auto expr_vis = [this, ¶m] () { AST::DefaultASTVisitor::visit (param); };
186 : :
187 : 6763 : ctx.scoped (Rib::Kind::ForwardTypeParamBan, param.get_node_id (), expr_vis);
188 : 6763 : }
189 : :
190 : : } // namespace Resolver2_0
191 : : } // namespace Rust
|