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

Side by Side Diff: frog/leg/resolver.dart

Issue 9245002: Support getters and setters. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 interface TreeElements { 5 interface TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 } 8 }
9 9
10 class TreeElementMapping implements TreeElements { 10 class TreeElementMapping implements TreeElements {
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 } else { 603 } else {
604 visit(node.argumentsNode); 604 visit(node.argumentsNode);
605 mapping.setSelector(node, Selector.BINARY_OPERATOR); 605 mapping.setSelector(node, Selector.BINARY_OPERATOR);
606 } 606 }
607 } else if (node.isIndex) { 607 } else if (node.isIndex) {
608 visit(node.argumentsNode); 608 visit(node.argumentsNode);
609 assert(node.arguments.tail.isEmpty()); 609 assert(node.arguments.tail.isEmpty());
610 mapping.setSelector(node, Selector.INDEX); 610 mapping.setSelector(node, Selector.INDEX);
611 } else if (node.isPropertyAccess) { 611 } else if (node.isPropertyAccess) {
612 mapping.setSelector(node, Selector.GETTER); 612 mapping.setSelector(node, Selector.GETTER);
613 if (target != null && target.kind == ElementKind.ABSTRACT_FIELD) {
614 AbstractFieldElement field = target;
615 target = field.getter;
616 }
613 } else { 617 } else {
614 int count = 0; 618 int count = 0;
615 List<SourceString> namedArguments = <SourceString>[]; 619 List<SourceString> namedArguments = <SourceString>[];
616 for (Link<Node> link = node.argumentsNode.nodes; 620 for (Link<Node> link = node.argumentsNode.nodes;
617 !link.isEmpty(); 621 !link.isEmpty();
618 link = link.tail) { 622 link = link.tail) {
619 count++; 623 count++;
620 Expression argument = link.head; 624 Expression argument = link.head;
621 visit(argument); 625 visit(argument);
622 if (argument.asNamedArgument() != null) { 626 if (argument.asNamedArgument() != null) {
623 NamedArgument named = argument; 627 NamedArgument named = argument;
624 namedArguments.add(named.name.source); 628 namedArguments.add(named.name.source);
625 } 629 }
626 } 630 }
627 mapping.setSelector(node, new Invocation(count, namedArguments)); 631 mapping.setSelector(node, new Invocation(count, namedArguments));
628 } 632 }
629 // TODO(ngeoffray): If target is a field, check that there's a 633 // TODO(ngeoffray): Warn if target is null and the send is
630 // getter. 634 // unqualified.
631 return useElement(node, target); 635 return useElement(node, target);
632 } 636 }
633 637
634 visitSendSet(SendSet node) { 638 visitSendSet(SendSet node) {
635 Element target = resolveSend(node); 639 Element target = resolveSend(node);
636 visit(node.argumentsNode); 640 Element setter = null;
637 // TODO(ngeoffray): If target is a field, check that there's a 641 Element getter = null;
638 // setter. 642 if (target != null && target.kind == ElementKind.ABSTRACT_FIELD) {
643 AbstractFieldElement field = target;
644 setter = field.setter;
645 getter = field.getter;
646 } else {
647 setter = target;
648 getter = target;
649 }
639 // TODO(ngeoffray): Check if the target can be assigned. 650 // TODO(ngeoffray): Check if the target can be assigned.
640 Identifier op = node.assignmentOperator; 651 Identifier op = node.assignmentOperator;
641 bool needsGetter = op.source.stringValue !== '='; 652 bool needsGetter = op.source.stringValue !== '=';
642 Selector selector; 653 Selector selector;
643 if (needsGetter) { 654 if (needsGetter) {
644 // Resolve the getter for the lhs (receiver+selector).
645 // Currently this is the same as the setter.
646 // TODO(ngeoffray): Adapt for fields.
647 Element getter;
648 if (node.isIndex) { 655 if (node.isIndex) {
649 selector = Selector.INDEX_AND_INDEX_SET; 656 selector = Selector.INDEX_AND_INDEX_SET;
650 getter = target;
651 } else { 657 } else {
652 selector = Selector.GETTER_AND_SETTER; 658 selector = Selector.GETTER_AND_SETTER;
653 // TODO(ngeoffray): Find the getter from the setter.
654 getter = target;
655 } 659 }
656 useElement(node.selector, getter); 660 useElement(node.selector, getter);
657 } else if (node.isIndex) { 661 } else if (node.isIndex) {
658 selector = Selector.INDEX_SET; 662 selector = Selector.INDEX_SET;
659 } else { 663 } else {
660 selector = Selector.SETTER; 664 selector = Selector.SETTER;
661 } 665 }
666 visit(node.argumentsNode);
662 mapping.setSelector(node, selector); 667 mapping.setSelector(node, selector);
663 return useElement(node, target); 668 // TODO(ngeoffray): Warn if target is null and the send is
669 // unqualified.
670 return useElement(node, setter);
664 } 671 }
665 672
666 visitLiteralInt(LiteralInt node) { 673 visitLiteralInt(LiteralInt node) {
667 } 674 }
668 675
669 visitLiteralDouble(LiteralDouble node) { 676 visitLiteralDouble(LiteralDouble node) {
670 } 677 }
671 678
672 visitLiteralBool(LiteralBool node) { 679 visitLiteralBool(LiteralBool node) {
673 } 680 }
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 class TopScope extends Scope { 1129 class TopScope extends Scope {
1123 Universe universe; 1130 Universe universe;
1124 1131
1125 TopScope(Universe this.universe) : super(null, null); 1132 TopScope(Universe this.universe) : super(null, null);
1126 Element lookup(SourceString name) => universe.find(name); 1133 Element lookup(SourceString name) => universe.find(name);
1127 1134
1128 Element add(Element element) { 1135 Element add(Element element) {
1129 throw "Cannot add an element in the top scope"; 1136 throw "Cannot add an element in the top scope";
1130 } 1137 }
1131 } 1138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698