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

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: 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..99495d6d5d36f635ba37fee64fa5958636fe51d4 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 {
@@ -42,11 +43,13 @@ abstract class Constant {
bool isNaN() => false;
bool isMinusZero() => false;
+ bool get isType => false;
ngeoffray 2012/11/15 16:07:24 bool isType() => false and move it to where the ot
karlklose 2012/11/19 15:08:58 Done.
+
DartType computeType(Compiler compiler);
List<Constant> getDependencies();
- accept(ConstantVisitor);
+ accept(ConstantVisitor visitor);
}
class SentinelConstant extends Constant {
@@ -316,11 +319,35 @@ abstract class ObjectConstant extends Constant {
DartType computeType(Compiler compiler) => type;
- // TODO(1603): The class should be marked as abstract, but the VM doesn't
- // currently allow this.
int get hashCode;
floitsch 2012/11/16 13:53:31 Remove the hashCode line too.
karlklose 2012/11/19 15:08:58 Done.
}
+class TypeConstant extends Constant {
ngeoffray 2012/11/15 16:07:24 extends ObjectConstant ?
karlklose 2012/11/19 15:08:58 Done.
+ /// The user type that this constant represents.
+ final DartType representedType;
+ /// The type of the constant (currently always [Type]).
ngeoffray 2012/11/15 16:07:24 Should it be something else? Please add a comment.
karlklose 2012/11/19 15:08:58 It could be more specific in the future, but the c
+ final DartType type;
+
+ TypeConstant(this.representedType, this.type);
+
+ bool get isType => true;
+ bool isObject() => true;
+
+ DartType computeType(Compiler compiler) {
+ return compiler.typeClass.computeType(compiler);
ngeoffray 2012/11/15 16:07:24 Remove, it will be inherited with ObjectConstant.
karlklose 2012/11/19 15:08:58 Done.
+ }
+
+ bool operator ==(other) {
+ return other is TypeConstant && representedType == other.representedType;
+ }
+
+ int get hashCode => representedType.hashCode * 13;
+
+ List<Constant> getDependencies() => const <Constant>[];
+
+ accept(ConstantVisitor visitor) => visitor.visitType(this);
+}
+
class ListConstant extends ObjectConstant {
final List<Constant> entries;
final int hashCode;

Powered by Google App Engine
This is Rietveld 408576698