| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 arguments = _referenceList(args) { | 190 arguments = _referenceList(args) { |
| 191 assert(target is ErroneousElement || selector.name == target.name); | 191 assert(target is ErroneousElement || selector.name == target.name); |
| 192 } | 192 } |
| 193 | 193 |
| 194 accept(Visitor visitor) => visitor.visitInvokeStatic(this); | 194 accept(Visitor visitor) => visitor.visitInvokeStatic(this); |
| 195 } | 195 } |
| 196 | 196 |
| 197 /// Invoke a method, operator, getter, setter, or index getter/setter. | 197 /// Invoke a method, operator, getter, setter, or index getter/setter. |
| 198 /// Converting a method to a function object is treated as a getter invocation. | 198 /// Converting a method to a function object is treated as a getter invocation. |
| 199 class InvokeMethod extends Expression implements Invoke { | 199 class InvokeMethod extends Expression implements Invoke { |
| 200 final Reference<Primitive> receiver; | 200 Reference<Primitive> receiver; |
| 201 final Selector selector; | 201 final Selector selector; |
| 202 final Reference<Continuation> continuation; | 202 final Reference<Continuation> continuation; |
| 203 final List<Reference<Primitive>> arguments; | 203 final List<Reference<Primitive>> arguments; |
| 204 | 204 |
| 205 InvokeMethod(Primitive receiver, | 205 InvokeMethod(Primitive receiver, |
| 206 Selector selector, | 206 Selector selector, |
| 207 Continuation cont, | 207 Continuation cont, |
| 208 List<Primitive> args) | 208 List<Primitive> args) |
| 209 : this.internal(new Reference<Primitive>(receiver), | 209 : this.internal(new Reference<Primitive>(receiver), |
| 210 selector, | 210 selector, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 222 (selector.kind == SelectorKind.SETTER && arguments.length == 1) || | 222 (selector.kind == SelectorKind.SETTER && arguments.length == 1) || |
| 223 (selector.kind == SelectorKind.INDEX && arguments.length == 1) || | 223 (selector.kind == SelectorKind.INDEX && arguments.length == 1) || |
| 224 (selector.kind == SelectorKind.INDEX && arguments.length == 2)); | 224 (selector.kind == SelectorKind.INDEX && arguments.length == 2)); |
| 225 } | 225 } |
| 226 | 226 |
| 227 bool get isIntercepted => receiver.definition is Interceptor; | 227 bool get isIntercepted => receiver.definition is Interceptor; |
| 228 | 228 |
| 229 accept(Visitor visitor) => visitor.visitInvokeMethod(this); | 229 accept(Visitor visitor) => visitor.visitInvokeMethod(this); |
| 230 } | 230 } |
| 231 | 231 |
| 232 /// Invoke a method, operator, getter, setter, or index getter/setter from the | 232 /// Invoke [target] on [receiver], bypassing dispatch and override semantics. |
| 233 /// super class in tail position. | 233 /// |
| 234 class InvokeSuperMethod extends Expression implements Invoke { | 234 /// That is, if [receiver] is an instance of a class that overrides [target] |
| 235 /// with a different implementation, the overriding implementation is bypassed |
| 236 /// and [target]'s implementation is invoked. |
| 237 /// |
| 238 /// As with [InvokeMethod], this can be used to invoke a method, operator, |
| 239 /// getter, setter, or index getter/setter. |
| 240 /// |
| 241 /// If it is known that [target] does not use its receiver argument, then |
| 242 /// [receiver] may refer to a null constant primitive. This happens for direct |
| 243 /// invocations to intercepted methods, where the effective receiver is instead |
| 244 /// passed as a formal parameter. |
| 245 /// |
| 246 /// When targeting Dart, this instruction is used to represent super calls. |
| 247 /// Here, [receiver] must always be a reference to `this`, and [target] must be |
| 248 /// a method that is available in the super class. |
| 249 class InvokeMethodDirectly extends Expression implements Invoke { |
| 250 Reference<Primitive> receiver; |
| 251 final Element target; |
| 235 final Selector selector; | 252 final Selector selector; |
| 236 final Reference<Continuation> continuation; | 253 final Reference<Continuation> continuation; |
| 237 final List<Reference<Primitive>> arguments; | 254 final List<Reference<Primitive>> arguments; |
| 238 | 255 |
| 239 InvokeSuperMethod(this.selector, | 256 InvokeMethodDirectly(Primitive receiver, |
| 240 Continuation cont, | 257 this.target, |
| 241 List<Primitive> args) | 258 this.selector, |
| 242 : continuation = new Reference<Continuation>(cont), | 259 Continuation cont, |
| 260 List<Primitive> args) |
| 261 : this.receiver = new Reference<Primitive>(receiver), |
| 262 continuation = new Reference<Continuation>(cont), |
| 243 arguments = _referenceList(args) { | 263 arguments = _referenceList(args) { |
| 244 assert(selector != null); | 264 assert(selector != null); |
| 245 assert(selector.kind == SelectorKind.CALL || | 265 assert(selector.kind == SelectorKind.CALL || |
| 246 selector.kind == SelectorKind.OPERATOR || | 266 selector.kind == SelectorKind.OPERATOR || |
| 247 (selector.kind == SelectorKind.GETTER && arguments.isEmpty) || | 267 (selector.kind == SelectorKind.GETTER && arguments.isEmpty) || |
| 248 (selector.kind == SelectorKind.SETTER && arguments.length == 1) || | 268 (selector.kind == SelectorKind.SETTER && arguments.length == 1) || |
| 249 (selector.kind == SelectorKind.INDEX && arguments.length == 1) || | 269 (selector.kind == SelectorKind.INDEX && arguments.length == 1) || |
| 250 (selector.kind == SelectorKind.INDEX && arguments.length == 2)); | 270 (selector.kind == SelectorKind.INDEX && arguments.length == 2)); |
| 251 } | 271 } |
| 252 | 272 |
| 253 accept(Visitor visitor) => visitor.visitInvokeSuperMethod(this); | 273 accept(Visitor visitor) => visitor.visitInvokeMethodDirectly(this); |
| 254 } | 274 } |
| 255 | 275 |
| 256 /// Non-const call to a constructor. The [target] may be a generative | 276 /// Non-const call to a constructor. The [target] may be a generative |
| 257 /// constructor, factory, or redirecting factory. | 277 /// constructor, factory, or redirecting factory. |
| 258 class InvokeConstructor extends Expression implements Invoke { | 278 class InvokeConstructor extends Expression implements Invoke { |
| 259 final DartType type; | 279 final DartType type; |
| 260 final FunctionElement target; | 280 final FunctionElement target; |
| 261 final Reference<Continuation> continuation; | 281 final Reference<Continuation> continuation; |
| 262 final List<Reference<Primitive>> arguments; | 282 final List<Reference<Primitive>> arguments; |
| 263 final Selector selector; | 283 final Selector selector; |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 T visitInitializer(Initializer node) => visitNode(node); | 824 T visitInitializer(Initializer node) => visitNode(node); |
| 805 T visitFieldInitializer(FieldInitializer node) => visitInitializer(node); | 825 T visitFieldInitializer(FieldInitializer node) => visitInitializer(node); |
| 806 T visitSuperInitializer(SuperInitializer node) => visitInitializer(node); | 826 T visitSuperInitializer(SuperInitializer node) => visitInitializer(node); |
| 807 | 827 |
| 808 // Expressions. | 828 // Expressions. |
| 809 T visitLetPrim(LetPrim node) => visitExpression(node); | 829 T visitLetPrim(LetPrim node) => visitExpression(node); |
| 810 T visitLetCont(LetCont node) => visitExpression(node); | 830 T visitLetCont(LetCont node) => visitExpression(node); |
| 811 T visitInvokeStatic(InvokeStatic node) => visitExpression(node); | 831 T visitInvokeStatic(InvokeStatic node) => visitExpression(node); |
| 812 T visitInvokeContinuation(InvokeContinuation node) => visitExpression(node); | 832 T visitInvokeContinuation(InvokeContinuation node) => visitExpression(node); |
| 813 T visitInvokeMethod(InvokeMethod node) => visitExpression(node); | 833 T visitInvokeMethod(InvokeMethod node) => visitExpression(node); |
| 814 T visitInvokeSuperMethod(InvokeSuperMethod node) => visitExpression(node); | 834 T visitInvokeMethodDirectly(InvokeMethodDirectly node) => visitExpression(node
); |
| 815 T visitInvokeConstructor(InvokeConstructor node) => visitExpression(node); | 835 T visitInvokeConstructor(InvokeConstructor node) => visitExpression(node); |
| 816 T visitConcatenateStrings(ConcatenateStrings node) => visitExpression(node); | 836 T visitConcatenateStrings(ConcatenateStrings node) => visitExpression(node); |
| 817 T visitBranch(Branch node) => visitExpression(node); | 837 T visitBranch(Branch node) => visitExpression(node); |
| 818 T visitTypeOperator(TypeOperator node) => visitExpression(node); | 838 T visitTypeOperator(TypeOperator node) => visitExpression(node); |
| 819 T visitSetClosureVariable(SetClosureVariable node) => visitExpression(node); | 839 T visitSetClosureVariable(SetClosureVariable node) => visitExpression(node); |
| 820 T visitDeclareFunction(DeclareFunction node) => visitExpression(node); | 840 T visitDeclareFunction(DeclareFunction node) => visitExpression(node); |
| 821 T visitSetField(SetField node) => visitExpression(node); | 841 T visitSetField(SetField node) => visitExpression(node); |
| 822 | 842 |
| 823 // Definitions. | 843 // Definitions. |
| 824 T visitLiteralList(LiteralList node) => visitPrimitive(node); | 844 T visitLiteralList(LiteralList node) => visitPrimitive(node); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 } | 953 } |
| 934 | 954 |
| 935 processInvokeMethod(InvokeMethod node) {} | 955 processInvokeMethod(InvokeMethod node) {} |
| 936 visitInvokeMethod(InvokeMethod node) { | 956 visitInvokeMethod(InvokeMethod node) { |
| 937 processInvokeMethod(node); | 957 processInvokeMethod(node); |
| 938 processReference(node.receiver); | 958 processReference(node.receiver); |
| 939 processReference(node.continuation); | 959 processReference(node.continuation); |
| 940 node.arguments.forEach(processReference); | 960 node.arguments.forEach(processReference); |
| 941 } | 961 } |
| 942 | 962 |
| 943 processInvokeSuperMethod(InvokeSuperMethod node) {} | 963 processInvokeMethodDirectly(InvokeMethodDirectly node) {} |
| 944 visitInvokeSuperMethod(InvokeSuperMethod node) { | 964 visitInvokeMethodDirectly(InvokeMethodDirectly node) { |
| 945 processInvokeSuperMethod(node); | 965 processInvokeMethodDirectly(node); |
| 966 processReference(node.receiver); |
| 946 processReference(node.continuation); | 967 processReference(node.continuation); |
| 947 node.arguments.forEach(processReference); | 968 node.arguments.forEach(processReference); |
| 948 } | 969 } |
| 949 | 970 |
| 950 processInvokeConstructor(InvokeConstructor node) {} | 971 processInvokeConstructor(InvokeConstructor node) {} |
| 951 visitInvokeConstructor(InvokeConstructor node) { | 972 visitInvokeConstructor(InvokeConstructor node) { |
| 952 processInvokeConstructor(node); | 973 processInvokeConstructor(node); |
| 953 processReference(node.continuation); | 974 processReference(node.continuation); |
| 954 node.arguments.forEach(processReference); | 975 node.arguments.forEach(processReference); |
| 955 } | 976 } |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 | 1228 |
| 1208 void visitInvokeContinuation(InvokeContinuation node) { | 1229 void visitInvokeContinuation(InvokeContinuation node) { |
| 1209 node.arguments.forEach(visitReference); | 1230 node.arguments.forEach(visitReference); |
| 1210 } | 1231 } |
| 1211 | 1232 |
| 1212 void visitInvokeMethod(InvokeMethod node) { | 1233 void visitInvokeMethod(InvokeMethod node) { |
| 1213 visitReference(node.receiver); | 1234 visitReference(node.receiver); |
| 1214 node.arguments.forEach(visitReference); | 1235 node.arguments.forEach(visitReference); |
| 1215 } | 1236 } |
| 1216 | 1237 |
| 1217 void visitInvokeSuperMethod(InvokeSuperMethod node) { | 1238 void visitInvokeMethodDirectly(InvokeMethodDirectly node) { |
| 1239 visitReference(node.receiver); |
| 1218 node.arguments.forEach(visitReference); | 1240 node.arguments.forEach(visitReference); |
| 1219 } | 1241 } |
| 1220 | 1242 |
| 1221 void visitInvokeConstructor(InvokeConstructor node) { | 1243 void visitInvokeConstructor(InvokeConstructor node) { |
| 1222 node.arguments.forEach(visitReference); | 1244 node.arguments.forEach(visitReference); |
| 1223 } | 1245 } |
| 1224 | 1246 |
| 1225 void visitConcatenateStrings(ConcatenateStrings node) { | 1247 void visitConcatenateStrings(ConcatenateStrings node) { |
| 1226 node.arguments.forEach(visitReference); | 1248 node.arguments.forEach(visitReference); |
| 1227 } | 1249 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 | 1333 |
| 1312 void visitIdentical(Identical node) { | 1334 void visitIdentical(Identical node) { |
| 1313 visitReference(node.left); | 1335 visitReference(node.left); |
| 1314 visitReference(node.right); | 1336 visitReference(node.right); |
| 1315 } | 1337 } |
| 1316 | 1338 |
| 1317 void visitInterceptor(Interceptor node) { | 1339 void visitInterceptor(Interceptor node) { |
| 1318 visitReference(node.input); | 1340 visitReference(node.input); |
| 1319 } | 1341 } |
| 1320 } | 1342 } |
| OLD | NEW |