Appearance
| 1 | namespace Syntax.Trees.Expressions is | |
| 2 | ||
| 3 | use Source; | |
| 4 | ||
| 5 | class VARIABLE: Expression is | |
| 6 | name: Identifiers.Identifier; | |
| 7 | initializer: Expression?; | |
| 8 | type_expression: TypeExpressions.TypeExpression; | |
| 9 | ||
| 10 | // Attribute pragmas (`@Foo() name: T`) written directly before a | |
| 11 | // lambda-literal parameter. Only ever populated by | |
| 12 | // Expressions.PRIMARY's `@` handler; null everywhere else this | |
| 13 | // node shows up (rewritten from a tuple element, or synthesised | |
| 14 | // for an untyped lambda parameter). | |
| 15 | pragmas: Collections.LIST[Pragmas.PRAGMA]? public; | |
| 16 | ||
| 17 | // Set when this parameter is written as a destructure pattern | |
| 18 | // (`((a, b)) => …`) rather than a plain name. The parameter is | |
| 19 | // still one physical argument, under the synthesised `name` | |
| 20 | // above; `left` says how to unpack it into the names the body | |
| 21 | // actually uses. Null for an ordinary named parameter, which | |
| 22 | // is every other place this node appears. | |
| 23 | left: Variables.VariableLeft? public; | |
| 24 | ||
| 25 | is_destructuring: bool => left?; | |
| 26 | ||
| 27 | could_be_formal_argument: bool => true; | |
| 28 | ||
| 29 | init( | |
| 30 | location: LOCATION, | |
| 31 | name: Identifiers.Identifier, | |
| 32 | type_expression: TypeExpressions.TypeExpression, | |
| 33 | initializer: Expression? | |
| 34 | ) | |
| 35 | is | |
| 36 | super.init(location); | |
| 37 | ||
| 38 | self.name = name; | |
| 39 | self.type_expression = type_expression; | |
| 40 | self.initializer = initializer; | |
| 41 | si | |
| 42 | ||
| 43 | set_pragmas(pragmas: Collections.LIST[Pragmas.PRAGMA]) is | |
| 44 | self.pragmas = pragmas; | |
| 45 | si | |
| 46 | ||
| 47 | set_left(left: Variables.VariableLeft) is | |
| 48 | self.left = left; | |
| 49 | si | |
| 50 | ||
| 51 | // An element written `name: T` inside a pattern is a leaf with | |
| 52 | // a per-element type ascription, exactly as in a `let`. | |
| 53 | try_copy_as_variable_left() -> Variables.VariableLeft? is | |
| 54 | let result = Variables.SIMPLE_VARIABLE_LEFT(location, name.copy()); | |
| 55 | ||
| 56 | if !isa TypeExpressions.INFER(type_expression) then | |
| 57 | result.set_type_expression(type_expression.copy()); | |
| 58 | fi | |
| 59 | ||
| 60 | return result; | |
| 61 | si | |
| 62 | ||
| 63 | try_copy_as_tuple_element() -> TUPLE_ELEMENT is | |
| 64 | let result = TUPLE_ELEMENT(location, name, type_expression, initializer); | |
| 65 | ||
| 66 | if let self_pragmas = pragmas then | |
| 67 | result.set_pragmas(self_pragmas); | |
| 68 | fi | |
| 69 | ||
| 70 | return result; | |
| 71 | si | |
| 72 | ||
| 73 | accept(visitor: Visitor) is | |
| 74 | visitor.visit(self); | |
| 75 | si | |
| 76 | ||
| 77 | walk(visitor: Visitor) is | |
| 78 | if !visitor.pre(self) then | |
| 79 | if pragmas? then | |
| 80 | for pragma in pragmas do | |
| 81 | pragma.walk(visitor); | |
| 82 | od | |
| 83 | fi | |
| 84 | ||
| 85 | name.walk(visitor); | |
| 86 | ||
| 87 | if let self.left? then | |
| 88 | left.walk(visitor); | |
| 89 | fi | |
| 90 | ||
| 91 | type_expression.walk(visitor); | |
| 92 | ||
| 93 | if initializer? then | |
| 94 | initializer.walk(visitor); | |
| 95 | fi | |
| 96 | fi | |
| 97 | ||
| 98 | accept(visitor); | |
| 99 | si | |
| 100 | si | |
| 101 | si |