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

Unified Diff: lib/compiler/implementation/ssa/codegen.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
Index: lib/compiler/implementation/ssa/codegen.dart
===================================================================
--- lib/compiler/implementation/ssa/codegen.dart (revision 12025)
+++ lib/compiler/implementation/ssa/codegen.dart (working copy)
@@ -2252,11 +2252,26 @@
}
}
+ void handleNumberOrStringSupertypeCheck(HInstruction input, DartType type) {
+ assert(type.element !== compiler.listClass
+ && !Elements.isListSupertype(type.element, compiler)
+ && !Elements.isStringOnlySupertype(type.element, compiler));
+ checkNum(input, '===');
+ js.Expression numberTest = pop();
+ checkString(input, '===');
+ js.Expression stringTest = pop();
+ checkObject(input, '===');
+ js.Expression objectTest = pop();
+ checkType(input, type);
+ push(new js.Binary('||',
+ new js.Binary('||', numberTest, stringTest),
+ new js.Binary('&&', objectTest, pop())));
+ }
+
void handleStringSupertypeCheck(HInstruction input, DartType type) {
- // Make sure List and String don't share supertypes, otherwise we
- // would need to check for List too.
assert(type.element !== compiler.listClass
- && !Elements.isListSupertype(type.element, compiler));
+ && !Elements.isListSupertype(type.element, compiler)
+ && !Elements.isNumberOrStringSupertype(type.element, compiler));
checkString(input, '===');
js.Expression stringTest = pop();
checkObject(input, '===');
@@ -2268,10 +2283,9 @@
}
void handleListOrSupertypeCheck(HInstruction input, DartType type) {
- // Make sure List and String don't share supertypes, otherwise we
- // would need to check for String too.
assert(type.element !== compiler.stringClass
- && !Elements.isStringSupertype(type.element, compiler));
+ && !Elements.isStringOnlySupertype(type.element, compiler)
+ && !Elements.isNumberOrStringSupertype(type.element, compiler));
checkObject(input, '===');
js.Expression objectTest = pop();
checkArray(input, '===');
@@ -2321,7 +2335,10 @@
js.Expression numTest = pop();
checkBigInt(input, '===');
push(new js.Binary('&&', numTest, pop()), node);
- } else if (Elements.isStringSupertype(element, compiler)) {
+ } else if (Elements.isNumberOrStringSupertype(element, compiler)) {
+ handleNumberOrStringSupertypeCheck(input, type);
+ attachLocationToLast(node);
+ } else if (Elements.isStringOnlySupertype(element, compiler)) {
handleStringSupertypeCheck(input, type);
attachLocationToLast(node);
} else if (element === compiler.listClass
@@ -2375,6 +2392,10 @@
const SourceString("functionTypeCast"),
"intTypeCheck":
const SourceString("intTypeCast"),
+ "numberOrStringSuperNativeTypeCheck":
+ const SourceString("numberOrStringSuperNativeTypeCast"),
+ "numberOrStringSuperTypeCheck":
+ const SourceString("numberOrStringSuperTypeCast"),
"stringSuperNativeTypeCheck":
const SourceString("stringSuperNativeTypeCast"),
"stringSuperTypeCheck":

Powered by Google App Engine
This is Rietveld 408576698