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 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 | 1712 |
1713 visitLocalSet(HLocalSet node) { | 1713 visitLocalSet(HLocalSet node) { |
1714 use(node.value); | 1714 use(node.value); |
1715 assignVariable(variableNames.getName(node.receiver), pop()); | 1715 assignVariable(variableNames.getName(node.receiver), pop()); |
1716 } | 1716 } |
1717 | 1717 |
1718 void registerForeignTypes(HForeign node) { | 1718 void registerForeignTypes(HForeign node) { |
1719 native.NativeBehavior nativeBehavior = node.nativeBehavior; | 1719 native.NativeBehavior nativeBehavior = node.nativeBehavior; |
1720 if (nativeBehavior == null) return; | 1720 if (nativeBehavior == null) return; |
1721 nativeBehavior.typesReturned.forEach((type) { | 1721 nativeBehavior.typesReturned.forEach((type) { |
1722 if (type is DartType) { | 1722 if (type is InterfaceType) { |
1723 registry.registerInstantiatedType(type); | 1723 registry.registerInstantiatedType(type); |
1724 } | 1724 } |
1725 }); | 1725 }); |
1726 } | 1726 } |
1727 | 1727 |
1728 visitForeign(HForeign node) { | 1728 visitForeign(HForeign node) { |
1729 List<HInstruction> inputs = node.inputs; | 1729 List<HInstruction> inputs = node.inputs; |
1730 if (node.isJsStatement()) { | 1730 if (node.isJsStatement()) { |
1731 List<js.Expression> interpolatedExpressions = <js.Expression>[]; | 1731 List<js.Expression> interpolatedExpressions = <js.Expression>[]; |
1732 for (int i = 0; i < inputs.length; i++) { | 1732 for (int i = 0; i < inputs.length; i++) { |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2403 attachLocationToLast(node); | 2403 attachLocationToLast(node); |
2404 } else if (Elements.isStringOnlySupertype(element, compiler)) { | 2404 } else if (Elements.isStringOnlySupertype(element, compiler)) { |
2405 handleStringSupertypeCheck( | 2405 handleStringSupertypeCheck( |
2406 input, interceptor, type, negative: negative); | 2406 input, interceptor, type, negative: negative); |
2407 attachLocationToLast(node); | 2407 attachLocationToLast(node); |
2408 } else if (identical(element, compiler.listClass) | 2408 } else if (identical(element, compiler.listClass) |
2409 || Elements.isListSupertype(element, compiler)) { | 2409 || Elements.isListSupertype(element, compiler)) { |
2410 handleListOrSupertypeCheck( | 2410 handleListOrSupertypeCheck( |
2411 input, interceptor, type, negative: negative); | 2411 input, interceptor, type, negative: negative); |
2412 attachLocationToLast(node); | 2412 attachLocationToLast(node); |
2413 } else if (type.kind == TypeKind.FUNCTION) { | 2413 } else if (type.isFunctionType) { |
2414 checkType(input, interceptor, type, negative: negative); | 2414 checkType(input, interceptor, type, negative: negative); |
2415 attachLocationToLast(node); | 2415 attachLocationToLast(node); |
2416 } else if ((input.canBePrimitive(compiler) | 2416 } else if ((input.canBePrimitive(compiler) |
2417 && !input.canBePrimitiveArray(compiler)) | 2417 && !input.canBePrimitiveArray(compiler)) |
2418 || input.canBeNull()) { | 2418 || input.canBeNull()) { |
2419 checkObject(input, relation); | 2419 checkObject(input, relation); |
2420 js.Expression objectTest = pop(); | 2420 js.Expression objectTest = pop(); |
2421 checkType(input, interceptor, type, negative: negative); | 2421 checkType(input, interceptor, type, negative: negative); |
2422 push(new js.Binary(negative ? '||' : '&&', objectTest, pop()), node); | 2422 push(new js.Binary(negative ? '||' : '&&', objectTest, pop()), node); |
2423 } else { | 2423 } else { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2545 } | 2545 } |
2546 currentContainer = oldContainer; | 2546 currentContainer = oldContainer; |
2547 body = unwrapStatement(body); | 2547 body = unwrapStatement(body); |
2548 pushStatement(new js.If.noElse(test, body), node); | 2548 pushStatement(new js.If.noElse(test, body), node); |
2549 return; | 2549 return; |
2550 } | 2550 } |
2551 | 2551 |
2552 assert(node.isCheckedModeCheck || node.isCastTypeCheck); | 2552 assert(node.isCheckedModeCheck || node.isCastTypeCheck); |
2553 DartType type = node.typeExpression; | 2553 DartType type = node.typeExpression; |
2554 assert(type.kind != TypeKind.TYPEDEF); | 2554 assert(type.kind != TypeKind.TYPEDEF); |
2555 if (type.kind == TypeKind.FUNCTION) { | 2555 if (type.isFunctionType) { |
2556 // TODO(5022): We currently generate $isFunction checks for | 2556 // TODO(5022): We currently generate $isFunction checks for |
2557 // function types. | 2557 // function types. |
2558 registry.registerIsCheck(compiler.functionClass.rawType); | 2558 registry.registerIsCheck(compiler.functionClass.rawType); |
2559 } | 2559 } |
2560 registry.registerIsCheck(type); | 2560 registry.registerIsCheck(type); |
2561 | 2561 |
2562 CheckedModeHelper helper; | 2562 CheckedModeHelper helper; |
2563 if (node.isBooleanConversionCheck) { | 2563 if (node.isBooleanConversionCheck) { |
2564 helper = | 2564 helper = |
2565 const CheckedModeHelper('boolConversionCheck'); | 2565 const CheckedModeHelper('boolConversionCheck'); |
2566 } else { | 2566 } else { |
2567 helper = | 2567 helper = |
2568 backend.getCheckedModeHelper(type, typeCast: node.isCastTypeCheck); | 2568 backend.getCheckedModeHelper(type, typeCast: node.isCastTypeCheck); |
2569 } | 2569 } |
2570 | 2570 |
2571 if (helper == null) { | 2571 if (helper == null) { |
2572 assert(type.kind == TypeKind.FUNCTION); | 2572 assert(type.isFunctionType); |
2573 use(node.inputs[0]); | 2573 use(node.inputs[0]); |
2574 } else { | 2574 } else { |
2575 push(helper.generateCall(this, node)); | 2575 push(helper.generateCall(this, node)); |
2576 } | 2576 } |
2577 } | 2577 } |
2578 | 2578 |
2579 void visitTypeKnown(HTypeKnown node) { | 2579 void visitTypeKnown(HTypeKnown node) { |
2580 // [HTypeKnown] instructions are removed before generating code. | 2580 // [HTypeKnown] instructions are removed before generating code. |
2581 assert(false); | 2581 assert(false); |
2582 } | 2582 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2677 js.PropertyAccess accessHelper(String name) { | 2677 js.PropertyAccess accessHelper(String name) { |
2678 Element helper = compiler.findHelper(name); | 2678 Element helper = compiler.findHelper(name); |
2679 if (helper == null) { | 2679 if (helper == null) { |
2680 // For mocked-up tests. | 2680 // For mocked-up tests. |
2681 return js.js('(void 0).$name'); | 2681 return js.js('(void 0).$name'); |
2682 } | 2682 } |
2683 registry.registerStaticUse(helper); | 2683 registry.registerStaticUse(helper); |
2684 return backend.namer.elementAccess(helper); | 2684 return backend.namer.elementAccess(helper); |
2685 } | 2685 } |
2686 } | 2686 } |
OLD | NEW |