OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of ssa; | 5 part of ssa; |
6 | 6 |
7 /** | 7 /** |
8 * A special element for the extra parameter taken by intercepted | 8 * A special element for the extra parameter taken by intercepted |
9 * methods. We need to override [Element.computeType] because our | 9 * methods. We need to override [Element.computeType] because our |
10 * optimizers may look at its declared type. | 10 * optimizers may look at its declared type. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 builder.graph.thisInstruction = thisInstruction; | 267 builder.graph.thisInstruction = thisInstruction; |
268 builder.graph.entry.addAtEntry(thisInstruction); | 268 builder.graph.entry.addAtEntry(thisInstruction); |
269 directLocals[closureData.thisElement] = thisInstruction; | 269 directLocals[closureData.thisElement] = thisInstruction; |
270 } | 270 } |
271 | 271 |
272 // If this method is an intercepted method, add the extra | 272 // If this method is an intercepted method, add the extra |
273 // parameter to it, that is the actual receiver for intercepted | 273 // parameter to it, that is the actual receiver for intercepted |
274 // classes, or the same as [:this:] for non-intercepted classes. | 274 // classes, or the same as [:this:] for non-intercepted classes. |
275 ClassElement cls = element.getEnclosingClass(); | 275 ClassElement cls = element.getEnclosingClass(); |
276 JavaScriptBackend backend = compiler.backend; | 276 JavaScriptBackend backend = compiler.backend; |
| 277 |
| 278 // When the class extends a native class, the instance is pre-constructed |
| 279 // and passed to the generative constructor factory function as a parameter. |
| 280 // Instead of allocating and initializing the object, the constructor |
| 281 // 'upgrades' the native subclass object by initializing the Dart fields. |
277 bool isNativeUpgradeFactory = element.isGenerativeConstructor() | 282 bool isNativeUpgradeFactory = element.isGenerativeConstructor() |
278 && Elements.isNativeOrExtendsNative(cls); | 283 && Elements.isNativeOrExtendsNative(cls); |
279 if (backend.isInterceptedMethod(element)) { | 284 if (backend.isInterceptedMethod(element)) { |
280 bool isInterceptorClass = backend.isInterceptorClass(cls.declaration); | 285 bool isInterceptorClass = backend.isInterceptorClass(cls.declaration); |
281 String name = isInterceptorClass ? 'receiver' : '_'; | 286 String name = isInterceptorClass ? 'receiver' : '_'; |
282 Element parameter = new InterceptedElement( | 287 Element parameter = new InterceptedElement( |
283 cls.computeType(compiler), name, element); | 288 cls.computeType(compiler), name, element); |
284 HParameterValue value = new HParameterValue(parameter); | 289 HParameterValue value = new HParameterValue(parameter); |
285 builder.graph.explicitReceiverParameter = value; | 290 builder.graph.explicitReceiverParameter = value; |
286 builder.graph.entry.addAfter( | 291 builder.graph.entry.addAfter( |
287 directLocals[closureData.thisElement], value); | 292 directLocals[closureData.thisElement], value); |
288 if (isInterceptorClass) { | 293 if (isInterceptorClass) { |
289 // Only use the extra parameter in intercepted classes. | 294 // Only use the extra parameter in intercepted classes. |
290 directLocals[closureData.thisElement] = value; | 295 directLocals[closureData.thisElement] = value; |
291 } | 296 } |
292 value.instructionType = builder.getTypeOfThis(); | 297 value.instructionType = builder.getTypeOfThis(); |
293 } else if (isNativeUpgradeFactory) { | 298 } else if (isNativeUpgradeFactory) { |
294 bool isInterceptorClass = backend.isInterceptorClass(cls.declaration); | |
295 Element parameter = new InterceptedElement( | 299 Element parameter = new InterceptedElement( |
296 cls.computeType(compiler), 'receiver', element); | 300 cls.computeType(compiler), 'receiver', element); |
297 HParameterValue value = new HParameterValue(parameter); | 301 HParameterValue value = new HParameterValue(parameter); |
298 builder.graph.explicitReceiverParameter = value; | 302 builder.graph.explicitReceiverParameter = value; |
299 builder.graph.entry.addAtEntry(value); | 303 builder.graph.entry.addAtEntry(value); |
300 // Unlike `this`, receiver is nullable since direct calls to generative | 304 // Unlike `this`, receiver is nullable since direct calls to generative |
301 // constructor call the constructor with `null`. | 305 // constructor call the constructor with `null`. |
302 value.instructionType = new HType.exact(cls, compiler); | 306 value.instructionType = new HType.exact(cls, compiler); |
303 } | 307 } |
304 } | 308 } |
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1606 classElement.forEachInstanceField( | 1610 classElement.forEachInstanceField( |
1607 (ClassElement enclosingClass, Element member) { | 1611 (ClassElement enclosingClass, Element member) { |
1608 compiler.withCurrentElement(member, () { | 1612 compiler.withCurrentElement(member, () { |
1609 TreeElements definitions = compiler.analyzeElement(member); | 1613 TreeElements definitions = compiler.analyzeElement(member); |
1610 Node node = member.parseNode(compiler); | 1614 Node node = member.parseNode(compiler); |
1611 SendSet assignment = node.asSendSet(); | 1615 SendSet assignment = node.asSendSet(); |
1612 if (assignment == null) { | 1616 if (assignment == null) { |
1613 // Unassigned fields of native classes are not initialized to | 1617 // Unassigned fields of native classes are not initialized to |
1614 // prevent overwriting pre-initialized native properties. | 1618 // prevent overwriting pre-initialized native properties. |
1615 if (!Elements.isNativeOrExtendsNative(classElement)) { | 1619 if (!Elements.isNativeOrExtendsNative(classElement)) { |
1616 HInstruction value = graph.addConstantNull(compiler); | 1620 fieldValues[member] = graph.addConstantNull(compiler); |
1617 fieldValues[member] = value; | |
1618 } | 1621 } |
1619 } else { | 1622 } else { |
1620 Node right = assignment.arguments.head; | 1623 Node right = assignment.arguments.head; |
1621 TreeElements savedElements = elements; | 1624 TreeElements savedElements = elements; |
1622 elements = definitions; | 1625 elements = definitions; |
1623 // In case the field initializer uses closures, run the | 1626 // In case the field initializer uses closures, run the |
1624 // closure to class mapper. | 1627 // closure to class mapper. |
1625 compiler.closureToClassMapper.computeClosureToClassMapping( | 1628 compiler.closureToClassMapper.computeClosureToClassMapping( |
1626 member, node, elements); | 1629 member, node, elements); |
1627 inlinedFrom(member, () => right.accept(this)); | 1630 inlinedFrom(member, () => right.accept(this)); |
1628 elements = savedElements; | 1631 elements = savedElements; |
1629 HInstruction value = pop(); | 1632 fieldValues[member] = pop(); |
1630 fieldValues[member] = value; | |
1631 } | 1633 } |
1632 }); | 1634 }); |
1633 }); | 1635 }); |
1634 } | 1636 } |
1635 | 1637 |
1636 /** | 1638 /** |
1637 * Build the factory function corresponding to the constructor | 1639 * Build the factory function corresponding to the constructor |
1638 * [functionElement]: | 1640 * [functionElement]: |
1639 * - Initialize fields with the values of the field initializers of the | 1641 * - Initialize fields with the values of the field initializers of the |
1640 * current constructor and super constructors or constructors redirected | 1642 * current constructor and super constructors or constructors redirected |
(...skipping 3945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5586 new HSubGraphBlockInformation(elseBranch.graph)); | 5588 new HSubGraphBlockInformation(elseBranch.graph)); |
5587 | 5589 |
5588 HBasicBlock conditionStartBlock = conditionBranch.block; | 5590 HBasicBlock conditionStartBlock = conditionBranch.block; |
5589 conditionStartBlock.setBlockFlow(info, joinBlock); | 5591 conditionStartBlock.setBlockFlow(info, joinBlock); |
5590 SubGraph conditionGraph = conditionBranch.graph; | 5592 SubGraph conditionGraph = conditionBranch.graph; |
5591 HIf branch = conditionGraph.end.last; | 5593 HIf branch = conditionGraph.end.last; |
5592 assert(branch is HIf); | 5594 assert(branch is HIf); |
5593 branch.blockInformation = conditionStartBlock.blockFlow; | 5595 branch.blockInformation = conditionStartBlock.blockFlow; |
5594 } | 5596 } |
5595 } | 5597 } |
OLD | NEW |