| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import '../common.dart'; | 5 import '../common.dart'; |
| 6 import '../common_elements.dart' show CommonElements; |
| 6 import '../common/names.dart' show Identifiers, Names, Selectors; | 7 import '../common/names.dart' show Identifiers, Names, Selectors; |
| 7 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
| 8 import '../elements/entities.dart'; | 9 import '../elements/entities.dart'; |
| 9 import '../types/types.dart'; | 10 import '../types/types.dart'; |
| 10 import '../tree/tree.dart'; | 11 import '../tree/tree.dart'; |
| 11 import 'backend_helpers.dart'; | |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Categorizes `noSuchMethod` implementations. | 14 * Categorizes `noSuchMethod` implementations. |
| 15 * | 15 * |
| 16 * If user code includes `noSuchMethod` implementations, type inference is | 16 * If user code includes `noSuchMethod` implementations, type inference is |
| 17 * hindered because (for instance) any selector where the type of the | 17 * hindered because (for instance) any selector where the type of the |
| 18 * receiver is not known all implementations of `noSuchMethod` must be taken | 18 * receiver is not known all implementations of `noSuchMethod` must be taken |
| 19 * into account when inferring the return type. | 19 * into account when inferring the return type. |
| 20 * | 20 * |
| 21 * The situation can be ameliorated with some heuristics for disregarding some | 21 * The situation can be ameliorated with some heuristics for disregarding some |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 /// The implementations that fall into category D1 | 63 /// The implementations that fall into category D1 |
| 64 final Set<FunctionEntity> complexNoReturnImpls = new Set<FunctionEntity>(); | 64 final Set<FunctionEntity> complexNoReturnImpls = new Set<FunctionEntity>(); |
| 65 | 65 |
| 66 /// The implementations that fall into category D2 | 66 /// The implementations that fall into category D2 |
| 67 final Set<FunctionEntity> complexReturningImpls = new Set<FunctionEntity>(); | 67 final Set<FunctionEntity> complexReturningImpls = new Set<FunctionEntity>(); |
| 68 | 68 |
| 69 /// The implementations that have not yet been categorized. | 69 /// The implementations that have not yet been categorized. |
| 70 final Set<FunctionEntity> _uncategorizedImpls = new Set<FunctionEntity>(); | 70 final Set<FunctionEntity> _uncategorizedImpls = new Set<FunctionEntity>(); |
| 71 | 71 |
| 72 final BackendHelpers _helpers; | 72 final CommonElements _commonElements; |
| 73 final NoSuchMethodResolver _resolver; | 73 final NoSuchMethodResolver _resolver; |
| 74 | 74 |
| 75 NoSuchMethodRegistry(this._helpers, this._resolver); | 75 NoSuchMethodRegistry(this._commonElements, this._resolver); |
| 76 | 76 |
| 77 bool get hasThrowingNoSuchMethod => throwingImpls.isNotEmpty; | 77 bool get hasThrowingNoSuchMethod => throwingImpls.isNotEmpty; |
| 78 bool get hasComplexNoSuchMethod => otherImpls.isNotEmpty; | 78 bool get hasComplexNoSuchMethod => otherImpls.isNotEmpty; |
| 79 | 79 |
| 80 void registerNoSuchMethod(FunctionEntity noSuchMethodElement) { | 80 void registerNoSuchMethod(FunctionEntity noSuchMethodElement) { |
| 81 _uncategorizedImpls.add(noSuchMethodElement); | 81 _uncategorizedImpls.add(noSuchMethodElement); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void onQueueEmpty() { | 84 void onQueueEmpty() { |
| 85 _uncategorizedImpls.forEach(_categorizeImpl); | 85 _uncategorizedImpls.forEach(_categorizeImpl); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 if (otherImpls.contains(element)) { | 139 if (otherImpls.contains(element)) { |
| 140 return NsmCategory.OTHER; | 140 return NsmCategory.OTHER; |
| 141 } | 141 } |
| 142 if (notApplicableImpls.contains(element)) { | 142 if (notApplicableImpls.contains(element)) { |
| 143 return NsmCategory.NOT_APPLICABLE; | 143 return NsmCategory.NOT_APPLICABLE; |
| 144 } | 144 } |
| 145 if (!Selectors.noSuchMethod_.signatureApplies(element)) { | 145 if (!Selectors.noSuchMethod_.signatureApplies(element)) { |
| 146 notApplicableImpls.add(element); | 146 notApplicableImpls.add(element); |
| 147 return NsmCategory.NOT_APPLICABLE; | 147 return NsmCategory.NOT_APPLICABLE; |
| 148 } | 148 } |
| 149 if (_helpers.isDefaultNoSuchMethodImplementation(element)) { | 149 if (_commonElements.isDefaultNoSuchMethodImplementation(element)) { |
| 150 defaultImpls.add(element); | 150 defaultImpls.add(element); |
| 151 return NsmCategory.DEFAULT; | 151 return NsmCategory.DEFAULT; |
| 152 } else if (_resolver.hasForwardingSyntax(element)) { | 152 } else if (_resolver.hasForwardingSyntax(element)) { |
| 153 // If the implementation is 'noSuchMethod(x) => super.noSuchMethod(x);' | 153 // If the implementation is 'noSuchMethod(x) => super.noSuchMethod(x);' |
| 154 // then it is in the same category as the super call. | 154 // then it is in the same category as the super call. |
| 155 FunctionEntity superCall = _resolver.getSuperNoSuchMethod(element); | 155 FunctionEntity superCall = _resolver.getSuperNoSuchMethod(element); |
| 156 NsmCategory category = _categorizeImpl(superCall); | 156 NsmCategory category = _categorizeImpl(superCall); |
| 157 switch (category) { | 157 switch (category) { |
| 158 case NsmCategory.DEFAULT: | 158 case NsmCategory.DEFAULT: |
| 159 defaultImpls.add(element); | 159 defaultImpls.add(element); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 return stmt.expression is Throw; | 281 return stmt.expression is Throw; |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 return false; | 284 return false; |
| 285 } | 285 } |
| 286 | 286 |
| 287 MethodElement getSuperNoSuchMethod(MethodElement method) { | 287 MethodElement getSuperNoSuchMethod(MethodElement method) { |
| 288 return method.enclosingClass.lookupSuperByName(Names.noSuchMethod_); | 288 return method.enclosingClass.lookupSuperByName(Names.noSuchMethod_); |
| 289 } | 289 } |
| 290 } | 290 } |
| OLD | NEW |