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 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 * updated in the [localsHandler]. This function creates such an element and | 860 * updated in the [localsHandler]. This function creates such an element and |
861 * stores it in the [returnLocal] field. | 861 * stores it in the [returnLocal] field. |
862 */ | 862 */ |
863 void setupStateForInlining( | 863 void setupStateForInlining( |
864 MethodElement function, List<HInstruction> compiledArguments, | 864 MethodElement function, List<HInstruction> compiledArguments, |
865 {ResolutionInterfaceType instanceType}) { | 865 {ResolutionInterfaceType instanceType}) { |
866 ResolvedAst resolvedAst = function.resolvedAst; | 866 ResolvedAst resolvedAst = function.resolvedAst; |
867 assert(resolvedAst != null); | 867 assert(resolvedAst != null); |
868 localsHandler = new LocalsHandler(this, function, function.memberContext, | 868 localsHandler = new LocalsHandler(this, function, function.memberContext, |
869 function.contextClass, instanceType, nativeData, interceptorData); | 869 function.contextClass, instanceType, nativeData, interceptorData); |
870 localsHandler.closureData = closureToClassMapper.getMemberMap(function); | 870 localsHandler.closureData = |
| 871 closureToClassMapper.getClosureRepresentationInfo(function); |
871 returnLocal = | 872 returnLocal = |
872 new SyntheticLocal("result", function, function.memberContext); | 873 new SyntheticLocal("result", function, function.memberContext); |
873 localsHandler.updateLocal(returnLocal, graph.addConstantNull(closedWorld)); | 874 localsHandler.updateLocal(returnLocal, graph.addConstantNull(closedWorld)); |
874 | 875 |
875 inTryStatement = false; // TODO(lry): why? Document. | 876 inTryStatement = false; // TODO(lry): why? Document. |
876 | 877 |
877 int argumentIndex = 0; | 878 int argumentIndex = 0; |
878 if (function.isInstanceMember) { | 879 if (function.isInstanceMember) { |
879 localsHandler.updateLocal(localsHandler.closureData.thisLocal, | 880 localsHandler.updateLocal(localsHandler.closureData.thisLocal, |
880 compiledArguments[argumentIndex++]); | 881 compiledArguments[argumentIndex++]); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 InitializingFormalElement fieldParameterElement = parameter; | 1027 InitializingFormalElement fieldParameterElement = parameter; |
1027 fieldValues[fieldParameterElement.fieldElement] = argument; | 1028 fieldValues[fieldParameterElement.fieldElement] = argument; |
1028 } | 1029 } |
1029 }); | 1030 }); |
1030 | 1031 |
1031 // Build the initializers in the context of the new constructor. | 1032 // Build the initializers in the context of the new constructor. |
1032 ResolvedAst oldResolvedAst = resolvedAst; | 1033 ResolvedAst oldResolvedAst = resolvedAst; |
1033 resolvedAst = callee.resolvedAst; | 1034 resolvedAst = callee.resolvedAst; |
1034 final oldElementInferenceResults = elementInferenceResults; | 1035 final oldElementInferenceResults = elementInferenceResults; |
1035 elementInferenceResults = globalInferenceResults.resultOfMember(callee); | 1036 elementInferenceResults = globalInferenceResults.resultOfMember(callee); |
1036 ClosureClassMap oldClosureData = localsHandler.closureData; | 1037 ClosureRepresentationInfo oldClosureData = localsHandler.closureData; |
1037 ClosureClassMap newClosureData = | 1038 ClosureRepresentationInfo newClosureData = |
1038 closureToClassMapper.getMemberMap(callee); | 1039 closureToClassMapper.getClosureRepresentationInfo(callee); |
1039 localsHandler.closureData = newClosureData; | 1040 localsHandler.closureData = newClosureData; |
1040 if (resolvedAst.kind == ResolvedAstKind.PARSED) { | 1041 if (resolvedAst.kind == ResolvedAstKind.PARSED) { |
1041 // TODO(efortuna): Take out the test below for null once we are no | 1042 localsHandler.enterScope( |
1042 // longer dealing with the ClosureClassMap interface directly. | 1043 closureToClassMapper.getClosureAnalysisInfo(resolvedAst.node), |
1043 if (newClosureData.capturingScopes[resolvedAst.node] != null) { | 1044 forGenerativeConstructorBody: callee.isGenerativeConstructorBody); |
1044 localsHandler.enterScope( | |
1045 newClosureData.capturingScopes[resolvedAst.node], | |
1046 forGenerativeConstructorBody: callee.isGenerativeConstructorBody); | |
1047 } | |
1048 } | 1045 } |
1049 buildInitializers(callee, constructorResolvedAsts, fieldValues); | 1046 buildInitializers(callee, constructorResolvedAsts, fieldValues); |
1050 localsHandler.closureData = oldClosureData; | 1047 localsHandler.closureData = oldClosureData; |
1051 resolvedAst = oldResolvedAst; | 1048 resolvedAst = oldResolvedAst; |
1052 elementInferenceResults = oldElementInferenceResults; | 1049 elementInferenceResults = oldElementInferenceResults; |
1053 }); | 1050 }); |
1054 } | 1051 } |
1055 | 1052 |
1056 void buildInitializers( | 1053 void buildInitializers( |
1057 ConstructorElement constructor, | 1054 ConstructorElement constructor, |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 | 1446 |
1450 Map<Local, TypeMask> parameters = <Local, TypeMask>{}; | 1447 Map<Local, TypeMask> parameters = <Local, TypeMask>{}; |
1451 if (element is MethodElement) { | 1448 if (element is MethodElement) { |
1452 element.functionSignature | 1449 element.functionSignature |
1453 .orderedForEachParameter((ParameterElement parameter) { | 1450 .orderedForEachParameter((ParameterElement parameter) { |
1454 parameters[parameter] = TypeMaskFactory.inferredTypeForParameter( | 1451 parameters[parameter] = TypeMaskFactory.inferredTypeForParameter( |
1455 parameter, globalInferenceResults); | 1452 parameter, globalInferenceResults); |
1456 }); | 1453 }); |
1457 } | 1454 } |
1458 | 1455 |
1459 ClosureClassMap closureData = closureToClassMapper.getMemberMap(element); | 1456 ClosureRepresentationInfo closureData = |
1460 localsHandler.startFunction( | 1457 closureToClassMapper.getClosureRepresentationInfo(element); |
1461 element, closureData, closureData.capturingScopes[node], parameters, | 1458 localsHandler.startFunction(element, closureData, |
| 1459 closureToClassMapper.getClosureAnalysisInfo(node), parameters, |
1462 isGenerativeConstructorBody: element.isGenerativeConstructorBody); | 1460 isGenerativeConstructorBody: element.isGenerativeConstructorBody); |
1463 close(new HGoto()).addSuccessor(block); | 1461 close(new HGoto()).addSuccessor(block); |
1464 | 1462 |
1465 open(block); | 1463 open(block); |
1466 | 1464 |
1467 // Add the type parameters of the class as parameters of this method. This | 1465 // Add the type parameters of the class as parameters of this method. This |
1468 // must be done before adding the normal parameters, because their types | 1466 // must be done before adding the normal parameters, because their types |
1469 // may contain references to type variables. | 1467 // may contain references to type variables. |
1470 ClassElement cls = element.enclosingClass; | 1468 ClassElement cls = element.enclosingClass; |
1471 if ((element.isConstructor || element.isGenerativeConstructorBody) && | 1469 if ((element.isConstructor || element.isGenerativeConstructorBody) && |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1892 block.remove(breakInstruction); | 1890 block.remove(breakInstruction); |
1893 }); | 1891 }); |
1894 } | 1892 } |
1895 } | 1893 } |
1896 jumpHandler.close(); | 1894 jumpHandler.close(); |
1897 loopDepth--; | 1895 loopDepth--; |
1898 } | 1896 } |
1899 | 1897 |
1900 visitFunctionExpression(ast.FunctionExpression node) { | 1898 visitFunctionExpression(ast.FunctionExpression node) { |
1901 LocalFunctionElement methodElement = elements[node]; | 1899 LocalFunctionElement methodElement = elements[node]; |
1902 ClosureClassMap nestedClosureData = | 1900 ClosureRepresentationInfo closureInfo = |
1903 closureToClassMapper.getLocalFunctionMap(methodElement); | 1901 closureToClassMapper.getClosureRepresentationInfo(methodElement); |
1904 assert(nestedClosureData != null); | 1902 ClassEntity closureClassEntity = closureInfo.closureClassEntity; |
1905 assert(nestedClosureData.closureClassElement != null); | |
1906 ClosureClassElement closureClassElement = | |
1907 nestedClosureData.closureClassElement; | |
1908 MethodElement callElement = nestedClosureData.callElement; | |
1909 | 1903 |
1910 List<HInstruction> capturedVariables = <HInstruction>[]; | 1904 List<HInstruction> capturedVariables = <HInstruction>[]; |
1911 closureClassElement.closureFields.forEach((ClosureFieldElement field) { | 1905 closureInfo.createdFieldEntities.forEach((Local field) { |
1912 Local capturedLocal = | 1906 assert(field != null); |
1913 nestedClosureData.getLocalVariableForClosureField(field); | 1907 capturedVariables.add(localsHandler.readLocal(field)); |
1914 assert(capturedLocal != null); | |
1915 capturedVariables.add(localsHandler.readLocal(capturedLocal)); | |
1916 }); | 1908 }); |
1917 | 1909 |
1918 TypeMask type = new TypeMask.nonNullExact(closureClassElement, closedWorld); | 1910 TypeMask type = new TypeMask.nonNullExact(closureClassEntity, closedWorld); |
1919 push(new HCreate(closureClassElement, capturedVariables, type, | 1911 push(new HCreate(closureClassEntity, capturedVariables, type, |
1920 callMethod: callElement, localFunction: methodElement) | 1912 callMethod: closureInfo.callMethod, localFunction: methodElement) |
1921 ..sourceInformation = sourceInformationBuilder.buildCreate(node)); | 1913 ..sourceInformation = sourceInformationBuilder.buildCreate(node)); |
1922 } | 1914 } |
1923 | 1915 |
1924 visitFunctionDeclaration(ast.FunctionDeclaration node) { | 1916 visitFunctionDeclaration(ast.FunctionDeclaration node) { |
1925 assert(isReachable); | 1917 assert(isReachable); |
1926 visit(node.function); | 1918 visit(node.function); |
1927 LocalFunctionElement localFunction = | 1919 LocalFunctionElement localFunction = |
1928 elements.getFunctionDefinition(node.function); | 1920 elements.getFunctionDefinition(node.function); |
1929 localsHandler.updateLocal(localFunction, pop()); | 1921 localsHandler.updateLocal(localFunction, pop()); |
1930 } | 1922 } |
(...skipping 4944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6875 this.oldReturnLocal, | 6867 this.oldReturnLocal, |
6876 this.oldReturnType, | 6868 this.oldReturnType, |
6877 this.oldResolvedAst, | 6869 this.oldResolvedAst, |
6878 this.oldStack, | 6870 this.oldStack, |
6879 this.oldLocalsHandler, | 6871 this.oldLocalsHandler, |
6880 this.inTryStatement, | 6872 this.inTryStatement, |
6881 this.allFunctionsCalledOnce, | 6873 this.allFunctionsCalledOnce, |
6882 this.oldElementInferenceResults) | 6874 this.oldElementInferenceResults) |
6883 : super(function); | 6875 : super(function); |
6884 } | 6876 } |
OLD | NEW |