| 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 2426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2437 js.Binary notObjectOrIndexingTest = | 2437 js.Binary notObjectOrIndexingTest = |
| 2438 new js.Binary('||', objectTest, notIndexingTest); | 2438 new js.Binary('||', objectTest, notIndexingTest); |
| 2439 test = new js.Binary('&&', stringTest, notObjectOrIndexingTest); | 2439 test = new js.Binary('&&', stringTest, notObjectOrIndexingTest); |
| 2440 } else { | 2440 } else { |
| 2441 compiler.internalError('Unexpected type guard', instruction: input); | 2441 compiler.internalError('Unexpected type guard', instruction: input); |
| 2442 } | 2442 } |
| 2443 return test; | 2443 return test; |
| 2444 } | 2444 } |
| 2445 | 2445 |
| 2446 void visitTypeConversion(HTypeConversion node) { | 2446 void visitTypeConversion(HTypeConversion node) { |
| 2447 if (node.isChecked) { | 2447 if (!node.isChecked) { |
| 2448 if (node.isArgumentTypeCheck || node.isReceiverTypeCheck) { | 2448 use(node.checkedInput); |
| 2449 js.Expression test = generateTest(node); | 2449 return; |
| 2450 js.Block oldContainer = currentContainer; | 2450 } |
| 2451 js.Statement body = new js.Block.empty(); | 2451 if (node.isArgumentTypeCheck || node.isReceiverTypeCheck) { |
| 2452 currentContainer = body; | 2452 js.Expression test = generateTest(node); |
| 2453 if (node.isArgumentTypeCheck) { | 2453 js.Block oldContainer = currentContainer; |
| 2454 generateThrowWithHelper('iae', node.checkedInput); | 2454 js.Statement body = new js.Block.empty(); |
| 2455 } else if (node.isReceiverTypeCheck) { | 2455 currentContainer = body; |
| 2456 use(node.checkedInput); | 2456 if (node.isArgumentTypeCheck) { |
| 2457 String methodName = | 2457 generateThrowWithHelper('iae', node.checkedInput); |
| 2458 backend.namer.invocationName(node.receiverTypeCheckSelector); | 2458 } else if (node.isReceiverTypeCheck) { |
| 2459 js.Expression call = jsPropertyCall(pop(), methodName, []); | 2459 use(node.checkedInput); |
| 2460 pushStatement(new js.Throw(call)); | 2460 String methodName = |
| 2461 } | 2461 backend.namer.invocationName(node.receiverTypeCheckSelector); |
| 2462 currentContainer = oldContainer; | 2462 js.Expression call = jsPropertyCall(pop(), methodName, []); |
| 2463 body = unwrapStatement(body); | 2463 pushStatement(new js.Throw(call)); |
| 2464 pushStatement(new js.If.noElse(test, body), node); | |
| 2465 return; | |
| 2466 } | 2464 } |
| 2465 currentContainer = oldContainer; |
| 2466 body = unwrapStatement(body); |
| 2467 pushStatement(new js.If.noElse(test, body), node); |
| 2468 return; |
| 2469 } |
| 2467 | 2470 |
| 2468 assert(node.isCheckedModeCheck || node.isCastTypeCheck); | 2471 assert(node.isCheckedModeCheck || node.isCastTypeCheck); |
| 2469 DartType type = node.typeExpression; | 2472 DartType type = node.typeExpression; |
| 2470 if (type.kind == TypeKind.FUNCTION) { | 2473 if (type.kind == TypeKind.FUNCTION) { |
| 2471 // TODO(5022): We currently generate $isFunction checks for | 2474 // TODO(5022): We currently generate $isFunction checks for |
| 2472 // function types. | 2475 // function types. |
| 2473 world.registerIsCheck( | 2476 world.registerIsCheck( |
| 2474 compiler.functionClass.computeType(compiler), work.resolutionTree); | 2477 compiler.functionClass.computeType(compiler), work.resolutionTree); |
| 2475 } | 2478 } |
| 2476 world.registerIsCheck(type, work.resolutionTree); | 2479 world.registerIsCheck(type, work.resolutionTree); |
| 2477 | 2480 |
| 2478 // TODO(kasperl): For now, we ignore type checks against type | 2481 FunctionElement helperElement; |
| 2479 // variables. This is clearly wrong. | 2482 if (node.isBooleanConversionCheck) { |
| 2480 if (type.kind == TypeKind.TYPE_VARIABLE) { | 2483 helperElement = |
| 2481 use(node.checkedInput); | 2484 compiler.findHelper(const SourceString('boolConversionCheck')); |
| 2482 return; | 2485 } else { |
| 2483 } | 2486 helperElement = backend.getCheckedModeHelper(type, |
| 2484 | 2487 typeCast: node.isCastTypeCheck); |
| 2485 FunctionElement helperElement; | 2488 } |
| 2486 if (node.isBooleanConversionCheck) { | 2489 world.registerStaticUse(helperElement); |
| 2487 helperElement = | 2490 List<js.Expression> arguments = <js.Expression>[]; |
| 2488 compiler.findHelper(const SourceString('boolConversionCheck')); | 2491 use(node.checkedInput); |
| 2489 } else { | 2492 arguments.add(pop()); |
| 2490 helperElement = backend.getCheckedModeHelper(type, | 2493 int parameterCount = |
| 2491 typeCast: node.isCastTypeCheck); | 2494 helperElement.computeSignature(compiler).parameterCount; |
| 2492 } | 2495 // TODO(johnniwinther): Refactor this to avoid using the parameter count |
| 2493 world.registerStaticUse(helperElement); | 2496 // to determine how the helper should be called. |
| 2494 List<js.Expression> arguments = <js.Expression>[]; | 2497 if (node.typeExpression.kind == TypeKind.TYPE_VARIABLE) { |
| 2495 use(node.checkedInput); | 2498 assert(parameterCount == 2); |
| 2499 use(node.typeRepresentation); |
| 2496 arguments.add(pop()); | 2500 arguments.add(pop()); |
| 2497 int parameterCount = | 2501 } else if (parameterCount == 2) { |
| 2498 helperElement.computeSignature(compiler).parameterCount; | 2502 // 2 arguments implies that the method is either [propertyTypeCheck], |
| 2499 // TODO(johnniwinther): Refactor this to avoid using the parameter count | 2503 // [propertyTypeCast] or [assertObjectIsSubtype]. |
| 2500 // to determine how the helper should be called. | 2504 assert(!type.isMalformed); |
| 2501 if (parameterCount == 2) { | 2505 String additionalArgument = backend.namer.operatorIs(type.element); |
| 2502 // 2 arguments implies that the method is either [propertyTypeCheck] | 2506 arguments.add(js.string(additionalArgument)); |
| 2503 // or [propertyTypeCast]. | 2507 } else if (parameterCount == 3) { |
| 2504 assert(!type.isMalformed); | 2508 // 3 arguments implies that the method is [malformedTypeCheck]. |
| 2505 String additionalArgument = backend.namer.operatorIs(type.element); | 2509 assert(type.isMalformed); |
| 2506 arguments.add(js.string(additionalArgument)); | 2510 String reasons = Types.fetchReasonsFromMalformedType(type); |
| 2507 } else if (parameterCount == 3) { | 2511 arguments.add(js.string('$type')); |
| 2508 // 3 arguments implies that the method is [malformedTypeCheck]. | 2512 // TODO(johnniwinther): Handle escaping correctly. |
| 2509 assert(type.isMalformed); | 2513 arguments.add(js.string(reasons)); |
| 2510 String reasons = Types.fetchReasonsFromMalformedType(type); | 2514 } else if (parameterCount == 4) { |
| 2511 arguments.add(js.string('$type')); | 2515 Element element = type.element; |
| 2512 // TODO(johnniwinther): Handle escaping correctly. | 2516 String isField = backend.namer.operatorIs(element); |
| 2513 arguments.add(js.string(reasons)); | 2517 arguments.add(js.string(isField)); |
| 2514 } else { | 2518 use(node.typeRepresentation); |
| 2515 assert(!type.isMalformed); | 2519 arguments.add(pop()); |
| 2516 } | 2520 String asField = backend.namer.substitutionName(element); |
| 2517 String helperName = backend.namer.isolateAccess(helperElement); | 2521 arguments.add(js.string(asField)); |
| 2518 push(new js.Call(new js.VariableUse(helperName), arguments)); | |
| 2519 } else { | 2522 } else { |
| 2520 use(node.checkedInput); | 2523 assert(!type.isMalformed); |
| 2524 // No additional arguments needed. |
| 2521 } | 2525 } |
| 2526 String helperName = backend.namer.isolateAccess(helperElement); |
| 2527 push(new js.Call(new js.VariableUse(helperName), arguments)); |
| 2522 } | 2528 } |
| 2523 } | 2529 } |
| 2524 | 2530 |
| 2525 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { | 2531 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { |
| 2526 SsaOptimizedCodeGenerator(backend, work) : super(backend, work); | 2532 SsaOptimizedCodeGenerator(backend, work) : super(backend, work); |
| 2527 | 2533 |
| 2528 HBasicBlock beginGraph(HGraph graph) { | 2534 HBasicBlock beginGraph(HGraph graph) { |
| 2529 return graph.entry; | 2535 return graph.entry; |
| 2530 } | 2536 } |
| 2531 | 2537 |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2959 if (leftType.canBeNull() && rightType.canBeNull()) { | 2965 if (leftType.canBeNull() && rightType.canBeNull()) { |
| 2960 if (left.isConstantNull() || right.isConstantNull() || | 2966 if (left.isConstantNull() || right.isConstantNull() || |
| 2961 (leftType.isPrimitive() && leftType == rightType)) { | 2967 (leftType.isPrimitive() && leftType == rightType)) { |
| 2962 return '=='; | 2968 return '=='; |
| 2963 } | 2969 } |
| 2964 return null; | 2970 return null; |
| 2965 } else { | 2971 } else { |
| 2966 return '==='; | 2972 return '==='; |
| 2967 } | 2973 } |
| 2968 } | 2974 } |
| OLD | NEW |