| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 abstract class ClassWorld { | 7 abstract class ClassWorld { |
| 8 // TODO(johnniwinther): Refine this into a `BackendClasses` interface. | 8 // TODO(johnniwinther): Refine this into a `BackendClasses` interface. |
| 9 Backend get backend; | 9 Backend get backend; |
| 10 | 10 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 104 |
| 105 class World implements ClassWorld { | 105 class World implements ClassWorld { |
| 106 ClassElement get objectClass => compiler.objectClass; | 106 ClassElement get objectClass => compiler.objectClass; |
| 107 ClassElement get functionClass => compiler.functionClass; | 107 ClassElement get functionClass => compiler.functionClass; |
| 108 ClassElement get boolClass => compiler.boolClass; | 108 ClassElement get boolClass => compiler.boolClass; |
| 109 ClassElement get numClass => compiler.numClass; | 109 ClassElement get numClass => compiler.numClass; |
| 110 ClassElement get intClass => compiler.intClass; | 110 ClassElement get intClass => compiler.intClass; |
| 111 ClassElement get doubleClass => compiler.doubleClass; | 111 ClassElement get doubleClass => compiler.doubleClass; |
| 112 ClassElement get stringClass => compiler.stringClass; | 112 ClassElement get stringClass => compiler.stringClass; |
| 113 | 113 |
| 114 Map<Selector, Map<ti.TypeMask, TypedSelector>> canonicalizedValues = |
| 115 new Map<Selector, Map<ti.TypeMask, TypedSelector>>(); |
| 116 |
| 114 bool checkInvariants(ClassElement cls, {bool mustBeInstantiated: true}) { | 117 bool checkInvariants(ClassElement cls, {bool mustBeInstantiated: true}) { |
| 115 return | 118 return |
| 116 invariant(cls, cls.isDeclaration, | 119 invariant(cls, cls.isDeclaration, |
| 117 message: '$cls must be the declaration.') && | 120 message: '$cls must be the declaration.') && |
| 118 invariant(cls, cls.isResolved, | 121 invariant(cls, cls.isResolved, |
| 119 message: '$cls must be resolved.') && | 122 message: '$cls must be resolved.') && |
| 120 (!mustBeInstantiated || | 123 (!mustBeInstantiated || |
| 121 invariant(cls, isInstantiated(cls), | 124 invariant(cls, isInstantiated(cls), |
| 122 message: '$cls is not instantiated.')); | 125 message: '$cls is not instantiated.')); |
| 123 } | 126 } |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 ClassElement mixin) { | 398 ClassElement mixin) { |
| 396 // TODO(johnniwinther): Add map restricted to live classes. | 399 // TODO(johnniwinther): Add map restricted to live classes. |
| 397 // We don't support patch classes as mixin. | 400 // We don't support patch classes as mixin. |
| 398 assert(mixin.isDeclaration); | 401 assert(mixin.isDeclaration); |
| 399 List<MixinApplicationElement> users = | 402 List<MixinApplicationElement> users = |
| 400 _mixinUses.putIfAbsent(mixin, () => | 403 _mixinUses.putIfAbsent(mixin, () => |
| 401 new List<MixinApplicationElement>()); | 404 new List<MixinApplicationElement>()); |
| 402 users.add(mixinApplication); | 405 users.add(mixinApplication); |
| 403 } | 406 } |
| 404 | 407 |
| 405 bool hasAnyUserDefinedGetter(Selector selector, ti.TypeMask mask) { | 408 bool hasAnyUserDefinedGetter(Selector selector) { |
| 406 return allFunctions.filter(selector, mask).any((each) => each.isGetter); | 409 return allFunctions.filter(selector).any((each) => each.isGetter); |
| 407 } | 410 } |
| 408 | 411 |
| 409 void registerUsedElement(Element element) { | 412 void registerUsedElement(Element element) { |
| 410 if (element.isInstanceMember && !element.isAbstract) { | 413 if (element.isInstanceMember && !element.isAbstract) { |
| 411 allFunctions.add(element); | 414 allFunctions.add(element); |
| 412 } | 415 } |
| 413 } | 416 } |
| 414 | 417 |
| 415 VariableElement locateSingleField(Selector selector, ti.TypeMask mask) { | 418 VariableElement locateSingleField(Selector selector) { |
| 416 Element result = locateSingleElement(selector, mask); | 419 Element result = locateSingleElement(selector); |
| 417 return (result != null && result.isField) ? result : null; | 420 return (result != null && result.isField) ? result : null; |
| 418 } | 421 } |
| 419 | 422 |
| 420 Element locateSingleElement(Selector selector, ti.TypeMask mask) { | 423 Element locateSingleElement(Selector selector) { |
| 421 mask = mask == null | 424 ti.TypeMask mask = selector.mask == null |
| 422 ? compiler.typesTask.dynamicType | 425 ? compiler.typesTask.dynamicType |
| 423 : mask; | 426 : selector.mask; |
| 424 return mask.locateSingleElement(selector, mask, compiler); | 427 return mask.locateSingleElement(selector, compiler); |
| 425 } | |
| 426 | |
| 427 ti.TypeMask extendMaskIfReachesAll(Selector selector, ti.TypeMask mask) { | |
| 428 bool canReachAll = true; | |
| 429 if (mask != null) { | |
| 430 canReachAll = | |
| 431 compiler.enabledInvokeOn && | |
| 432 mask.needsNoSuchMethodHandling(selector, this); | |
| 433 } | |
| 434 return canReachAll ? compiler.typesTask.dynamicType : mask; | |
| 435 } | 428 } |
| 436 | 429 |
| 437 void addFunctionCalledInLoop(Element element) { | 430 void addFunctionCalledInLoop(Element element) { |
| 438 functionsCalledInLoop.add(element.declaration); | 431 functionsCalledInLoop.add(element.declaration); |
| 439 } | 432 } |
| 440 | 433 |
| 441 bool isCalledInLoop(Element element) { | 434 bool isCalledInLoop(Element element) { |
| 442 return functionsCalledInLoop.contains(element.declaration); | 435 return functionsCalledInLoop.contains(element.declaration); |
| 443 } | 436 } |
| 444 | 437 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 475 void registerSideEffects(Element element, SideEffects effects) { | 468 void registerSideEffects(Element element, SideEffects effects) { |
| 476 if (sideEffectsFreeElements.contains(element)) return; | 469 if (sideEffectsFreeElements.contains(element)) return; |
| 477 sideEffects[element.declaration] = effects; | 470 sideEffects[element.declaration] = effects; |
| 478 } | 471 } |
| 479 | 472 |
| 480 void registerSideEffectsFree(Element element) { | 473 void registerSideEffectsFree(Element element) { |
| 481 sideEffects[element.declaration] = new SideEffects.empty(); | 474 sideEffects[element.declaration] = new SideEffects.empty(); |
| 482 sideEffectsFreeElements.add(element); | 475 sideEffectsFreeElements.add(element); |
| 483 } | 476 } |
| 484 | 477 |
| 485 SideEffects getSideEffectsOfSelector(Selector selector, ti.TypeMask mask) { | 478 SideEffects getSideEffectsOfSelector(Selector selector) { |
| 486 // We're not tracking side effects of closures. | 479 // We're not tracking side effects of closures. |
| 487 if (selector.isClosureCall) return new SideEffects(); | 480 if (selector.isClosureCall) return new SideEffects(); |
| 488 SideEffects sideEffects = new SideEffects.empty(); | 481 SideEffects sideEffects = new SideEffects.empty(); |
| 489 for (Element e in allFunctions.filter(selector, mask)) { | 482 for (Element e in allFunctions.filter(selector)) { |
| 490 if (e.isField) { | 483 if (e.isField) { |
| 491 if (selector.isGetter) { | 484 if (selector.isGetter) { |
| 492 if (!fieldNeverChanges(e)) { | 485 if (!fieldNeverChanges(e)) { |
| 493 sideEffects.setDependsOnInstancePropertyStore(); | 486 sideEffects.setDependsOnInstancePropertyStore(); |
| 494 } | 487 } |
| 495 } else if (selector.isSetter) { | 488 } else if (selector.isSetter) { |
| 496 sideEffects.setChangesInstanceProperty(); | 489 sideEffects.setChangesInstanceProperty(); |
| 497 } else { | 490 } else { |
| 498 assert(selector.isCall); | 491 assert(selector.isCall); |
| 499 sideEffects.setAllSideEffects(); | 492 sideEffects.setAllSideEffects(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 // function expressions's element. | 524 // function expressions's element. |
| 532 // TODO(herhut): Generate classes for function expressions earlier. | 525 // TODO(herhut): Generate classes for function expressions earlier. |
| 533 if (element is closureMapping.SynthesizedCallMethodElementX) { | 526 if (element is closureMapping.SynthesizedCallMethodElementX) { |
| 534 return getMightBePassedToApply(element.expression); | 527 return getMightBePassedToApply(element.expression); |
| 535 } | 528 } |
| 536 return functionsThatMightBePassedToApply.contains(element); | 529 return functionsThatMightBePassedToApply.contains(element); |
| 537 } | 530 } |
| 538 | 531 |
| 539 bool get hasClosedWorldAssumption => !compiler.hasIncrementalSupport; | 532 bool get hasClosedWorldAssumption => !compiler.hasIncrementalSupport; |
| 540 } | 533 } |
| OLD | NEW |