Line data Source code
1 : // Copyright (C) 2021-2026 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-expr.h"
20 : #include "rust-hir-full-decls.h"
21 : #include "rust-hir-visitor.h"
22 : #include "rust-hir-full.h"
23 : #include "rust-system.h"
24 :
25 : namespace Rust {
26 : namespace HIR {
27 :
28 : void
29 5916 : DefaultHIRVisitor::walk (Lifetime &)
30 5916 : {}
31 :
32 : void
33 160 : DefaultHIRVisitor::walk (LifetimeParam &lifetime_param)
34 : {
35 160 : visit_outer_attrs (lifetime_param);
36 160 : lifetime_param.get_lifetime ().accept_vis (*this);
37 160 : for (Lifetime &lifetime_bound : lifetime_param.get_lifetime_bounds ())
38 0 : lifetime_bound.accept_vis (*this);
39 160 : }
40 :
41 : void
42 2345 : DefaultHIRVisitor::visit_generic_args (GenericArgs &generic_args)
43 : {
44 2364 : for (auto &lifetime : generic_args.get_lifetime_args ())
45 19 : lifetime.accept_vis (*this);
46 4774 : for (auto &type : generic_args.get_type_args ())
47 2429 : type->accept_vis (*this);
48 2410 : for (auto &binding : generic_args.get_binding_args ())
49 65 : binding.get_type ().accept_vis (*this);
50 2381 : for (auto &const_arg : generic_args.get_const_args ())
51 36 : const_arg.get_expression ()->accept_vis (*this);
52 2345 : }
53 :
54 : void
55 38 : DefaultHIRVisitor::walk (PathInExpression &path_in_expr)
56 : {
57 38 : visit_outer_attrs (path_in_expr);
58 38 : if (!path_in_expr.is_lang_item ())
59 76 : for (auto &segment : path_in_expr.get_segments ())
60 38 : visit_path_expr_segment (segment);
61 38 : }
62 :
63 : void
64 46222 : DefaultHIRVisitor::walk (TypePathSegment &)
65 46222 : {}
66 :
67 : void
68 27 : DefaultHIRVisitor::walk (TypePathSegmentFunction &segment_function)
69 : {
70 27 : TypePathFunction &function_path = segment_function.get_function_path ();
71 27 : if (function_path.has_inputs ())
72 56 : for (auto ¶m : function_path.get_params ())
73 29 : param->accept_vis (*this);
74 27 : if (function_path.has_return_type ())
75 27 : function_path.get_return_type ().accept_vis (*this);
76 27 : }
77 :
78 : void
79 2345 : DefaultHIRVisitor::walk (TypePathSegmentGeneric &segment_generic)
80 : {
81 2345 : if (segment_generic.has_generic_args ())
82 2345 : visit_generic_args (segment_generic.get_generic_args ());
83 2345 : }
84 :
85 : void
86 46589 : DefaultHIRVisitor::walk (TypePath &type_path)
87 : {
88 94984 : for (auto &segment : type_path.get_segments ())
89 48395 : segment->accept_vis (*this);
90 46589 : }
91 :
92 : void
93 271 : DefaultHIRVisitor::visit_qualified_path_type (QualifiedPathType &path)
94 : {
95 271 : path.get_type ().accept_vis (*this);
96 271 : if (path.has_as_clause ())
97 239 : path.get_trait ().accept_vis (*this);
98 271 : }
99 :
100 : // TODO: Implement visit_path_expr_segment
101 : void
102 1490 : DefaultHIRVisitor::visit_path_expr_segment (PathExprSegment &segment)
103 : {
104 1490 : if (segment.has_generic_args ())
105 0 : visit_generic_args (segment.get_generic_args ());
106 1490 : }
107 :
108 : void
109 72 : DefaultHIRVisitor::walk (QualifiedPathInExpression &path_in_expr)
110 : {
111 72 : visit_outer_attrs (path_in_expr);
112 72 : visit_qualified_path_type (path_in_expr.get_path_type ());
113 144 : for (auto &segment : path_in_expr.get_segments ())
114 72 : visit_path_expr_segment (segment);
115 72 : }
116 :
117 : void
118 199 : DefaultHIRVisitor::walk (QualifiedPathInType &path_in_type)
119 : {
120 199 : visit_qualified_path_type (path_in_type.get_path_type ());
121 199 : path_in_type.get_associated_segment ().accept_vis (*this);
122 199 : for (auto &segment : path_in_type.get_segments ())
123 0 : segment->accept_vis (*this);
124 199 : }
125 :
126 : void
127 49 : DefaultHIRVisitor::walk (LiteralExpr &expr)
128 : {
129 49 : visit_outer_attrs (expr);
130 49 : }
131 :
132 : void
133 1223 : DefaultHIRVisitor::walk (BorrowExpr &expr)
134 : {
135 1223 : visit_outer_attrs (expr);
136 1223 : expr.get_expr ().accept_vis (*this);
137 1223 : }
138 :
139 : void
140 0 : DefaultHIRVisitor::walk (DereferenceExpr &expr)
141 : {
142 0 : visit_outer_attrs (expr);
143 0 : expr.get_expr ().accept_vis (*this);
144 0 : }
145 :
146 : void
147 0 : DefaultHIRVisitor::walk (ErrorPropagationExpr &expr)
148 : {
149 0 : visit_outer_attrs (expr);
150 0 : expr.get_expr ().accept_vis (*this);
151 0 : }
152 :
153 : void
154 480 : DefaultHIRVisitor::walk (NegationExpr &expr)
155 : {
156 480 : visit_outer_attrs (expr);
157 480 : expr.get_expr ().accept_vis (*this);
158 480 : }
159 :
160 : void
161 2211 : DefaultHIRVisitor::walk (ArithmeticOrLogicalExpr &expr)
162 : {
163 2211 : visit_outer_attrs (expr);
164 2211 : expr.get_lhs ().accept_vis (*this);
165 2211 : expr.get_rhs ().accept_vis (*this);
166 2211 : }
167 :
168 : void
169 3419 : DefaultHIRVisitor::walk (ComparisonExpr &expr)
170 : {
171 3419 : visit_outer_attrs (expr);
172 3419 : expr.get_lhs ().accept_vis (*this);
173 3419 : expr.get_rhs ().accept_vis (*this);
174 3419 : }
175 :
176 : void
177 355 : DefaultHIRVisitor::walk (LazyBooleanExpr &expr)
178 : {
179 355 : visit_outer_attrs (expr);
180 355 : expr.get_lhs ().accept_vis (*this);
181 355 : expr.get_rhs ().accept_vis (*this);
182 355 : }
183 :
184 : void
185 2041 : DefaultHIRVisitor::walk (TypeCastExpr &expr)
186 : {
187 2041 : visit_outer_attrs (expr);
188 2041 : expr.get_expr ().accept_vis (*this);
189 2041 : expr.get_type_to_convert_to ().accept_vis (*this);
190 2041 : }
191 :
192 : void
193 0 : DefaultHIRVisitor::walk (AssignmentExpr &expr)
194 : {
195 0 : visit_outer_attrs (expr);
196 0 : expr.get_lhs ().accept_vis (*this);
197 0 : expr.get_rhs ().accept_vis (*this);
198 0 : }
199 :
200 : void
201 675 : DefaultHIRVisitor::walk (CompoundAssignmentExpr &expr)
202 : {
203 675 : visit_outer_attrs (expr);
204 675 : expr.get_lhs ().accept_vis (*this);
205 675 : expr.get_rhs ().accept_vis (*this);
206 675 : }
207 :
208 : void
209 185 : DefaultHIRVisitor::walk (GroupedExpr &expr)
210 : {
211 185 : visit_outer_attrs (expr);
212 185 : visit_inner_attrs (expr);
213 185 : expr.get_expr_in_parens ().accept_vis (*this);
214 185 : }
215 :
216 : void
217 38 : DefaultHIRVisitor::walk (ArrayElemsValues &elems)
218 : {
219 248 : for (auto &elem : elems.get_values ())
220 210 : elem->accept_vis (*this);
221 38 : }
222 :
223 : void
224 37 : DefaultHIRVisitor::walk (ArrayElemsCopied &elems)
225 : {
226 37 : elems.get_elem_to_copy ().accept_vis (*this);
227 37 : elems.get_num_copies_expr ().accept_vis (*this);
228 37 : }
229 :
230 : void
231 75 : DefaultHIRVisitor::walk (ArrayExpr &expr)
232 : {
233 75 : visit_outer_attrs (expr);
234 75 : visit_inner_attrs (expr);
235 75 : expr.get_internal_elements ().accept_vis (*this);
236 75 : }
237 :
238 : void
239 0 : DefaultHIRVisitor::walk (ArrayIndexExpr &expr)
240 : {
241 0 : visit_outer_attrs (expr);
242 0 : expr.get_array_expr ().accept_vis (*this);
243 0 : expr.get_index_expr ().accept_vis (*this);
244 0 : }
245 :
246 : void
247 2 : DefaultHIRVisitor::walk (TupleExpr &expr)
248 : {
249 2 : visit_outer_attrs (expr);
250 2 : visit_inner_attrs (expr);
251 6 : for (auto &elem : expr.get_tuple_elems ())
252 4 : elem->accept_vis (*this);
253 2 : }
254 :
255 : void
256 0 : DefaultHIRVisitor::walk (TupleIndexExpr &expr)
257 : {
258 0 : visit_outer_attrs (expr);
259 0 : expr.get_tuple_expr ().accept_vis (*this);
260 0 : }
261 :
262 : void
263 13 : DefaultHIRVisitor::walk (StructExprStruct &expr)
264 : {
265 13 : visit_outer_attrs (expr);
266 13 : visit_inner_attrs (expr);
267 13 : expr.get_struct_name ().accept_vis (*this);
268 13 : }
269 :
270 : void
271 100 : DefaultHIRVisitor::walk (StructExprFieldIdentifier &)
272 100 : {}
273 :
274 : void
275 295 : DefaultHIRVisitor::walk (StructExprFieldIdentifierValue &field)
276 : {
277 295 : field.get_value ().accept_vis (*this);
278 295 : }
279 :
280 : void
281 0 : DefaultHIRVisitor::walk (StructExprFieldIndexValue &field)
282 : {
283 0 : field.get_value ().accept_vis (*this);
284 0 : }
285 :
286 : void
287 197 : DefaultHIRVisitor::walk (StructExprStructFields &expr)
288 : {
289 197 : visit_outer_attrs (expr);
290 197 : visit_inner_attrs (expr);
291 197 : expr.get_struct_name ().accept_vis (*this);
292 197 : if (expr.has_struct_base ())
293 : {
294 0 : StructBase &base = expr.get_struct_base ();
295 0 : base.get_base ().accept_vis (*this);
296 : }
297 592 : for (auto &field : expr.get_fields ())
298 395 : field->accept_vis (*this);
299 197 : }
300 :
301 : void
302 0 : DefaultHIRVisitor::walk (StructExprStructBase &expr)
303 : {
304 0 : visit_outer_attrs (expr);
305 0 : visit_inner_attrs (expr);
306 0 : expr.get_struct_name ().accept_vis (*this);
307 0 : StructBase &base = expr.get_struct_base ();
308 0 : base.get_base ().accept_vis (*this);
309 0 : }
310 :
311 : void
312 9241 : DefaultHIRVisitor::walk (CallExpr &expr)
313 : {
314 9241 : visit_outer_attrs (expr);
315 9241 : expr.get_fnexpr ().accept_vis (*this);
316 19386 : for (auto &arg : expr.get_arguments ())
317 10145 : arg->accept_vis (*this);
318 9241 : }
319 :
320 : void
321 1380 : DefaultHIRVisitor::walk (MethodCallExpr &expr)
322 : {
323 1380 : visit_outer_attrs (expr);
324 1380 : expr.get_receiver ().accept_vis (*this);
325 1380 : visit_path_expr_segment (expr.get_method_name ());
326 2255 : for (auto &arg : expr.get_arguments ())
327 875 : arg->accept_vis (*this);
328 1380 : }
329 :
330 : void
331 0 : DefaultHIRVisitor::walk (FieldAccessExpr &expr)
332 : {
333 0 : visit_outer_attrs (expr);
334 0 : expr.get_receiver_expr ().accept_vis (*this);
335 0 : }
336 :
337 : void
338 0 : DefaultHIRVisitor::visit_closure_param (ClosureParam ¶m)
339 : {
340 0 : visit_outer_attrs (param);
341 0 : param.get_pattern ().accept_vis (*this);
342 0 : if (param.has_type_given ())
343 : {
344 0 : param.get_type ().accept_vis (*this);
345 : }
346 0 : }
347 :
348 : void
349 7 : DefaultHIRVisitor::walk (ClosureExpr &expr)
350 : {
351 7 : visit_outer_attrs (expr);
352 7 : for (auto ¶m : expr.get_params ())
353 0 : visit_closure_param (param);
354 7 : if (expr.has_return_type ())
355 0 : expr.get_return_type ().accept_vis (*this);
356 7 : expr.get_expr ().accept_vis (*this);
357 7 : }
358 :
359 : void
360 21958 : DefaultHIRVisitor::walk (BlockExpr &expr)
361 : {
362 21958 : visit_outer_attrs (expr);
363 21958 : visit_inner_attrs (expr);
364 45585 : for (auto &stmt : expr.get_statements ())
365 23627 : stmt->accept_vis (*this);
366 21958 : if (expr.has_expr ())
367 15508 : expr.get_final_expr ().accept_vis (*this);
368 21958 : }
369 :
370 : void
371 481 : DefaultHIRVisitor::walk (AnonConst &expr)
372 : {
373 481 : if (!expr.is_deferred ())
374 481 : expr.get_inner_expr ().accept_vis (*this);
375 481 : }
376 :
377 : void
378 7 : DefaultHIRVisitor::walk (ConstBlock &expr)
379 : {
380 7 : expr.get_const_expr ().accept_vis (*this);
381 7 : }
382 :
383 : void
384 18 : DefaultHIRVisitor::walk (ContinueExpr &expr)
385 : {
386 18 : visit_outer_attrs (expr);
387 18 : if (expr.has_label ())
388 8 : expr.get_label ().accept_vis (*this);
389 18 : }
390 :
391 : void
392 67 : DefaultHIRVisitor::walk (BreakExpr &expr)
393 : {
394 67 : visit_outer_attrs (expr);
395 67 : if (expr.has_label ())
396 30 : expr.get_label ().accept_vis (*this);
397 :
398 67 : if (expr.has_break_expr ())
399 1 : expr.get_expr ().accept_vis (*this);
400 67 : }
401 :
402 : void
403 0 : DefaultHIRVisitor::walk (RangeFromToExpr &expr)
404 : {
405 0 : expr.get_from_expr ().accept_vis (*this);
406 0 : expr.get_to_expr ().accept_vis (*this);
407 0 : }
408 :
409 : void
410 0 : DefaultHIRVisitor::walk (RangeFromExpr &expr)
411 : {
412 0 : expr.get_from_expr ().accept_vis (*this);
413 0 : }
414 :
415 : void
416 0 : DefaultHIRVisitor::walk (RangeToExpr &expr)
417 : {
418 0 : expr.get_to_expr ().accept_vis (*this);
419 0 : }
420 :
421 : void
422 0 : DefaultHIRVisitor::walk (RangeFullExpr &)
423 0 : {}
424 :
425 : void
426 0 : DefaultHIRVisitor::walk (RangeToInclExpr &expr)
427 : {
428 0 : expr.get_to_expr ().accept_vis (*this);
429 0 : }
430 :
431 : void
432 1 : DefaultHIRVisitor::walk (BoxExpr &expr)
433 : {
434 1 : visit_outer_attrs (expr);
435 1 : expr.get_expr ().accept_vis (*this);
436 1 : }
437 :
438 : void
439 521 : DefaultHIRVisitor::walk (ReturnExpr &expr)
440 : {
441 521 : visit_outer_attrs (expr);
442 521 : if (expr.has_return_expr ())
443 490 : expr.get_expr ().accept_vis (*this);
444 521 : }
445 :
446 : void
447 3241 : DefaultHIRVisitor::walk (UnsafeBlockExpr &expr)
448 : {
449 3241 : visit_outer_attrs (expr);
450 3241 : expr.get_block_expr ().accept_vis (*this);
451 3241 : }
452 :
453 : void
454 53 : DefaultHIRVisitor::visit_loop_label (LoopLabel &label)
455 : {
456 53 : label.get_lifetime ().accept_vis (*this);
457 53 : }
458 :
459 : void
460 103 : DefaultHIRVisitor::walk (LoopExpr &expr)
461 : {
462 103 : visit_outer_attrs (expr);
463 103 : if (expr.has_loop_label ())
464 51 : visit_loop_label (expr.get_loop_label ());
465 103 : expr.get_loop_block ().accept_vis (*this);
466 103 : }
467 :
468 : void
469 79 : DefaultHIRVisitor::walk (WhileLoopExpr &expr)
470 : {
471 79 : visit_outer_attrs (expr);
472 79 : if (expr.has_loop_label ())
473 6 : visit_loop_label (expr.get_loop_label ());
474 79 : expr.get_predicate_expr ().accept_vis (*this);
475 79 : expr.get_loop_block ().accept_vis (*this);
476 79 : }
477 :
478 : void
479 0 : DefaultHIRVisitor::walk (WhileLetLoopExpr &expr)
480 : {
481 0 : visit_outer_attrs (expr);
482 0 : expr.get_pattern ()->accept_vis (*this);
483 0 : if (expr.has_loop_label ())
484 0 : visit_loop_label (expr.get_loop_label ());
485 0 : expr.get_cond ().accept_vis (*this);
486 0 : expr.get_loop_block ().accept_vis (*this);
487 0 : }
488 :
489 : void
490 2430 : DefaultHIRVisitor::walk (IfExpr &expr)
491 : {
492 2430 : visit_outer_attrs (expr);
493 2430 : expr.get_if_condition ().accept_vis (*this);
494 2430 : expr.get_if_block ().accept_vis (*this);
495 2430 : }
496 :
497 : void
498 1200 : DefaultHIRVisitor::walk (IfExprConseqElse &expr)
499 : {
500 1200 : expr.IfExpr::accept_vis (*this);
501 1200 : expr.get_else_block ().accept_vis (*this);
502 1200 : }
503 :
504 : void
505 2363 : DefaultHIRVisitor::visit_match_arm (MatchArm &arm)
506 : {
507 : // visit_outer_attrs (arm);
508 2363 : arm.get_pattern ()->accept_vis (*this);
509 2363 : if (arm.has_match_arm_guard ())
510 1 : arm.get_guard_expr ().accept_vis (*this);
511 2363 : }
512 :
513 : void
514 2363 : DefaultHIRVisitor::visit_match_case (MatchCase &arm)
515 : {
516 2363 : visit_match_arm (arm.get_arm ());
517 2363 : arm.get_expr ().accept_vis (*this);
518 2363 : }
519 :
520 : void
521 1005 : DefaultHIRVisitor::walk (MatchExpr &expr)
522 : {
523 1005 : visit_outer_attrs (expr);
524 1005 : visit_inner_attrs (expr);
525 1005 : expr.get_scrutinee_expr ().accept_vis (*this);
526 3368 : for (auto &arm : expr.get_match_cases ())
527 2363 : visit_match_case (arm);
528 1005 : }
529 :
530 : void
531 0 : DefaultHIRVisitor::walk (AwaitExpr &expr)
532 : {
533 0 : visit_outer_attrs (expr);
534 0 : expr.get_awaited_expr ().accept_vis (*this);
535 0 : }
536 :
537 : void
538 0 : DefaultHIRVisitor::walk (AsyncBlockExpr &expr)
539 : {
540 0 : visit_outer_attrs (expr);
541 0 : expr.get_block_expr ().accept_vis (*this);
542 0 : }
543 :
544 : void
545 24 : DefaultHIRVisitor::walk (InlineAsm &expr)
546 : {
547 24 : visit_outer_attrs (expr);
548 24 : auto &operands = expr.get_operands ();
549 24 : using RegisterType = AST::InlineAsmOperand::RegisterType;
550 53 : for (auto &operand : operands)
551 : {
552 29 : switch (operand.get_register_type ())
553 : {
554 10 : case RegisterType::In:
555 10 : {
556 10 : operand.get_in ().expr->accept_vis (*this);
557 10 : break;
558 : }
559 17 : case RegisterType::Out:
560 17 : {
561 17 : operand.get_out ().expr->accept_vis (*this);
562 17 : break;
563 : }
564 0 : case RegisterType::InOut:
565 0 : {
566 0 : operand.get_in_out ().expr->accept_vis (*this);
567 0 : break;
568 : }
569 2 : case RegisterType::SplitInOut:
570 2 : {
571 2 : operand.get_split_in_out ().in_expr->accept_vis (*this);
572 2 : operand.get_split_in_out ().out_expr->accept_vis (*this);
573 2 : break;
574 : }
575 0 : case RegisterType::Const:
576 0 : {
577 0 : operand.get_const ().anon_const.get_inner_expr ().accept_vis (
578 : *this);
579 0 : break;
580 : }
581 0 : case RegisterType::Sym:
582 0 : {
583 0 : operand.get_sym ().expr->accept_vis (*this);
584 0 : break;
585 : }
586 0 : case RegisterType::Label:
587 0 : {
588 0 : operand.get_label ().expr->accept_vis (*this);
589 0 : break;
590 : }
591 : }
592 : }
593 24 : }
594 :
595 : void
596 2 : DefaultHIRVisitor::walk (LlvmInlineAsm &expr)
597 : {
598 2 : for (auto &output : expr.outputs)
599 0 : output.expr->accept_vis (*this);
600 4 : for (auto &input : expr.inputs)
601 2 : input.expr->accept_vis (*this);
602 2 : }
603 :
604 : void
605 0 : DefaultHIRVisitor::walk (OffsetOf &expr)
606 : {
607 0 : expr.get_type ().accept_vis (*this);
608 0 : }
609 :
610 : void
611 8191 : DefaultHIRVisitor::walk (TypeParam ¶m)
612 : {
613 8191 : visit_outer_attrs (param);
614 9004 : for (auto &bounds : param.get_type_param_bounds ())
615 813 : bounds->accept_vis (*this);
616 8191 : if (param.has_type ())
617 347 : param.get_type ().accept_vis (*this);
618 8191 : }
619 :
620 : void
621 0 : DefaultHIRVisitor::walk (ConstGenericParam &const_param)
622 : {
623 0 : visit_outer_attrs (const_param);
624 0 : const_param.get_type ().accept_vis (*this);
625 0 : if (const_param.has_default_expression ())
626 0 : const_param.get_default_expression ().accept_vis (*this);
627 0 : }
628 :
629 : void
630 0 : DefaultHIRVisitor::walk (LifetimeWhereClauseItem &item)
631 : {
632 0 : item.get_lifetime ().accept_vis (*this);
633 0 : for (auto &bound : item.get_lifetime_bounds ())
634 0 : bound.accept_vis (*this);
635 0 : }
636 :
637 : void
638 139 : DefaultHIRVisitor::walk (TypeBoundWhereClauseItem &item)
639 : {
640 146 : for (auto &lifetime : item.get_for_lifetimes ())
641 7 : lifetime.accept_vis (*this);
642 139 : item.get_bound_type ().accept_vis (*this);
643 278 : for (auto ¶m : item.get_type_param_bounds ())
644 139 : param->accept_vis (*this);
645 139 : }
646 :
647 : void
648 1141 : DefaultHIRVisitor::walk (Module &module)
649 : {
650 1141 : visit_outer_attrs (module);
651 1141 : visit_inner_attrs (module);
652 4728 : for (auto &item : module.get_items ())
653 3587 : item->accept_vis (*this);
654 1141 : }
655 :
656 : void
657 0 : DefaultHIRVisitor::walk (ExternCrate &crate)
658 : {
659 0 : visit_outer_attrs (crate);
660 0 : }
661 :
662 : void
663 0 : DefaultHIRVisitor::walk (UseTreeGlob &)
664 0 : {}
665 :
666 : void
667 0 : DefaultHIRVisitor::walk (UseTreeList &)
668 0 : {}
669 :
670 : void
671 0 : DefaultHIRVisitor::walk (UseTreeRebind &)
672 0 : {}
673 :
674 : void
675 0 : DefaultHIRVisitor::walk (UseDeclaration &)
676 0 : {}
677 :
678 : void
679 7846 : DefaultHIRVisitor::visit_function_param (FunctionParam ¶m)
680 : {
681 7846 : param.get_param_name ().accept_vis (*this);
682 7846 : param.get_type ().accept_vis (*this);
683 7846 : }
684 :
685 : void
686 13091 : DefaultHIRVisitor::walk (Function &function)
687 : {
688 13091 : visit_outer_attrs (function);
689 13846 : for (auto &generic : function.get_generic_params ())
690 755 : generic->accept_vis (*this);
691 19326 : for (auto ¶m : function.get_function_params ())
692 6235 : visit_function_param (param);
693 13091 : if (function.has_return_type ())
694 9619 : function.get_return_type ().accept_vis (*this);
695 13091 : if (function.has_where_clause ())
696 27 : visit_where_clause (function.get_where_clause ());
697 13091 : function.get_definition ().accept_vis (*this);
698 13091 : }
699 :
700 : void
701 1236 : DefaultHIRVisitor::walk (TypeAlias &type_alias)
702 : {
703 1236 : visit_outer_attrs (type_alias);
704 1259 : for (auto &generic : type_alias.get_generic_params ())
705 23 : generic->accept_vis (*this);
706 1236 : if (type_alias.has_where_clause ())
707 0 : visit_where_clause (type_alias.get_where_clause ());
708 1236 : type_alias.get_type_aliased ().accept_vis (*this);
709 1236 : }
710 :
711 : void
712 2090 : DefaultHIRVisitor::visit_struct_field (StructField &field)
713 : {
714 2090 : field.get_field_type ().accept_vis (*this);
715 2090 : }
716 :
717 : void
718 1486 : DefaultHIRVisitor::walk (StructStruct &struct_item)
719 : {
720 1486 : visit_outer_attrs (struct_item);
721 1972 : for (auto &generic : struct_item.get_generic_params ())
722 486 : generic->accept_vis (*this);
723 1486 : if (struct_item.has_where_clause ())
724 2 : visit_where_clause (struct_item.get_where_clause ());
725 3281 : for (auto &field : struct_item.get_fields ())
726 1795 : visit_struct_field (field);
727 1486 : }
728 :
729 : void
730 933 : DefaultHIRVisitor::walk (TupleStruct &tuple_struct)
731 : {
732 933 : visit_outer_attrs (tuple_struct);
733 1282 : for (auto &generic : tuple_struct.get_generic_params ())
734 349 : generic->accept_vis (*this);
735 933 : if (tuple_struct.has_where_clause ())
736 0 : visit_where_clause (tuple_struct.get_where_clause ());
737 2516 : for (auto &field : tuple_struct.get_fields ())
738 1583 : field.get_field_type ().accept_vis (*this);
739 933 : }
740 :
741 : void
742 1164 : DefaultHIRVisitor::walk (EnumItem &item)
743 : {
744 1164 : visit_outer_attrs (item);
745 1164 : }
746 :
747 : void
748 391 : DefaultHIRVisitor::walk (EnumItemTuple &item_tuple)
749 : {
750 391 : item_tuple.EnumItem::accept_vis (*this);
751 805 : for (auto &field : item_tuple.get_tuple_fields ())
752 414 : field.get_field_type ().accept_vis (*this);
753 391 : }
754 :
755 : void
756 79 : DefaultHIRVisitor::walk (EnumItemStruct &item_struct)
757 : {
758 79 : item_struct.EnumItem::accept_vis (*this);
759 209 : for (auto &field : item_struct.get_struct_fields ())
760 130 : field.get_field_type ().accept_vis (*this);
761 79 : }
762 :
763 : void
764 273 : DefaultHIRVisitor::walk (EnumItemDiscriminant &item)
765 : {
766 273 : item.EnumItem::accept_vis (*this);
767 273 : item.get_discriminant_expression ().accept_vis (*this);
768 273 : }
769 :
770 : void
771 495 : DefaultHIRVisitor::walk (Enum &enum_item)
772 : {
773 495 : visit_outer_attrs (enum_item);
774 763 : for (auto &generic : enum_item.get_generic_params ())
775 268 : generic->accept_vis (*this);
776 495 : if (enum_item.has_where_clause ())
777 0 : visit_where_clause (enum_item.get_where_clause ());
778 1659 : for (auto &item : enum_item.get_variants ())
779 1164 : item->accept_vis (*this);
780 495 : }
781 :
782 : void
783 101 : DefaultHIRVisitor::walk (Union &union_item)
784 : {
785 101 : visit_outer_attrs (union_item);
786 175 : for (auto &generic : union_item.get_generic_params ())
787 74 : generic->accept_vis (*this);
788 101 : if (union_item.has_where_clause ())
789 0 : visit_where_clause (union_item.get_where_clause ());
790 396 : for (auto &variant : union_item.get_variants ())
791 295 : visit_struct_field (variant);
792 101 : }
793 :
794 : void
795 511 : DefaultHIRVisitor::walk (ConstantItem &const_item)
796 : {
797 511 : visit_outer_attrs (const_item);
798 511 : const_item.get_type ().accept_vis (*this);
799 511 : const_item.get_expr ().accept_vis (*this);
800 511 : }
801 :
802 : void
803 52 : DefaultHIRVisitor::walk (StaticItem &static_item)
804 : {
805 52 : visit_outer_attrs (static_item);
806 52 : static_item.get_type ().accept_vis (*this);
807 52 : static_item.get_expr ().accept_vis (*this);
808 52 : }
809 :
810 : void
811 2211 : DefaultHIRVisitor::visit_self_param (SelfParam &self_param)
812 : {
813 2211 : if (self_param.has_lifetime ())
814 : {
815 1652 : Lifetime lifetime = self_param.get_lifetime ();
816 1652 : lifetime.accept_vis (*this);
817 1652 : }
818 2211 : if (self_param.has_type ())
819 0 : self_param.get_type ().accept_vis (*this);
820 2211 : }
821 :
822 : void
823 2504 : DefaultHIRVisitor::walk (TraitItemFunc &item)
824 : {
825 2504 : visit_outer_attrs (item);
826 2504 : TraitFunctionDecl &decl = item.get_decl ();
827 2528 : for (auto &generic : decl.get_generic_params ())
828 24 : generic->accept_vis (*this);
829 2504 : if (decl.get_self ().has_value ())
830 2211 : visit_self_param (decl.get_self ().value ());
831 4115 : for (auto ¶m : decl.get_function_params ())
832 1611 : visit_function_param (param);
833 2504 : if (decl.has_return_type ())
834 2085 : decl.get_return_type ().accept_vis (*this);
835 2504 : if (decl.has_where_clause ())
836 0 : visit_where_clause (decl.get_where_clause ());
837 2504 : if (item.has_definition ())
838 843 : item.get_block_expr ().accept_vis (*this);
839 2504 : }
840 :
841 : void
842 30 : DefaultHIRVisitor::walk (TraitItemConst &item)
843 : {
844 30 : visit_outer_attrs (item);
845 30 : item.get_type ().accept_vis (*this);
846 30 : if (item.has_expr ())
847 7 : item.get_expr ().accept_vis (*this);
848 30 : }
849 :
850 : void
851 710 : DefaultHIRVisitor::walk (TraitItemType &item)
852 : {
853 710 : visit_outer_attrs (item);
854 746 : for (auto &bound : item.get_type_param_bounds ())
855 36 : bound->accept_vis (*this);
856 710 : }
857 :
858 : void
859 0 : DefaultHIRVisitor::visit_where_clause (const WhereClause &where_clause)
860 : {
861 0 : for (auto &item : where_clause.get_items ())
862 0 : item->accept_vis (*this);
863 0 : }
864 :
865 : void
866 119 : DefaultHIRVisitor::visit_where_clause (WhereClause &where_clause)
867 : {
868 258 : for (auto &item : where_clause.get_items ())
869 : {
870 139 : item->accept_vis (*this);
871 : }
872 119 : }
873 :
874 : void
875 0 : DefaultHIRVisitor::walk (WhereClauseItem &node)
876 0 : {}
877 :
878 : void
879 3734 : DefaultHIRVisitor::walk (Trait &trait)
880 : {
881 3734 : visit_outer_attrs (trait);
882 8090 : for (auto &generic : trait.get_generic_params ())
883 4356 : generic->accept_vis (*this);
884 3734 : if (trait.has_where_clause ())
885 7 : visit_where_clause (trait.get_where_clause ());
886 4313 : for (auto &bound : trait.get_type_param_bounds ())
887 579 : bound->accept_vis (*this);
888 6980 : for (auto &item : trait.get_trait_items ())
889 3246 : item->accept_vis (*this);
890 3734 : }
891 :
892 : void
893 5413 : DefaultHIRVisitor::walk (ImplBlock &impl)
894 : {
895 5413 : visit_outer_attrs (impl);
896 6488 : for (auto &generic : impl.get_generic_params ())
897 1075 : generic->accept_vis (*this);
898 5413 : if (impl.has_trait_ref ())
899 4471 : impl.get_trait_ref ().accept_vis (*this);
900 5413 : impl.get_type ().accept_vis (*this);
901 5413 : if (impl.has_where_clause ())
902 83 : visit_where_clause (impl.get_where_clause ());
903 5413 : visit_inner_attrs (impl);
904 13402 : for (auto &item : impl.get_impl_items ())
905 7989 : item->accept_vis (*this);
906 5413 : }
907 :
908 : void
909 0 : DefaultHIRVisitor::walk (ExternalStaticItem &item)
910 : {
911 0 : visit_outer_attrs (item);
912 0 : item.get_item_type ().accept_vis (*this);
913 0 : }
914 :
915 : void
916 2845 : DefaultHIRVisitor::visit_named_function_param (NamedFunctionParam ¶m)
917 : {
918 2845 : param.get_type ().accept_vis (*this);
919 2845 : }
920 :
921 : void
922 2509 : DefaultHIRVisitor::walk (ExternalFunctionItem &item)
923 : {
924 2509 : visit_outer_attrs (item);
925 3508 : for (auto &generic : item.get_generic_params ())
926 999 : generic->accept_vis (*this);
927 5354 : for (auto ¶m : item.get_function_params ())
928 2845 : visit_named_function_param (param);
929 2509 : if (item.has_return_type ())
930 1285 : item.get_return_type ().accept_vis (*this);
931 2509 : if (item.has_where_clause ())
932 0 : visit_where_clause (item.get_where_clause ());
933 2509 : }
934 :
935 : void
936 0 : DefaultHIRVisitor::walk (ExternalTypeItem &item)
937 : {
938 0 : visit_outer_attrs (item);
939 0 : }
940 :
941 : void
942 1634 : DefaultHIRVisitor::walk (ExternBlock &block)
943 : {
944 1634 : visit_outer_attrs (block);
945 1634 : visit_inner_attrs (block);
946 4143 : for (auto &item : block.get_extern_items ())
947 2509 : item->accept_vis (*this);
948 1634 : }
949 :
950 : void
951 405 : DefaultHIRVisitor::walk (LiteralPattern &)
952 405 : {}
953 :
954 : void
955 8415 : DefaultHIRVisitor::walk (IdentifierPattern &pattern)
956 : {
957 8415 : if (pattern.has_subpattern ())
958 11 : pattern.get_subpattern ().accept_vis (*this);
959 8415 : }
960 :
961 : void
962 755 : DefaultHIRVisitor::walk (WildcardPattern &)
963 755 : {}
964 :
965 : void
966 77 : DefaultHIRVisitor::walk (RangePatternBoundLiteral &)
967 77 : {}
968 :
969 : void
970 21 : DefaultHIRVisitor::walk (RangePatternBoundPath &bound)
971 : {
972 21 : bound.get_path ().accept_vis (*this);
973 21 : }
974 :
975 : void
976 0 : DefaultHIRVisitor::walk (RangePatternBoundQualPath &bound)
977 : {
978 0 : bound.get_qualified_path ().accept_vis (*this);
979 0 : }
980 :
981 : void
982 49 : DefaultHIRVisitor::walk (RangePattern &pattern)
983 : {
984 49 : pattern.get_lower_bound ().accept_vis (*this);
985 49 : pattern.get_upper_bound ().accept_vis (*this);
986 49 : }
987 :
988 : void
989 175 : DefaultHIRVisitor::walk (ReferencePattern &pattern)
990 : {
991 175 : pattern.get_referenced_pattern ().accept_vis (*this);
992 175 : }
993 :
994 : void
995 18 : DefaultHIRVisitor::walk (StructPatternFieldTuplePat &field)
996 : {
997 18 : visit_outer_attrs (field);
998 18 : field.get_tuple_pattern ().accept_vis (*this);
999 18 : }
1000 :
1001 : void
1002 120 : DefaultHIRVisitor::walk (StructPatternFieldIdentPat &field)
1003 : {
1004 120 : visit_outer_attrs (field);
1005 120 : field.get_pattern ().accept_vis (*this);
1006 120 : }
1007 :
1008 : void
1009 93 : DefaultHIRVisitor::walk (StructPatternFieldIdent &field)
1010 : {
1011 93 : visit_outer_attrs (field);
1012 93 : }
1013 :
1014 : void
1015 137 : DefaultHIRVisitor::walk (StructPattern &pattern)
1016 : {
1017 137 : pattern.get_path ().accept_vis (*this);
1018 137 : StructPatternElements &elements = pattern.get_struct_pattern_elems ();
1019 370 : for (auto &field : elements.get_struct_pattern_fields ())
1020 233 : field->accept_vis (*this);
1021 137 : }
1022 :
1023 : void
1024 881 : DefaultHIRVisitor::walk (TupleStructItemsNoRest &tuple_items)
1025 : {
1026 1850 : for (auto &item : tuple_items.get_patterns ())
1027 969 : item->accept_vis (*this);
1028 881 : }
1029 :
1030 : void
1031 36 : DefaultHIRVisitor::walk (TupleStructItemsHasRest &tuple_items)
1032 : {
1033 65 : for (auto &lower : tuple_items.get_lower_patterns ())
1034 29 : lower->accept_vis (*this);
1035 86 : for (auto &upper : tuple_items.get_upper_patterns ())
1036 14 : upper->accept_vis (*this);
1037 36 : }
1038 :
1039 : void
1040 917 : DefaultHIRVisitor::walk (TupleStructPattern &pattern)
1041 : {
1042 917 : pattern.get_path ().accept_vis (*this);
1043 917 : pattern.get_items ().accept_vis (*this);
1044 917 : }
1045 :
1046 : void
1047 109 : DefaultHIRVisitor::walk (TuplePatternItemsNoRest &tuple_items)
1048 : {
1049 334 : for (auto &pattern : tuple_items.get_patterns ())
1050 225 : pattern->accept_vis (*this);
1051 109 : }
1052 :
1053 : void
1054 26 : DefaultHIRVisitor::walk (TuplePatternItemsHasRest &tuple_items)
1055 : {
1056 50 : for (auto &lower : tuple_items.get_lower_patterns ())
1057 24 : lower->accept_vis (*this);
1058 49 : for (auto &upper : tuple_items.get_upper_patterns ())
1059 23 : upper->accept_vis (*this);
1060 26 : }
1061 :
1062 : void
1063 135 : DefaultHIRVisitor::walk (TuplePattern &pattern)
1064 : {
1065 135 : pattern.get_items ().accept_vis (*this);
1066 135 : }
1067 :
1068 : void
1069 31 : DefaultHIRVisitor::walk (SlicePatternItemsNoRest &items)
1070 : {
1071 92 : for (auto &pattern : items.get_patterns ())
1072 61 : pattern->accept_vis (*this);
1073 31 : }
1074 :
1075 : void
1076 44 : DefaultHIRVisitor::walk (SlicePatternItemsHasRest &items)
1077 : {
1078 87 : for (auto &lower : items.get_lower_patterns ())
1079 43 : lower->accept_vis (*this);
1080 87 : for (auto &upper : items.get_upper_patterns ())
1081 43 : upper->accept_vis (*this);
1082 44 : }
1083 :
1084 : void
1085 75 : DefaultHIRVisitor::walk (SlicePattern &pattern)
1086 : {
1087 75 : pattern.get_items ().accept_vis (*this);
1088 75 : }
1089 :
1090 : void
1091 145 : DefaultHIRVisitor::walk (AltPattern &pattern)
1092 : {
1093 436 : for (auto &item : pattern.get_alts ())
1094 291 : item->accept_vis (*this);
1095 145 : }
1096 :
1097 : void
1098 46 : DefaultHIRVisitor::walk (EmptyStmt &stmt)
1099 46 : {}
1100 :
1101 : void
1102 22 : DefaultHIRVisitor::walk (LetStmt &stmt)
1103 : {
1104 22 : visit_outer_attrs (stmt);
1105 22 : stmt.get_pattern ().accept_vis (*this);
1106 22 : if (stmt.has_type ())
1107 0 : stmt.get_type ().accept_vis (*this);
1108 22 : if (stmt.has_init_expr ())
1109 22 : stmt.get_init_expr ().accept_vis (*this);
1110 22 : }
1111 :
1112 : void
1113 10675 : DefaultHIRVisitor::walk (ExprStmt &stmt)
1114 : {
1115 10675 : stmt.get_expr ().accept_vis (*this);
1116 10675 : }
1117 :
1118 : void
1119 1690 : DefaultHIRVisitor::walk (TraitBound &bound)
1120 : {
1121 1697 : for (auto &lifetime : bound.get_for_lifetimes ())
1122 7 : lifetime.accept_vis (*this);
1123 1690 : bound.get_path ().accept_vis (*this);
1124 1690 : }
1125 :
1126 : void
1127 28 : DefaultHIRVisitor::walk (ImplTraitType &type)
1128 : {
1129 56 : for (auto &bound : type.get_type_param_bounds ())
1130 28 : bound->accept_vis (*this);
1131 28 : }
1132 :
1133 : void
1134 94 : DefaultHIRVisitor::walk (TraitObjectType &type)
1135 : {
1136 200 : for (auto &bound : type.get_type_param_bounds ())
1137 106 : bound->accept_vis (*this);
1138 94 : }
1139 :
1140 : void
1141 4 : DefaultHIRVisitor::walk (ParenthesisedType &type)
1142 : {
1143 4 : type.get_type_in_parens ().accept_vis (*this);
1144 4 : }
1145 :
1146 : void
1147 328 : DefaultHIRVisitor::walk (TupleType &type)
1148 : {
1149 867 : for (auto &elem : type.get_elems ())
1150 539 : elem->accept_vis (*this);
1151 328 : }
1152 :
1153 : void
1154 185 : DefaultHIRVisitor::walk (NeverType &type)
1155 185 : {}
1156 :
1157 : void
1158 4099 : DefaultHIRVisitor::walk (RawPointerType &type)
1159 : {
1160 4099 : type.get_type ().accept_vis (*this);
1161 4099 : }
1162 :
1163 : void
1164 3983 : DefaultHIRVisitor::walk (ReferenceType &type)
1165 : {
1166 3983 : if (type.has_lifetime ())
1167 3983 : type.get_lifetime ().accept_vis (*this);
1168 3983 : type.get_base_type ().accept_vis (*this);
1169 3983 : }
1170 :
1171 : void
1172 474 : DefaultHIRVisitor::walk (ArrayType &type)
1173 : {
1174 474 : type.get_element_type ().accept_vis (*this);
1175 474 : type.get_size_expr ().accept_vis (*this);
1176 474 : }
1177 :
1178 : void
1179 848 : DefaultHIRVisitor::walk (SliceType &type)
1180 : {
1181 848 : type.get_element_type ().accept_vis (*this);
1182 848 : }
1183 :
1184 : void
1185 14 : DefaultHIRVisitor::walk (InferredType &type)
1186 14 : {}
1187 :
1188 : void
1189 33 : DefaultHIRVisitor::walk (BareFunctionType &type)
1190 : {
1191 33 : for (auto &lifetime : type.get_for_lifetimes ())
1192 0 : lifetime.accept_vis (*this);
1193 54 : for (auto ¶m : type.get_function_params ())
1194 21 : param.get_type ().accept_vis (*this);
1195 33 : if (type.has_return_type ())
1196 23 : type.get_return_type ().accept_vis (*this);
1197 33 : }
1198 :
1199 : } // namespace HIR
1200 : } // namespace Rust
|