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 library dart2js.selector; | 5 library dart2js.selector; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/names.dart' show Names; | 8 import '../common/names.dart' show Names; |
9 import '../elements/elements.dart' | 9 import '../elements/elements.dart' |
10 show | 10 show |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 const int SETTER = 2; | 210 const int SETTER = 2; |
211 int kind = METHOD; | 211 int kind = METHOD; |
212 if (isGetter) { | 212 if (isGetter) { |
213 kind = GETTER; | 213 kind = GETTER; |
214 } else if (isSetter) { | 214 } else if (isSetter) { |
215 kind = SETTER; | 215 kind = SETTER; |
216 } | 216 } |
217 return kind; | 217 return kind; |
218 } | 218 } |
219 | 219 |
220 bool appliesUnnamed(Element element, Target target) { | 220 bool appliesUnnamed(Element element) { |
221 assert(sameNameHack(element)); | 221 assert(sameNameHack(element)); |
222 return appliesUntyped(element, target); | 222 return appliesUntyped(element); |
223 } | 223 } |
224 | 224 |
225 bool appliesUntyped(Element element, Target target) { | 225 bool appliesUntyped(Element element) { |
226 assert(sameNameHack(element)); | 226 assert(sameNameHack(element)); |
227 if (Elements.isUnresolved(element)) return false; | 227 if (Elements.isUnresolved(element)) return false; |
228 if (memberName.isPrivate && memberName.library != element.library) { | 228 if (memberName.isPrivate && memberName.library != element.library) { |
229 // TODO(johnniwinther): Maybe this should be | 229 // TODO(johnniwinther): Maybe this should be |
230 // `memberName != element.memberName`. | 230 // `memberName != element.memberName`. |
231 return false; | 231 return false; |
232 } | 232 } |
233 if (target.isForeign(element)) return true; | |
Johnni Winther
2016/09/26 14:04:42
This wasn't needed. In the very old days selectors
| |
234 if (element.isSetter) return isSetter; | 233 if (element.isSetter) return isSetter; |
235 if (element.isGetter) return isGetter || isCall; | 234 if (element.isGetter) return isGetter || isCall; |
236 if (element.isField) { | 235 if (element.isField) { |
237 return isSetter | 236 return isSetter |
238 ? !element.isFinal && !element.isConst | 237 ? !element.isFinal && !element.isConst |
239 : isGetter || isCall; | 238 : isGetter || isCall; |
240 } | 239 } |
241 if (isGetter) return true; | 240 if (isGetter) return true; |
242 if (isSetter) return false; | 241 if (isSetter) return false; |
243 return signatureApplies(element); | 242 return signatureApplies(element); |
244 } | 243 } |
245 | 244 |
246 bool signatureApplies(FunctionElement function) { | 245 bool signatureApplies(FunctionElement function) { |
247 if (Elements.isUnresolved(function)) return false; | 246 if (Elements.isUnresolved(function)) return false; |
248 return callStructure.signatureApplies(function.functionSignature); | 247 return callStructure.signatureApplies(function.functionSignature); |
249 } | 248 } |
250 | 249 |
251 bool sameNameHack(Element element) { | 250 bool sameNameHack(Element element) { |
252 // TODO(ngeoffray): Remove workaround checks. | 251 // TODO(ngeoffray): Remove workaround checks. |
253 return element.isConstructor || name == element.name; | 252 return element.isConstructor || name == element.name; |
254 } | 253 } |
255 | 254 |
256 bool applies(Element element, Target target) { | 255 bool applies(Element element) { |
257 if (!sameNameHack(element)) return false; | 256 if (!sameNameHack(element)) return false; |
258 return appliesUnnamed(element, target); | 257 return appliesUnnamed(element); |
259 } | 258 } |
260 | 259 |
261 bool match(SelectorKind kind, Name memberName, CallStructure callStructure) { | 260 bool match(SelectorKind kind, Name memberName, CallStructure callStructure) { |
262 return this.kind == kind && | 261 return this.kind == kind && |
263 this.memberName == memberName && | 262 this.memberName == memberName && |
264 this.callStructure.match(callStructure); | 263 this.callStructure.match(callStructure); |
265 } | 264 } |
266 | 265 |
267 static int computeHashCode( | 266 static int computeHashCode( |
268 SelectorKind kind, Name name, CallStructure callStructure) { | 267 SelectorKind kind, Name name, CallStructure callStructure) { |
269 // Add bits from name and kind. | 268 // Add bits from name and kind. |
270 int hash = Hashing.mixHashCodeBits(name.hashCode, kind.hashCode); | 269 int hash = Hashing.mixHashCodeBits(name.hashCode, kind.hashCode); |
271 // Add bits from the call structure. | 270 // Add bits from the call structure. |
272 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); | 271 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); |
273 } | 272 } |
274 | 273 |
275 String toString() { | 274 String toString() { |
276 return 'Selector($kind, $name, ${callStructure.structureToString()})'; | 275 return 'Selector($kind, $name, ${callStructure.structureToString()})'; |
277 } | 276 } |
278 | 277 |
279 Selector toCallSelector() => new Selector.callClosureFrom(this); | 278 Selector toCallSelector() => new Selector.callClosureFrom(this); |
280 } | 279 } |
OLD | NEW |