Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 class SsaCodeGeneratorTask extends CompilerTask { | 7 class SsaCodeGeneratorTask extends CompilerTask { |
| 8 | 8 |
| 9 final JavaScriptBackend backend; | 9 final JavaScriptBackend backend; |
| 10 | 10 |
| (...skipping 2286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2297 use(input); | 2297 use(input); |
| 2298 | 2298 |
| 2299 js.PropertyAccess field = | 2299 js.PropertyAccess field = |
| 2300 new js.PropertyAccess.field(pop(), backend.namer.operatorIsType(type)); | 2300 new js.PropertyAccess.field(pop(), backend.namer.operatorIsType(type)); |
| 2301 // We always negate at least once so that the result is boolified. | 2301 // We always negate at least once so that the result is boolified. |
| 2302 push(new js.Prefix('!', field)); | 2302 push(new js.Prefix('!', field)); |
| 2303 // If the result is not negated, put another '!' in front. | 2303 // If the result is not negated, put another '!' in front. |
| 2304 if (!negative) push(new js.Prefix('!', pop())); | 2304 if (!negative) push(new js.Prefix('!', pop())); |
| 2305 } | 2305 } |
| 2306 | 2306 |
| 2307 void checkTypeViaInstanceof( | |
| 2308 HInstruction input, DartType type, bool negative) { | |
| 2309 registry.registerIsCheck(type); | |
| 2310 | |
| 2311 use(input); | |
| 2312 | |
| 2313 js.Expression jsClassReference = | |
| 2314 backend.emitter.constructorAccess(type.element); | |
|
floitsch
2015/01/16 14:14:33
Please confirm that `constructorAccess` is correct
sra1
2015/01/20 20:07:27
Verified.
| |
| 2315 push(js.js('# instanceof #', [pop(), jsClassReference])); | |
| 2316 if (negative) push(new js.Prefix('!', pop())); | |
| 2317 } | |
| 2318 | |
| 2307 void handleNumberOrStringSupertypeCheck(HInstruction input, | 2319 void handleNumberOrStringSupertypeCheck(HInstruction input, |
| 2308 HInstruction interceptor, | 2320 HInstruction interceptor, |
| 2309 DartType type, | 2321 DartType type, |
| 2310 { bool negative: false }) { | 2322 { bool negative: false }) { |
| 2311 assert(!identical(type.element, compiler.listClass) | 2323 assert(!identical(type.element, compiler.listClass) |
| 2312 && !Elements.isListSupertype(type.element, compiler) | 2324 && !Elements.isListSupertype(type.element, compiler) |
| 2313 && !Elements.isStringOnlySupertype(type.element, compiler)); | 2325 && !Elements.isStringOnlySupertype(type.element, compiler)); |
| 2314 String relation = negative ? '!==' : '==='; | 2326 String relation = negative ? '!==' : '==='; |
| 2315 checkNum(input, relation); | 2327 checkNum(input, relation); |
| 2316 js.Expression numberTest = pop(); | 2328 js.Expression numberTest = pop(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2414 checkBool(input, relation); | 2426 checkBool(input, relation); |
| 2415 attachLocationToLast(node); | 2427 attachLocationToLast(node); |
| 2416 } else if (element == compiler.intClass) { | 2428 } else if (element == compiler.intClass) { |
| 2417 // The is check in the code tells us that it might not be an | 2429 // The is check in the code tells us that it might not be an |
| 2418 // int. So we do a typeof first to avoid possible | 2430 // int. So we do a typeof first to avoid possible |
| 2419 // deoptimizations on the JS engine due to the Math.floor check. | 2431 // deoptimizations on the JS engine due to the Math.floor check. |
| 2420 checkNum(input, relation); | 2432 checkNum(input, relation); |
| 2421 js.Expression numTest = pop(); | 2433 js.Expression numTest = pop(); |
| 2422 checkBigInt(input, relation); | 2434 checkBigInt(input, relation); |
| 2423 push(new js.Binary(negative ? '||' : '&&', numTest, pop()), node); | 2435 push(new js.Binary(negative ? '||' : '&&', numTest, pop()), node); |
| 2436 } else if (node.useInstanceOf) { | |
| 2437 assert(interceptor == null); | |
| 2438 checkTypeViaInstanceof(input, type, negative); | |
| 2439 attachLocationToLast(node); | |
| 2424 } else if (Elements.isNumberOrStringSupertype(element, compiler)) { | 2440 } else if (Elements.isNumberOrStringSupertype(element, compiler)) { |
| 2425 handleNumberOrStringSupertypeCheck( | 2441 handleNumberOrStringSupertypeCheck( |
| 2426 input, interceptor, type, negative: negative); | 2442 input, interceptor, type, negative: negative); |
| 2427 attachLocationToLast(node); | 2443 attachLocationToLast(node); |
| 2428 } else if (Elements.isStringOnlySupertype(element, compiler)) { | 2444 } else if (Elements.isStringOnlySupertype(element, compiler)) { |
| 2429 handleStringSupertypeCheck( | 2445 handleStringSupertypeCheck( |
| 2430 input, interceptor, type, negative: negative); | 2446 input, interceptor, type, negative: negative); |
| 2431 attachLocationToLast(node); | 2447 attachLocationToLast(node); |
| 2432 } else if (identical(element, compiler.listClass) | 2448 } else if (identical(element, compiler.listClass) |
| 2433 || Elements.isListSupertype(element, compiler)) { | 2449 || Elements.isListSupertype(element, compiler)) { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2652 js.PropertyAccess accessHelper(String name) { | 2668 js.PropertyAccess accessHelper(String name) { |
| 2653 Element helper = backend.findHelper(name); | 2669 Element helper = backend.findHelper(name); |
| 2654 if (helper == null) { | 2670 if (helper == null) { |
| 2655 // For mocked-up tests. | 2671 // For mocked-up tests. |
| 2656 return js.js('(void 0).$name'); | 2672 return js.js('(void 0).$name'); |
| 2657 } | 2673 } |
| 2658 registry.registerStaticUse(helper); | 2674 registry.registerStaticUse(helper); |
| 2659 return backend.emitter.staticFunctionAccess(helper); | 2675 return backend.emitter.staticFunctionAccess(helper); |
| 2660 } | 2676 } |
| 2661 } | 2677 } |
| OLD | NEW |