| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 | 6 |
| 7 import '../closure.dart'; | 7 import '../closure.dart'; |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../common/codegen.dart' show CodegenRegistry; | 9 import '../common/codegen.dart' show CodegenRegistry; |
| 10 import '../common/names.dart'; | 10 import '../common/names.dart'; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 HInstruction.idCounter = 0; | 132 HInstruction.idCounter = 0; |
| 133 MemberDefinition definition = | 133 MemberDefinition definition = |
| 134 _elementMap.getMemberDefinition(targetElement); | 134 _elementMap.getMemberDefinition(targetElement); |
| 135 | 135 |
| 136 switch (definition.kind) { | 136 switch (definition.kind) { |
| 137 case MemberKind.regular: | 137 case MemberKind.regular: |
| 138 case MemberKind.closureCall: | 138 case MemberKind.closureCall: |
| 139 ir.Node target = definition.node; | 139 ir.Node target = definition.node; |
| 140 if (target is ir.Procedure) { | 140 if (target is ir.Procedure) { |
| 141 _targetFunction = target.function; | 141 _targetFunction = target.function; |
| 142 buildFunctionNode(_targetFunction); | 142 if (target.isExternal) { |
| 143 buildExternalFunctionNode(_targetFunction); |
| 144 } else { |
| 145 buildFunctionNode(_targetFunction); |
| 146 } |
| 143 } else if (target is ir.Field) { | 147 } else if (target is ir.Field) { |
| 144 if (handleConstantField(targetElement, registry, closedWorld)) { | 148 if (handleConstantField(targetElement, registry, closedWorld)) { |
| 145 // No code is generated for `targetElement`: All references inline | 149 // No code is generated for `targetElement`: All references inline |
| 146 // the constant value. | 150 // the constant value. |
| 147 return null; | 151 return null; |
| 148 } else if (targetElement.isStatic || targetElement.isTopLevel) { | 152 } else if (targetElement.isStatic || targetElement.isTopLevel) { |
| 149 backend.constants.registerLazyStatic(targetElement); | 153 backend.constants.registerLazyStatic(targetElement); |
| 150 } | 154 } |
| 151 buildField(target); | 155 buildField(target); |
| 152 } else if (target is ir.FunctionExpression) { | 156 } else if (target is ir.FunctionExpression) { |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 constructor.function.body.accept(this); | 676 constructor.function.body.accept(this); |
| 673 closeFunction(); | 677 closeFunction(); |
| 674 } | 678 } |
| 675 | 679 |
| 676 /// Builds a SSA graph for FunctionNodes, found in FunctionExpressions and | 680 /// Builds a SSA graph for FunctionNodes, found in FunctionExpressions and |
| 677 /// Procedures. | 681 /// Procedures. |
| 678 void buildFunctionNode(ir.FunctionNode functionNode) { | 682 void buildFunctionNode(ir.FunctionNode functionNode) { |
| 679 openFunction(functionNode); | 683 openFunction(functionNode); |
| 680 ir.TreeNode parent = functionNode.parent; | 684 ir.TreeNode parent = functionNode.parent; |
| 681 if (parent is ir.Procedure && parent.kind == ir.ProcedureKind.Factory) { | 685 if (parent is ir.Procedure && parent.kind == ir.ProcedureKind.Factory) { |
| 682 _addClassTypeVariablesIfNeeded(functionNode.parent); | 686 _addClassTypeVariablesIfNeeded(parent); |
| 683 } | 687 } |
| 684 | 688 |
| 685 // If [functionNode] is `operator==` we explicitly add a null check at the | 689 // If [functionNode] is `operator==` we explicitly add a null check at the |
| 686 // beginning of the method. This is to avoid having call sites do the null | 690 // beginning of the method. This is to avoid having call sites do the null |
| 687 // check. | 691 // check. |
| 688 if (parent is ir.Procedure && | 692 if (parent is ir.Procedure && |
| 689 parent.kind == ir.ProcedureKind.Operator && | 693 parent.kind == ir.ProcedureKind.Operator && |
| 690 parent.name.name == '==') { | 694 parent.name.name == '==') { |
| 691 FunctionEntity method = _elementMap.getMethod(parent); | 695 FunctionEntity method = _elementMap.getMethod(parent); |
| 692 if (!_commonElements.operatorEqHandlesNullArgument(method)) { | 696 if (!_commonElements.operatorEqHandlesNullArgument(method)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 706 visitElse: null, | 710 visitElse: null, |
| 707 // TODO(27394): Add sourceInformation via | 711 // TODO(27394): Add sourceInformation via |
| 708 // `sourceInformationBuilder.buildIf(?)`. | 712 // `sourceInformationBuilder.buildIf(?)`. |
| 709 ); | 713 ); |
| 710 } | 714 } |
| 711 } | 715 } |
| 712 functionNode.body.accept(this); | 716 functionNode.body.accept(this); |
| 713 closeFunction(); | 717 closeFunction(); |
| 714 } | 718 } |
| 715 | 719 |
| 720 /// Builds a SSA graph for FunctionNodes of external methods. |
| 721 void buildExternalFunctionNode(ir.FunctionNode functionNode) { |
| 722 openFunction(functionNode); |
| 723 ir.TreeNode parent = functionNode.parent; |
| 724 if (parent is ir.Procedure && parent.kind == ir.ProcedureKind.Factory) { |
| 725 _addClassTypeVariablesIfNeeded(parent); |
| 726 } |
| 727 // TODO(sra): Generate conversion of Function typed arguments to JavaScript |
| 728 // functions. |
| 729 // TODO(sra): Invoke native method. |
| 730 assert(functionNode.body == null); |
| 731 closeFunction(); |
| 732 } |
| 733 |
| 716 void addImplicitInstantiation(DartType type) { | 734 void addImplicitInstantiation(DartType type) { |
| 717 if (type != null) { | 735 if (type != null) { |
| 718 currentImplicitInstantiations.add(type); | 736 currentImplicitInstantiations.add(type); |
| 719 } | 737 } |
| 720 } | 738 } |
| 721 | 739 |
| 722 void removeImplicitInstantiation(DartType type) { | 740 void removeImplicitInstantiation(DartType type) { |
| 723 if (type != null) { | 741 if (type != null) { |
| 724 currentImplicitInstantiations.removeLast(); | 742 currentImplicitInstantiations.removeLast(); |
| 725 } | 743 } |
| (...skipping 2940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3666 enterBlock.setBlockFlow( | 3684 enterBlock.setBlockFlow( |
| 3667 new HTryBlockInformation( | 3685 new HTryBlockInformation( |
| 3668 kernelBuilder.wrapStatementGraph(bodyGraph), | 3686 kernelBuilder.wrapStatementGraph(bodyGraph), |
| 3669 exception, | 3687 exception, |
| 3670 kernelBuilder.wrapStatementGraph(catchGraph), | 3688 kernelBuilder.wrapStatementGraph(catchGraph), |
| 3671 kernelBuilder.wrapStatementGraph(finallyGraph)), | 3689 kernelBuilder.wrapStatementGraph(finallyGraph)), |
| 3672 exitBlock); | 3690 exitBlock); |
| 3673 kernelBuilder.inTryStatement = previouslyInTryStatement; | 3691 kernelBuilder.inTryStatement = previouslyInTryStatement; |
| 3674 } | 3692 } |
| 3675 } | 3693 } |
| OLD | NEW |