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

Unified Diff: lib/compiler/implementation/compile_time_constants.dart

Issue 10916002: Change switch to give errors when cases don't follow the newest syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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: lib/compiler/implementation/compile_time_constants.dart
diff --git a/lib/compiler/implementation/compile_time_constants.dart b/lib/compiler/implementation/compile_time_constants.dart
index ef4bbc8e72813c5a1d3920a56bb097ec7d058ba1..d080edb7fd97caee78b97047870c07996a3cc465 100644
--- a/lib/compiler/implementation/compile_time_constants.dart
+++ b/lib/compiler/implementation/compile_time_constants.dart
@@ -24,6 +24,8 @@ class Constant implements Hashable {
bool isNaN() => false;
+ abstract bool isSameType(Constant constant);
ngeoffray 2012/08/30 07:29:13 I'd prefer having something consistant with what w
Lasse Reichstein Nielsen 2012/08/30 10:54:25 Seems reasonable if there is a simple way to get a
ngeoffray 2012/08/30 11:07:13 The Dart "primitive" types? compiler.boolClass.com
Lasse Reichstein Nielsen 2012/09/03 09:12:56 Done.
+
abstract void _writeJsCode(CodeBuffer buffer, ConstantHandler handler);
/**
* Unless the constant can be emitted multiple times (as for numbers and
@@ -94,6 +96,7 @@ class NullConstant extends PrimitiveConstant {
const NullConstant._internal();
bool isNull() => true;
get value => null;
+ bool isSameType(Constant constant) => constant.isNull();
void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) {
buffer.add(JsNull);
@@ -132,6 +135,7 @@ class IntConstant extends NumConstant {
}
const IntConstant._internal(this.value);
bool isInt() => true;
+ bool isSameType(Constant constant) => constant.isInt();
void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) {
buffer.add("$value");
@@ -171,6 +175,7 @@ class DoubleConstant extends NumConstant {
const DoubleConstant._internal(this.value);
bool isDouble() => true;
bool isNaN() => value.isNaN();
+ bool isSameType(Constant constant) => constant.isDouble();
void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) {
if (value.isNaN()) {
@@ -207,6 +212,7 @@ class BoolConstant extends PrimitiveConstant {
}
const BoolConstant._internal();
bool isBool() => true;
+ bool isSameType(Constant constant) => constant.isBool();
BoolConstant unaryFold(String op) {
if (op == "!") return new BoolConstant(!value);
@@ -268,6 +274,7 @@ class StringConstant extends PrimitiveConstant {
_hashCode = value.slowToString().hashCode();
}
bool isString() => true;
+ bool isSameType(Constant constant) => constant.isString();
void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) {
buffer.add("'");
@@ -288,14 +295,12 @@ class StringConstant extends PrimitiveConstant {
int get length => value.length;
}
-class ObjectConstant extends Constant {
+abstract class ObjectConstant extends Constant {
final Type type;
ObjectConstant(this.type);
bool isObject() => true;
- // TODO(1603): The class should be marked as abstract, but the VM doesn't
- // currently allow this.
abstract int hashCode();
void _writeCanonicalizedJsCode(CodeBuffer buffer, ConstantHandler handler) {
@@ -315,6 +320,12 @@ class ListConstant extends ObjectConstant {
_hashCode = hash;
}
bool isList() => true;
+ bool isSameType(Constant constant) {
+ if (!constant.isList()) return false;
+ ListConstant listConstant = constant;
+ // TODO(lrn): Does this work at all?
+ return type == listConstant.type;
floitsch 2012/08/30 14:08:18 I would expect this to be always true. Maybe chang
Lasse Reichstein Nielsen 2012/09/03 09:12:56 It's gone now. Switched everything to having a com
+ }
void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) {
// TODO(floitsch): we should not need to go through the compiler to make
@@ -378,6 +389,12 @@ class MapConstant extends ObjectConstant {
}
bool isMap() => true;
+ bool isSameType(Constant constant) {
+ if (!constant.isMap()) return false;
+ MapConstant mapConstant = constant;
floitsch 2012/08/30 14:08:18 ditto, but no assert, since maps containing __prot
Lasse Reichstein Nielsen 2012/09/03 09:12:56 Gone too.
+ return type == mapConstant.type;
+ }
+
void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) {
void writeJsMap() {
@@ -476,6 +493,12 @@ class ConstructedConstant extends ObjectConstant {
_hashCode = hash;
}
bool isConstructedObject() => true;
+ bool isSameType(Constant constant) {
+ if (!constant.isConstructedObject()) return false;
+ ConstructredConstant constructedConstant = constant;
+ // TODO(lrn): Is this the entire type, including type parameters?
+ return type == constructedConstant.type;
+ }
void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) {
buffer.add("new ");
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/builder.dart » ('j') | lib/compiler/implementation/ssa/builder.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698