| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 universe; | 5 library universe; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import '../common/names.dart' show |
| 10 Identifiers, |
| 11 Names, |
| 12 Selectors; |
| 9 import '../compiler.dart' show | 13 import '../compiler.dart' show |
| 10 Compiler; | 14 Compiler; |
| 11 import '../diagnostics/invariant.dart' show | 15 import '../diagnostics/invariant.dart' show |
| 12 invariant; | 16 invariant; |
| 13 import '../diagnostics/spannable.dart' show | 17 import '../diagnostics/spannable.dart' show |
| 14 SpannableAssertionFailure; | 18 SpannableAssertionFailure; |
| 15 import '../elements/elements.dart'; | 19 import '../elements/elements.dart'; |
| 16 import '../dart_types.dart'; | 20 import '../dart_types.dart'; |
| 17 import '../types/types.dart'; | 21 import '../types/types.dart'; |
| 18 import '../tree/tree.dart'; | 22 import '../tree/tree.dart'; |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 int get namedArgumentCount => callStructure.namedArgumentCount; | 670 int get namedArgumentCount => callStructure.namedArgumentCount; |
| 667 int get positionalArgumentCount => callStructure.positionalArgumentCount; | 671 int get positionalArgumentCount => callStructure.positionalArgumentCount; |
| 668 List<String> get namedArguments => callStructure.namedArguments; | 672 List<String> get namedArguments => callStructure.namedArguments; |
| 669 | 673 |
| 670 String get name => memberName.text; | 674 String get name => memberName.text; |
| 671 | 675 |
| 672 LibraryElement get library => memberName.library; | 676 LibraryElement get library => memberName.library; |
| 673 | 677 |
| 674 static const Name INDEX_NAME = const PublicName("[]"); | 678 static const Name INDEX_NAME = const PublicName("[]"); |
| 675 static const Name INDEX_SET_NAME = const PublicName("[]="); | 679 static const Name INDEX_SET_NAME = const PublicName("[]="); |
| 676 static const Name CALL_NAME = const PublicName(Compiler.CALL_OPERATOR_NAME); | 680 static const Name CALL_NAME = Names.call; |
| 677 | 681 |
| 678 Selector.internal(this.kind, | 682 Selector.internal(this.kind, |
| 679 this.memberName, | 683 this.memberName, |
| 680 this.callStructure, | 684 this.callStructure, |
| 681 this.hashCode) { | 685 this.hashCode) { |
| 682 assert(kind == SelectorKind.INDEX || | 686 assert(kind == SelectorKind.INDEX || |
| 683 (memberName != INDEX_NAME && memberName != INDEX_SET_NAME)); | 687 (memberName != INDEX_NAME && memberName != INDEX_SET_NAME)); |
| 684 assert(kind == SelectorKind.OPERATOR || | 688 assert(kind == SelectorKind.OPERATOR || |
| 685 kind == SelectorKind.INDEX || | 689 kind == SelectorKind.INDEX || |
| 686 !Elements.isOperatorName(memberName.text) || | 690 !Elements.isOperatorName(memberName.text) || |
| (...skipping 23 matching lines...) Expand all Loading... |
| 710 return existing; | 714 return existing; |
| 711 } | 715 } |
| 712 } | 716 } |
| 713 Selector result = new Selector.internal( | 717 Selector result = new Selector.internal( |
| 714 kind, name, callStructure, hashCode); | 718 kind, name, callStructure, hashCode); |
| 715 list.add(result); | 719 list.add(result); |
| 716 return result; | 720 return result; |
| 717 } | 721 } |
| 718 | 722 |
| 719 factory Selector.fromElement(Element element) { | 723 factory Selector.fromElement(Element element) { |
| 720 String name = element.name; | 724 Name name = new Name(element.name, element.library); |
| 721 if (element.isFunction) { | 725 if (element.isFunction) { |
| 722 if (name == '[]') { | 726 if (name == INDEX_NAME) { |
| 723 return new Selector.index(); | 727 return new Selector.index(); |
| 724 } else if (name == '[]=') { | 728 } else if (name == INDEX_SET_NAME) { |
| 725 return new Selector.indexSet(); | 729 return new Selector.indexSet(); |
| 726 } | 730 } |
| 727 FunctionSignature signature = | 731 FunctionSignature signature = |
| 728 element.asFunctionElement().functionSignature; | 732 element.asFunctionElement().functionSignature; |
| 729 int arity = signature.parameterCount; | 733 int arity = signature.parameterCount; |
| 730 List<String> namedArguments = null; | 734 List<String> namedArguments = null; |
| 731 if (signature.optionalParametersAreNamed) { | 735 if (signature.optionalParametersAreNamed) { |
| 732 namedArguments = | 736 namedArguments = |
| 733 signature.orderedOptionalParameters.map((e) => e.name).toList(); | 737 signature.orderedOptionalParameters.map((e) => e.name).toList(); |
| 734 } | 738 } |
| 735 if (element.isOperator) { | 739 if (element.isOperator) { |
| 736 // Operators cannot have named arguments, however, that doesn't prevent | 740 // Operators cannot have named arguments, however, that doesn't prevent |
| 737 // a user from declaring such an operator. | 741 // a user from declaring such an operator. |
| 738 return new Selector( | 742 return new Selector( |
| 739 SelectorKind.OPERATOR, | 743 SelectorKind.OPERATOR, |
| 740 new PublicName(name), | 744 name, |
| 741 new CallStructure(arity, namedArguments)); | 745 new CallStructure(arity, namedArguments)); |
| 742 } else { | 746 } else { |
| 743 return new Selector.call( | 747 return new Selector.call( |
| 744 name, element.library, arity, namedArguments); | 748 name, arity, namedArguments); |
| 745 } | 749 } |
| 746 } else if (element.isSetter) { | 750 } else if (element.isSetter) { |
| 747 return new Selector.setter(name, element.library); | 751 return new Selector.setter(name); |
| 748 } else if (element.isGetter) { | 752 } else if (element.isGetter) { |
| 749 return new Selector.getter(name, element.library); | 753 return new Selector.getter(name); |
| 750 } else if (element.isField) { | 754 } else if (element.isField) { |
| 751 return new Selector.getter(name, element.library); | 755 return new Selector.getter(name); |
| 752 } else if (element.isConstructor) { | 756 } else if (element.isConstructor) { |
| 753 return new Selector.callConstructor(name, element.library); | 757 return new Selector.callConstructor(name); |
| 754 } else { | 758 } else { |
| 755 throw new SpannableAssertionFailure( | 759 throw new SpannableAssertionFailure( |
| 756 element, "Can't get selector from $element"); | 760 element, "Can't get selector from $element"); |
| 757 } | 761 } |
| 758 } | 762 } |
| 759 | 763 |
| 760 factory Selector.getter(String name, LibraryElement library) | 764 factory Selector.getter(Name name) |
| 761 => new Selector(SelectorKind.GETTER, | 765 => new Selector(SelectorKind.GETTER, |
| 762 new Name(name, library), | 766 name.getter, |
| 763 CallStructure.NO_ARGS); | 767 CallStructure.NO_ARGS); |
| 764 | 768 |
| 765 factory Selector.getterFrom(Selector selector) | 769 factory Selector.getterFrom(Selector selector) |
| 766 => new Selector(SelectorKind.GETTER, | 770 => new Selector(SelectorKind.GETTER, |
| 767 selector.memberName.getter, | 771 selector.memberName.getter, |
| 768 CallStructure.NO_ARGS); | 772 CallStructure.NO_ARGS); |
| 769 | 773 |
| 770 factory Selector.setter(String name, LibraryElement library) | 774 factory Selector.setter(Name name) |
| 771 => new Selector(SelectorKind.SETTER, | 775 => new Selector(SelectorKind.SETTER, |
| 772 new Name(name, library, isSetter: true), | 776 name.setter, |
| 773 CallStructure.ONE_ARG); | 777 CallStructure.ONE_ARG); |
| 774 | 778 |
| 775 factory Selector.unaryOperator(String name) => new Selector( | 779 factory Selector.unaryOperator(String name) => new Selector( |
| 776 SelectorKind.OPERATOR, | 780 SelectorKind.OPERATOR, |
| 777 new PublicName(Elements.constructOperatorName(name, true)), | 781 new PublicName(Elements.constructOperatorName(name, true)), |
| 778 CallStructure.NO_ARGS); | 782 CallStructure.NO_ARGS); |
| 779 | 783 |
| 780 factory Selector.binaryOperator(String name) => new Selector( | 784 factory Selector.binaryOperator(String name) => new Selector( |
| 781 SelectorKind.OPERATOR, | 785 SelectorKind.OPERATOR, |
| 782 new PublicName(Elements.constructOperatorName(name, false)), | 786 new PublicName(Elements.constructOperatorName(name, false)), |
| 783 CallStructure.ONE_ARG); | 787 CallStructure.ONE_ARG); |
| 784 | 788 |
| 785 factory Selector.index() | 789 factory Selector.index() |
| 786 => new Selector(SelectorKind.INDEX, INDEX_NAME, | 790 => new Selector(SelectorKind.INDEX, INDEX_NAME, |
| 787 CallStructure.ONE_ARG); | 791 CallStructure.ONE_ARG); |
| 788 | 792 |
| 789 factory Selector.indexSet() | 793 factory Selector.indexSet() |
| 790 => new Selector(SelectorKind.INDEX, INDEX_SET_NAME, | 794 => new Selector(SelectorKind.INDEX, INDEX_SET_NAME, |
| 791 CallStructure.TWO_ARGS); | 795 CallStructure.TWO_ARGS); |
| 792 | 796 |
| 793 factory Selector.call(String name, | 797 factory Selector.call(Name name, |
| 794 LibraryElement library, | |
| 795 int arity, | 798 int arity, |
| 796 [List<String> namedArguments]) | 799 [List<String> namedArguments]) |
| 797 => new Selector(SelectorKind.CALL, | 800 => new Selector(SelectorKind.CALL, name, |
| 798 new Name(name, library), | |
| 799 new CallStructure(arity, namedArguments)); | 801 new CallStructure(arity, namedArguments)); |
| 800 | 802 |
| 801 factory Selector.callClosure(int arity, [List<String> namedArguments]) | 803 factory Selector.callClosure(int arity, [List<String> namedArguments]) |
| 802 => new Selector(SelectorKind.CALL, CALL_NAME, | 804 => new Selector(SelectorKind.CALL, CALL_NAME, |
| 803 new CallStructure(arity, namedArguments)); | 805 new CallStructure(arity, namedArguments)); |
| 804 | 806 |
| 805 factory Selector.callClosureFrom(Selector selector) | 807 factory Selector.callClosureFrom(Selector selector) |
| 806 => new Selector(SelectorKind.CALL, CALL_NAME, selector.callStructure); | 808 => new Selector(SelectorKind.CALL, CALL_NAME, selector.callStructure); |
| 807 | 809 |
| 808 factory Selector.callConstructor(String name, LibraryElement library, | 810 factory Selector.callConstructor(Name name, |
| 809 [int arity = 0, | 811 [int arity = 0, |
| 810 List<String> namedArguments]) | 812 List<String> namedArguments]) |
| 811 => new Selector(SelectorKind.CALL, new Name(name, library), | 813 => new Selector(SelectorKind.CALL, name, |
| 812 new CallStructure(arity, namedArguments)); | 814 new CallStructure(arity, namedArguments)); |
| 813 | 815 |
| 814 factory Selector.callDefaultConstructor() | 816 factory Selector.callDefaultConstructor() |
| 815 => new Selector( | 817 => new Selector( |
| 816 SelectorKind.CALL, | 818 SelectorKind.CALL, |
| 817 const PublicName(''), | 819 const PublicName(''), |
| 818 CallStructure.NO_ARGS); | 820 CallStructure.NO_ARGS); |
| 819 | 821 |
| 820 bool get isGetter => kind == SelectorKind.GETTER; | 822 bool get isGetter => kind == SelectorKind.GETTER; |
| 821 bool get isSetter => kind == SelectorKind.SETTER; | 823 bool get isSetter => kind == SelectorKind.SETTER; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 // Add bits from the call structure. | 911 // Add bits from the call structure. |
| 910 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); | 912 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); |
| 911 } | 913 } |
| 912 | 914 |
| 913 String toString() { | 915 String toString() { |
| 914 return 'Selector($kind, $name, ${callStructure.structureToString()})'; | 916 return 'Selector($kind, $name, ${callStructure.structureToString()})'; |
| 915 } | 917 } |
| 916 | 918 |
| 917 Selector toCallSelector() => new Selector.callClosureFrom(this); | 919 Selector toCallSelector() => new Selector.callClosureFrom(this); |
| 918 } | 920 } |
| OLD | NEW |