| 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 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 List bodyCallInputs = <HInstruction>[]; | 1360 List bodyCallInputs = <HInstruction>[]; |
| 1361 if (isNativeUpgradeFactory) { | 1361 if (isNativeUpgradeFactory) { |
| 1362 if (interceptor == null) { | 1362 if (interceptor == null) { |
| 1363 ConstantValue constant = new InterceptorConstantValue(classElement); | 1363 ConstantValue constant = new InterceptorConstantValue(classElement); |
| 1364 interceptor = graph.addConstant(constant, closedWorld); | 1364 interceptor = graph.addConstant(constant, closedWorld); |
| 1365 } | 1365 } |
| 1366 bodyCallInputs.add(interceptor); | 1366 bodyCallInputs.add(interceptor); |
| 1367 } | 1367 } |
| 1368 bodyCallInputs.add(newObject); | 1368 bodyCallInputs.add(newObject); |
| 1369 ast.Node node = constructorResolvedAst.node; | 1369 ast.Node node = constructorResolvedAst.node; |
| 1370 ClosureClassMap parameterClosureData = | |
| 1371 closureToClassMapper.getMemberMap(constructor); | |
| 1372 | 1370 |
| 1373 FunctionSignature functionSignature = body.functionSignature; | 1371 FunctionSignature functionSignature = body.functionSignature; |
| 1374 // Provide the parameters to the generative constructor body. | 1372 // Provide the parameters to the generative constructor body. |
| 1375 functionSignature.orderedForEachParameter((ParameterElement parameter) { | 1373 functionSignature.orderedForEachParameter((ParameterElement parameter) { |
| 1376 // If [parameter] is boxed, it will be a field in the box passed as the | 1374 // If [parameter] is boxed, it will be a field in the box passed as the |
| 1377 // last parameter. So no need to directly pass it. | 1375 // last parameter. So no need to directly pass it. |
| 1378 if (!localsHandler.isBoxed(parameter)) { | 1376 if (!localsHandler.isBoxed(parameter)) { |
| 1379 bodyCallInputs.add(localsHandler.readLocal(parameter)); | 1377 bodyCallInputs.add(localsHandler.readLocal(parameter)); |
| 1380 } | 1378 } |
| 1381 }); | 1379 }); |
| 1382 | 1380 |
| 1383 // If there are locals that escape (ie mutated in closures), we | 1381 // If there are locals that escape (ie mutated in closures), we |
| 1384 // pass the box to the constructor. | 1382 // pass the box to the constructor. |
| 1385 // The box must be passed before any type variable. | 1383 // The box must be passed before any type variable. |
| 1386 ClosureScope scopeData = parameterClosureData.capturingScopes[node]; | 1384 CapturedVariableInfo scopeData = |
| 1387 if (scopeData != null) { | 1385 closureToClassMapper.getCapturedVariableInfo(node); |
| 1388 bodyCallInputs.add(localsHandler.readLocal(scopeData.boxElement)); | 1386 if (scopeData.hasCapturedVariables()) { |
| 1387 bodyCallInputs.add(localsHandler |
| 1388 .readLocal(closureToClassMapper.getExecutableContext(node))); |
| 1389 } | 1389 } |
| 1390 | 1390 |
| 1391 // Type variables arguments must come after the box (if there is one). | 1391 // Type variables arguments must come after the box (if there is one). |
| 1392 ClassElement currentClass = constructor.enclosingClass; | 1392 ClassElement currentClass = constructor.enclosingClass; |
| 1393 if (rtiNeed.classNeedsRti(currentClass)) { | 1393 if (rtiNeed.classNeedsRti(currentClass)) { |
| 1394 // If [currentClass] needs RTI, we add the type variables as | 1394 // If [currentClass] needs RTI, we add the type variables as |
| 1395 // parameters of the generative constructor body. | 1395 // parameters of the generative constructor body. |
| 1396 currentClass.typeVariables | 1396 currentClass.typeVariables |
| 1397 .forEach((ResolutionTypeVariableType argument) { | 1397 .forEach((ResolutionTypeVariableType argument) { |
| 1398 // TODO(johnniwinther): Substitute [argument] with | 1398 // TODO(johnniwinther): Substitute [argument] with |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 } | 1453 } |
| 1454 | 1454 |
| 1455 if (element is MethodElement) { | 1455 if (element is MethodElement) { |
| 1456 MethodElement functionElement = element; | 1456 MethodElement functionElement = element; |
| 1457 FunctionSignature signature = functionElement.functionSignature; | 1457 FunctionSignature signature = functionElement.functionSignature; |
| 1458 | 1458 |
| 1459 // Put the type checks in the first successor of the entry, | 1459 // Put the type checks in the first successor of the entry, |
| 1460 // because that is where the type guards will also be inserted. | 1460 // because that is where the type guards will also be inserted. |
| 1461 // This way we ensure that a type guard will dominate the type | 1461 // This way we ensure that a type guard will dominate the type |
| 1462 // check. | 1462 // check. |
| 1463 ClosureScope scopeData = localsHandler.closureData.capturingScopes[node]; | |
| 1464 signature.orderedForEachParameter((ParameterElement parameterElement) { | 1463 signature.orderedForEachParameter((ParameterElement parameterElement) { |
| 1465 if (element.isGenerativeConstructorBody) { | 1464 if (element.isGenerativeConstructorBody) { |
| 1466 if (scopeData != null && | 1465 if (closureToClassMapper |
| 1467 scopeData.isCapturedVariable(parameterElement)) { | 1466 .getCapturedVariableInfo(node) |
| 1467 .isCaptured(parameterElement)) { |
| 1468 // The parameter will be a field in the box passed as the | 1468 // The parameter will be a field in the box passed as the |
| 1469 // last parameter. So no need to have it. | 1469 // last parameter. So no need to have it. |
| 1470 return; | 1470 return; |
| 1471 } | 1471 } |
| 1472 } | 1472 } |
| 1473 HInstruction newParameter = | 1473 HInstruction newParameter = |
| 1474 localsHandler.directLocals[parameterElement]; | 1474 localsHandler.directLocals[parameterElement]; |
| 1475 if (!element.isConstructor || | 1475 if (!element.isConstructor || |
| 1476 !(element as ConstructorElement).isRedirectingFactory) { | 1476 !(element as ConstructorElement).isRedirectingFactory) { |
| 1477 // Redirection factories must not check their argument types. | 1477 // Redirection factories must not check their argument types. |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1854 block.remove(breakInstruction); | 1854 block.remove(breakInstruction); |
| 1855 }); | 1855 }); |
| 1856 } | 1856 } |
| 1857 } | 1857 } |
| 1858 jumpHandler.close(); | 1858 jumpHandler.close(); |
| 1859 loopDepth--; | 1859 loopDepth--; |
| 1860 } | 1860 } |
| 1861 | 1861 |
| 1862 visitFunctionExpression(ast.FunctionExpression node) { | 1862 visitFunctionExpression(ast.FunctionExpression node) { |
| 1863 LocalFunctionElement methodElement = elements[node]; | 1863 LocalFunctionElement methodElement = elements[node]; |
| 1864 ClosureClassMap nestedClosureData = | 1864 ClassEntity closureClassElement = |
| 1865 closureToClassMapper.getLocalFunctionMap(methodElement); | 1865 closureToClassMapper.getClosureClassEntity(methodElement); |
| 1866 assert(nestedClosureData != null); | |
| 1867 assert(nestedClosureData.closureClassElement != null); | |
| 1868 ClosureClassElement closureClassElement = | |
| 1869 nestedClosureData.closureClassElement; | |
| 1870 MethodElement callElement = nestedClosureData.callElement; | |
| 1871 | 1866 |
| 1872 List<HInstruction> capturedVariables = <HInstruction>[]; | 1867 List<HInstruction> capturedVariables = <HInstruction>[]; |
| 1873 closureClassElement.closureFields.forEach((ClosureFieldElement field) { | 1868 closureToClassMapper.forEachClosureClassFieldEntity(methodElement, |
| 1869 (ClosureFieldElement field) { |
| 1874 Local capturedLocal = | 1870 Local capturedLocal = |
| 1875 nestedClosureData.getLocalVariableForClosureField(field); | 1871 closureToClassMapper.getLocalVarForClosureField(methodElement, field); |
| 1876 assert(capturedLocal != null); | 1872 assert(capturedLocal != null); |
| 1877 capturedVariables.add(localsHandler.readLocal(capturedLocal)); | 1873 capturedVariables.add(localsHandler.readLocal(capturedLocal)); |
| 1878 }); | 1874 }); |
| 1879 | 1875 |
| 1880 TypeMask type = new TypeMask.nonNullExact(closureClassElement, closedWorld); | 1876 TypeMask type = new TypeMask.nonNullExact(closureClassElement, closedWorld); |
| 1881 push(new HCreate(closureClassElement, capturedVariables, type, | 1877 push(new HCreate(closureClassElement, capturedVariables, type, |
| 1882 callMethod: callElement, localFunction: methodElement) | 1878 callMethod: closureToClassMapper.getCallEntity(methodElement), |
| 1879 localFunction: methodElement) |
| 1883 ..sourceInformation = sourceInformationBuilder.buildCreate(node)); | 1880 ..sourceInformation = sourceInformationBuilder.buildCreate(node)); |
| 1884 } | 1881 } |
| 1885 | 1882 |
| 1886 visitFunctionDeclaration(ast.FunctionDeclaration node) { | 1883 visitFunctionDeclaration(ast.FunctionDeclaration node) { |
| 1887 assert(isReachable); | 1884 assert(isReachable); |
| 1888 visit(node.function); | 1885 visit(node.function); |
| 1889 LocalFunctionElement localFunction = | 1886 LocalFunctionElement localFunction = |
| 1890 elements.getFunctionDefinition(node.function); | 1887 elements.getFunctionDefinition(node.function); |
| 1891 localsHandler.updateLocal(localFunction, pop()); | 1888 localsHandler.updateLocal(localFunction, pop()); |
| 1892 } | 1889 } |
| (...skipping 4919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6812 this.oldReturnLocal, | 6809 this.oldReturnLocal, |
| 6813 this.oldReturnType, | 6810 this.oldReturnType, |
| 6814 this.oldResolvedAst, | 6811 this.oldResolvedAst, |
| 6815 this.oldStack, | 6812 this.oldStack, |
| 6816 this.oldLocalsHandler, | 6813 this.oldLocalsHandler, |
| 6817 this.inTryStatement, | 6814 this.inTryStatement, |
| 6818 this.allFunctionsCalledOnce, | 6815 this.allFunctionsCalledOnce, |
| 6819 this.oldElementInferenceResults) | 6816 this.oldElementInferenceResults) |
| 6820 : super(function); | 6817 : super(function); |
| 6821 } | 6818 } |
| OLD | NEW |