| 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 2447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2458 js.Binary notObjectOrIndexingTest = | 2458 js.Binary notObjectOrIndexingTest = |
| 2459 new js.Binary('||', objectTest, notIndexingTest); | 2459 new js.Binary('||', objectTest, notIndexingTest); |
| 2460 test = new js.Binary('&&', stringTest, notObjectOrIndexingTest); | 2460 test = new js.Binary('&&', stringTest, notObjectOrIndexingTest); |
| 2461 } else { | 2461 } else { |
| 2462 compiler.internalError('Unexpected type guard', instruction: input); | 2462 compiler.internalError('Unexpected type guard', instruction: input); |
| 2463 } | 2463 } |
| 2464 return test; | 2464 return test; |
| 2465 } | 2465 } |
| 2466 | 2466 |
| 2467 void visitTypeConversion(HTypeConversion node) { | 2467 void visitTypeConversion(HTypeConversion node) { |
| 2468 if (node.isChecked) { | 2468 if (!node.isChecked) { |
| 2469 if (node.isArgumentTypeCheck || node.isReceiverTypeCheck) { | 2469 use(node.checkedInput); |
| 2470 js.Expression test = generateTest(node); | 2470 return; |
| 2471 js.Block oldContainer = currentContainer; | 2471 } |
| 2472 js.Statement body = new js.Block.empty(); | 2472 if (node.isArgumentTypeCheck || node.isReceiverTypeCheck) { |
| 2473 currentContainer = body; | 2473 js.Expression test = generateTest(node); |
| 2474 if (node.isArgumentTypeCheck) { | 2474 js.Block oldContainer = currentContainer; |
| 2475 generateThrowWithHelper('iae', node.checkedInput); | 2475 js.Statement body = new js.Block.empty(); |
| 2476 } else if (node.isReceiverTypeCheck) { | 2476 currentContainer = body; |
| 2477 use(node.checkedInput); | 2477 if (node.isArgumentTypeCheck) { |
| 2478 String methodName = | 2478 generateThrowWithHelper('iae', node.checkedInput); |
| 2479 backend.namer.invocationName(node.receiverTypeCheckSelector); | 2479 } else if (node.isReceiverTypeCheck) { |
| 2480 js.Expression call = jsPropertyCall(pop(), methodName, []); | 2480 use(node.checkedInput); |
| 2481 pushStatement(new js.Throw(call)); | 2481 String methodName = |
| 2482 } | 2482 backend.namer.invocationName(node.receiverTypeCheckSelector); |
| 2483 currentContainer = oldContainer; | 2483 js.Expression call = jsPropertyCall(pop(), methodName, []); |
| 2484 body = unwrapStatement(body); | 2484 pushStatement(new js.Throw(call)); |
| 2485 pushStatement(new js.If.noElse(test, body), node); | |
| 2486 return; | |
| 2487 } | 2485 } |
| 2486 currentContainer = oldContainer; |
| 2487 body = unwrapStatement(body); |
| 2488 pushStatement(new js.If.noElse(test, body), node); |
| 2489 return; |
| 2490 } |
| 2488 | 2491 |
| 2489 assert(node.isCheckedModeCheck || node.isCastTypeCheck); | 2492 assert(node.isCheckedModeCheck || node.isCastTypeCheck); |
| 2490 DartType type = node.typeExpression; | 2493 DartType type = node.typeExpression; |
| 2491 world.registerIsCheck(type, work.resolutionTree); | 2494 world.registerIsCheck(type, work.resolutionTree); |
| 2492 | 2495 |
| 2493 // TODO(kasperl): For now, we ignore type checks against type | 2496 FunctionElement helperElement; |
| 2494 // variables. This is clearly wrong. | 2497 if (node.isBooleanConversionCheck) { |
| 2495 if (type.kind == TypeKind.TYPE_VARIABLE) { | 2498 helperElement = |
| 2496 use(node.checkedInput); | 2499 compiler.findHelper(const SourceString('boolConversionCheck')); |
| 2497 return; | 2500 } else { |
| 2498 } | 2501 helperElement = backend.getCheckedModeHelper(type, |
| 2499 | 2502 typeCast: node.isCastTypeCheck); |
| 2500 FunctionElement helperElement; | 2503 } |
| 2501 if (node.isBooleanConversionCheck) { | 2504 world.registerStaticUse(helperElement); |
| 2502 helperElement = | 2505 List<js.Expression> arguments = <js.Expression>[]; |
| 2503 compiler.findHelper(const SourceString('boolConversionCheck')); | 2506 use(node.checkedInput); |
| 2504 } else { | 2507 arguments.add(pop()); |
| 2505 helperElement = backend.getCheckedModeHelper(type, | 2508 int parameterCount = |
| 2506 typeCast: node.isCastTypeCheck); | 2509 helperElement.computeSignature(compiler).parameterCount; |
| 2507 } | 2510 // TODO(johnniwinther): Refactor this to avoid using the parameter count |
| 2508 world.registerStaticUse(helperElement); | 2511 // to determine how the helper should be called. |
| 2509 List<js.Expression> arguments = <js.Expression>[]; | 2512 if (node.typeExpression.kind == TypeKind.TYPE_VARIABLE) { |
| 2510 use(node.checkedInput); | 2513 assert(parameterCount == 2); |
| 2514 use(node.typeRepresentation); |
| 2511 arguments.add(pop()); | 2515 arguments.add(pop()); |
| 2512 int parameterCount = | 2516 } else if (parameterCount == 2) { |
| 2513 helperElement.computeSignature(compiler).parameterCount; | 2517 // 2 arguments implies that the method is either [propertyTypeCheck], |
| 2514 // TODO(johnniwinther): Refactor this to avoid using the parameter count | 2518 // [propertyTypeCast] or [assertObjectIsSubtype]. |
| 2515 // to determine how the helper should be called. | 2519 assert(!type.isMalformed); |
| 2516 if (parameterCount == 2) { | 2520 String additionalArgument = backend.namer.operatorIs(type.element); |
| 2517 // 2 arguments implies that the method is either [propertyTypeCheck] | 2521 arguments.add(js.string(additionalArgument)); |
| 2518 // or [propertyTypeCast]. | 2522 } else if (parameterCount == 3) { |
| 2519 assert(!type.isMalformed); | 2523 // 3 arguments implies that the method is [malformedTypeCheck]. |
| 2520 String additionalArgument = backend.namer.operatorIs(type.element); | 2524 assert(type.isMalformed); |
| 2521 arguments.add(js.string(additionalArgument)); | 2525 String reasons = Types.fetchReasonsFromMalformedType(type); |
| 2522 } else if (parameterCount == 3) { | 2526 arguments.add(js.string('$type')); |
| 2523 // 3 arguments implies that the method is [malformedTypeCheck]. | 2527 // TODO(johnniwinther): Handle escaping correctly. |
| 2524 assert(type.isMalformed); | 2528 arguments.add(js.string(reasons)); |
| 2525 String reasons = Types.fetchReasonsFromMalformedType(type); | 2529 } else if (parameterCount == 4) { |
| 2526 arguments.add(js.string('$type')); | 2530 Element element = type.element; |
| 2527 // TODO(johnniwinther): Handle escaping correctly. | 2531 String isField = backend.namer.operatorIs(element); |
| 2528 arguments.add(js.string(reasons)); | 2532 arguments.add(js.string(isField)); |
| 2529 } else { | 2533 use(node.typeRepresentation); |
| 2530 assert(!type.isMalformed); | 2534 arguments.add(pop()); |
| 2531 } | 2535 String asField = backend.namer.substitutionName(element); |
| 2532 String helperName = backend.namer.isolateAccess(helperElement); | 2536 arguments.add(js.string(asField)); |
| 2533 push(new js.Call(new js.VariableUse(helperName), arguments)); | |
| 2534 } else { | 2537 } else { |
| 2535 use(node.checkedInput); | 2538 assert(!type.isMalformed); |
| 2539 // No additional arguments needed. |
| 2536 } | 2540 } |
| 2541 String helperName = backend.namer.isolateAccess(helperElement); |
| 2542 push(new js.Call(new js.VariableUse(helperName), arguments)); |
| 2537 } | 2543 } |
| 2538 } | 2544 } |
| 2539 | 2545 |
| 2540 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { | 2546 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { |
| 2541 SsaOptimizedCodeGenerator(backend, work) : super(backend, work); | 2547 SsaOptimizedCodeGenerator(backend, work) : super(backend, work); |
| 2542 | 2548 |
| 2543 HBasicBlock beginGraph(HGraph graph) { | 2549 HBasicBlock beginGraph(HGraph graph) { |
| 2544 return graph.entry; | 2550 return graph.entry; |
| 2545 } | 2551 } |
| 2546 | 2552 |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2974 if (leftType.canBeNull() && rightType.canBeNull()) { | 2980 if (leftType.canBeNull() && rightType.canBeNull()) { |
| 2975 if (left.isConstantNull() || right.isConstantNull() || | 2981 if (left.isConstantNull() || right.isConstantNull() || |
| 2976 (leftType.isPrimitive() && leftType == rightType)) { | 2982 (leftType.isPrimitive() && leftType == rightType)) { |
| 2977 return '=='; | 2983 return '=='; |
| 2978 } | 2984 } |
| 2979 return null; | 2985 return null; |
| 2980 } else { | 2986 } else { |
| 2981 return '==='; | 2987 return '==='; |
| 2982 } | 2988 } |
| 2983 } | 2989 } |
| OLD | NEW |