| 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 dart2js.resolution.members; | 5 library dart2js.resolution.members; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/names.dart' show | 8 import '../common/names.dart' show |
| 9 Selectors; | 9 Selectors; |
| 10 import '../common/resolution.dart' show | 10 import '../common/resolution.dart' show |
| (...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 // patch. | 1017 // patch. |
| 1018 Element target = currentClass.lookupSuperByName(name); | 1018 Element target = currentClass.lookupSuperByName(name); |
| 1019 // [target] may be null which means invoking noSuchMethod on super. | 1019 // [target] may be null which means invoking noSuchMethod on super. |
| 1020 if (target == null) { | 1020 if (target == null) { |
| 1021 if (alternateName != null) { | 1021 if (alternateName != null) { |
| 1022 target = currentClass.lookupSuperByName(alternateName); | 1022 target = currentClass.lookupSuperByName(alternateName); |
| 1023 } | 1023 } |
| 1024 Element error; | 1024 Element error; |
| 1025 if (selector.isSetter) { | 1025 if (selector.isSetter) { |
| 1026 error = reportAndCreateErroneousElement( | 1026 error = reportAndCreateErroneousElement( |
| 1027 node, name.text, MessageKind.SETTER_NOT_FOUND_IN_SUPER, | 1027 node, name.text, MessageKind.UNDEFINED_SUPER_SETTER, |
| 1028 {'className': currentClass.name, 'name': name}); | 1028 {'className': currentClass.name, 'name': name}); |
| 1029 } else { | 1029 } else { |
| 1030 error = reportAndCreateErroneousElement( | 1030 error = reportAndCreateErroneousElement( |
| 1031 node, name.text, MessageKind.NO_SUCH_SUPER_MEMBER, | 1031 node, name.text, MessageKind.NO_SUCH_SUPER_MEMBER, |
| 1032 {'className': currentClass.name, 'memberName': name}); | 1032 {'className': currentClass.name, 'memberName': name}); |
| 1033 } | 1033 } |
| 1034 if (target == null) { | 1034 if (target == null) { |
| 1035 // If a setter wasn't resolved, use the [ErroneousElement]. | 1035 // If a setter wasn't resolved, use the [ErroneousElement]. |
| 1036 target = error; | 1036 target = error; |
| 1037 } | 1037 } |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 // a constructor. | 1753 // a constructor. |
| 1754 | 1754 |
| 1755 // TODO(johnniwinther): With the simplified [TreeElements] invariant, | 1755 // TODO(johnniwinther): With the simplified [TreeElements] invariant, |
| 1756 // try to resolve injected elements if [currentClass] is in the patch | 1756 // try to resolve injected elements if [currentClass] is in the patch |
| 1757 // library of [receiverClass]. | 1757 // library of [receiverClass]. |
| 1758 | 1758 |
| 1759 // TODO(karlklose): this should be reported by the caller of | 1759 // TODO(karlklose): this should be reported by the caller of |
| 1760 // [resolveSend] to select better warning messages for getters and | 1760 // [resolveSend] to select better warning messages for getters and |
| 1761 // setters. | 1761 // setters. |
| 1762 ErroneousElement error = reportAndCreateErroneousElement( | 1762 ErroneousElement error = reportAndCreateErroneousElement( |
| 1763 node, name.text, MessageKind.MEMBER_NOT_FOUND, | 1763 node, name.text, MessageKind.UNDEFINED_GETTER, |
| 1764 {'className': receiverClass.name, 'memberName': name.text}); | 1764 {'className': receiverClass.name, 'memberName': name.text}); |
| 1765 // TODO(johnniwinther): Add an [AccessSemantics] for unresolved static | 1765 // TODO(johnniwinther): Add an [AccessSemantics] for unresolved static |
| 1766 // member access. | 1766 // member access. |
| 1767 return handleErroneousAccess( | 1767 return handleErroneousAccess( |
| 1768 node, name, new StaticAccess.unresolved(error)); | 1768 node, name, new StaticAccess.unresolved(error)); |
| 1769 } | 1769 } |
| 1770 | 1770 |
| 1771 /// Handle qualified update to an unresolved static class member, like | 1771 /// Handle qualified update to an unresolved static class member, like |
| 1772 /// `a.b = c` or `a.b++` where `a` is a class and `b` is unresolved. | 1772 /// `a.b = c` or `a.b++` where `a` is a class and `b` is unresolved. |
| 1773 ResolutionResult handleUnresolvedStaticMemberUpdate( | 1773 ResolutionResult handleUnresolvedStaticMemberUpdate( |
| 1774 SendSet node, Name name, ClassElement receiverClass) { | 1774 SendSet node, Name name, ClassElement receiverClass) { |
| 1775 // TODO(johnniwinther): Share code with [handleStaticInstanceMemberUpdate] | 1775 // TODO(johnniwinther): Share code with [handleStaticInstanceMemberUpdate] |
| 1776 // and [handlePrivateStaticMemberUpdate]. | 1776 // and [handlePrivateStaticMemberUpdate]. |
| 1777 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); | 1777 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); |
| 1778 // TODO(johnniwinther): Produce a different error if [name] is resolves to | 1778 // TODO(johnniwinther): Produce a different error if [name] is resolves to |
| 1779 // a constructor. | 1779 // a constructor. |
| 1780 | 1780 |
| 1781 // TODO(johnniwinther): With the simplified [TreeElements] invariant, | 1781 // TODO(johnniwinther): With the simplified [TreeElements] invariant, |
| 1782 // try to resolve injected elements if [currentClass] is in the patch | 1782 // try to resolve injected elements if [currentClass] is in the patch |
| 1783 // library of [receiverClass]. | 1783 // library of [receiverClass]. |
| 1784 | 1784 |
| 1785 // TODO(johnniwinther): Produce a different error for complex update. | 1785 // TODO(johnniwinther): Produce a different error for complex update. |
| 1786 ErroneousElement error = reportAndCreateErroneousElement( | 1786 ErroneousElement error = reportAndCreateErroneousElement( |
| 1787 node, name.text, MessageKind.MEMBER_NOT_FOUND, | 1787 node, name.text, MessageKind.UNDEFINED_GETTER, |
| 1788 {'className': receiverClass.name, 'memberName': name.text}); | 1788 {'className': receiverClass.name, 'memberName': name.text}); |
| 1789 // TODO(johnniwinther): Add an [AccessSemantics] for unresolved static | 1789 // TODO(johnniwinther): Add an [AccessSemantics] for unresolved static |
| 1790 // member access. | 1790 // member access. |
| 1791 return handleUpdate(node, name, new StaticAccess.unresolved(error)); | 1791 return handleUpdate(node, name, new StaticAccess.unresolved(error)); |
| 1792 } | 1792 } |
| 1793 | 1793 |
| 1794 /// Handle qualified access of an instance member, like `a.b` or `a.b()` where | 1794 /// Handle qualified access of an instance member, like `a.b` or `a.b()` where |
| 1795 /// `a` is a class and `b` is a non-static member. | 1795 /// `a` is a class and `b` is a non-static member. |
| 1796 ResolutionResult handleStaticInstanceMemberAccess( | 1796 ResolutionResult handleStaticInstanceMemberAccess( |
| 1797 Send node, Name name, ClassElement receiverClass, Element member) { | 1797 Send node, Name name, ClassElement receiverClass, Element member) { |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2647 } | 2647 } |
| 2648 | 2648 |
| 2649 /// Handle update of a parameter, local variable or local function. | 2649 /// Handle update of a parameter, local variable or local function. |
| 2650 ResolutionResult handleLocalUpdate(Send node, Name name, Element element) { | 2650 ResolutionResult handleLocalUpdate(Send node, Name name, Element element) { |
| 2651 AccessSemantics semantics; | 2651 AccessSemantics semantics; |
| 2652 ErroneousElement error; | 2652 ErroneousElement error; |
| 2653 if (element.isParameter) { | 2653 if (element.isParameter) { |
| 2654 if (element.isFinal) { | 2654 if (element.isFinal) { |
| 2655 error = reportAndCreateErroneousElement( | 2655 error = reportAndCreateErroneousElement( |
| 2656 node.selector, name.text, | 2656 node.selector, name.text, |
| 2657 MessageKind.CANNOT_RESOLVE_SETTER, const {}); | 2657 MessageKind.UNDEFINED_STATIC_SETTER_BUT_GETTER, |
| 2658 {'name': name}); |
| 2658 semantics = new StaticAccess.finalParameter(element); | 2659 semantics = new StaticAccess.finalParameter(element); |
| 2659 } else { | 2660 } else { |
| 2660 semantics = new StaticAccess.parameter(element); | 2661 semantics = new StaticAccess.parameter(element); |
| 2661 } | 2662 } |
| 2662 } else if (element.isVariable) { | 2663 } else if (element.isVariable) { |
| 2663 if (element.isFinal || element.isConst) { | 2664 if (element.isFinal || element.isConst) { |
| 2664 error = reportAndCreateErroneousElement( | 2665 error = reportAndCreateErroneousElement( |
| 2665 node.selector, name.text, | 2666 node.selector, name.text, |
| 2666 MessageKind.CANNOT_RESOLVE_SETTER, const {}); | 2667 MessageKind.UNDEFINED_STATIC_SETTER_BUT_GETTER, |
| 2668 {'name': name}); |
| 2667 semantics = new StaticAccess.finalLocalVariable(element); | 2669 semantics = new StaticAccess.finalLocalVariable(element); |
| 2668 } else { | 2670 } else { |
| 2669 semantics = new StaticAccess.localVariable(element); | 2671 semantics = new StaticAccess.localVariable(element); |
| 2670 } | 2672 } |
| 2671 } else { | 2673 } else { |
| 2672 assert(invariant(node, element.isFunction, | 2674 assert(invariant(node, element.isFunction, |
| 2673 message: "Unexpected local $element.")); | 2675 message: "Unexpected local $element.")); |
| 2674 error = reportAndCreateErroneousElement( | 2676 error = reportAndCreateErroneousElement( |
| 2675 node.selector, name.text, | 2677 node.selector, name.text, |
| 2676 MessageKind.ASSIGNING_METHOD, const {}); | 2678 MessageKind.ASSIGNING_METHOD, const {}); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2768 selector = callStructure.callSelector; | 2770 selector = callStructure.callSelector; |
| 2769 registry.registerDynamicUse( | 2771 registry.registerDynamicUse( |
| 2770 new DynamicUse(selector, null)); | 2772 new DynamicUse(selector, null)); |
| 2771 break; | 2773 break; |
| 2772 case AccessKind.STATIC_SETTER: | 2774 case AccessKind.STATIC_SETTER: |
| 2773 case AccessKind.TOPLEVEL_SETTER: | 2775 case AccessKind.TOPLEVEL_SETTER: |
| 2774 case AccessKind.UNRESOLVED: | 2776 case AccessKind.UNRESOLVED: |
| 2775 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); | 2777 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); |
| 2776 member = reportAndCreateErroneousElement( | 2778 member = reportAndCreateErroneousElement( |
| 2777 node.selector, name.text, | 2779 node.selector, name.text, |
| 2778 MessageKind.CANNOT_RESOLVE_GETTER, const {}); | 2780 MessageKind.UNDEFINED_STATIC_GETTER_BUT_SETTER, |
| 2781 {'name': name}); |
| 2779 break; | 2782 break; |
| 2780 default: | 2783 default: |
| 2781 reporter.internalError(node, | 2784 reporter.internalError(node, |
| 2782 "Unexpected statically resolved access $semantics."); | 2785 "Unexpected statically resolved access $semantics."); |
| 2783 break; | 2786 break; |
| 2784 } | 2787 } |
| 2785 registry.registerSendStructure(node, | 2788 registry.registerSendStructure(node, |
| 2786 isIncompatibleInvoke | 2789 isIncompatibleInvoke |
| 2787 ? new IncompatibleInvokeStructure(semantics, selector) | 2790 ? new IncompatibleInvokeStructure(semantics, selector) |
| 2788 : new InvokeStructure(semantics, selector)); | 2791 : new InvokeStructure(semantics, selector)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2802 case AccessKind.TOPLEVEL_GETTER: | 2805 case AccessKind.TOPLEVEL_GETTER: |
| 2803 registry.registerStaticUse( | 2806 registry.registerStaticUse( |
| 2804 new StaticUse.staticGet(semantics.element)); | 2807 new StaticUse.staticGet(semantics.element)); |
| 2805 break; | 2808 break; |
| 2806 case AccessKind.STATIC_SETTER: | 2809 case AccessKind.STATIC_SETTER: |
| 2807 case AccessKind.TOPLEVEL_SETTER: | 2810 case AccessKind.TOPLEVEL_SETTER: |
| 2808 case AccessKind.UNRESOLVED: | 2811 case AccessKind.UNRESOLVED: |
| 2809 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); | 2812 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); |
| 2810 member = reportAndCreateErroneousElement( | 2813 member = reportAndCreateErroneousElement( |
| 2811 node.selector, name.text, | 2814 node.selector, name.text, |
| 2812 MessageKind.CANNOT_RESOLVE_GETTER, const {}); | 2815 MessageKind.UNDEFINED_STATIC_GETTER_BUT_SETTER, |
| 2816 {'name': name}); |
| 2813 break; | 2817 break; |
| 2814 default: | 2818 default: |
| 2815 reporter.internalError(node, | 2819 reporter.internalError(node, |
| 2816 "Unexpected statically resolved access $semantics."); | 2820 "Unexpected statically resolved access $semantics."); |
| 2817 break; | 2821 break; |
| 2818 } | 2822 } |
| 2819 registry.registerSendStructure(node, new GetStructure(semantics)); | 2823 registry.registerSendStructure(node, new GetStructure(semantics)); |
| 2820 if (member.isConst) { | 2824 if (member.isConst) { |
| 2821 FieldElement field = member; | 2825 FieldElement field = member; |
| 2822 result = new ConstantResult( | 2826 result = new ConstantResult( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2836 | 2840 |
| 2837 /// Handle update of a static or top level [element]. | 2841 /// Handle update of a static or top level [element]. |
| 2838 ResolutionResult handleStaticOrTopLevelUpdate( | 2842 ResolutionResult handleStaticOrTopLevelUpdate( |
| 2839 SendSet node, Name name, Element element) { | 2843 SendSet node, Name name, Element element) { |
| 2840 AccessSemantics semantics; | 2844 AccessSemantics semantics; |
| 2841 if (element.isAbstractField) { | 2845 if (element.isAbstractField) { |
| 2842 AbstractFieldElement abstractField = element; | 2846 AbstractFieldElement abstractField = element; |
| 2843 if (abstractField.setter == null) { | 2847 if (abstractField.setter == null) { |
| 2844 ErroneousElement error = reportAndCreateErroneousElement( | 2848 ErroneousElement error = reportAndCreateErroneousElement( |
| 2845 node.selector, name.text, | 2849 node.selector, name.text, |
| 2846 MessageKind.CANNOT_RESOLVE_SETTER, const {}); | 2850 MessageKind.UNDEFINED_STATIC_SETTER_BUT_GETTER, |
| 2851 {'name': name}); |
| 2847 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); | 2852 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); |
| 2848 | 2853 |
| 2849 if (node.isComplex) { | 2854 if (node.isComplex) { |
| 2850 // `a++` or `a += b` where `a` has no setter. | 2855 // `a++` or `a += b` where `a` has no setter. |
| 2851 semantics = new CompoundAccessSemantics( | 2856 semantics = new CompoundAccessSemantics( |
| 2852 element.isTopLevel | 2857 element.isTopLevel |
| 2853 ? CompoundAccessKind.UNRESOLVED_TOPLEVEL_SETTER | 2858 ? CompoundAccessKind.UNRESOLVED_TOPLEVEL_SETTER |
| 2854 : CompoundAccessKind.UNRESOLVED_STATIC_SETTER, | 2859 : CompoundAccessKind.UNRESOLVED_STATIC_SETTER, |
| 2855 abstractField.getter, | 2860 abstractField.getter, |
| 2856 error); | 2861 error); |
| 2857 } else { | 2862 } else { |
| 2858 // `a = b` where `a` has no setter. | 2863 // `a = b` where `a` has no setter. |
| 2859 semantics = element.isTopLevel | 2864 semantics = element.isTopLevel |
| 2860 ? new StaticAccess.topLevelGetter(abstractField.getter) | 2865 ? new StaticAccess.topLevelGetter(abstractField.getter) |
| 2861 : new StaticAccess.staticGetter(abstractField.getter); | 2866 : new StaticAccess.staticGetter(abstractField.getter); |
| 2862 } | 2867 } |
| 2863 registry.registerStaticUse( | 2868 registry.registerStaticUse( |
| 2864 new StaticUse.staticGet(abstractField.getter)); | 2869 new StaticUse.staticGet(abstractField.getter)); |
| 2865 } else if (node.isComplex) { | 2870 } else if (node.isComplex) { |
| 2866 if (abstractField.getter == null) { | 2871 if (abstractField.getter == null) { |
| 2867 ErroneousElement error = reportAndCreateErroneousElement( | 2872 ErroneousElement error = reportAndCreateErroneousElement( |
| 2868 node.selector, name.text, | 2873 node.selector, name.text, |
| 2869 MessageKind.CANNOT_RESOLVE_GETTER, const {}); | 2874 MessageKind.UNDEFINED_STATIC_GETTER_BUT_SETTER, |
| 2875 {'name': name}); |
| 2870 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); | 2876 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); |
| 2871 // `a++` or `a += b` where `a` has no getter. | 2877 // `a++` or `a += b` where `a` has no getter. |
| 2872 semantics = new CompoundAccessSemantics( | 2878 semantics = new CompoundAccessSemantics( |
| 2873 element.isTopLevel | 2879 element.isTopLevel |
| 2874 ? CompoundAccessKind.UNRESOLVED_TOPLEVEL_GETTER | 2880 ? CompoundAccessKind.UNRESOLVED_TOPLEVEL_GETTER |
| 2875 : CompoundAccessKind.UNRESOLVED_STATIC_GETTER, | 2881 : CompoundAccessKind.UNRESOLVED_STATIC_GETTER, |
| 2876 error, | 2882 error, |
| 2877 abstractField.setter); | 2883 abstractField.setter); |
| 2878 registry.registerStaticUse( | 2884 registry.registerStaticUse( |
| 2879 new StaticUse.staticSet(abstractField.setter)); | 2885 new StaticUse.staticSet(abstractField.setter)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2924 // `a = b`, `a++` or `a += b` where `a` is a field. | 2930 // `a = b`, `a++` or `a += b` where `a` is a field. |
| 2925 assert(invariant(node, member.isField, | 2931 assert(invariant(node, member.isField, |
| 2926 message: "Unexpected element: $member.")); | 2932 message: "Unexpected element: $member.")); |
| 2927 if (node.isComplex) { | 2933 if (node.isComplex) { |
| 2928 // `a++` or `a += b` where `a` is a field. | 2934 // `a++` or `a += b` where `a` is a field. |
| 2929 registry.registerStaticUse(new StaticUse.staticGet(member)); | 2935 registry.registerStaticUse(new StaticUse.staticGet(member)); |
| 2930 } | 2936 } |
| 2931 if (member.isFinal || member.isConst) { | 2937 if (member.isFinal || member.isConst) { |
| 2932 ErroneousElement error = reportAndCreateErroneousElement( | 2938 ErroneousElement error = reportAndCreateErroneousElement( |
| 2933 node.selector, name.text, | 2939 node.selector, name.text, |
| 2934 MessageKind.CANNOT_RESOLVE_SETTER, const {}); | 2940 MessageKind.UNDEFINED_STATIC_SETTER_BUT_GETTER, |
| 2941 {'name': name}); |
| 2935 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); | 2942 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); |
| 2936 semantics = member.isTopLevel | 2943 semantics = member.isTopLevel |
| 2937 ? new StaticAccess.finalTopLevelField(member) | 2944 ? new StaticAccess.finalTopLevelField(member) |
| 2938 : new StaticAccess.finalStaticField(member); | 2945 : new StaticAccess.finalStaticField(member); |
| 2939 } else { | 2946 } else { |
| 2940 registry.registerStaticUse(new StaticUse.staticSet(member)); | 2947 registry.registerStaticUse(new StaticUse.staticSet(member)); |
| 2941 semantics = member.isTopLevel | 2948 semantics = member.isTopLevel |
| 2942 ? new StaticAccess.topLevelField(member) | 2949 ? new StaticAccess.topLevelField(member) |
| 2943 : new StaticAccess.staticField(member); | 2950 : new StaticAccess.staticField(member); |
| 2944 } | 2951 } |
| (...skipping 1918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4863 } | 4870 } |
| 4864 return const NoneResult(); | 4871 return const NoneResult(); |
| 4865 } | 4872 } |
| 4866 } | 4873 } |
| 4867 | 4874 |
| 4868 /// Looks up [name] in [scope] and unwraps the result. | 4875 /// Looks up [name] in [scope] and unwraps the result. |
| 4869 Element lookupInScope(DiagnosticReporter reporter, Node node, | 4876 Element lookupInScope(DiagnosticReporter reporter, Node node, |
| 4870 Scope scope, String name) { | 4877 Scope scope, String name) { |
| 4871 return Elements.unwrap(scope.lookup(name), reporter, node); | 4878 return Elements.unwrap(scope.lookup(name), reporter, node); |
| 4872 } | 4879 } |
| OLD | NEW |