| 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 part of resolution; | 5 part of resolution; |
| 6 | 6 |
| 7 abstract class TreeElements { | 7 abstract class TreeElements { |
| 8 AnalyzableElement get analyzedElement; | 8 AnalyzableElement get analyzedElement; |
| 9 Iterable<Node> get superUses; | 9 Iterable<Node> get superUses; |
| 10 | 10 |
| (...skipping 2597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2608 registry.registerAssert(node); | 2608 registry.registerAssert(node); |
| 2609 registry.registerSendStructure(node, sendStructure); | 2609 registry.registerSendStructure(node, sendStructure); |
| 2610 return const AssertResult(); | 2610 return const AssertResult(); |
| 2611 } | 2611 } |
| 2612 | 2612 |
| 2613 return node.selector.accept(this); | 2613 return node.selector.accept(this); |
| 2614 } | 2614 } |
| 2615 | 2615 |
| 2616 var oldCategory = allowedCategory; | 2616 var oldCategory = allowedCategory; |
| 2617 allowedCategory |= ElementCategory.PREFIX | ElementCategory.SUPER; | 2617 allowedCategory |= ElementCategory.PREFIX | ElementCategory.SUPER; |
| 2618 |
| 2619 bool oldSendIsMemberAccess = sendIsMemberAccess; |
| 2620 int oldAllowedCategory = allowedCategory; |
| 2621 |
| 2622 // Conditional sends like `e?.foo` treat the receiver as an expression. So |
| 2623 // `C?.foo` needs to be treated like `(C).foo`, not like C.foo. Prefixes and |
| 2624 // super are not allowed on their own in that context. |
| 2625 if (node.isConditional) { |
| 2626 sendIsMemberAccess = false; |
| 2627 allowedCategory = |
| 2628 ElementCategory.VARIABLE | |
| 2629 ElementCategory.FUNCTION | |
| 2630 ElementCategory.IMPLIES_TYPE; |
| 2631 } |
| 2618 ResolutionResult resolvedReceiver = visit(node.receiver); | 2632 ResolutionResult resolvedReceiver = visit(node.receiver); |
| 2633 if (node.isConditional) { |
| 2634 sendIsMemberAccess = oldSendIsMemberAccess; |
| 2635 allowedCategory = oldAllowedCategory; |
| 2636 } |
| 2637 |
| 2619 allowedCategory = oldCategory; | 2638 allowedCategory = oldCategory; |
| 2620 | 2639 |
| 2621 Element target; | 2640 Element target; |
| 2622 String name = node.selector.asIdentifier().source; | 2641 String name = node.selector.asIdentifier().source; |
| 2623 if (identical(name, 'this')) { | 2642 if (identical(name, 'this')) { |
| 2624 // TODO(ahe): Why is this using GENERIC? | 2643 // TODO(ahe): Why is this using GENERIC? |
| 2625 error(node.selector, MessageKind.GENERIC, | 2644 error(node.selector, MessageKind.GENERIC, |
| 2626 {'text': "expected an identifier"}); | 2645 {'text': "expected an identifier"}); |
| 2627 return null; | 2646 return null; |
| 2628 } else if (node.isSuperCall) { | 2647 } else if (node.isSuperCall) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2733 if (node.isIndex) { | 2752 if (node.isIndex) { |
| 2734 return isSet ? new Selector.indexSet() : new Selector.index(); | 2753 return isSet ? new Selector.indexSet() : new Selector.index(); |
| 2735 } | 2754 } |
| 2736 | 2755 |
| 2737 if (node.isOperator) { | 2756 if (node.isOperator) { |
| 2738 String source = node.selector.asOperator().source; | 2757 String source = node.selector.asOperator().source; |
| 2739 String string = source; | 2758 String string = source; |
| 2740 if (identical(string, '!') || | 2759 if (identical(string, '!') || |
| 2741 identical(string, '&&') || identical(string, '||') || | 2760 identical(string, '&&') || identical(string, '||') || |
| 2742 identical(string, 'is') || identical(string, 'as') || | 2761 identical(string, 'is') || identical(string, 'as') || |
| 2743 identical(string, '?') || | 2762 identical(string, '?') || identical(string, '??') || |
| 2744 identical(string, '>>>')) { | 2763 identical(string, '>>>')) { |
| 2745 return null; | 2764 return null; |
| 2746 } | 2765 } |
| 2747 String op = source; | 2766 String op = source; |
| 2748 if (!isUserDefinableOperator(source)) { | 2767 if (!isUserDefinableOperator(source)) { |
| 2749 op = Elements.mapToUserOperatorOrNull(source); | 2768 op = Elements.mapToUserOperatorOrNull(source); |
| 2750 } | 2769 } |
| 2751 if (op == null) { | 2770 if (op == null) { |
| 2752 // Unsupported operator. An error has been reported during parsing. | 2771 // Unsupported operator. An error has been reported during parsing. |
| 2753 return new Selector.call( | 2772 return new Selector.call( |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2938 registry.registerAsCheck(type); | 2957 registry.registerAsCheck(type); |
| 2939 } | 2958 } |
| 2940 resolvedArguments = true; | 2959 resolvedArguments = true; |
| 2941 } else if (identical(operatorString, '&&')) { | 2960 } else if (identical(operatorString, '&&')) { |
| 2942 doInPromotionScope(node.arguments.head, | 2961 doInPromotionScope(node.arguments.head, |
| 2943 () => resolveArguments(node.argumentsNode)); | 2962 () => resolveArguments(node.argumentsNode)); |
| 2944 sendStructure = const LogicalAndStructure(); | 2963 sendStructure = const LogicalAndStructure(); |
| 2945 resolvedArguments = true; | 2964 resolvedArguments = true; |
| 2946 } else if (operatorString == '||') { | 2965 } else if (operatorString == '||') { |
| 2947 sendStructure = const LogicalOrStructure(); | 2966 sendStructure = const LogicalOrStructure(); |
| 2967 } else if (operatorString == '??') { |
| 2968 sendStructure = const IfNullStructure(); |
| 2948 } | 2969 } |
| 2949 if (sendStructure != null) { | 2970 if (sendStructure != null) { |
| 2950 registry.registerSendStructure(node, sendStructure); | 2971 registry.registerSendStructure(node, sendStructure); |
| 2951 } | 2972 } |
| 2952 } | 2973 } |
| 2953 | 2974 |
| 2954 if (!resolvedArguments) { | 2975 if (!resolvedArguments) { |
| 2955 resolveArguments(node.argumentsNode); | 2976 resolveArguments(node.argumentsNode); |
| 2956 } | 2977 } |
| 2957 | 2978 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3052 MessageKind.CANNOT_RESOLVE_SETTER, const {}); | 3073 MessageKind.CANNOT_RESOLVE_SETTER, const {}); |
| 3053 registry.registerThrowNoSuchMethod(); | 3074 registry.registerThrowNoSuchMethod(); |
| 3054 } | 3075 } |
| 3055 } | 3076 } |
| 3056 if (isComplex && getter == null && !inInstanceContext) { | 3077 if (isComplex && getter == null && !inInstanceContext) { |
| 3057 getter = reportAndCreateErroneousElement(node.selector, field.name, | 3078 getter = reportAndCreateErroneousElement(node.selector, field.name, |
| 3058 MessageKind.CANNOT_RESOLVE_GETTER, const {}); | 3079 MessageKind.CANNOT_RESOLVE_GETTER, const {}); |
| 3059 registry.registerThrowNoSuchMethod(); | 3080 registry.registerThrowNoSuchMethod(); |
| 3060 } | 3081 } |
| 3061 } else if (target.impliesType) { | 3082 } else if (target.impliesType) { |
| 3062 setter = reportAndCreateErroneousElement(node.selector, target.name, | 3083 if (node.isIfNullAssignment) { |
| 3063 MessageKind.ASSIGNING_TYPE, const {}); | 3084 setter = reportAndCreateErroneousElement(node.selector, target.name, |
| 3064 registry.registerThrowNoSuchMethod(); | 3085 MessageKind.IF_NULL_ASSIGNING_TYPE, const {}); |
| 3086 // In this case, no assignment happens, the rest of the compiler can |
| 3087 // treat the expression `C ??= e` as if it's just reading `C`. |
| 3088 } else { |
| 3089 setter = reportAndCreateErroneousElement(node.selector, target.name, |
| 3090 MessageKind.ASSIGNING_TYPE, const {}); |
| 3091 registry.registerThrowNoSuchMethod(); |
| 3092 } |
| 3065 registerTypeLiteralAccess(node, target); | 3093 registerTypeLiteralAccess(node, target); |
| 3066 } else if (target.isFinal || target.isConst) { | 3094 } else if (target.isFinal || target.isConst) { |
| 3067 if (Elements.isStaticOrTopLevelField(target) || target.isLocal) { | 3095 if (Elements.isStaticOrTopLevelField(target) || target.isLocal) { |
| 3068 setter = reportAndCreateErroneousElement( | 3096 setter = reportAndCreateErroneousElement( |
| 3069 node.selector, target.name, MessageKind.CANNOT_RESOLVE_SETTER, | 3097 node.selector, target.name, MessageKind.CANNOT_RESOLVE_SETTER, |
| 3070 const {}); | 3098 const {}); |
| 3071 } else if (node.isSuperCall) { | 3099 } else if (node.isSuperCall) { |
| 3072 setter = reportAndCreateErroneousElement( | 3100 setter = reportAndCreateErroneousElement( |
| 3073 node.selector, target.name, MessageKind.SETTER_NOT_FOUND_IN_SUPER, | 3101 node.selector, target.name, MessageKind.SETTER_NOT_FOUND_IN_SUPER, |
| 3074 {'name': target.name, 'className': currentClass.name}); | 3102 {'name': target.name, 'className': currentClass.name}); |
| (...skipping 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5194 } | 5222 } |
| 5195 | 5223 |
| 5196 /// The result for the resolution of the `assert` method. | 5224 /// The result for the resolution of the `assert` method. |
| 5197 class AssertResult implements ResolutionResult { | 5225 class AssertResult implements ResolutionResult { |
| 5198 const AssertResult(); | 5226 const AssertResult(); |
| 5199 | 5227 |
| 5200 Element get element => null; | 5228 Element get element => null; |
| 5201 | 5229 |
| 5202 String toString() => 'AssertResult()'; | 5230 String toString() => 'AssertResult()'; |
| 5203 } | 5231 } |
| OLD | NEW |