Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart

Issue 787603003: Generative constructors in the new dart backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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; 5 library dart2js.ir_builder;
6 6
7 import '../constants/expressions.dart'; 7 import '../constants/expressions.dart';
8 import '../constants/values.dart' show PrimitiveConstantValue; 8 import '../constants/values.dart' show PrimitiveConstantValue;
9 import '../dart_backend/dart_backend.dart' show DartBackend; 9 import '../dart_backend/dart_backend.dart' show DartBackend;
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 * statement on each branch. This includes functions with an empty body, 567 * statement on each branch. This includes functions with an empty body,
568 * such as `foo(){ }`. 568 * such as `foo(){ }`.
569 */ 569 */
570 void _ensureReturn() { 570 void _ensureReturn() {
571 if (!isOpen) return; 571 if (!isOpen) return;
572 ir.Constant constant = buildNullLiteral(); 572 ir.Constant constant = buildNullLiteral();
573 add(new ir.InvokeContinuation(state.returnContinuation, [constant])); 573 add(new ir.InvokeContinuation(state.returnContinuation, [constant]));
574 _current = null; 574 _current = null;
575 } 575 }
576 576
577 ir.SuperInitializer makeSuperInitializer(ConstructorElement target,
578 Selector selector,
579 List<ir.RunnableBody> arguments) {
580 return new ir.SuperInitializer(target, arguments, selector);
581 }
582
583 ir.FieldInitializer makeFieldInitializer(FieldElement element,
584 ir.RunnableBody body) {
585 return new ir.FieldInitializer(element, body);
586 }
587
577 /// Create a [ir.FieldDefinition] for the current [Element] using [_root] as 588 /// Create a [ir.FieldDefinition] for the current [Element] using [_root] as
578 /// the body using [initializer] as the initial value. 589 /// the body using [initializer] as the initial value.
579 ir.FieldDefinition makeFieldDefinition(ir.Primitive initializer) { 590 ir.FieldDefinition makeFieldDefinition(ir.Primitive initializer) {
580 if (initializer == null) { 591 if (initializer == null) {
581 return new ir.FieldDefinition.withoutInitializer(state.currentElement); 592 return new ir.FieldDefinition.withoutInitializer(state.currentElement);
582 } else { 593 } else {
583 buildReturn(initializer);
584 return new ir.FieldDefinition(state.currentElement, 594 return new ir.FieldDefinition(state.currentElement,
585 state.returnContinuation, 595 makeRunnableBody(initializer));
586 _root);
587 } 596 }
588 } 597 }
589 598
599 ir.RunnableBody makeRunnableBody([ir.Primitive value]) {
600 if (value == null) {
601 _ensureReturn();
602 } else {
603 buildReturn(value);
604 }
605 return new ir.RunnableBody(_root, state.returnContinuation);
606 }
607
590 /// Create a [ir.FunctionDefinition] for [element] using [_root] as the body. 608 /// Create a [ir.FunctionDefinition] for [element] using [_root] as the body.
591 /// 609 ///
592 /// Parameters must be created before the construction of the body using 610 /// Parameters must be created before the construction of the body using
593 /// [createFunctionParameter]. 611 /// [createFunctionParameter].
594 ir.FunctionDefinition makeFunctionDefinition( 612 ir.FunctionDefinition makeFunctionDefinition(
595 List<ConstantExpression> defaults) { 613 List<ConstantExpression> defaults) {
596 FunctionElement element = state.currentElement; 614 FunctionElement element = state.currentElement;
597 if (element.isAbstract || element.isExternal) { 615 if (element.isAbstract || element.isExternal) {
598 assert(invariant(element, _root == null, 616 assert(invariant(element, _root == null,
599 message: "Non-empty body for abstract method $element: $_root")); 617 message: "Non-empty body for abstract method $element: $_root"));
600 assert(invariant(element, state.localConstants.isEmpty, 618 assert(invariant(element, state.localConstants.isEmpty,
601 message: "Local constants for abstract method $element: " 619 message: "Local constants for abstract method $element: "
602 "${state.localConstants}")); 620 "${state.localConstants}"));
603 return new ir.FunctionDefinition.abstract( 621 return new ir.FunctionDefinition.abstract(
604 element, state.functionParameters, defaults); 622 element, state.functionParameters, defaults);
605 } else { 623 } else {
606 _ensureReturn();
607 return new ir.FunctionDefinition( 624 return new ir.FunctionDefinition(
608 element, state.returnContinuation, state.functionParameters, _root, 625 element, state.functionParameters, makeRunnableBody(),
609 state.localConstants, defaults, closure.getClosureList(element)); 626 state.localConstants, defaults, closure.getClosureList(element));
610 } 627 }
611 } 628 }
612 629
630 ir.ConstructorDefinition makeConstructorDefinition(
631 List<ConstantExpression> defaults, List<ir.Initializer> initializers) {
632 FunctionElement element = state.currentElement;
633 if (element.isExternal) {
634 assert(invariant(element, _root == null,
635 message: "Non-empty body for external constructor $element: $_root"));
636 assert(invariant(element, state.localConstants.isEmpty,
637 message: "Local constants for external constructor $element: "
638 "${state.localConstants}"));
639 return new ir.ConstructorDefinition.abstract(
640 element, state.functionParameters, defaults, element.isConst);
641 }
642 return new ir.ConstructorDefinition(
643 element, state.functionParameters, makeRunnableBody(), initializers,
floitsch 2014/12/08 17:45:02 assign "makeRunnableBody" to a temporary first, so
sigurdm 2014/12/09 09:57:10 Done.
644 state.localConstants, defaults, element.isConst,
645 closure.getClosureList(element));
646 }
647
613 /// Create a super invocation where the method name and the argument structure 648 /// Create a super invocation where the method name and the argument structure
614 /// are defined by [selector] and the argument values are defined by 649 /// are defined by [selector] and the argument values are defined by
615 /// [arguments]. 650 /// [arguments].
616 ir.Primitive buildSuperInvocation(Selector selector, 651 ir.Primitive buildSuperInvocation(Selector selector,
617 List<ir.Primitive> arguments) { 652 List<ir.Primitive> arguments) {
618 return _buildInvokeSuper(selector, arguments); 653 return _buildInvokeSuper(selector, arguments);
619 } 654 }
620 655
621 /// Create a getter invocation on the super class where the getter name is 656 /// Create a getter invocation on the super class where the getter name is
622 /// defined by [selector]. 657 /// defined by [selector].
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 index = 0; 1544 index = 0;
1510 for (int i = 0; i < environment.length; ++i) { 1545 for (int i = 0; i < environment.length; ++i) {
1511 if (common[i] == null) { 1546 if (common[i] == null) {
1512 environment.index2value[i] = parameters[index++]; 1547 environment.index2value[i] = parameters[index++];
1513 } 1548 }
1514 } 1549 }
1515 1550
1516 return join; 1551 return join;
1517 } 1552 }
1518 } 1553 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698