Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

gleam / compiler-core / src / ast / visit.rs
51 kB 1870 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::{BitArraySize, TypedBitArraySize, TypedTailPattern, typed::InvalidExpression}, 44 exhaustiveness::CompiledCase, 45 type_::{ 46 ModuleValueConstructor, PatternConstructor, TypedCallArg, ValueConstructor, 47 error::VariableOrigin, 48 }, 49}; 50use std::sync::Arc; 51 52use ecow::EcoString; 53use vec1::Vec1; 54 55use crate::type_::Type; 56 57use super::{ 58 AssignName, BinOp, BitArrayOption, CallArg, Definition, Pattern, PipelineAssignmentKind, 59 SrcSpan, Statement, TodoKind, TypeAst, TypedArg, TypedAssert, TypedAssignment, TypedClause, 60 TypedClauseGuard, TypedConstant, TypedCustomType, TypedDefinition, TypedExpr, 61 TypedExprBitArraySegment, TypedFunction, TypedModule, TypedModuleConstant, TypedPattern, 62 TypedPatternBitArraySegment, TypedPipelineAssignment, TypedStatement, TypedUse, 63 untyped::FunctionLiteralKind, 64}; 65 66pub trait Visit<'ast> { 67 fn visit_typed_module(&mut self, module: &'ast TypedModule) { 68 visit_typed_module(self, module); 69 } 70 71 fn visit_typed_definition(&mut self, def: &'ast TypedDefinition) { 72 visit_typed_definition(self, def); 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 Vec<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 620pub fn visit_typed_module<'a, V>(v: &mut V, module: &'a TypedModule) 621where 622 V: Visit<'a> + ?Sized, 623{ 624 for definition in &module.definitions { 625 v.visit_typed_definition(definition); 626 } 627} 628 629pub fn visit_typed_definition<'a, V>(v: &mut V, def: &'a TypedDefinition) 630where 631 V: Visit<'a> + ?Sized, 632{ 633 match def { 634 Definition::Function(fun) => v.visit_typed_function(fun), 635 Definition::TypeAlias(_typealias) => { /* TODO */ } 636 Definition::CustomType(custom_type) => v.visit_typed_custom_type(custom_type), 637 Definition::Import(_import) => { /* TODO */ } 638 Definition::ModuleConstant(constant) => v.visit_typed_module_constant(constant), 639 } 640} 641pub fn visit_typed_function<'a, V>(v: &mut V, fun: &'a TypedFunction) 642where 643 V: Visit<'a> + ?Sized, 644{ 645 for argument in fun.arguments.iter() { 646 if let Some(annotation) = &argument.annotation { 647 v.visit_type_ast(annotation); 648 } 649 } 650 if let Some(annotation) = &fun.return_annotation { 651 v.visit_type_ast(annotation); 652 } 653 654 for statement in &fun.body { 655 v.visit_typed_statement(statement); 656 } 657} 658 659pub fn visit_type_ast<'a, V>(v: &mut V, node: &'a TypeAst) 660where 661 V: Visit<'a> + ?Sized, 662{ 663 match node { 664 TypeAst::Constructor(super::TypeAstConstructor { 665 location, 666 name_location, 667 arguments, 668 module, 669 name, 670 start_parentheses: _, 671 }) => { 672 v.visit_type_ast_constructor(location, name_location, module, name, arguments); 673 } 674 TypeAst::Fn(super::TypeAstFn { 675 location, 676 arguments, 677 return_, 678 }) => { 679 v.visit_type_ast_fn(location, arguments, return_); 680 } 681 TypeAst::Var(super::TypeAstVar { location, name }) => { 682 v.visit_type_ast_var(location, name); 683 } 684 TypeAst::Tuple(super::TypeAstTuple { location, elements }) => { 685 v.visit_type_ast_tuple(location, elements); 686 } 687 TypeAst::Hole(super::TypeAstHole { location, name }) => { 688 v.visit_type_ast_hole(location, name); 689 } 690 } 691} 692 693pub fn visit_type_ast_constructor<'a, V>( 694 v: &mut V, 695 _location: &'a SrcSpan, 696 _name_location: &'a SrcSpan, 697 _module: &'a Option<(EcoString, SrcSpan)>, 698 _name: &'a EcoString, 699 arguments: &'a Vec<TypeAst>, 700) where 701 V: Visit<'a> + ?Sized, 702{ 703 for argument in arguments { 704 v.visit_type_ast(argument); 705 } 706} 707 708pub fn visit_type_ast_fn<'a, V>( 709 v: &mut V, 710 _location: &'a SrcSpan, 711 arguments: &'a Vec<TypeAst>, 712 return_: &'a TypeAst, 713) where 714 V: Visit<'a> + ?Sized, 715{ 716 for argument in arguments { 717 v.visit_type_ast(argument); 718 } 719 v.visit_type_ast(return_); 720} 721 722pub fn visit_type_ast_var<'a, V>(_v: &mut V, _location: &'a SrcSpan, _name: &'a EcoString) 723where 724 V: Visit<'a> + ?Sized, 725{ 726 // No further traversal needed for variables 727} 728 729pub fn visit_type_ast_tuple<'a, V>(v: &mut V, _location: &'a SrcSpan, elements: &'a Vec<TypeAst>) 730where 731 V: Visit<'a> + ?Sized, 732{ 733 for element in elements { 734 v.visit_type_ast(element); 735 } 736} 737 738pub fn visit_type_ast_hole<'a, V>(_v: &mut V, _location: &'a SrcSpan, _name: &'a EcoString) 739where 740 V: Visit<'a> + ?Sized, 741{ 742 // No further traversal needed for holes 743} 744 745pub fn visit_typed_module_constant<'a, V>(_v: &mut V, _constant: &'a TypedModuleConstant) 746where 747 V: Visit<'a> + ?Sized, 748{ 749} 750 751pub fn visit_typed_custom_type<'a, V>(v: &mut V, custom_type: &'a TypedCustomType) 752where 753 V: Visit<'a> + ?Sized, 754{ 755 for record in &custom_type.constructors { 756 for argument in &record.arguments { 757 v.visit_type_ast(&argument.ast); 758 } 759 } 760} 761 762pub fn visit_typed_expr<'a, V>(v: &mut V, node: &'a TypedExpr) 763where 764 V: Visit<'a> + ?Sized, 765{ 766 match node { 767 TypedExpr::Int { 768 location, 769 type_, 770 value, 771 int_value: _, 772 } => v.visit_typed_expr_int(location, type_, value), 773 TypedExpr::Float { 774 location, 775 type_, 776 value, 777 float_value: _, 778 } => v.visit_typed_expr_float(location, type_, value), 779 TypedExpr::String { 780 location, 781 type_, 782 value, 783 } => v.visit_typed_expr_string(location, type_, value), 784 TypedExpr::Block { 785 location, 786 statements, 787 } => v.visit_typed_expr_block(location, statements), 788 TypedExpr::Pipeline { 789 location, 790 first_value, 791 assignments, 792 finally, 793 finally_kind, 794 } => v.visit_typed_expr_pipeline(location, first_value, assignments, finally, finally_kind), 795 TypedExpr::Var { 796 location, 797 constructor, 798 name, 799 } => v.visit_typed_expr_var(location, constructor, name), 800 TypedExpr::Fn { 801 location, 802 type_, 803 kind, 804 arguments, 805 body, 806 return_annotation, 807 purity: _, 808 } => v.visit_typed_expr_fn(location, type_, kind, arguments, body, return_annotation), 809 TypedExpr::List { 810 location, 811 type_, 812 elements, 813 tail, 814 } => v.visit_typed_expr_list(location, type_, elements, tail), 815 TypedExpr::Call { 816 location, 817 type_, 818 fun, 819 arguments, 820 } => v.visit_typed_expr_call(location, type_, fun, arguments), 821 TypedExpr::BinOp { 822 location, 823 type_, 824 name, 825 name_location, 826 left, 827 right, 828 } => v.visit_typed_expr_bin_op(location, type_, name, name_location, left, right), 829 TypedExpr::Case { 830 location, 831 type_, 832 subjects, 833 clauses, 834 compiled_case, 835 } => v.visit_typed_expr_case(location, type_, subjects, clauses, compiled_case), 836 TypedExpr::RecordAccess { 837 location, 838 field_start, 839 type_, 840 label, 841 index, 842 record, 843 documentation, 844 } => v.visit_typed_expr_record_access( 845 location, 846 field_start, 847 type_, 848 label, 849 index, 850 record, 851 documentation, 852 ), 853 TypedExpr::ModuleSelect { 854 location, 855 field_start, 856 type_, 857 label, 858 module_name, 859 module_alias, 860 constructor, 861 } => v.visit_typed_expr_module_select( 862 location, 863 field_start, 864 type_, 865 label, 866 module_name, 867 module_alias, 868 constructor, 869 ), 870 TypedExpr::Tuple { 871 location, 872 type_, 873 elements, 874 } => v.visit_typed_expr_tuple(location, type_, elements), 875 TypedExpr::TupleIndex { 876 location, 877 type_, 878 index, 879 tuple, 880 } => v.visit_typed_expr_tuple_index(location, type_, index, tuple), 881 TypedExpr::Todo { 882 location, 883 message, 884 kind, 885 type_, 886 } => v.visit_typed_expr_todo(location, message, kind, type_), 887 TypedExpr::Panic { 888 location, 889 message, 890 type_, 891 } => v.visit_typed_expr_panic(location, message, type_), 892 TypedExpr::BitArray { 893 location, 894 type_, 895 segments, 896 } => v.visit_typed_expr_bit_array(location, type_, segments), 897 TypedExpr::RecordUpdate { 898 location, 899 type_, 900 record_assignment, 901 constructor, 902 arguments, 903 } => v.visit_typed_expr_record_update( 904 location, 905 type_, 906 record_assignment, 907 constructor, 908 arguments, 909 ), 910 TypedExpr::NegateBool { location, value } => { 911 v.visit_typed_expr_negate_bool(location, value) 912 } 913 TypedExpr::NegateInt { location, value } => v.visit_typed_expr_negate_int(location, value), 914 TypedExpr::Invalid { 915 location, 916 type_, 917 extra_information, 918 } => v.visit_typed_expr_invalid(location, type_, extra_information), 919 TypedExpr::Echo { 920 location, 921 expression, 922 message, 923 type_, 924 } => v.visit_typed_expr_echo(location, type_, expression, message), 925 } 926} 927 928pub fn visit_typed_expr_int<'a, V>( 929 _v: &mut V, 930 _location: &'a SrcSpan, 931 _type_: &'a Arc<Type>, 932 _value: &'a EcoString, 933) where 934 V: Visit<'a> + ?Sized, 935{ 936} 937 938pub fn visit_typed_expr_float<'a, V>( 939 _v: &mut V, 940 _location: &'a SrcSpan, 941 _type_: &'a Arc<Type>, 942 _value: &'a EcoString, 943) where 944 V: Visit<'a> + ?Sized, 945{ 946} 947 948pub fn visit_typed_expr_string<'a, V>( 949 _v: &mut V, 950 _location: &'a SrcSpan, 951 _type_: &'a Arc<Type>, 952 _value: &'a EcoString, 953) where 954 V: Visit<'a> + ?Sized, 955{ 956} 957 958pub fn visit_typed_expr_block<'a, V>( 959 v: &mut V, 960 _location: &'a SrcSpan, 961 statements: &'a [TypedStatement], 962) where 963 V: Visit<'a> + ?Sized, 964{ 965 for statement in statements { 966 v.visit_typed_statement(statement); 967 } 968} 969 970pub fn visit_typed_expr_pipeline<'a, V>( 971 v: &mut V, 972 _location: &'a SrcSpan, 973 first_value: &'a TypedPipelineAssignment, 974 assignments: &'a [(TypedPipelineAssignment, PipelineAssignmentKind)], 975 finally: &'a TypedExpr, 976 _finally_kind: &'a PipelineAssignmentKind, 977) where 978 V: Visit<'a> + ?Sized, 979{ 980 v.visit_typed_pipeline_assignment(first_value); 981 for (assignment, _kind) in assignments { 982 v.visit_typed_pipeline_assignment(assignment); 983 } 984 985 v.visit_typed_expr(finally); 986} 987 988pub fn visit_typed_pipeline_assignment<'a, V>(v: &mut V, assignment: &'a TypedPipelineAssignment) 989where 990 V: Visit<'a> + ?Sized, 991{ 992 v.visit_typed_expr(&assignment.value); 993} 994 995pub fn visit_typed_expr_var<'a, V>( 996 _v: &mut V, 997 _location: &'a SrcSpan, 998 _constructor: &'a ValueConstructor, 999 _name: &'a EcoString, 1000) where 1001 V: Visit<'a> + ?Sized, 1002{ 1003 /* TODO */ 1004} 1005 1006pub fn visit_typed_expr_fn<'a, V>( 1007 v: &mut V, 1008 _location: &'a SrcSpan, 1009 _type_: &'a Arc<Type>, 1010 _kind: &'a FunctionLiteralKind, 1011 arguments: &'a [TypedArg], 1012 body: &'a Vec1<TypedStatement>, 1013 return_annotation: &'a Option<TypeAst>, 1014) where 1015 V: Visit<'a> + ?Sized, 1016{ 1017 for argument in arguments { 1018 if let Some(annotation) = &argument.annotation { 1019 v.visit_type_ast(annotation); 1020 } 1021 } 1022 if let Some(return_) = return_annotation { 1023 v.visit_type_ast(return_); 1024 } 1025 1026 for statement in body { 1027 v.visit_typed_statement(statement); 1028 } 1029} 1030 1031pub fn visit_typed_expr_list<'a, V>( 1032 v: &mut V, 1033 _location: &'a SrcSpan, 1034 _type_: &'a Arc<Type>, 1035 elements: &'a [TypedExpr], 1036 tail: &'a Option<Box<TypedExpr>>, 1037) where 1038 V: Visit<'a> + ?Sized, 1039{ 1040 for element in elements { 1041 v.visit_typed_expr(element); 1042 } 1043 1044 if let Some(tail) = tail { 1045 v.visit_typed_expr(tail); 1046 } 1047} 1048 1049pub fn visit_typed_expr_call<'a, V>( 1050 v: &mut V, 1051 _location: &'a SrcSpan, 1052 _type_: &'a Arc<Type>, 1053 fun: &'a TypedExpr, 1054 arguments: &'a [TypedCallArg], 1055) where 1056 V: Visit<'a> + ?Sized, 1057{ 1058 v.visit_typed_expr(fun); 1059 for argument in arguments { 1060 v.visit_typed_call_arg(argument); 1061 } 1062} 1063 1064pub fn visit_typed_expr_bin_op<'a, V>( 1065 v: &mut V, 1066 _location: &'a SrcSpan, 1067 _type_: &'a Arc<Type>, 1068 _name: &'a BinOp, 1069 _name_location: &'a SrcSpan, 1070 left: &'a TypedExpr, 1071 right: &'a TypedExpr, 1072) where 1073 V: Visit<'a> + ?Sized, 1074{ 1075 v.visit_typed_expr(left); 1076 v.visit_typed_expr(right); 1077} 1078 1079pub fn visit_typed_expr_case<'a, V>( 1080 v: &mut V, 1081 _location: &'a SrcSpan, 1082 _type_: &'a Arc<Type>, 1083 subjects: &'a [TypedExpr], 1084 clauses: &'a [TypedClause], 1085 _compiled_case: &'a CompiledCase, 1086) where 1087 V: Visit<'a> + ?Sized, 1088{ 1089 for subject in subjects { 1090 v.visit_typed_expr(subject); 1091 } 1092 1093 for clause in clauses { 1094 v.visit_typed_clause(clause); 1095 } 1096} 1097 1098#[allow(clippy::too_many_arguments)] 1099pub fn visit_typed_expr_record_access<'a, V>( 1100 v: &mut V, 1101 _location: &'a SrcSpan, 1102 _field_start: &'a u32, 1103 _type_: &'a Arc<Type>, 1104 _label: &'a EcoString, 1105 _index: &'a u64, 1106 record: &'a TypedExpr, 1107 _documentation: &'a Option<EcoString>, 1108) where 1109 V: Visit<'a> + ?Sized, 1110{ 1111 v.visit_typed_expr(record); 1112} 1113 1114#[allow(clippy::too_many_arguments)] 1115pub fn visit_typed_expr_module_select<'a, V>( 1116 _v: &mut V, 1117 _location: &'a SrcSpan, 1118 _field_start: &'a u32, 1119 _type_: &'a Arc<Type>, 1120 _label: &'a EcoString, 1121 _module_name: &'a EcoString, 1122 _module_alias: &'a EcoString, 1123 _constructor: &'a ModuleValueConstructor, 1124) where 1125 V: Visit<'a> + ?Sized, 1126{ 1127 /* TODO */ 1128} 1129 1130pub fn visit_typed_expr_tuple<'a, V>( 1131 v: &mut V, 1132 _location: &'a SrcSpan, 1133 _type_: &'a Arc<Type>, 1134 elements: &'a [TypedExpr], 1135) where 1136 V: Visit<'a> + ?Sized, 1137{ 1138 for element in elements { 1139 v.visit_typed_expr(element); 1140 } 1141} 1142 1143pub fn visit_typed_expr_tuple_index<'a, V>( 1144 v: &mut V, 1145 _location: &'a SrcSpan, 1146 _type_: &'a Arc<Type>, 1147 _index: &'a u64, 1148 tuple: &'a TypedExpr, 1149) where 1150 V: Visit<'a> + ?Sized, 1151{ 1152 v.visit_typed_expr(tuple); 1153} 1154 1155pub fn visit_typed_expr_todo<'a, V>( 1156 v: &mut V, 1157 _location: &'a SrcSpan, 1158 message: &'a Option<Box<TypedExpr>>, 1159 _kind: &'a TodoKind, 1160 _type_: &'a Arc<Type>, 1161) where 1162 V: Visit<'a> + ?Sized, 1163{ 1164 if let Some(message) = message { 1165 v.visit_typed_expr(message); 1166 } 1167} 1168 1169pub fn visit_typed_expr_echo<'a, V>( 1170 v: &mut V, 1171 _location: &'a SrcSpan, 1172 _type_: &'a Arc<Type>, 1173 expression: &'a Option<Box<TypedExpr>>, 1174 message: &'a Option<Box<TypedExpr>>, 1175) where 1176 V: Visit<'a> + ?Sized, 1177{ 1178 if let Some(expression) = expression { 1179 v.visit_typed_expr(expression) 1180 } 1181 if let Some(message) = message { 1182 v.visit_typed_expr(message) 1183 } 1184} 1185 1186pub fn visit_typed_expr_panic<'a, V>( 1187 v: &mut V, 1188 _location: &'a SrcSpan, 1189 message: &'a Option<Box<TypedExpr>>, 1190 _type_: &'a Arc<Type>, 1191) where 1192 V: Visit<'a> + ?Sized, 1193{ 1194 if let Some(message) = message { 1195 v.visit_typed_expr(message); 1196 } 1197} 1198 1199pub fn visit_typed_expr_bit_array<'a, V>( 1200 v: &mut V, 1201 _location: &'a SrcSpan, 1202 _type_: &'a Arc<Type>, 1203 segments: &'a [TypedExprBitArraySegment], 1204) where 1205 V: Visit<'a> + ?Sized, 1206{ 1207 for segment in segments { 1208 v.visit_typed_expr_bit_array_segment(segment); 1209 } 1210} 1211 1212pub fn visit_typed_expr_record_update<'a, V>( 1213 v: &mut V, 1214 _location: &'a SrcSpan, 1215 _type_: &'a Arc<Type>, 1216 record: &'a Option<Box<TypedAssignment>>, 1217 constructor: &'a TypedExpr, 1218 arguments: &'a [TypedCallArg], 1219) where 1220 V: Visit<'a> + ?Sized, 1221{ 1222 v.visit_typed_expr(constructor); 1223 if let Some(record) = record { 1224 v.visit_typed_assignment(record); 1225 } 1226 for argument in arguments { 1227 v.visit_typed_call_arg(argument); 1228 } 1229} 1230 1231pub fn visit_typed_expr_negate_bool<'a, V>(v: &mut V, _location: &'a SrcSpan, value: &'a TypedExpr) 1232where 1233 V: Visit<'a> + ?Sized, 1234{ 1235 v.visit_typed_expr(value); 1236} 1237 1238pub fn visit_typed_expr_negate_int<'a, V>(v: &mut V, _location: &'a SrcSpan, value: &'a TypedExpr) 1239where 1240 V: Visit<'a> + ?Sized, 1241{ 1242 v.visit_typed_expr(value); 1243} 1244 1245pub fn visit_typed_statement<'a, V>(v: &mut V, statement: &'a TypedStatement) 1246where 1247 V: Visit<'a> + ?Sized, 1248{ 1249 match statement { 1250 Statement::Expression(expression) => v.visit_typed_expr(expression), 1251 Statement::Assignment(assignment) => v.visit_typed_assignment(assignment), 1252 Statement::Use(use_) => v.visit_typed_use(use_), 1253 Statement::Assert(assert) => v.visit_typed_assert(assert), 1254 } 1255} 1256 1257pub fn visit_typed_assignment<'a, V>(v: &mut V, assignment: &'a TypedAssignment) 1258where 1259 V: Visit<'a> + ?Sized, 1260{ 1261 if let Some(annotation) = &assignment.annotation { 1262 v.visit_type_ast(annotation); 1263 } 1264 v.visit_typed_expr(&assignment.value); 1265 v.visit_typed_pattern(&assignment.pattern); 1266} 1267 1268pub fn visit_typed_use<'a, V>(v: &mut V, use_: &'a TypedUse) 1269where 1270 V: Visit<'a> + ?Sized, 1271{ 1272 v.visit_typed_expr(&use_.call); 1273 // TODO: We should also visit the typed patterns!! 1274} 1275 1276pub fn visit_typed_assert<'a, V>(v: &mut V, assert: &'a TypedAssert) 1277where 1278 V: Visit<'a> + ?Sized, 1279{ 1280 v.visit_typed_expr(&assert.value); 1281 if let Some(message) = &assert.message { 1282 v.visit_typed_expr(message); 1283 } 1284} 1285 1286pub fn visit_typed_call_arg<'a, V>(v: &mut V, arg: &'a TypedCallArg) 1287where 1288 V: Visit<'a> + ?Sized, 1289{ 1290 v.visit_typed_expr(&arg.value); 1291} 1292 1293pub fn visit_typed_clause<'a, V>(v: &mut V, clause: &'a TypedClause) 1294where 1295 V: Visit<'a> + ?Sized, 1296{ 1297 for pattern in clause.pattern.iter() { 1298 v.visit_typed_pattern(pattern); 1299 } 1300 for patterns in clause.alternative_patterns.iter() { 1301 for pattern in patterns { 1302 v.visit_typed_pattern(pattern); 1303 } 1304 } 1305 if let Some(guard) = &clause.guard { 1306 v.visit_typed_clause_guard(guard); 1307 } 1308 v.visit_typed_expr(&clause.then); 1309} 1310 1311pub fn visit_typed_clause_guard<'a, V>(v: &mut V, guard: &'a TypedClauseGuard) 1312where 1313 V: Visit<'a> + ?Sized, 1314{ 1315 match guard { 1316 super::ClauseGuard::Equals { 1317 location: _, 1318 left, 1319 right, 1320 } 1321 | super::ClauseGuard::NotEquals { 1322 location: _, 1323 left, 1324 right, 1325 } 1326 | super::ClauseGuard::GtInt { 1327 location: _, 1328 left, 1329 right, 1330 } 1331 | super::ClauseGuard::GtEqInt { 1332 location: _, 1333 left, 1334 right, 1335 } 1336 | super::ClauseGuard::LtInt { 1337 location: _, 1338 left, 1339 right, 1340 } 1341 | super::ClauseGuard::LtEqInt { 1342 location: _, 1343 left, 1344 right, 1345 } 1346 | super::ClauseGuard::GtFloat { 1347 location: _, 1348 left, 1349 right, 1350 } 1351 | super::ClauseGuard::GtEqFloat { 1352 location: _, 1353 left, 1354 right, 1355 } 1356 | super::ClauseGuard::LtFloat { 1357 location: _, 1358 left, 1359 right, 1360 } 1361 | super::ClauseGuard::LtEqFloat { 1362 location: _, 1363 left, 1364 right, 1365 } 1366 | super::ClauseGuard::AddInt { 1367 location: _, 1368 left, 1369 right, 1370 } 1371 | super::ClauseGuard::AddFloat { 1372 location: _, 1373 left, 1374 right, 1375 } 1376 | super::ClauseGuard::SubInt { 1377 location: _, 1378 left, 1379 right, 1380 } 1381 | super::ClauseGuard::SubFloat { 1382 location: _, 1383 left, 1384 right, 1385 } 1386 | super::ClauseGuard::MultInt { 1387 location: _, 1388 left, 1389 right, 1390 } 1391 | super::ClauseGuard::MultFloat { 1392 location: _, 1393 left, 1394 right, 1395 } 1396 | super::ClauseGuard::DivInt { 1397 location: _, 1398 left, 1399 right, 1400 } 1401 | super::ClauseGuard::DivFloat { 1402 location: _, 1403 left, 1404 right, 1405 } 1406 | super::ClauseGuard::RemainderInt { 1407 location: _, 1408 left, 1409 right, 1410 } 1411 | super::ClauseGuard::Or { 1412 location: _, 1413 left, 1414 right, 1415 } 1416 | super::ClauseGuard::And { 1417 location: _, 1418 left, 1419 right, 1420 } => { 1421 v.visit_typed_clause_guard(left); 1422 v.visit_typed_clause_guard(right); 1423 } 1424 super::ClauseGuard::Block { location: _, value } => v.visit_typed_clause_guard(value), 1425 super::ClauseGuard::Not { 1426 location: _, 1427 expression, 1428 } => v.visit_typed_clause_guard(expression), 1429 super::ClauseGuard::Var { 1430 location, 1431 type_, 1432 name, 1433 definition_location, 1434 } => v.visit_typed_clause_guard_var(location, name, type_, definition_location), 1435 super::ClauseGuard::TupleIndex { 1436 location, 1437 index, 1438 type_, 1439 tuple, 1440 } => v.visit_typed_clause_guard_tuple_index(location, index, type_, tuple), 1441 super::ClauseGuard::FieldAccess { 1442 label_location, 1443 index, 1444 label, 1445 type_, 1446 container, 1447 } => { 1448 v.visit_typed_clause_guard_field_access(label_location, index, label, type_, container) 1449 } 1450 super::ClauseGuard::ModuleSelect { 1451 location, 1452 type_, 1453 label, 1454 module_name, 1455 module_alias, 1456 literal, 1457 } => v.visit_typed_clause_guard_module_select( 1458 location, 1459 type_, 1460 label, 1461 module_name, 1462 module_alias, 1463 literal, 1464 ), 1465 super::ClauseGuard::Constant(_constant) => {} 1466 } 1467} 1468 1469pub fn visit_typed_clause_guard_var<'a, V>( 1470 _v: &mut V, 1471 _location: &'a SrcSpan, 1472 _name: &'a EcoString, 1473 _type_: &'a Arc<Type>, 1474 _definition_location: &'a SrcSpan, 1475) where 1476 V: Visit<'a> + ?Sized, 1477{ 1478} 1479 1480pub fn visit_typed_clause_guard_tuple_index<'a, V>( 1481 v: &mut V, 1482 _location: &'a SrcSpan, 1483 _index: &'a u64, 1484 _type_: &'a Arc<Type>, 1485 tuple: &'a TypedClauseGuard, 1486) where 1487 V: Visit<'a> + ?Sized, 1488{ 1489 v.visit_typed_clause_guard(tuple); 1490} 1491 1492pub fn visit_typed_clause_guard_field_access<'a, V>( 1493 v: &mut V, 1494 _label_location: &'a SrcSpan, 1495 _index: &'a Option<u64>, 1496 _label: &'a EcoString, 1497 _type_: &'a Arc<Type>, 1498 container: &'a TypedClauseGuard, 1499) where 1500 V: Visit<'a> + ?Sized, 1501{ 1502 v.visit_typed_clause_guard(container); 1503} 1504 1505pub fn visit_typed_clause_guard_module_select<'a, V>( 1506 _v: &mut V, 1507 _location: &'a SrcSpan, 1508 _type_: &'a Arc<Type>, 1509 _label: &'a EcoString, 1510 _module_name: &'a EcoString, 1511 _module_alias: &'a EcoString, 1512 _literal: &'a TypedConstant, 1513) where 1514 V: Visit<'a> + ?Sized, 1515{ 1516} 1517 1518pub fn visit_typed_expr_bit_array_segment<'a, V>(v: &mut V, segment: &'a TypedExprBitArraySegment) 1519where 1520 V: Visit<'a> + ?Sized, 1521{ 1522 v.visit_typed_expr(&segment.value); 1523 for option in &segment.options { 1524 v.visit_typed_bit_array_option(option); 1525 } 1526} 1527 1528pub fn visit_typed_bit_array_option<'a, V>(v: &mut V, option: &'a BitArrayOption<TypedExpr>) 1529where 1530 V: Visit<'a> + ?Sized, 1531{ 1532 match option { 1533 BitArrayOption::Bytes { location: _ } => { /* TODO */ } 1534 BitArrayOption::Int { location: _ } => { /* TODO */ } 1535 BitArrayOption::Float { location: _ } => { /* TODO */ } 1536 BitArrayOption::Bits { location: _ } => { /* TODO */ } 1537 BitArrayOption::Utf8 { location: _ } => { /* TODO */ } 1538 BitArrayOption::Utf16 { location: _ } => { /* TODO */ } 1539 BitArrayOption::Utf32 { location: _ } => { /* TODO */ } 1540 BitArrayOption::Utf8Codepoint { location: _ } => { /* TODO */ } 1541 BitArrayOption::Utf16Codepoint { location: _ } => { /* TODO */ } 1542 BitArrayOption::Utf32Codepoint { location: _ } => { /* TODO */ } 1543 BitArrayOption::Signed { location: _ } => { /* TODO */ } 1544 BitArrayOption::Unsigned { location: _ } => { /* TODO */ } 1545 BitArrayOption::Big { location: _ } => { /* TODO */ } 1546 BitArrayOption::Little { location: _ } => { /* TODO */ } 1547 BitArrayOption::Native { location: _ } => { /* TODO */ } 1548 BitArrayOption::Size { 1549 location: _, 1550 value, 1551 short_form: _, 1552 } => { 1553 v.visit_typed_expr(value); 1554 } 1555 BitArrayOption::Unit { 1556 location: _, 1557 value: _, 1558 } => { /* TODO */ } 1559 } 1560} 1561 1562pub fn visit_typed_pattern<'a, V>(v: &mut V, pattern: &'a TypedPattern) 1563where 1564 V: Visit<'a> + ?Sized, 1565{ 1566 match pattern { 1567 Pattern::Int { 1568 location, 1569 value, 1570 int_value: _, 1571 } => v.visit_typed_pattern_int(location, value), 1572 Pattern::Float { 1573 location, 1574 value, 1575 float_value: _, 1576 } => v.visit_typed_pattern_float(location, value), 1577 Pattern::String { location, value } => v.visit_typed_pattern_string(location, value), 1578 Pattern::Variable { 1579 location, 1580 name, 1581 type_, 1582 origin, 1583 } => v.visit_typed_pattern_variable(location, name, type_, origin), 1584 Pattern::BitArraySize(size) => v.visit_typed_pattern_bit_array_size(size), 1585 Pattern::Assign { 1586 location, 1587 name, 1588 pattern, 1589 } => v.visit_typed_pattern_assign(location, name, pattern), 1590 Pattern::Discard { 1591 location, 1592 name, 1593 type_, 1594 } => v.visit_typed_pattern_discard(location, name, type_), 1595 Pattern::List { 1596 location, 1597 elements, 1598 tail, 1599 type_, 1600 } => v.visit_typed_pattern_list(location, elements, tail, type_), 1601 Pattern::Constructor { 1602 location, 1603 name_location, 1604 name, 1605 arguments, 1606 module, 1607 constructor, 1608 spread, 1609 type_, 1610 } => v.visit_typed_pattern_constructor( 1611 location, 1612 name_location, 1613 name, 1614 arguments, 1615 module, 1616 constructor, 1617 spread, 1618 type_, 1619 ), 1620 Pattern::Tuple { location, elements } => v.visit_typed_pattern_tuple(location, elements), 1621 Pattern::BitArray { location, segments } => { 1622 v.visit_typed_pattern_bit_array(location, segments) 1623 } 1624 Pattern::StringPrefix { 1625 location, 1626 left_location, 1627 left_side_assignment, 1628 right_location, 1629 left_side_string, 1630 right_side_assignment, 1631 } => v.visit_typed_pattern_string_prefix( 1632 location, 1633 left_location, 1634 left_side_assignment, 1635 right_location, 1636 left_side_string, 1637 right_side_assignment, 1638 ), 1639 Pattern::Invalid { location, type_ } => v.visit_typed_pattern_invalid(location, type_), 1640 } 1641} 1642 1643fn visit_typed_pattern_int<'a, V>(_v: &mut V, _location: &'a SrcSpan, _value: &'a EcoString) 1644where 1645 V: Visit<'a> + ?Sized, 1646{ 1647} 1648 1649pub fn visit_typed_pattern_float<'a, V>(_v: &mut V, _location: &'a SrcSpan, _value: &'a EcoString) 1650where 1651 V: Visit<'a> + ?Sized, 1652{ 1653} 1654 1655pub fn visit_typed_pattern_string<'a, V>(_v: &mut V, _location: &'a SrcSpan, _value: &'a EcoString) 1656where 1657 V: Visit<'a> + ?Sized, 1658{ 1659} 1660 1661pub fn visit_typed_pattern_variable<'a, V>( 1662 _v: &mut V, 1663 _location: &'a SrcSpan, 1664 _name: &'a EcoString, 1665 _type_: &'a Arc<Type>, 1666 _origin: &'a VariableOrigin, 1667) where 1668 V: Visit<'a> + ?Sized, 1669{ 1670} 1671 1672pub fn visit_typed_pattern_bit_array_size<'a, V>(v: &mut V, size: &'a TypedBitArraySize) 1673where 1674 V: Visit<'a> + ?Sized, 1675{ 1676 match size { 1677 BitArraySize::Int { 1678 location, 1679 value, 1680 int_value: _, 1681 } => v.visit_typed_bit_array_size_int(location, value), 1682 BitArraySize::Variable { 1683 location, 1684 name, 1685 constructor, 1686 type_, 1687 } => v.visit_typed_bit_array_size_variable(location, name, constructor, type_), 1688 BitArraySize::BinaryOperator { left, right, .. } => { 1689 v.visit_typed_pattern_bit_array_size(left); 1690 v.visit_typed_pattern_bit_array_size(right); 1691 } 1692 BitArraySize::Block { inner, .. } => v.visit_typed_pattern_bit_array_size(inner), 1693 } 1694} 1695 1696pub fn visit_typed_bit_array_size_int<'a, V>( 1697 _v: &mut V, 1698 _location: &'a SrcSpan, 1699 _value: &'a EcoString, 1700) where 1701 V: Visit<'a> + ?Sized, 1702{ 1703} 1704 1705pub fn visit_typed_bit_array_size_variable<'a, V>( 1706 _v: &mut V, 1707 _location: &'a SrcSpan, 1708 _name: &'a EcoString, 1709 _constructor: &'a Option<Box<ValueConstructor>>, 1710 _type_: &'a Arc<Type>, 1711) where 1712 V: Visit<'a> + ?Sized, 1713{ 1714} 1715 1716pub fn visit_typed_pattern_assign<'a, V>( 1717 v: &mut V, 1718 _location: &'a SrcSpan, 1719 _name: &'a EcoString, 1720 pattern: &'a TypedPattern, 1721) where 1722 V: Visit<'a> + ?Sized, 1723{ 1724 v.visit_typed_pattern(pattern); 1725} 1726 1727pub fn visit_typed_pattern_discard<'a, V>( 1728 _v: &mut V, 1729 _location: &'a SrcSpan, 1730 _name: &'a EcoString, 1731 _type_: &'a Arc<Type>, 1732) where 1733 V: Visit<'a> + ?Sized, 1734{ 1735} 1736 1737pub fn visit_typed_pattern_list<'a, V>( 1738 v: &mut V, 1739 _location: &'a SrcSpan, 1740 elements: &'a Vec<TypedPattern>, 1741 tail: &'a Option<Box<TypedTailPattern>>, 1742 _type_: &'a Arc<Type>, 1743) where 1744 V: Visit<'a> + ?Sized, 1745{ 1746 for element in elements { 1747 v.visit_typed_pattern(element); 1748 } 1749 if let Some(tail) = tail { 1750 v.visit_typed_pattern(&tail.pattern); 1751 } 1752} 1753 1754#[allow(clippy::too_many_arguments)] 1755pub fn visit_typed_pattern_constructor<'a, V>( 1756 v: &mut V, 1757 _location: &'a SrcSpan, 1758 _name_location: &'a SrcSpan, 1759 _name: &'a EcoString, 1760 arguments: &'a Vec<CallArg<TypedPattern>>, 1761 _module: &'a Option<(EcoString, SrcSpan)>, 1762 _constructor: &'a Inferred<PatternConstructor>, 1763 _spread: &'a Option<SrcSpan>, 1764 _type_: &'a Arc<Type>, 1765) where 1766 V: Visit<'a> + ?Sized, 1767{ 1768 for argument in arguments { 1769 v.visit_typed_pattern_call_arg(argument); 1770 } 1771} 1772 1773pub fn visit_typed_pattern_call_arg<'a, V>(v: &mut V, argument: &'a CallArg<TypedPattern>) 1774where 1775 V: Visit<'a> + ?Sized, 1776{ 1777 v.visit_typed_pattern(&argument.value) 1778} 1779 1780pub fn visit_typed_pattern_tuple<'a, V>( 1781 v: &mut V, 1782 _location: &'a SrcSpan, 1783 elements: &'a Vec<TypedPattern>, 1784) where 1785 V: Visit<'a> + ?Sized, 1786{ 1787 for element in elements { 1788 v.visit_typed_pattern(element); 1789 } 1790} 1791 1792pub fn visit_typed_pattern_bit_array<'a, V>( 1793 v: &mut V, 1794 _location: &'a SrcSpan, 1795 segments: &'a Vec<TypedPatternBitArraySegment>, 1796) where 1797 V: Visit<'a> + ?Sized, 1798{ 1799 for segment in segments { 1800 v.visit_typed_pattern(&segment.value); 1801 for option in segment.options.iter() { 1802 v.visit_typed_pattern_bit_array_option(option); 1803 } 1804 } 1805} 1806 1807pub fn visit_typed_pattern_bit_array_option<'a, V>( 1808 v: &mut V, 1809 option: &'a BitArrayOption<TypedPattern>, 1810) where 1811 V: Visit<'a> + ?Sized, 1812{ 1813 match option { 1814 BitArrayOption::Bytes { location: _ } => { /* TODO */ } 1815 BitArrayOption::Int { location: _ } => { /* TODO */ } 1816 BitArrayOption::Float { location: _ } => { /* TODO */ } 1817 BitArrayOption::Bits { location: _ } => { /* TODO */ } 1818 BitArrayOption::Utf8 { location: _ } => { /* TODO */ } 1819 BitArrayOption::Utf16 { location: _ } => { /* TODO */ } 1820 BitArrayOption::Utf32 { location: _ } => { /* TODO */ } 1821 BitArrayOption::Utf8Codepoint { location: _ } => { /* TODO */ } 1822 BitArrayOption::Utf16Codepoint { location: _ } => { /* TODO */ } 1823 BitArrayOption::Utf32Codepoint { location: _ } => { /* TODO */ } 1824 BitArrayOption::Signed { location: _ } => { /* TODO */ } 1825 BitArrayOption::Unsigned { location: _ } => { /* TODO */ } 1826 BitArrayOption::Big { location: _ } => { /* TODO */ } 1827 BitArrayOption::Little { location: _ } => { /* TODO */ } 1828 BitArrayOption::Native { location: _ } => { /* TODO */ } 1829 BitArrayOption::Size { 1830 location: _, 1831 value, 1832 short_form: _, 1833 } => { 1834 v.visit_typed_pattern(value); 1835 } 1836 BitArrayOption::Unit { 1837 location: _, 1838 value: _, 1839 } => { /* TODO */ } 1840 } 1841} 1842 1843pub fn visit_typed_pattern_string_prefix<'a, V>( 1844 _v: &mut V, 1845 _location: &'a SrcSpan, 1846 _left_location: &'a SrcSpan, 1847 _left_side_assignment: &'a Option<(EcoString, SrcSpan)>, 1848 _right_location: &'a SrcSpan, 1849 _left_side_string: &'a EcoString, 1850 _right_side_assignment: &'a AssignName, 1851) where 1852 V: Visit<'a> + ?Sized, 1853{ 1854} 1855 1856pub fn visit_typed_pattern_invalid<'a, V>(_v: &mut V, _location: &'a SrcSpan, _type_: &'a Arc<Type>) 1857where 1858 V: Visit<'a> + ?Sized, 1859{ 1860} 1861 1862pub fn visit_typed_expr_invalid<'a, V>( 1863 _v: &mut V, 1864 _location: &'a SrcSpan, 1865 _type_: &'a Arc<Type>, 1866 _extra_information: &'a Option<InvalidExpression>, 1867) where 1868 V: Visit<'a> + ?Sized, 1869{ 1870}