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

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

Issue 10916172: num implements Comparable and Hashable. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
« no previous file with comments | « lib/compiler/implementation/ssa/optimize.dart ('k') | pkg/pkg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/ssa/types.dart
===================================================================
--- lib/compiler/implementation/ssa/types.dart (revision 12035)
+++ lib/compiler/implementation/ssa/types.dart (working copy)
@@ -32,7 +32,9 @@
} else if (element === compiler.listClass
|| Elements.isListSupertype(element, compiler)) {
return new HBoundedPotentialPrimitiveArray(type, canBeNull);
- } else if (Elements.isStringSupertype(element, compiler)) {
+ } else if (Elements.isNumberOrStringSupertype(element, compiler)) {
+ return new HBoundedPotentialPrimitiveNumberOrString(type, canBeNull);
+ } else if (Elements.isStringOnlySupertype(element, compiler)) {
return new HBoundedPotentialPrimitiveString(type, canBeNull);
} else {
return canBeNull ? new HBoundedType.withNull(type)
@@ -703,6 +705,47 @@
bool canBePrimitive() => true;
}
+class HBoundedPotentialPrimitiveNumberOrString
+ extends HBoundedPotentialPrimitiveType {
+ const HBoundedPotentialPrimitiveNumberOrString(DartType type, bool canBeNull)
+ : super(type, canBeNull);
+
+ HType union(HType other) {
+ if (other.isNumber()) return this;
+ if (other.isNumberOrNull()) {
+ if (canBeNull()) return this;
+ return new HBoundedPotentialPrimitiveNumberOrString(type, true);
+ }
+
+ if (other.isString()) return this;
+ if (other.isStringOrNull()) {
+ if (canBeNull()) return this;
+ return new HBoundedPotentialPrimitiveNumberOrString(type, true);
+ }
+
+ if (other.isNull()) {
+ if (canBeNull()) return this;
+ return new HBoundedPotentialPrimitiveNumberOrString(type, true);
+ }
+
+ return super.union(other);
+ }
+
+ HType intersection(HType other) {
+ if (other.isNumber()) return other;
+ if (other.isNumberOrNull()) {
+ if (!canBeNull()) return HType.NUMBER;
+ return other;
+ }
+ if (other.isString()) return other;
+ if (other.isStringOrNull()) {
+ if (!canBeNull()) return HType.STRING;
+ return other;
+ }
+ return super.intersection(other);
+ }
+}
+
class HBoundedPotentialPrimitiveArray extends HBoundedPotentialPrimitiveType {
const HBoundedPotentialPrimitiveArray(DartType type, bool canBeNull)
: super(type, canBeNull);
« no previous file with comments | « lib/compiler/implementation/ssa/optimize.dart ('k') | pkg/pkg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698