| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library dart2js.ir_builder_task; | 5 library dart2js.ir_builder_task; |
| 6 | 6 |
| 7 import '../closure.dart' as closure; | 7 import '../closure.dart' as closure; |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../common/names.dart' show | 9 import '../common/names.dart' show |
| 10 Names, | 10 Names, |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 assert(elements[node] != null); | 750 assert(elements[node] != null); |
| 751 | 751 |
| 752 closureClassMap = | 752 closureClassMap = |
| 753 compiler.closureToClassMapper.computeClosureToClassMapping( | 753 compiler.closureToClassMapper.computeClosureToClassMapping( |
| 754 element, | 754 element, |
| 755 node, | 755 node, |
| 756 elements); | 756 elements); |
| 757 TryBoxedVariables variables = _analyzeTryBoxedVariables(node); | 757 TryBoxedVariables variables = _analyzeTryBoxedVariables(node); |
| 758 tryStatements = variables.tryStatements; | 758 tryStatements = variables.tryStatements; |
| 759 IrBuilder builder = getBuilderFor(element); | 759 IrBuilder builder = getBuilderFor(element); |
| 760 return withBuilder(builder, () => _makeFunctionBody(element, node)); | 760 return withBuilder(builder, |
| 761 () => _makeFunctionBody(builder, element, node)); |
| 761 } | 762 } |
| 762 | 763 |
| 763 ir.FunctionDefinition buildStaticFieldInitializer(FieldElement element) { | 764 ir.FunctionDefinition buildStaticFieldInitializer(FieldElement element) { |
| 764 if (!backend.constants.lazyStatics.contains(element)) { | 765 if (!backend.constants.lazyStatics.contains(element)) { |
| 765 return null; // Nothing to do. | 766 return null; // Nothing to do. |
| 766 } | 767 } |
| 767 closureClassMap = | 768 closureClassMap = |
| 768 compiler.closureToClassMapper.computeClosureToClassMapping( | 769 compiler.closureToClassMapper.computeClosureToClassMapping( |
| 769 element, | 770 element, |
| 770 element.node, | 771 element.node, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 if (constant != null && !field.isAssignable) { | 873 if (constant != null && !field.isAssignable) { |
| 873 typeMaskSystem.associateConstantValueWithElement(constant, field); | 874 typeMaskSystem.associateConstantValueWithElement(constant, field); |
| 874 return irBuilder.buildConstant(constant, sourceInformation: src); | 875 return irBuilder.buildConstant(constant, sourceInformation: src); |
| 875 } else if (backend.constants.lazyStatics.contains(field)) { | 876 } else if (backend.constants.lazyStatics.contains(field)) { |
| 876 return irBuilder.addPrimitive(new ir.GetLazyStatic(field, src)); | 877 return irBuilder.addPrimitive(new ir.GetLazyStatic(field, src)); |
| 877 } else { | 878 } else { |
| 878 return irBuilder.addPrimitive(new ir.GetStatic(field, src)); | 879 return irBuilder.addPrimitive(new ir.GetStatic(field, src)); |
| 879 } | 880 } |
| 880 } | 881 } |
| 881 | 882 |
| 882 ir.FunctionDefinition _makeFunctionBody(FunctionElement element, | 883 ir.FunctionDefinition _makeFunctionBody( |
| 883 ast.FunctionExpression node) { | 884 IrBuilder builder, |
| 885 FunctionElement element, |
| 886 ast.FunctionExpression node) { |
| 884 FunctionSignature signature = element.functionSignature; | 887 FunctionSignature signature = element.functionSignature; |
| 885 List<Local> parameters = <Local>[]; | 888 List<Local> parameters = <Local>[]; |
| 886 signature.orderedForEachParameter( | 889 signature.orderedForEachParameter( |
| 887 (LocalParameterElement e) => parameters.add(e)); | 890 (LocalParameterElement e) => parameters.add(e)); |
| 888 | 891 |
| 892 bool requiresRuntimeTypes = false; |
| 889 if (element.isFactoryConstructor) { | 893 if (element.isFactoryConstructor) { |
| 890 // Type arguments are passed in as extra parameters. | 894 requiresRuntimeTypes = |
| 891 for (DartType typeVariable in element.enclosingClass.typeVariables) { | 895 builder.program.requiresRuntimeTypesFor(element.enclosingElement); |
| 892 parameters.add(new closure.TypeVariableLocal(typeVariable, element)); | 896 if (requiresRuntimeTypes) { |
| 897 // Type arguments are passed in as extra parameters. |
| 898 for (DartType typeVariable in element.enclosingClass.typeVariables) { |
| 899 parameters.add(new closure.TypeVariableLocal(typeVariable, element)); |
| 900 } |
| 893 } | 901 } |
| 894 } | 902 } |
| 895 | 903 |
| 896 irBuilder.buildFunctionHeader(parameters, | 904 irBuilder.buildFunctionHeader(parameters, |
| 897 closureScope: getClosureScopeForNode(node), | 905 closureScope: getClosureScopeForNode(node), |
| 898 env: getClosureEnvironment()); | 906 env: getClosureEnvironment()); |
| 899 | 907 |
| 900 visit(node.body); | 908 if (element == helpers.jsArrayTypedConstructor) { |
| 909 // Generate a body for JSArray<E>.typed(allocation): |
| 910 // |
| 911 // t1 = setRuntimeTypeInfo(allocation, TypeExpression($E)); |
| 912 // return Refinement(t1, <JSArray>); |
| 913 // |
| 914 assert(parameters.length == 1 || parameters.length == 2); |
| 915 ir.Primitive allocation = irBuilder.buildLocalGet(parameters[0]); |
| 916 ClassElement classElement = element.enclosingElement; |
| 917 |
| 918 // Only call setRuntimeTypeInfo if JSArray requires the type parameter. |
| 919 if (requiresRuntimeTypes) { |
| 920 assert(parameters.length == 2); |
| 921 ir.Primitive typeArgument = |
| 922 irBuilder.buildTypeVariableAccess(parameters[1].typeVariable); |
| 923 |
| 924 ir.Primitive typeInformation = irBuilder.addPrimitive( |
| 925 new ir.TypeExpression(ir.TypeExpressionKind.INSTANCE, |
| 926 element.enclosingClass.thisType, |
| 927 <ir.Primitive>[typeArgument])); |
| 928 |
| 929 Element helper = helpers.setRuntimeTypeInfo; |
| 930 CallStructure callStructure = CallStructure.TWO_ARGS; |
| 931 Selector selector = new Selector.call(helper.memberName, callStructure); |
| 932 allocation = irBuilder.buildInvokeStatic( |
| 933 helper, selector, <ir.Primitive>[allocation, typeInformation], |
| 934 sourceInformationBuilder.buildGeneric(node)); |
| 935 } |
| 936 |
| 937 ir.Primitive refinement = irBuilder.addPrimitive( |
| 938 new ir.Refinement(allocation, typeMaskSystem.arrayType)); |
| 939 |
| 940 irBuilder.buildReturn(value: refinement, |
| 941 sourceInformation: |
| 942 sourceInformationBuilder.buildImplicitReturn(element)); |
| 943 } else { |
| 944 visit(node.body); |
| 945 } |
| 901 return irBuilder.makeFunctionDefinition(); | 946 return irBuilder.makeFunctionDefinition(); |
| 902 } | 947 } |
| 903 | 948 |
| 904 /// Builds the IR for creating an instance of the closure class corresponding | 949 /// Builds the IR for creating an instance of the closure class corresponding |
| 905 /// to the given nested function. | 950 /// to the given nested function. |
| 906 closure.ClosureClassElement makeSubFunction(ast.FunctionExpression node) { | 951 closure.ClosureClassElement makeSubFunction(ast.FunctionExpression node) { |
| 907 closure.ClosureClassMap innerMap = | 952 closure.ClosureClassMap innerMap = |
| 908 compiler.closureToClassMapper.getMappingForNestedFunction(node); | 953 compiler.closureToClassMapper.getMappingForNestedFunction(node); |
| 909 closure.ClosureClassElement closureClass = innerMap.closureClassElement; | 954 closure.ClosureClassElement closureClass = innerMap.closureClassElement; |
| 910 return closureClass; | 955 return closureClass; |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 return compiler.typesTask.getGuaranteedTypeOfNode( | 1593 return compiler.typesTask.getGuaranteedTypeOfNode( |
| 1549 elements.analyzedElement, node); | 1594 elements.analyzedElement, node); |
| 1550 } | 1595 } |
| 1551 | 1596 |
| 1552 ir.Primitive visitLiteralList(ast.LiteralList node) { | 1597 ir.Primitive visitLiteralList(ast.LiteralList node) { |
| 1553 if (node.isConst) { | 1598 if (node.isConst) { |
| 1554 return translateConstant(node); | 1599 return translateConstant(node); |
| 1555 } | 1600 } |
| 1556 List<ir.Primitive> values = node.elements.nodes.mapToList(visit); | 1601 List<ir.Primitive> values = node.elements.nodes.mapToList(visit); |
| 1557 InterfaceType type = elements.getType(node); | 1602 InterfaceType type = elements.getType(node); |
| 1558 return irBuilder.buildListLiteral(type, values, | 1603 TypeMask allocationSiteType = getAllocationSiteType(node); |
| 1559 allocationSiteType: getAllocationSiteType(node)); | 1604 // TODO(sra): In checked mode, the elements must be checked as though |
| 1605 // operator[]= is called. |
| 1606 ir.Primitive list = irBuilder.buildListLiteral(type, values, |
| 1607 allocationSiteType: allocationSiteType); |
| 1608 if (type.treatAsRaw) return list; |
| 1609 // Call JSArray<E>.typed(allocation) to install the reified type. |
| 1610 ConstructorElement constructor = helpers.jsArrayTypedConstructor; |
| 1611 ir.Primitive tagged = irBuilder.buildConstructorInvocation( |
| 1612 constructor.effectiveTarget, |
| 1613 CallStructure.ONE_ARG, |
| 1614 constructor.computeEffectiveTargetType(type), |
| 1615 <ir.Primitive>[list], |
| 1616 sourceInformationBuilder.buildNew(node)); |
| 1617 |
| 1618 if (allocationSiteType == null) return tagged; |
| 1619 |
| 1620 return irBuilder.addPrimitive( |
| 1621 new ir.Refinement(tagged, allocationSiteType)); |
| 1560 } | 1622 } |
| 1561 | 1623 |
| 1562 ir.Primitive visitLiteralMap(ast.LiteralMap node) { | 1624 ir.Primitive visitLiteralMap(ast.LiteralMap node) { |
| 1563 assert(irBuilder.isOpen); | 1625 assert(irBuilder.isOpen); |
| 1564 if (node.isConst) { | 1626 if (node.isConst) { |
| 1565 return translateConstant(node); | 1627 return translateConstant(node); |
| 1566 } | 1628 } |
| 1567 | 1629 |
| 1568 InterfaceType type = elements.getType(node); | 1630 InterfaceType type = elements.getType(node); |
| 1569 | 1631 |
| (...skipping 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3827 } | 3889 } |
| 3828 | 3890 |
| 3829 Element get closureConverter { | 3891 Element get closureConverter { |
| 3830 return _backend.helpers.closureConverter; | 3892 return _backend.helpers.closureConverter; |
| 3831 } | 3893 } |
| 3832 | 3894 |
| 3833 void addNativeMethod(FunctionElement function) { | 3895 void addNativeMethod(FunctionElement function) { |
| 3834 _backend.emitter.nativeEmitter.nativeMethods.add(function); | 3896 _backend.emitter.nativeEmitter.nativeMethods.add(function); |
| 3835 } | 3897 } |
| 3836 } | 3898 } |
| OLD | NEW |