| 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 // If there are no subtypes then the subtype set contains the class itself. | 237 var info = _infoFor[class_]; |
| 238 return !getSubtypesOf(class_).isSingleton; | 238 var subtypes = info.subtypeIntervalList; |
| 239 } | 239 return !(subtypes.length == 2 && |
| 240 | 240 subtypes[0] == info.topDownIndex && |
| 241 /// Returns the subtypes of [class_] as an interval list. | 241 subtypes[1] == info.topDownIndex + 1); |
| 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); | |
| 249 } | 242 } |
| 250 | 243 |
| 251 ClassHierarchy._internal(Program program, int numberOfClasses) | 244 ClassHierarchy._internal(Program program, int numberOfClasses) |
| 252 : classes = new List<Class>(numberOfClasses) { | 245 : classes = new List<Class>(numberOfClasses) { |
| 253 // Build the class ordering based on a topological sort. | 246 // Build the class ordering based on a topological sort. |
| 254 for (var library in program.libraries) { | 247 for (var library in program.libraries) { |
| 255 for (var classNode in library.classes) { | 248 for (var classNode in library.classes) { |
| 256 _topologicalSortVisit(classNode); | 249 _topologicalSortVisit(classNode); |
| 257 } | 250 } |
| 258 } | 251 } |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 | 857 |
| 865 /// Non-final instance fields and setters implemented by this class | 858 /// Non-final instance fields and setters implemented by this class |
| 866 /// (declared or inherited). | 859 /// (declared or inherited). |
| 867 List<Member> implementedSetters; | 860 List<Member> implementedSetters; |
| 868 | 861 |
| 869 List<Member> interfaceGettersAndCalls; | 862 List<Member> interfaceGettersAndCalls; |
| 870 List<Member> interfaceSetters; | 863 List<Member> interfaceSetters; |
| 871 | 864 |
| 872 _ClassInfo(this.classNode); | 865 _ClassInfo(this.classNode); |
| 873 } | 866 } |
| 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 |