| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // IrNodes are kept in a separate library to have precise control over their | 5 // IrNodes are kept in a separate library to have precise control over their |
| 6 // dependencies on other parts of the system. | 6 // dependencies on other parts of the system. |
| 7 library dart2js.ir_nodes; | 7 library dart2js.ir_nodes; |
| 8 | 8 |
| 9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
| 10 import '../constants/values.dart' as values show ConstantValue; | 10 import '../constants/values.dart' as values show ConstantValue; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 Expression plug(Expression expr) { | 147 Expression plug(Expression expr) { |
| 148 assert(continuations != null && | 148 assert(continuations != null && |
| 149 continuations.isNotEmpty && | 149 continuations.isNotEmpty && |
| 150 continuations.first.body == null); | 150 continuations.first.body == null); |
| 151 return continuations.first.body = expr; | 151 return continuations.first.body = expr; |
| 152 } | 152 } |
| 153 | 153 |
| 154 accept(Visitor visitor) => visitor.visitLetCont(this); | 154 accept(Visitor visitor) => visitor.visitLetCont(this); |
| 155 } | 155 } |
| 156 | 156 |
| 157 // Binding an exception handler. |
| 158 // |
| 159 // let handler h(v0, v1) = E0 in E1 |
| 160 // |
| 161 // The handler is a two-argument (exception, stack trace) continuation which |
| 162 // is implicitly the error continuation of all the code in its body E1. |
| 163 // [LetHandler] differs from a [LetCont] binding in that it (1) has the |
| 164 // runtime semantics of pushing/popping a handler from the dynamic exception |
| 165 // handler stack and (2) it does not have any explicit invocations. |
| 166 class LetHandler extends Expression implements InteriorNode { |
| 167 Continuation handler; |
| 168 Expression body; |
| 169 |
| 170 LetHandler(this.handler, this.body); |
| 171 |
| 172 accept(Visitor visitor) => visitor.visitLetHandler(this); |
| 173 } |
| 174 |
| 157 /// Binding mutable variables. | 175 /// Binding mutable variables. |
| 158 /// | 176 /// |
| 159 /// let mutable v = P in E | 177 /// let mutable v = P in E |
| 160 /// | 178 /// |
| 161 /// [MutableVariable]s can be seen as ref cells that are not first-class | 179 /// [MutableVariable]s can be seen as ref cells that are not first-class |
| 162 /// values. They are therefore not [Primitive]s and not bound by [LetPrim] | 180 /// values. They are therefore not [Primitive]s and not bound by [LetPrim] |
| 163 /// to prevent unrestricted use of references to them. During one-pass | 181 /// to prevent unrestricted use of references to them. During one-pass |
| 164 /// construction, a [LetMutable] with an empty body is use to represent the | 182 /// construction, a [LetMutable] with an empty body is use to represent the |
| 165 /// one-hole context 'let mutable v = P in []'. | 183 /// one-hole context 'let mutable v = P in []'. |
| 166 class LetMutable extends Expression implements InteriorNode { | 184 class LetMutable extends Expression implements InteriorNode { |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 } | 884 } |
| 867 | 885 |
| 868 // Initializers | 886 // Initializers |
| 869 T visitInitializer(Initializer node) => visitNode(node); | 887 T visitInitializer(Initializer node) => visitNode(node); |
| 870 T visitFieldInitializer(FieldInitializer node) => visitInitializer(node); | 888 T visitFieldInitializer(FieldInitializer node) => visitInitializer(node); |
| 871 T visitSuperInitializer(SuperInitializer node) => visitInitializer(node); | 889 T visitSuperInitializer(SuperInitializer node) => visitInitializer(node); |
| 872 | 890 |
| 873 // Expressions. | 891 // Expressions. |
| 874 T visitLetPrim(LetPrim node) => visitExpression(node); | 892 T visitLetPrim(LetPrim node) => visitExpression(node); |
| 875 T visitLetCont(LetCont node) => visitExpression(node); | 893 T visitLetCont(LetCont node) => visitExpression(node); |
| 894 T visitLetHandler(LetHandler node) => visitExpression(node); |
| 876 T visitLetMutable(LetMutable node) => visitExpression(node); | 895 T visitLetMutable(LetMutable node) => visitExpression(node); |
| 877 T visitInvokeStatic(InvokeStatic node) => visitExpression(node); | 896 T visitInvokeStatic(InvokeStatic node) => visitExpression(node); |
| 878 T visitInvokeContinuation(InvokeContinuation node) => visitExpression(node); | 897 T visitInvokeContinuation(InvokeContinuation node) => visitExpression(node); |
| 879 T visitInvokeMethod(InvokeMethod node) => visitExpression(node); | 898 T visitInvokeMethod(InvokeMethod node) => visitExpression(node); |
| 880 T visitInvokeMethodDirectly(InvokeMethodDirectly node) => visitExpression(node
); | 899 T visitInvokeMethodDirectly(InvokeMethodDirectly node) => visitExpression(node
); |
| 881 T visitInvokeConstructor(InvokeConstructor node) => visitExpression(node); | 900 T visitInvokeConstructor(InvokeConstructor node) => visitExpression(node); |
| 882 T visitConcatenateStrings(ConcatenateStrings node) => visitExpression(node); | 901 T visitConcatenateStrings(ConcatenateStrings node) => visitExpression(node); |
| 883 T visitBranch(Branch node) => visitExpression(node); | 902 T visitBranch(Branch node) => visitExpression(node); |
| 884 T visitTypeOperator(TypeOperator node) => visitExpression(node); | 903 T visitTypeOperator(TypeOperator node) => visitExpression(node); |
| 885 T visitSetMutableVariable(SetMutableVariable node) => visitExpression(node); | 904 T visitSetMutableVariable(SetMutableVariable node) => visitExpression(node); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 visit(node.body); | 997 visit(node.body); |
| 979 } | 998 } |
| 980 | 999 |
| 981 processLetCont(LetCont node) {} | 1000 processLetCont(LetCont node) {} |
| 982 visitLetCont(LetCont node) { | 1001 visitLetCont(LetCont node) { |
| 983 processLetCont(node); | 1002 processLetCont(node); |
| 984 node.continuations.forEach(visit); | 1003 node.continuations.forEach(visit); |
| 985 visit(node.body); | 1004 visit(node.body); |
| 986 } | 1005 } |
| 987 | 1006 |
| 1007 processLetHandler(LetHandler node) {} |
| 1008 visitLetHandler(LetHandler node) { |
| 1009 processLetHandler(node); |
| 1010 visit(node.handler); |
| 1011 visit(node.body); |
| 1012 } |
| 1013 |
| 988 processLetMutable(LetMutable node) {} | 1014 processLetMutable(LetMutable node) {} |
| 989 visitLetMutable(LetMutable node) { | 1015 visitLetMutable(LetMutable node) { |
| 990 processLetMutable(node); | 1016 processLetMutable(node); |
| 991 visit(node.variable); | 1017 visit(node.variable); |
| 992 processReference(node.value); | 1018 processReference(node.value); |
| 993 visit(node.body); | 1019 visit(node.body); |
| 994 } | 1020 } |
| 995 | 1021 |
| 996 processInvokeStatic(InvokeStatic node) {} | 1022 processInvokeStatic(InvokeStatic node) {} |
| 997 visitInvokeStatic(InvokeStatic node) { | 1023 visitInvokeStatic(InvokeStatic node) { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 visit(node.body); | 1298 visit(node.body); |
| 1273 release(node.primitive); | 1299 release(node.primitive); |
| 1274 visit(node.primitive); | 1300 visit(node.primitive); |
| 1275 } | 1301 } |
| 1276 | 1302 |
| 1277 void visitLetCont(LetCont node) { | 1303 void visitLetCont(LetCont node) { |
| 1278 node.continuations.forEach(visit); | 1304 node.continuations.forEach(visit); |
| 1279 visit(node.body); | 1305 visit(node.body); |
| 1280 } | 1306 } |
| 1281 | 1307 |
| 1308 void visitLetHandler(LetHandler node) { |
| 1309 visit(node.handler); |
| 1310 // Handler parameters that were not used in the handler body will not have |
| 1311 // had register indexes assigned. Assign them here, otherwise they will |
| 1312 // be eliminated later and they should not be (i.e., a catch clause that |
| 1313 // does not use the exception parameter should not have the exception |
| 1314 // parameter eliminated, because it would not be well-formed anymore). |
| 1315 // In any case release the parameter indexes because the parameters are |
| 1316 // not live in the try block. |
| 1317 node.handler.parameters.forEach((Parameter parameter) { |
| 1318 allocate(parameter); |
| 1319 release(parameter); |
| 1320 }); |
| 1321 visit(node.body); |
| 1322 } |
| 1323 |
| 1282 void visitLetMutable(LetMutable node) { | 1324 void visitLetMutable(LetMutable node) { |
| 1283 visit(node.body); | 1325 visit(node.body); |
| 1284 visitReference(node.value); | 1326 visitReference(node.value); |
| 1285 } | 1327 } |
| 1286 | 1328 |
| 1287 void visitInvokeStatic(InvokeStatic node) { | 1329 void visitInvokeStatic(InvokeStatic node) { |
| 1288 node.arguments.forEach(visitReference); | 1330 node.arguments.forEach(visitReference); |
| 1289 } | 1331 } |
| 1290 | 1332 |
| 1291 void visitInvokeContinuation(InvokeContinuation node) { | 1333 void visitInvokeContinuation(InvokeContinuation node) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 | 1437 |
| 1396 void visitIdentical(Identical node) { | 1438 void visitIdentical(Identical node) { |
| 1397 visitReference(node.left); | 1439 visitReference(node.left); |
| 1398 visitReference(node.right); | 1440 visitReference(node.right); |
| 1399 } | 1441 } |
| 1400 | 1442 |
| 1401 void visitInterceptor(Interceptor node) { | 1443 void visitInterceptor(Interceptor node) { |
| 1402 visitReference(node.input); | 1444 visitReference(node.input); |
| 1403 } | 1445 } |
| 1404 } | 1446 } |
| OLD | NEW |