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); |
| 2315 push(js.js('# instanceof #', [pop(), jsClassReference])); |
| 2316 if (negative) push(new js.Prefix('!', pop())); |
| 2317 registry.registerInstantiatedType(type); |
| 2318 } |
| 2319 |
2307 void handleNumberOrStringSupertypeCheck(HInstruction input, | 2320 void handleNumberOrStringSupertypeCheck(HInstruction input, |
2308 HInstruction interceptor, | 2321 HInstruction interceptor, |
2309 DartType type, | 2322 DartType type, |
2310 { bool negative: false }) { | 2323 { bool negative: false }) { |
2311 assert(!identical(type.element, compiler.listClass) | 2324 assert(!identical(type.element, compiler.listClass) |
2312 && !Elements.isListSupertype(type.element, compiler) | 2325 && !Elements.isListSupertype(type.element, compiler) |
2313 && !Elements.isStringOnlySupertype(type.element, compiler)); | 2326 && !Elements.isStringOnlySupertype(type.element, compiler)); |
2314 String relation = negative ? '!==' : '==='; | 2327 String relation = negative ? '!==' : '==='; |
2315 checkNum(input, relation); | 2328 checkNum(input, relation); |
2316 js.Expression numberTest = pop(); | 2329 js.Expression numberTest = pop(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2414 checkBool(input, relation); | 2427 checkBool(input, relation); |
2415 attachLocationToLast(node); | 2428 attachLocationToLast(node); |
2416 } else if (element == compiler.intClass) { | 2429 } else if (element == compiler.intClass) { |
2417 // The is check in the code tells us that it might not be an | 2430 // 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 | 2431 // int. So we do a typeof first to avoid possible |
2419 // deoptimizations on the JS engine due to the Math.floor check. | 2432 // deoptimizations on the JS engine due to the Math.floor check. |
2420 checkNum(input, relation); | 2433 checkNum(input, relation); |
2421 js.Expression numTest = pop(); | 2434 js.Expression numTest = pop(); |
2422 checkBigInt(input, relation); | 2435 checkBigInt(input, relation); |
2423 push(new js.Binary(negative ? '||' : '&&', numTest, pop()), node); | 2436 push(new js.Binary(negative ? '||' : '&&', numTest, pop()), node); |
| 2437 } else if (node.useInstanceOf) { |
| 2438 assert(interceptor == null); |
| 2439 checkTypeViaInstanceof(input, type, negative); |
| 2440 attachLocationToLast(node); |
2424 } else if (Elements.isNumberOrStringSupertype(element, compiler)) { | 2441 } else if (Elements.isNumberOrStringSupertype(element, compiler)) { |
2425 handleNumberOrStringSupertypeCheck( | 2442 handleNumberOrStringSupertypeCheck( |
2426 input, interceptor, type, negative: negative); | 2443 input, interceptor, type, negative: negative); |
2427 attachLocationToLast(node); | 2444 attachLocationToLast(node); |
2428 } else if (Elements.isStringOnlySupertype(element, compiler)) { | 2445 } else if (Elements.isStringOnlySupertype(element, compiler)) { |
2429 handleStringSupertypeCheck( | 2446 handleStringSupertypeCheck( |
2430 input, interceptor, type, negative: negative); | 2447 input, interceptor, type, negative: negative); |
2431 attachLocationToLast(node); | 2448 attachLocationToLast(node); |
2432 } else if (identical(element, compiler.listClass) | 2449 } else if (identical(element, compiler.listClass) |
2433 || Elements.isListSupertype(element, compiler)) { | 2450 || Elements.isListSupertype(element, compiler)) { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2652 js.PropertyAccess accessHelper(String name) { | 2669 js.PropertyAccess accessHelper(String name) { |
2653 Element helper = backend.findHelper(name); | 2670 Element helper = backend.findHelper(name); |
2654 if (helper == null) { | 2671 if (helper == null) { |
2655 // For mocked-up tests. | 2672 // For mocked-up tests. |
2656 return js.js('(void 0).$name'); | 2673 return js.js('(void 0).$name'); |
2657 } | 2674 } |
2658 registry.registerStaticUse(helper); | 2675 registry.registerStaticUse(helper); |
2659 return backend.emitter.staticFunctionAccess(helper); | 2676 return backend.emitter.staticFunctionAccess(helper); |
2660 } | 2677 } |
2661 } | 2678 } |
OLD | NEW |