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 Identifiers, | 10 Identifiers, |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 irBuilder.addPrimitive(new ir.InvokeMethodDirectly( | 480 irBuilder.addPrimitive(new ir.InvokeMethodDirectly( |
481 instance, bodyElement, selector, bodyArguments, null)); | 481 instance, bodyElement, selector, bodyArguments, null)); |
482 } | 482 } |
483 | 483 |
484 // --- step 4: return the created object ---- | 484 // --- step 4: return the created object ---- |
485 irBuilder.buildReturn( | 485 irBuilder.buildReturn( |
486 value: instance, | 486 value: instance, |
487 sourceInformation: | 487 sourceInformation: |
488 sourceInformationBuilder.buildImplicitReturn(constructor)); | 488 sourceInformationBuilder.buildImplicitReturn(constructor)); |
489 | 489 |
490 return irBuilder.makeFunctionDefinition(); | 490 return irBuilder.makeFunctionDefinition( |
| 491 sourceInformationBuilder.buildVariableDeclaration()); |
491 }); | 492 }); |
492 } | 493 } |
493 | 494 |
494 /// Make a visitor suitable for translating ASTs taken from [context]. | 495 /// Make a visitor suitable for translating ASTs taken from [context]. |
495 /// | 496 /// |
496 /// Every visitor can only be applied to nodes in one context, because | 497 /// Every visitor can only be applied to nodes in one context, because |
497 /// the [elements] field is specific to that context. | 498 /// the [elements] field is specific to that context. |
498 IrBuilderVisitor makeVisitorForContext(AstElement context) { | 499 IrBuilderVisitor makeVisitorForContext(AstElement context) { |
499 return new IrBuilderVisitor( | 500 return new IrBuilderVisitor( |
500 context.resolvedAst.elements, | 501 context.resolvedAst.elements, |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 // TODO(kmillikin): We should combine closure conversion and try/catch | 732 // TODO(kmillikin): We should combine closure conversion and try/catch |
732 // variable analysis in some way. | 733 // variable analysis in some way. |
733 TryBoxedVariables variables = _analyzeTryBoxedVariables(node); | 734 TryBoxedVariables variables = _analyzeTryBoxedVariables(node); |
734 tryStatements = variables.tryStatements; | 735 tryStatements = variables.tryStatements; |
735 IrBuilder builder = getBuilderFor(body); | 736 IrBuilder builder = getBuilderFor(body); |
736 | 737 |
737 return withBuilder(builder, () { | 738 return withBuilder(builder, () { |
738 irBuilder.buildConstructorBodyHeader(getConstructorBodyParameters(body), | 739 irBuilder.buildConstructorBodyHeader(getConstructorBodyParameters(body), |
739 getClosureScopeForNode(node)); | 740 getClosureScopeForNode(node)); |
740 visit(node.body); | 741 visit(node.body); |
741 return irBuilder.makeFunctionDefinition(); | 742 return irBuilder.makeFunctionDefinition( |
| 743 sourceInformationBuilder.buildVariableDeclaration()); |
742 }); | 744 }); |
743 } | 745 } |
744 | 746 |
745 ir.FunctionDefinition buildFunction(FunctionElement element) { | 747 ir.FunctionDefinition buildFunction(FunctionElement element) { |
746 assert(invariant(element, element.isImplementation)); | 748 assert(invariant(element, element.isImplementation)); |
747 ast.FunctionExpression node = element.node; | 749 ast.FunctionExpression node = element.node; |
748 | 750 |
749 assert(!element.isSynthesized); | 751 assert(!element.isSynthesized); |
750 assert(node != null); | 752 assert(node != null); |
751 assert(elements[node] != null); | 753 assert(elements[node] != null); |
(...skipping 22 matching lines...) Expand all Loading... |
774 IrBuilder builder = getBuilderFor(element); | 776 IrBuilder builder = getBuilderFor(element); |
775 return withBuilder(builder, () { | 777 return withBuilder(builder, () { |
776 irBuilder.buildFunctionHeader(<Local>[]); | 778 irBuilder.buildFunctionHeader(<Local>[]); |
777 ir.Primitive initialValue = visit(element.initializer); | 779 ir.Primitive initialValue = visit(element.initializer); |
778 ast.VariableDefinitions node = element.node; | 780 ast.VariableDefinitions node = element.node; |
779 ast.SendSet sendSet = node.definitions.nodes.head; | 781 ast.SendSet sendSet = node.definitions.nodes.head; |
780 irBuilder.buildReturn( | 782 irBuilder.buildReturn( |
781 value: initialValue, | 783 value: initialValue, |
782 sourceInformation: | 784 sourceInformation: |
783 sourceInformationBuilder.buildReturn(sendSet.assignmentOperator)); | 785 sourceInformationBuilder.buildReturn(sendSet.assignmentOperator)); |
784 return irBuilder.makeFunctionDefinition(); | 786 return irBuilder.makeFunctionDefinition( |
| 787 sourceInformationBuilder.buildVariableDeclaration()); |
785 }); | 788 }); |
786 } | 789 } |
787 | 790 |
788 /// Builds the IR for a constant taken from a different [context]. | 791 /// Builds the IR for a constant taken from a different [context]. |
789 /// | 792 /// |
790 /// Such constants need to be compiled with a different [sourceFile] and | 793 /// Such constants need to be compiled with a different [sourceFile] and |
791 /// [elements] mapping. | 794 /// [elements] mapping. |
792 ir.Primitive inlineConstant(AstElement context, ast.Expression exp) { | 795 ir.Primitive inlineConstant(AstElement context, ast.Expression exp) { |
793 IrBuilderVisitor visitor = makeVisitorForContext(context); | 796 IrBuilderVisitor visitor = makeVisitorForContext(context); |
794 return visitor.withBuilder(irBuilder, () => visitor.translateConstant(exp)); | 797 return visitor.withBuilder(irBuilder, () => visitor.translateConstant(exp)); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 | 948 |
946 ir.Primitive refinement = irBuilder.addPrimitive( | 949 ir.Primitive refinement = irBuilder.addPrimitive( |
947 new ir.Refinement(allocation, typeMaskSystem.arrayType)); | 950 new ir.Refinement(allocation, typeMaskSystem.arrayType)); |
948 | 951 |
949 irBuilder.buildReturn(value: refinement, | 952 irBuilder.buildReturn(value: refinement, |
950 sourceInformation: | 953 sourceInformation: |
951 sourceInformationBuilder.buildImplicitReturn(element)); | 954 sourceInformationBuilder.buildImplicitReturn(element)); |
952 } else { | 955 } else { |
953 visit(node.body); | 956 visit(node.body); |
954 } | 957 } |
955 return irBuilder.makeFunctionDefinition(); | 958 return irBuilder.makeFunctionDefinition( |
| 959 sourceInformationBuilder.buildVariableDeclaration()); |
956 } | 960 } |
957 | 961 |
958 /// Builds the IR for creating an instance of the closure class corresponding | 962 /// Builds the IR for creating an instance of the closure class corresponding |
959 /// to the given nested function. | 963 /// to the given nested function. |
960 closure.ClosureClassElement makeSubFunction(ast.FunctionExpression node) { | 964 closure.ClosureClassElement makeSubFunction(ast.FunctionExpression node) { |
961 closure.ClosureClassMap innerMap = | 965 closure.ClosureClassMap innerMap = |
962 compiler.closureToClassMapper.getMappingForNestedFunction(node); | 966 compiler.closureToClassMapper.getMappingForNestedFunction(node); |
963 closure.ClosureClassElement closureClass = innerMap.closureClassElement; | 967 closure.ClosureClassElement closureClass = innerMap.closureClassElement; |
964 return closureClass; | 968 return closureClass; |
965 } | 969 } |
(...skipping 3077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4043 _backend.jsInteropAnalysis.hasAnonymousAnnotation(element.contextClass); | 4047 _backend.jsInteropAnalysis.hasAnonymousAnnotation(element.contextClass); |
4044 | 4048 |
4045 String getJsInteropTargetPath(FunctionElement element) { | 4049 String getJsInteropTargetPath(FunctionElement element) { |
4046 return '${_backend.namer.fixedBackendPath(element)}.' | 4050 return '${_backend.namer.fixedBackendPath(element)}.' |
4047 '${_backend.getFixedBackendName(element)}'; | 4051 '${_backend.getFixedBackendName(element)}'; |
4048 } | 4052 } |
4049 | 4053 |
4050 DartType get jsJavascriptObjectType => | 4054 DartType get jsJavascriptObjectType => |
4051 _backend.helpers.jsJavaScriptObjectClass.thisType; | 4055 _backend.helpers.jsJavaScriptObjectClass.thisType; |
4052 } | 4056 } |
OLD | NEW |