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