Fork of daniellemaywood.uk/gleam — Wasm codegen work
60 kB
2219 lines
1//! AST traversal routines, referenced from [`syn::visit`](https://docs.rs/syn/latest/syn/visit/index.html)
2//!
3//! Each method of the [`Visit`] trait can be overriden to customize the
4//! behaviour when visiting the corresponding type of AST node. By default,
5//! every method recursively visits the substructure of the node by using the
6//! right visitor method.
7//!
8//! # Example
9//!
10//! Suppose we would like to collect all function names in a module,
11//! we can do the following:
12//!
13//! ```no_run
14//! use gleam_core::ast::{TypedFunction, visit::{self, Visit}};
15//!
16//! struct FnCollector<'ast> {
17//! functions: Vec<&'ast TypedFunction>
18//! }
19//!
20//! impl<'ast> Visit<'ast> for FnCollector<'ast> {
21//! fn visit_typed_function(&mut self, fun: &'ast TypedFunction) {
22//! self.functions.push(fun);
23//!
24//! // Use the default behaviour to visit any nested functions
25//! visit::visit_typed_function(self, fun);
26//! }
27//! }
28//!
29//! fn print_all_module_functions() {
30//! let module = todo!("module");
31//! let mut fn_collector = FnCollector { functions: vec![] };
32//!
33//! // This will walk the AST and collect all functions
34//! fn_collector.visit_typed_module(module);
35//!
36//! // Print the collected functions
37//! println!("{:#?}", fn_collector.functions);
38//! }
39//! ```
40
41use crate::{
42 analyse::Inferred,
43 ast::{
44 BitArraySize, RecordBeingUpdated, TypedBitArraySize, TypedConstantBitArraySegment,
45 TypedDefinitions, TypedTailPattern, typed::InvalidExpression,
46 },
47 exhaustiveness::CompiledCase,
48 parse::LiteralFloatValue,
49 type_::{
50 FieldMap, ModuleValueConstructor, PatternConstructor, TypedCallArg, ValueConstructor,
51 error::VariableOrigin,
52 },
53};
54use std::sync::Arc;
55
56use ecow::EcoString;
57use num_bigint::BigInt;
58use vec1::Vec1;
59
60use crate::type_::Type;
61
62use super::{
63 AssignName, BinOp, BitArrayOption, CallArg, Pattern, PipelineAssignmentKind, RecordUpdateArg,
64 SrcSpan, Statement, TodoKind, TypeAst, TypedArg, TypedAssert, TypedAssignment, TypedClause,
65 TypedClauseGuard, TypedConstant, TypedCustomType, TypedExpr, TypedExprBitArraySegment,
66 TypedFunction, TypedModule, TypedModuleConstant, TypedPattern, TypedPatternBitArraySegment,
67 TypedPipelineAssignment, TypedStatement, TypedUse, untyped::FunctionLiteralKind,
68};
69
70pub trait Visit<'ast> {
71 fn visit_typed_module(&mut self, module: &'ast TypedModule) {
72 visit_typed_module(self, module);
73 }
74
75 fn visit_typed_function(&mut self, fun: &'ast TypedFunction) {
76 visit_typed_function(self, fun);
77 }
78
79 fn visit_typed_module_constant(&mut self, constant: &'ast TypedModuleConstant) {
80 visit_typed_module_constant(self, constant);
81 }
82
83 fn visit_typed_custom_type(&mut self, custom_type: &'ast TypedCustomType) {
84 visit_typed_custom_type(self, custom_type);
85 }
86
87 fn visit_typed_expr(&mut self, expr: &'ast TypedExpr) {
88 visit_typed_expr(self, expr);
89 }
90
91 fn visit_typed_expr_echo(
92 &mut self,
93 location: &'ast SrcSpan,
94 type_: &'ast Arc<Type>,
95 expression: &'ast Option<Box<TypedExpr>>,
96 message: &'ast Option<Box<TypedExpr>>,
97 ) {
98 visit_typed_expr_echo(self, location, type_, expression, message);
99 }
100
101 fn visit_typed_expr_int(
102 &mut self,
103 location: &'ast SrcSpan,
104 type_: &'ast Arc<Type>,
105 value: &'ast EcoString,
106 ) {
107 visit_typed_expr_int(self, location, type_, value);
108 }
109
110 fn visit_typed_expr_float(
111 &mut self,
112 location: &'ast SrcSpan,
113 type_: &'ast Arc<Type>,
114 value: &'ast EcoString,
115 ) {
116 visit_typed_expr_float(self, location, type_, value);
117 }
118
119 fn visit_typed_expr_string(
120 &mut self,
121 location: &'ast SrcSpan,
122 type_: &'ast Arc<Type>,
123 value: &'ast EcoString,
124 ) {
125 visit_typed_expr_string(self, location, type_, value);
126 }
127
128 fn visit_typed_expr_block(
129 &mut self,
130 location: &'ast SrcSpan,
131 statements: &'ast [TypedStatement],
132 ) {
133 visit_typed_expr_block(self, location, statements);
134 }
135
136 fn visit_typed_expr_pipeline(
137 &mut self,
138 location: &'ast SrcSpan,
139 first_value: &'ast TypedPipelineAssignment,
140 assignments: &'ast [(TypedPipelineAssignment, PipelineAssignmentKind)],
141 finally: &'ast TypedExpr,
142 finally_kind: &'ast PipelineAssignmentKind,
143 ) {
144 visit_typed_expr_pipeline(
145 self,
146 location,
147 first_value,
148 assignments,
149 finally,
150 finally_kind,
151 );
152 }
153
154 fn visit_typed_expr_var(
155 &mut self,
156 location: &'ast SrcSpan,
157 constructor: &'ast ValueConstructor,
158 name: &'ast EcoString,
159 ) {
160 visit_typed_expr_var(self, location, constructor, name);
161 }
162
163 fn visit_typed_expr_fn(
164 &mut self,
165 location: &'ast SrcSpan,
166 type_: &'ast Arc<Type>,
167 kind: &'ast FunctionLiteralKind,
168 arguments: &'ast [TypedArg],
169 body: &'ast Vec1<TypedStatement>,
170 return_annotation: &'ast Option<TypeAst>,
171 ) {
172 visit_typed_expr_fn(
173 self,
174 location,
175 type_,
176 kind,
177 arguments,
178 body,
179 return_annotation,
180 );
181 }
182
183 fn visit_typed_expr_list(
184 &mut self,
185 location: &'ast SrcSpan,
186 type_: &'ast Arc<Type>,
187 elements: &'ast [TypedExpr],
188 tail: &'ast Option<Box<TypedExpr>>,
189 ) {
190 visit_typed_expr_list(self, location, type_, elements, tail);
191 }
192
193 fn visit_typed_expr_call(
194 &mut self,
195 location: &'ast SrcSpan,
196 type_: &'ast Arc<Type>,
197 fun: &'ast TypedExpr,
198 arguments: &'ast [TypedCallArg],
199 ) {
200 visit_typed_expr_call(self, location, type_, fun, arguments);
201 }
202
203 fn visit_typed_expr_bin_op(
204 &mut self,
205 location: &'ast SrcSpan,
206 type_: &'ast Arc<Type>,
207 name: &'ast BinOp,
208 name_location: &'ast SrcSpan,
209 left: &'ast TypedExpr,
210 right: &'ast TypedExpr,
211 ) {
212 visit_typed_expr_bin_op(self, location, type_, name, name_location, left, right);
213 }
214
215 fn visit_typed_expr_case(
216 &mut self,
217 location: &'ast SrcSpan,
218 type_: &'ast Arc<Type>,
219 subjects: &'ast [TypedExpr],
220 clauses: &'ast [TypedClause],
221 compiled_case: &'ast CompiledCase,
222 ) {
223 visit_typed_expr_case(self, location, type_, subjects, clauses, compiled_case);
224 }
225
226 #[allow(clippy::too_many_arguments)]
227 fn visit_typed_expr_record_access(
228 &mut self,
229 location: &'ast SrcSpan,
230 field_start: &'ast u32,
231 type_: &'ast Arc<Type>,
232 label: &'ast EcoString,
233 index: &'ast u64,
234 record: &'ast TypedExpr,
235 documentation: &'ast Option<EcoString>,
236 ) {
237 visit_typed_expr_record_access(
238 self,
239 location,
240 field_start,
241 type_,
242 label,
243 index,
244 record,
245 documentation,
246 );
247 }
248
249 #[allow(clippy::too_many_arguments)]
250 fn visit_typed_expr_module_select(
251 &mut self,
252 location: &'ast SrcSpan,
253 field_start: &'ast u32,
254 type_: &'ast Arc<Type>,
255 label: &'ast EcoString,
256 module_name: &'ast EcoString,
257 module_alias: &'ast EcoString,
258 constructor: &'ast ModuleValueConstructor,
259 ) {
260 visit_typed_expr_module_select(
261 self,
262 location,
263 field_start,
264 type_,
265 label,
266 module_name,
267 module_alias,
268 constructor,
269 );
270 }
271
272 fn visit_typed_expr_tuple(
273 &mut self,
274 location: &'ast SrcSpan,
275 type_: &'ast Arc<Type>,
276 elements: &'ast [TypedExpr],
277 ) {
278 visit_typed_expr_tuple(self, location, type_, elements);
279 }
280
281 fn visit_typed_expr_tuple_index(
282 &mut self,
283 location: &'ast SrcSpan,
284 type_: &'ast Arc<Type>,
285 index: &'ast u64,
286 tuple: &'ast TypedExpr,
287 ) {
288 visit_typed_expr_tuple_index(self, location, type_, index, tuple);
289 }
290
291 fn visit_typed_expr_todo(
292 &mut self,
293 location: &'ast SrcSpan,
294 message: &'ast Option<Box<TypedExpr>>,
295 kind: &'ast TodoKind,
296 type_: &'ast Arc<Type>,
297 ) {
298 visit_typed_expr_todo(self, location, message, kind, type_);
299 }
300
301 fn visit_typed_expr_panic(
302 &mut self,
303 location: &'ast SrcSpan,
304 message: &'ast Option<Box<TypedExpr>>,
305 type_: &'ast Arc<Type>,
306 ) {
307 visit_typed_expr_panic(self, location, message, type_);
308 }
309
310 fn visit_typed_expr_bit_array(
311 &mut self,
312 location: &'ast SrcSpan,
313 type_: &'ast Arc<Type>,
314 segments: &'ast [TypedExprBitArraySegment],
315 ) {
316 visit_typed_expr_bit_array(self, location, type_, segments);
317 }
318
319 fn visit_typed_expr_record_update(
320 &mut self,
321 location: &'ast SrcSpan,
322 type_: &'ast Arc<Type>,
323 record: &'ast Option<Box<TypedAssignment>>,
324 constructor: &'ast TypedExpr,
325 arguments: &'ast [TypedCallArg],
326 ) {
327 visit_typed_expr_record_update(self, location, type_, record, constructor, arguments);
328 }
329
330 fn visit_typed_expr_negate_bool(&mut self, location: &'ast SrcSpan, value: &'ast TypedExpr) {
331 visit_typed_expr_negate_bool(self, location, value);
332 }
333
334 fn visit_typed_expr_negate_int(&mut self, location: &'ast SrcSpan, value: &'ast TypedExpr) {
335 visit_typed_expr_negate_int(self, location, value)
336 }
337
338 fn visit_typed_expr_invalid(
339 &mut self,
340 location: &'ast SrcSpan,
341 type_: &'ast Arc<Type>,
342 extra_information: &'ast Option<InvalidExpression>,
343 ) {
344 visit_typed_expr_invalid(self, location, type_, extra_information);
345 }
346
347 fn visit_typed_statement(&mut self, statement: &'ast TypedStatement) {
348 visit_typed_statement(self, statement);
349 }
350
351 fn visit_typed_assignment(&mut self, assignment: &'ast TypedAssignment) {
352 visit_typed_assignment(self, assignment);
353 }
354
355 fn visit_typed_use(&mut self, use_: &'ast TypedUse) {
356 visit_typed_use(self, use_);
357 }
358
359 fn visit_typed_assert(&mut self, assert: &'ast TypedAssert) {
360 visit_typed_assert(self, assert);
361 }
362
363 fn visit_typed_pipeline_assignment(&mut self, assignment: &'ast TypedPipelineAssignment) {
364 visit_typed_pipeline_assignment(self, assignment);
365 }
366
367 fn visit_typed_call_arg(&mut self, arg: &'ast TypedCallArg) {
368 visit_typed_call_arg(self, arg);
369 }
370
371 fn visit_typed_clause(&mut self, clause: &'ast TypedClause) {
372 visit_typed_clause(self, clause);
373 }
374
375 fn visit_typed_clause_guard(&mut self, guard: &'ast TypedClauseGuard) {
376 visit_typed_clause_guard(self, guard);
377 }
378
379 fn visit_typed_clause_guard_var(
380 &mut self,
381 location: &'ast SrcSpan,
382 name: &'ast EcoString,
383 type_: &'ast Arc<Type>,
384 definition_location: &'ast SrcSpan,
385 ) {
386 visit_typed_clause_guard_var(self, location, name, type_, definition_location);
387 }
388
389 fn visit_typed_clause_guard_tuple_index(
390 &mut self,
391 location: &'ast SrcSpan,
392 index: &'ast u64,
393 type_: &'ast Arc<Type>,
394 tuple: &'ast TypedClauseGuard,
395 ) {
396 visit_typed_clause_guard_tuple_index(self, location, index, type_, tuple)
397 }
398
399 fn visit_typed_clause_guard_field_access(
400 &mut self,
401 label_location: &'ast SrcSpan,
402 index: &'ast Option<u64>,
403 label: &'ast EcoString,
404 type_: &'ast Arc<Type>,
405 container: &'ast TypedClauseGuard,
406 ) {
407 visit_typed_clause_guard_field_access(self, label_location, index, label, type_, container)
408 }
409
410 fn visit_typed_clause_guard_module_select(
411 &mut self,
412 location: &'ast SrcSpan,
413 type_: &'ast Arc<Type>,
414 label: &'ast EcoString,
415 module_name: &'ast EcoString,
416 module_alias: &'ast EcoString,
417 literal: &'ast TypedConstant,
418 ) {
419 visit_typed_clause_guard_module_select(
420 self,
421 location,
422 type_,
423 label,
424 module_name,
425 module_alias,
426 literal,
427 )
428 }
429
430 fn visit_typed_expr_bit_array_segment(&mut self, segment: &'ast TypedExprBitArraySegment) {
431 visit_typed_expr_bit_array_segment(self, segment);
432 }
433
434 fn visit_typed_bit_array_option(&mut self, option: &'ast BitArrayOption<TypedExpr>) {
435 visit_typed_bit_array_option(self, option);
436 }
437
438 fn visit_typed_pattern(&mut self, pattern: &'ast TypedPattern) {
439 visit_typed_pattern(self, pattern);
440 }
441
442 fn visit_typed_pattern_int(&mut self, location: &'ast SrcSpan, value: &'ast EcoString) {
443 visit_typed_pattern_int(self, location, value);
444 }
445
446 fn visit_typed_pattern_float(&mut self, location: &'ast SrcSpan, value: &'ast EcoString) {
447 visit_typed_pattern_float(self, location, value);
448 }
449
450 fn visit_typed_pattern_string(&mut self, location: &'ast SrcSpan, value: &'ast EcoString) {
451 visit_typed_pattern_string(self, location, value);
452 }
453
454 fn visit_typed_pattern_variable(
455 &mut self,
456 location: &'ast SrcSpan,
457 name: &'ast EcoString,
458 type_: &'ast Arc<Type>,
459 origin: &'ast VariableOrigin,
460 ) {
461 visit_typed_pattern_variable(self, location, name, type_, origin);
462 }
463
464 fn visit_typed_pattern_bit_array_size(&mut self, size: &'ast TypedBitArraySize) {
465 visit_typed_pattern_bit_array_size(self, size);
466 }
467
468 fn visit_typed_bit_array_size_int(&mut self, location: &'ast SrcSpan, value: &'ast EcoString) {
469 visit_typed_bit_array_size_int(self, location, value)
470 }
471
472 fn visit_typed_bit_array_size_variable(
473 &mut self,
474 location: &'ast SrcSpan,
475 name: &'ast EcoString,
476 constructor: &'ast Option<Box<ValueConstructor>>,
477 type_: &'ast Arc<Type>,
478 ) {
479 visit_typed_bit_array_size_variable(self, location, name, constructor, type_)
480 }
481
482 fn visit_typed_pattern_assign(
483 &mut self,
484 location: &'ast SrcSpan,
485 name: &'ast EcoString,
486 pattern: &'ast TypedPattern,
487 ) {
488 visit_typed_pattern_assign(self, location, name, pattern);
489 }
490
491 fn visit_typed_pattern_discard(
492 &mut self,
493 location: &'ast SrcSpan,
494 name: &'ast EcoString,
495 type_: &'ast Arc<Type>,
496 ) {
497 visit_typed_pattern_discard(self, location, name, type_)
498 }
499
500 fn visit_typed_pattern_list(
501 &mut self,
502 location: &'ast SrcSpan,
503 elements: &'ast Vec<TypedPattern>,
504 tail: &'ast Option<Box<TypedTailPattern>>,
505 type_: &'ast Arc<Type>,
506 ) {
507 visit_typed_pattern_list(self, location, elements, tail, type_);
508 }
509
510 #[allow(clippy::too_many_arguments)]
511 fn visit_typed_pattern_constructor(
512 &mut self,
513 location: &'ast SrcSpan,
514 name_location: &'ast SrcSpan,
515 name: &'ast EcoString,
516 arguments: &'ast Vec<CallArg<TypedPattern>>,
517 module: &'ast Option<(EcoString, SrcSpan)>,
518 constructor: &'ast Inferred<PatternConstructor>,
519 spread: &'ast Option<SrcSpan>,
520 type_: &'ast Arc<Type>,
521 ) {
522 visit_typed_pattern_constructor(
523 self,
524 location,
525 name_location,
526 name,
527 arguments,
528 module,
529 constructor,
530 spread,
531 type_,
532 );
533 }
534
535 fn visit_typed_pattern_call_arg(&mut self, arg: &'ast CallArg<TypedPattern>) {
536 visit_typed_pattern_call_arg(self, arg);
537 }
538
539 fn visit_typed_pattern_tuple(
540 &mut self,
541 location: &'ast SrcSpan,
542 elements: &'ast Vec<TypedPattern>,
543 ) {
544 visit_typed_pattern_tuple(self, location, elements);
545 }
546
547 fn visit_typed_pattern_bit_array(
548 &mut self,
549 location: &'ast SrcSpan,
550 segments: &'ast [TypedPatternBitArraySegment],
551 ) {
552 visit_typed_pattern_bit_array(self, location, segments);
553 }
554
555 fn visit_typed_pattern_bit_array_option(&mut self, option: &'ast BitArrayOption<TypedPattern>) {
556 visit_typed_pattern_bit_array_option(self, option);
557 }
558
559 fn visit_typed_pattern_string_prefix(
560 &mut self,
561 location: &'ast SrcSpan,
562 left_location: &'ast SrcSpan,
563 left_side_assignment: &'ast Option<(EcoString, SrcSpan)>,
564 right_location: &'ast SrcSpan,
565 left_side_string: &'ast EcoString,
566 right_side_assignment: &'ast AssignName,
567 ) {
568 visit_typed_pattern_string_prefix(
569 self,
570 location,
571 left_location,
572 left_side_assignment,
573 right_location,
574 left_side_string,
575 right_side_assignment,
576 );
577 }
578
579 fn visit_typed_pattern_invalid(&mut self, location: &'ast SrcSpan, type_: &'ast Arc<Type>) {
580 visit_typed_pattern_invalid(self, location, type_);
581 }
582
583 fn visit_type_ast(&mut self, node: &'ast TypeAst) {
584 visit_type_ast(self, node);
585 }
586
587 fn visit_type_ast_constructor(
588 &mut self,
589 location: &'ast SrcSpan,
590 name_location: &'ast SrcSpan,
591 module: &'ast Option<(EcoString, SrcSpan)>,
592 name: &'ast EcoString,
593 arguments: &'ast Vec<TypeAst>,
594 ) {
595 visit_type_ast_constructor(self, location, name_location, module, name, arguments);
596 }
597
598 fn visit_type_ast_fn(
599 &mut self,
600 location: &'ast SrcSpan,
601 arguments: &'ast Vec<TypeAst>,
602 return_: &'ast TypeAst,
603 ) {
604 visit_type_ast_fn(self, location, arguments, return_);
605 }
606
607 fn visit_type_ast_var(&mut self, location: &'ast SrcSpan, name: &'ast EcoString) {
608 visit_type_ast_var(self, location, name);
609 }
610
611 fn visit_type_ast_tuple(&mut self, location: &'ast SrcSpan, elements: &'ast Vec<TypeAst>) {
612 visit_type_ast_tuple(self, location, elements);
613 }
614
615 fn visit_type_ast_hole(&mut self, location: &'ast SrcSpan, name: &'ast EcoString) {
616 visit_type_ast_hole(self, location, name);
617 }
618
619 fn visit_typed_constant(&mut self, constant: &'ast TypedConstant) {
620 visit_typed_constant(self, constant);
621 }
622
623 fn visit_typed_constant_int(
624 &mut self,
625 location: &'ast SrcSpan,
626 value: &'ast EcoString,
627 int_value: &'ast BigInt,
628 ) {
629 visit_typed_constant_int(self, location, value, int_value);
630 }
631
632 fn visit_typed_constant_float(
633 &mut self,
634 location: &'ast SrcSpan,
635 value: &'ast EcoString,
636 float_value: &'ast LiteralFloatValue,
637 ) {
638 visit_typed_constant_float(self, location, value, float_value);
639 }
640
641 fn visit_typed_constant_string(&mut self, location: &'ast SrcSpan, value: &'ast EcoString) {
642 visit_typed_constant_string(self, location, value);
643 }
644
645 fn visit_typed_constant_tuple(
646 &mut self,
647 location: &'ast SrcSpan,
648 elements: &'ast Vec<TypedConstant>,
649 type_: &'ast Arc<Type>,
650 ) {
651 visit_typed_constant_tuple(self, location, elements, type_);
652 }
653
654 fn visit_typed_constant_list(
655 &mut self,
656 location: &'ast SrcSpan,
657 elements: &'ast Vec<TypedConstant>,
658 type_: &'ast Arc<Type>,
659 ) {
660 visit_typed_constant_list(self, location, elements, type_);
661 }
662
663 #[allow(clippy::too_many_arguments)]
664 fn visit_typed_constant_record(
665 &mut self,
666 location: &'ast SrcSpan,
667 module: &'ast Option<(EcoString, SrcSpan)>,
668 name: &'ast EcoString,
669 arguments: &'ast Vec<CallArg<TypedConstant>>,
670 tag: &'ast EcoString,
671 type_: &'ast Arc<Type>,
672 field_map: &'ast Inferred<FieldMap>,
673 record_constructor: &'ast Option<Box<ValueConstructor>>,
674 ) {
675 visit_typed_constant_record(
676 self,
677 location,
678 module,
679 name,
680 arguments,
681 tag,
682 type_,
683 field_map,
684 record_constructor,
685 )
686 }
687
688 #[allow(clippy::too_many_arguments)]
689 fn visit_typed_constant_record_update(
690 &mut self,
691 location: &'ast SrcSpan,
692 constructor_location: &'ast SrcSpan,
693 module: &'ast Option<(EcoString, SrcSpan)>,
694 name: &'ast EcoString,
695 record: &'ast RecordBeingUpdated<TypedConstant>,
696 arguments: &'ast [RecordUpdateArg<TypedConstant>],
697 tag: &'ast EcoString,
698 type_: &'ast Arc<Type>,
699 field_map: &'ast Inferred<FieldMap>,
700 ) {
701 visit_typed_constant_record_update(
702 self,
703 location,
704 constructor_location,
705 module,
706 name,
707 record,
708 arguments,
709 tag,
710 type_,
711 field_map,
712 )
713 }
714
715 fn visit_typed_constant_bit_array(
716 &mut self,
717 location: &'ast SrcSpan,
718 segments: &'ast [TypedConstantBitArraySegment],
719 ) {
720 visit_typed_constant_bit_array(self, location, segments);
721 }
722
723 fn visit_typed_constant_var(
724 &mut self,
725 location: &'ast SrcSpan,
726 module: &'ast Option<(EcoString, SrcSpan)>,
727 name: &'ast EcoString,
728 constructor: &'ast Option<Box<ValueConstructor>>,
729 type_: &'ast Arc<Type>,
730 ) {
731 visit_typed_constant_var(self, location, module, name, constructor, type_);
732 }
733
734 fn visit_typed_constant_string_concatenation(
735 &mut self,
736 location: &'ast SrcSpan,
737 left: &'ast TypedConstant,
738 right: &'ast TypedConstant,
739 ) {
740 visit_typed_constant_string_concatenation(self, location, left, right);
741 }
742
743 fn visit_typed_constant_invalid(
744 &mut self,
745 location: &'ast SrcSpan,
746 type_: &'ast Arc<Type>,
747 extra_information: &'ast Option<InvalidExpression>,
748 ) {
749 visit_typed_constant_invalid(self, location, type_, extra_information);
750 }
751}
752
753fn visit_typed_constant_invalid<'a, V: Visit<'a> + ?Sized>(
754 _v: &mut V,
755 _location: &'a SrcSpan,
756 _type_: &'a Type,
757 _extra_information: &'a Option<InvalidExpression>,
758) {
759 // No further traversal needed for constant invalid expressions
760}
761
762fn visit_typed_constant_string_concatenation<'a, V: Visit<'a> + ?Sized>(
763 v: &mut V,
764 _location: &'a SrcSpan,
765 left: &'a TypedConstant,
766 right: &'a TypedConstant,
767) {
768 v.visit_typed_constant(left);
769 v.visit_typed_constant(right);
770}
771
772pub fn visit_typed_constant_var<'a, V: Visit<'a> + ?Sized>(
773 _v: &mut V,
774 _location: &'a SrcSpan,
775 _module: &'a Option<(EcoString, SrcSpan)>,
776 _name: &'a EcoString,
777 _constructor: &'a Option<Box<ValueConstructor>>,
778 _type_: &'a Arc<Type>,
779) {
780 // No further traversal needed for constant vars
781}
782
783fn visit_typed_constant_bit_array<'a, V: Visit<'a> + ?Sized>(
784 _v: &mut V,
785 _location: &'a SrcSpan,
786 _segments: &'a [TypedConstantBitArraySegment],
787) {
788 // TODO
789}
790
791#[allow(clippy::too_many_arguments)]
792pub fn visit_typed_constant_record<'a, V: Visit<'a> + ?Sized>(
793 v: &mut V,
794 _location: &'a SrcSpan,
795 _module: &'a Option<(EcoString, SrcSpan)>,
796 _name: &'a EcoString,
797 arguments: &'a Vec<CallArg<TypedConstant>>,
798 _tag: &'a EcoString,
799 _type_: &'a Arc<Type>,
800 _field_map: &'a Inferred<FieldMap>,
801 _record_constructor: &'a Option<Box<ValueConstructor>>,
802) {
803 for argument in arguments {
804 v.visit_typed_constant(&argument.value)
805 }
806}
807
808#[allow(clippy::too_many_arguments)]
809fn visit_typed_constant_record_update<'a, V: Visit<'a> + ?Sized>(
810 v: &mut V,
811 _location: &'a SrcSpan,
812 _constructor_location: &'a SrcSpan,
813 _module: &'a Option<(EcoString, SrcSpan)>,
814 _name: &'a EcoString,
815 record: &'a RecordBeingUpdated<TypedConstant>,
816 arguments: &'a [RecordUpdateArg<TypedConstant>],
817 _tag: &'a EcoString,
818 _type_: &'a Arc<Type>,
819 _field_map: &'a Inferred<FieldMap>,
820) {
821 v.visit_typed_constant(&record.base);
822 for argument in arguments {
823 v.visit_typed_constant(&argument.value);
824 }
825}
826
827fn visit_typed_constant_list<'a, V: Visit<'a> + ?Sized>(
828 v: &mut V,
829 _location: &'a SrcSpan,
830 elements: &'a Vec<TypedConstant>,
831 _type_: &'a Arc<Type>,
832) {
833 for element in elements {
834 v.visit_typed_constant(element)
835 }
836}
837
838fn visit_typed_constant_tuple<'a, V: Visit<'a> + ?Sized>(
839 v: &mut V,
840 _location: &'a SrcSpan,
841 elements: &'a Vec<TypedConstant>,
842 _type_: &'a Arc<Type>,
843) {
844 for element in elements {
845 v.visit_typed_constant(element)
846 }
847}
848
849fn visit_typed_constant_string<'a, V: Visit<'a> + ?Sized>(
850 _v: &mut V,
851 _location: &'a SrcSpan,
852 _value: &'a EcoString,
853) {
854 // No further traversal needed for constant strings
855}
856
857fn visit_typed_constant_float<'a, V: Visit<'a> + ?Sized>(
858 _v: &mut V,
859 _location: &'a SrcSpan,
860 _value: &'a EcoString,
861 _float_value: &'a LiteralFloatValue,
862) {
863 // No further traversal needed for constant floats
864}
865
866fn visit_typed_constant_int<'a, V: Visit<'a> + ?Sized>(
867 _v: &mut V,
868 _location: &'a SrcSpan,
869 _value: &'a EcoString,
870 _int_value: &'a BigInt,
871) {
872 // No further traversal needed for constant ints
873}
874
875pub fn visit_typed_module<'a, V>(v: &mut V, module: &'a TypedModule)
876where
877 V: Visit<'a> + ?Sized,
878{
879 let TypedDefinitions {
880 imports: _, // TODO
881 constants,
882 custom_types,
883 type_aliases: _, // TODO
884 functions,
885 } = &module.definitions;
886
887 for constant in constants {
888 v.visit_typed_module_constant(constant);
889 }
890
891 for custom_type in custom_types {
892 v.visit_typed_custom_type(custom_type);
893 }
894
895 for function in functions {
896 v.visit_typed_function(function);
897 }
898}
899
900pub fn visit_typed_function<'a, V>(v: &mut V, fun: &'a TypedFunction)
901where
902 V: Visit<'a> + ?Sized,
903{
904 for argument in fun.arguments.iter() {
905 if let Some(annotation) = &argument.annotation {
906 v.visit_type_ast(annotation);
907 }
908 }
909 if let Some(annotation) = &fun.return_annotation {
910 v.visit_type_ast(annotation);
911 }
912
913 for statement in &fun.body {
914 v.visit_typed_statement(statement);
915 }
916}
917
918pub fn visit_type_ast<'a, V>(v: &mut V, node: &'a TypeAst)
919where
920 V: Visit<'a> + ?Sized,
921{
922 match node {
923 TypeAst::Constructor(super::TypeAstConstructor {
924 location,
925 name_location,
926 arguments,
927 module,
928 name,
929 start_parentheses: _,
930 }) => {
931 v.visit_type_ast_constructor(location, name_location, module, name, arguments);
932 }
933 TypeAst::Fn(super::TypeAstFn {
934 location,
935 arguments,
936 return_,
937 }) => {
938 v.visit_type_ast_fn(location, arguments, return_);
939 }
940 TypeAst::Var(super::TypeAstVar { location, name }) => {
941 v.visit_type_ast_var(location, name);
942 }
943 TypeAst::Tuple(super::TypeAstTuple { location, elements }) => {
944 v.visit_type_ast_tuple(location, elements);
945 }
946 TypeAst::Hole(super::TypeAstHole { location, name }) => {
947 v.visit_type_ast_hole(location, name);
948 }
949 }
950}
951
952pub fn visit_type_ast_constructor<'a, V>(
953 v: &mut V,
954 _location: &'a SrcSpan,
955 _name_location: &'a SrcSpan,
956 _module: &'a Option<(EcoString, SrcSpan)>,
957 _name: &'a EcoString,
958 arguments: &'a Vec<TypeAst>,
959) where
960 V: Visit<'a> + ?Sized,
961{
962 for argument in arguments {
963 v.visit_type_ast(argument);
964 }
965}
966
967pub fn visit_type_ast_fn<'a, V>(
968 v: &mut V,
969 _location: &'a SrcSpan,
970 arguments: &'a Vec<TypeAst>,
971 return_: &'a TypeAst,
972) where
973 V: Visit<'a> + ?Sized,
974{
975 for argument in arguments {
976 v.visit_type_ast(argument);
977 }
978 v.visit_type_ast(return_);
979}
980
981pub fn visit_type_ast_var<'a, V>(_v: &mut V, _location: &'a SrcSpan, _name: &'a EcoString)
982where
983 V: Visit<'a> + ?Sized,
984{
985 // No further traversal needed for variables
986}
987
988pub fn visit_type_ast_tuple<'a, V>(v: &mut V, _location: &'a SrcSpan, elements: &'a Vec<TypeAst>)
989where
990 V: Visit<'a> + ?Sized,
991{
992 for element in elements {
993 v.visit_type_ast(element);
994 }
995}
996
997pub fn visit_type_ast_hole<'a, V>(_v: &mut V, _location: &'a SrcSpan, _name: &'a EcoString)
998where
999 V: Visit<'a> + ?Sized,
1000{
1001 // No further traversal needed for holes
1002}
1003
1004pub fn visit_typed_module_constant<'a, V>(v: &mut V, constant: &'a TypedModuleConstant)
1005where
1006 V: Visit<'a> + ?Sized,
1007{
1008 v.visit_typed_constant(&constant.value);
1009}
1010
1011pub fn visit_typed_constant<'a, V: Visit<'a> + ?Sized>(v: &mut V, constant: &'a TypedConstant) {
1012 match constant {
1013 super::Constant::Int {
1014 location,
1015 value,
1016 int_value,
1017 } => v.visit_typed_constant_int(location, value, int_value),
1018 super::Constant::Float {
1019 location,
1020 value,
1021 float_value,
1022 } => v.visit_typed_constant_float(location, value, float_value),
1023 super::Constant::String { location, value } => {
1024 v.visit_typed_constant_string(location, value)
1025 }
1026 super::Constant::Tuple {
1027 location,
1028 elements,
1029 type_,
1030 } => v.visit_typed_constant_tuple(location, elements, type_),
1031 super::Constant::List {
1032 location,
1033 elements,
1034 type_,
1035 } => v.visit_typed_constant_list(location, elements, type_),
1036 super::Constant::Record {
1037 location,
1038 module,
1039 name,
1040 arguments,
1041 tag,
1042 type_,
1043 field_map,
1044 record_constructor,
1045 } => v.visit_typed_constant_record(
1046 location,
1047 module,
1048 name,
1049 arguments,
1050 tag,
1051 type_,
1052 field_map,
1053 record_constructor,
1054 ),
1055 super::Constant::RecordUpdate {
1056 location,
1057 constructor_location,
1058 module,
1059 name,
1060 record,
1061 arguments,
1062 tag,
1063 type_,
1064 field_map,
1065 } => v.visit_typed_constant_record_update(
1066 location,
1067 constructor_location,
1068 module,
1069 name,
1070 record,
1071 arguments,
1072 tag,
1073 type_,
1074 field_map,
1075 ),
1076 super::Constant::BitArray { location, segments } => {
1077 v.visit_typed_constant_bit_array(location, segments)
1078 }
1079 super::Constant::Var {
1080 location,
1081 module,
1082 name,
1083 constructor,
1084 type_,
1085 } => v.visit_typed_constant_var(location, module, name, constructor, type_),
1086 super::Constant::StringConcatenation {
1087 location,
1088 left,
1089 right,
1090 } => v.visit_typed_constant_string_concatenation(location, left, right),
1091 super::Constant::Invalid {
1092 location,
1093 type_,
1094 extra_information,
1095 } => v.visit_typed_constant_invalid(location, type_, extra_information),
1096 }
1097}
1098
1099pub fn visit_typed_custom_type<'a, V>(v: &mut V, custom_type: &'a TypedCustomType)
1100where
1101 V: Visit<'a> + ?Sized,
1102{
1103 for record in &custom_type.constructors {
1104 for argument in &record.arguments {
1105 v.visit_type_ast(&argument.ast);
1106 }
1107 }
1108}
1109
1110pub fn visit_typed_expr<'a, V>(v: &mut V, node: &'a TypedExpr)
1111where
1112 V: Visit<'a> + ?Sized,
1113{
1114 match node {
1115 TypedExpr::Int {
1116 location,
1117 type_,
1118 value,
1119 int_value: _,
1120 } => v.visit_typed_expr_int(location, type_, value),
1121 TypedExpr::Float {
1122 location,
1123 type_,
1124 value,
1125 float_value: _,
1126 } => v.visit_typed_expr_float(location, type_, value),
1127 TypedExpr::String {
1128 location,
1129 type_,
1130 value,
1131 } => v.visit_typed_expr_string(location, type_, value),
1132 TypedExpr::Block {
1133 location,
1134 statements,
1135 } => v.visit_typed_expr_block(location, statements),
1136 TypedExpr::Pipeline {
1137 location,
1138 first_value,
1139 assignments,
1140 finally,
1141 finally_kind,
1142 } => v.visit_typed_expr_pipeline(location, first_value, assignments, finally, finally_kind),
1143 TypedExpr::Var {
1144 location,
1145 constructor,
1146 name,
1147 } => v.visit_typed_expr_var(location, constructor, name),
1148 TypedExpr::Fn {
1149 location,
1150 type_,
1151 kind,
1152 arguments,
1153 body,
1154 return_annotation,
1155 purity: _,
1156 } => v.visit_typed_expr_fn(location, type_, kind, arguments, body, return_annotation),
1157 TypedExpr::List {
1158 location,
1159 type_,
1160 elements,
1161 tail,
1162 } => v.visit_typed_expr_list(location, type_, elements, tail),
1163 TypedExpr::Call {
1164 location,
1165 type_,
1166 fun,
1167 arguments,
1168 } => v.visit_typed_expr_call(location, type_, fun, arguments),
1169 TypedExpr::BinOp {
1170 location,
1171 type_,
1172 name,
1173 name_location,
1174 left,
1175 right,
1176 } => v.visit_typed_expr_bin_op(location, type_, name, name_location, left, right),
1177 TypedExpr::Case {
1178 location,
1179 type_,
1180 subjects,
1181 clauses,
1182 compiled_case,
1183 } => v.visit_typed_expr_case(location, type_, subjects, clauses, compiled_case),
1184 TypedExpr::RecordAccess {
1185 location,
1186 field_start,
1187 type_,
1188 label,
1189 index,
1190 record,
1191 documentation,
1192 kind: _,
1193 } => v.visit_typed_expr_record_access(
1194 location,
1195 field_start,
1196 type_,
1197 label,
1198 index,
1199 record,
1200 documentation,
1201 ),
1202 TypedExpr::ModuleSelect {
1203 location,
1204 field_start,
1205 type_,
1206 label,
1207 module_name,
1208 module_alias,
1209 constructor,
1210 } => v.visit_typed_expr_module_select(
1211 location,
1212 field_start,
1213 type_,
1214 label,
1215 module_name,
1216 module_alias,
1217 constructor,
1218 ),
1219 TypedExpr::Tuple {
1220 location,
1221 type_,
1222 elements,
1223 } => v.visit_typed_expr_tuple(location, type_, elements),
1224 TypedExpr::TupleIndex {
1225 location,
1226 type_,
1227 index,
1228 tuple,
1229 } => v.visit_typed_expr_tuple_index(location, type_, index, tuple),
1230 TypedExpr::Todo {
1231 location,
1232 message,
1233 kind,
1234 type_,
1235 } => v.visit_typed_expr_todo(location, message, kind, type_),
1236 TypedExpr::Panic {
1237 location,
1238 message,
1239 type_,
1240 } => v.visit_typed_expr_panic(location, message, type_),
1241 TypedExpr::BitArray {
1242 location,
1243 type_,
1244 segments,
1245 } => v.visit_typed_expr_bit_array(location, type_, segments),
1246 TypedExpr::RecordUpdate {
1247 location,
1248 type_,
1249 record_assignment,
1250 constructor,
1251 arguments,
1252 } => v.visit_typed_expr_record_update(
1253 location,
1254 type_,
1255 record_assignment,
1256 constructor,
1257 arguments,
1258 ),
1259 TypedExpr::NegateBool { location, value } => {
1260 v.visit_typed_expr_negate_bool(location, value)
1261 }
1262 TypedExpr::NegateInt { location, value } => v.visit_typed_expr_negate_int(location, value),
1263 TypedExpr::Invalid {
1264 location,
1265 type_,
1266 extra_information,
1267 } => v.visit_typed_expr_invalid(location, type_, extra_information),
1268 TypedExpr::Echo {
1269 location,
1270 expression,
1271 message,
1272 type_,
1273 } => v.visit_typed_expr_echo(location, type_, expression, message),
1274 }
1275}
1276
1277pub fn visit_typed_expr_int<'a, V>(
1278 _v: &mut V,
1279 _location: &'a SrcSpan,
1280 _type_: &'a Arc<Type>,
1281 _value: &'a EcoString,
1282) where
1283 V: Visit<'a> + ?Sized,
1284{
1285}
1286
1287pub fn visit_typed_expr_float<'a, V>(
1288 _v: &mut V,
1289 _location: &'a SrcSpan,
1290 _type_: &'a Arc<Type>,
1291 _value: &'a EcoString,
1292) where
1293 V: Visit<'a> + ?Sized,
1294{
1295}
1296
1297pub fn visit_typed_expr_string<'a, V>(
1298 _v: &mut V,
1299 _location: &'a SrcSpan,
1300 _type_: &'a Arc<Type>,
1301 _value: &'a EcoString,
1302) where
1303 V: Visit<'a> + ?Sized,
1304{
1305}
1306
1307pub fn visit_typed_expr_block<'a, V>(
1308 v: &mut V,
1309 _location: &'a SrcSpan,
1310 statements: &'a [TypedStatement],
1311) where
1312 V: Visit<'a> + ?Sized,
1313{
1314 for statement in statements {
1315 v.visit_typed_statement(statement);
1316 }
1317}
1318
1319pub fn visit_typed_expr_pipeline<'a, V>(
1320 v: &mut V,
1321 _location: &'a SrcSpan,
1322 first_value: &'a TypedPipelineAssignment,
1323 assignments: &'a [(TypedPipelineAssignment, PipelineAssignmentKind)],
1324 finally: &'a TypedExpr,
1325 _finally_kind: &'a PipelineAssignmentKind,
1326) where
1327 V: Visit<'a> + ?Sized,
1328{
1329 v.visit_typed_pipeline_assignment(first_value);
1330 for (assignment, _kind) in assignments {
1331 v.visit_typed_pipeline_assignment(assignment);
1332 }
1333
1334 v.visit_typed_expr(finally);
1335}
1336
1337pub fn visit_typed_pipeline_assignment<'a, V>(v: &mut V, assignment: &'a TypedPipelineAssignment)
1338where
1339 V: Visit<'a> + ?Sized,
1340{
1341 v.visit_typed_expr(&assignment.value);
1342}
1343
1344pub fn visit_typed_expr_var<'a, V>(
1345 _v: &mut V,
1346 _location: &'a SrcSpan,
1347 _constructor: &'a ValueConstructor,
1348 _name: &'a EcoString,
1349) where
1350 V: Visit<'a> + ?Sized,
1351{
1352 /* TODO */
1353}
1354
1355pub fn visit_typed_expr_fn<'a, V>(
1356 v: &mut V,
1357 _location: &'a SrcSpan,
1358 _type_: &'a Arc<Type>,
1359 _kind: &'a FunctionLiteralKind,
1360 arguments: &'a [TypedArg],
1361 body: &'a Vec1<TypedStatement>,
1362 return_annotation: &'a Option<TypeAst>,
1363) where
1364 V: Visit<'a> + ?Sized,
1365{
1366 for argument in arguments {
1367 if let Some(annotation) = &argument.annotation {
1368 v.visit_type_ast(annotation);
1369 }
1370 }
1371 if let Some(return_) = return_annotation {
1372 v.visit_type_ast(return_);
1373 }
1374
1375 for statement in body {
1376 v.visit_typed_statement(statement);
1377 }
1378}
1379
1380pub fn visit_typed_expr_list<'a, V>(
1381 v: &mut V,
1382 _location: &'a SrcSpan,
1383 _type_: &'a Arc<Type>,
1384 elements: &'a [TypedExpr],
1385 tail: &'a Option<Box<TypedExpr>>,
1386) where
1387 V: Visit<'a> + ?Sized,
1388{
1389 for element in elements {
1390 v.visit_typed_expr(element);
1391 }
1392
1393 if let Some(tail) = tail {
1394 v.visit_typed_expr(tail);
1395 }
1396}
1397
1398pub fn visit_typed_expr_call<'a, V>(
1399 v: &mut V,
1400 _location: &'a SrcSpan,
1401 _type_: &'a Arc<Type>,
1402 fun: &'a TypedExpr,
1403 arguments: &'a [TypedCallArg],
1404) where
1405 V: Visit<'a> + ?Sized,
1406{
1407 v.visit_typed_expr(fun);
1408 for argument in arguments {
1409 v.visit_typed_call_arg(argument);
1410 }
1411}
1412
1413pub fn visit_typed_expr_bin_op<'a, V>(
1414 v: &mut V,
1415 _location: &'a SrcSpan,
1416 _type_: &'a Arc<Type>,
1417 _name: &'a BinOp,
1418 _name_location: &'a SrcSpan,
1419 left: &'a TypedExpr,
1420 right: &'a TypedExpr,
1421) where
1422 V: Visit<'a> + ?Sized,
1423{
1424 v.visit_typed_expr(left);
1425 v.visit_typed_expr(right);
1426}
1427
1428pub fn visit_typed_expr_case<'a, V>(
1429 v: &mut V,
1430 _location: &'a SrcSpan,
1431 _type_: &'a Arc<Type>,
1432 subjects: &'a [TypedExpr],
1433 clauses: &'a [TypedClause],
1434 _compiled_case: &'a CompiledCase,
1435) where
1436 V: Visit<'a> + ?Sized,
1437{
1438 for subject in subjects {
1439 v.visit_typed_expr(subject);
1440 }
1441
1442 for clause in clauses {
1443 v.visit_typed_clause(clause);
1444 }
1445}
1446
1447#[allow(clippy::too_many_arguments)]
1448pub fn visit_typed_expr_record_access<'a, V>(
1449 v: &mut V,
1450 _location: &'a SrcSpan,
1451 _field_start: &'a u32,
1452 _type_: &'a Arc<Type>,
1453 _label: &'a EcoString,
1454 _index: &'a u64,
1455 record: &'a TypedExpr,
1456 _documentation: &'a Option<EcoString>,
1457) where
1458 V: Visit<'a> + ?Sized,
1459{
1460 v.visit_typed_expr(record);
1461}
1462
1463#[allow(clippy::too_many_arguments)]
1464pub fn visit_typed_expr_module_select<'a, V>(
1465 _v: &mut V,
1466 _location: &'a SrcSpan,
1467 _field_start: &'a u32,
1468 _type_: &'a Arc<Type>,
1469 _label: &'a EcoString,
1470 _module_name: &'a EcoString,
1471 _module_alias: &'a EcoString,
1472 _constructor: &'a ModuleValueConstructor,
1473) where
1474 V: Visit<'a> + ?Sized,
1475{
1476 /* TODO */
1477}
1478
1479pub fn visit_typed_expr_tuple<'a, V>(
1480 v: &mut V,
1481 _location: &'a SrcSpan,
1482 _type_: &'a Arc<Type>,
1483 elements: &'a [TypedExpr],
1484) where
1485 V: Visit<'a> + ?Sized,
1486{
1487 for element in elements {
1488 v.visit_typed_expr(element);
1489 }
1490}
1491
1492pub fn visit_typed_expr_tuple_index<'a, V>(
1493 v: &mut V,
1494 _location: &'a SrcSpan,
1495 _type_: &'a Arc<Type>,
1496 _index: &'a u64,
1497 tuple: &'a TypedExpr,
1498) where
1499 V: Visit<'a> + ?Sized,
1500{
1501 v.visit_typed_expr(tuple);
1502}
1503
1504pub fn visit_typed_expr_todo<'a, V>(
1505 v: &mut V,
1506 _location: &'a SrcSpan,
1507 message: &'a Option<Box<TypedExpr>>,
1508 _kind: &'a TodoKind,
1509 _type_: &'a Arc<Type>,
1510) where
1511 V: Visit<'a> + ?Sized,
1512{
1513 if let Some(message) = message {
1514 v.visit_typed_expr(message);
1515 }
1516}
1517
1518pub fn visit_typed_expr_echo<'a, V>(
1519 v: &mut V,
1520 _location: &'a SrcSpan,
1521 _type_: &'a Arc<Type>,
1522 expression: &'a Option<Box<TypedExpr>>,
1523 message: &'a Option<Box<TypedExpr>>,
1524) where
1525 V: Visit<'a> + ?Sized,
1526{
1527 if let Some(expression) = expression {
1528 v.visit_typed_expr(expression)
1529 }
1530 if let Some(message) = message {
1531 v.visit_typed_expr(message)
1532 }
1533}
1534
1535pub fn visit_typed_expr_panic<'a, V>(
1536 v: &mut V,
1537 _location: &'a SrcSpan,
1538 message: &'a Option<Box<TypedExpr>>,
1539 _type_: &'a Arc<Type>,
1540) where
1541 V: Visit<'a> + ?Sized,
1542{
1543 if let Some(message) = message {
1544 v.visit_typed_expr(message);
1545 }
1546}
1547
1548pub fn visit_typed_expr_bit_array<'a, V>(
1549 v: &mut V,
1550 _location: &'a SrcSpan,
1551 _type_: &'a Arc<Type>,
1552 segments: &'a [TypedExprBitArraySegment],
1553) where
1554 V: Visit<'a> + ?Sized,
1555{
1556 for segment in segments {
1557 v.visit_typed_expr_bit_array_segment(segment);
1558 }
1559}
1560
1561pub fn visit_typed_expr_record_update<'a, V>(
1562 v: &mut V,
1563 _location: &'a SrcSpan,
1564 _type_: &'a Arc<Type>,
1565 record: &'a Option<Box<TypedAssignment>>,
1566 constructor: &'a TypedExpr,
1567 arguments: &'a [TypedCallArg],
1568) where
1569 V: Visit<'a> + ?Sized,
1570{
1571 v.visit_typed_expr(constructor);
1572 if let Some(record) = record {
1573 v.visit_typed_assignment(record);
1574 }
1575 for argument in arguments {
1576 v.visit_typed_call_arg(argument);
1577 }
1578}
1579
1580pub fn visit_typed_expr_negate_bool<'a, V>(v: &mut V, _location: &'a SrcSpan, value: &'a TypedExpr)
1581where
1582 V: Visit<'a> + ?Sized,
1583{
1584 v.visit_typed_expr(value);
1585}
1586
1587pub fn visit_typed_expr_negate_int<'a, V>(v: &mut V, _location: &'a SrcSpan, value: &'a TypedExpr)
1588where
1589 V: Visit<'a> + ?Sized,
1590{
1591 v.visit_typed_expr(value);
1592}
1593
1594pub fn visit_typed_statement<'a, V>(v: &mut V, statement: &'a TypedStatement)
1595where
1596 V: Visit<'a> + ?Sized,
1597{
1598 match statement {
1599 Statement::Expression(expression) => v.visit_typed_expr(expression),
1600 Statement::Assignment(assignment) => v.visit_typed_assignment(assignment),
1601 Statement::Use(use_) => v.visit_typed_use(use_),
1602 Statement::Assert(assert) => v.visit_typed_assert(assert),
1603 }
1604}
1605
1606pub fn visit_typed_assignment<'a, V>(v: &mut V, assignment: &'a TypedAssignment)
1607where
1608 V: Visit<'a> + ?Sized,
1609{
1610 if let Some(annotation) = &assignment.annotation {
1611 v.visit_type_ast(annotation);
1612 }
1613 v.visit_typed_expr(&assignment.value);
1614 v.visit_typed_pattern(&assignment.pattern);
1615}
1616
1617pub fn visit_typed_use<'a, V>(v: &mut V, use_: &'a TypedUse)
1618where
1619 V: Visit<'a> + ?Sized,
1620{
1621 v.visit_typed_expr(&use_.call);
1622 // TODO: We should also visit the typed patterns!!
1623}
1624
1625pub fn visit_typed_assert<'a, V>(v: &mut V, assert: &'a TypedAssert)
1626where
1627 V: Visit<'a> + ?Sized,
1628{
1629 v.visit_typed_expr(&assert.value);
1630 if let Some(message) = &assert.message {
1631 v.visit_typed_expr(message);
1632 }
1633}
1634
1635pub fn visit_typed_call_arg<'a, V>(v: &mut V, arg: &'a TypedCallArg)
1636where
1637 V: Visit<'a> + ?Sized,
1638{
1639 v.visit_typed_expr(&arg.value);
1640}
1641
1642pub fn visit_typed_clause<'a, V>(v: &mut V, clause: &'a TypedClause)
1643where
1644 V: Visit<'a> + ?Sized,
1645{
1646 for pattern in clause.pattern.iter() {
1647 v.visit_typed_pattern(pattern);
1648 }
1649 for patterns in clause.alternative_patterns.iter() {
1650 for pattern in patterns {
1651 v.visit_typed_pattern(pattern);
1652 }
1653 }
1654 if let Some(guard) = &clause.guard {
1655 v.visit_typed_clause_guard(guard);
1656 }
1657 v.visit_typed_expr(&clause.then);
1658}
1659
1660pub fn visit_typed_clause_guard<'a, V>(v: &mut V, guard: &'a TypedClauseGuard)
1661where
1662 V: Visit<'a> + ?Sized,
1663{
1664 match guard {
1665 super::ClauseGuard::Equals {
1666 location: _,
1667 left,
1668 right,
1669 }
1670 | super::ClauseGuard::NotEquals {
1671 location: _,
1672 left,
1673 right,
1674 }
1675 | super::ClauseGuard::GtInt {
1676 location: _,
1677 left,
1678 right,
1679 }
1680 | super::ClauseGuard::GtEqInt {
1681 location: _,
1682 left,
1683 right,
1684 }
1685 | super::ClauseGuard::LtInt {
1686 location: _,
1687 left,
1688 right,
1689 }
1690 | super::ClauseGuard::LtEqInt {
1691 location: _,
1692 left,
1693 right,
1694 }
1695 | super::ClauseGuard::GtFloat {
1696 location: _,
1697 left,
1698 right,
1699 }
1700 | super::ClauseGuard::GtEqFloat {
1701 location: _,
1702 left,
1703 right,
1704 }
1705 | super::ClauseGuard::LtFloat {
1706 location: _,
1707 left,
1708 right,
1709 }
1710 | super::ClauseGuard::LtEqFloat {
1711 location: _,
1712 left,
1713 right,
1714 }
1715 | super::ClauseGuard::AddInt {
1716 location: _,
1717 left,
1718 right,
1719 }
1720 | super::ClauseGuard::AddFloat {
1721 location: _,
1722 left,
1723 right,
1724 }
1725 | super::ClauseGuard::SubInt {
1726 location: _,
1727 left,
1728 right,
1729 }
1730 | super::ClauseGuard::SubFloat {
1731 location: _,
1732 left,
1733 right,
1734 }
1735 | super::ClauseGuard::MultInt {
1736 location: _,
1737 left,
1738 right,
1739 }
1740 | super::ClauseGuard::MultFloat {
1741 location: _,
1742 left,
1743 right,
1744 }
1745 | super::ClauseGuard::DivInt {
1746 location: _,
1747 left,
1748 right,
1749 }
1750 | super::ClauseGuard::DivFloat {
1751 location: _,
1752 left,
1753 right,
1754 }
1755 | super::ClauseGuard::RemainderInt {
1756 location: _,
1757 left,
1758 right,
1759 }
1760 | super::ClauseGuard::Or {
1761 location: _,
1762 left,
1763 right,
1764 }
1765 | super::ClauseGuard::And {
1766 location: _,
1767 left,
1768 right,
1769 } => {
1770 v.visit_typed_clause_guard(left);
1771 v.visit_typed_clause_guard(right);
1772 }
1773 super::ClauseGuard::Block { location: _, value } => v.visit_typed_clause_guard(value),
1774 super::ClauseGuard::Not {
1775 location: _,
1776 expression,
1777 } => v.visit_typed_clause_guard(expression),
1778 super::ClauseGuard::Var {
1779 location,
1780 type_,
1781 name,
1782 definition_location,
1783 } => v.visit_typed_clause_guard_var(location, name, type_, definition_location),
1784 super::ClauseGuard::TupleIndex {
1785 location,
1786 index,
1787 type_,
1788 tuple,
1789 } => v.visit_typed_clause_guard_tuple_index(location, index, type_, tuple),
1790 super::ClauseGuard::FieldAccess {
1791 label_location,
1792 index,
1793 label,
1794 type_,
1795 container,
1796 } => {
1797 v.visit_typed_clause_guard_field_access(label_location, index, label, type_, container)
1798 }
1799 super::ClauseGuard::ModuleSelect {
1800 location,
1801 type_,
1802 label,
1803 module_name,
1804 module_alias,
1805 literal,
1806 } => v.visit_typed_clause_guard_module_select(
1807 location,
1808 type_,
1809 label,
1810 module_name,
1811 module_alias,
1812 literal,
1813 ),
1814 super::ClauseGuard::Constant(_constant) => {}
1815 }
1816}
1817
1818pub fn visit_typed_clause_guard_var<'a, V>(
1819 _v: &mut V,
1820 _location: &'a SrcSpan,
1821 _name: &'a EcoString,
1822 _type_: &'a Arc<Type>,
1823 _definition_location: &'a SrcSpan,
1824) where
1825 V: Visit<'a> + ?Sized,
1826{
1827}
1828
1829pub fn visit_typed_clause_guard_tuple_index<'a, V>(
1830 v: &mut V,
1831 _location: &'a SrcSpan,
1832 _index: &'a u64,
1833 _type_: &'a Arc<Type>,
1834 tuple: &'a TypedClauseGuard,
1835) where
1836 V: Visit<'a> + ?Sized,
1837{
1838 v.visit_typed_clause_guard(tuple);
1839}
1840
1841pub fn visit_typed_clause_guard_field_access<'a, V>(
1842 v: &mut V,
1843 _label_location: &'a SrcSpan,
1844 _index: &'a Option<u64>,
1845 _label: &'a EcoString,
1846 _type_: &'a Arc<Type>,
1847 container: &'a TypedClauseGuard,
1848) where
1849 V: Visit<'a> + ?Sized,
1850{
1851 v.visit_typed_clause_guard(container);
1852}
1853
1854pub fn visit_typed_clause_guard_module_select<'a, V>(
1855 _v: &mut V,
1856 _location: &'a SrcSpan,
1857 _type_: &'a Arc<Type>,
1858 _label: &'a EcoString,
1859 _module_name: &'a EcoString,
1860 _module_alias: &'a EcoString,
1861 _literal: &'a TypedConstant,
1862) where
1863 V: Visit<'a> + ?Sized,
1864{
1865}
1866
1867pub fn visit_typed_expr_bit_array_segment<'a, V>(v: &mut V, segment: &'a TypedExprBitArraySegment)
1868where
1869 V: Visit<'a> + ?Sized,
1870{
1871 v.visit_typed_expr(&segment.value);
1872 for option in &segment.options {
1873 v.visit_typed_bit_array_option(option);
1874 }
1875}
1876
1877pub fn visit_typed_bit_array_option<'a, V>(v: &mut V, option: &'a BitArrayOption<TypedExpr>)
1878where
1879 V: Visit<'a> + ?Sized,
1880{
1881 match option {
1882 BitArrayOption::Bytes { location: _ } => { /* TODO */ }
1883 BitArrayOption::Int { location: _ } => { /* TODO */ }
1884 BitArrayOption::Float { location: _ } => { /* TODO */ }
1885 BitArrayOption::Bits { location: _ } => { /* TODO */ }
1886 BitArrayOption::Utf8 { location: _ } => { /* TODO */ }
1887 BitArrayOption::Utf16 { location: _ } => { /* TODO */ }
1888 BitArrayOption::Utf32 { location: _ } => { /* TODO */ }
1889 BitArrayOption::Utf8Codepoint { location: _ } => { /* TODO */ }
1890 BitArrayOption::Utf16Codepoint { location: _ } => { /* TODO */ }
1891 BitArrayOption::Utf32Codepoint { location: _ } => { /* TODO */ }
1892 BitArrayOption::Signed { location: _ } => { /* TODO */ }
1893 BitArrayOption::Unsigned { location: _ } => { /* TODO */ }
1894 BitArrayOption::Big { location: _ } => { /* TODO */ }
1895 BitArrayOption::Little { location: _ } => { /* TODO */ }
1896 BitArrayOption::Native { location: _ } => { /* TODO */ }
1897 BitArrayOption::Size {
1898 location: _,
1899 value,
1900 short_form: _,
1901 } => {
1902 v.visit_typed_expr(value);
1903 }
1904 BitArrayOption::Unit {
1905 location: _,
1906 value: _,
1907 } => { /* TODO */ }
1908 }
1909}
1910
1911pub fn visit_typed_pattern<'a, V>(v: &mut V, pattern: &'a TypedPattern)
1912where
1913 V: Visit<'a> + ?Sized,
1914{
1915 match pattern {
1916 Pattern::Int {
1917 location,
1918 value,
1919 int_value: _,
1920 } => v.visit_typed_pattern_int(location, value),
1921 Pattern::Float {
1922 location,
1923 value,
1924 float_value: _,
1925 } => v.visit_typed_pattern_float(location, value),
1926 Pattern::String { location, value } => v.visit_typed_pattern_string(location, value),
1927 Pattern::Variable {
1928 location,
1929 name,
1930 type_,
1931 origin,
1932 } => v.visit_typed_pattern_variable(location, name, type_, origin),
1933 Pattern::BitArraySize(size) => v.visit_typed_pattern_bit_array_size(size),
1934 Pattern::Assign {
1935 location,
1936 name,
1937 pattern,
1938 } => v.visit_typed_pattern_assign(location, name, pattern),
1939 Pattern::Discard {
1940 location,
1941 name,
1942 type_,
1943 } => v.visit_typed_pattern_discard(location, name, type_),
1944 Pattern::List {
1945 location,
1946 elements,
1947 tail,
1948 type_,
1949 } => v.visit_typed_pattern_list(location, elements, tail, type_),
1950 Pattern::Constructor {
1951 location,
1952 name_location,
1953 name,
1954 arguments,
1955 module,
1956 constructor,
1957 spread,
1958 type_,
1959 } => v.visit_typed_pattern_constructor(
1960 location,
1961 name_location,
1962 name,
1963 arguments,
1964 module,
1965 constructor,
1966 spread,
1967 type_,
1968 ),
1969 Pattern::Tuple { location, elements } => v.visit_typed_pattern_tuple(location, elements),
1970 Pattern::BitArray { location, segments } => {
1971 v.visit_typed_pattern_bit_array(location, segments)
1972 }
1973 Pattern::StringPrefix {
1974 location,
1975 left_location,
1976 left_side_assignment,
1977 right_location,
1978 left_side_string,
1979 right_side_assignment,
1980 } => v.visit_typed_pattern_string_prefix(
1981 location,
1982 left_location,
1983 left_side_assignment,
1984 right_location,
1985 left_side_string,
1986 right_side_assignment,
1987 ),
1988 Pattern::Invalid { location, type_ } => v.visit_typed_pattern_invalid(location, type_),
1989 }
1990}
1991
1992fn visit_typed_pattern_int<'a, V>(_v: &mut V, _location: &'a SrcSpan, _value: &'a EcoString)
1993where
1994 V: Visit<'a> + ?Sized,
1995{
1996}
1997
1998pub fn visit_typed_pattern_float<'a, V>(_v: &mut V, _location: &'a SrcSpan, _value: &'a EcoString)
1999where
2000 V: Visit<'a> + ?Sized,
2001{
2002}
2003
2004pub fn visit_typed_pattern_string<'a, V>(_v: &mut V, _location: &'a SrcSpan, _value: &'a EcoString)
2005where
2006 V: Visit<'a> + ?Sized,
2007{
2008}
2009
2010pub fn visit_typed_pattern_variable<'a, V>(
2011 _v: &mut V,
2012 _location: &'a SrcSpan,
2013 _name: &'a EcoString,
2014 _type_: &'a Arc<Type>,
2015 _origin: &'a VariableOrigin,
2016) where
2017 V: Visit<'a> + ?Sized,
2018{
2019}
2020
2021pub fn visit_typed_pattern_bit_array_size<'a, V>(v: &mut V, size: &'a TypedBitArraySize)
2022where
2023 V: Visit<'a> + ?Sized,
2024{
2025 match size {
2026 BitArraySize::Int {
2027 location,
2028 value,
2029 int_value: _,
2030 } => v.visit_typed_bit_array_size_int(location, value),
2031 BitArraySize::Variable {
2032 location,
2033 name,
2034 constructor,
2035 type_,
2036 } => v.visit_typed_bit_array_size_variable(location, name, constructor, type_),
2037 BitArraySize::BinaryOperator { left, right, .. } => {
2038 v.visit_typed_pattern_bit_array_size(left);
2039 v.visit_typed_pattern_bit_array_size(right);
2040 }
2041 BitArraySize::Block { inner, .. } => v.visit_typed_pattern_bit_array_size(inner),
2042 }
2043}
2044
2045pub fn visit_typed_bit_array_size_int<'a, V>(
2046 _v: &mut V,
2047 _location: &'a SrcSpan,
2048 _value: &'a EcoString,
2049) where
2050 V: Visit<'a> + ?Sized,
2051{
2052}
2053
2054pub fn visit_typed_bit_array_size_variable<'a, V>(
2055 _v: &mut V,
2056 _location: &'a SrcSpan,
2057 _name: &'a EcoString,
2058 _constructor: &'a Option<Box<ValueConstructor>>,
2059 _type_: &'a Arc<Type>,
2060) where
2061 V: Visit<'a> + ?Sized,
2062{
2063}
2064
2065pub fn visit_typed_pattern_assign<'a, V>(
2066 v: &mut V,
2067 _location: &'a SrcSpan,
2068 _name: &'a EcoString,
2069 pattern: &'a TypedPattern,
2070) where
2071 V: Visit<'a> + ?Sized,
2072{
2073 v.visit_typed_pattern(pattern);
2074}
2075
2076pub fn visit_typed_pattern_discard<'a, V>(
2077 _v: &mut V,
2078 _location: &'a SrcSpan,
2079 _name: &'a EcoString,
2080 _type_: &'a Arc<Type>,
2081) where
2082 V: Visit<'a> + ?Sized,
2083{
2084}
2085
2086pub fn visit_typed_pattern_list<'a, V>(
2087 v: &mut V,
2088 _location: &'a SrcSpan,
2089 elements: &'a Vec<TypedPattern>,
2090 tail: &'a Option<Box<TypedTailPattern>>,
2091 _type_: &'a Arc<Type>,
2092) where
2093 V: Visit<'a> + ?Sized,
2094{
2095 for element in elements {
2096 v.visit_typed_pattern(element);
2097 }
2098 if let Some(tail) = tail {
2099 v.visit_typed_pattern(&tail.pattern);
2100 }
2101}
2102
2103#[allow(clippy::too_many_arguments)]
2104pub fn visit_typed_pattern_constructor<'a, V>(
2105 v: &mut V,
2106 _location: &'a SrcSpan,
2107 _name_location: &'a SrcSpan,
2108 _name: &'a EcoString,
2109 arguments: &'a Vec<CallArg<TypedPattern>>,
2110 _module: &'a Option<(EcoString, SrcSpan)>,
2111 _constructor: &'a Inferred<PatternConstructor>,
2112 _spread: &'a Option<SrcSpan>,
2113 _type_: &'a Arc<Type>,
2114) where
2115 V: Visit<'a> + ?Sized,
2116{
2117 for argument in arguments {
2118 v.visit_typed_pattern_call_arg(argument);
2119 }
2120}
2121
2122pub fn visit_typed_pattern_call_arg<'a, V>(v: &mut V, argument: &'a CallArg<TypedPattern>)
2123where
2124 V: Visit<'a> + ?Sized,
2125{
2126 v.visit_typed_pattern(&argument.value)
2127}
2128
2129pub fn visit_typed_pattern_tuple<'a, V>(
2130 v: &mut V,
2131 _location: &'a SrcSpan,
2132 elements: &'a Vec<TypedPattern>,
2133) where
2134 V: Visit<'a> + ?Sized,
2135{
2136 for element in elements {
2137 v.visit_typed_pattern(element);
2138 }
2139}
2140
2141pub fn visit_typed_pattern_bit_array<'a, V>(
2142 v: &mut V,
2143 _location: &'a SrcSpan,
2144 segments: &'a [TypedPatternBitArraySegment],
2145) where
2146 V: Visit<'a> + ?Sized,
2147{
2148 for segment in segments {
2149 v.visit_typed_pattern(&segment.value);
2150 for option in segment.options.iter() {
2151 v.visit_typed_pattern_bit_array_option(option);
2152 }
2153 }
2154}
2155
2156pub fn visit_typed_pattern_bit_array_option<'a, V>(
2157 v: &mut V,
2158 option: &'a BitArrayOption<TypedPattern>,
2159) where
2160 V: Visit<'a> + ?Sized,
2161{
2162 match option {
2163 BitArrayOption::Bytes { location: _ } => { /* TODO */ }
2164 BitArrayOption::Int { location: _ } => { /* TODO */ }
2165 BitArrayOption::Float { location: _ } => { /* TODO */ }
2166 BitArrayOption::Bits { location: _ } => { /* TODO */ }
2167 BitArrayOption::Utf8 { location: _ } => { /* TODO */ }
2168 BitArrayOption::Utf16 { location: _ } => { /* TODO */ }
2169 BitArrayOption::Utf32 { location: _ } => { /* TODO */ }
2170 BitArrayOption::Utf8Codepoint { location: _ } => { /* TODO */ }
2171 BitArrayOption::Utf16Codepoint { location: _ } => { /* TODO */ }
2172 BitArrayOption::Utf32Codepoint { location: _ } => { /* TODO */ }
2173 BitArrayOption::Signed { location: _ } => { /* TODO */ }
2174 BitArrayOption::Unsigned { location: _ } => { /* TODO */ }
2175 BitArrayOption::Big { location: _ } => { /* TODO */ }
2176 BitArrayOption::Little { location: _ } => { /* TODO */ }
2177 BitArrayOption::Native { location: _ } => { /* TODO */ }
2178 BitArrayOption::Size {
2179 location: _,
2180 value,
2181 short_form: _,
2182 } => {
2183 v.visit_typed_pattern(value);
2184 }
2185 BitArrayOption::Unit {
2186 location: _,
2187 value: _,
2188 } => { /* TODO */ }
2189 }
2190}
2191
2192pub fn visit_typed_pattern_string_prefix<'a, V>(
2193 _v: &mut V,
2194 _location: &'a SrcSpan,
2195 _left_location: &'a SrcSpan,
2196 _left_side_assignment: &'a Option<(EcoString, SrcSpan)>,
2197 _right_location: &'a SrcSpan,
2198 _left_side_string: &'a EcoString,
2199 _right_side_assignment: &'a AssignName,
2200) where
2201 V: Visit<'a> + ?Sized,
2202{
2203}
2204
2205pub fn visit_typed_pattern_invalid<'a, V>(_v: &mut V, _location: &'a SrcSpan, _type_: &'a Arc<Type>)
2206where
2207 V: Visit<'a> + ?Sized,
2208{
2209}
2210
2211pub fn visit_typed_expr_invalid<'a, V>(
2212 _v: &mut V,
2213 _location: &'a SrcSpan,
2214 _type_: &'a Arc<Type>,
2215 _extra_information: &'a Option<InvalidExpression>,
2216) where
2217 V: Visit<'a> + ?Sized,
2218{
2219}