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 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); |
|
floitsch
2012/08/30 14:35:14
Add Element element = type.element;
It's used freq
ngeoffray
2012/08/30 17:10:21
Done.
| |
| 2340 world.registerIsCheck(element); | 2340 world.registerIsCheck(type.element); |
| 2341 SourceString helper; | |
| 2342 String additionalArgument; | |
| 2343 bool nativeCheck = | |
| 2344 backend.emitter.nativeEmitter.requiresNativeIsCheck(element); | |
| 2345 | 2341 |
| 2346 if (node.isArgumentTypeCheck) { | 2342 if (node.isArgumentTypeCheck) { |
| 2347 if (element == compiler.intClass) { | 2343 if (type.element == compiler.intClass) { |
| 2348 checkInt(node.checkedInput, '!=='); | 2344 checkInt(node.checkedInput, '!=='); |
| 2349 } else { | 2345 } else { |
| 2350 assert(element == compiler.numClass); | 2346 assert(type.element == compiler.numClass); |
| 2351 checkNum(node.checkedInput, '!=='); | 2347 checkNum(node.checkedInput, '!=='); |
| 2352 } | 2348 } |
| 2353 js.Expression test = pop(); | 2349 js.Expression test = pop(); |
| 2354 js.Block oldContainer = currentContainer; | 2350 js.Block oldContainer = currentContainer; |
| 2355 js.Statement body = new js.Block.empty(); | 2351 js.Statement body = new js.Block.empty(); |
| 2356 currentContainer = body; | 2352 currentContainer = body; |
| 2357 generateThrowWithHelper('iae', node.checkedInput); | 2353 generateThrowWithHelper('iae', node.checkedInput); |
| 2358 currentContainer = oldContainer; | 2354 currentContainer = oldContainer; |
| 2359 body = unwrapStatement(body); | 2355 body = unwrapStatement(body); |
| 2360 pushStatement(new js.If.then(test, body), node); | 2356 pushStatement(new js.If.then(test, body), node); |
| 2361 return; | 2357 return; |
| 2362 } | 2358 } |
| 2363 | 2359 |
| 2364 assert(node.isCheckedModeCheck || node.isCastTypeCheck); | 2360 assert(node.isCheckedModeCheck || node.isCastTypeCheck); |
| 2365 if (element == compiler.stringClass) { | 2361 SourceString helper = backend.getCheckedModeHelper(type); |
| 2366 helper = const SourceString('stringTypeCheck'); | 2362 String additionalArgument = compiler.namer.operatorIs(type.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) { | 2363 if (node.isCastTypeCheck) { |
| 2401 helper = castNames[helper.stringValue]; | 2364 helper = castNames[helper.stringValue]; |
| 2402 } | 2365 } |
| 2403 Element helperElement = compiler.findHelper(helper); | 2366 Element helperElement = compiler.findHelper(helper); |
| 2404 world.registerStaticUse(helperElement); | 2367 world.registerStaticUse(helperElement); |
| 2405 List<js.Expression> arguments = <js.Expression>[]; | 2368 List<js.Expression> arguments = <js.Expression>[]; |
| 2406 use(node.checkedInput); | 2369 use(node.checkedInput); |
| 2407 arguments.add(pop()); | 2370 arguments.add(pop()); |
| 2408 if (additionalArgument !== null) { | 2371 arguments.add(new js.LiteralString("'$additionalArgument'")); |
| 2409 arguments.add(new js.LiteralString("'$additionalArgument'")); | |
| 2410 } | |
| 2411 String helperName = compiler.namer.isolateAccess(helperElement); | 2372 String helperName = compiler.namer.isolateAccess(helperElement); |
| 2412 push(new js.Call(new js.VariableUse(helperName), arguments)); | 2373 push(new js.Call(new js.VariableUse(helperName), arguments)); |
| 2413 } else { | 2374 } else { |
| 2414 use(node.checkedInput); | 2375 use(node.checkedInput); |
| 2415 } | 2376 } |
| 2416 } | 2377 } |
| 2417 } | 2378 } |
| 2418 | 2379 |
| 2419 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { | 2380 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { |
| 2420 SsaOptimizedCodeGenerator(backend, work, parameters, parameterNames) | 2381 SsaOptimizedCodeGenerator(backend, work, parameters, parameterNames) |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2925 if (leftType.canBeNull() && rightType.canBeNull()) { | 2886 if (leftType.canBeNull() && rightType.canBeNull()) { |
| 2926 if (left.isConstantNull() || right.isConstantNull() || | 2887 if (left.isConstantNull() || right.isConstantNull() || |
| 2927 (leftType.isPrimitive() && leftType == rightType)) { | 2888 (leftType.isPrimitive() && leftType == rightType)) { |
| 2928 return '=='; | 2889 return '=='; |
| 2929 } | 2890 } |
| 2930 return null; | 2891 return null; |
| 2931 } else { | 2892 } else { |
| 2932 return '==='; | 2893 return '==='; |
| 2933 } | 2894 } |
| 2934 } | 2895 } |
| OLD | NEW |