| 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 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 // Find a type for the element. Use the element type of the indexer of the | 804 // Find a type for the element. Use the element type of the indexer of the |
| 805 // array, as this is stronger than the iterator's `get current` type, for | 805 // array, as this is stronger than the iterator's `get current` type, for |
| 806 // example, `get current` includes null. | 806 // example, `get current` includes null. |
| 807 // TODO(sra): The element type of a container type mask might be better. | 807 // TODO(sra): The element type of a container type mask might be better. |
| 808 TypeMask type = astAdapter.inferredIndexType(forInStatement); | 808 TypeMask type = astAdapter.inferredIndexType(forInStatement); |
| 809 | 809 |
| 810 HInstruction index = localsHandler.readLocal(indexVariable); | 810 HInstruction index = localsHandler.readLocal(indexVariable); |
| 811 HInstruction value = new HIndex(array, index, null, type); | 811 HInstruction value = new HIndex(array, index, null, type); |
| 812 add(value); | 812 add(value); |
| 813 | 813 |
| 814 localsHandler.updateLocal( | 814 Local loopVariableLocal = astAdapter.getLocal(forInStatement.variable); |
| 815 astAdapter.getLocal(forInStatement.variable), value); | 815 localsHandler.updateLocal(loopVariableLocal, value); |
| 816 // Hint to name loop value after name of loop variable. |
| 817 if (loopVariableLocal is !SyntheticLocal) { |
| 818 value.sourceElement ??= loopVariableLocal; |
| 819 } |
| 816 | 820 |
| 817 forInStatement.body.accept(this); | 821 forInStatement.body.accept(this); |
| 818 } | 822 } |
| 819 | 823 |
| 820 void buildUpdate() { | 824 void buildUpdate() { |
| 821 // See buildBody as to why we check here. | 825 // See buildBody as to why we check here. |
| 822 buildConcurrentModificationErrorCheck(); | 826 buildConcurrentModificationErrorCheck(); |
| 823 | 827 |
| 824 // TODO(sra): It would be slightly shorter to generate `a[i++]` in the | 828 // TODO(sra): It would be slightly shorter to generate `a[i++]` in the |
| 825 // body (and that more closely follows what an inlined iterator would do) | 829 // body (and that more closely follows what an inlined iterator would do) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 TypeMask mask = astAdapter.typeOfIteratorMoveNext(forInStatement); | 865 TypeMask mask = astAdapter.typeOfIteratorMoveNext(forInStatement); |
| 862 _pushDynamicInvocation(forInStatement, mask, <HInstruction>[iterator], | 866 _pushDynamicInvocation(forInStatement, mask, <HInstruction>[iterator], |
| 863 selector: Selectors.moveNext); | 867 selector: Selectors.moveNext); |
| 864 return popBoolified(); | 868 return popBoolified(); |
| 865 } | 869 } |
| 866 | 870 |
| 867 void buildBody() { | 871 void buildBody() { |
| 868 TypeMask mask = astAdapter.typeOfIteratorCurrent(forInStatement); | 872 TypeMask mask = astAdapter.typeOfIteratorCurrent(forInStatement); |
| 869 _pushDynamicInvocation(forInStatement, mask, [iterator], | 873 _pushDynamicInvocation(forInStatement, mask, [iterator], |
| 870 selector: Selectors.current); | 874 selector: Selectors.current); |
| 871 localsHandler.updateLocal( | 875 Local loopVariableLocal = astAdapter.getLocal(forInStatement.variable); |
| 872 astAdapter.getLocal(forInStatement.variable), pop()); | 876 HInstruction value = pop(); |
| 877 localsHandler.updateLocal(loopVariableLocal, value); |
| 878 // Hint to name loop value after name of loop variable. |
| 879 if (loopVariableLocal is !SyntheticLocal) { |
| 880 value.sourceElement ??= loopVariableLocal; |
| 881 } |
| 873 forInStatement.body.accept(this); | 882 forInStatement.body.accept(this); |
| 874 } | 883 } |
| 875 | 884 |
| 876 loopHandler.handleLoop( | 885 loopHandler.handleLoop( |
| 877 forInStatement, buildInitializer, buildCondition, () {}, buildBody); | 886 forInStatement, buildInitializer, buildCondition, () {}, buildBody); |
| 878 } | 887 } |
| 879 | 888 |
| 880 void _buildAsyncForIn(ir.ForInStatement forInStatement) { | 889 void _buildAsyncForIn(ir.ForInStatement forInStatement) { |
| 881 // The async-for is implemented with a StreamIterator. | 890 // The async-for is implemented with a StreamIterator. |
| 882 HInstruction streamIterator; | 891 HInstruction streamIterator; |
| (...skipping 2223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3106 enterBlock.setBlockFlow( | 3115 enterBlock.setBlockFlow( |
| 3107 new HTryBlockInformation( | 3116 new HTryBlockInformation( |
| 3108 kernelBuilder.wrapStatementGraph(bodyGraph), | 3117 kernelBuilder.wrapStatementGraph(bodyGraph), |
| 3109 exception, | 3118 exception, |
| 3110 kernelBuilder.wrapStatementGraph(catchGraph), | 3119 kernelBuilder.wrapStatementGraph(catchGraph), |
| 3111 kernelBuilder.wrapStatementGraph(finallyGraph)), | 3120 kernelBuilder.wrapStatementGraph(finallyGraph)), |
| 3112 exitBlock); | 3121 exitBlock); |
| 3113 kernelBuilder.inTryStatement = previouslyInTryStatement; | 3122 kernelBuilder.inTryStatement = previouslyInTryStatement; |
| 3114 } | 3123 } |
| 3115 } | 3124 } |
| OLD | NEW |