| 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 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 2318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2329 const SourceString("listSuperNativeTypeCast"), | 2329 const SourceString("listSuperNativeTypeCast"), |
| 2330 "listSuperTypeCheck": | 2330 "listSuperTypeCheck": |
| 2331 const SourceString("listSuperTypeCast"), | 2331 const SourceString("listSuperTypeCast"), |
| 2332 "callTypeCheck": | 2332 "callTypeCheck": |
| 2333 const SourceString("callTypeCast"), | 2333 const SourceString("callTypeCast"), |
| 2334 "propertyTypeCheck": | 2334 "propertyTypeCheck": |
| 2335 const SourceString("propertyTypeCast") | 2335 const SourceString("propertyTypeCast") |
| 2336 }; | 2336 }; |
| 2337 | 2337 |
| 2338 if (node.isChecked) { | 2338 if (node.isChecked) { |
| 2339 Element element = node.type.computeType(compiler).element; | 2339 Type type = node.type.computeType(compiler); |
| 2340 Element element = type.element; |
| 2340 world.registerIsCheck(element); | 2341 world.registerIsCheck(element); |
| 2341 SourceString helper; | |
| 2342 String additionalArgument; | |
| 2343 bool nativeCheck = | |
| 2344 backend.emitter.nativeEmitter.requiresNativeIsCheck(element); | |
| 2345 | 2342 |
| 2346 if (node.isArgumentTypeCheck) { | 2343 if (node.isArgumentTypeCheck) { |
| 2347 if (element == compiler.intClass) { | 2344 if (element == compiler.intClass) { |
| 2348 checkInt(node.checkedInput, '!=='); | 2345 checkInt(node.checkedInput, '!=='); |
| 2349 } else { | 2346 } else { |
| 2350 assert(element == compiler.numClass); | 2347 assert(element == compiler.numClass); |
| 2351 checkNum(node.checkedInput, '!=='); | 2348 checkNum(node.checkedInput, '!=='); |
| 2352 } | 2349 } |
| 2353 js.Expression test = pop(); | 2350 js.Expression test = pop(); |
| 2354 js.Block oldContainer = currentContainer; | 2351 js.Block oldContainer = currentContainer; |
| 2355 js.Statement body = new js.Block.empty(); | 2352 js.Statement body = new js.Block.empty(); |
| 2356 currentContainer = body; | 2353 currentContainer = body; |
| 2357 generateThrowWithHelper('iae', node.checkedInput); | 2354 generateThrowWithHelper('iae', node.checkedInput); |
| 2358 currentContainer = oldContainer; | 2355 currentContainer = oldContainer; |
| 2359 body = unwrapStatement(body); | 2356 body = unwrapStatement(body); |
| 2360 pushStatement(new js.If.then(test, body), node); | 2357 pushStatement(new js.If.then(test, body), node); |
| 2361 return; | 2358 return; |
| 2362 } | 2359 } |
| 2363 | 2360 |
| 2364 assert(node.isCheckedModeCheck || node.isCastTypeCheck); | 2361 assert(node.isCheckedModeCheck || node.isCastTypeCheck); |
| 2365 if (element == compiler.stringClass) { | 2362 SourceString helper = backend.getCheckedModeHelper(type); |
| 2366 helper = const SourceString('stringTypeCheck'); | 2363 String additionalArgument = compiler.namer.operatorIs(element); |
| 2367 } else if (element == compiler.doubleClass) { | |
| 2368 helper = const SourceString('doubleTypeCheck'); | |
| 2369 } else if (element == compiler.numClass) { | |
| 2370 helper = const SourceString('numTypeCheck'); | |
| 2371 } else if (element == compiler.boolClass) { | |
| 2372 helper = const SourceString('boolTypeCheck'); | |
| 2373 } else if (element == compiler.functionClass || element.isTypedef()) { | |
| 2374 helper = const SourceString('functionTypeCheck'); | |
| 2375 } else if (element == compiler.intClass) { | |
| 2376 helper = const SourceString('intTypeCheck'); | |
| 2377 } else if (Elements.isStringSupertype(element, compiler)) { | |
| 2378 additionalArgument = compiler.namer.operatorIs(element); | |
| 2379 if (nativeCheck) { | |
| 2380 helper = const SourceString('stringSuperNativeTypeCheck'); | |
| 2381 } else { | |
| 2382 helper = const SourceString('stringSuperTypeCheck'); | |
| 2383 } | |
| 2384 } else if (element === compiler.listClass) { | |
| 2385 helper = const SourceString('listTypeCheck'); | |
| 2386 } else { | |
| 2387 additionalArgument = compiler.namer.operatorIs(element); | |
| 2388 if (Elements.isListSupertype(element, compiler)) { | |
| 2389 if (nativeCheck) { | |
| 2390 helper = const SourceString('listSuperNativeTypeCheck'); | |
| 2391 } else { | |
| 2392 helper = const SourceString('listSuperTypeCheck'); | |
| 2393 } | |
| 2394 } else if (nativeCheck) { | |
| 2395 helper = const SourceString('callTypeCheck'); | |
| 2396 } else { | |
| 2397 helper = const SourceString('propertyTypeCheck'); | |
| 2398 } | |
| 2399 } | |
| 2400 if (node.isCastTypeCheck) { | 2364 if (node.isCastTypeCheck) { |
| 2401 helper = castNames[helper.stringValue]; | 2365 helper = castNames[helper.stringValue]; |
| 2402 } | 2366 } |
| 2403 Element helperElement = compiler.findHelper(helper); | 2367 Element helperElement = compiler.findHelper(helper); |
| 2404 world.registerStaticUse(helperElement); | 2368 world.registerStaticUse(helperElement); |
| 2405 List<js.Expression> arguments = <js.Expression>[]; | 2369 List<js.Expression> arguments = <js.Expression>[]; |
| 2406 use(node.checkedInput); | 2370 use(node.checkedInput); |
| 2407 arguments.add(pop()); | 2371 arguments.add(pop()); |
| 2408 if (additionalArgument !== null) { | 2372 arguments.add(new js.LiteralString("'$additionalArgument'")); |
| 2409 arguments.add(new js.LiteralString("'$additionalArgument'")); | |
| 2410 } | |
| 2411 String helperName = compiler.namer.isolateAccess(helperElement); | 2373 String helperName = compiler.namer.isolateAccess(helperElement); |
| 2412 push(new js.Call(new js.VariableUse(helperName), arguments)); | 2374 push(new js.Call(new js.VariableUse(helperName), arguments)); |
| 2413 } else { | 2375 } else { |
| 2414 use(node.checkedInput); | 2376 use(node.checkedInput); |
| 2415 } | 2377 } |
| 2416 } | 2378 } |
| 2417 } | 2379 } |
| 2418 | 2380 |
| 2419 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { | 2381 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { |
| 2420 SsaOptimizedCodeGenerator(backend, work, parameters, parameterNames) | 2382 SsaOptimizedCodeGenerator(backend, work, parameters, parameterNames) |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2925 if (leftType.canBeNull() && rightType.canBeNull()) { | 2887 if (leftType.canBeNull() && rightType.canBeNull()) { |
| 2926 if (left.isConstantNull() || right.isConstantNull() || | 2888 if (left.isConstantNull() || right.isConstantNull() || |
| 2927 (leftType.isPrimitive() && leftType == rightType)) { | 2889 (leftType.isPrimitive() && leftType == rightType)) { |
| 2928 return '=='; | 2890 return '=='; |
| 2929 } | 2891 } |
| 2930 return null; | 2892 return null; |
| 2931 } else { | 2893 } else { |
| 2932 return '==='; | 2894 return '==='; |
| 2933 } | 2895 } |
| 2934 } | 2896 } |
| OLD | NEW |