Appearance
| 1 | namespace Syntax.Trees.Statements is | |
| 2 | use Source; | |
| 3 | ||
| 4 | use Logging; | |
| 5 | ||
| 6 | use Ghul.Pipes; | |
| 7 | ||
| 8 | class IF: Statement is | |
| 9 | branches: Collections.Iterable[IF_BRANCH]; | |
| 10 | provides_value: bool => true; | |
| 11 | // Expected-type constraint pushed down by compile-expressions. | |
| 12 | branch_state: Syntax.Process.EXPECTED_TYPE_STATE field; | |
| 13 | ||
| 14 | expected_type: Semantic.Types.Type? => branch_state.expected_type; | |
| 15 | expected_type_error_message: string? => branch_state.expected_type_error_message; | |
| 16 | ||
| 17 | is_tuple_literal: bool => | |
| 18 | if branches |> all(b => b.body.is_tuple_literal) then | |
| 19 | true | |
| 20 | else | |
| 21 | false | |
| 22 | fi; | |
| 23 | ||
| 24 | init(location: LOCATION, branches: Collections.Iterable[IF_BRANCH]) is | |
| 25 | super.init(location); | |
| 26 | ||
| 27 | self.branches = Collections.LIST(branches); | |
| 28 | si | |
| 29 | ||
| 30 | set_expected_type(expected_type: Semantic.Types.Type?, error_message: string?) is | |
| 31 | branch_state.set(expected_type, error_message); | |
| 32 | ||
| 33 | for b in branches do | |
| 34 | b.body.set_expected_type(expected_type, error_message); | |
| 35 | od | |
| 36 | si | |
| 37 | ||
| 38 | clear() is | |
| 39 | super.clear(); | |
| 40 | branch_state.clear(); | |
| 41 | si | |
| 42 | ||
| 43 | clear_expected_type() is | |
| 44 | branch_state.clear(); | |
| 45 | si | |
| 46 | ||
| 47 | accept(visitor: Visitor) is | |
| 48 | visitor.visit(self); | |
| 49 | si | |
| 50 | ||
| 51 | walk(visitor: Visitor) is | |
| 52 | if !visitor.pre(self) then | |
| 53 | for branch in branches do | |
| 54 | branch.walk(visitor); | |
| 55 | od | |
| 56 | fi | |
| 57 | ||
| 58 | accept(visitor); | |
| 59 | si | |
| 60 | si | |
| 61 | ||
| 62 | class IF_BRANCH: Trees.Node, ScopeCarrier is | |
| 63 | scope: Semantic.Scope? public; | |
| 64 | ||
| 65 | condition: Expressions.Expression?; | |
| 66 | binding: REFUTABLE_BINDING?; | |
| 67 | body: LIST; | |
| 68 | ||
| 69 | init( | |
| 70 | location: LOCATION, | |
| 71 | condition: Expressions.Expression?, | |
| 72 | body: LIST | |
| 73 | ) | |
| 74 | is | |
| 75 | init(location, condition, null, body); | |
| 76 | si | |
| 77 | ||
| 78 | init( | |
| 79 | location: LOCATION, | |
| 80 | condition: Expressions.Expression?, | |
| 81 | binding: REFUTABLE_BINDING?, | |
| 82 | body: LIST | |
| 83 | ) | |
| 84 | is | |
| 85 | super.init(location); | |
| 86 | ||
| 87 | self.condition = condition; | |
| 88 | self.binding = binding; | |
| 89 | self.body = body; | |
| 90 | si | |
| 91 | ||
| 92 | accept(visitor: Visitor) is | |
| 93 | visitor.visit(self); | |
| 94 | si | |
| 95 | ||
| 96 | walk(visitor: Visitor) is | |
| 97 | if !visitor.pre(self) then | |
| 98 | if let self.condition? then | |
| 99 | condition.walk(visitor); | |
| 100 | fi | |
| 101 | ||
| 102 | if let self.binding? then | |
| 103 | binding.walk(visitor); | |
| 104 | fi | |
| 105 | ||
| 106 | body.walk(visitor); | |
| 107 | fi | |
| 108 | ||
| 109 | accept(visitor); | |
| 110 | si | |
| 111 | si | |
| 112 | si |