| 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 class Universe { | 5 class Universe { |
| 6 Map<Element, CodeBuffer> generatedCode; | 6 Map<Element, CodeBuffer> generatedCode; |
| 7 Map<Element, CodeBuffer> generatedBailoutCode; | 7 Map<Element, CodeBuffer> generatedBailoutCode; |
| 8 final Set<ClassElement> instantiatedClasses; | 8 final Set<ClassElement> instantiatedClasses; |
| 9 final Set<SourceString> instantiatedClassInstanceFields; | 9 final Set<SourceString> instantiatedClassInstanceFields; |
| 10 final Set<FunctionElement> staticFunctionsNeedingGetter; | 10 final Set<FunctionElement> staticFunctionsNeedingGetter; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 : super(selector.kind, | 297 : super(selector.kind, |
| 298 selector.argumentCount, | 298 selector.argumentCount, |
| 299 selector.namedArguments); | 299 selector.namedArguments); |
| 300 | 300 |
| 301 /** | 301 /** |
| 302 * Check if [element] will be the one used at runtime when being | 302 * Check if [element] will be the one used at runtime when being |
| 303 * invoked on an instance of [cls]. | 303 * invoked on an instance of [cls]. |
| 304 */ | 304 */ |
| 305 bool hasElementIn(ClassElement cls, Element element) { | 305 bool hasElementIn(ClassElement cls, Element element) { |
| 306 Element resolved = cls.lookupMember(element.name); | 306 Element resolved = cls.lookupMember(element.name); |
| 307 if (resolved === element) return true; | 307 if (resolved === element) return true; |
| 308 if (resolved === null) return false; | 308 if (resolved === null) return false; |
| 309 if (resolved.kind === ElementKind.ABSTRACT_FIELD) { | 309 if (resolved.kind === ElementKind.ABSTRACT_FIELD) { |
| 310 AbstractFieldElement field = resolved; | 310 AbstractFieldElement field = resolved; |
| 311 if (element === field.getter || element === field.setter) { | 311 if (element === field.getter || element === field.setter) { |
| 312 return true; | 312 return true; |
| 313 } else { | 313 } else { |
| 314 ClassElement otherCls = field.enclosingElement; | 314 ClassElement otherCls = field.getEnclosingClass(); |
| 315 // We have not found a match, but another class higher in the | 315 // We have not found a match, but another class higher in the |
| 316 // hierarchy may define the getter or the setter. | 316 // hierarchy may define the getter or the setter. |
| 317 return hasElementIn(otherCls.superclass, element); | 317 return hasElementIn(otherCls.superclass, element); |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 return false; | 320 return false; |
| 321 } | 321 } |
| 322 | 322 |
| 323 bool applies(Element element, Compiler compiler) { | 323 bool applies(Element element, Compiler compiler) { |
| 324 if (!element.enclosingElement.isClass()) return false; | 324 if (!element.isMember()) return false; |
| 325 | 325 |
| 326 // A closure can be called through any typed selector: | 326 // A closure can be called through any typed selector: |
| 327 // class A { | 327 // class A { |
| 328 // get foo() => () => 42; | 328 // get foo() => () => 42; |
| 329 // bar() => foo(); // The call to 'foo' is a typed selector. | 329 // bar() => foo(); // The call to 'foo' is a typed selector. |
| 330 // } | 330 // } |
| 331 ClassElement other = element.enclosingElement; | 331 ClassElement other = element.getEnclosingClass(); |
| 332 if (other.superclass === compiler.closureClass) { | 332 if (other.superclass === compiler.closureClass) { |
| 333 return super.applies(element, compiler); | 333 return super.applies(element, compiler); |
| 334 } | 334 } |
| 335 | 335 |
| 336 ClassElement self = receiverType.element; | 336 ClassElement self = receiverType.element; |
| 337 // TODO(ngeoffray): tree-shake on interfaces. | 337 // TODO(ngeoffray): tree-shake on interfaces. |
| 338 if (self.isInterface() || other.isSubclassOf(self)) { | 338 if (self.isInterface() || other.isSubclassOf(self)) { |
| 339 return super.applies(element, compiler); | 339 return super.applies(element, compiler); |
| 340 } | 340 } |
| 341 | 341 |
| 342 if (!self.isInterface() && self.isSubclassOf(other)) { | 342 if (!self.isInterface() && self.isSubclassOf(other)) { |
| 343 // Resolve an invocation of [element.name] on [self]. If it | 343 // Resolve an invocation of [element.name] on [self]. If it |
| 344 // is found, this selector is a candidate. | 344 // is found, this selector is a candidate. |
| 345 return hasElementIn(self, element) && super.applies(element, compiler); | 345 return hasElementIn(self, element) && super.applies(element, compiler); |
| 346 } | 346 } |
| 347 | 347 |
| 348 return false; | 348 return false; |
| 349 } | 349 } |
| 350 | 350 |
| 351 bool operator ==(other) { | 351 bool operator ==(other) { |
| 352 if (other is !TypedSelector) return false; | 352 if (other is !TypedSelector) return false; |
| 353 if (other.receiverType !== receiverType) return false; | 353 if (other.receiverType !== receiverType) return false; |
| 354 return super == other; | 354 return super == other; |
| 355 } | 355 } |
| 356 } | 356 } |
| OLD | NEW |