| 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 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import '../cache_strategy.dart'; | 9 import '../cache_strategy.dart'; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 | 103 |
| 104 /// Strategy for computing the constraints on potential receivers of dynamic | 104 /// Strategy for computing the constraints on potential receivers of dynamic |
| 105 /// call sites. | 105 /// call sites. |
| 106 abstract class SelectorConstraintsStrategy { | 106 abstract class SelectorConstraintsStrategy { |
| 107 /// Create a [UniverseSelectorConstraints] to represent the global receiver | 107 /// Create a [UniverseSelectorConstraints] to represent the global receiver |
| 108 /// constraints for dynamic call sites with [selector]. | 108 /// constraints for dynamic call sites with [selector]. |
| 109 UniverseSelectorConstraints createSelectorConstraints(Selector selector); | 109 UniverseSelectorConstraints createSelectorConstraints(Selector selector); |
| 110 } | 110 } |
| 111 | 111 |
| 112 class OpenWorldStrategy implements SelectorConstraintsStrategy { |
| 113 const OpenWorldStrategy(); |
| 114 |
| 115 OpenWorldConstraints createSelectorConstraints(Selector selector) { |
| 116 return new OpenWorldConstraints(); |
| 117 } |
| 118 } |
| 119 |
| 120 class OpenWorldConstraints extends UniverseSelectorConstraints { |
| 121 bool isAll = false; |
| 122 |
| 123 @override |
| 124 bool applies(Element element, Selector selector, World world) => isAll; |
| 125 |
| 126 @override |
| 127 bool needsNoSuchMethodHandling(Selector selector, World world) => isAll; |
| 128 |
| 129 @override |
| 130 bool addReceiverConstraint(ReceiverConstraint constraint) { |
| 131 if (isAll) return false; |
| 132 isAll = true; |
| 133 return true; |
| 134 } |
| 135 |
| 136 String toString() { |
| 137 if (isAll) { |
| 138 return '<all>'; |
| 139 } else { |
| 140 return '<none>'; |
| 141 } |
| 142 } |
| 143 } |
| 144 |
| 112 /// The [WorldBuilder] is an auxiliary class used in the process of computing | 145 /// The [WorldBuilder] is an auxiliary class used in the process of computing |
| 113 /// the [ClosedWorld]. | 146 /// the [ClosedWorld]. |
| 114 // TODO(johnniwinther): Move common implementation to a [WorldBuilderBase] when | 147 // TODO(johnniwinther): Move common implementation to a [WorldBuilderBase] when |
| 115 // universes and worlds have been unified. | 148 // universes and worlds have been unified. |
| 116 abstract class WorldBuilder { | 149 abstract class WorldBuilder { |
| 117 /// All directly instantiated classes, that is, classes with a generative | 150 /// All directly instantiated classes, that is, classes with a generative |
| 118 /// constructor that has been called directly and not only through a | 151 /// constructor that has been called directly and not only through a |
| 119 /// super-call. | 152 /// super-call. |
| 120 // TODO(johnniwinther): Improve semantic precision. | 153 // TODO(johnniwinther): Improve semantic precision. |
| 121 Iterable<ClassElement> get directlyInstantiatedClasses; | 154 Iterable<ClassElement> get directlyInstantiatedClasses; |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 Iterable<ClassElement> get processedClasses => _processedClasses.keys | 479 Iterable<ClassElement> get processedClasses => _processedClasses.keys |
| 447 .where((cls) => _processedClasses[cls].isInstantiated); | 480 .where((cls) => _processedClasses[cls].isInstantiated); |
| 448 | 481 |
| 449 OpenWorld get openWorld => _openWorld; | 482 OpenWorld get openWorld => _openWorld; |
| 450 | 483 |
| 451 ClosedWorld get closedWorldForTesting { | 484 ClosedWorld get closedWorldForTesting { |
| 452 if (!_openWorld.isClosed) { | 485 if (!_openWorld.isClosed) { |
| 453 throw new SpannableAssertionFailure( | 486 throw new SpannableAssertionFailure( |
| 454 NO_LOCATION_SPANNABLE, "The world builder has not yet been closed."); | 487 NO_LOCATION_SPANNABLE, "The world builder has not yet been closed."); |
| 455 } | 488 } |
| 456 return _openWorld; | 489 return _openWorld.closedWorldCache; |
| 457 } | 490 } |
| 458 | 491 |
| 459 /// All directly instantiated classes, that is, classes with a generative | 492 /// All directly instantiated classes, that is, classes with a generative |
| 460 /// constructor that has been called directly and not only through a | 493 /// constructor that has been called directly and not only through a |
| 461 /// super-call. | 494 /// super-call. |
| 462 // TODO(johnniwinther): Improve semantic precision. | 495 // TODO(johnniwinther): Improve semantic precision. |
| 463 Iterable<ClassElement> get directlyInstantiatedClasses { | 496 Iterable<ClassElement> get directlyInstantiatedClasses { |
| 464 Set<ClassElement> classes = new Set<ClassElement>(); | 497 Set<ClassElement> classes = new Set<ClassElement>(); |
| 465 getInstantiationMap().forEach((ClassElement cls, InstantiationInfo info) { | 498 getInstantiationMap().forEach((ClassElement cls, InstantiationInfo info) { |
| 466 if (info.hasInstantiation) { | 499 if (info.hasInstantiation) { |
| (...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 if (hasClosurization) { | 1574 if (hasClosurization) { |
| 1542 return MemberUses.NONE; | 1575 return MemberUses.NONE; |
| 1543 } | 1576 } |
| 1544 hasNormalUse = hasClosurization = true; | 1577 hasNormalUse = hasClosurization = true; |
| 1545 return _pendingUse.removeAll(MemberUses.ALL_STATIC); | 1578 return _pendingUse.removeAll(MemberUses.ALL_STATIC); |
| 1546 } | 1579 } |
| 1547 | 1580 |
| 1548 @override | 1581 @override |
| 1549 EnumSet<MemberUse> get _originalUse => MemberUses.ALL_STATIC; | 1582 EnumSet<MemberUse> get _originalUse => MemberUses.ALL_STATIC; |
| 1550 } | 1583 } |
| OLD | NEW |