| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /// Visitor of the simplified expression syntax tree. | |
| 6 library summary.src.visitor; | |
| 7 | |
| 8 import 'expressions.dart'; | |
| 9 | |
| 10 /// Post-order recursive visitor. | |
| 11 /// | |
| 12 /// Will invoke `handle*` methods in post order (children first, parents | |
| 13 /// afterwards). | |
| 14 class RecursiveVisitor extends Visitor { | |
| 15 visitAs(As n) { | |
| 16 n.exp.accept(this); | |
| 17 handleAs(n); | |
| 18 } | |
| 19 | |
| 20 visitBinary(Binary n) { | |
| 21 n.left.accept(this); | |
| 22 n.right.accept(this); | |
| 23 handleBinary(n); | |
| 24 } | |
| 25 | |
| 26 visitConditional(Conditional n) { | |
| 27 n.test.accept(this); | |
| 28 n.trueBranch.accept(this); | |
| 29 n.falseBranch.accept(this); | |
| 30 handleConditional(n); | |
| 31 } | |
| 32 | |
| 33 visitConstCreation(ConstCreation n) { | |
| 34 for (var arg in n.positionalArgs) { | |
| 35 arg.accept(this); | |
| 36 } | |
| 37 for (var arg in n.namedArgs) { | |
| 38 arg.value.accept(this); | |
| 39 } | |
| 40 handleConstCreation(n); | |
| 41 } | |
| 42 | |
| 43 visitIdentical(Identical n) { | |
| 44 n.left.accept(this); | |
| 45 n.right.accept(this); | |
| 46 handleIdentical(n); | |
| 47 } | |
| 48 | |
| 49 visitIs(Is n) { | |
| 50 n.exp.accept(this); | |
| 51 handleIs(n); | |
| 52 } | |
| 53 | |
| 54 visitList(ListLiteral n) { | |
| 55 for (var v in n.values) { | |
| 56 v.accept(this); | |
| 57 } | |
| 58 handleList(n); | |
| 59 } | |
| 60 | |
| 61 visitLoad(Load n) { | |
| 62 n.left.accept(this); | |
| 63 handleLoad(n); | |
| 64 } | |
| 65 | |
| 66 visitMap(MapLiteral n) { | |
| 67 for (var v in n.values) { | |
| 68 v.key.accept(this); | |
| 69 v.value.accept(this); | |
| 70 } | |
| 71 handleMap(n); | |
| 72 } | |
| 73 | |
| 74 visitOpaqueOp(OpaqueOp n) { | |
| 75 n.exp.accept(this); | |
| 76 handleOpaqueOp(n); | |
| 77 } | |
| 78 | |
| 79 visitUnary(Unary n) { | |
| 80 n.exp.accept(this); | |
| 81 handleUnary(n); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 /// Plain non-recursive visitor. | |
| 86 class Visitor { | |
| 87 // References | |
| 88 | |
| 89 handleAs(As n) {} | |
| 90 handleBinary(Binary n) {} | |
| 91 | |
| 92 // Literals | |
| 93 | |
| 94 handleBool(BoolLiteral n) {} | |
| 95 handleConditional(Conditional n) {} | |
| 96 handleConstCreation(ConstCreation n) {} | |
| 97 handleDouble(DoubleLiteral n) {} | |
| 98 handleIdentical(Identical n) {} | |
| 99 handleInt(IntLiteral n) {} | |
| 100 handleInvalid(Invalid n) {} | |
| 101 handleIs(Is n) {} | |
| 102 | |
| 103 handleList(ListLiteral n) {} | |
| 104 handleLoad(Load n) {} | |
| 105 handleMap(MapLiteral n) {} | |
| 106 handleNull(NullLiteral n) {} | |
| 107 handleOpaque(Opaque n) {} | |
| 108 handleOpaqueOp(OpaqueOp n) {} | |
| 109 handleRef(Ref n) {} | |
| 110 handleString(StringLiteral n) {} | |
| 111 | |
| 112 // Compound expressions | |
| 113 | |
| 114 handleSymbol(SymbolLiteral n) {} | |
| 115 handleUnary(Unary n) {} | |
| 116 visitAs(As n) => handleAs(n); | |
| 117 visitBinary(Binary n) => handleBinary(n); | |
| 118 visitBool(BoolLiteral n) => handleBool(n); | |
| 119 visitConditional(Conditional n) => handleConditional(n); | |
| 120 visitConstCreation(ConstCreation n) => handleConstCreation(n); | |
| 121 visitDouble(DoubleLiteral n) => handleDouble(n); | |
| 122 | |
| 123 visitIdentical(Identical n) => handleIdentical(n); | |
| 124 visitInt(IntLiteral n) => handleInt(n); | |
| 125 visitInvalid(Invalid n) => handleInvalid(n); | |
| 126 visitIs(Is n) => handleIs(n); | |
| 127 visitList(ListLiteral n) => handleList(n); | |
| 128 visitLoad(Load n) => handleLoad(n); | |
| 129 visitMap(MapLiteral n) => handleMap(n); | |
| 130 visitNull(NullLiteral n) => handleNull(n); | |
| 131 | |
| 132 // Non-traditional expressions. | |
| 133 | |
| 134 visitOpaque(Opaque n) => handleOpaque(n); | |
| 135 visitOpaqueOp(OpaqueOp n) => handleOpaqueOp(n); | |
| 136 visitRef(Ref n) => handleRef(n); | |
| 137 | |
| 138 visitString(StringLiteral n) => handleString(n); | |
| 139 visitSymbol(SymbolLiteral n) => handleSymbol(n); | |
| 140 visitUnary(Unary n) => handleUnary(n); | |
| 141 } | |
| OLD | NEW |