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

Unified Diff: lib/compiler/implementation/ssa/types.dart

Issue 10353014: Start implementing checked mode and tools support for using it. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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/ssa/types.dart
===================================================================
--- lib/compiler/implementation/ssa/types.dart (revision 7269)
+++ lib/compiler/implementation/ssa/types.dart (working copy)
@@ -5,26 +5,44 @@
abstract class HType {
const HType();
- factory HType.fromBoundedType(Type type, Compiler compiler) {
+ factory HType.fromBoundedType(Type type,
floitsch 2012/05/07 09:50:07 /***/ doc explaining what boundedType means.
ngeoffray 2012/05/07 13:15:42 Done.
+ Compiler compiler,
+ [bool canBeNull = false]) {
Element element = type.element;
if (element.kind === ElementKind.TYPE_VARIABLE) {
compiler.unimplemented("type variables");
}
- if (element === compiler.intClass) {
- return HType.INTEGER;
- } else if (element === compiler.numClass) {
- return HType.NUMBER;
- } else if (element === compiler.doubleClass) {
- return HType.DOUBLE;
- } else if (element === compiler.stringClass) {
- return HType.STRING;
- } else if (element === compiler.listClass
- || Elements.isStringSupertype(element, compiler)
- || Elements.isListSupertype(element, compiler)) {
- return new HBoundedPotentialPrimitiveType(type);
+ if (!canBeNull) {
+ if (element === compiler.intClass) {
+ return HType.INTEGER;
+ } else if (element === compiler.numClass) {
+ return HType.NUMBER;
+ } else if (element === compiler.doubleClass) {
+ return HType.DOUBLE;
+ } else if (element === compiler.stringClass) {
+ return HType.STRING;
+ } else if (element === compiler.boolClass) {
+ return HType.BOOLEAN;
+ }
+ }
+ if (element === compiler.listClass
+ || Elements.isListSupertype(element, compiler)) {
+ return new HBoundedPotentialPrimitiveArray(type, canBeNull);
+ } else if (Elements.isStringSupertype(element, compiler)) {
+ return new HBoundedPotentialPrimitiveString(type, canBeNull);
+ } else if (element === compiler.objectClass
+ || element === compiler.dynamicClass) {
+ return null;
+ } else if (element === compiler.intClass
+ || element === compiler.boolClass
+ || element === compiler.numClass
+ || element === compiler.doubleClass
+ || element === compiler.stringClass) {
+ // TODO(ngeoffray): Create primitive nullable types.
+ return null;
floitsch 2012/05/07 09:50:07 Please don't return 'null' from a factory. I would
ngeoffray 2012/05/07 13:15:42 I plan on changing that. I added a TODO here and w
} else {
- return new HBoundedType(type);
+ return new HBoundedType(type, canBeNull);
}
}
@@ -328,8 +346,11 @@
class HBoundedType extends HType {
final Type type;
+ final bool _canBeNull;
- const HBoundedType(Type this.type);
+ bool canBeNull() => _canBeNull;
+
+ const HBoundedType(Type this.type, [bool this._canBeNull = false]);
String toString() => type.toString();
Type computeType(Compiler compiler) => type;
@@ -369,7 +390,26 @@
}
}
-class HBoundedPotentialPrimitiveType extends HBoundedType {
- const HBoundedPotentialPrimitiveType(Type type) : super(type);
+class HBoundedPotentialPrimitiveArray extends HBoundedType {
+ const HBoundedPotentialPrimitiveArray(Type type, bool canBeNull)
+ : super(type, canBeNull);
bool canBePrimitive() => true;
+
+ HType combine(HType other) {
+ if (other.isReadableArray()) return other;
+ if (other.isIndexablePrimitive()) return HType.READABLE_ARRAY;
+ return super.combine(other);
+ }
}
+
+class HBoundedPotentialPrimitiveString extends HBoundedType {
+ const HBoundedPotentialPrimitiveString(Type type, bool canBeNull)
+ : super(type, canBeNull);
+ bool canBePrimitive() => true;
+
+ HType combine(HType other) {
+ if (other.isString()) return other;
+ if (other.isIndexablePrimitive) return HType.STRING;
+ return super.combine(other);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698