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 '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
(...skipping 2510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2521 if (Elements.isNativeOrExtendsNative(c)) { | 2521 if (Elements.isNativeOrExtendsNative(c)) { |
2522 // Native field is initialized elsewhere. | 2522 // Native field is initialized elsewhere. |
2523 } else { | 2523 } else { |
2524 // Fields without an initializer default to null. | 2524 // Fields without an initializer default to null. |
2525 // This value will be overwritten below if an initializer is found. | 2525 // This value will be overwritten below if an initializer is found. |
2526 fieldValues[field] = irBuilder.buildNullConstant(); | 2526 fieldValues[field] = irBuilder.buildNullConstant(); |
2527 } | 2527 } |
2528 } | 2528 } |
2529 }); | 2529 }); |
2530 } | 2530 } |
| 2531 // If this is a mixin constructor, it does not have its own parameter list |
| 2532 // or initializer list. Directly forward to the super constructor. |
| 2533 // Note that the declaration-site initializers originating from the |
| 2534 // mixed-in class were handled above. |
| 2535 if (enclosingClass.isMixinApplication) { |
| 2536 forwardSynthesizedMixinConstructor(constructor, supers, fieldValues); |
| 2537 return; |
| 2538 } |
2531 // Evaluate initializing parameters, e.g. `Foo(this.x)`. | 2539 // Evaluate initializing parameters, e.g. `Foo(this.x)`. |
2532 constructor.functionSignature.orderedForEachParameter( | 2540 constructor.functionSignature.orderedForEachParameter( |
2533 (ParameterElement parameter) { | 2541 (ParameterElement parameter) { |
2534 if (parameter.isInitializingFormal) { | 2542 if (parameter.isInitializingFormal) { |
2535 InitializingFormalElement fieldParameter = parameter; | 2543 InitializingFormalElement fieldParameter = parameter; |
2536 fieldValues[fieldParameter.fieldElement] = | 2544 fieldValues[fieldParameter.fieldElement] = |
2537 irBuilder.buildLocalVariableGet(parameter); | 2545 irBuilder.buildLocalVariableGet(parameter); |
2538 } | 2546 } |
2539 }); | 2547 }); |
2540 // Evaluate constructor initializers, e.g. `Foo() : x = 50`. | 2548 // Evaluate constructor initializers, e.g. `Foo() : x = 50`. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2587 /// | 2595 /// |
2588 /// Calls [loadArguments] and [evaluateConstructorFieldInitializers] in a | 2596 /// Calls [loadArguments] and [evaluateConstructorFieldInitializers] in a |
2589 /// visitor that has the proper [TreeElements] mapping. | 2597 /// visitor that has the proper [TreeElements] mapping. |
2590 void evaluateConstructorCallFromInitializer( | 2598 void evaluateConstructorCallFromInitializer( |
2591 ConstructorElement target, | 2599 ConstructorElement target, |
2592 CallStructure call, | 2600 CallStructure call, |
2593 List<ir.Primitive> arguments, | 2601 List<ir.Primitive> arguments, |
2594 List<ConstructorElement> supers, | 2602 List<ConstructorElement> supers, |
2595 Map<FieldElement, ir.Primitive> fieldValues) { | 2603 Map<FieldElement, ir.Primitive> fieldValues) { |
2596 JsIrBuilderVisitor visitor = makeVisitorForContext(target); | 2604 JsIrBuilderVisitor visitor = makeVisitorForContext(target); |
2597 return visitor.withBuilder(irBuilder, () { | 2605 visitor.withBuilder(irBuilder, () { |
2598 visitor.loadArguments(target, call, arguments); | 2606 visitor.loadArguments(target, call, arguments); |
2599 visitor.evaluateConstructorFieldInitializers(target, supers, fieldValues); | 2607 visitor.evaluateConstructorFieldInitializers(target, supers, fieldValues); |
2600 }); | 2608 }); |
2601 } | 2609 } |
2602 | 2610 |
| 2611 /// Evaluate the implicit super call in the given mixin constructor. |
| 2612 void forwardSynthesizedMixinConstructor( |
| 2613 ConstructorElement constructor, |
| 2614 List<ConstructorElement> supers, |
| 2615 Map<FieldElement, ir.Primitive> fieldValues) { |
| 2616 assert(constructor.enclosingClass.implementation.isMixinApplication); |
| 2617 assert(constructor.isSynthesized); |
| 2618 ConstructorElement target = |
| 2619 constructor.definingConstructor.implementation; |
| 2620 // The resolver gives us the exact same FunctionSignature for the two |
| 2621 // constructors. The parameters for the synthesized constructor |
| 2622 // are already in the environment, so the target constructor's parameters |
| 2623 // are also in the environment since their elements are the same. |
| 2624 assert(constructor.functionSignature == target.functionSignature); |
| 2625 JsIrBuilderVisitor visitor = makeVisitorForContext(target); |
| 2626 visitor.withBuilder(irBuilder, () { |
| 2627 visitor.evaluateConstructorFieldInitializers(target, supers, fieldValues); |
| 2628 }); |
| 2629 } |
| 2630 |
2603 /// Loads the type variables for all super classes of [superClass] into the | 2631 /// Loads the type variables for all super classes of [superClass] into the |
2604 /// IR builder's environment with their corresponding values. | 2632 /// IR builder's environment with their corresponding values. |
2605 /// | 2633 /// |
2606 /// The type variables for [currentClass] must already be in the IR builder's | 2634 /// The type variables for [currentClass] must already be in the IR builder's |
2607 /// environment. | 2635 /// environment. |
2608 /// | 2636 /// |
2609 /// Type variables are stored as [TypeVariableLocal] in the environment. | 2637 /// Type variables are stored as [TypeVariableLocal] in the environment. |
2610 /// | 2638 /// |
2611 /// This ensures that access to type variables mentioned inside the | 2639 /// This ensures that access to type variables mentioned inside the |
2612 /// constructors and initializers will happen through the local environment | 2640 /// constructors and initializers will happen through the local environment |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3252 } | 3280 } |
3253 | 3281 |
3254 processSetStatic(ir.SetStatic node) { | 3282 processSetStatic(ir.SetStatic node) { |
3255 node.body = replacementFor(node.body); | 3283 node.body = replacementFor(node.body); |
3256 } | 3284 } |
3257 | 3285 |
3258 processContinuation(ir.Continuation node) { | 3286 processContinuation(ir.Continuation node) { |
3259 node.body = replacementFor(node.body); | 3287 node.body = replacementFor(node.body); |
3260 } | 3288 } |
3261 } | 3289 } |
OLD | NEW |