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/constants.dart

Issue 11299009: Support type literals as compile-time constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 1 month 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/constants.dart
diff --git a/sdk/lib/_internal/compiler/implementation/constants.dart b/sdk/lib/_internal/compiler/implementation/constants.dart
index 6e20124983af46d758df100113e5424b07e555a8..880149bc03df0986ae918a3aa62c1cbc474736bc 100644
--- a/sdk/lib/_internal/compiler/implementation/constants.dart
+++ b/sdk/lib/_internal/compiler/implementation/constants.dart
@@ -16,6 +16,7 @@ abstract class ConstantVisitor<R> {
R visitList(ListConstant constant);
R visitMap(MapConstant constant);
R visitConstructed(ConstructedConstant constant);
+ R visitType(TypeConstant constant);
}
abstract class Constant {
@@ -37,6 +38,7 @@ abstract class Constant {
bool isPrimitive() => false;
/** Returns true if the constant is a list, a map or a constructed object. */
bool isObject() => false;
+ bool isType() => false;
bool isSentinel() => false;
bool isNaN() => false;
@@ -46,7 +48,7 @@ abstract class Constant {
List<Constant> getDependencies();
- accept(ConstantVisitor);
+ accept(ConstantVisitor visitor);
}
class SentinelConstant extends Constant {
@@ -315,10 +317,25 @@ abstract class ObjectConstant extends Constant {
bool isObject() => true;
DartType computeType(Compiler compiler) => type;
+}
+
+class TypeConstant extends ObjectConstant {
+ /// The user type that this constant represents.
+ final DartType representedType;
+
+ TypeConstant(this.representedType, type) : super(type);
+
+ bool isType() => true;
+
+ bool operator ==(other) {
+ return other is TypeConstant && representedType == other.representedType;
+ }
+
+ int get hashCode => representedType.hashCode * 13;
+
+ List<Constant> getDependencies() => const <Constant>[];
- // TODO(1603): The class should be marked as abstract, but the VM doesn't
- // currently allow this.
- int get hashCode;
+ accept(ConstantVisitor visitor) => visitor.visitType(this);
}
class ListConstant extends ObjectConstant {

Powered by Google App Engine
This is Rietveld 408576698