OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 library kernel.transformations.closure.rewriter; | 5 library kernel.transformations.closure.rewriter; |
6 | 6 |
7 import '../../ast.dart'; | 7 import '../../ast.dart'; |
8 import 'converter.dart' show ClosureConverter; | 8 import 'converter.dart' show ClosureConverter; |
9 | 9 |
10 /// Used by the [Context] to initialize and update the context variable | 10 /// Used by the [Context] to initialize and update the context variable |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 class BlockRewriter extends AstRewriter { | 44 class BlockRewriter extends AstRewriter { |
45 Block _currentBlock; | 45 Block _currentBlock; |
46 int _insertionIndex; | 46 int _insertionIndex; |
47 | 47 |
48 BlockRewriter(this._currentBlock) : _insertionIndex = 0; | 48 BlockRewriter(this._currentBlock) : _insertionIndex = 0; |
49 | 49 |
50 BlockRewriter forNestedBlock(Block block) { | 50 BlockRewriter forNestedBlock(Block block) { |
51 return _currentBlock != block ? new BlockRewriter(block) : this; | 51 return _currentBlock != block ? new BlockRewriter(block) : this; |
52 } | 52 } |
53 | 53 |
54 void transformStatements(Block block, ClosureConverter converter) { | 54 void transformStatements(ClosureConverter converter) { |
55 while (_insertionIndex < _currentBlock.statements.length) { | 55 while (_insertionIndex < _currentBlock.statements.length) { |
56 var original = _currentBlock.statements[_insertionIndex]; | 56 var original = _currentBlock.statements[_insertionIndex]; |
57 var transformed = original.accept(converter); | 57 var transformed = original.accept(converter); |
58 assert(_currentBlock.statements[_insertionIndex] == original); | 58 assert(_currentBlock.statements[_insertionIndex] == original); |
59 if (transformed == null) { | 59 if (transformed == null) { |
60 _currentBlock.statements.removeAt(_insertionIndex); | 60 _currentBlock.statements.removeAt(_insertionIndex); |
61 } else { | 61 } else { |
62 _currentBlock.statements[_insertionIndex++] = transformed; | 62 _currentBlock.statements[_insertionIndex++] = transformed; |
63 transformed.parent = _currentBlock; | 63 transformed.parent = _currentBlock; |
64 } | 64 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 @override | 112 @override |
113 void insertExtendContext(VectorSet extender) { | 113 void insertExtendContext(VectorSet extender) { |
114 Let parent = initializingExpression.parent; | 114 Let parent = initializingExpression.parent; |
115 Let binding = new Let(new VariableDeclaration(null, initializer: extender), | 115 Let binding = new Let(new VariableDeclaration(null, initializer: extender), |
116 initializingExpression); | 116 initializingExpression); |
117 parent.body = binding; | 117 parent.body = binding; |
118 binding.parent = parent; | 118 binding.parent = parent; |
119 } | 119 } |
120 } | 120 } |
OLD | NEW |