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 closurelib; | 7 import '../closure.dart' as closurelib; |
8 import '../closure.dart' hide ClosureScope; | 8 import '../closure.dart' hide ClosureScope; |
9 import '../common/names.dart' show | 9 import '../common/names.dart' show |
10 Names, | 10 Names, |
11 Selectors; | 11 Selectors; |
12 import '../common/tasks.dart' show | 12 import '../common/tasks.dart' show |
13 CompilerTask; | 13 CompilerTask; |
14 import '../compiler.dart' show | 14 import '../compiler.dart' show |
15 Compiler; | 15 Compiler; |
16 import '../constants/expressions.dart'; | 16 import '../constants/expressions.dart'; |
17 import '../dart_types.dart'; | 17 import '../dart_types.dart'; |
| 18 import '../diagnostics/diagnostic_listener.dart' show |
| 19 DiagnosticReporter; |
18 import '../diagnostics/invariant.dart' show | 20 import '../diagnostics/invariant.dart' show |
19 invariant; | 21 invariant; |
20 import '../elements/elements.dart'; | 22 import '../elements/elements.dart'; |
21 import '../elements/modelx.dart' show | 23 import '../elements/modelx.dart' show |
22 SynthesizedConstructorElementX, | 24 SynthesizedConstructorElementX, |
23 ConstructorBodyElementX, | 25 ConstructorBodyElementX, |
24 FunctionSignatureX; | 26 FunctionSignatureX; |
25 import '../io/source_information.dart'; | 27 import '../io/source_information.dart'; |
26 import '../js_backend/js_backend.dart' show | 28 import '../js_backend/js_backend.dart' show |
27 JavaScriptBackend, | 29 JavaScriptBackend, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 : super(compiler); | 78 : super(compiler); |
77 | 79 |
78 String get name => 'CPS builder'; | 80 String get name => 'CPS builder'; |
79 | 81 |
80 ir.FunctionDefinition buildNode(AstElement element) { | 82 ir.FunctionDefinition buildNode(AstElement element) { |
81 return measure(() { | 83 return measure(() { |
82 bailoutMessage = null; | 84 bailoutMessage = null; |
83 | 85 |
84 TreeElements elementsMapping = element.resolvedAst.elements; | 86 TreeElements elementsMapping = element.resolvedAst.elements; |
85 element = element.implementation; | 87 element = element.implementation; |
86 return compiler.withCurrentElement(element, () { | 88 return reporter.withCurrentElement(element, () { |
87 SourceInformationBuilder sourceInformationBuilder = | 89 SourceInformationBuilder sourceInformationBuilder = |
88 sourceInformationStrategy.createBuilderForContext(element); | 90 sourceInformationStrategy.createBuilderForContext(element); |
89 | 91 |
90 IrBuilderVisitor builder = | 92 IrBuilderVisitor builder = |
91 new JsIrBuilderVisitor( | 93 new JsIrBuilderVisitor( |
92 elementsMapping, compiler, sourceInformationBuilder); | 94 elementsMapping, compiler, sourceInformationBuilder); |
93 ir.FunctionDefinition irNode = builder.buildExecutable(element); | 95 ir.FunctionDefinition irNode = builder.buildExecutable(element); |
94 if (irNode == null) { | 96 if (irNode == null) { |
95 bailoutMessage = builder.bailoutMessage; | 97 bailoutMessage = builder.bailoutMessage; |
96 } else if (builderCallback != null) { | 98 } else if (builderCallback != null) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // assigned in the delimited subexpression to their reaching definition --- | 155 // assigned in the delimited subexpression to their reaching definition --- |
154 // that is, the definition in effect at the hole in 'current'. These are | 156 // that is, the definition in effect at the hole in 'current'. These are |
155 // used to determine if a join-point continuation needs to be passed | 157 // used to determine if a join-point continuation needs to be passed |
156 // arguments, and what the arguments are. | 158 // arguments, and what the arguments are. |
157 | 159 |
158 /// Construct a top-level visitor. | 160 /// Construct a top-level visitor. |
159 IrBuilderVisitor(this.elements, | 161 IrBuilderVisitor(this.elements, |
160 this.compiler, | 162 this.compiler, |
161 this.sourceInformationBuilder); | 163 this.sourceInformationBuilder); |
162 | 164 |
| 165 DiagnosticReporter get reporter => compiler.reporter; |
| 166 |
163 String bailoutMessage = null; | 167 String bailoutMessage = null; |
164 | 168 |
165 @override | 169 @override |
166 ir.Primitive apply(ast.Node node, _) => node.accept(this); | 170 ir.Primitive apply(ast.Node node, _) => node.accept(this); |
167 | 171 |
168 @override | 172 @override |
169 SemanticSendVisitor get sendVisitor => this; | 173 SemanticSendVisitor get sendVisitor => this; |
170 | 174 |
171 /** | 175 /** |
172 * Builds the [ir.FunctionDefinition] for an executable element. In case the | 176 * Builds the [ir.FunctionDefinition] for an executable element. In case the |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 232 |
229 ir.Primitive visit(ast.Node node) => node.accept(this); | 233 ir.Primitive visit(ast.Node node) => node.accept(this); |
230 | 234 |
231 // ## Statements ## | 235 // ## Statements ## |
232 visitBlock(ast.Block node) { | 236 visitBlock(ast.Block node) { |
233 irBuilder.buildBlock(node.statements.nodes, build); | 237 irBuilder.buildBlock(node.statements.nodes, build); |
234 } | 238 } |
235 | 239 |
236 ir.Primitive visitBreakStatement(ast.BreakStatement node) { | 240 ir.Primitive visitBreakStatement(ast.BreakStatement node) { |
237 if (!irBuilder.buildBreak(elements.getTargetOf(node))) { | 241 if (!irBuilder.buildBreak(elements.getTargetOf(node))) { |
238 compiler.internalError(node, "'break' target not found"); | 242 reporter.internalError(node, "'break' target not found"); |
239 } | 243 } |
240 return null; | 244 return null; |
241 } | 245 } |
242 | 246 |
243 ir.Primitive visitContinueStatement(ast.ContinueStatement node) { | 247 ir.Primitive visitContinueStatement(ast.ContinueStatement node) { |
244 if (!irBuilder.buildContinue(elements.getTargetOf(node))) { | 248 if (!irBuilder.buildContinue(elements.getTargetOf(node))) { |
245 compiler.internalError(node, "'continue' target not found"); | 249 reporter.internalError(node, "'continue' target not found"); |
246 } | 250 } |
247 return null; | 251 return null; |
248 } | 252 } |
249 | 253 |
250 // Build(EmptyStatement, C) = C | 254 // Build(EmptyStatement, C) = C |
251 ir.Primitive visitEmptyStatement(ast.EmptyStatement node) { | 255 ir.Primitive visitEmptyStatement(ast.EmptyStatement node) { |
252 assert(irBuilder.isOpen); | 256 assert(irBuilder.isOpen); |
253 return null; | 257 return null; |
254 } | 258 } |
255 | 259 |
(...skipping 1996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2252 return action(); | 2256 return action(); |
2253 } catch(e) { | 2257 } catch(e) { |
2254 if (e == ABORT_IRNODE_BUILDER) { | 2258 if (e == ABORT_IRNODE_BUILDER) { |
2255 return null; | 2259 return null; |
2256 } | 2260 } |
2257 rethrow; | 2261 rethrow; |
2258 } | 2262 } |
2259 } | 2263 } |
2260 | 2264 |
2261 internalError(ast.Node node, String message) { | 2265 internalError(ast.Node node, String message) { |
2262 compiler.internalError(node, message); | 2266 reporter.internalError(node, message); |
2263 } | 2267 } |
2264 | 2268 |
2265 @override | 2269 @override |
2266 visitNode(ast.Node node) { | 2270 visitNode(ast.Node node) { |
2267 giveup(node, "Unhandled node"); | 2271 giveup(node, "Unhandled node"); |
2268 } | 2272 } |
2269 | 2273 |
2270 dynamic giveup(ast.Node node, [String reason]) { | 2274 dynamic giveup(ast.Node node, [String reason]) { |
2271 bailoutMessage = '($node): $reason'; | 2275 bailoutMessage = '($node): $reason'; |
2272 throw ABORT_IRNODE_BUILDER; | 2276 throw ABORT_IRNODE_BUILDER; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2640 root = buildStaticFieldInitializer(element); | 2644 root = buildStaticFieldInitializer(element); |
2641 } else { | 2645 } else { |
2642 // Instance field initializers are inlined in the constructor, | 2646 // Instance field initializers are inlined in the constructor, |
2643 // so we shouldn't need to build anything here. | 2647 // so we shouldn't need to build anything here. |
2644 // TODO(asgerf): But what should we return? | 2648 // TODO(asgerf): But what should we return? |
2645 return null; | 2649 return null; |
2646 } | 2650 } |
2647 break; | 2651 break; |
2648 | 2652 |
2649 default: | 2653 default: |
2650 compiler.internalError(element, "Unexpected element type $element"); | 2654 reporter.internalError(element, "Unexpected element type $element"); |
2651 } | 2655 } |
2652 return root; | 2656 return root; |
2653 }); | 2657 }); |
2654 } | 2658 } |
2655 | 2659 |
2656 ir.FunctionDefinition buildStaticFieldInitializer(FieldElement element) { | 2660 ir.FunctionDefinition buildStaticFieldInitializer(FieldElement element) { |
2657 if (!backend.constants.lazyStatics.contains(element)) { | 2661 if (!backend.constants.lazyStatics.contains(element)) { |
2658 return null; // Nothing to do. | 2662 return null; // Nothing to do. |
2659 } | 2663 } |
2660 closureClassMap = | 2664 closureClassMap = |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2899 Selector selector = elements.getSelector(initializer); | 2903 Selector selector = elements.getSelector(initializer); |
2900 List<ir.Primitive> arguments = initializer.arguments.mapToList(visit); | 2904 List<ir.Primitive> arguments = initializer.arguments.mapToList(visit); |
2901 evaluateConstructorCallFromInitializer( | 2905 evaluateConstructorCallFromInitializer( |
2902 target, | 2906 target, |
2903 selector.callStructure, | 2907 selector.callStructure, |
2904 arguments, | 2908 arguments, |
2905 supers, | 2909 supers, |
2906 fieldValues); | 2910 fieldValues); |
2907 hasConstructorCall = true; | 2911 hasConstructorCall = true; |
2908 } else { | 2912 } else { |
2909 compiler.internalError(initializer, | 2913 reporter.internalError(initializer, |
2910 "Unexpected initializer type $initializer"); | 2914 "Unexpected initializer type $initializer"); |
2911 } | 2915 } |
2912 } | 2916 } |
2913 } | 2917 } |
2914 // If no super() or this() was found, also call default superconstructor. | 2918 // If no super() or this() was found, also call default superconstructor. |
2915 if (!hasConstructorCall && !enclosingClass.isObject) { | 2919 if (!hasConstructorCall && !enclosingClass.isObject) { |
2916 ClassElement superClass = enclosingClass.superclass; | 2920 ClassElement superClass = enclosingClass.superclass; |
2917 FunctionElement target = superClass.lookupDefaultConstructor(); | 2921 FunctionElement target = superClass.lookupDefaultConstructor(); |
2918 if (target == null) { | 2922 if (target == null) { |
2919 compiler.internalError(superClass, "No default constructor available."); | 2923 reporter.internalError(superClass, "No default constructor available."); |
2920 } | 2924 } |
2921 target = target.implementation; | 2925 target = target.implementation; |
2922 evaluateConstructorCallFromInitializer( | 2926 evaluateConstructorCallFromInitializer( |
2923 target, | 2927 target, |
2924 CallStructure.NO_ARGS, | 2928 CallStructure.NO_ARGS, |
2925 const [], | 2929 const [], |
2926 supers, | 2930 supers, |
2927 fieldValues); | 2931 fieldValues); |
2928 } | 2932 } |
2929 // Add this constructor after the superconstructors. | 2933 // Add this constructor after the superconstructors. |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3365 internalError(node, 'Expected at least $minimum arguments.'); | 3369 internalError(node, 'Expected at least $minimum arguments.'); |
3366 } | 3370 } |
3367 } | 3371 } |
3368 | 3372 |
3369 /// Call a helper method from the isolate library. The isolate library uses | 3373 /// Call a helper method from the isolate library. The isolate library uses |
3370 /// its own isolate structure, that encapsulates dart2js's isolate. | 3374 /// its own isolate structure, that encapsulates dart2js's isolate. |
3371 ir.Primitive buildIsolateHelperInvocation(String helperName, | 3375 ir.Primitive buildIsolateHelperInvocation(String helperName, |
3372 CallStructure callStructure) { | 3376 CallStructure callStructure) { |
3373 Element element = backend.isolateHelperLibrary.find(helperName); | 3377 Element element = backend.isolateHelperLibrary.find(helperName); |
3374 if (element == null) { | 3378 if (element == null) { |
3375 compiler.internalError(node, | 3379 reporter.internalError(node, |
3376 'Isolate library and compiler mismatch.'); | 3380 'Isolate library and compiler mismatch.'); |
3377 } | 3381 } |
3378 List<ir.Primitive> arguments = translateStaticArguments(argumentList, | 3382 List<ir.Primitive> arguments = translateStaticArguments(argumentList, |
3379 element, callStructure); | 3383 element, callStructure); |
3380 return irBuilder.buildStaticFunctionInvocation(element, | 3384 return irBuilder.buildStaticFunctionInvocation(element, |
3381 callStructure, arguments, | 3385 callStructure, arguments, |
3382 sourceInformation: | 3386 sourceInformation: |
3383 sourceInformationBuilder.buildCall(node, node.selector)); | 3387 sourceInformationBuilder.buildCall(node, node.selector)); |
3384 } | 3388 } |
3385 | 3389 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3576 if (compiler.backend.isForeign(function)) { | 3580 if (compiler.backend.isForeign(function)) { |
3577 return handleForeignCode(node, function, argumentList, callStructure); | 3581 return handleForeignCode(node, function, argumentList, callStructure); |
3578 } else { | 3582 } else { |
3579 return irBuilder.buildStaticFunctionInvocation(function, callStructure, | 3583 return irBuilder.buildStaticFunctionInvocation(function, callStructure, |
3580 translateStaticArguments(argumentList, function, callStructure), | 3584 translateStaticArguments(argumentList, function, callStructure), |
3581 sourceInformation: | 3585 sourceInformation: |
3582 sourceInformationBuilder.buildCall(node, node.selector)); | 3586 sourceInformationBuilder.buildCall(node, node.selector)); |
3583 } | 3587 } |
3584 } | 3588 } |
3585 } | 3589 } |
OLD | NEW |