| 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 /// | 242 /// |
| 243 /// 7. Walk inheritance chain to call or inline constructor bodies. | 243 /// 7. Walk inheritance chain to call or inline constructor bodies. |
| 244 /// | 244 /// |
| 245 /// All the bindings are put in the constructor's locals handler. The | 245 /// All the bindings are put in the constructor's locals handler. The |
| 246 /// implication is that a class cannot be extended or mixed-in twice. If we in | 246 /// implication is that a class cannot be extended or mixed-in twice. If we in |
| 247 /// future support repeated uses of a mixin class, we should do so by cloning | 247 /// future support repeated uses of a mixin class, we should do so by cloning |
| 248 /// the mixin class in the Kernel input. | 248 /// the mixin class in the Kernel input. |
| 249 void buildConstructor(ir.Constructor constructor) { | 249 void buildConstructor(ir.Constructor constructor) { |
| 250 ir.Class constructedClass = constructor.enclosingClass; | 250 ir.Class constructedClass = constructor.enclosingClass; |
| 251 | 251 |
| 252 openFunction(); | 252 openFunction(constructor.function); |
| 253 _addClassTypeVariablesIfNeeded(constructor); | 253 _addClassTypeVariablesIfNeeded(constructor); |
| 254 | 254 |
| 255 // TODO(sra): Type parameter constraint checks. | 255 // TODO(sra): Type parameter constraint checks. |
| 256 | 256 |
| 257 // TODO(sra): Checked mode parameter checks. | 257 // TODO(sra): Checked mode parameter checks. |
| 258 | 258 |
| 259 // Collect field values for the current class. | 259 // Collect field values for the current class. |
| 260 Map<FieldEntity, HInstruction> fieldValues = | 260 Map<FieldEntity, HInstruction> fieldValues = |
| 261 _collectFieldValues(constructedClass); | 261 _collectFieldValues(constructedClass); |
| 262 List<ir.Constructor> constructorChain = <ir.Constructor>[]; | 262 List<ir.Constructor> constructorChain = <ir.Constructor>[]; |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 ..forEach(handleParameter); | 596 ..forEach(handleParameter); |
| 597 | 597 |
| 598 // Set the locals handler state as if we were inlining the constructor. | 598 // Set the locals handler state as if we were inlining the constructor. |
| 599 ConstructorElement astElement = _elementMap.getConstructor(constructor); | 599 ConstructorElement astElement = _elementMap.getConstructor(constructor); |
| 600 ResolvedAst resolvedAst = astElement.resolvedAst; | 600 ResolvedAst resolvedAst = astElement.resolvedAst; |
| 601 ClosureClassMap oldClosureData = localsHandler.closureData; | 601 ClosureClassMap oldClosureData = localsHandler.closureData; |
| 602 ClosureClassMap newClosureData = | 602 ClosureClassMap newClosureData = |
| 603 closureToClassMapper.getMemberMap(astElement); | 603 closureToClassMapper.getMemberMap(astElement); |
| 604 localsHandler.closureData = newClosureData; | 604 localsHandler.closureData = newClosureData; |
| 605 if (resolvedAst.kind == ResolvedAstKind.PARSED) { | 605 if (resolvedAst.kind == ResolvedAstKind.PARSED) { |
| 606 localsHandler.enterScope(resolvedAst.node, | 606 localsHandler.enterScope(newClosureData.capturingScopes[resolvedAst.node], |
| 607 forGenerativeConstructorBody: astElement.isGenerativeConstructorBody); | 607 forGenerativeConstructorBody: astElement.isGenerativeConstructorBody); |
| 608 } | 608 } |
| 609 inlinedFrom(astElement, () { | 609 inlinedFrom(astElement, () { |
| 610 _buildInitializers(constructor, constructorChain, fieldValues); | 610 _buildInitializers(constructor, constructorChain, fieldValues); |
| 611 }); | 611 }); |
| 612 localsHandler.closureData = oldClosureData; | 612 localsHandler.closureData = oldClosureData; |
| 613 } | 613 } |
| 614 | 614 |
| 615 /// Builds generative constructor body. | 615 /// Builds generative constructor body. |
| 616 void buildConstructorBody(ir.Constructor constructor) { | 616 void buildConstructorBody(ir.Constructor constructor) { |
| 617 openFunction(); | 617 openFunction(constructor.function); |
| 618 _addClassTypeVariablesIfNeeded(constructor); | 618 _addClassTypeVariablesIfNeeded(constructor); |
| 619 constructor.function.body.accept(this); | 619 constructor.function.body.accept(this); |
| 620 closeFunction(); | 620 closeFunction(); |
| 621 } | 621 } |
| 622 | 622 |
| 623 /// Builds a SSA graph for FunctionNodes, found in FunctionExpressions and | 623 /// Builds a SSA graph for FunctionNodes, found in FunctionExpressions and |
| 624 /// Procedures. | 624 /// Procedures. |
| 625 void buildFunctionNode(ir.FunctionNode functionNode) { | 625 void buildFunctionNode(ir.FunctionNode functionNode) { |
| 626 openFunction(); | 626 openFunction(functionNode); |
| 627 ir.TreeNode parent = functionNode.parent; | 627 ir.TreeNode parent = functionNode.parent; |
| 628 if (parent is ir.Procedure && parent.kind == ir.ProcedureKind.Factory) { | 628 if (parent is ir.Procedure && parent.kind == ir.ProcedureKind.Factory) { |
| 629 _addClassTypeVariablesIfNeeded(functionNode.parent); | 629 _addClassTypeVariablesIfNeeded(functionNode.parent); |
| 630 } | 630 } |
| 631 | 631 |
| 632 // If [functionNode] is `operator==` we explicitly add a null check at the | 632 // If [functionNode] is `operator==` we explicitly add a null check at the |
| 633 // beginning of the method. This is to avoid having call sites do the null | 633 // beginning of the method. This is to avoid having call sites do the null |
| 634 // check. | 634 // check. |
| 635 if (parent is ir.Procedure && | 635 if (parent is ir.Procedure && |
| 636 parent.kind == ir.ProcedureKind.Operator && | 636 parent.kind == ir.ProcedureKind.Operator && |
| (...skipping 26 matching lines...) Expand all Loading... |
| 663 currentImplicitInstantiations.add(type); | 663 currentImplicitInstantiations.add(type); |
| 664 } | 664 } |
| 665 } | 665 } |
| 666 | 666 |
| 667 void removeImplicitInstantiation(DartType type) { | 667 void removeImplicitInstantiation(DartType type) { |
| 668 if (type != null) { | 668 if (type != null) { |
| 669 currentImplicitInstantiations.removeLast(); | 669 currentImplicitInstantiations.removeLast(); |
| 670 } | 670 } |
| 671 } | 671 } |
| 672 | 672 |
| 673 void openFunction() { | 673 void openFunction([ir.FunctionNode function]) { |
| 674 Map<Local, TypeMask> parameterMap = <Local, TypeMask>{}; |
| 675 if (function != null) { |
| 676 void handleParameter(ir.VariableDeclaration node) { |
| 677 Local local = _localsMap.getLocal(node); |
| 678 parameterMap[local] = |
| 679 _typeInferenceMap.getInferredTypeOfParameter(local); |
| 680 } |
| 681 |
| 682 function.positionalParameters.forEach(handleParameter); |
| 683 function.namedParameters.toList() |
| 684 ..sort(namedOrdering) |
| 685 ..forEach(handleParameter); |
| 686 } |
| 687 |
| 674 HBasicBlock block = graph.addNewBlock(); | 688 HBasicBlock block = graph.addNewBlock(); |
| 675 open(graph.entry); | 689 open(graph.entry); |
| 676 | 690 |
| 677 localsHandler.startFunction(targetElement, functionNode, | 691 ClosureClassMap closureData = |
| 692 closureToClassMapper.getMemberMap(targetElement); |
| 693 localsHandler.startFunction(targetElement, closureData, |
| 694 closureData.capturingScopes[functionNode], parameterMap, |
| 678 isGenerativeConstructorBody: _targetIsConstructorBody); | 695 isGenerativeConstructorBody: _targetIsConstructorBody); |
| 679 close(new HGoto()).addSuccessor(block); | 696 close(new HGoto()).addSuccessor(block); |
| 680 | 697 |
| 681 open(block); | 698 open(block); |
| 682 } | 699 } |
| 683 | 700 |
| 684 void closeFunction() { | 701 void closeFunction() { |
| 685 if (!isAborted()) closeAndGotoExit(new HGoto()); | 702 if (!isAborted()) closeAndGotoExit(new HGoto()); |
| 686 graph.finalize(); | 703 graph.finalize(); |
| 687 } | 704 } |
| (...skipping 2737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3425 enterBlock.setBlockFlow( | 3442 enterBlock.setBlockFlow( |
| 3426 new HTryBlockInformation( | 3443 new HTryBlockInformation( |
| 3427 kernelBuilder.wrapStatementGraph(bodyGraph), | 3444 kernelBuilder.wrapStatementGraph(bodyGraph), |
| 3428 exception, | 3445 exception, |
| 3429 kernelBuilder.wrapStatementGraph(catchGraph), | 3446 kernelBuilder.wrapStatementGraph(catchGraph), |
| 3430 kernelBuilder.wrapStatementGraph(finallyGraph)), | 3447 kernelBuilder.wrapStatementGraph(finallyGraph)), |
| 3431 exitBlock); | 3448 exitBlock); |
| 3432 kernelBuilder.inTryStatement = previouslyInTryStatement; | 3449 kernelBuilder.inTryStatement = previouslyInTryStatement; |
| 3433 } | 3450 } |
| 3434 } | 3451 } |
| OLD | NEW |