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

Unified Diff: pkg/compiler/lib/src/types/type_mask.dart

Issue 1318383002: Extract ReceiverMask interface from TypeMask. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 4 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
Index: pkg/compiler/lib/src/types/type_mask.dart
diff --git a/pkg/compiler/lib/src/types/type_mask.dart b/pkg/compiler/lib/src/types/type_mask.dart
index 9ea82abea67e04a7d90e41ba9c98ee9149cd2a5e..65cf5969b9de21349f44b598076923f8cd8589e4 100644
--- a/pkg/compiler/lib/src/types/type_mask.dart
+++ b/pkg/compiler/lib/src/types/type_mask.dart
@@ -4,12 +4,78 @@
part of types;
+/// An implementation of a [UniverseReceiverMaskSet] that is consists if an only
+/// increasing set of [TypeMask]s, that is, once a mask is added it cannot be
+/// removed.
+class IncreasingTypeMaskSet extends UniverseReceiverMaskSet {
+ bool isAll = false;
+ Set<TypeMask> _masks;
+
+ @override
+ bool applies(Element element, Selector selector, ClassWorld world) {
+ if (isAll) return true;
+ if (_masks == null) return false;
+ for (TypeMask mask in _masks) {
+ if (mask.canHit(element, selector, world)) return true;
+ }
+ return false;
+ }
+
+ @override
+ bool needsNoSuchMethodHandling(Selector selector, ClassWorld world) {
+ if (isAll) {
+ TypeMask mask =
+ new TypeMask.subclass(world.objectClass, world);
+ return mask.needsNoSuchMethodHandling(selector, world);
+ }
+ for (TypeMask mask in _masks) {
+ if (mask.needsNoSuchMethodHandling(selector, world)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @override
+ bool addReceiverMask(TypeMask mask) {
+ if (isAll) return false;
+ if (mask == null) {
+ isAll = true;
+ _masks = null;
+ return true;
+ }
+ if (_masks == null) {
+ _masks = new Setlet<TypeMask>();
+ }
+ return _masks.add(mask);
+ }
+
+ String toString() {
+ if (isAll) {
+ return '<all>';
+ } else if (_masks != null) {
+ return '$_masks';
+ } else {
+ return '<none>';
+ }
+ }
+}
+
+class TypeMaskStrategy implements ReceiverMaskStrategy {
+ const TypeMaskStrategy();
+
+ @override
+ UniverseReceiverMaskSet createReceiverMaskSet(Selector selector) {
+ return new IncreasingTypeMaskSet();
+ }
+}
+
/**
* A type mask represents a set of contained classes, but the
* operations on it are not guaranteed to be precise and they may
* yield conservative answers that contain too many classes.
*/
-abstract class TypeMask {
+abstract class TypeMask implements ReceiverMask {
factory TypeMask(ClassElement base,
int kind,
bool isNullable,
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart ('k') | pkg/compiler/lib/src/universe/universe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698