| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library kernel.class_hierarchy; | 4 library kernel.class_hierarchy; |
| 5 | 5 |
| 6 import 'ast.dart'; | 6 import 'ast.dart'; |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 import 'dart:typed_data'; | 8 import 'dart:typed_data'; |
| 9 import 'type_algebra.dart'; | 9 import 'type_algebra.dart'; |
| 10 | 10 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 227 } |
| 228 // A given declared member may override multiple interface members, | 228 // A given declared member may override multiple interface members, |
| 229 // so only move past the interface member. | 229 // so only move past the interface member. |
| 230 ++j; | 230 ++j; |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 /// True if the program contains another class that is a subtype of given one. | 235 /// True if the program contains another class that is a subtype of given one. |
| 236 bool hasProperSubtypes(Class class_) { | 236 bool hasProperSubtypes(Class class_) { |
| 237 var info = _infoFor[class_]; | 237 // If there are no subtypes then the subtype set contains the class itself. |
| 238 var subtypes = info.subtypeIntervalList; | 238 return !getSubtypesOf(class_).isSingleton; |
| 239 return !(subtypes.length == 2 && | 239 } |
| 240 subtypes[0] == info.topDownIndex && | 240 |
| 241 subtypes[1] == info.topDownIndex + 1); | 241 /// Returns the subtypes of [class_] as an interval list. |
| 242 ClassSet getSubtypesOf(Class class_) { |
| 243 return new ClassSet(this, _infoFor[class_].subtypeIntervalList); |
| 244 } |
| 245 |
| 246 /// Returns the subclasses of [class_] as an interval list. |
| 247 ClassSet getSubclassesOf(Class class_) { |
| 248 return new ClassSet(this, _infoFor[class_].subclassIntervalList); |
| 242 } | 249 } |
| 243 | 250 |
| 244 ClassHierarchy._internal(Program program, int numberOfClasses) | 251 ClassHierarchy._internal(Program program, int numberOfClasses) |
| 245 : classes = new List<Class>(numberOfClasses) { | 252 : classes = new List<Class>(numberOfClasses) { |
| 246 // Build the class ordering based on a topological sort. | 253 // Build the class ordering based on a topological sort. |
| 247 for (var library in program.libraries) { | 254 for (var library in program.libraries) { |
| 248 for (var classNode in library.classes) { | 255 for (var classNode in library.classes) { |
| 249 _topologicalSortVisit(classNode); | 256 _topologicalSortVisit(classNode); |
| 250 } | 257 } |
| 251 } | 258 } |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 | 864 |
| 858 /// Non-final instance fields and setters implemented by this class | 865 /// Non-final instance fields and setters implemented by this class |
| 859 /// (declared or inherited). | 866 /// (declared or inherited). |
| 860 List<Member> implementedSetters; | 867 List<Member> implementedSetters; |
| 861 | 868 |
| 862 List<Member> interfaceGettersAndCalls; | 869 List<Member> interfaceGettersAndCalls; |
| 863 List<Member> interfaceSetters; | 870 List<Member> interfaceSetters; |
| 864 | 871 |
| 865 _ClassInfo(this.classNode); | 872 _ClassInfo(this.classNode); |
| 866 } | 873 } |
| 874 |
| 875 /// An immutable set of classes, internally represented as an interval list. |
| 876 class ClassSet { |
| 877 final ClassHierarchy _hierarchy; |
| 878 final Uint32List _intervalList; |
| 879 |
| 880 ClassSet(this._hierarchy, this._intervalList); |
| 881 |
| 882 bool get isEmpty => _intervalList.isEmpty; |
| 883 |
| 884 bool get isSingleton { |
| 885 var list = _intervalList; |
| 886 return list.length == 2 && list[0] + 1 == list[1]; |
| 887 } |
| 888 |
| 889 bool contains(Class class_) { |
| 890 return _intervalListContains( |
| 891 _intervalList, _hierarchy._infoFor[class_].topDownIndex); |
| 892 } |
| 893 |
| 894 ClassSet union(ClassSet other) { |
| 895 assert(_hierarchy == other._hierarchy); |
| 896 if (identical(_intervalList, other._intervalList)) return this; |
| 897 _IntervalListBuilder builder = new _IntervalListBuilder(); |
| 898 builder.addIntervalList(_intervalList); |
| 899 builder.addIntervalList(other._intervalList); |
| 900 return new ClassSet(_hierarchy, builder.buildIntervalList()); |
| 901 } |
| 902 } |
| OLD | NEW |