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 Identifiers, Names, Selectors; | 9 import '../common/names.dart' show Identifiers, Names, Selectors; |
10 import '../common/tasks.dart' show CompilerTask; | 10 import '../common/tasks.dart' show CompilerTask; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // We translate a ClosureScope from closure.dart into IR builder's variant | 186 // We translate a ClosureScope from closure.dart into IR builder's variant |
187 // because the IR builder should not depend on the synthetic elements | 187 // because the IR builder should not depend on the synthetic elements |
188 // created in closure.dart. | 188 // created in closure.dart. |
189 return new ClosureScope(closureClassMap.capturingScopes[node]); | 189 return new ClosureScope(closureClassMap.capturingScopes[node]); |
190 } | 190 } |
191 | 191 |
192 /// Returns the [ClosureScope] for any function, possibly different from the | 192 /// Returns the [ClosureScope] for any function, possibly different from the |
193 /// one currently being built. | 193 /// one currently being built. |
194 ClosureScope getClosureScopeForFunction(FunctionElement function) { | 194 ClosureScope getClosureScopeForFunction(FunctionElement function) { |
195 closure.ClosureClassMap map = compiler.closureToClassMapper | 195 closure.ClosureClassMap map = compiler.closureToClassMapper |
196 .computeClosureToClassMapping(function, function.node, elements); | 196 .computeClosureToClassMapping(function.resolvedAst); |
197 return new ClosureScope(map.capturingScopes[function.node]); | 197 return new ClosureScope(map.capturingScopes[function.node]); |
198 } | 198 } |
199 | 199 |
200 /// If the current function is a nested function with free variables (or a | 200 /// If the current function is a nested function with free variables (or a |
201 /// captured reference to `this`), returns a [ClosureEnvironment] | 201 /// captured reference to `this`), returns a [ClosureEnvironment] |
202 /// indicating how to access these. | 202 /// indicating how to access these. |
203 ClosureEnvironment getClosureEnvironment() { | 203 ClosureEnvironment getClosureEnvironment() { |
204 return new ClosureEnvironment(closureClassMap); | 204 return new ClosureEnvironment(closureClassMap); |
205 } | 205 } |
206 | 206 |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 } | 707 } |
708 | 708 |
709 /// Builds the IR for the body of a constructor. | 709 /// Builds the IR for the body of a constructor. |
710 /// | 710 /// |
711 /// This function is invoked from one or more "factory" constructors built by | 711 /// This function is invoked from one or more "factory" constructors built by |
712 /// [buildConstructor]. | 712 /// [buildConstructor]. |
713 ir.FunctionDefinition buildConstructorBody(ConstructorBodyElement body) { | 713 ir.FunctionDefinition buildConstructorBody(ConstructorBodyElement body) { |
714 ConstructorElement constructor = body.constructor; | 714 ConstructorElement constructor = body.constructor; |
715 ast.FunctionExpression node = constructor.node; | 715 ast.FunctionExpression node = constructor.node; |
716 closureClassMap = compiler.closureToClassMapper | 716 closureClassMap = compiler.closureToClassMapper |
717 .computeClosureToClassMapping(constructor, node, elements); | 717 .computeClosureToClassMapping(constructor.resolvedAst); |
718 | 718 |
719 // We compute variables boxed in mutable variables on entry to each try | 719 // We compute variables boxed in mutable variables on entry to each try |
720 // block, not including variables captured by a closure (which are boxed | 720 // block, not including variables captured by a closure (which are boxed |
721 // in the heap). This duplicates some of the work of closure conversion | 721 // in the heap). This duplicates some of the work of closure conversion |
722 // without directly using the results. This duplication is wasteful and | 722 // without directly using the results. This duplication is wasteful and |
723 // error-prone. | 723 // error-prone. |
724 // TODO(kmillikin): We should combine closure conversion and try/catch | 724 // TODO(kmillikin): We should combine closure conversion and try/catch |
725 // variable analysis in some way. | 725 // variable analysis in some way. |
726 TryBoxedVariables variables = _analyzeTryBoxedVariables(node); | 726 TryBoxedVariables variables = _analyzeTryBoxedVariables(node); |
727 tryStatements = variables.tryStatements; | 727 tryStatements = variables.tryStatements; |
(...skipping 10 matching lines...) Expand all Loading... |
738 | 738 |
739 ir.FunctionDefinition buildFunction(FunctionElement element) { | 739 ir.FunctionDefinition buildFunction(FunctionElement element) { |
740 assert(invariant(element, element.isImplementation)); | 740 assert(invariant(element, element.isImplementation)); |
741 ast.FunctionExpression node = element.node; | 741 ast.FunctionExpression node = element.node; |
742 | 742 |
743 assert(!element.isSynthesized); | 743 assert(!element.isSynthesized); |
744 assert(node != null); | 744 assert(node != null); |
745 assert(elements[node] != null); | 745 assert(elements[node] != null); |
746 | 746 |
747 closureClassMap = compiler.closureToClassMapper | 747 closureClassMap = compiler.closureToClassMapper |
748 .computeClosureToClassMapping(element, node, elements); | 748 .computeClosureToClassMapping(element.resolvedAst); |
749 TryBoxedVariables variables = _analyzeTryBoxedVariables(node); | 749 TryBoxedVariables variables = _analyzeTryBoxedVariables(node); |
750 tryStatements = variables.tryStatements; | 750 tryStatements = variables.tryStatements; |
751 IrBuilder builder = getBuilderFor(element); | 751 IrBuilder builder = getBuilderFor(element); |
752 return withBuilder( | 752 return withBuilder( |
753 builder, () => _makeFunctionBody(builder, element, node)); | 753 builder, () => _makeFunctionBody(builder, element, node)); |
754 } | 754 } |
755 | 755 |
756 ir.FunctionDefinition buildStaticFieldInitializer(FieldElement element) { | 756 ir.FunctionDefinition buildStaticFieldInitializer(FieldElement element) { |
757 if (!backend.constants.lazyStatics.contains(element)) { | 757 if (!backend.constants.lazyStatics.contains(element)) { |
758 return null; // Nothing to do. | 758 return null; // Nothing to do. |
759 } | 759 } |
760 closureClassMap = compiler.closureToClassMapper | 760 closureClassMap = compiler.closureToClassMapper |
761 .computeClosureToClassMapping(element, element.node, elements); | 761 .computeClosureToClassMapping(element.resolvedAst); |
762 IrBuilder builder = getBuilderFor(element); | 762 IrBuilder builder = getBuilderFor(element); |
763 return withBuilder(builder, () { | 763 return withBuilder(builder, () { |
764 irBuilder.buildFunctionHeader(<Local>[]); | 764 irBuilder.buildFunctionHeader(<Local>[]); |
765 ir.Primitive initialValue = visit(element.initializer); | 765 ir.Primitive initialValue = visit(element.initializer); |
766 ast.VariableDefinitions node = element.node; | 766 ast.VariableDefinitions node = element.node; |
767 ast.SendSet sendSet = node.definitions.nodes.head; | 767 ast.SendSet sendSet = node.definitions.nodes.head; |
768 irBuilder.buildReturn( | 768 irBuilder.buildReturn( |
769 value: initialValue, | 769 value: initialValue, |
770 sourceInformation: | 770 sourceInformation: |
771 sourceInformationBuilder.buildReturn(sendSet.assignmentOperator)); | 771 sourceInformationBuilder.buildReturn(sendSet.assignmentOperator)); |
(...skipping 3247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4019 _backend.jsInteropAnalysis.hasAnonymousAnnotation(element.contextClass); | 4019 _backend.jsInteropAnalysis.hasAnonymousAnnotation(element.contextClass); |
4020 | 4020 |
4021 String getJsInteropTargetPath(FunctionElement element) { | 4021 String getJsInteropTargetPath(FunctionElement element) { |
4022 return '${_backend.namer.fixedBackendPath(element)}.' | 4022 return '${_backend.namer.fixedBackendPath(element)}.' |
4023 '${_backend.nativeData.getFixedBackendName(element)}'; | 4023 '${_backend.nativeData.getFixedBackendName(element)}'; |
4024 } | 4024 } |
4025 | 4025 |
4026 DartType get jsJavascriptObjectType => | 4026 DartType get jsJavascriptObjectType => |
4027 _backend.helpers.jsJavaScriptObjectClass.thisType; | 4027 _backend.helpers.jsJavaScriptObjectClass.thisType; |
4028 } | 4028 } |
OLD | NEW |