Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Unified Diff: pkg/compiler/lib/src/universe/class_set.dart

Issue 2815513006: Compute isSubtype and isSubclass using ClassSet/ClassHierarchyNode (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/world.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/universe/class_set.dart
diff --git a/pkg/compiler/lib/src/universe/class_set.dart b/pkg/compiler/lib/src/universe/class_set.dart
index 3eaf8cbe0af8f0420e320a777876f78110b583dc..9df3c2d5b1366f4102f90fdb6a45db6b4164c143 100644
--- a/pkg/compiler/lib/src/universe/class_set.dart
+++ b/pkg/compiler/lib/src/universe/class_set.dart
@@ -228,6 +228,11 @@ class ClassHierarchyNode {
return false;
}
+ /// Returns `true` if `other.cls` is a subclass of [cls].
+ bool hasSubclass(ClassHierarchyNode other) {
+ return contains(other);
+ }
+
/// `true` if [cls] has been directly, indirectly, or abstractly instantiated.
bool get isInstantiated =>
isExplicitlyInstantiated || isIndirectlyInstantiated;
@@ -480,6 +485,20 @@ class ClassSet {
ClassEntity get cls => node.cls;
+ /// Returns `true` if `other.cls` is a subclass of [cls].
+ bool hasSubclass(ClassHierarchyNode other) => node.hasSubclass(other);
+
+ /// Returns `true` if `other.cls` is a subtype of [cls].
+ bool hasSubtype(ClassHierarchyNode other) {
+ if (hasSubclass(other)) return true;
+ if (_subtypes != null) {
+ for (ClassHierarchyNode subtypeNode in _subtypes) {
+ if (subtypeNode.hasSubclass(other)) return true;
+ }
+ }
+ return false;
+ }
+
/// Returns the number of directly instantiated subtypes of [cls].
int get instantiatedSubtypeCount {
int count = node.instantiatedSubclassCount;
« no previous file with comments | « no previous file | pkg/compiler/lib/src/world.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698