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

Side by Side Diff: pkg/kernel/lib/class_hierarchy.dart

Issue 2924713002: Replace ClassHierarchy.classes with getOrderedClasses(). (Closed)
Patch Set: Tweak the comment. Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/kernel/lib/src/incremental_class_hierarchy.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'src/heap.dart'; 9 import 'src/heap.dart';
10 import 'type_algebra.dart'; 10 import 'type_algebra.dart';
11 11
12 /// Interface for answering various subclassing queries. 12 /// Interface for answering various subclassing queries.
13 /// TODO(scheglov) Several methods are not used, or used only in tests. 13 /// TODO(scheglov) Several methods are not used, or used only in tests.
14 /// Check if these methods are not useful and should be removed . 14 /// Check if these methods are not useful and should be removed .
15 abstract class ClassHierarchy { 15 abstract class ClassHierarchy {
16 factory ClassHierarchy(Program program) => 16 factory ClassHierarchy(Program program) =>
17 new ClosedWorldClassHierarchy(program); 17 new ClosedWorldClassHierarchy(program);
18 18
19 /// All classes in the program. 19 /// Given the [unordered] classes, return them in such order that classes
20 /// occur after their super classes.
20 /// 21 ///
21 /// The iterable is ordered so that classes occur after their super classes. 22 /// If [unordered] does not include all superclasses, they might still be
22 Iterable<Class> get classes; 23 /// returned, it is up to the client to filter them out if required.
24 Iterable<Class> getOrderedClasses(Iterable<Class> unordered);
23 25
24 /// Returns the index of [class_] in the [classes] list. 26 /// Returns the unique index of the [class_].
25 int getClassIndex(Class class_); 27 int getClassIndex(Class class_);
26 28
27 /// True if the program contains another class that is a subtype of given one. 29 /// True if the program contains another class that is a subtype of given one.
28 bool hasProperSubtypes(Class class_); 30 bool hasProperSubtypes(Class class_);
29 31
30 /// Returns the number of steps in the longest inheritance path from [class_] 32 /// Returns the number of steps in the longest inheritance path from [class_]
31 /// to [Object]. 33 /// to [Object].
32 int getClassDepth(Class class_); 34 int getClassDepth(Class class_);
33 35
34 /// Returns a list of classes appropriate for use in calculating a least upper 36 /// Returns a list of classes appropriate for use in calculating a least upper
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 final List<Class> classes; 132 final List<Class> classes;
131 133
132 final Map<Class, _ClassInfo> _infoFor = <Class, _ClassInfo>{}; 134 final Map<Class, _ClassInfo> _infoFor = <Class, _ClassInfo>{};
133 135
134 ClosedWorldClassHierarchy(Program program) 136 ClosedWorldClassHierarchy(Program program)
135 : this._internal(program, _countClasses(program)); 137 : this._internal(program, _countClasses(program));
136 138
137 @override 139 @override
138 int getClassIndex(Class class_) => _infoFor[class_].topologicalIndex; 140 int getClassIndex(Class class_) => _infoFor[class_].topologicalIndex;
139 141
142 @override
143 Iterable<Class> getOrderedClasses(Iterable<Class> unordered) => classes;
Siggi Cherem (dart-lang) 2017/06/06 00:15:21 mmm - It seems a bit surprising if you pass 2 clas
scheglov 2017/06/06 01:33:27 I updated `getOrderedClasses` to perform filtering
Siggi Cherem (dart-lang) 2017/06/06 03:03:44 sorry, makes sense, I forgot that IncrementalCla
144
140 /// True if [subclass] inherits from [superclass] though zero or more 145 /// True if [subclass] inherits from [superclass] though zero or more
141 /// `extends` relationships. 146 /// `extends` relationships.
142 bool isSubclassOf(Class subclass, Class superclass) { 147 bool isSubclassOf(Class subclass, Class superclass) {
143 if (identical(subclass, superclass)) return true; 148 if (identical(subclass, superclass)) return true;
144 return _infoFor[subclass].isSubclassOf(_infoFor[superclass]); 149 return _infoFor[subclass].isSubclassOf(_infoFor[superclass]);
145 } 150 }
146 151
147 /// True if [submixture] inherits from [superclass] though zero or more 152 /// True if [submixture] inherits from [superclass] though zero or more
148 /// `extends` and `with` relationships. 153 /// `extends` and `with` relationships.
149 bool isSubmixtureOf(Class submixture, Class superclass) { 154 bool isSubmixtureOf(Class submixture, Class superclass) {
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 class _LubHeap extends Heap<_ClassInfo> { 1117 class _LubHeap extends Heap<_ClassInfo> {
1113 @override 1118 @override
1114 bool sortsBefore(_ClassInfo a, _ClassInfo b) => sortsBeforeStatic(a, b); 1119 bool sortsBefore(_ClassInfo a, _ClassInfo b) => sortsBeforeStatic(a, b);
1115 1120
1116 static bool sortsBeforeStatic(_ClassInfo a, _ClassInfo b) { 1121 static bool sortsBeforeStatic(_ClassInfo a, _ClassInfo b) {
1117 if (a.depth > b.depth) return true; 1122 if (a.depth > b.depth) return true;
1118 if (a.depth < b.depth) return false; 1123 if (a.depth < b.depth) return false;
1119 return a.topologicalIndex < b.topologicalIndex; 1124 return a.topologicalIndex < b.topologicalIndex;
1120 } 1125 }
1121 } 1126 }
OLDNEW
« no previous file with comments | « no previous file | pkg/kernel/lib/src/incremental_class_hierarchy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698