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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ir/ir_builder.dart

Issue 278823002: dart2dart: Method and constructor calls in new backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Formatting and copyright notice. Created 6 years, 7 months 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 'ir_nodes.dart' as ir; 7 import 'ir_nodes.dart' as ir;
8 import '../elements/elements.dart'; 8 import '../elements/elements.dart';
9 import '../dart2jslib.dart'; 9 import '../dart2jslib.dart';
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
11 import '../source_file.dart'; 11 import '../source_file.dart';
12 import '../tree/tree.dart' as ast; 12 import '../tree/tree.dart' as ast;
13 import '../scanner/scannerlib.dart' show Token; 13 import '../scanner/scannerlib.dart' show Token, isUserDefinableOperator;
14 import '../dart_backend/dart_backend.dart' show DartBackend; 14 import '../dart_backend/dart_backend.dart' show DartBackend;
15 import 'ir_pickler.dart' show Unpickler, IrConstantPool; 15 import 'ir_pickler.dart' show Unpickler, IrConstantPool;
16 import '../universe/universe.dart' show SelectorKind;
16 17
17 /** 18 /**
18 * This task iterates through all resolved elements and builds [ir.Node]s. The 19 * This task iterates through all resolved elements and builds [ir.Node]s. The
19 * nodes are stored in the [nodes] map and accessible through [hasIr] and 20 * nodes are stored in the [nodes] map and accessible through [hasIr] and
20 * [getIr]. 21 * [getIr].
21 * 22 *
22 * The functionality of the IrNodes is added gradually, therefore elements might 23 * The functionality of the IrNodes is added gradually, therefore elements might
23 * have an IR or not, depending on the language features that are used. For 24 * have an IR or not, depending on the language features that are used. For
24 * elements that do have an IR, the tree [ast.Node]s and the [Token]s are not 25 * elements that do have an IR, the tree [ast.Node]s and the [Token]s are not
25 * used in the rest of the compilation. This is ensured by setting the element's 26 * used in the rest of the compilation. This is ensured by setting the element's
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 } 572 }
572 573
573 574
574 ir.Primitive visitLiteralNull(ast.LiteralNull node) { 575 ir.Primitive visitLiteralNull(ast.LiteralNull node) {
575 assert(isOpen); 576 assert(isOpen);
576 ir.Constant constant = new ir.Constant(constantSystem.createNull()); 577 ir.Constant constant = new ir.Constant(constantSystem.createNull());
577 add(new ir.LetPrim(constant)); 578 add(new ir.LetPrim(constant));
578 return constant; 579 return constant;
579 } 580 }
580 581
581 // TODO(kmillikin): other literals. Strings require quoting and escaping 582 ir.Primitive visitLiteralString(ast.LiteralString node) {
582 // in the Dart backend. 583 assert(isOpen);
583 // LiteralString 584 ir.Constant constant =
585 new ir.Constant(constantSystem.createString(node.dartString));
586 add(new ir.LetPrim(constant));
587 return constant;
588 }
589
590 // TODO(kmillikin): other literals.
584 // LiteralList 591 // LiteralList
585 // LiteralMap 592 // LiteralMap
586 // LiteralMapEntry 593 // LiteralMapEntry
587 // LiteralSymbol 594 // LiteralSymbol
588 595
589 ir.Primitive visitParenthesizedExpression( 596 ir.Primitive visitParenthesizedExpression(
590 ast.ParenthesizedExpression node) { 597 ast.ParenthesizedExpression node) {
591 assert(isOpen); 598 assert(isOpen);
592 return visit(node.expression); 599 return visit(node.expression);
593 } 600 }
594 601
595 // ==== Sends ==== 602 // ==== Sends ====
596 ir.Primitive visitAssert(ast.Send node) { 603 ir.Primitive visitAssert(ast.Send node) {
597 assert(isOpen); 604 assert(isOpen);
598 return giveup(); 605 return giveup();
599 } 606 }
600 607
601 ir.Primitive visitClosureSend(ast.Send node) { 608 ir.Primitive visitClosureSend(ast.Send node) {
602 assert(isOpen); 609 assert(isOpen);
603 return giveup(); 610 return giveup();
604 } 611 }
605 612
606 ir.Primitive visitDynamicSend(ast.Send node) { 613 ir.Primitive visitDynamicSend(ast.Send node) {
614 if (node.receiver == null || node.receiver.isSuper()) {
615 return giveup();
616 }
607 assert(isOpen); 617 assert(isOpen);
608 return giveup(); 618 Selector selector = elements.getSelector(node);
619 ir.Primitive receiver = visit(node.receiver);
620 List arguments = node.arguments.toList(growable:false)
621 .map(visit).toList(growable:false);
622 ir.Parameter v = new ir.Parameter(null);
623 ir.Continuation k = new ir.Continuation([v]);
624 ir.Expression invoke =
625 new ir.InvokeMethod(receiver, selector, k, arguments);
626 add(new ir.LetCont(k, invoke));
627 return v;
609 } 628 }
610 629
611 ir.Primitive visitGetterSend(ast.Send node) { 630 ir.Primitive visitGetterSend(ast.Send node) {
612 assert(isOpen); 631 assert(isOpen);
613 Element element = elements[node]; 632 Element element = elements[node];
614 if (!Elements.isLocal(element)) return giveup(); 633 if (Elements.isLocal(element)) {
615 int index = variableIndex[element]; 634 int index = variableIndex[element];
616 ir.Primitive value = assignedVars[index]; 635 ir.Primitive value = assignedVars[index];
617 return value == null ? freeVars[index] : value; 636 return value == null ? freeVars[index] : value;
637 } else if (Elements.isInstanceField(element)) {
638 ir.Primitive receiver = visit(node.receiver);
639 ir.Parameter v = new ir.Parameter(null);
640 ir.Continuation k = new ir.Continuation([v]);
641 Selector selector = elements.getSelector(node);
642 assert(selector.kind == SelectorKind.GETTER);
643 ir.InvokeMethod invoke = new ir.InvokeMethod(receiver, selector, k, []);
644 add(new ir.LetCont(k, invoke));
645 return v;
646 } else {
647 // TODO(asgerf): static and top-level
648 // NOTE: Index-getters are OperatorSends, not GetterSends
649 return giveup();
650 }
618 } 651 }
619 652
620 ir.Primitive visitOperatorSend(ast.Send node) { 653 ir.Primitive visitOperatorSend(ast.Send node) {
621 assert(isOpen); 654 ast.Operator selectorNode = node.selector;
622 return giveup(); 655 if (!isUserDefinableOperator(selectorNode.source)) {
656 return giveup();
657 } else {
658 return visitDynamicSend(node);
659 }
623 } 660 }
624 661
625 // Build(StaticSend(f, arguments), C) = C[C'[InvokeStatic(f, xs)]] 662 // Build(StaticSend(f, arguments), C) = C[C'[InvokeStatic(f, xs)]]
626 // where (C', xs) = arguments.fold(Build, C) 663 // where (C', xs) = arguments.fold(Build, C)
627 ir.Primitive visitStaticSend(ast.Send node) { 664 ir.Primitive visitStaticSend(ast.Send node) {
628 assert(isOpen); 665 assert(isOpen);
629 Element element = elements[node]; 666 Element element = elements[node];
630 // TODO(lry): support static fields. (separate IR instruction?) 667 // TODO(lry): support static fields. (separate IR instruction?)
631 if (element.isField || element.isGetter) return giveup(); 668 if (element.isField || element.isGetter) return giveup();
632 // TODO(kmillikin): support static setters. 669 // TODO(kmillikin): support static setters.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 708 }
672 709
673 ir.Primitive visitTypeReferenceSend(ast.Send node) { 710 ir.Primitive visitTypeReferenceSend(ast.Send node) {
674 assert(isOpen); 711 assert(isOpen);
675 return giveup(); 712 return giveup();
676 } 713 }
677 714
678 ir.Primitive visitSendSet(ast.SendSet node) { 715 ir.Primitive visitSendSet(ast.SendSet node) {
679 assert(isOpen); 716 assert(isOpen);
680 Element element = elements[node]; 717 Element element = elements[node];
681 if (!Elements.isLocal(element)) return giveup();
682 if (node.assignmentOperator.source != '=') return giveup(); 718 if (node.assignmentOperator.source != '=') return giveup();
683 // Exactly one argument expected for a simple assignment. 719 if (Elements.isLocal(element)) {
684 assert(!node.arguments.isEmpty); 720 // Exactly one argument expected for a simple assignment.
685 assert(node.arguments.tail.isEmpty); 721 assert(!node.arguments.isEmpty);
686 ir.Primitive result = visit(node.arguments.head); 722 assert(node.arguments.tail.isEmpty);
687 assignedVars[variableIndex[element]] = result; 723 ir.Primitive result = visit(node.arguments.head);
688 return result; 724 assignedVars[variableIndex[element]] = result;
725 return result;
726 } else if (Elements.isStaticOrTopLevel(element)) {
727 // TODO(asgerf): static and top-level
728 return giveup();
729 } else if (node.receiver == null) {
730 // Nodes that fall in this case:
731 // - Unresolved top-level
732 // - Assignment to final variable (will not be resolved)
733 return giveup();
734 } else {
735 // Setter or index-setter invocation
736 assert(node.receiver != null);
737 if (node.receiver.isSuper()) return giveup();
738
739 ir.Primitive receiver = visit(node.receiver);
740 ir.Parameter v = new ir.Parameter(null);
741 ir.Continuation k = new ir.Continuation([v]);
742 Selector selector = elements.getSelector(node);
743 assert(selector.kind == SelectorKind.SETTER ||
744 selector.kind == SelectorKind.INDEX);
745 List<ir.Definition> args = node.arguments.toList(growable:false)
746 .map(visit).toList(growable:false);
747 ir.InvokeMethod invoke = new ir.InvokeMethod(receiver, selector, k, args);
748 add(new ir.LetCont(k, invoke));
749 return args.last;
750 }
751 }
752
753 ir.Primitive visitNewExpression(ast.NewExpression node) {
754 if (node.isConst) {
755 return giveup(); // TODO(asgerf): Const constructor call.
756 }
757 FunctionElement element = elements[node.send];
758 if (Elements.isUnresolved(element)) {
759 return giveup();
760 }
761 ast.Node selector = node.send.selector;
762 GenericType type = elements.getType(node);
763 ir.Parameter v = new ir.Parameter(null);
764 ir.Continuation k = new ir.Continuation([v]);
765 List<ir.Definition> args = node.send.arguments.toList(growable:false)
766 .map(visit).toList(growable:false);
767 ir.InvokeConstructor invoke = new ir.InvokeConstructor(
768 type,
769 element,
770 k,
771 args);
772 add(new ir.LetCont(k, invoke));
773 return v;
689 } 774 }
690 775
691 static final String ABORT_IRNODE_BUILDER = "IrNode builder aborted"; 776 static final String ABORT_IRNODE_BUILDER = "IrNode builder aborted";
692 777
693 ir.Primitive giveup() => throw ABORT_IRNODE_BUILDER; 778 ir.Primitive giveup() => throw ABORT_IRNODE_BUILDER;
694 779
695 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) { 780 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) {
696 try { 781 try {
697 return action(); 782 return action();
698 } catch(e) { 783 } catch(e) {
(...skipping 12 matching lines...) Expand all
711 bool visit(DartType type, Null _) => type.accept(this, null); 796 bool visit(DartType type, Null _) => type.accept(this, null);
712 797
713 bool visitType(DartType type, Null _) => false; 798 bool visitType(DartType type, Null _) => false;
714 799
715 bool visitVoidType(VoidType type, Null _) => true; 800 bool visitVoidType(VoidType type, Null _) => true;
716 801
717 // Currently, InterfaceType and TypedefType are supported so long as they 802 // Currently, InterfaceType and TypedefType are supported so long as they
718 // do not have type parameters. They are subclasses of GenericType. 803 // do not have type parameters. They are subclasses of GenericType.
719 bool visitGenericType(GenericType type, Null _) => !type.isGeneric; 804 bool visitGenericType(GenericType type, Null _) => !type.isGeneric;
720 } 805 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698