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

Unified Diff: sdk/lib/_internal/compiler/implementation/types/element_type_mask.dart

Issue 17017003: Introduce an ElementTypeMask to recognize simple constraints like "the type of parameter foo is the… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/types/element_type_mask.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/types/element_type_mask.dart (revision 0)
+++ sdk/lib/_internal/compiler/implementation/types/element_type_mask.dart (revision 0)
@@ -0,0 +1,54 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of types;
+
+/**
+ * A [TypeMask] specific to an element: the return type for a
+ * function, or the type for a field.
+ */
+class ElementTypeMask extends ForwardingTypeMask {
+ final Element element;
+ // Callback function to fetch the actual inferred type of the
+ // element. It is used when a user wants to know about the type this
+ // [ForwardingTypeMask] forwards to.
+ final Function fetchForwardTo;
+ final bool isNullable;
+
+ ElementTypeMask(
+ this.fetchForwardTo, this.element, {this.isNullable: true});
+
+ bool get isElement => true;
+
+ TypeMask get forwardTo {
+ TypeMask forward = fetchForwardTo(element);
+ return isNullable ? forward.nullable() : forward.nonNullable();
+ }
+
+ bool operator==(other) {
+ if (other is! ElementTypeMask) return false;
+ return element == other.element && isNullable == other.isNullable;
+ }
+
+ bool equalsDisregardNull(other) {
+ if (other is! ElementTypeMask) return false;
+ return element == other.element;
+ }
+
+ TypeMask nullable() {
+ return isNullable
+ ? this
+ : new ElementTypeMask(fetchForwardTo, element, isNullable: true);
+ }
+
+ TypeMask nonNullable() {
+ return isNullable
+ ? new ElementTypeMask(fetchForwardTo, element, isNullable: false)
+ : this;
+ }
+
+ String toString() {
+ return 'Type for element $element';
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698