| 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 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 import 'package:js_runtime/shared/embedded_names.dart'; | 7 import 'package:js_runtime/shared/embedded_names.dart'; |
| 8 | 8 |
| 9 import '../closure.dart'; | 9 import '../closure.dart'; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 * updated in the [localsHandler]. This function creates such an element and | 809 * updated in the [localsHandler]. This function creates such an element and |
| 810 * stores it in the [returnLocal] field. | 810 * stores it in the [returnLocal] field. |
| 811 */ | 811 */ |
| 812 void setupStateForInlining( | 812 void setupStateForInlining( |
| 813 FunctionElement function, List<HInstruction> compiledArguments, | 813 FunctionElement function, List<HInstruction> compiledArguments, |
| 814 {InterfaceType instanceType}) { | 814 {InterfaceType instanceType}) { |
| 815 ResolvedAst resolvedAst = function.resolvedAst; | 815 ResolvedAst resolvedAst = function.resolvedAst; |
| 816 assert(resolvedAst != null); | 816 assert(resolvedAst != null); |
| 817 localsHandler = new LocalsHandler(this, function, instanceType, compiler); | 817 localsHandler = new LocalsHandler(this, function, instanceType, compiler); |
| 818 localsHandler.closureData = | 818 localsHandler.closureData = |
| 819 compiler.closureToClassMapper.computeClosureToClassMapping(resolvedAst); | 819 compiler.closureToClassMapper.getClosureToClassMapping(resolvedAst); |
| 820 returnLocal = new SyntheticLocal("result", function); | 820 returnLocal = new SyntheticLocal("result", function); |
| 821 localsHandler.updateLocal(returnLocal, graph.addConstantNull(compiler)); | 821 localsHandler.updateLocal(returnLocal, graph.addConstantNull(compiler)); |
| 822 | 822 |
| 823 inTryStatement = false; // TODO(lry): why? Document. | 823 inTryStatement = false; // TODO(lry): why? Document. |
| 824 | 824 |
| 825 int argumentIndex = 0; | 825 int argumentIndex = 0; |
| 826 if (function.isInstanceMember) { | 826 if (function.isInstanceMember) { |
| 827 localsHandler.updateLocal(localsHandler.closureData.thisLocal, | 827 localsHandler.updateLocal(localsHandler.closureData.thisLocal, |
| 828 compiledArguments[argumentIndex++]); | 828 compiledArguments[argumentIndex++]); |
| 829 } | 829 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 if (parameter.isInitializingFormal) { | 983 if (parameter.isInitializingFormal) { |
| 984 InitializingFormalElement fieldParameterElement = parameter; | 984 InitializingFormalElement fieldParameterElement = parameter; |
| 985 fieldValues[fieldParameterElement.fieldElement] = argument; | 985 fieldValues[fieldParameterElement.fieldElement] = argument; |
| 986 } | 986 } |
| 987 }); | 987 }); |
| 988 | 988 |
| 989 // Build the initializers in the context of the new constructor. | 989 // Build the initializers in the context of the new constructor. |
| 990 ResolvedAst oldResolvedAst = resolvedAst; | 990 ResolvedAst oldResolvedAst = resolvedAst; |
| 991 resolvedAst = callee.resolvedAst; | 991 resolvedAst = callee.resolvedAst; |
| 992 ClosureClassMap oldClosureData = localsHandler.closureData; | 992 ClosureClassMap oldClosureData = localsHandler.closureData; |
| 993 ClosureClassMap newClosureData = compiler.closureToClassMapper | 993 ClosureClassMap newClosureData = |
| 994 .computeClosureToClassMapping(resolvedAst); | 994 compiler.closureToClassMapper.getClosureToClassMapping(resolvedAst); |
| 995 localsHandler.closureData = newClosureData; | 995 localsHandler.closureData = newClosureData; |
| 996 if (resolvedAst.kind == ResolvedAstKind.PARSED) { | 996 if (resolvedAst.kind == ResolvedAstKind.PARSED) { |
| 997 localsHandler.enterScope(resolvedAst.node, callee); | 997 localsHandler.enterScope(resolvedAst.node, callee); |
| 998 } | 998 } |
| 999 buildInitializers(callee, constructorResolvedAsts, fieldValues); | 999 buildInitializers(callee, constructorResolvedAsts, fieldValues); |
| 1000 localsHandler.closureData = oldClosureData; | 1000 localsHandler.closureData = oldClosureData; |
| 1001 resolvedAst = oldResolvedAst; | 1001 resolvedAst = oldResolvedAst; |
| 1002 }); | 1002 }); |
| 1003 } | 1003 } |
| 1004 | 1004 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 // prevent overwriting pre-initialized native properties. | 1156 // prevent overwriting pre-initialized native properties. |
| 1157 if (!backend.isNativeOrExtendsNative(classElement)) { | 1157 if (!backend.isNativeOrExtendsNative(classElement)) { |
| 1158 fieldValues[member] = graph.addConstantNull(compiler); | 1158 fieldValues[member] = graph.addConstantNull(compiler); |
| 1159 } | 1159 } |
| 1160 } else { | 1160 } else { |
| 1161 ast.Node right = initializer; | 1161 ast.Node right = initializer; |
| 1162 ResolvedAst savedResolvedAst = resolvedAst; | 1162 ResolvedAst savedResolvedAst = resolvedAst; |
| 1163 resolvedAst = fieldResolvedAst; | 1163 resolvedAst = fieldResolvedAst; |
| 1164 // In case the field initializer uses closures, run the | 1164 // In case the field initializer uses closures, run the |
| 1165 // closure to class mapper. | 1165 // closure to class mapper. |
| 1166 compiler.closureToClassMapper | 1166 compiler.closureToClassMapper.getClosureToClassMapping(resolvedAst); |
| 1167 .computeClosureToClassMapping(resolvedAst); | |
| 1168 inlinedFrom(fieldResolvedAst, () => right.accept(this)); | 1167 inlinedFrom(fieldResolvedAst, () => right.accept(this)); |
| 1169 resolvedAst = savedResolvedAst; | 1168 resolvedAst = savedResolvedAst; |
| 1170 fieldValues[member] = pop(); | 1169 fieldValues[member] = pop(); |
| 1171 } | 1170 } |
| 1172 }); | 1171 }); |
| 1173 }); | 1172 }); |
| 1174 } | 1173 } |
| 1175 | 1174 |
| 1176 /** | 1175 /** |
| 1177 * Build the factory function corresponding to the constructor | 1176 * Build the factory function corresponding to the constructor |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1315 if (isNativeUpgradeFactory) { | 1314 if (isNativeUpgradeFactory) { |
| 1316 if (interceptor == null) { | 1315 if (interceptor == null) { |
| 1317 ConstantValue constant = | 1316 ConstantValue constant = |
| 1318 new InterceptorConstantValue(classElement.thisType); | 1317 new InterceptorConstantValue(classElement.thisType); |
| 1319 interceptor = graph.addConstant(constant, compiler); | 1318 interceptor = graph.addConstant(constant, compiler); |
| 1320 } | 1319 } |
| 1321 bodyCallInputs.add(interceptor); | 1320 bodyCallInputs.add(interceptor); |
| 1322 } | 1321 } |
| 1323 bodyCallInputs.add(newObject); | 1322 bodyCallInputs.add(newObject); |
| 1324 ast.Node node = constructorResolvedAst.node; | 1323 ast.Node node = constructorResolvedAst.node; |
| 1325 ClosureClassMap parameterClosureData = | 1324 ClosureClassMap parameterClosureData = compiler.closureToClassMapper |
| 1326 compiler.closureToClassMapper.getMappingForNestedFunction(node); | 1325 .getClosureToClassMapping(constructorResolvedAst); |
| 1327 | 1326 |
| 1328 FunctionSignature functionSignature = body.functionSignature; | 1327 FunctionSignature functionSignature = body.functionSignature; |
| 1329 // Provide the parameters to the generative constructor body. | 1328 // Provide the parameters to the generative constructor body. |
| 1330 functionSignature.orderedForEachParameter((ParameterElement parameter) { | 1329 functionSignature.orderedForEachParameter((ParameterElement parameter) { |
| 1331 // If [parameter] is boxed, it will be a field in the box passed as the | 1330 // If [parameter] is boxed, it will be a field in the box passed as the |
| 1332 // last parameter. So no need to directly pass it. | 1331 // last parameter. So no need to directly pass it. |
| 1333 if (!localsHandler.isBoxed(parameter)) { | 1332 if (!localsHandler.isBoxed(parameter)) { |
| 1334 bodyCallInputs.add(localsHandler.readLocal(parameter)); | 1333 bodyCallInputs.add(localsHandler.readLocal(parameter)); |
| 1335 } | 1334 } |
| 1336 }); | 1335 }); |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1899 block.addAtExit(new HBreak.toLabel(label)); | 1898 block.addAtExit(new HBreak.toLabel(label)); |
| 1900 block.remove(breakInstruction); | 1899 block.remove(breakInstruction); |
| 1901 }); | 1900 }); |
| 1902 } | 1901 } |
| 1903 } | 1902 } |
| 1904 jumpHandler.close(); | 1903 jumpHandler.close(); |
| 1905 loopDepth--; | 1904 loopDepth--; |
| 1906 } | 1905 } |
| 1907 | 1906 |
| 1908 visitFunctionExpression(ast.FunctionExpression node) { | 1907 visitFunctionExpression(ast.FunctionExpression node) { |
| 1909 ClosureClassMap nestedClosureData = | 1908 LocalFunctionElement methodElement = elements[node]; |
| 1910 compiler.closureToClassMapper.getMappingForNestedFunction(node); | 1909 ClosureClassMap nestedClosureData = compiler.closureToClassMapper |
| 1910 .getClosureToClassMapping(methodElement.resolvedAst); |
| 1911 assert(nestedClosureData != null); | 1911 assert(nestedClosureData != null); |
| 1912 assert(nestedClosureData.closureClassElement != null); | 1912 assert(nestedClosureData.closureClassElement != null); |
| 1913 ClosureClassElement closureClassElement = | 1913 ClosureClassElement closureClassElement = |
| 1914 nestedClosureData.closureClassElement; | 1914 nestedClosureData.closureClassElement; |
| 1915 FunctionElement callElement = nestedClosureData.callElement; | 1915 FunctionElement callElement = nestedClosureData.callElement; |
| 1916 // TODO(ahe): This should be registered in codegen, not here. | 1916 // TODO(ahe): This should be registered in codegen, not here. |
| 1917 // TODO(johnniwinther): Is [registerStaticUse] equivalent to | 1917 // TODO(johnniwinther): Is [registerStaticUse] equivalent to |
| 1918 // [addToWorkList]? | 1918 // [addToWorkList]? |
| 1919 registry?.registerStaticUse(new StaticUse.foreignUse(callElement)); | 1919 registry?.registerStaticUse(new StaticUse.foreignUse(callElement)); |
| 1920 | 1920 |
| 1921 List<HInstruction> capturedVariables = <HInstruction>[]; | 1921 List<HInstruction> capturedVariables = <HInstruction>[]; |
| 1922 closureClassElement.closureFields.forEach((ClosureFieldElement field) { | 1922 closureClassElement.closureFields.forEach((ClosureFieldElement field) { |
| 1923 Local capturedLocal = | 1923 Local capturedLocal = |
| 1924 nestedClosureData.getLocalVariableForClosureField(field); | 1924 nestedClosureData.getLocalVariableForClosureField(field); |
| 1925 assert(capturedLocal != null); | 1925 assert(capturedLocal != null); |
| 1926 capturedVariables.add(localsHandler.readLocal(capturedLocal)); | 1926 capturedVariables.add(localsHandler.readLocal(capturedLocal)); |
| 1927 }); | 1927 }); |
| 1928 | 1928 |
| 1929 TypeMask type = | 1929 TypeMask type = |
| 1930 new TypeMask.nonNullExact(closureClassElement, compiler.closedWorld); | 1930 new TypeMask.nonNullExact(closureClassElement, compiler.closedWorld); |
| 1931 push(new HCreate(closureClassElement, capturedVariables, type) | 1931 push(new HCreate(closureClassElement, capturedVariables, type) |
| 1932 ..sourceInformation = sourceInformationBuilder.buildCreate(node)); | 1932 ..sourceInformation = sourceInformationBuilder.buildCreate(node)); |
| 1933 | 1933 |
| 1934 Element methodElement = nestedClosureData.closureElement; | |
| 1935 registry?.registerInstantiatedClosure(methodElement); | 1934 registry?.registerInstantiatedClosure(methodElement); |
| 1936 } | 1935 } |
| 1937 | 1936 |
| 1938 visitFunctionDeclaration(ast.FunctionDeclaration node) { | 1937 visitFunctionDeclaration(ast.FunctionDeclaration node) { |
| 1939 assert(isReachable); | 1938 assert(isReachable); |
| 1940 visit(node.function); | 1939 visit(node.function); |
| 1941 LocalFunctionElement localFunction = | 1940 LocalFunctionElement localFunction = |
| 1942 elements.getFunctionDefinition(node.function); | 1941 elements.getFunctionDefinition(node.function); |
| 1943 localsHandler.updateLocal(localFunction, pop()); | 1942 localsHandler.updateLocal(localFunction, pop()); |
| 1944 } | 1943 } |
| (...skipping 5099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7044 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 7043 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
| 7045 unaliased.accept(this, builder); | 7044 unaliased.accept(this, builder); |
| 7046 } | 7045 } |
| 7047 | 7046 |
| 7048 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 7047 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
| 7049 JavaScriptBackend backend = builder.compiler.backend; | 7048 JavaScriptBackend backend = builder.compiler.backend; |
| 7050 ClassElement cls = backend.helpers.DynamicRuntimeType; | 7049 ClassElement cls = backend.helpers.DynamicRuntimeType; |
| 7051 builder.push(new HDynamicType(type, new TypeMask.exact(cls, closedWorld))); | 7050 builder.push(new HDynamicType(type, new TypeMask.exact(cls, closedWorld))); |
| 7052 } | 7051 } |
| 7053 } | 7052 } |
| OLD | NEW |