]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/rust/resolve/rust-early-name-resolver.cc
gccrs: Skip this debug test case which is failing on the latest mac-os devtools and...
[thirdparty/gcc.git] / gcc / rust / resolve / rust-early-name-resolver.cc
CommitLineData
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
23namespace Rust {
24namespace Resolver {
25
26EarlyNameResolver::EarlyNameResolver ()
27 : resolver (*Resolver::get ()), mappings (*Analysis::Mappings::get ())
28{}
29
30void
31EarlyNameResolver::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
43void
44EarlyNameResolver::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
53void
54EarlyNameResolver::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
62void
63EarlyNameResolver::visit (AST::Token &tok)
64{}
65
66void
67EarlyNameResolver::visit (AST::DelimTokenTree &delim_tok_tree)
68{}
69
70void
71EarlyNameResolver::visit (AST::AttrInputMetaItemContainer &input)
72{}
73
74void
75EarlyNameResolver::visit (AST::IdentifierExpr &ident_expr)
76{}
77
78void
79EarlyNameResolver::visit (AST::Lifetime &lifetime)
80{}
81
82void
83EarlyNameResolver::visit (AST::LifetimeParam &lifetime_param)
84{}
85
86void
87EarlyNameResolver::visit (AST::ConstGenericParam &const_param)
88{}
89
90// FIXME: ARTHUR: Do we need to perform macro resolution for paths as well?
91// std::arch::asm!()?
92void
93EarlyNameResolver::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
100void
101EarlyNameResolver::visit (AST::TypePathSegment &segment)
102{}
103
104void
105EarlyNameResolver::visit (AST::TypePathSegmentGeneric &segment)
106{
107 if (segment.has_generic_args ())
108 resolve_generic_args (segment.get_generic_args ());
109}
110
111void
112EarlyNameResolver::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
120void
121EarlyNameResolver::visit (AST::TypePath &path)
122{
123 for (auto &seg : path.get_segments ())
124 seg->accept_vis (*this);
125}
126
127void
128EarlyNameResolver::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
137void
138EarlyNameResolver::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
146void
147EarlyNameResolver::visit (AST::LiteralExpr &expr)
148{}
149
150void
151EarlyNameResolver::visit (AST::AttrInputLiteral &attr_input)
152{}
153
154void
155EarlyNameResolver::visit (AST::MetaItemLitExpr &meta_item)
156{}
157
158void
159EarlyNameResolver::visit (AST::MetaItemPathLit &meta_item)
160{}
161
162void
163EarlyNameResolver::visit (AST::BorrowExpr &expr)
164{
165 expr.get_borrowed_expr ()->accept_vis (*this);
166}
167
168void
169EarlyNameResolver::visit (AST::DereferenceExpr &expr)
170{
171 expr.get_dereferenced_expr ()->accept_vis (*this);
172}
173
174void
175EarlyNameResolver::visit (AST::ErrorPropagationExpr &expr)
176{
177 expr.get_propagating_expr ()->accept_vis (*this);
178}
179
180void
181EarlyNameResolver::visit (AST::NegationExpr &expr)
182{
183 expr.get_negated_expr ()->accept_vis (*this);
184}
185
186void
187EarlyNameResolver::visit (AST::ArithmeticOrLogicalExpr &expr)
188{
189 expr.get_left_expr ()->accept_vis (*this);
190 expr.get_right_expr ()->accept_vis (*this);
191}
192
193void
194EarlyNameResolver::visit (AST::ComparisonExpr &expr)
195{
196 expr.get_left_expr ()->accept_vis (*this);
197 expr.get_right_expr ()->accept_vis (*this);
198}
199
200void
201EarlyNameResolver::visit (AST::LazyBooleanExpr &expr)
202{
203 expr.get_left_expr ()->accept_vis (*this);
204 expr.get_right_expr ()->accept_vis (*this);
205}
206
207void
208EarlyNameResolver::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
214void
215EarlyNameResolver::visit (AST::AssignmentExpr &expr)
216{
217 expr.get_left_expr ()->accept_vis (*this);
218 expr.get_right_expr ()->accept_vis (*this);
219}
220
221void
222EarlyNameResolver::visit (AST::CompoundAssignmentExpr &expr)
223{
224 expr.get_left_expr ()->accept_vis (*this);
225 expr.get_right_expr ()->accept_vis (*this);
226}
227
228void
229EarlyNameResolver::visit (AST::GroupedExpr &expr)
230{
231 expr.get_expr_in_parens ()->accept_vis (*this);
232}
233
234void
235EarlyNameResolver::visit (AST::ArrayElemsValues &elems)
236{
237 for (auto &expr : elems.get_values ())
238 expr->accept_vis (*this);
239}
240
241void
242EarlyNameResolver::visit (AST::ArrayElemsCopied &elems)
243{
244 elems.get_elem_to_copy ()->accept_vis (*this);
245}
246
247void
248EarlyNameResolver::visit (AST::ArrayExpr &expr)
249{
250 expr.get_array_elems ()->accept_vis (*this);
251}
252
253void
254EarlyNameResolver::visit (AST::ArrayIndexExpr &expr)
255{
256 expr.get_array_expr ()->accept_vis (*this);
257 expr.get_index_expr ()->accept_vis (*this);
258}
259
260void
261EarlyNameResolver::visit (AST::TupleExpr &expr)
262{
263 for (auto &elem : expr.get_tuple_elems ())
264 elem->accept_vis (*this);
265}
266
267void
268EarlyNameResolver::visit (AST::TupleIndexExpr &expr)
269{
270 expr.get_tuple_expr ()->accept_vis (*this);
271}
272
273void
274EarlyNameResolver::visit (AST::StructExprStruct &expr)
275{}
276
277void
278EarlyNameResolver::visit (AST::StructExprFieldIdentifier &field)
279{}
280
281void
282EarlyNameResolver::visit (AST::StructExprFieldIdentifierValue &field)
283{
284 field.get_value ()->accept_vis (*this);
285}
286
287void
288EarlyNameResolver::visit (AST::StructExprFieldIndexValue &field)
289{
290 field.get_value ()->accept_vis (*this);
291}
292
293void
294EarlyNameResolver::visit (AST::StructExprStructFields &expr)
295{
296 for (auto &field : expr.get_fields ())
297 field->accept_vis (*this);
298}
299
300void
301EarlyNameResolver::visit (AST::StructExprStructBase &expr)
302{}
303
304void
305EarlyNameResolver::visit (AST::CallExpr &expr)
306{
307 expr.get_function_expr ()->accept_vis (*this);
308 for (auto &param : expr.get_params ())
309 param->accept_vis (*this);
310}
311
312void
313EarlyNameResolver::visit (AST::MethodCallExpr &expr)
314{
315 expr.get_receiver_expr ()->accept_vis (*this);
316 for (auto &param : expr.get_params ())
317 param->accept_vis (*this);
318}
319
320void
321EarlyNameResolver::visit (AST::FieldAccessExpr &expr)
322{
323 expr.get_receiver_expr ()->accept_vis (*this);
324}
325
326void
327EarlyNameResolver::visit (AST::ClosureExprInner &expr)
328{
329 expr.get_definition_expr ()->accept_vis (*this);
330
331 for (auto &param : expr.get_params ())
332 param.get_type ()->accept_vis (*this);
333}
334
335void
336EarlyNameResolver::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
345void
346EarlyNameResolver::visit (AST::ClosureExprInnerTyped &expr)
347{
348 expr.get_definition_block ()->accept_vis (*this);
349
350 for (auto &param : expr.get_params ())
351 param.get_type ()->accept_vis (*this);
352}
353
354void
355EarlyNameResolver::visit (AST::ContinueExpr &expr)
356{}
357
358void
359EarlyNameResolver::visit (AST::BreakExpr &expr)
360{
361 if (expr.has_break_expr ())
362 expr.get_break_expr ()->accept_vis (*this);
363}
364
365void
366EarlyNameResolver::visit (AST::RangeFromToExpr &expr)
367{
368 expr.get_from_expr ()->accept_vis (*this);
369 expr.get_to_expr ()->accept_vis (*this);
370}
371
372void
373EarlyNameResolver::visit (AST::RangeFromExpr &expr)
374{
375 expr.get_from_expr ()->accept_vis (*this);
376}
377
378void
379EarlyNameResolver::visit (AST::RangeToExpr &expr)
380{
381 expr.get_to_expr ()->accept_vis (*this);
382}
383
384void
385EarlyNameResolver::visit (AST::RangeFullExpr &expr)
386{}
387
388void
389EarlyNameResolver::visit (AST::RangeFromToInclExpr &expr)
390{
391 expr.get_from_expr ()->accept_vis (*this);
392 expr.get_to_expr ()->accept_vis (*this);
393}
394
395void
396EarlyNameResolver::visit (AST::RangeToInclExpr &expr)
397{
398 expr.get_to_expr ()->accept_vis (*this);
399}
400
401void
402EarlyNameResolver::visit (AST::ReturnExpr &expr)
403{
404 if (expr.has_returned_expr ())
405 expr.get_returned_expr ()->accept_vis (*this);
406}
407
408void
409EarlyNameResolver::visit (AST::UnsafeBlockExpr &expr)
410{
411 expr.get_block_expr ()->accept_vis (*this);
412}
413
414void
415EarlyNameResolver::visit (AST::LoopExpr &expr)
416{
417 expr.get_loop_block ()->accept_vis (*this);
418}
419
420void
421EarlyNameResolver::visit (AST::WhileLoopExpr &expr)
422{
423 expr.get_predicate_expr ()->accept_vis (*this);
424 expr.get_loop_block ()->accept_vis (*this);
425}
426
427void
428EarlyNameResolver::visit (AST::WhileLetLoopExpr &expr)
429{
430 expr.get_scrutinee_expr ()->accept_vis (*this);
431 expr.get_loop_block ()->accept_vis (*this);
432}
433
434void
435EarlyNameResolver::visit (AST::ForLoopExpr &expr)
436{
437 expr.get_iterator_expr ()->accept_vis (*this);
438 expr.get_loop_block ()->accept_vis (*this);
439}
440
441void
442EarlyNameResolver::visit (AST::IfExpr &expr)
443{
444 expr.get_condition_expr ()->accept_vis (*this);
445 expr.get_if_block ()->accept_vis (*this);
446}
447
448void
449EarlyNameResolver::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
456void
457EarlyNameResolver::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
464void
465EarlyNameResolver::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
472void
473EarlyNameResolver::visit (AST::IfLetExpr &expr)
474{
475 expr.get_value_expr ()->accept_vis (*this);
476 expr.get_if_block ()->accept_vis (*this);
477}
478
479void
480EarlyNameResolver::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
487void
488EarlyNameResolver::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
495void
496EarlyNameResolver::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
503void
504EarlyNameResolver::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
519void
520EarlyNameResolver::visit (AST::AwaitExpr &expr)
521{
522 expr.get_awaited_expr ()->accept_vis (*this);
523}
524
525void
526EarlyNameResolver::visit (AST::AsyncBlockExpr &expr)
527{
528 expr.get_block_expr ()->accept_vis (*this);
529}
530
531void
532EarlyNameResolver::visit (AST::TypeParam &param)
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
541void
542EarlyNameResolver::visit (AST::LifetimeWhereClauseItem &item)
543{}
544
545void
546EarlyNameResolver::visit (AST::TypeBoundWhereClauseItem &item)
547{
548 for (auto &bound : item.get_type_param_bounds ())
549 bound->accept_vis (*this);
550}
551
552void
553EarlyNameResolver::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 &param : 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
571void
572EarlyNameResolver::visit (AST::Module &module)
573{
574 for (auto &item : module.get_items ())
575 item->accept_vis (*this);
576}
577
578void
579EarlyNameResolver::visit (AST::ExternCrate &crate)
580{}
581
582void
583EarlyNameResolver::visit (AST::UseTreeGlob &use_tree)
584{}
585
586void
587EarlyNameResolver::visit (AST::UseTreeList &use_tree)
588{}
589
590void
591EarlyNameResolver::visit (AST::UseTreeRebind &use_tree)
592{}
593
594void
595EarlyNameResolver::visit (AST::UseDeclaration &use_decl)
596{}
597
598void
599EarlyNameResolver::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 &param : 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
614void
615EarlyNameResolver::visit (AST::TypeAlias &type_alias)
616{
617 type_alias.get_type_aliased ()->accept_vis (*this);
618}
619
620void
621EarlyNameResolver::visit (AST::StructStruct &struct_item)
622{
623 for (auto &field : struct_item.get_fields ())
624 field.get_field_type ()->accept_vis (*this);
625}
626
627void
628EarlyNameResolver::visit (AST::TupleStruct &tuple_struct)
629{
630 for (auto &field : tuple_struct.get_fields ())
631 field.get_field_type ()->accept_vis (*this);
632}
633
634void
635EarlyNameResolver::visit (AST::EnumItem &item)
636{}
637
638void
639EarlyNameResolver::visit (AST::EnumItemTuple &item)
640{}
641
642void
643EarlyNameResolver::visit (AST::EnumItemStruct &item)
644{}
645
646void
647EarlyNameResolver::visit (AST::EnumItemDiscriminant &item)
648{}
649
650void
651EarlyNameResolver::visit (AST::Enum &enum_item)
652{}
653
654void
655EarlyNameResolver::visit (AST::Union &union_item)
656{}
657
658void
659EarlyNameResolver::visit (AST::ConstantItem &const_item)
660{
661 const_item.get_type ()->accept_vis (*this);
662 const_item.get_expr ()->accept_vis (*this);
663}
664
665void
666EarlyNameResolver::visit (AST::StaticItem &static_item)
667{
668 static_item.get_type ()->accept_vis (*this);
669 static_item.get_expr ()->accept_vis (*this);
670}
671
672void
673EarlyNameResolver::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 &param : 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
690void
691EarlyNameResolver::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 &param : 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
709void
710EarlyNameResolver::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
718void
719EarlyNameResolver::visit (AST::TraitItemType &item)
720{}
721
722void
723EarlyNameResolver::visit (AST::Trait &trait)
724{
725 for (auto &item : trait.get_trait_items ())
726 item->accept_vis (*this);
727}
728
729void
730EarlyNameResolver::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
741void
742EarlyNameResolver::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
753void
754EarlyNameResolver::visit (AST::ExternalStaticItem &item)
755{
756 item.get_type ()->accept_vis (*this);
757}
758
759void
760EarlyNameResolver::visit (AST::ExternalFunctionItem &item)
761{
762 for (auto &generic : item.get_generic_params ())
763 generic->accept_vis (*this);
764
765 for (auto &param : 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
772void
773EarlyNameResolver::visit (AST::ExternBlock &block)
774{
775 for (auto &item : block.get_extern_items ())
776 item->accept_vis (*this);
777}
778
779void
780EarlyNameResolver::visit (AST::MacroMatchFragment &match)
781{}
782
783void
784EarlyNameResolver::visit (AST::MacroMatchRepetition &match)
785{}
786
787void
788EarlyNameResolver::visit (AST::MacroMatcher &matcher)
789{}
790
791void
792EarlyNameResolver::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
803void
804EarlyNameResolver::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
855void
856EarlyNameResolver::visit (AST::MetaItemPath &meta_item)
857{}
858
859void
860EarlyNameResolver::visit (AST::MetaItemSeq &meta_item)
861{}
862
863void
864EarlyNameResolver::visit (AST::MetaWord &meta_item)
865{}
866
867void
868EarlyNameResolver::visit (AST::MetaNameValueStr &meta_item)
869{}
870
871void
872EarlyNameResolver::visit (AST::MetaListPaths &meta_item)
873{}
874
875void
876EarlyNameResolver::visit (AST::MetaListNameValueStr &meta_item)
877{}
878
879void
880EarlyNameResolver::visit (AST::LiteralPattern &pattern)
881{}
882
883void
884EarlyNameResolver::visit (AST::IdentifierPattern &pattern)
885{
886 if (pattern.has_pattern_to_bind ())
887 pattern.get_pattern_to_bind ()->accept_vis (*this);
888}
889
890void
891EarlyNameResolver::visit (AST::WildcardPattern &pattern)
892{}
893
894void
895EarlyNameResolver::visit (AST::RangePatternBoundLiteral &bound)
896{}
897
898void
899EarlyNameResolver::visit (AST::RangePatternBoundPath &bound)
900{}
901
902void
903EarlyNameResolver::visit (AST::RangePatternBoundQualPath &bound)
904{}
905
906void
907EarlyNameResolver::visit (AST::RangePattern &pattern)
908{
909 pattern.get_lower_bound ()->accept_vis (*this);
910 pattern.get_upper_bound ()->accept_vis (*this);
911}
912
913void
914EarlyNameResolver::visit (AST::ReferencePattern &pattern)
915{
916 pattern.get_referenced_pattern ()->accept_vis (*this);
917}
918
919void
920EarlyNameResolver::visit (AST::StructPatternFieldTuplePat &field)
921{
922 field.get_index_pattern ()->accept_vis (*this);
923}
924
925void
926EarlyNameResolver::visit (AST::StructPatternFieldIdentPat &field)
927{
928 field.get_ident_pattern ()->accept_vis (*this);
929}
930
931void
932EarlyNameResolver::visit (AST::StructPatternFieldIdent &field)
933{}
934
935void
936EarlyNameResolver::visit (AST::StructPattern &pattern)
937{}
938
939void
940EarlyNameResolver::visit (AST::TupleStructItemsNoRange &tuple_items)
941{
942 for (auto &pattern : tuple_items.get_patterns ())
943 pattern->accept_vis (*this);
944}
945
946void
947EarlyNameResolver::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
955void
956EarlyNameResolver::visit (AST::TupleStructPattern &pattern)
957{
958 pattern.get_items ()->accept_vis (*this);
959}
960
961void
962EarlyNameResolver::visit (AST::TuplePatternItemsMultiple &tuple_items)
963{
964 for (auto &pattern : tuple_items.get_patterns ())
965 pattern->accept_vis (*this);
966}
967
968void
969EarlyNameResolver::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
977void
978EarlyNameResolver::visit (AST::TuplePattern &pattern)
979{
980 pattern.get_items ()->accept_vis (*this);
981}
982
983void
984EarlyNameResolver::visit (AST::GroupedPattern &pattern)
985{
986 pattern.get_pattern_in_parens ()->accept_vis (*this);
987}
988
989void
990EarlyNameResolver::visit (AST::SlicePattern &pattern)
991{
992 for (auto &item : pattern.get_items ())
993 item->accept_vis (*this);
994}
995
996void
997EarlyNameResolver::visit (AST::EmptyStmt &stmt)
998{}
999
1000void
1001EarlyNameResolver::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
1012void
1013EarlyNameResolver::visit (AST::ExprStmtWithoutBlock &stmt)
1014{
1015 stmt.get_expr ()->accept_vis (*this);
1016}
1017
1018void
1019EarlyNameResolver::visit (AST::ExprStmtWithBlock &stmt)
1020{
1021 stmt.get_expr ()->accept_vis (*this);
1022}
1023
1024void
1025EarlyNameResolver::visit (AST::TraitBound &bound)
1026{}
1027
1028void
1029EarlyNameResolver::visit (AST::ImplTraitType &type)
1030{}
1031
1032void
1033EarlyNameResolver::visit (AST::TraitObjectType &type)
1034{}
1035
1036void
1037EarlyNameResolver::visit (AST::ParenthesisedType &type)
1038{}
1039
1040void
1041EarlyNameResolver::visit (AST::ImplTraitTypeOneBound &type)
1042{}
1043
1044void
1045EarlyNameResolver::visit (AST::TraitObjectTypeOneBound &type)
1046{}
1047
1048void
1049EarlyNameResolver::visit (AST::TupleType &type)
1050{}
1051
1052void
1053EarlyNameResolver::visit (AST::NeverType &type)
1054{}
1055
1056void
1057EarlyNameResolver::visit (AST::RawPointerType &type)
1058{}
1059
1060void
1061EarlyNameResolver::visit (AST::ReferenceType &type)
1062{}
1063
1064void
1065EarlyNameResolver::visit (AST::ArrayType &type)
1066{}
1067
1068void
1069EarlyNameResolver::visit (AST::SliceType &type)
1070{}
1071
1072void
1073EarlyNameResolver::visit (AST::InferredType &type)
1074{}
1075
1076void
1077EarlyNameResolver::visit (AST::BareFunctionType &type)
1078{
1079 for (auto &param : 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