| 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 class SsaFunctionCompiler implements FunctionCompiler { | 7 class SsaFunctionCompiler implements FunctionCompiler { |
| 8 SsaCodeGeneratorTask generator; | 8 SsaCodeGeneratorTask generator; |
| 9 SsaBuilderTask builder; | 9 SsaBuilderTask builder; |
| 10 SsaOptimizerTask optimizer; | 10 SsaOptimizerTask optimizer; |
| (...skipping 1809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1820 HInstruction argument = localsHandler.readLocal(parameter); | 1820 HInstruction argument = localsHandler.readLocal(parameter); |
| 1821 potentiallyCheckOrTrustType(argument, parameter.type); | 1821 potentiallyCheckOrTrustType(argument, parameter.type); |
| 1822 }); | 1822 }); |
| 1823 } | 1823 } |
| 1824 | 1824 |
| 1825 /** | 1825 /** |
| 1826 * Documentation wanted -- johnniwinther | 1826 * Documentation wanted -- johnniwinther |
| 1827 * | 1827 * |
| 1828 * Invariant: [constructors] must contain only implementation elements. | 1828 * Invariant: [constructors] must contain only implementation elements. |
| 1829 */ | 1829 */ |
| 1830 void inlineSuperOrRedirect(FunctionElement callee, | 1830 void inlineSuperOrRedirect(ConstructorElement callee, |
| 1831 List<HInstruction> compiledArguments, | 1831 List<HInstruction> compiledArguments, |
| 1832 List<FunctionElement> constructors, | 1832 List<FunctionElement> constructors, |
| 1833 Map<Element, HInstruction> fieldValues, | 1833 Map<Element, HInstruction> fieldValues, |
| 1834 FunctionElement caller) { | 1834 FunctionElement caller) { |
| 1835 callee = callee.implementation; | 1835 callee = callee.implementation; |
| 1836 compiler.withCurrentElement(callee, () { | 1836 compiler.withCurrentElement(callee, () { |
| 1837 constructors.add(callee); | 1837 constructors.add(callee); |
| 1838 ClassElement enclosingClass = callee.enclosingClass; | 1838 ClassElement enclosingClass = callee.enclosingClass; |
| 1839 if (backend.classNeedsRti(enclosingClass)) { | 1839 if (backend.classNeedsRti(enclosingClass)) { |
| 1840 // If [enclosingClass] needs RTI, we have to give a value to its | 1840 // If [enclosingClass] needs RTI, we have to give a value to its |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1862 // If the supertype is a raw type, we need to set to null the | 1862 // If the supertype is a raw type, we need to set to null the |
| 1863 // type variables. | 1863 // type variables. |
| 1864 for (TypeVariableType variable in typeVariables) { | 1864 for (TypeVariableType variable in typeVariables) { |
| 1865 localsHandler.updateLocal( | 1865 localsHandler.updateLocal( |
| 1866 localsHandler.getTypeVariableAsLocal(variable), | 1866 localsHandler.getTypeVariableAsLocal(variable), |
| 1867 graph.addConstantNull(compiler)); | 1867 graph.addConstantNull(compiler)); |
| 1868 } | 1868 } |
| 1869 } | 1869 } |
| 1870 } | 1870 } |
| 1871 | 1871 |
| 1872 // For redirecting constructors, the fields have already been | 1872 // For redirecting constructors, the fields will be initialized later |
| 1873 // initialized by the caller. | 1873 // by the effective target. |
| 1874 if (callee.enclosingClass != caller.enclosingClass) { | 1874 if (!callee.isRedirectingGenerative) { |
| 1875 inlinedFrom(callee, () { | 1875 inlinedFrom(callee, () { |
| 1876 buildFieldInitializers(callee.enclosingElement.implementation, | 1876 buildFieldInitializers(callee.enclosingElement.implementation, |
| 1877 fieldValues); | 1877 fieldValues); |
| 1878 }); | 1878 }); |
| 1879 } | 1879 } |
| 1880 | 1880 |
| 1881 int index = 0; | 1881 int index = 0; |
| 1882 FunctionSignature params = callee.functionSignature; | 1882 FunctionSignature params = callee.functionSignature; |
| 1883 params.orderedForEachParameter((ParameterElement parameter) { | 1883 params.orderedForEachParameter((ParameterElement parameter) { |
| 1884 HInstruction argument = compiledArguments[index++]; | 1884 HInstruction argument = compiledArguments[index++]; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2067 | 2067 |
| 2068 /** | 2068 /** |
| 2069 * Build the factory function corresponding to the constructor | 2069 * Build the factory function corresponding to the constructor |
| 2070 * [functionElement]: | 2070 * [functionElement]: |
| 2071 * - Initialize fields with the values of the field initializers of the | 2071 * - Initialize fields with the values of the field initializers of the |
| 2072 * current constructor and super constructors or constructors redirected | 2072 * current constructor and super constructors or constructors redirected |
| 2073 * to, starting from the current constructor. | 2073 * to, starting from the current constructor. |
| 2074 * - Call the constructor bodies, starting from the constructor(s) in the | 2074 * - Call the constructor bodies, starting from the constructor(s) in the |
| 2075 * super class(es). | 2075 * super class(es). |
| 2076 */ | 2076 */ |
| 2077 HGraph buildFactory(FunctionElement functionElement) { | 2077 HGraph buildFactory(ConstructorElement functionElement) { |
| 2078 functionElement = functionElement.implementation; | 2078 functionElement = functionElement.implementation; |
| 2079 ClassElement classElement = | 2079 ClassElement classElement = |
| 2080 functionElement.enclosingClass.implementation; | 2080 functionElement.enclosingClass.implementation; |
| 2081 bool isNativeUpgradeFactory = | 2081 bool isNativeUpgradeFactory = |
| 2082 Elements.isNativeOrExtendsNative(classElement); | 2082 Elements.isNativeOrExtendsNative(classElement); |
| 2083 ast.FunctionExpression function = functionElement.node; | 2083 ast.FunctionExpression function = functionElement.node; |
| 2084 // Note that constructors (like any other static function) do not need | 2084 // Note that constructors (like any other static function) do not need |
| 2085 // to deal with optional arguments. It is the callers job to provide all | 2085 // to deal with optional arguments. It is the callers job to provide all |
| 2086 // arguments as if they were positional. | 2086 // arguments as if they were positional. |
| 2087 | 2087 |
| 2088 if (inliningStack.isEmpty) { | 2088 if (inliningStack.isEmpty) { |
| 2089 // The initializer list could contain closures. | 2089 // The initializer list could contain closures. |
| 2090 openFunction(functionElement, function); | 2090 openFunction(functionElement, function); |
| 2091 } | 2091 } |
| 2092 | 2092 |
| 2093 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>(); | 2093 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>(); |
| 2094 | 2094 |
| 2095 // Compile the possible initialization code for local fields and | 2095 // Compile the possible initialization code for local fields and |
| 2096 // super fields. | 2096 // super fields, unless this is a redirecting constructor, in which case |
| 2097 buildFieldInitializers(classElement, fieldValues); | 2097 // the effective target will initialize these. |
| 2098 if (!functionElement.isRedirectingGenerative) { |
| 2099 buildFieldInitializers(classElement, fieldValues); |
| 2100 } |
| 2098 | 2101 |
| 2099 // Compile field-parameters such as [:this.x:]. | 2102 // Compile field-parameters such as [:this.x:]. |
| 2100 FunctionSignature params = functionElement.functionSignature; | 2103 FunctionSignature params = functionElement.functionSignature; |
| 2101 params.orderedForEachParameter((ParameterElement parameter) { | 2104 params.orderedForEachParameter((ParameterElement parameter) { |
| 2102 if (parameter.isInitializingFormal) { | 2105 if (parameter.isInitializingFormal) { |
| 2103 // If the [element] is a field-parameter then | 2106 // If the [element] is a field-parameter then |
| 2104 // initialize the field element with its value. | 2107 // initialize the field element with its value. |
| 2105 InitializingFormalElement fieldParameter = parameter; | 2108 InitializingFormalElement fieldParameter = parameter; |
| 2106 HInstruction parameterValue = | 2109 HInstruction parameterValue = |
| 2107 localsHandler.readLocal(fieldParameter); | 2110 localsHandler.readLocal(fieldParameter); |
| (...skipping 5560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7668 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 7671 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
| 7669 unaliased.accept(this, builder); | 7672 unaliased.accept(this, builder); |
| 7670 } | 7673 } |
| 7671 | 7674 |
| 7672 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 7675 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
| 7673 JavaScriptBackend backend = builder.compiler.backend; | 7676 JavaScriptBackend backend = builder.compiler.backend; |
| 7674 ClassElement cls = backend.findHelper('DynamicRuntimeType'); | 7677 ClassElement cls = backend.findHelper('DynamicRuntimeType'); |
| 7675 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 7678 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
| 7676 } | 7679 } |
| 7677 } | 7680 } |
| OLD | NEW |