Appearance
| 1 | namespace Syntax.Trees.Statements is | |
| 2 | use Source | |
| 3 | ||
| 4 | class FOR( | |
| 5 | location: LOCATION, | |
| 6 | variable: Variables.VARIABLE?, | |
| 7 | expression: Expressions.Expression?, | |
| 8 | body: Statements.LIST? | |
| 9 | ): Statement, ScopeCarrier, IteratorCarrier is | |
| 10 | scope: Semantic.Scope? public | |
| 11 | ||
| 12 | iterated: Expressions.Expression? => expression | |
| 13 | ||
| 14 | read_iterator: Semantic.Symbols.Function? public => iterator_state.read_iterator, = value is iterator_state.read_iterator = value si | |
| 15 | read_current: Semantic.Symbols.Function? public => iterator_state.read_current, = value is iterator_state.read_current = value si | |
| 16 | move_next: Semantic.Symbols.Function? public => iterator_state.move_next, = value is iterator_state.move_next = value si | |
| 17 | ||
| 18 | iterator_field: Semantic.Symbols.Field? public => iterator_state.iterator_field, = value is iterator_state.iterator_field = value si | |
| 19 | ||
| 20 | iterator_state: Syntax.Process.ITERATOR_STATE field | |
| 21 | ||
| 22 | // Set by compile-expressions when the loop expression is a | |
| 23 | // fusible Pipe[T] chain: the IL pass then lowers the whole | |
| 24 | // chain to one inline loop instead of iterating the built pipe | |
| 25 | // objects. Null means iterate normally. See | |
| 26 | // Syntax.Process.PIPE_FUSION_RECOGNIZER. | |
| 27 | fusion: Syntax.Process.PIPE_FUSION? public => iterator_state.fusion, = value is iterator_state.fusion = value si | |
| 28 | ||
| 29 | // Pushed expected type from the wrapping context when the loop | |
| 30 | // is an expression; compile-expressions unwraps the optional and | |
| 31 | // threads it onto every valued break so they infer against T. | |
| 32 | expected_state: Syntax.Process.EXPECTED_TYPE_STATE field | |
| 33 | ||
| 34 | expected_type: Semantic.Types.Type? => expected_state.expected_type | |
| 35 | expected_type_error_message: string? => expected_state.expected_type_error_message | |
| 36 | ||
| 37 | set_expected_type(expected_type: Semantic.Types.Type?, error_message: string?) is | |
| 38 | expected_state.set(expected_type, error_message) | |
| 39 | si | |
| 40 | ||
| 41 | clear_expected_type() is | |
| 42 | expected_state.clear() | |
| 43 | si | |
| 44 | ||
| 45 | clear() is | |
| 46 | super.clear() | |
| 47 | expected_state.clear() | |
| 48 | iterator_state.clear() | |
| 49 | si | |
| 50 | ||
| 51 | clear_outputs() is | |
| 52 | super.clear_outputs() | |
| 53 | iterator_state.clear_outputs() | |
| 54 | si | |
| 55 | ||
| 56 | super(location) | |
| 57 | ||
| 58 | debug_location: LOCATION is | |
| 59 | if let self.expression? then | |
| 60 | return location.start_position :: expression.location | |
| 61 | fi | |
| 62 | ||
| 63 | return location.start_position | |
| 64 | si | |
| 65 | ||
| 66 | accept(visitor: Visitor) is | |
| 67 | visitor.visit(self) | |
| 68 | si | |
| 69 | ||
| 70 | walk(visitor: Visitor) is | |
| 71 | if !visitor.pre(self) then | |
| 72 | if variable? then | |
| 73 | variable.walk(visitor) | |
| 74 | fi | |
| 75 | ||
| 76 | if expression? then | |
| 77 | expression.walk(visitor) | |
| 78 | fi | |
| 79 | ||
| 80 | if body? then | |
| 81 | body.walk(visitor) | |
| 82 | fi | |
| 83 | fi | |
| 84 | ||
| 85 | accept(visitor) | |
| 86 | si | |
| 87 | si | |
| 88 | si |