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

Side by Side Diff: pkg/compiler/lib/src/universe/member_usage.dart

Issue 2913713004: Add model test of CodegenWorldBuilder to compile_from_dill_test (Closed)
Patch Set: So much patch set for so small a typo. 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
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 world_builder; 5 part of world_builder;
6 6
7 abstract class _AbstractUsage<T> { 7 abstract class AbstractUsage<T> {
8 final EnumSet<T> _pendingUse = new EnumSet<T>(); 8 final EnumSet<T> _pendingUse = new EnumSet<T>();
9 9
10 _AbstractUsage() { 10 AbstractUsage() {
11 _pendingUse.addAll(_originalUse); 11 _pendingUse.addAll(_originalUse);
12 } 12 }
13 13
14 /// Returns the possible uses of [entity] that have not yet been registered. 14 /// Returns the possible uses of [entity] that have not yet been registered.
15 EnumSet<T> get pendingUse => _pendingUse; 15 EnumSet<T> get pendingUse => _pendingUse;
16 16
17 /// Returns the uses of [entity] that have been registered. 17 /// Returns the uses of [entity] that have been registered.
18 EnumSet<T> get appliedUse => _originalUse.minus(_pendingUse); 18 EnumSet<T> get appliedUse => _originalUse.minus(_pendingUse);
19 19
20 EnumSet<T> get _originalUse; 20 EnumSet<T> get _originalUse;
21 21
22 /// `true` if the [appliedUse] is non-empty. 22 /// `true` if the [appliedUse] is non-empty.
23 bool get hasUse => appliedUse.isNotEmpty; 23 bool get hasUse => appliedUse.isNotEmpty;
24
25 /// Returns `true` if [other] has the same original and pending usage as this.
26 bool hasSameUsage(AbstractUsage<T> other) {
27 if (identical(this, other)) return true;
28 return _originalUse.value == other._originalUse.value &&
29 _pendingUse.value == other._pendingUse.value;
30 }
24 } 31 }
25 32
26 /// Registry for the observed use of a member [entity] in the open world. 33 /// Registry for the observed use of a member [entity] in the open world.
27 abstract class _MemberUsage extends _AbstractUsage<MemberUse> { 34 abstract class _MemberUsage extends AbstractUsage<MemberUse> {
28 // TODO(johnniwinther): Change [Entity] to [MemberEntity]. 35 // TODO(johnniwinther): Change [Entity] to [MemberEntity].
29 final Entity entity; 36 final Entity entity;
30 37
31 _MemberUsage.internal(this.entity); 38 _MemberUsage.internal(this.entity);
32 39
33 factory _MemberUsage(MemberEntity member, {bool isNative: false}) { 40 factory _MemberUsage(MemberEntity member, {bool isNative: false}) {
34 if (member.isField) { 41 if (member.isField) {
35 if (member.isAssignable) { 42 if (member.isAssignable) {
36 return new _FieldUsage(member, isNative: isNative); 43 return new _FieldUsage(member, isNative: isNative);
37 } else { 44 } else {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 EnumSet<MemberUse> get _originalUse => MemberUses.NORMAL_ONLY; 95 EnumSet<MemberUse> get _originalUse => MemberUses.NORMAL_ONLY;
89 96
90 int get hashCode => entity.hashCode; 97 int get hashCode => entity.hashCode;
91 98
92 bool operator ==(other) { 99 bool operator ==(other) {
93 if (identical(this, other)) return true; 100 if (identical(this, other)) return true;
94 if (other is! _MemberUsage) return false; 101 if (other is! _MemberUsage) return false;
95 return entity == other.entity; 102 return entity == other.entity;
96 } 103 }
97 104
98 String toString() => entity.toString(); 105 String toString() => '$entity:${appliedUse.iterable(MemberUse.values)}';
99 } 106 }
100 107
101 class _FieldUsage extends _MemberUsage { 108 class _FieldUsage extends _MemberUsage {
102 bool hasRead = false; 109 bool hasRead = false;
103 bool hasWrite = false; 110 bool hasWrite = false;
104 111
105 _FieldUsage(FieldEntity field, {bool isNative: false}) 112 _FieldUsage(FieldEntity field, {bool isNative: false})
106 : super.internal(field) { 113 : super.internal(field) {
107 if (!isNative) { 114 if (!isNative) {
108 // All field initializers must be resolved as they could 115 // All field initializers must be resolved as they could
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 static const EnumSet<MemberUse> ALL_INSTANCE = 287 static const EnumSet<MemberUse> ALL_INSTANCE =
281 const EnumSet<MemberUse>.fixed(3); 288 const EnumSet<MemberUse>.fixed(3);
282 static const EnumSet<MemberUse> ALL_STATIC = 289 static const EnumSet<MemberUse> ALL_STATIC =
283 const EnumSet<MemberUse>.fixed(5); 290 const EnumSet<MemberUse>.fixed(5);
284 } 291 }
285 292
286 typedef void MemberUsedCallback(MemberEntity member, EnumSet<MemberUse> useSet); 293 typedef void MemberUsedCallback(MemberEntity member, EnumSet<MemberUse> useSet);
287 294
288 /// Registry for the observed use of a class [entity] in the open world. 295 /// Registry for the observed use of a class [entity] in the open world.
289 // TODO(johnniwinther): Merge this with [InstantiationInfo]. 296 // TODO(johnniwinther): Merge this with [InstantiationInfo].
290 class _ClassUsage extends _AbstractUsage<ClassUse> { 297 class _ClassUsage extends AbstractUsage<ClassUse> {
291 bool isInstantiated = false; 298 bool isInstantiated = false;
292 bool isImplemented = false; 299 bool isImplemented = false;
293 300
294 final ClassEntity cls; 301 final ClassEntity cls;
295 302
296 _ClassUsage(this.cls); 303 _ClassUsage(this.cls);
297 304
298 EnumSet<ClassUse> instantiate() { 305 EnumSet<ClassUse> instantiate() {
299 if (isInstantiated) { 306 if (isInstantiated) {
300 return ClassUses.NONE; 307 return ClassUses.NONE;
301 } 308 }
302 isInstantiated = true; 309 isInstantiated = true;
303 return _pendingUse.removeAll(ClassUses.INSTANTIATED_ONLY); 310 return _pendingUse.removeAll(ClassUses.INSTANTIATED_ONLY);
304 } 311 }
305 312
306 EnumSet<ClassUse> implement() { 313 EnumSet<ClassUse> implement() {
307 if (isImplemented) { 314 if (isImplemented) {
308 return ClassUses.NONE; 315 return ClassUses.NONE;
309 } 316 }
310 isImplemented = true; 317 isImplemented = true;
311 return _pendingUse.removeAll(ClassUses.IMPLEMENTED_ONLY); 318 return _pendingUse.removeAll(ClassUses.IMPLEMENTED_ONLY);
312 } 319 }
313 320
314 @override 321 @override
315 EnumSet<ClassUse> get _originalUse => ClassUses.ALL; 322 EnumSet<ClassUse> get _originalUse => ClassUses.ALL;
316 323
317 String toString() => cls.toString(); 324 String toString() => '$cls:${appliedUse.iterable(ClassUse.values)}';
318 } 325 }
319 326
320 /// Enum class for the possible kind of use of [ClassEntity] objects. 327 /// Enum class for the possible kind of use of [ClassEntity] objects.
321 enum ClassUse { INSTANTIATED, IMPLEMENTED } 328 enum ClassUse { INSTANTIATED, IMPLEMENTED }
322 329
323 /// Common [EnumSet]s used for [ClassUse]. 330 /// Common [EnumSet]s used for [ClassUse].
324 class ClassUses { 331 class ClassUses {
325 static const EnumSet<ClassUse> NONE = const EnumSet<ClassUse>.fixed(0); 332 static const EnumSet<ClassUse> NONE = const EnumSet<ClassUse>.fixed(0);
326 static const EnumSet<ClassUse> INSTANTIATED_ONLY = 333 static const EnumSet<ClassUse> INSTANTIATED_ONLY =
327 const EnumSet<ClassUse>.fixed(1); 334 const EnumSet<ClassUse>.fixed(1);
328 static const EnumSet<ClassUse> IMPLEMENTED_ONLY = 335 static const EnumSet<ClassUse> IMPLEMENTED_ONLY =
329 const EnumSet<ClassUse>.fixed(2); 336 const EnumSet<ClassUse>.fixed(2);
330 static const EnumSet<ClassUse> ALL = const EnumSet<ClassUse>.fixed(3); 337 static const EnumSet<ClassUse> ALL = const EnumSet<ClassUse>.fixed(3);
331 } 338 }
332 339
333 typedef void ClassUsedCallback(ClassEntity cls, EnumSet<ClassUse> useSet); 340 typedef void ClassUsedCallback(ClassEntity cls, EnumSet<ClassUse> useSet);
334 341
335 // TODO(johnniwinther): Merge this with [_MemberUsage]. 342 // TODO(johnniwinther): Merge this with [_MemberUsage].
336 abstract class _StaticMemberUsage extends _AbstractUsage<MemberUse> { 343 abstract class _StaticMemberUsage extends AbstractUsage<MemberUse> {
337 final Entity entity; 344 final Entity entity;
338 345
339 bool hasNormalUse = false; 346 bool hasNormalUse = false;
340 bool get hasClosurization => false; 347 bool get hasClosurization => false;
341 348
342 _StaticMemberUsage.internal(this.entity); 349 _StaticMemberUsage.internal(this.entity);
343 350
344 EnumSet<MemberUse> normalUse() { 351 EnumSet<MemberUse> normalUse() {
345 if (hasNormalUse) { 352 if (hasNormalUse) {
346 return MemberUses.NONE; 353 return MemberUses.NONE;
347 } 354 }
348 hasNormalUse = true; 355 hasNormalUse = true;
349 return _pendingUse.removeAll(MemberUses.NORMAL_ONLY); 356 return _pendingUse.removeAll(MemberUses.NORMAL_ONLY);
350 } 357 }
351 358
352 EnumSet<MemberUse> tearOff(); 359 EnumSet<MemberUse> tearOff();
353 360
354 @override 361 @override
355 EnumSet<MemberUse> get _originalUse => MemberUses.NORMAL_ONLY; 362 EnumSet<MemberUse> get _originalUse => MemberUses.NORMAL_ONLY;
356 363
357 String toString() => entity.toString(); 364 String toString() => '$entity:${appliedUse.iterable(MemberUse.values)}';
358 } 365 }
359 366
360 class _GeneralStaticMemberUsage extends _StaticMemberUsage { 367 class _GeneralStaticMemberUsage extends _StaticMemberUsage {
361 _GeneralStaticMemberUsage(Entity entity) : super.internal(entity); 368 _GeneralStaticMemberUsage(Entity entity) : super.internal(entity);
362 369
363 EnumSet<MemberUse> tearOff() => normalUse(); 370 EnumSet<MemberUse> tearOff() => normalUse();
364 } 371 }
365 372
366 class _StaticFunctionUsage extends _StaticMemberUsage { 373 class _StaticFunctionUsage extends _StaticMemberUsage {
367 bool hasClosurization = false; 374 bool hasClosurization = false;
368 375
369 _StaticFunctionUsage(Entity entity) : super.internal(entity); 376 _StaticFunctionUsage(Entity entity) : super.internal(entity);
370 377
371 EnumSet<MemberUse> tearOff() { 378 EnumSet<MemberUse> tearOff() {
372 if (hasClosurization) { 379 if (hasClosurization) {
373 return MemberUses.NONE; 380 return MemberUses.NONE;
374 } 381 }
375 hasNormalUse = hasClosurization = true; 382 hasNormalUse = hasClosurization = true;
376 return _pendingUse.removeAll(MemberUses.ALL_STATIC); 383 return _pendingUse.removeAll(MemberUses.ALL_STATIC);
377 } 384 }
378 385
379 @override 386 @override
380 EnumSet<MemberUse> get _originalUse => MemberUses.ALL_STATIC; 387 EnumSet<MemberUse> get _originalUse => MemberUses.ALL_STATIC;
381 } 388 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/universe/codegen_world_builder.dart ('k') | pkg/compiler/lib/src/universe/resolution_world_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698