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

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: Rebased 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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 * statement on each branch. This includes functions with an empty body, 573 * statement on each branch. This includes functions with an empty body,
574 * such as `foo(){ }`. 574 * such as `foo(){ }`.
575 */ 575 */
576 void _ensureReturn() { 576 void _ensureReturn() {
577 if (!isOpen) return; 577 if (!isOpen) return;
578 ir.Constant constant = buildNullLiteral(); 578 ir.Constant constant = buildNullLiteral();
579 add(new ir.InvokeContinuation(state.returnContinuation, [constant])); 579 add(new ir.InvokeContinuation(state.returnContinuation, [constant]));
580 _current = null; 580 _current = null;
581 } 581 }
582 582
583 ir.SuperInitializer makeSuperInitializer(ConstructorElement target,
Kevin Millikin (Google) 2014/12/11 09:28:25 Is there any reason that this function takes the a
sigurdm 2014/12/17 10:20:56 No reason besides oversight.
584 Selector selector,
585 List<ir.RunnableBody> arguments) {
586 return new ir.SuperInitializer(target, arguments, selector);
587 }
588
589 ir.FieldInitializer makeFieldInitializer(FieldElement element,
590 ir.RunnableBody body) {
591 return new ir.FieldInitializer(element, body);
592 }
593
583 /// Create a [ir.FieldDefinition] for the current [Element] using [_root] as 594 /// Create a [ir.FieldDefinition] for the current [Element] using [_root] as
584 /// the body using [initializer] as the initial value. 595 /// the body using [initializer] as the initial value.
585 ir.FieldDefinition makeFieldDefinition(ir.Primitive initializer) { 596 ir.FieldDefinition makeFieldDefinition(ir.Primitive initializer) {
586 if (initializer == null) { 597 if (initializer == null) {
587 return new ir.FieldDefinition.withoutInitializer(state.currentElement); 598 return new ir.FieldDefinition.withoutInitializer(state.currentElement);
588 } else { 599 } else {
589 buildReturn(initializer); 600 ir.RunnableBody body = makeRunnableBody();
590 return new ir.FieldDefinition(state.currentElement, 601 return new ir.FieldDefinition(state.currentElement, body);
591 state.returnContinuation,
592 _root);
593 } 602 }
594 } 603 }
595 604
605 ir.RunnableBody makeRunnableBody([ir.Primitive value]) {
606 if (value == null) {
607 _ensureReturn();
608 } else {
609 buildReturn(value);
610 }
611 return new ir.RunnableBody(_root, state.returnContinuation);
612 }
613
596 /// Create a [ir.FunctionDefinition] for [element] using [_root] as the body. 614 /// Create a [ir.FunctionDefinition] for [element] using [_root] as the body.
597 /// 615 ///
598 /// Parameters must be created before the construction of the body using 616 /// Parameters must be created before the construction of the body using
599 /// [createFunctionParameter]. 617 /// [createFunctionParameter].
600 ir.FunctionDefinition makeFunctionDefinition( 618 ir.FunctionDefinition makeFunctionDefinition(
601 List<ConstantExpression> defaults) { 619 List<ConstantExpression> defaults) {
602 FunctionElement element = state.currentElement; 620 FunctionElement element = state.currentElement;
603 if (element.isAbstract || element.isExternal) { 621 if (element.isAbstract || element.isExternal) {
604 assert(invariant(element, _root == null, 622 assert(invariant(element, _root == null,
605 message: "Non-empty body for abstract method $element: $_root")); 623 message: "Non-empty body for abstract method $element: $_root"));
606 assert(invariant(element, state.localConstants.isEmpty, 624 assert(invariant(element, state.localConstants.isEmpty,
607 message: "Local constants for abstract method $element: " 625 message: "Local constants for abstract method $element: "
608 "${state.localConstants}")); 626 "${state.localConstants}"));
609 return new ir.FunctionDefinition.abstract( 627 return new ir.FunctionDefinition.abstract(
610 element, state.functionParameters, defaults); 628 element, state.functionParameters, defaults);
611 } else { 629 } else {
612 _ensureReturn(); 630 ir.RunnableBody body = makeRunnableBody();
613 return new ir.FunctionDefinition( 631 return new ir.FunctionDefinition(
614 element, state.returnContinuation, state.functionParameters, _root, 632 element, state.functionParameters, body,
615 state.localConstants, defaults, closure.getClosureList(element)); 633 state.localConstants, defaults, closure.getClosureList(element));
616 } 634 }
617 } 635 }
618 636
637 ir.ConstructorDefinition makeConstructorDefinition(
638 List<ConstantExpression> defaults, List<ir.Initializer> initializers) {
639 FunctionElement element = state.currentElement;
640 if (element.isExternal) {
641 assert(invariant(element, _root == null,
642 message: "Non-empty body for external constructor $element: $_root"));
643 assert(invariant(element, state.localConstants.isEmpty,
644 message: "Local constants for external constructor $element: "
645 "${state.localConstants}"));
646 return new ir.ConstructorDefinition.abstract(
647 element, state.functionParameters, defaults, element.isConst);
648 }
649 ir.RunnableBody body = makeRunnableBody();
650 return new ir.ConstructorDefinition(
651 element, state.functionParameters, body, initializers,
652 state.localConstants, defaults, element.isConst,
Kevin Millikin (Google) 2014/12/11 09:28:25 Since we're passing in element, maybe it's better
sigurdm 2014/12/17 10:20:56 Removed the isConst property from tre_ir and cps_i
653 closure.getClosureList(element));
654 }
655
619 /// Create a super invocation where the method name and the argument structure 656 /// Create a super invocation where the method name and the argument structure
620 /// are defined by [selector] and the argument values are defined by 657 /// are defined by [selector] and the argument values are defined by
621 /// [arguments]. 658 /// [arguments].
622 ir.Primitive buildSuperInvocation(Selector selector, 659 ir.Primitive buildSuperInvocation(Selector selector,
623 List<ir.Primitive> arguments) { 660 List<ir.Primitive> arguments) {
624 return _buildInvokeSuper(selector, arguments); 661 return _buildInvokeSuper(selector, arguments);
625 } 662 }
626 663
627 /// Create a getter invocation on the super class where the getter name is 664 /// Create a getter invocation on the super class where the getter name is
628 /// defined by [selector]. 665 /// defined by [selector].
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 index = 0; 1552 index = 0;
1516 for (int i = 0; i < environment.length; ++i) { 1553 for (int i = 0; i < environment.length; ++i) {
1517 if (common[i] == null) { 1554 if (common[i] == null) {
1518 environment.index2value[i] = parameters[index++]; 1555 environment.index2value[i] = parameters[index++];
1519 } 1556 }
1520 } 1557 }
1521 1558
1522 return join; 1559 return join;
1523 } 1560 }
1524 } 1561 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698