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

Side by Side Diff: pkg/compiler/lib/src/world.dart

Issue 1224753002: Remove ClassWorld.subclassesOf and ClassWorld.subtypesOf. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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 | « pkg/compiler/lib/src/universe/function_set.dart ('k') | tests/compiler/dart2js/world_test.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 4
5 part of dart2js; 5 part of dart2js;
6 6
7 abstract class ClassWorld { 7 abstract class ClassWorld {
8 // TODO(johnniwinther): Refine this into a `BackendClasses` interface. 8 // TODO(johnniwinther): Refine this into a `BackendClasses` interface.
9 Backend get backend; 9 Backend get backend;
10 10
(...skipping 28 matching lines...) Expand all
39 /// Returns `true` if the class world is closed. 39 /// Returns `true` if the class world is closed.
40 bool get isClosed; 40 bool get isClosed;
41 41
42 /// Return `true` if [x] is a subclass of [y]. 42 /// Return `true` if [x] is a subclass of [y].
43 bool isSubclassOf(ClassElement x, ClassElement y); 43 bool isSubclassOf(ClassElement x, ClassElement y);
44 44
45 /// Returns `true` if [x] is a subtype of [y], that is, if [x] implements an 45 /// Returns `true` if [x] is a subtype of [y], that is, if [x] implements an
46 /// instance of [y]. 46 /// instance of [y].
47 bool isSubtypeOf(ClassElement x, ClassElement y); 47 bool isSubtypeOf(ClassElement x, ClassElement y);
48 48
49 /// Returns an iterable over the live classes that extend [cls] including
50 /// [cls] itself.
51 Iterable<ClassElement> subclassesOf(ClassElement cls);
52
53 /// Returns an iterable over the live classes that extend [cls] _not_ 49 /// Returns an iterable over the live classes that extend [cls] _not_
54 /// including [cls] itself. 50 /// including [cls] itself.
55 Iterable<ClassElement> strictSubclassesOf(ClassElement cls); 51 Iterable<ClassElement> strictSubclassesOf(ClassElement cls);
56 52
57 /// Returns an iterable over the live classes that implement [cls] including
58 /// [cls] if it is live.
59 Iterable<ClassElement> subtypesOf(ClassElement cls);
60
61 /// Returns an iterable over the live classes that implement [cls] _not_ 53 /// Returns an iterable over the live classes that implement [cls] _not_
62 /// including [cls] if it is live. 54 /// including [cls] if it is live.
63 Iterable<ClassElement> strictSubtypesOf(ClassElement cls); 55 Iterable<ClassElement> strictSubtypesOf(ClassElement cls);
64 56
65 /// Returns `true` if any live class extends [cls].
66 bool hasAnySubclass(ClassElement cls);
67
68 /// Returns `true` if any live class other than [cls] extends [cls]. 57 /// Returns `true` if any live class other than [cls] extends [cls].
69 bool hasAnyStrictSubclass(ClassElement cls); 58 bool hasAnyStrictSubclass(ClassElement cls);
70 59
71 /// Returns `true` if any live class implements [cls].
72 bool hasAnySubtype(ClassElement cls);
73
74 /// Returns `true` if any live class other than [cls] implements [cls]. 60 /// Returns `true` if any live class other than [cls] implements [cls].
75 bool hasAnyStrictSubtype(ClassElement cls); 61 bool hasAnyStrictSubtype(ClassElement cls);
76 62
77 /// Returns `true` if all live classes that implement [cls] extend it. 63 /// Returns `true` if all live classes that implement [cls] extend it.
78 bool hasOnlySubclasses(ClassElement cls); 64 bool hasOnlySubclasses(ClassElement cls);
79 65
80 /// Returns an iterable over the common supertypes of the [classes]. 66 /// Returns an iterable over the common supertypes of the [classes].
81 Iterable<ClassElement> commonSupertypesOf(Iterable<ClassElement> classes); 67 Iterable<ClassElement> commonSupertypesOf(Iterable<ClassElement> classes);
82 68
83 /// Returns an iterable over the live mixin applications that mixin [cls]. 69 /// Returns an iterable over the live mixin applications that mixin [cls].
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 x = x.superclass; 138 x = x.superclass;
153 } 139 }
154 return false; 140 return false;
155 } 141 }
156 142
157 /// Returns `true` if [cls] is instantiated. 143 /// Returns `true` if [cls] is instantiated.
158 bool isInstantiated(ClassElement cls) { 144 bool isInstantiated(ClassElement cls) {
159 return compiler.resolverWorld.isInstantiated(cls); 145 return compiler.resolverWorld.isInstantiated(cls);
160 } 146 }
161 147
162 /// Returns an iterable over the live classes that extend [cls] including 148 /// Returns an iterable over the live classes that extend [cls] _not_
163 /// [cls] itself. 149 /// including [cls] itself.
164 Iterable<ClassElement> subclassesOf(ClassElement cls) { 150 Iterable<ClassElement> strictSubclassesOf(ClassElement cls) {
165 Set<ClassElement> subclasses = _subclasses[cls.declaration]; 151 Set<ClassElement> subclasses = _subclasses[cls.declaration];
166 if (subclasses == null) return const <ClassElement>[]; 152 if (subclasses == null) return const <ClassElement>[];
167 assert(invariant(cls, isInstantiated(cls.declaration), 153 assert(invariant(cls, isInstantiated(cls.declaration),
168 message: 'Class $cls has not been instantiated.')); 154 message: 'Class $cls has not been instantiated.'));
169 return subclasses; 155 return subclasses;
170 } 156 }
171 157
172 /// Returns an iterable over the live classes that extend [cls] _not_
173 /// including [cls] itself.
174 Iterable<ClassElement> strictSubclassesOf(ClassElement cls) {
175 return subclassesOf(cls).where((c) => c != cls);
176 }
177
178 /// Returns an iterable over the live classes that implement [cls] including
179 /// [cls] if it is live.
180 Iterable<ClassElement> subtypesOf(ClassElement cls) {
181 Set<ClassElement> subtypes = _subtypes[cls.declaration];
182 return subtypes != null ? subtypes : const <ClassElement>[];
183 }
184
185 /// Returns an iterable over the live classes that implement [cls] _not_ 158 /// Returns an iterable over the live classes that implement [cls] _not_
186 /// including [cls] if it is live. 159 /// including [cls] if it is live.
187 Iterable<ClassElement> strictSubtypesOf(ClassElement cls) { 160 Iterable<ClassElement> strictSubtypesOf(ClassElement cls) {
188 return subtypesOf(cls).where((c) => c != cls); 161 Set<ClassElement> subtypes = _subtypes[cls.declaration];
189 } 162 return subtypes != null ? subtypes : const <ClassElement>[];
190
191 /// Returns `true` if any live class extends [cls].
192 bool hasAnySubclass(ClassElement cls) {
193 return !subclassesOf(cls).isEmpty;
194 } 163 }
195 164
196 /// Returns `true` if any live class other than [cls] extends [cls]. 165 /// Returns `true` if any live class other than [cls] extends [cls].
197 bool hasAnyStrictSubclass(ClassElement cls) { 166 bool hasAnyStrictSubclass(ClassElement cls) {
198 return !strictSubclassesOf(cls).isEmpty; 167 return !strictSubclassesOf(cls).isEmpty;
199 } 168 }
200 169
201 /// Returns `true` if any live class implements [cls].
202 bool hasAnySubtype(ClassElement cls) {
203 return !subtypesOf(cls).isEmpty;
204 }
205
206 /// Returns `true` if any live class other than [cls] implements [cls]. 170 /// Returns `true` if any live class other than [cls] implements [cls].
207 bool hasAnyStrictSubtype(ClassElement cls) { 171 bool hasAnyStrictSubtype(ClassElement cls) {
208 return !strictSubtypesOf(cls).isEmpty; 172 return !strictSubtypesOf(cls).isEmpty;
209 } 173 }
210 174
211 /// Returns `true` if all live classes that implement [cls] extend it. 175 /// Returns `true` if all live classes that implement [cls] extend it.
212 bool hasOnlySubclasses(ClassElement cls) { 176 bool hasOnlySubclasses(ClassElement cls) {
213 Iterable<ClassElement> subtypes = subtypesOf(cls); 177 Iterable<ClassElement> subtypes = strictSubtypesOf(cls);
214 if (subtypes == null) return true; 178 if (subtypes == null) return true;
215 Iterable<ClassElement> subclasses = subclassesOf(cls); 179 Iterable<ClassElement> subclasses = strictSubclassesOf(cls);
216 return subclasses != null && (subclasses.length == subtypes.length); 180 return subclasses != null && (subclasses.length == subtypes.length);
217 } 181 }
218 182
219 /// Returns an iterable over the common supertypes of the [classes]. 183 /// Returns an iterable over the common supertypes of the [classes].
220 Iterable<ClassElement> commonSupertypesOf(Iterable<ClassElement> classes) { 184 Iterable<ClassElement> commonSupertypesOf(Iterable<ClassElement> classes) {
221 Iterator<ClassElement> iterator = classes.iterator; 185 Iterator<ClassElement> iterator = classes.iterator;
222 if (!iterator.moveNext()) return const <ClassElement>[]; 186 if (!iterator.moveNext()) return const <ClassElement>[];
223 187
224 ClassElement cls = iterator.current; 188 ClassElement cls = iterator.current;
225 assert(checkInvariants(cls)); 189 assert(checkInvariants(cls));
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // function expressions's element. 500 // function expressions's element.
537 // TODO(herhut): Generate classes for function expressions earlier. 501 // TODO(herhut): Generate classes for function expressions earlier.
538 if (element is closureMapping.SynthesizedCallMethodElementX) { 502 if (element is closureMapping.SynthesizedCallMethodElementX) {
539 return getMightBePassedToApply(element.expression); 503 return getMightBePassedToApply(element.expression);
540 } 504 }
541 return functionsThatMightBePassedToApply.contains(element); 505 return functionsThatMightBePassedToApply.contains(element);
542 } 506 }
543 507
544 bool get hasClosedWorldAssumption => !compiler.hasIncrementalSupport; 508 bool get hasClosedWorldAssumption => !compiler.hasIncrementalSupport;
545 } 509 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/universe/function_set.dart ('k') | tests/compiler/dart2js/world_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698