| 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 SourceString name = isInterceptorClass | 286 SourceString name = isInterceptorClass |
| 282 ? const SourceString('receiver') | 287 ? const SourceString('receiver') |
| 283 : const SourceString('_'); | 288 : const SourceString('_'); |
| 284 Element parameter = new InterceptedElement( | 289 Element parameter = new InterceptedElement( |
| 285 cls.computeType(compiler), name, element); | 290 cls.computeType(compiler), name, element); |
| 286 HParameterValue value = new HParameterValue(parameter); | 291 HParameterValue value = new HParameterValue(parameter); |
| 287 builder.graph.explicitReceiverParameter = value; | 292 builder.graph.explicitReceiverParameter = value; |
| 288 builder.graph.entry.addAfter( | 293 builder.graph.entry.addAfter( |
| 289 directLocals[closureData.thisElement], value); | 294 directLocals[closureData.thisElement], value); |
| 290 if (isInterceptorClass) { | 295 if (isInterceptorClass) { |
| 291 // Only use the extra parameter in intercepted classes. | 296 // Only use the extra parameter in intercepted classes. |
| 292 directLocals[closureData.thisElement] = value; | 297 directLocals[closureData.thisElement] = value; |
| 293 } | 298 } |
| 294 value.instructionType = builder.getTypeOfThis(); | 299 value.instructionType = builder.getTypeOfThis(); |
| 295 } else if (isNativeUpgradeFactory) { | 300 } else if (isNativeUpgradeFactory) { |
| 296 bool isInterceptorClass = backend.isInterceptorClass(cls.declaration); | |
| 297 Element parameter = new InterceptedElement( | 301 Element parameter = new InterceptedElement( |
| 298 cls.computeType(compiler), const SourceString('receiver'), element); | 302 cls.computeType(compiler), const SourceString('receiver'), element); |
| 299 HParameterValue value = new HParameterValue(parameter); | 303 HParameterValue value = new HParameterValue(parameter); |
| 300 builder.graph.explicitReceiverParameter = value; | 304 builder.graph.explicitReceiverParameter = value; |
| 301 builder.graph.entry.addAtEntry(value); | 305 builder.graph.entry.addAtEntry(value); |
| 302 // Unlike `this`, receiver is nullable since direct calls to generative | 306 // Unlike `this`, receiver is nullable since direct calls to generative |
| 303 // constructor call the constructor with `null`. | 307 // constructor call the constructor with `null`. |
| 304 value.instructionType = new HType.exact(cls, compiler); | 308 value.instructionType = new HType.exact(cls, compiler); |
| 305 } | 309 } |
| 306 } | 310 } |
| (...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1608 classElement.forEachInstanceField( | 1612 classElement.forEachInstanceField( |
| 1609 (ClassElement enclosingClass, Element member) { | 1613 (ClassElement enclosingClass, Element member) { |
| 1610 compiler.withCurrentElement(member, () { | 1614 compiler.withCurrentElement(member, () { |
| 1611 TreeElements definitions = compiler.analyzeElement(member); | 1615 TreeElements definitions = compiler.analyzeElement(member); |
| 1612 Node node = member.parseNode(compiler); | 1616 Node node = member.parseNode(compiler); |
| 1613 SendSet assignment = node.asSendSet(); | 1617 SendSet assignment = node.asSendSet(); |
| 1614 if (assignment == null) { | 1618 if (assignment == null) { |
| 1615 // Unassigned fields of native classes are not initialized to | 1619 // Unassigned fields of native classes are not initialized to |
| 1616 // prevent overwriting pre-initialized native properties. | 1620 // prevent overwriting pre-initialized native properties. |
| 1617 if (!Elements.isNativeOrExtendsNative(classElement)) { | 1621 if (!Elements.isNativeOrExtendsNative(classElement)) { |
| 1618 HInstruction value = graph.addConstantNull(compiler); | 1622 fieldValues[member] = graph.addConstantNull(compiler); |
| 1619 fieldValues[member] = value; | |
| 1620 } | 1623 } |
| 1621 } else { | 1624 } else { |
| 1622 Node right = assignment.arguments.head; | 1625 Node right = assignment.arguments.head; |
| 1623 TreeElements savedElements = elements; | 1626 TreeElements savedElements = elements; |
| 1624 elements = definitions; | 1627 elements = definitions; |
| 1625 // In case the field initializer uses closures, run the | 1628 // In case the field initializer uses closures, run the |
| 1626 // closure to class mapper. | 1629 // closure to class mapper. |
| 1627 compiler.closureToClassMapper.computeClosureToClassMapping( | 1630 compiler.closureToClassMapper.computeClosureToClassMapping( |
| 1628 member, node, elements); | 1631 member, node, elements); |
| 1629 inlinedFrom(member, () => right.accept(this)); | 1632 inlinedFrom(member, () => right.accept(this)); |
| 1630 elements = savedElements; | 1633 elements = savedElements; |
| 1631 HInstruction value = pop(); | 1634 fieldValues[member] = pop(); |
| 1632 fieldValues[member] = value; | |
| 1633 } | 1635 } |
| 1634 }); | 1636 }); |
| 1635 }); | 1637 }); |
| 1636 } | 1638 } |
| 1637 | 1639 |
| 1638 /** | 1640 /** |
| 1639 * Build the factory function corresponding to the constructor | 1641 * Build the factory function corresponding to the constructor |
| 1640 * [functionElement]: | 1642 * [functionElement]: |
| 1641 * - Initialize fields with the values of the field initializers of the | 1643 * - Initialize fields with the values of the field initializers of the |
| 1642 * current constructor and super constructors or constructors redirected | 1644 * current constructor and super constructors or constructors redirected |
| (...skipping 3948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5591 new HSubGraphBlockInformation(elseBranch.graph)); | 5593 new HSubGraphBlockInformation(elseBranch.graph)); |
| 5592 | 5594 |
| 5593 HBasicBlock conditionStartBlock = conditionBranch.block; | 5595 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 5594 conditionStartBlock.setBlockFlow(info, joinBlock); | 5596 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 5595 SubGraph conditionGraph = conditionBranch.graph; | 5597 SubGraph conditionGraph = conditionBranch.graph; |
| 5596 HIf branch = conditionGraph.end.last; | 5598 HIf branch = conditionGraph.end.last; |
| 5597 assert(branch is HIf); | 5599 assert(branch is HIf); |
| 5598 branch.blockInformation = conditionStartBlock.blockFlow; | 5600 branch.blockInformation = conditionStartBlock.blockFlow; |
| 5599 } | 5601 } |
| 5600 } | 5602 } |
| OLD | NEW |