| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 typeBuilder = new TypeBuilder(this); | 146 typeBuilder = new TypeBuilder(this); |
| 147 graph.element = targetElement; | 147 graph.element = targetElement; |
| 148 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? | 148 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? |
| 149 this.sourceInformationBuilder = | 149 this.sourceInformationBuilder = |
| 150 sourceInformationFactory.createBuilderForContext(resolvedAst); | 150 sourceInformationFactory.createBuilderForContext(resolvedAst); |
| 151 graph.sourceInformation = | 151 graph.sourceInformation = |
| 152 sourceInformationBuilder.buildVariableDeclaration(); | 152 sourceInformationBuilder.buildVariableDeclaration(); |
| 153 this.localsHandler = new LocalsHandler(this, targetElement, null, compiler); | 153 this.localsHandler = new LocalsHandler(this, targetElement, null, compiler); |
| 154 this.astAdapter = new KernelAstAdapter(kernel, compiler.backend, | 154 this.astAdapter = new KernelAstAdapter(kernel, compiler.backend, |
| 155 resolvedAst, kernel.nodeToAst, kernel.nodeToElement); | 155 resolvedAst, kernel.nodeToAst, kernel.nodeToElement); |
| 156 Element originTarget = targetElement; | 156 target = astAdapter.getInitialKernelNode(targetElement); |
| 157 if (originTarget.isPatch) { | 157 if (targetElement is ConstructorBodyElement) { |
| 158 originTarget = originTarget.origin; | 158 _targetIsConstructorBody = true; |
| 159 } | |
| 160 if (originTarget is FunctionElement) { | |
| 161 if (originTarget is ConstructorBodyElement) { | |
| 162 ConstructorBodyElement body = originTarget; | |
| 163 _targetIsConstructorBody = true; | |
| 164 originTarget = body.constructor; | |
| 165 } | |
| 166 target = kernel.functions[originTarget]; | |
| 167 // Closures require a lookup one level deeper in the closure class mapper. | |
| 168 if (target == null) { | |
| 169 FunctionElement originTargetFunction = originTarget; | |
| 170 ClosureClassMap classMap = compiler.closureToClassMapper | |
| 171 .getClosureToClassMapping(originTargetFunction.resolvedAst); | |
| 172 if (classMap.closureElement != null) { | |
| 173 target = kernel.localFunctions[classMap.closureElement]; | |
| 174 } | |
| 175 } | |
| 176 } else if (originTarget is FieldElement) { | |
| 177 target = kernel.fields[originTarget]; | |
| 178 } | 159 } |
| 179 } | 160 } |
| 180 | 161 |
| 181 HGraph build() { | 162 HGraph build() { |
| 182 // TODO(het): no reason to do this here... | 163 // TODO(het): no reason to do this here... |
| 183 HInstruction.idCounter = 0; | 164 HInstruction.idCounter = 0; |
| 184 if (target is ir.Procedure) { | 165 if (target is ir.Procedure) { |
| 185 _targetFunction = (target as ir.Procedure).function; | 166 _targetFunction = (target as ir.Procedure).function; |
| 186 buildFunctionNode(_targetFunction); | 167 buildFunctionNode(_targetFunction); |
| 187 } else if (target is ir.Field) { | 168 } else if (target is ir.Field) { |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 } | 840 } |
| 860 | 841 |
| 861 loopHandler.handleLoop(forInStatement, buildInitializer, buildCondition, | 842 loopHandler.handleLoop(forInStatement, buildInitializer, buildCondition, |
| 862 buildUpdate, buildBody); | 843 buildUpdate, buildBody); |
| 863 } | 844 } |
| 864 | 845 |
| 865 _buildForInIterator(ir.ForInStatement forInStatement) { | 846 _buildForInIterator(ir.ForInStatement forInStatement) { |
| 866 // Generate a structure equivalent to: | 847 // Generate a structure equivalent to: |
| 867 // Iterator<E> $iter = <iterable>.iterator; | 848 // Iterator<E> $iter = <iterable>.iterator; |
| 868 // while ($iter.moveNext()) { | 849 // while ($iter.moveNext()) { |
| 869 // <declaredIdentifier> = $iter.current; | 850 // <variable> = $iter.current; |
| 870 // <body> | 851 // <body> |
| 871 // } | 852 // } |
| 872 | 853 |
| 873 // The iterator is shared between initializer, condition and body. | 854 // The iterator is shared between initializer, condition and body. |
| 874 HInstruction iterator; | 855 HInstruction iterator; |
| 875 | 856 |
| 876 void buildInitializer() { | 857 void buildInitializer() { |
| 877 TypeMask mask = astAdapter.typeOfIterator(forInStatement); | 858 TypeMask mask = astAdapter.typeOfIterator(forInStatement); |
| 878 forInStatement.iterable.accept(this); | 859 forInStatement.iterable.accept(this); |
| 879 HInstruction receiver = pop(); | 860 HInstruction receiver = pop(); |
| (...skipping 2367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3247 enterBlock.setBlockFlow( | 3228 enterBlock.setBlockFlow( |
| 3248 new HTryBlockInformation( | 3229 new HTryBlockInformation( |
| 3249 kernelBuilder.wrapStatementGraph(bodyGraph), | 3230 kernelBuilder.wrapStatementGraph(bodyGraph), |
| 3250 exception, | 3231 exception, |
| 3251 kernelBuilder.wrapStatementGraph(catchGraph), | 3232 kernelBuilder.wrapStatementGraph(catchGraph), |
| 3252 kernelBuilder.wrapStatementGraph(finallyGraph)), | 3233 kernelBuilder.wrapStatementGraph(finallyGraph)), |
| 3253 exitBlock); | 3234 exitBlock); |
| 3254 kernelBuilder.inTryStatement = previouslyInTryStatement; | 3235 kernelBuilder.inTryStatement = previouslyInTryStatement; |
| 3255 } | 3236 } |
| 3256 } | 3237 } |
| OLD | NEW |