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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class SsaCodeGeneratorTask extends CompilerTask { 5 class SsaCodeGeneratorTask extends CompilerTask {
6 6
7 final JavaScriptBackend backend; 7 final JavaScriptBackend backend;
8 8
9 SsaCodeGeneratorTask(JavaScriptBackend backend) 9 SsaCodeGeneratorTask(JavaScriptBackend backend)
10 : this.backend = backend, 10 : this.backend = backend,
(...skipping 2234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 push(new js.Call(field, <js.Expression>[])); 2245 push(new js.Call(field, <js.Expression>[]));
2246 if (negative) push(new js.Prefix('!', pop())); 2246 if (negative) push(new js.Prefix('!', pop()));
2247 } else { 2247 } else {
2248 // We always negate at least once so that the result is boolified. 2248 // We always negate at least once so that the result is boolified.
2249 push(new js.Prefix('!', field)); 2249 push(new js.Prefix('!', field));
2250 // If the result is not negated, put another '!' in front. 2250 // If the result is not negated, put another '!' in front.
2251 if (!negative) push(new js.Prefix('!', pop())); 2251 if (!negative) push(new js.Prefix('!', pop()));
2252 } 2252 }
2253 } 2253 }
2254 2254
2255 void handleStringSupertypeCheck(HInstruction input, DartType type) { 2255 void handleNumberOrStringSupertypeCheck(HInstruction input, DartType type) {
2256 // Make sure List and String don't share supertypes, otherwise we
2257 // would need to check for List too.
2258 assert(type.element !== compiler.listClass 2256 assert(type.element !== compiler.listClass
2259 && !Elements.isListSupertype(type.element, compiler)); 2257 && !Elements.isListSupertype(type.element, compiler)
2258 && !Elements.isStringOnlySupertype(type.element, compiler));
2259 checkNum(input, '===');
2260 js.Expression numberTest = pop();
2260 checkString(input, '==='); 2261 checkString(input, '===');
2261 js.Expression stringTest = pop(); 2262 js.Expression stringTest = pop();
2262 checkObject(input, '==='); 2263 checkObject(input, '===');
2264 js.Expression objectTest = pop();
2265 checkType(input, type);
2266 push(new js.Binary('||',
2267 new js.Binary('||', numberTest, stringTest),
2268 new js.Binary('&&', objectTest, pop())));
2269 }
2270
2271 void handleStringSupertypeCheck(HInstruction input, DartType type) {
2272 assert(type.element !== compiler.listClass
2273 && !Elements.isListSupertype(type.element, compiler)
2274 && !Elements.isNumberOrStringSupertype(type.element, compiler));
2275 checkString(input, '===');
2276 js.Expression stringTest = pop();
2277 checkObject(input, '===');
2263 js.Expression objectTest = pop(); 2278 js.Expression objectTest = pop();
2264 checkType(input, type); 2279 checkType(input, type);
2265 push(new js.Binary('||', 2280 push(new js.Binary('||',
2266 stringTest, 2281 stringTest,
2267 new js.Binary('&&', objectTest, pop()))); 2282 new js.Binary('&&', objectTest, pop())));
2268 } 2283 }
2269 2284
2270 void handleListOrSupertypeCheck(HInstruction input, DartType type) { 2285 void handleListOrSupertypeCheck(HInstruction input, DartType type) {
2271 // Make sure List and String don't share supertypes, otherwise we
2272 // would need to check for String too.
2273 assert(type.element !== compiler.stringClass 2286 assert(type.element !== compiler.stringClass
2274 && !Elements.isStringSupertype(type.element, compiler)); 2287 && !Elements.isStringOnlySupertype(type.element, compiler)
2288 && !Elements.isNumberOrStringSupertype(type.element, compiler));
2275 checkObject(input, '==='); 2289 checkObject(input, '===');
2276 js.Expression objectTest = pop(); 2290 js.Expression objectTest = pop();
2277 checkArray(input, '==='); 2291 checkArray(input, '===');
2278 js.Expression arrayTest = pop(); 2292 js.Expression arrayTest = pop();
2279 checkType(input, type); 2293 checkType(input, type);
2280 push(new js.Binary('&&', 2294 push(new js.Binary('&&',
2281 objectTest, 2295 objectTest,
2282 new js.Binary('||', arrayTest, pop()))); 2296 new js.Binary('||', arrayTest, pop())));
2283 } 2297 }
2284 2298
(...skipping 29 matching lines...) Expand all
2314 checkFunction(input, type); 2328 checkFunction(input, type);
2315 attachLocationToLast(node); 2329 attachLocationToLast(node);
2316 } else if (element == compiler.intClass) { 2330 } else if (element == compiler.intClass) {
2317 // The is check in the code tells us that it might not be an 2331 // The is check in the code tells us that it might not be an
2318 // int. So we do a typeof first to avoid possible 2332 // int. So we do a typeof first to avoid possible
2319 // deoptimizations on the JS engine due to the Math.floor check. 2333 // deoptimizations on the JS engine due to the Math.floor check.
2320 checkNum(input, '==='); 2334 checkNum(input, '===');
2321 js.Expression numTest = pop(); 2335 js.Expression numTest = pop();
2322 checkBigInt(input, '==='); 2336 checkBigInt(input, '===');
2323 push(new js.Binary('&&', numTest, pop()), node); 2337 push(new js.Binary('&&', numTest, pop()), node);
2324 } else if (Elements.isStringSupertype(element, compiler)) { 2338 } else if (Elements.isNumberOrStringSupertype(element, compiler)) {
2339 handleNumberOrStringSupertypeCheck(input, type);
2340 attachLocationToLast(node);
2341 } else if (Elements.isStringOnlySupertype(element, compiler)) {
2325 handleStringSupertypeCheck(input, type); 2342 handleStringSupertypeCheck(input, type);
2326 attachLocationToLast(node); 2343 attachLocationToLast(node);
2327 } else if (element === compiler.listClass 2344 } else if (element === compiler.listClass
2328 || Elements.isListSupertype(element, compiler)) { 2345 || Elements.isListSupertype(element, compiler)) {
2329 handleListOrSupertypeCheck(input, type); 2346 handleListOrSupertypeCheck(input, type);
2330 attachLocationToLast(node); 2347 attachLocationToLast(node);
2331 } else if (types[input].canBePrimitive() || types[input].canBeNull()) { 2348 } else if (types[input].canBePrimitive() || types[input].canBeNull()) {
2332 checkObject(input, '==='); 2349 checkObject(input, '===');
2333 js.Expression objectTest = pop(); 2350 js.Expression objectTest = pop();
2334 checkType(input, type); 2351 checkType(input, type);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 "doubleTypeCheck": 2385 "doubleTypeCheck":
2369 const SourceString("doubleTypeCast"), 2386 const SourceString("doubleTypeCast"),
2370 "numTypeCheck": 2387 "numTypeCheck":
2371 const SourceString("numTypeCast"), 2388 const SourceString("numTypeCast"),
2372 "boolTypeCheck": 2389 "boolTypeCheck":
2373 const SourceString("boolTypeCast"), 2390 const SourceString("boolTypeCast"),
2374 "functionTypeCheck": 2391 "functionTypeCheck":
2375 const SourceString("functionTypeCast"), 2392 const SourceString("functionTypeCast"),
2376 "intTypeCheck": 2393 "intTypeCheck":
2377 const SourceString("intTypeCast"), 2394 const SourceString("intTypeCast"),
2395 "numberOrStringSuperNativeTypeCheck":
2396 const SourceString("numberOrStringSuperNativeTypeCast"),
2397 "numberOrStringSuperTypeCheck":
2398 const SourceString("numberOrStringSuperTypeCast"),
2378 "stringSuperNativeTypeCheck": 2399 "stringSuperNativeTypeCheck":
2379 const SourceString("stringSuperNativeTypeCast"), 2400 const SourceString("stringSuperNativeTypeCast"),
2380 "stringSuperTypeCheck": 2401 "stringSuperTypeCheck":
2381 const SourceString("stringSuperTypeCast"), 2402 const SourceString("stringSuperTypeCast"),
2382 "listTypeCheck": 2403 "listTypeCheck":
2383 const SourceString("listTypeCast"), 2404 const SourceString("listTypeCast"),
2384 "listSuperNativeTypeCheck": 2405 "listSuperNativeTypeCheck":
2385 const SourceString("listSuperNativeTypeCast"), 2406 const SourceString("listSuperNativeTypeCast"),
2386 "listSuperTypeCheck": 2407 "listSuperTypeCheck":
2387 const SourceString("listSuperTypeCast"), 2408 const SourceString("listSuperTypeCast"),
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
2947 if (leftType.canBeNull() && rightType.canBeNull()) { 2968 if (leftType.canBeNull() && rightType.canBeNull()) {
2948 if (left.isConstantNull() || right.isConstantNull() || 2969 if (left.isConstantNull() || right.isConstantNull() ||
2949 (leftType.isPrimitive() && leftType == rightType)) { 2970 (leftType.isPrimitive() && leftType == rightType)) {
2950 return '=='; 2971 return '==';
2951 } 2972 }
2952 return null; 2973 return null;
2953 } else { 2974 } else {
2954 return '==='; 2975 return '===';
2955 } 2976 }
2956 } 2977 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698