]>
Commit | Line | Data |
---|---|---|
52219746 AC |
1 | // Copyright (C) 2020-2022 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-early-name-resolver.h" | |
20 | #include "rust-ast-full.h" | |
21 | #include "rust-name-resolver.h" | |
22 | ||
23 | namespace Rust { | |
24 | namespace Resolver { | |
25 | ||
26 | EarlyNameResolver::EarlyNameResolver () | |
27 | : resolver (*Resolver::get ()), mappings (*Analysis::Mappings::get ()) | |
28 | {} | |
29 | ||
30 | void | |
31 | EarlyNameResolver::go (AST::Crate &crate) | |
32 | { | |
33 | // FIXME: Is that valid? Why is the regular name resolution doing | |
34 | // mappings->get_next_node_id()? | |
35 | resolver.get_macro_scope ().push (crate.get_node_id ()); | |
36 | ||
37 | for (auto &item : crate.items) | |
38 | item->accept_vis (*this); | |
39 | ||
40 | // FIXME: Should we pop the macro scope? | |
41 | } | |
42 | ||
43 | void | |
44 | EarlyNameResolver::resolve_generic_args (AST::GenericArgs &generic_args) | |
45 | { | |
46 | for (auto &arg : generic_args.get_generic_args ()) | |
47 | arg.accept_vis (*this); | |
48 | ||
49 | for (auto &arg : generic_args.get_binding_args ()) | |
50 | arg.get_type ()->accept_vis (*this); | |
51 | } | |
52 | ||
53 | void | |
54 | EarlyNameResolver::resolve_qualified_path_type (AST::QualifiedPathType &path) | |
55 | { | |
56 | path.get_type ()->accept_vis (*this); | |
57 | ||
58 | if (path.has_as_clause ()) | |
59 | path.get_as_type_path ().accept_vis (*this); | |
60 | } | |
61 | ||
62 | void | |
9f455ed8 | 63 | EarlyNameResolver::visit (AST::Token &) |
52219746 AC |
64 | {} |
65 | ||
66 | void | |
9f455ed8 | 67 | EarlyNameResolver::visit (AST::DelimTokenTree &) |
52219746 AC |
68 | {} |
69 | ||
70 | void | |
9f455ed8 | 71 | EarlyNameResolver::visit (AST::AttrInputMetaItemContainer &) |
52219746 AC |
72 | {} |
73 | ||
74 | void | |
9f455ed8 | 75 | EarlyNameResolver::visit (AST::IdentifierExpr &) |
52219746 AC |
76 | {} |
77 | ||
78 | void | |
9f455ed8 | 79 | EarlyNameResolver::visit (AST::Lifetime &) |
52219746 AC |
80 | {} |
81 | ||
82 | void | |
9f455ed8 | 83 | EarlyNameResolver::visit (AST::LifetimeParam &) |
52219746 AC |
84 | {} |
85 | ||
86 | void | |
9f455ed8 | 87 | EarlyNameResolver::visit (AST::ConstGenericParam &) |
52219746 AC |
88 | {} |
89 | ||
90 | // FIXME: ARTHUR: Do we need to perform macro resolution for paths as well? | |
91 | // std::arch::asm!()? | |
92 | void | |
93 | EarlyNameResolver::visit (AST::PathInExpression &path) | |
94 | { | |
95 | for (auto &segment : path.get_segments ()) | |
96 | if (segment.has_generic_args ()) | |
97 | resolve_generic_args (segment.get_generic_args ()); | |
98 | } | |
99 | ||
100 | void | |
9f455ed8 | 101 | EarlyNameResolver::visit (AST::TypePathSegment &) |
52219746 AC |
102 | {} |
103 | ||
104 | void | |
105 | EarlyNameResolver::visit (AST::TypePathSegmentGeneric &segment) | |
106 | { | |
107 | if (segment.has_generic_args ()) | |
108 | resolve_generic_args (segment.get_generic_args ()); | |
109 | } | |
110 | ||
111 | void | |
112 | EarlyNameResolver::visit (AST::TypePathSegmentFunction &segment) | |
113 | { | |
114 | for (auto &type : segment.get_type_path_function ().get_params ()) | |
115 | type->accept_vis (*this); | |
116 | ||
117 | segment.get_type_path_function ().get_return_type ()->accept_vis (*this); | |
118 | } | |
119 | ||
120 | void | |
121 | EarlyNameResolver::visit (AST::TypePath &path) | |
122 | { | |
123 | for (auto &seg : path.get_segments ()) | |
124 | seg->accept_vis (*this); | |
125 | } | |
126 | ||
127 | void | |
128 | EarlyNameResolver::visit (AST::QualifiedPathInExpression &path) | |
129 | { | |
130 | resolve_qualified_path_type (path.get_qualified_path_type ()); | |
131 | ||
132 | for (auto &segment : path.get_segments ()) | |
133 | if (segment.has_generic_args ()) | |
134 | resolve_generic_args (segment.get_generic_args ()); | |
135 | } | |
136 | ||
137 | void | |
138 | EarlyNameResolver::visit (AST::QualifiedPathInType &path) | |
139 | { | |
140 | resolve_qualified_path_type (path.get_qualified_path_type ()); | |
141 | ||
142 | for (auto &segment : path.get_segments ()) | |
143 | segment->accept_vis (*this); | |
144 | } | |
145 | ||
146 | void | |
9f455ed8 | 147 | EarlyNameResolver::visit (AST::LiteralExpr &) |
52219746 AC |
148 | {} |
149 | ||
150 | void | |
9f455ed8 | 151 | EarlyNameResolver::visit (AST::AttrInputLiteral &) |
52219746 AC |
152 | {} |
153 | ||
154 | void | |
9f455ed8 | 155 | EarlyNameResolver::visit (AST::MetaItemLitExpr &) |
52219746 AC |
156 | {} |
157 | ||
158 | void | |
9f455ed8 | 159 | EarlyNameResolver::visit (AST::MetaItemPathLit &) |
52219746 AC |
160 | {} |
161 | ||
162 | void | |
163 | EarlyNameResolver::visit (AST::BorrowExpr &expr) | |
164 | { | |
165 | expr.get_borrowed_expr ()->accept_vis (*this); | |
166 | } | |
167 | ||
168 | void | |
169 | EarlyNameResolver::visit (AST::DereferenceExpr &expr) | |
170 | { | |
171 | expr.get_dereferenced_expr ()->accept_vis (*this); | |
172 | } | |
173 | ||
174 | void | |
175 | EarlyNameResolver::visit (AST::ErrorPropagationExpr &expr) | |
176 | { | |
177 | expr.get_propagating_expr ()->accept_vis (*this); | |
178 | } | |
179 | ||
180 | void | |
181 | EarlyNameResolver::visit (AST::NegationExpr &expr) | |
182 | { | |
183 | expr.get_negated_expr ()->accept_vis (*this); | |
184 | } | |
185 | ||
186 | void | |
187 | EarlyNameResolver::visit (AST::ArithmeticOrLogicalExpr &expr) | |
188 | { | |
189 | expr.get_left_expr ()->accept_vis (*this); | |
190 | expr.get_right_expr ()->accept_vis (*this); | |
191 | } | |
192 | ||
193 | void | |
194 | EarlyNameResolver::visit (AST::ComparisonExpr &expr) | |
195 | { | |
196 | expr.get_left_expr ()->accept_vis (*this); | |
197 | expr.get_right_expr ()->accept_vis (*this); | |
198 | } | |
199 | ||
200 | void | |
201 | EarlyNameResolver::visit (AST::LazyBooleanExpr &expr) | |
202 | { | |
203 | expr.get_left_expr ()->accept_vis (*this); | |
204 | expr.get_right_expr ()->accept_vis (*this); | |
205 | } | |
206 | ||
207 | void | |
208 | EarlyNameResolver::visit (AST::TypeCastExpr &expr) | |
209 | { | |
210 | expr.get_casted_expr ()->accept_vis (*this); | |
211 | expr.get_type_to_cast_to ()->accept_vis (*this); | |
212 | } | |
213 | ||
214 | void | |
215 | EarlyNameResolver::visit (AST::AssignmentExpr &expr) | |
216 | { | |
217 | expr.get_left_expr ()->accept_vis (*this); | |
218 | expr.get_right_expr ()->accept_vis (*this); | |
219 | } | |
220 | ||
221 | void | |
222 | EarlyNameResolver::visit (AST::CompoundAssignmentExpr &expr) | |
223 | { | |
224 | expr.get_left_expr ()->accept_vis (*this); | |
225 | expr.get_right_expr ()->accept_vis (*this); | |
226 | } | |
227 | ||
228 | void | |
229 | EarlyNameResolver::visit (AST::GroupedExpr &expr) | |
230 | { | |
231 | expr.get_expr_in_parens ()->accept_vis (*this); | |
232 | } | |
233 | ||
234 | void | |
235 | EarlyNameResolver::visit (AST::ArrayElemsValues &elems) | |
236 | { | |
237 | for (auto &expr : elems.get_values ()) | |
238 | expr->accept_vis (*this); | |
239 | } | |
240 | ||
241 | void | |
242 | EarlyNameResolver::visit (AST::ArrayElemsCopied &elems) | |
243 | { | |
244 | elems.get_elem_to_copy ()->accept_vis (*this); | |
245 | } | |
246 | ||
247 | void | |
248 | EarlyNameResolver::visit (AST::ArrayExpr &expr) | |
249 | { | |
250 | expr.get_array_elems ()->accept_vis (*this); | |
251 | } | |
252 | ||
253 | void | |
254 | EarlyNameResolver::visit (AST::ArrayIndexExpr &expr) | |
255 | { | |
256 | expr.get_array_expr ()->accept_vis (*this); | |
257 | expr.get_index_expr ()->accept_vis (*this); | |
258 | } | |
259 | ||
260 | void | |
261 | EarlyNameResolver::visit (AST::TupleExpr &expr) | |
262 | { | |
263 | for (auto &elem : expr.get_tuple_elems ()) | |
264 | elem->accept_vis (*this); | |
265 | } | |
266 | ||
267 | void | |
268 | EarlyNameResolver::visit (AST::TupleIndexExpr &expr) | |
269 | { | |
270 | expr.get_tuple_expr ()->accept_vis (*this); | |
271 | } | |
272 | ||
273 | void | |
9f455ed8 | 274 | EarlyNameResolver::visit (AST::StructExprStruct &) |
52219746 AC |
275 | {} |
276 | ||
277 | void | |
9f455ed8 | 278 | EarlyNameResolver::visit (AST::StructExprFieldIdentifier &) |
52219746 AC |
279 | {} |
280 | ||
281 | void | |
282 | EarlyNameResolver::visit (AST::StructExprFieldIdentifierValue &field) | |
283 | { | |
284 | field.get_value ()->accept_vis (*this); | |
285 | } | |
286 | ||
287 | void | |
288 | EarlyNameResolver::visit (AST::StructExprFieldIndexValue &field) | |
289 | { | |
290 | field.get_value ()->accept_vis (*this); | |
291 | } | |
292 | ||
293 | void | |
294 | EarlyNameResolver::visit (AST::StructExprStructFields &expr) | |
295 | { | |
296 | for (auto &field : expr.get_fields ()) | |
297 | field->accept_vis (*this); | |
298 | } | |
299 | ||
300 | void | |
9f455ed8 | 301 | EarlyNameResolver::visit (AST::StructExprStructBase &) |
52219746 AC |
302 | {} |
303 | ||
304 | void | |
305 | EarlyNameResolver::visit (AST::CallExpr &expr) | |
306 | { | |
307 | expr.get_function_expr ()->accept_vis (*this); | |
308 | for (auto ¶m : expr.get_params ()) | |
309 | param->accept_vis (*this); | |
310 | } | |
311 | ||
312 | void | |
313 | EarlyNameResolver::visit (AST::MethodCallExpr &expr) | |
314 | { | |
315 | expr.get_receiver_expr ()->accept_vis (*this); | |
316 | for (auto ¶m : expr.get_params ()) | |
317 | param->accept_vis (*this); | |
318 | } | |
319 | ||
320 | void | |
321 | EarlyNameResolver::visit (AST::FieldAccessExpr &expr) | |
322 | { | |
323 | expr.get_receiver_expr ()->accept_vis (*this); | |
324 | } | |
325 | ||
326 | void | |
327 | EarlyNameResolver::visit (AST::ClosureExprInner &expr) | |
328 | { | |
329 | expr.get_definition_expr ()->accept_vis (*this); | |
330 | ||
331 | for (auto ¶m : expr.get_params ()) | |
332 | param.get_type ()->accept_vis (*this); | |
333 | } | |
334 | ||
335 | void | |
336 | EarlyNameResolver::visit (AST::BlockExpr &expr) | |
337 | { | |
338 | for (auto &stmt : expr.get_statements ()) | |
339 | stmt->accept_vis (*this); | |
340 | ||
341 | if (expr.has_tail_expr ()) | |
342 | expr.get_tail_expr ()->accept_vis (*this); | |
343 | } | |
344 | ||
345 | void | |
346 | EarlyNameResolver::visit (AST::ClosureExprInnerTyped &expr) | |
347 | { | |
348 | expr.get_definition_block ()->accept_vis (*this); | |
349 | ||
350 | for (auto ¶m : expr.get_params ()) | |
351 | param.get_type ()->accept_vis (*this); | |
352 | } | |
353 | ||
354 | void | |
9f455ed8 | 355 | EarlyNameResolver::visit (AST::ContinueExpr &) |
52219746 AC |
356 | {} |
357 | ||
358 | void | |
359 | EarlyNameResolver::visit (AST::BreakExpr &expr) | |
360 | { | |
361 | if (expr.has_break_expr ()) | |
362 | expr.get_break_expr ()->accept_vis (*this); | |
363 | } | |
364 | ||
365 | void | |
366 | EarlyNameResolver::visit (AST::RangeFromToExpr &expr) | |
367 | { | |
368 | expr.get_from_expr ()->accept_vis (*this); | |
369 | expr.get_to_expr ()->accept_vis (*this); | |
370 | } | |
371 | ||
372 | void | |
373 | EarlyNameResolver::visit (AST::RangeFromExpr &expr) | |
374 | { | |
375 | expr.get_from_expr ()->accept_vis (*this); | |
376 | } | |
377 | ||
378 | void | |
379 | EarlyNameResolver::visit (AST::RangeToExpr &expr) | |
380 | { | |
381 | expr.get_to_expr ()->accept_vis (*this); | |
382 | } | |
383 | ||
384 | void | |
9f455ed8 | 385 | EarlyNameResolver::visit (AST::RangeFullExpr &) |
52219746 AC |
386 | {} |
387 | ||
388 | void | |
389 | EarlyNameResolver::visit (AST::RangeFromToInclExpr &expr) | |
390 | { | |
391 | expr.get_from_expr ()->accept_vis (*this); | |
392 | expr.get_to_expr ()->accept_vis (*this); | |
393 | } | |
394 | ||
395 | void | |
396 | EarlyNameResolver::visit (AST::RangeToInclExpr &expr) | |
397 | { | |
398 | expr.get_to_expr ()->accept_vis (*this); | |
399 | } | |
400 | ||
401 | void | |
402 | EarlyNameResolver::visit (AST::ReturnExpr &expr) | |
403 | { | |
404 | if (expr.has_returned_expr ()) | |
405 | expr.get_returned_expr ()->accept_vis (*this); | |
406 | } | |
407 | ||
408 | void | |
409 | EarlyNameResolver::visit (AST::UnsafeBlockExpr &expr) | |
410 | { | |
411 | expr.get_block_expr ()->accept_vis (*this); | |
412 | } | |
413 | ||
414 | void | |
415 | EarlyNameResolver::visit (AST::LoopExpr &expr) | |
416 | { | |
417 | expr.get_loop_block ()->accept_vis (*this); | |
418 | } | |
419 | ||
420 | void | |
421 | EarlyNameResolver::visit (AST::WhileLoopExpr &expr) | |
422 | { | |
423 | expr.get_predicate_expr ()->accept_vis (*this); | |
424 | expr.get_loop_block ()->accept_vis (*this); | |
425 | } | |
426 | ||
427 | void | |
428 | EarlyNameResolver::visit (AST::WhileLetLoopExpr &expr) | |
429 | { | |
430 | expr.get_scrutinee_expr ()->accept_vis (*this); | |
431 | expr.get_loop_block ()->accept_vis (*this); | |
432 | } | |
433 | ||
434 | void | |
435 | EarlyNameResolver::visit (AST::ForLoopExpr &expr) | |
436 | { | |
437 | expr.get_iterator_expr ()->accept_vis (*this); | |
438 | expr.get_loop_block ()->accept_vis (*this); | |
439 | } | |
440 | ||
441 | void | |
442 | EarlyNameResolver::visit (AST::IfExpr &expr) | |
443 | { | |
444 | expr.get_condition_expr ()->accept_vis (*this); | |
445 | expr.get_if_block ()->accept_vis (*this); | |
446 | } | |
447 | ||
448 | void | |
449 | EarlyNameResolver::visit (AST::IfExprConseqElse &expr) | |
450 | { | |
451 | expr.get_condition_expr ()->accept_vis (*this); | |
452 | expr.get_if_block ()->accept_vis (*this); | |
453 | expr.get_else_block ()->accept_vis (*this); | |
454 | } | |
455 | ||
456 | void | |
457 | EarlyNameResolver::visit (AST::IfExprConseqIf &expr) | |
458 | { | |
459 | expr.get_condition_expr ()->accept_vis (*this); | |
460 | expr.get_if_block ()->accept_vis (*this); | |
461 | expr.get_conseq_if_expr ()->accept_vis (*this); | |
462 | } | |
463 | ||
464 | void | |
465 | EarlyNameResolver::visit (AST::IfExprConseqIfLet &expr) | |
466 | { | |
467 | expr.get_condition_expr ()->accept_vis (*this); | |
468 | expr.get_if_block ()->accept_vis (*this); | |
469 | expr.get_conseq_if_let_expr ()->accept_vis (*this); | |
470 | } | |
471 | ||
472 | void | |
473 | EarlyNameResolver::visit (AST::IfLetExpr &expr) | |
474 | { | |
475 | expr.get_value_expr ()->accept_vis (*this); | |
476 | expr.get_if_block ()->accept_vis (*this); | |
477 | } | |
478 | ||
479 | void | |
480 | EarlyNameResolver::visit (AST::IfLetExprConseqElse &expr) | |
481 | { | |
482 | expr.get_value_expr ()->accept_vis (*this); | |
483 | expr.get_if_block ()->accept_vis (*this); | |
484 | expr.get_else_block ()->accept_vis (*this); | |
485 | } | |
486 | ||
487 | void | |
488 | EarlyNameResolver::visit (AST::IfLetExprConseqIf &expr) | |
489 | { | |
490 | expr.get_value_expr ()->accept_vis (*this); | |
491 | expr.get_if_block ()->accept_vis (*this); | |
492 | expr.get_conseq_if_expr ()->accept_vis (*this); | |
493 | } | |
494 | ||
495 | void | |
496 | EarlyNameResolver::visit (AST::IfLetExprConseqIfLet &expr) | |
497 | { | |
498 | expr.get_value_expr ()->accept_vis (*this); | |
499 | expr.get_if_block ()->accept_vis (*this); | |
500 | expr.get_conseq_if_let_expr ()->accept_vis (*this); | |
501 | } | |
502 | ||
503 | void | |
504 | EarlyNameResolver::visit (AST::MatchExpr &expr) | |
505 | { | |
506 | expr.get_scrutinee_expr ()->accept_vis (*this); | |
507 | for (auto &match_arm : expr.get_match_cases ()) | |
508 | { | |
509 | if (match_arm.get_arm ().has_match_arm_guard ()) | |
510 | match_arm.get_arm ().get_guard_expr ()->accept_vis (*this); | |
511 | ||
512 | for (auto &pattern : match_arm.get_arm ().get_patterns ()) | |
513 | pattern->accept_vis (*this); | |
514 | ||
515 | match_arm.get_expr ()->accept_vis (*this); | |
516 | } | |
517 | } | |
518 | ||
519 | void | |
520 | EarlyNameResolver::visit (AST::AwaitExpr &expr) | |
521 | { | |
522 | expr.get_awaited_expr ()->accept_vis (*this); | |
523 | } | |
524 | ||
525 | void | |
526 | EarlyNameResolver::visit (AST::AsyncBlockExpr &expr) | |
527 | { | |
528 | expr.get_block_expr ()->accept_vis (*this); | |
529 | } | |
530 | ||
531 | void | |
532 | EarlyNameResolver::visit (AST::TypeParam ¶m) | |
533 | { | |
534 | for (auto &bound : param.get_type_param_bounds ()) | |
535 | bound->accept_vis (*this); | |
536 | ||
537 | if (param.has_type ()) | |
538 | param.get_type ()->accept_vis (*this); | |
539 | } | |
540 | ||
541 | void | |
9f455ed8 | 542 | EarlyNameResolver::visit (AST::LifetimeWhereClauseItem &) |
52219746 AC |
543 | {} |
544 | ||
545 | void | |
546 | EarlyNameResolver::visit (AST::TypeBoundWhereClauseItem &item) | |
547 | { | |
548 | for (auto &bound : item.get_type_param_bounds ()) | |
549 | bound->accept_vis (*this); | |
550 | } | |
551 | ||
552 | void | |
553 | EarlyNameResolver::visit (AST::Method &method) | |
554 | { | |
555 | if (method.has_generics ()) | |
556 | for (auto &generic : method.get_generic_params ()) | |
557 | generic->accept_vis (*this); | |
558 | ||
559 | if (method.get_self_param ().has_type ()) | |
560 | method.get_self_param ().get_type ()->accept_vis (*this); | |
561 | ||
562 | for (auto ¶m : method.get_function_params ()) | |
563 | param.get_type ()->accept_vis (*this); | |
564 | ||
565 | if (method.has_return_type ()) | |
566 | method.get_return_type ()->accept_vis (*this); | |
567 | ||
568 | method.get_definition ()->accept_vis (*this); | |
569 | } | |
570 | ||
571 | void | |
572 | EarlyNameResolver::visit (AST::Module &module) | |
573 | { | |
574 | for (auto &item : module.get_items ()) | |
575 | item->accept_vis (*this); | |
576 | } | |
577 | ||
578 | void | |
9f455ed8 | 579 | EarlyNameResolver::visit (AST::ExternCrate &) |
52219746 AC |
580 | {} |
581 | ||
582 | void | |
9f455ed8 | 583 | EarlyNameResolver::visit (AST::UseTreeGlob &) |
52219746 AC |
584 | {} |
585 | ||
586 | void | |
9f455ed8 | 587 | EarlyNameResolver::visit (AST::UseTreeList &) |
52219746 AC |
588 | {} |
589 | ||
590 | void | |
9f455ed8 | 591 | EarlyNameResolver::visit (AST::UseTreeRebind &) |
52219746 AC |
592 | {} |
593 | ||
594 | void | |
9f455ed8 | 595 | EarlyNameResolver::visit (AST::UseDeclaration &) |
52219746 AC |
596 | {} |
597 | ||
598 | void | |
599 | EarlyNameResolver::visit (AST::Function &function) | |
600 | { | |
601 | if (function.has_generics ()) | |
602 | for (auto &generic : function.get_generic_params ()) | |
603 | generic->accept_vis (*this); | |
604 | ||
605 | for (auto ¶m : function.get_function_params ()) | |
606 | param.get_type ()->accept_vis (*this); | |
607 | ||
608 | if (function.has_return_type ()) | |
609 | function.get_return_type ()->accept_vis (*this); | |
610 | ||
611 | function.get_definition ()->accept_vis (*this); | |
612 | } | |
613 | ||
614 | void | |
615 | EarlyNameResolver::visit (AST::TypeAlias &type_alias) | |
616 | { | |
617 | type_alias.get_type_aliased ()->accept_vis (*this); | |
618 | } | |
619 | ||
620 | void | |
621 | EarlyNameResolver::visit (AST::StructStruct &struct_item) | |
622 | { | |
623 | for (auto &field : struct_item.get_fields ()) | |
624 | field.get_field_type ()->accept_vis (*this); | |
625 | } | |
626 | ||
627 | void | |
628 | EarlyNameResolver::visit (AST::TupleStruct &tuple_struct) | |
629 | { | |
630 | for (auto &field : tuple_struct.get_fields ()) | |
631 | field.get_field_type ()->accept_vis (*this); | |
632 | } | |
633 | ||
634 | void | |
9f455ed8 | 635 | EarlyNameResolver::visit (AST::EnumItem &) |
52219746 AC |
636 | {} |
637 | ||
638 | void | |
9f455ed8 | 639 | EarlyNameResolver::visit (AST::EnumItemTuple &) |
52219746 AC |
640 | {} |
641 | ||
642 | void | |
9f455ed8 | 643 | EarlyNameResolver::visit (AST::EnumItemStruct &) |
52219746 AC |
644 | {} |
645 | ||
646 | void | |
9f455ed8 | 647 | EarlyNameResolver::visit (AST::EnumItemDiscriminant &) |
52219746 AC |
648 | {} |
649 | ||
650 | void | |
9f455ed8 | 651 | EarlyNameResolver::visit (AST::Enum &) |
52219746 AC |
652 | {} |
653 | ||
654 | void | |
9f455ed8 | 655 | EarlyNameResolver::visit (AST::Union &) |
52219746 AC |
656 | {} |
657 | ||
658 | void | |
659 | EarlyNameResolver::visit (AST::ConstantItem &const_item) | |
660 | { | |
661 | const_item.get_type ()->accept_vis (*this); | |
662 | const_item.get_expr ()->accept_vis (*this); | |
663 | } | |
664 | ||
665 | void | |
666 | EarlyNameResolver::visit (AST::StaticItem &static_item) | |
667 | { | |
668 | static_item.get_type ()->accept_vis (*this); | |
669 | static_item.get_expr ()->accept_vis (*this); | |
670 | } | |
671 | ||
672 | void | |
673 | EarlyNameResolver::visit (AST::TraitItemFunc &item) | |
674 | { | |
675 | auto &decl = item.get_trait_function_decl (); | |
676 | ||
677 | if (decl.has_return_type ()) | |
678 | decl.get_return_type ()->accept_vis (*this); | |
679 | ||
680 | for (auto &generic : decl.get_generic_params ()) | |
681 | generic->accept_vis (*this); | |
682 | ||
683 | for (auto ¶m : decl.get_function_params ()) | |
684 | param.get_type ()->accept_vis (*this); | |
685 | ||
686 | if (item.has_definition ()) | |
687 | item.get_definition ()->accept_vis (*this); | |
688 | } | |
689 | ||
690 | void | |
691 | EarlyNameResolver::visit (AST::TraitItemMethod &item) | |
692 | { | |
693 | // FIXME: Can we factor this with the above function? | |
694 | auto &decl = item.get_trait_method_decl (); | |
695 | ||
696 | if (decl.has_return_type ()) | |
697 | decl.get_return_type ()->accept_vis (*this); | |
698 | ||
699 | for (auto &generic : decl.get_generic_params ()) | |
700 | generic->accept_vis (*this); | |
701 | ||
702 | for (auto ¶m : decl.get_function_params ()) | |
703 | param.get_type ()->accept_vis (*this); | |
704 | ||
705 | if (item.has_definition ()) | |
706 | item.get_definition ()->accept_vis (*this); | |
707 | } | |
708 | ||
709 | void | |
710 | EarlyNameResolver::visit (AST::TraitItemConst &item) | |
711 | { | |
712 | item.get_type ()->accept_vis (*this); | |
713 | ||
714 | if (item.has_expr ()) | |
715 | item.get_expr ()->accept_vis (*this); | |
716 | } | |
717 | ||
718 | void | |
9f455ed8 | 719 | EarlyNameResolver::visit (AST::TraitItemType &) |
52219746 AC |
720 | {} |
721 | ||
722 | void | |
723 | EarlyNameResolver::visit (AST::Trait &trait) | |
724 | { | |
725 | for (auto &item : trait.get_trait_items ()) | |
726 | item->accept_vis (*this); | |
727 | } | |
728 | ||
729 | void | |
730 | EarlyNameResolver::visit (AST::InherentImpl &impl) | |
731 | { | |
732 | impl.get_type ()->accept_vis (*this); | |
733 | ||
734 | for (auto &generic : impl.get_generic_params ()) | |
735 | generic->accept_vis (*this); | |
736 | ||
737 | for (auto &item : impl.get_impl_items ()) | |
738 | item->accept_vis (*this); | |
739 | } | |
740 | ||
741 | void | |
742 | EarlyNameResolver::visit (AST::TraitImpl &impl) | |
743 | { | |
744 | impl.get_type ()->accept_vis (*this); | |
745 | ||
746 | for (auto &generic : impl.get_generic_params ()) | |
747 | generic->accept_vis (*this); | |
748 | ||
749 | for (auto &item : impl.get_impl_items ()) | |
750 | item->accept_vis (*this); | |
751 | } | |
752 | ||
753 | void | |
754 | EarlyNameResolver::visit (AST::ExternalStaticItem &item) | |
755 | { | |
756 | item.get_type ()->accept_vis (*this); | |
757 | } | |
758 | ||
759 | void | |
760 | EarlyNameResolver::visit (AST::ExternalFunctionItem &item) | |
761 | { | |
762 | for (auto &generic : item.get_generic_params ()) | |
763 | generic->accept_vis (*this); | |
764 | ||
765 | for (auto ¶m : item.get_function_params ()) | |
766 | param.get_type ()->accept_vis (*this); | |
767 | ||
768 | if (item.has_return_type ()) | |
769 | item.get_return_type ()->accept_vis (*this); | |
770 | } | |
771 | ||
772 | void | |
773 | EarlyNameResolver::visit (AST::ExternBlock &block) | |
774 | { | |
775 | for (auto &item : block.get_extern_items ()) | |
776 | item->accept_vis (*this); | |
777 | } | |
778 | ||
779 | void | |
9f455ed8 | 780 | EarlyNameResolver::visit (AST::MacroMatchFragment &) |
52219746 AC |
781 | {} |
782 | ||
783 | void | |
9f455ed8 | 784 | EarlyNameResolver::visit (AST::MacroMatchRepetition &) |
52219746 AC |
785 | {} |
786 | ||
787 | void | |
9f455ed8 | 788 | EarlyNameResolver::visit (AST::MacroMatcher &) |
52219746 AC |
789 | {} |
790 | ||
791 | void | |
792 | EarlyNameResolver::visit (AST::MacroRulesDefinition &rules_def) | |
793 | { | |
794 | auto path = CanonicalPath::new_seg (rules_def.get_node_id (), | |
795 | rules_def.get_rule_name ()); | |
796 | resolver.get_macro_scope ().insert (path, rules_def.get_node_id (), | |
797 | rules_def.get_locus ()); | |
798 | mappings.insert_macro_def (&rules_def); | |
799 | rust_debug_loc (rules_def.get_locus (), "inserting macro def: [%s]", | |
800 | path.get ().c_str ()); | |
801 | } | |
802 | ||
803 | void | |
804 | EarlyNameResolver::visit (AST::MacroInvocation &invoc) | |
805 | { | |
806 | auto &invoc_data = invoc.get_invoc_data (); | |
807 | auto has_semicolon = invoc.has_semicolon (); | |
808 | ||
809 | // ?? | |
810 | // switch on type of macro: | |
811 | // - '!' syntax macro (inner switch) | |
812 | // - procedural macro - "A token-based function-like macro" | |
813 | // - 'macro_rules' (by example/pattern-match) macro? or not? "an | |
814 | // AST-based function-like macro" | |
815 | // - else is unreachable | |
816 | // - attribute syntax macro (inner switch) | |
817 | // - procedural macro attribute syntax - "A token-based attribute | |
818 | // macro" | |
819 | // - legacy macro attribute syntax? - "an AST-based attribute macro" | |
820 | // - non-macro attribute: mark known | |
821 | // - else is unreachable | |
822 | // - derive macro (inner switch) | |
823 | // - derive or legacy derive - "token-based" vs "AST-based" | |
824 | // - else is unreachable | |
825 | // - derive container macro - unreachable | |
826 | ||
827 | // lookup the rules for this macro | |
828 | NodeId resolved_node = UNKNOWN_NODEID; | |
829 | NodeId source_node = UNKNOWN_NODEID; | |
830 | if (has_semicolon) | |
831 | source_node = invoc.get_macro_node_id (); | |
832 | else | |
833 | source_node = invoc.get_pattern_node_id (); | |
834 | auto seg | |
835 | = CanonicalPath::new_seg (source_node, invoc_data.get_path ().as_string ()); | |
836 | ||
837 | bool found = resolver.get_macro_scope ().lookup (seg, &resolved_node); | |
838 | if (!found) | |
839 | { | |
840 | rust_error_at (invoc.get_locus (), "unknown macro: [%s]", | |
841 | seg.get ().c_str ()); | |
842 | return; | |
843 | } | |
844 | ||
845 | // lookup the rules | |
846 | AST::MacroRulesDefinition *rules_def = nullptr; | |
847 | bool ok = mappings.lookup_macro_def (resolved_node, &rules_def); | |
848 | rust_assert (ok); | |
849 | ||
850 | mappings.insert_macro_invocation (invoc, rules_def); | |
851 | } | |
852 | ||
853 | // FIXME: ARTHUR: Do we need to resolve these as well here? | |
854 | ||
855 | void | |
9f455ed8 | 856 | EarlyNameResolver::visit (AST::MetaItemPath &) |
52219746 AC |
857 | {} |
858 | ||
859 | void | |
9f455ed8 | 860 | EarlyNameResolver::visit (AST::MetaItemSeq &) |
52219746 AC |
861 | {} |
862 | ||
863 | void | |
9f455ed8 | 864 | EarlyNameResolver::visit (AST::MetaWord &) |
52219746 AC |
865 | {} |
866 | ||
867 | void | |
9f455ed8 | 868 | EarlyNameResolver::visit (AST::MetaNameValueStr &) |
52219746 AC |
869 | {} |
870 | ||
871 | void | |
9f455ed8 | 872 | EarlyNameResolver::visit (AST::MetaListPaths &) |
52219746 AC |
873 | {} |
874 | ||
875 | void | |
9f455ed8 | 876 | EarlyNameResolver::visit (AST::MetaListNameValueStr &) |
52219746 AC |
877 | {} |
878 | ||
879 | void | |
9f455ed8 | 880 | EarlyNameResolver::visit (AST::LiteralPattern &) |
52219746 AC |
881 | {} |
882 | ||
883 | void | |
884 | EarlyNameResolver::visit (AST::IdentifierPattern &pattern) | |
885 | { | |
886 | if (pattern.has_pattern_to_bind ()) | |
887 | pattern.get_pattern_to_bind ()->accept_vis (*this); | |
888 | } | |
889 | ||
890 | void | |
9f455ed8 | 891 | EarlyNameResolver::visit (AST::WildcardPattern &) |
52219746 AC |
892 | {} |
893 | ||
894 | void | |
9f455ed8 | 895 | EarlyNameResolver::visit (AST::RangePatternBoundLiteral &) |
52219746 AC |
896 | {} |
897 | ||
898 | void | |
9f455ed8 | 899 | EarlyNameResolver::visit (AST::RangePatternBoundPath &) |
52219746 AC |
900 | {} |
901 | ||
902 | void | |
9f455ed8 | 903 | EarlyNameResolver::visit (AST::RangePatternBoundQualPath &) |
52219746 AC |
904 | {} |
905 | ||
906 | void | |
907 | EarlyNameResolver::visit (AST::RangePattern &pattern) | |
908 | { | |
909 | pattern.get_lower_bound ()->accept_vis (*this); | |
910 | pattern.get_upper_bound ()->accept_vis (*this); | |
911 | } | |
912 | ||
913 | void | |
914 | EarlyNameResolver::visit (AST::ReferencePattern &pattern) | |
915 | { | |
916 | pattern.get_referenced_pattern ()->accept_vis (*this); | |
917 | } | |
918 | ||
919 | void | |
920 | EarlyNameResolver::visit (AST::StructPatternFieldTuplePat &field) | |
921 | { | |
922 | field.get_index_pattern ()->accept_vis (*this); | |
923 | } | |
924 | ||
925 | void | |
926 | EarlyNameResolver::visit (AST::StructPatternFieldIdentPat &field) | |
927 | { | |
928 | field.get_ident_pattern ()->accept_vis (*this); | |
929 | } | |
930 | ||
931 | void | |
9f455ed8 | 932 | EarlyNameResolver::visit (AST::StructPatternFieldIdent &) |
52219746 AC |
933 | {} |
934 | ||
935 | void | |
9f455ed8 | 936 | EarlyNameResolver::visit (AST::StructPattern &) |
52219746 AC |
937 | {} |
938 | ||
939 | void | |
940 | EarlyNameResolver::visit (AST::TupleStructItemsNoRange &tuple_items) | |
941 | { | |
942 | for (auto &pattern : tuple_items.get_patterns ()) | |
943 | pattern->accept_vis (*this); | |
944 | } | |
945 | ||
946 | void | |
947 | EarlyNameResolver::visit (AST::TupleStructItemsRange &tuple_items) | |
948 | { | |
949 | for (auto &pattern : tuple_items.get_lower_patterns ()) | |
950 | pattern->accept_vis (*this); | |
951 | for (auto &pattern : tuple_items.get_upper_patterns ()) | |
952 | pattern->accept_vis (*this); | |
953 | } | |
954 | ||
955 | void | |
956 | EarlyNameResolver::visit (AST::TupleStructPattern &pattern) | |
957 | { | |
958 | pattern.get_items ()->accept_vis (*this); | |
959 | } | |
960 | ||
961 | void | |
962 | EarlyNameResolver::visit (AST::TuplePatternItemsMultiple &tuple_items) | |
963 | { | |
964 | for (auto &pattern : tuple_items.get_patterns ()) | |
965 | pattern->accept_vis (*this); | |
966 | } | |
967 | ||
968 | void | |
969 | EarlyNameResolver::visit (AST::TuplePatternItemsRanged &tuple_items) | |
970 | { | |
971 | for (auto &pattern : tuple_items.get_lower_patterns ()) | |
972 | pattern->accept_vis (*this); | |
973 | for (auto &pattern : tuple_items.get_upper_patterns ()) | |
974 | pattern->accept_vis (*this); | |
975 | } | |
976 | ||
977 | void | |
978 | EarlyNameResolver::visit (AST::TuplePattern &pattern) | |
979 | { | |
980 | pattern.get_items ()->accept_vis (*this); | |
981 | } | |
982 | ||
983 | void | |
984 | EarlyNameResolver::visit (AST::GroupedPattern &pattern) | |
985 | { | |
986 | pattern.get_pattern_in_parens ()->accept_vis (*this); | |
987 | } | |
988 | ||
989 | void | |
990 | EarlyNameResolver::visit (AST::SlicePattern &pattern) | |
991 | { | |
992 | for (auto &item : pattern.get_items ()) | |
993 | item->accept_vis (*this); | |
994 | } | |
995 | ||
996 | void | |
9f455ed8 | 997 | EarlyNameResolver::visit (AST::EmptyStmt &) |
52219746 AC |
998 | {} |
999 | ||
1000 | void | |
1001 | EarlyNameResolver::visit (AST::LetStmt &stmt) | |
1002 | { | |
1003 | if (stmt.has_type ()) | |
1004 | stmt.get_type ()->accept_vis (*this); | |
1005 | ||
1006 | if (stmt.has_init_expr ()) | |
1007 | stmt.get_init_expr ()->accept_vis (*this); | |
1008 | ||
1009 | stmt.get_pattern ()->accept_vis (*this); | |
1010 | } | |
1011 | ||
1012 | void | |
1013 | EarlyNameResolver::visit (AST::ExprStmtWithoutBlock &stmt) | |
1014 | { | |
1015 | stmt.get_expr ()->accept_vis (*this); | |
1016 | } | |
1017 | ||
1018 | void | |
1019 | EarlyNameResolver::visit (AST::ExprStmtWithBlock &stmt) | |
1020 | { | |
1021 | stmt.get_expr ()->accept_vis (*this); | |
1022 | } | |
1023 | ||
1024 | void | |
9f455ed8 | 1025 | EarlyNameResolver::visit (AST::TraitBound &) |
52219746 AC |
1026 | {} |
1027 | ||
1028 | void | |
9f455ed8 | 1029 | EarlyNameResolver::visit (AST::ImplTraitType &) |
52219746 AC |
1030 | {} |
1031 | ||
1032 | void | |
9f455ed8 | 1033 | EarlyNameResolver::visit (AST::TraitObjectType &) |
52219746 AC |
1034 | {} |
1035 | ||
1036 | void | |
9f455ed8 | 1037 | EarlyNameResolver::visit (AST::ParenthesisedType &) |
52219746 AC |
1038 | {} |
1039 | ||
1040 | void | |
9f455ed8 | 1041 | EarlyNameResolver::visit (AST::ImplTraitTypeOneBound &) |
52219746 AC |
1042 | {} |
1043 | ||
1044 | void | |
9f455ed8 | 1045 | EarlyNameResolver::visit (AST::TraitObjectTypeOneBound &) |
52219746 AC |
1046 | {} |
1047 | ||
1048 | void | |
9f455ed8 | 1049 | EarlyNameResolver::visit (AST::TupleType &) |
52219746 AC |
1050 | {} |
1051 | ||
1052 | void | |
9f455ed8 | 1053 | EarlyNameResolver::visit (AST::NeverType &) |
52219746 AC |
1054 | {} |
1055 | ||
1056 | void | |
9f455ed8 | 1057 | EarlyNameResolver::visit (AST::RawPointerType &) |
52219746 AC |
1058 | {} |
1059 | ||
1060 | void | |
9f455ed8 | 1061 | EarlyNameResolver::visit (AST::ReferenceType &) |
52219746 AC |
1062 | {} |
1063 | ||
1064 | void | |
9f455ed8 | 1065 | EarlyNameResolver::visit (AST::ArrayType &) |
52219746 AC |
1066 | {} |
1067 | ||
1068 | void | |
9f455ed8 | 1069 | EarlyNameResolver::visit (AST::SliceType &) |
52219746 AC |
1070 | {} |
1071 | ||
1072 | void | |
9f455ed8 | 1073 | EarlyNameResolver::visit (AST::InferredType &) |
52219746 AC |
1074 | {} |
1075 | ||
1076 | void | |
1077 | EarlyNameResolver::visit (AST::BareFunctionType &type) | |
1078 | { | |
1079 | for (auto ¶m : type.get_function_params ()) | |
1080 | param.get_type ()->accept_vis (*this); | |
1081 | ||
1082 | if (type.has_return_type ()) | |
1083 | type.get_return_type ()->accept_vis (*this); | |
1084 | } | |
1085 | ||
1086 | } // namespace Resolver | |
1087 | } // namespace Rust |