| 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 final SourceInformationStrategy sourceInformationFactory; | 10 final SourceInformationStrategy sourceInformationFactory; |
| (...skipping 2484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2495 checkTypeViaProperty(interceptor, type, sourceInformation, | 2495 checkTypeViaProperty(interceptor, type, sourceInformation, |
| 2496 negative: negative); | 2496 negative: negative); |
| 2497 } else { | 2497 } else { |
| 2498 checkTypeViaProperty(input, type, sourceInformation, negative: negative); | 2498 checkTypeViaProperty(input, type, sourceInformation, negative: negative); |
| 2499 } | 2499 } |
| 2500 } | 2500 } |
| 2501 | 2501 |
| 2502 void checkTypeViaProperty(HInstruction input, DartType type, | 2502 void checkTypeViaProperty(HInstruction input, DartType type, |
| 2503 SourceInformation sourceInformation, | 2503 SourceInformation sourceInformation, |
| 2504 {bool negative: false}) { | 2504 {bool negative: false}) { |
| 2505 registry.registerIsCheck(type); | 2505 registry.registerTypeUse(new TypeUse.isCheck(type)); |
| 2506 | 2506 |
| 2507 use(input); | 2507 use(input); |
| 2508 | 2508 |
| 2509 js.PropertyAccess field = | 2509 js.PropertyAccess field = |
| 2510 new js.PropertyAccess(pop(), backend.namer.operatorIsType(type)) | 2510 new js.PropertyAccess(pop(), backend.namer.operatorIsType(type)) |
| 2511 .withSourceInformation(sourceInformation); | 2511 .withSourceInformation(sourceInformation); |
| 2512 // We always negate at least once so that the result is boolified. | 2512 // We always negate at least once so that the result is boolified. |
| 2513 push(new js.Prefix('!', field) | 2513 push(new js.Prefix('!', field) |
| 2514 .withSourceInformation(sourceInformation)); | 2514 .withSourceInformation(sourceInformation)); |
| 2515 // If the result is not negated, put another '!' in front. | 2515 // If the result is not negated, put another '!' in front. |
| 2516 if (!negative) { | 2516 if (!negative) { |
| 2517 push(new js.Prefix('!', pop()) | 2517 push(new js.Prefix('!', pop()) |
| 2518 .withSourceInformation(sourceInformation)); | 2518 .withSourceInformation(sourceInformation)); |
| 2519 } | 2519 } |
| 2520 } | 2520 } |
| 2521 | 2521 |
| 2522 void checkTypeViaInstanceof( | 2522 void checkTypeViaInstanceof( |
| 2523 HInstruction input, DartType type, | 2523 HInstruction input, DartType type, |
| 2524 SourceInformation sourceInformation, | 2524 SourceInformation sourceInformation, |
| 2525 {bool negative: false}) { | 2525 {bool negative: false}) { |
| 2526 registry.registerIsCheck(type); | 2526 registry.registerTypeUse(new TypeUse.isCheck(type)); |
| 2527 | 2527 |
| 2528 use(input); | 2528 use(input); |
| 2529 | 2529 |
| 2530 js.Expression jsClassReference = | 2530 js.Expression jsClassReference = |
| 2531 backend.emitter.constructorAccess(type.element); | 2531 backend.emitter.constructorAccess(type.element); |
| 2532 push(js.js('# instanceof #', [pop(), jsClassReference]) | 2532 push(js.js('# instanceof #', [pop(), jsClassReference]) |
| 2533 .withSourceInformation(sourceInformation)); | 2533 .withSourceInformation(sourceInformation)); |
| 2534 if (negative) { | 2534 if (negative) { |
| 2535 push(new js.Prefix('!', pop()) | 2535 push(new js.Prefix('!', pop()) |
| 2536 .withSourceInformation(sourceInformation)); | 2536 .withSourceInformation(sourceInformation)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2608 void visitIs(HIs node) { | 2608 void visitIs(HIs node) { |
| 2609 emitIs(node, "===", node.sourceInformation); | 2609 emitIs(node, "===", node.sourceInformation); |
| 2610 } | 2610 } |
| 2611 | 2611 |
| 2612 void visitIsViaInterceptor(HIsViaInterceptor node) { | 2612 void visitIsViaInterceptor(HIsViaInterceptor node) { |
| 2613 emitIsViaInterceptor(node, node.sourceInformation, negative: false); | 2613 emitIsViaInterceptor(node, node.sourceInformation, negative: false); |
| 2614 } | 2614 } |
| 2615 | 2615 |
| 2616 void emitIs(HIs node, String relation, SourceInformation sourceInformation) { | 2616 void emitIs(HIs node, String relation, SourceInformation sourceInformation) { |
| 2617 DartType type = node.typeExpression; | 2617 DartType type = node.typeExpression; |
| 2618 registry.registerIsCheck(type); | 2618 registry.registerTypeUse(new TypeUse.isCheck(type)); |
| 2619 HInstruction input = node.expression; | 2619 HInstruction input = node.expression; |
| 2620 | 2620 |
| 2621 // If this is changed to single == there are several places below that must | 2621 // If this is changed to single == there are several places below that must |
| 2622 // be changed to match. | 2622 // be changed to match. |
| 2623 assert(relation == '===' || relation == '!=='); | 2623 assert(relation == '===' || relation == '!=='); |
| 2624 bool negative = relation == '!=='; | 2624 bool negative = relation == '!=='; |
| 2625 | 2625 |
| 2626 if (node.isVariableCheck || node.isCompoundCheck) { | 2626 if (node.isVariableCheck || node.isCompoundCheck) { |
| 2627 use(node.checkCall); | 2627 use(node.checkCall); |
| 2628 if (negative) push(new js.Prefix('!', pop())); | 2628 if (negative) push(new js.Prefix('!', pop())); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2780 .withSourceInformation(node.sourceInformation)); | 2780 .withSourceInformation(node.sourceInformation)); |
| 2781 return; | 2781 return; |
| 2782 } | 2782 } |
| 2783 | 2783 |
| 2784 assert(node.isCheckedModeCheck || node.isCastTypeCheck); | 2784 assert(node.isCheckedModeCheck || node.isCastTypeCheck); |
| 2785 DartType type = node.typeExpression; | 2785 DartType type = node.typeExpression; |
| 2786 assert(type.kind != TypeKind.TYPEDEF); | 2786 assert(type.kind != TypeKind.TYPEDEF); |
| 2787 if (type.isFunctionType) { | 2787 if (type.isFunctionType) { |
| 2788 // TODO(5022): We currently generate $isFunction checks for | 2788 // TODO(5022): We currently generate $isFunction checks for |
| 2789 // function types. | 2789 // function types. |
| 2790 registry.registerIsCheck(compiler.coreTypes.functionType); | 2790 registry.registerTypeUse( |
| 2791 new TypeUse.isCheck(compiler.coreTypes.functionType)); |
| 2791 } | 2792 } |
| 2792 registry.registerIsCheck(type); | 2793 registry.registerTypeUse(new TypeUse.isCheck(type)); |
| 2793 | 2794 |
| 2794 CheckedModeHelper helper; | 2795 CheckedModeHelper helper; |
| 2795 if (node.isBooleanConversionCheck) { | 2796 if (node.isBooleanConversionCheck) { |
| 2796 helper = | 2797 helper = |
| 2797 const CheckedModeHelper('boolConversionCheck'); | 2798 const CheckedModeHelper('boolConversionCheck'); |
| 2798 } else { | 2799 } else { |
| 2799 helper = | 2800 helper = |
| 2800 backend.getCheckedModeHelper(type, typeCast: node.isCastTypeCheck); | 2801 backend.getCheckedModeHelper(type, typeCast: node.isCastTypeCheck); |
| 2801 } | 2802 } |
| 2802 | 2803 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2918 new StaticUse.staticInvoke(helper, | 2919 new StaticUse.staticInvoke(helper, |
| 2919 new CallStructure.unnamed(argumentCount))); | 2920 new CallStructure.unnamed(argumentCount))); |
| 2920 return backend.emitter.staticFunctionAccess(helper); | 2921 return backend.emitter.staticFunctionAccess(helper); |
| 2921 } | 2922 } |
| 2922 | 2923 |
| 2923 @override | 2924 @override |
| 2924 void visitRef(HRef node) { | 2925 void visitRef(HRef node) { |
| 2925 visit(node.value); | 2926 visit(node.value); |
| 2926 } | 2927 } |
| 2927 } | 2928 } |
| OLD | NEW |