Chromium Code Reviews| 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, CodegenWorkItem; | 9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
| 10 import '../common/names.dart'; | 10 import '../common/names.dart'; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 if (target is ir.Procedure) { | 134 if (target is ir.Procedure) { |
| 135 target = (target as ir.Procedure).function; | 135 target = (target as ir.Procedure).function; |
| 136 buildFunctionNode(target); | 136 buildFunctionNode(target); |
| 137 } else if (target is ir.Field) { | 137 } else if (target is ir.Field) { |
| 138 buildField(target); | 138 buildField(target); |
| 139 } else if (target is ir.Constructor) { | 139 } else if (target is ir.Constructor) { |
| 140 buildConstructor(target); | 140 buildConstructor(target); |
| 141 } else if (target is ir.FunctionExpression) { | 141 } else if (target is ir.FunctionExpression) { |
| 142 target = (target as ir.FunctionExpression).function; | 142 target = (target as ir.FunctionExpression).function; |
| 143 buildFunctionNode(target); | 143 buildFunctionNode(target); |
| 144 } else if (target is ir.FunctionDeclaration) { | |
| 145 target = (target as ir.FunctionDeclaration).function; | |
| 146 buildFunctionNode(target); | |
|
sra1
2016/12/06 23:26:15
why not:
buildFunctionNode(target.function);
you
| |
| 144 } else { | 147 } else { |
| 145 throw 'No case implemented to handle $target'; | 148 throw 'No case implemented to handle $target'; |
| 146 } | 149 } |
| 147 assert(graph.isValid()); | 150 assert(graph.isValid()); |
| 148 return graph; | 151 return graph; |
| 149 } | 152 } |
| 150 | 153 |
| 151 void buildField(ir.Field field) { | 154 void buildField(ir.Field field) { |
| 152 openFunction(); | 155 openFunction(); |
| 153 if (field.initializer != null) { | 156 if (field.initializer != null) { |
| (...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1643 push(new HInvokeDynamicGetter(selector, mask, null, inputs, type)); | 1646 push(new HInvokeDynamicGetter(selector, mask, null, inputs, type)); |
| 1644 } else if (selector.isSetter) { | 1647 } else if (selector.isSetter) { |
| 1645 push(new HInvokeDynamicSetter(selector, mask, null, inputs, type)); | 1648 push(new HInvokeDynamicSetter(selector, mask, null, inputs, type)); |
| 1646 } else { | 1649 } else { |
| 1647 push(new HInvokeDynamicMethod( | 1650 push(new HInvokeDynamicMethod( |
| 1648 selector, mask, inputs, type, isIntercepted)); | 1651 selector, mask, inputs, type, isIntercepted)); |
| 1649 } | 1652 } |
| 1650 } | 1653 } |
| 1651 | 1654 |
| 1652 @override | 1655 @override |
| 1653 void visitFunctionExpression(ir.FunctionExpression funcExpression) { | 1656 visitFunctionNode(ir.FunctionNode node) { |
| 1654 LocalFunctionElement methodElement = astAdapter.getElement(funcExpression); | 1657 LocalFunctionElement methodElement = astAdapter.getElement(node); |
| 1655 ClosureClassMap nestedClosureData = compiler.closureToClassMapper | 1658 ClosureClassMap nestedClosureData = compiler.closureToClassMapper |
| 1656 .getClosureToClassMapping(methodElement.resolvedAst); | 1659 .getClosureToClassMapping(methodElement.resolvedAst); |
| 1657 assert(nestedClosureData != null); | 1660 assert(nestedClosureData != null); |
| 1658 assert(nestedClosureData.closureClassElement != null); | 1661 assert(nestedClosureData.closureClassElement != null); |
| 1659 ClosureClassElement closureClassElement = | 1662 ClosureClassElement closureClassElement = |
| 1660 nestedClosureData.closureClassElement; | 1663 nestedClosureData.closureClassElement; |
| 1661 FunctionElement callElement = nestedClosureData.callElement; | 1664 FunctionElement callElement = nestedClosureData.callElement; |
| 1662 // TODO(ahe): This should be registered in codegen, not here. | 1665 // TODO(ahe): This should be registered in codegen, not here. |
| 1663 // TODO(johnniwinther): Is [registerStaticUse] equivalent to | 1666 // TODO(johnniwinther): Is [registerStaticUse] equivalent to |
| 1664 // [addToWorkList]? | 1667 // [addToWorkList]? |
| 1665 registry?.registerStaticUse(new StaticUse.foreignUse(callElement)); | 1668 registry?.registerStaticUse(new StaticUse.foreignUse(callElement)); |
| 1666 | 1669 |
| 1667 List<HInstruction> capturedVariables = <HInstruction>[]; | 1670 List<HInstruction> capturedVariables = <HInstruction>[]; |
| 1668 closureClassElement.closureFields.forEach((ClosureFieldElement field) { | 1671 closureClassElement.closureFields.forEach((ClosureFieldElement field) { |
| 1669 Local capturedLocal = | 1672 Local capturedLocal = |
| 1670 nestedClosureData.getLocalVariableForClosureField(field); | 1673 nestedClosureData.getLocalVariableForClosureField(field); |
| 1671 assert(capturedLocal != null); | 1674 assert(capturedLocal != null); |
| 1672 capturedVariables.add(localsHandler.readLocal(capturedLocal)); | 1675 capturedVariables.add(localsHandler.readLocal(capturedLocal)); |
| 1673 }); | 1676 }); |
| 1674 | 1677 |
| 1675 TypeMask type = | 1678 TypeMask type = |
| 1676 new TypeMask.nonNullExact(closureClassElement, compiler.closedWorld); | 1679 new TypeMask.nonNullExact(closureClassElement, compiler.closedWorld); |
| 1677 // TODO(efortuna): Add source information here. | 1680 // TODO(efortuna): Add source information here. |
| 1678 push(new HCreate(closureClassElement, capturedVariables, type)); | 1681 push(new HCreate(closureClassElement, capturedVariables, type)); |
| 1679 | 1682 |
| 1680 registry?.registerInstantiatedClosure(methodElement); | 1683 registry?.registerInstantiatedClosure(methodElement); |
| 1681 } | 1684 } |
| 1682 | 1685 |
| 1686 @override | |
| 1687 visitFunctionDeclaration(ir.FunctionDeclaration declaration) { | |
| 1688 assert(isReachable); | |
| 1689 declaration.function.accept(this); | |
| 1690 LocalFunctionElement localFunction = astAdapter.getElement( | |
| 1691 declaration.function); | |
| 1692 //LocalFunctionElement localFunction = | |
| 1693 // elements.getFunctionDefinition(declaration.function); | |
|
sra1
2016/12/06 23:26:15
comment
| |
| 1694 localsHandler.updateLocal(localFunction, pop()); | |
| 1695 } | |
| 1696 | |
| 1697 @override | |
| 1698 void visitFunctionExpression(ir.FunctionExpression funcExpression) { | |
| 1699 funcExpression.function.accept(this); | |
| 1700 } | |
| 1701 | |
| 1683 // TODO(het): Decide when to inline | 1702 // TODO(het): Decide when to inline |
| 1684 @override | 1703 @override |
| 1685 void visitMethodInvocation(ir.MethodInvocation invocation) { | 1704 void visitMethodInvocation(ir.MethodInvocation invocation) { |
| 1686 // Handle `x == null` specially. When these come from null-aware operators, | 1705 // Handle `x == null` specially. When these come from null-aware operators, |
| 1687 // there is no mapping in the astAdapter. | 1706 // there is no mapping in the astAdapter. |
| 1688 if (_handleEqualsNull(invocation)) return; | 1707 if (_handleEqualsNull(invocation)) return; |
| 1689 invocation.receiver.accept(this); | 1708 invocation.receiver.accept(this); |
| 1690 HInstruction receiver = pop(); | 1709 HInstruction receiver = pop(); |
| 1691 Selector selector = astAdapter.getSelector(invocation); | 1710 Selector selector = astAdapter.getSelector(invocation); |
| 1692 _pushDynamicInvocation( | 1711 _pushDynamicInvocation( |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1847 push(new HNot(popBoolified(), backend.boolType)); | 1866 push(new HNot(popBoolified(), backend.boolType)); |
| 1848 } | 1867 } |
| 1849 | 1868 |
| 1850 @override | 1869 @override |
| 1851 void visitStringConcatenation(ir.StringConcatenation stringConcat) { | 1870 void visitStringConcatenation(ir.StringConcatenation stringConcat) { |
| 1852 KernelStringBuilder stringBuilder = new KernelStringBuilder(this); | 1871 KernelStringBuilder stringBuilder = new KernelStringBuilder(this); |
| 1853 stringConcat.accept(stringBuilder); | 1872 stringConcat.accept(stringBuilder); |
| 1854 stack.add(stringBuilder.result); | 1873 stack.add(stringBuilder.result); |
| 1855 } | 1874 } |
| 1856 } | 1875 } |
| OLD | NEW |