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

Unified Diff: sdk/lib/_internal/compiler/implementation/dart_types.dart

Issue 12334070: Support runtime check of function types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix status files 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/dart_types.dart
diff --git a/sdk/lib/_internal/compiler/implementation/dart_types.dart b/sdk/lib/_internal/compiler/implementation/dart_types.dart
index bcec9216fd829498ade4442538813988b38e116b..e24c7e92cb55c95fec5358cdda7aff7882d239a1 100644
--- a/sdk/lib/_internal/compiler/implementation/dart_types.dart
+++ b/sdk/lib/_internal/compiler/implementation/dart_types.dart
@@ -908,6 +908,8 @@ class Member {
}
abstract class DartTypeVisitor<R, A> {
+ const DartTypeVisitor();
+
R visitType(DartType type, A argument);
R visitVoidType(VoidType type, A argument) =>
@@ -1140,6 +1142,7 @@ class Types {
final VoidType voidType;
final DynamicType dynamicType;
final SubtypeVisitor subtypeVisitor;
+ final PotentialSubtypeVisitor potentialSubtypeVisitor;
factory Types(Compiler compiler, BaseClassElementX dynamicElement) {
LibraryElement library = new LibraryElementX(new Script(null, null));
@@ -1148,11 +1151,15 @@ class Types {
dynamicElement.rawTypeCache = dynamicElement.thisType = dynamicType;
SubtypeVisitor subtypeVisitor =
new SubtypeVisitor(compiler, dynamicType, voidType);
karlklose 2013/06/19 14:37:05 Can these two allocations be const? (see comment o
Johnni Winther 2013/06/21 12:19:15 No. See below.
- return new Types.internal(compiler, voidType, dynamicType, subtypeVisitor);
+ PotentialSubtypeVisitor potentialSubtypeVisitor =
+ new PotentialSubtypeVisitor(compiler, dynamicType, voidType);
+
+ return new Types.internal(compiler, voidType, dynamicType,
+ subtypeVisitor, potentialSubtypeVisitor);
}
Types.internal(this.compiler, this.voidType, this.dynamicType,
- this.subtypeVisitor);
+ this.subtypeVisitor, this.potentialSubtypeVisitor);
/** Returns true if t is a subtype of s */
bool isSubtype(DartType t, DartType s) {
@@ -1163,6 +1170,11 @@ class Types {
return subtypeVisitor.isAssignable(r, s);
}
+ bool isPotentialSubtype(DartType t, DartType s) {
+ // TODO(johnniwinther): Return a set of variable points in the positive
+ // cases.
+ return potentialSubtypeVisitor.isSubtype(t, s);
+ }
/**
* Helper method for performing substitution of a linked list of types.
@@ -1217,3 +1229,18 @@ class Types {
return typeVariable.element.enclosingElement;
}
}
+
+class PotentialSubtypeVisitor extends SubtypeVisitor {
karlklose 2013/06/19 14:37:05 Please add a comment on what this class does (in c
Johnni Winther 2013/06/21 12:19:15 Done.
+ PotentialSubtypeVisitor(Compiler compiler,
karlklose 2013/06/19 14:37:05 Can this constructor be const?
Johnni Winther 2013/06/21 12:19:15 It could, but we can provide no constant values fo
+ DynamicType dynamicType,
+ VoidType voidType)
+ : super(compiler, dynamicType, voidType);
+
+
+ bool isSubtype(DartType t, DartType s) {
+ if (t is TypeVariableType || s is TypeVariableType) {
+ return true;
+ }
+ return super.isSubtype(t, s);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698