| 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 '../closure.dart'; | 7 import '../closure.dart'; |
| 8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
| 9 import '../dart2jslib.dart'; | 9 import '../dart2jslib.dart'; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 invokedNames = new Map<SourceString, Set<Selector>>(), | 43 invokedNames = new Map<SourceString, Set<Selector>>(), |
| 44 invokedGetters = new Map<SourceString, Set<Selector>>(), | 44 invokedGetters = new Map<SourceString, Set<Selector>>(), |
| 45 invokedSetters = new Map<SourceString, Set<Selector>>(), | 45 invokedSetters = new Map<SourceString, Set<Selector>>(), |
| 46 isChecks = new Set<DartType>(); | 46 isChecks = new Set<DartType>(); |
| 47 | 47 |
| 48 bool hasMatchingSelector(Set<Selector> selectors, | 48 bool hasMatchingSelector(Set<Selector> selectors, |
| 49 Element member, | 49 Element member, |
| 50 Compiler compiler) { | 50 Compiler compiler) { |
| 51 if (selectors == null) return false; | 51 if (selectors == null) return false; |
| 52 for (Selector selector in selectors) { | 52 for (Selector selector in selectors) { |
| 53 if (selector.applies(member, compiler)) return true; | 53 if (selector.appliesUnnamed(member, compiler)) return true; |
| 54 } | 54 } |
| 55 return false; | 55 return false; |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool hasInvocation(Element member, Compiler compiler) { | 58 bool hasInvocation(Element member, Compiler compiler) { |
| 59 return hasMatchingSelector(invokedNames[member.name], member, compiler); | 59 return hasMatchingSelector(invokedNames[member.name], member, compiler); |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool hasInvokedGetter(Element member, Compiler compiler) { | 62 bool hasInvokedGetter(Element member, Compiler compiler) { |
| 63 return hasMatchingSelector(invokedGetters[member.name], member, compiler); | 63 return hasMatchingSelector(invokedGetters[member.name], member, compiler); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 const int SETTER = 2; | 248 const int SETTER = 2; |
| 249 int kind = METHOD; | 249 int kind = METHOD; |
| 250 if (isGetter()) { | 250 if (isGetter()) { |
| 251 kind = GETTER; | 251 kind = GETTER; |
| 252 } else if (isSetter()) { | 252 } else if (isSetter()) { |
| 253 kind = SETTER; | 253 kind = SETTER; |
| 254 } | 254 } |
| 255 return kind; | 255 return kind; |
| 256 } | 256 } |
| 257 | 257 |
| 258 bool applies(Element element, Compiler compiler) | 258 bool appliesUnnamed(Element element, Compiler compiler) { |
| 259 => appliesUntyped(element, compiler); | 259 assert(sameNameHack(element, compiler)); |
| 260 return appliesUntyped(element, compiler); |
| 261 } |
| 260 | 262 |
| 261 bool appliesUntyped(Element element, Compiler compiler) { | 263 bool appliesUntyped(Element element, Compiler compiler) { |
| 264 assert(sameNameHack(element, compiler)); |
| 262 if (Elements.isUnresolved(element)) return false; | 265 if (Elements.isUnresolved(element)) return false; |
| 263 if (name.isPrivate() && library != element.getLibrary()) return false; | 266 if (name.isPrivate() && library != element.getLibrary()) return false; |
| 264 if (element.isForeign(compiler)) return true; | 267 if (element.isForeign(compiler)) return true; |
| 265 if (element.isSetter()) return isSetter(); | 268 if (element.isSetter()) return isSetter(); |
| 266 if (element.isGetter()) return isGetter() || isCall(); | 269 if (element.isGetter()) return isGetter() || isCall(); |
| 267 if (element.isField()) return isGetter() || isSetter() || isCall(); | 270 if (element.isField()) return isGetter() || isSetter() || isCall(); |
| 268 if (isGetter()) return true; | 271 if (isGetter()) return true; |
| 269 if (isSetter()) return false; | 272 if (isSetter()) return false; |
| 270 | 273 |
| 271 FunctionElement function = element; | 274 FunctionElement function = element; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 294 if (!nameSet.contains(name)) return false; | 297 if (!nameSet.contains(name)) return false; |
| 295 // TODO(5213): By removing from the set we are checking | 298 // TODO(5213): By removing from the set we are checking |
| 296 // that we are not passing the name twice. We should have this | 299 // that we are not passing the name twice. We should have this |
| 297 // check in the resolver also. | 300 // check in the resolver also. |
| 298 nameSet.remove(name); | 301 nameSet.remove(name); |
| 299 } | 302 } |
| 300 return true; | 303 return true; |
| 301 } | 304 } |
| 302 } | 305 } |
| 303 | 306 |
| 307 bool sameNameHack(Element element, Compiler compiler) { |
| 308 // TODO(ngeoffray): Remove workaround checks. |
| 309 return element == compiler.assertMethod |
| 310 || element.isConstructor() |
| 311 || name == element.name; |
| 312 } |
| 313 |
| 314 bool applies(Element element, Compiler compiler) { |
| 315 if (!sameNameHack(element, compiler)) return false; |
| 316 return appliesUnnamed(element, compiler); |
| 317 } |
| 318 |
| 304 /** | 319 /** |
| 320 * Fills [list] with the arguments in a defined order. |
| 321 * |
| 322 * [compileArgument] is a function that returns a compiled version |
| 323 * of an argument located in [arguments]. |
| 324 * |
| 325 * [compileConstant] is a function that returns a compiled constant |
| 326 * of an optional argument that is not in [arguments. |
| 327 * |
| 305 * Returns [:true:] if the selector and the [element] match; [:false:] | 328 * Returns [:true:] if the selector and the [element] match; [:false:] |
| 306 * otherwise. | 329 * otherwise. |
| 307 * | 330 * |
| 308 * Invariant: [element] must be the implementation element. | 331 * Invariant: [element] must be the implementation element. |
| 309 */ | 332 */ |
| 310 bool addArgumentsToList(Link<Node> arguments, | 333 bool addArgumentsToList(Link<Node> arguments, |
| 311 List list, | 334 List list, |
| 312 FunctionElement element, | 335 FunctionElement element, |
| 313 compileArgument(Node argument), | 336 compileArgument(Node argument), |
| 314 compileConstant(Element element), | 337 compileConstant(Element element), |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 } else { | 463 } else { |
| 441 ClassElement otherCls = field.getEnclosingClass(); | 464 ClassElement otherCls = field.getEnclosingClass(); |
| 442 // We have not found a match, but another class higher in the | 465 // We have not found a match, but another class higher in the |
| 443 // hierarchy may define the getter or the setter. | 466 // hierarchy may define the getter or the setter. |
| 444 return hasElementIn(otherCls.superclass, element); | 467 return hasElementIn(otherCls.superclass, element); |
| 445 } | 468 } |
| 446 } | 469 } |
| 447 return false; | 470 return false; |
| 448 } | 471 } |
| 449 | 472 |
| 450 bool applies(Element element, Compiler compiler) { | 473 bool appliesUnnamed(Element element, Compiler compiler) { |
| 474 assert(sameNameHack(element, compiler)); |
| 451 // [TypedSelector] are only used when compiling. | 475 // [TypedSelector] are only used when compiling. |
| 452 assert(compiler.phase == Compiler.PHASE_COMPILING); | 476 assert(compiler.phase == Compiler.PHASE_COMPILING); |
| 453 if (!element.isMember()) return false; | 477 if (!element.isMember()) return false; |
| 454 | 478 |
| 455 // A closure can be called through any typed selector: | 479 // A closure can be called through any typed selector: |
| 456 // class A { | 480 // class A { |
| 457 // get foo => () => 42; | 481 // get foo => () => 42; |
| 458 // bar() => foo(); // The call to 'foo' is a typed selector. | 482 // bar() => foo(); // The call to 'foo' is a typed selector. |
| 459 // } | 483 // } |
| 460 ClassElement other = element.getEnclosingClass(); | 484 ClassElement other = element.getEnclosingClass(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 480 ClassElement cls = self; | 504 ClassElement cls = self; |
| 481 if (cls.isSubclassOf(other)) { | 505 if (cls.isSubclassOf(other)) { |
| 482 // Resolve an invocation of [element.name] on [self]. If it | 506 // Resolve an invocation of [element.name] on [self]. If it |
| 483 // is found, this selector is a candidate. | 507 // is found, this selector is a candidate. |
| 484 return hasElementIn(self, element) && appliesUntyped(element, compiler); | 508 return hasElementIn(self, element) && appliesUntyped(element, compiler); |
| 485 } | 509 } |
| 486 | 510 |
| 487 return false; | 511 return false; |
| 488 } | 512 } |
| 489 } | 513 } |
| OLD | NEW |