Chromium Code Reviews| 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 => appliesUntyped(element, compiler); |
| 260 | 260 |
| 261 bool appliesUntyped(Element element, Compiler compiler) { | 261 bool appliesUntyped(Element element, Compiler compiler) { |
| 262 if (Elements.isUnresolved(element)) return false; | 262 if (Elements.isUnresolved(element)) return false; |
| 263 if (name.isPrivate() && library != element.getLibrary()) return false; | 263 if (name.isPrivate() && library != element.getLibrary()) return false; |
| 264 if (element.isForeign(compiler)) return true; | 264 if (element.isForeign(compiler)) return true; |
| 265 if (element.isSetter()) return isSetter(); | 265 if (element.isSetter()) return isSetter(); |
| 266 if (element.isGetter()) return isGetter() || isCall(); | 266 if (element.isGetter()) return isGetter() || isCall(); |
| 267 if (element.isField()) return isGetter() || isSetter() || isCall(); | 267 if (element.isField()) return isGetter() || isSetter() || isCall(); |
| 268 if (isGetter()) return true; | 268 if (isGetter()) return true; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 294 if (!nameSet.contains(name)) return false; | 294 if (!nameSet.contains(name)) return false; |
| 295 // TODO(5213): By removing from the set we are checking | 295 // TODO(5213): By removing from the set we are checking |
| 296 // that we are not passing the name twice. We should have this | 296 // that we are not passing the name twice. We should have this |
| 297 // check in the resolver also. | 297 // check in the resolver also. |
| 298 nameSet.remove(name); | 298 nameSet.remove(name); |
| 299 } | 299 } |
| 300 return true; | 300 return true; |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 bool applies(Element element, Compiler compiler) { | |
| 305 // TODO(ngeoffray): Remove workaround checks. | |
| 306 if (element != compiler.assertMethod | |
| 307 && !element.isConstructor() | |
| 308 && name != element.name) return false; | |
| 309 return appliesUnnamed(element, compiler); | |
| 310 } | |
| 311 | |
| 304 /** | 312 /** |
| 313 * Fills [list] with the arguments in a defined order. | |
| 314 * | |
| 315 * [compileArgument] is a function that returns a compiled version | |
| 316 * of an argument located in [arguments]. | |
| 317 * | |
| 318 * [compileConstant] is a function that returns a compiled constant | |
| 319 * of an optional argument that is not in [arguments. | |
| 320 * | |
| 305 * Returns [:true:] if the selector and the [element] match; [:false:] | 321 * Returns [:true:] if the selector and the [element] match; [:false:] |
| 306 * otherwise. | 322 * otherwise. |
| 307 * | 323 * |
| 308 * Invariant: [element] must be the implementation element. | 324 * Invariant: [element] must be the implementation element. |
| 309 */ | 325 */ |
| 310 bool addArgumentsToList(Link<Node> arguments, | 326 bool addArgumentsToList(Link<Node> arguments, |
| 311 List list, | 327 List list, |
| 312 FunctionElement element, | 328 FunctionElement element, |
| 313 compileArgument(Node argument), | 329 compileArgument(Node argument), |
| 314 compileConstant(Element element), | 330 compileConstant(Element element), |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 } else { | 456 } else { |
| 441 ClassElement otherCls = field.getEnclosingClass(); | 457 ClassElement otherCls = field.getEnclosingClass(); |
| 442 // We have not found a match, but another class higher in the | 458 // We have not found a match, but another class higher in the |
| 443 // hierarchy may define the getter or the setter. | 459 // hierarchy may define the getter or the setter. |
| 444 return hasElementIn(otherCls.superclass, element); | 460 return hasElementIn(otherCls.superclass, element); |
| 445 } | 461 } |
| 446 } | 462 } |
| 447 return false; | 463 return false; |
| 448 } | 464 } |
| 449 | 465 |
| 450 bool applies(Element element, Compiler compiler) { | 466 bool appliesUnnamed(Element element, Compiler compiler) { |
| 451 // [TypedSelector] are only used when compiling. | 467 // [TypedSelector] are only used when compiling. |
|
kasperl
2013/02/04 13:39:03
Can we assert that the names are the same in here?
ngeoffray
2013/02/04 14:51:07
Done with a helper method sameNameHack, until we c
| |
| 452 assert(compiler.phase == Compiler.PHASE_COMPILING); | 468 assert(compiler.phase == Compiler.PHASE_COMPILING); |
| 453 if (!element.isMember()) return false; | 469 if (!element.isMember()) return false; |
| 454 | 470 |
| 455 // A closure can be called through any typed selector: | 471 // A closure can be called through any typed selector: |
| 456 // class A { | 472 // class A { |
| 457 // get foo => () => 42; | 473 // get foo => () => 42; |
| 458 // bar() => foo(); // The call to 'foo' is a typed selector. | 474 // bar() => foo(); // The call to 'foo' is a typed selector. |
| 459 // } | 475 // } |
| 460 ClassElement other = element.getEnclosingClass(); | 476 ClassElement other = element.getEnclosingClass(); |
| 461 if (identical(other.superclass, compiler.closureClass)) { | 477 if (identical(other.superclass, compiler.closureClass)) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 480 ClassElement cls = self; | 496 ClassElement cls = self; |
| 481 if (cls.isSubclassOf(other)) { | 497 if (cls.isSubclassOf(other)) { |
| 482 // Resolve an invocation of [element.name] on [self]. If it | 498 // Resolve an invocation of [element.name] on [self]. If it |
| 483 // is found, this selector is a candidate. | 499 // is found, this selector is a candidate. |
| 484 return hasElementIn(self, element) && appliesUntyped(element, compiler); | 500 return hasElementIn(self, element) && appliesUntyped(element, compiler); |
| 485 } | 501 } |
| 486 | 502 |
| 487 return false; | 503 return false; |
| 488 } | 504 } |
| 489 } | 505 } |
| OLD | NEW |