| OLD | NEW |
| 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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 ClassElement cls = resolveTypeRequired(node); | 584 ClassElement cls = resolveTypeRequired(node); |
| 585 if (cls.name == const SourceString('String') || | 585 if (cls.name == const SourceString('String') || |
| 586 cls.name == const SourceString('List') || | 586 cls.name == const SourceString('List') || |
| 587 cls.name == const SourceString('int') || | 587 cls.name == const SourceString('int') || |
| 588 cls.name == const SourceString('num') || | 588 cls.name == const SourceString('num') || |
| 589 cls.name == const SourceString('double')) { | 589 cls.name == const SourceString('double')) { |
| 590 cancel(node, "type test for ${cls.name} is not implemented"); | 590 cancel(node, "type test for ${cls.name} is not implemented"); |
| 591 } | 591 } |
| 592 } | 592 } |
| 593 | 593 |
| 594 void handleArguments(Send node) { |
| 595 int count = 0; |
| 596 List<SourceString> namedArguments = <SourceString>[]; |
| 597 for (Link<Node> link = node.argumentsNode.nodes; |
| 598 !link.isEmpty(); |
| 599 link = link.tail) { |
| 600 count++; |
| 601 Expression argument = link.head; |
| 602 visit(argument); |
| 603 if (argument.asNamedArgument() != null) { |
| 604 NamedArgument named = argument; |
| 605 namedArguments.add(named.name.source); |
| 606 } |
| 607 } |
| 608 mapping.setSelector(node, new Invocation(count, namedArguments)); |
| 609 } |
| 610 |
| 594 visitSend(Send node) { | 611 visitSend(Send node) { |
| 595 Element target = resolveSend(node); | 612 Element target = resolveSend(node); |
| 596 if (node.isOperator) { | 613 if (node.isOperator) { |
| 597 if (node.selector.asIdentifier().source.stringValue === 'is') { | 614 if (node.selector.asIdentifier().source.stringValue === 'is') { |
| 598 resolveTypeTest(node.arguments.head); | 615 resolveTypeTest(node.arguments.head); |
| 599 assert(node.arguments.tail.isEmpty()); | 616 assert(node.arguments.tail.isEmpty()); |
| 600 mapping.setSelector(node, Selector.BINARY_OPERATOR); | 617 mapping.setSelector(node, Selector.BINARY_OPERATOR); |
| 601 } else if (node.arguments.isEmpty()) { | 618 } else if (node.arguments.isEmpty()) { |
| 602 mapping.setSelector(node, Selector.UNARY_OPERATOR); | 619 mapping.setSelector(node, Selector.UNARY_OPERATOR); |
| 603 } else { | 620 } else { |
| 604 visit(node.argumentsNode); | 621 visit(node.argumentsNode); |
| 605 mapping.setSelector(node, Selector.BINARY_OPERATOR); | 622 mapping.setSelector(node, Selector.BINARY_OPERATOR); |
| 606 } | 623 } |
| 607 } else if (node.isIndex) { | 624 } else if (node.isIndex) { |
| 608 visit(node.argumentsNode); | 625 visit(node.argumentsNode); |
| 609 assert(node.arguments.tail.isEmpty()); | 626 assert(node.arguments.tail.isEmpty()); |
| 610 mapping.setSelector(node, Selector.INDEX); | 627 mapping.setSelector(node, Selector.INDEX); |
| 611 } else if (node.isPropertyAccess) { | 628 } else if (node.isPropertyAccess) { |
| 612 mapping.setSelector(node, Selector.GETTER); | 629 mapping.setSelector(node, Selector.GETTER); |
| 613 } else { | 630 } else { |
| 614 int count = 0; | 631 handleArguments(node); |
| 615 List<SourceString> namedArguments = <SourceString>[]; | |
| 616 for (Link<Node> link = node.argumentsNode.nodes; | |
| 617 !link.isEmpty(); | |
| 618 link = link.tail) { | |
| 619 count++; | |
| 620 Expression argument = link.head; | |
| 621 visit(argument); | |
| 622 if (argument.asNamedArgument() != null) { | |
| 623 NamedArgument named = argument; | |
| 624 namedArguments.add(named.name.source); | |
| 625 } | |
| 626 } | |
| 627 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): If target is a field, check that there's a |
| 630 // getter. | 634 // getter. |
| 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 visit(node.argumentsNode); |
| 637 // TODO(ngeoffray): If target is a field, check that there's a | 641 // TODO(ngeoffray): If target is a field, check that there's a |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 visit(node.expression); | 716 visit(node.expression); |
| 713 } | 717 } |
| 714 | 718 |
| 715 visitNewExpression(NewExpression node) { | 719 visitNewExpression(NewExpression node) { |
| 716 if (node.isConst()) cancel(node, 'const expressions are not implemented'); | 720 if (node.isConst()) cancel(node, 'const expressions are not implemented'); |
| 717 if (node.send.selector.asTypeAnnotation() === null) { | 721 if (node.send.selector.asTypeAnnotation() === null) { |
| 718 cancel( | 722 cancel( |
| 719 node, 'named constructors with type arguments are not implemented'); | 723 node, 'named constructors with type arguments are not implemented'); |
| 720 } | 724 } |
| 721 | 725 |
| 722 visit(node.send.argumentsNode); | |
| 723 | |
| 724 SourceString constructorName; | 726 SourceString constructorName; |
| 725 Node typeName = node.send.selector.asTypeAnnotation().typeName; | 727 Node typeName = node.send.selector.asTypeAnnotation().typeName; |
| 726 if (typeName.asSend() !== null) { | 728 if (typeName.asSend() !== null) { |
| 727 Identifier receiver = typeName.asSend().receiver.asIdentifier(); | 729 Identifier receiver = typeName.asSend().receiver.asIdentifier(); |
| 728 Identifier selector = typeName.asSend().selector.asIdentifier(); | 730 Identifier selector = typeName.asSend().selector.asIdentifier(); |
| 729 SourceString className = receiver.source; | 731 SourceString className = receiver.source; |
| 730 SourceString name = selector.source; | 732 SourceString name = selector.source; |
| 731 constructorName = Elements.constructConstructorName(className, name); | 733 constructorName = Elements.constructConstructorName(className, name); |
| 732 } else { | 734 } else { |
| 733 constructorName = typeName.asIdentifier().source; | 735 constructorName = typeName.asIdentifier().source; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 749 if (node.send.argumentCount() != function.parameterCount(compiler)) { | 751 if (node.send.argumentCount() != function.parameterCount(compiler)) { |
| 750 // TODO(ngeoffray): reslution error with wrong number of | 752 // TODO(ngeoffray): reslution error with wrong number of |
| 751 // parameters. We cannot do this rigth now because of the | 753 // parameters. We cannot do this rigth now because of the |
| 752 // List constructor. | 754 // List constructor. |
| 753 } | 755 } |
| 754 } | 756 } |
| 755 } else { | 757 } else { |
| 756 Node selector = node.send.selector; | 758 Node selector = node.send.selector; |
| 757 error(selector, MessageKind.CANNOT_RESOLVE_TYPE, [selector]); | 759 error(selector, MessageKind.CANNOT_RESOLVE_TYPE, [selector]); |
| 758 } | 760 } |
| 761 handleArguments(node.send); |
| 759 useElement(node.send, constructor); | 762 useElement(node.send, constructor); |
| 760 return null; | 763 return null; |
| 761 } | 764 } |
| 762 | 765 |
| 763 ClassElement resolveTypeRequired(Node node) { | 766 ClassElement resolveTypeRequired(Node node) { |
| 764 bool old = typeRequired; | 767 bool old = typeRequired; |
| 765 typeRequired = true; | 768 typeRequired = true; |
| 766 ClassElement cls = visit(node); | 769 ClassElement cls = visit(node); |
| 767 typeRequired = old; | 770 typeRequired = old; |
| 768 return cls; | 771 return cls; |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 class TopScope extends Scope { | 1125 class TopScope extends Scope { |
| 1123 Universe universe; | 1126 Universe universe; |
| 1124 | 1127 |
| 1125 TopScope(Universe this.universe) : super(null, null); | 1128 TopScope(Universe this.universe) : super(null, null); |
| 1126 Element lookup(SourceString name) => universe.find(name); | 1129 Element lookup(SourceString name) => universe.find(name); |
| 1127 | 1130 |
| 1128 Element add(Element element) { | 1131 Element add(Element element) { |
| 1129 throw "Cannot add an element in the top scope"; | 1132 throw "Cannot add an element in the top scope"; |
| 1130 } | 1133 } |
| 1131 } | 1134 } |
| OLD | NEW |