| Index: pkg/kernel/lib/class_hierarchy.dart
|
| diff --git a/pkg/kernel/lib/class_hierarchy.dart b/pkg/kernel/lib/class_hierarchy.dart
|
| index 6771cc4560220bc7865d7eaea80b2189e215927f..40bc6e7972d429d37d03430eef3af6082b8cfc0b 100644
|
| --- a/pkg/kernel/lib/class_hierarchy.dart
|
| +++ b/pkg/kernel/lib/class_hierarchy.dart
|
| @@ -234,11 +234,18 @@ class ClassHierarchy {
|
|
|
| /// True if the program contains another class that is a subtype of given one.
|
| bool hasProperSubtypes(Class class_) {
|
| - var info = _infoFor[class_];
|
| - var subtypes = info.subtypeIntervalList;
|
| - return !(subtypes.length == 2 &&
|
| - subtypes[0] == info.topDownIndex &&
|
| - subtypes[1] == info.topDownIndex + 1);
|
| + // If there are no subtypes then the subtype set contains the class itself.
|
| + return !getSubtypesOf(class_).isSingleton;
|
| + }
|
| +
|
| + /// Returns the subtypes of [class_] as an interval list.
|
| + ClassSet getSubtypesOf(Class class_) {
|
| + return new ClassSet(this, _infoFor[class_].subtypeIntervalList);
|
| + }
|
| +
|
| + /// Returns the subclasses of [class_] as an interval list.
|
| + ClassSet getSubclassesOf(Class class_) {
|
| + return new ClassSet(this, _infoFor[class_].subclassIntervalList);
|
| }
|
|
|
| ClassHierarchy._internal(Program program, int numberOfClasses)
|
| @@ -864,3 +871,32 @@ class _ClassInfo {
|
|
|
| _ClassInfo(this.classNode);
|
| }
|
| +
|
| +/// An immutable set of classes, internally represented as an interval list.
|
| +class ClassSet {
|
| + final ClassHierarchy _hierarchy;
|
| + final Uint32List _intervalList;
|
| +
|
| + ClassSet(this._hierarchy, this._intervalList);
|
| +
|
| + bool get isEmpty => _intervalList.isEmpty;
|
| +
|
| + bool get isSingleton {
|
| + var list = _intervalList;
|
| + return list.length == 2 && list[0] + 1 == list[1];
|
| + }
|
| +
|
| + bool contains(Class class_) {
|
| + return _intervalListContains(
|
| + _intervalList, _hierarchy._infoFor[class_].topDownIndex);
|
| + }
|
| +
|
| + ClassSet union(ClassSet other) {
|
| + assert(_hierarchy == other._hierarchy);
|
| + if (identical(_intervalList, other._intervalList)) return this;
|
| + _IntervalListBuilder builder = new _IntervalListBuilder();
|
| + builder.addIntervalList(_intervalList);
|
| + builder.addIntervalList(other._intervalList);
|
| + return new ClassSet(_hierarchy, builder.buildIntervalList());
|
| + }
|
| +}
|
|
|