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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 InitializerRewriter(this.initializingExpression); | 93 InitializerRewriter(this.initializingExpression); |
94 | 94 |
95 @override | 95 @override |
96 BlockRewriter forNestedBlock(Block block) { | 96 BlockRewriter forNestedBlock(Block block) { |
97 return new BlockRewriter(block); | 97 return new BlockRewriter(block); |
98 } | 98 } |
99 | 99 |
100 @override | 100 @override |
101 void insertContextDeclaration(Expression accessParent) { | 101 void insertContextDeclaration(Expression accessParent) { |
102 _createDeclaration(); | 102 _createDeclaration(); |
| 103 var oldParent = initializingExpression.parent; |
103 Let binding = new Let(contextDeclaration, initializingExpression); | 104 Let binding = new Let(contextDeclaration, initializingExpression); |
| 105 binding.parent = oldParent; |
104 setInitializerExpression(binding); | 106 setInitializerExpression(binding); |
105 initializingExpression.parent = binding; | |
106 } | 107 } |
107 | 108 |
108 @override | 109 @override |
109 void insertExtendContext(VectorSet extender) { | 110 void insertExtendContext(VectorSet extender) { |
110 Let parent = initializingExpression.parent; | 111 Let parent = initializingExpression.parent; |
111 Let binding = new Let(new VariableDeclaration(null, initializer: extender), | 112 Let binding = new Let(new VariableDeclaration(null, initializer: extender), |
112 initializingExpression); | 113 initializingExpression); |
113 parent.body = binding; | 114 parent.body = binding; |
114 binding.parent = parent; | 115 binding.parent = parent; |
115 } | 116 } |
116 | 117 |
117 void setInitializerExpression(Expression expression); | 118 void setInitializerExpression(Expression expression); |
118 } | 119 } |
119 | 120 |
120 class FieldInitializerRewriter extends InitializerRewriter { | 121 class FieldInitializerRewriter extends InitializerRewriter { |
121 FieldInitializerRewriter(Expression initializingExpression) | 122 FieldInitializerRewriter(Expression initializingExpression) |
122 : super(initializingExpression) { | 123 : super(initializingExpression) { |
123 assert(initializingExpression.parent is FieldInitializer); | 124 assert(initializingExpression.parent is FieldInitializer); |
124 } | 125 } |
125 | 126 |
126 void setInitializerExpression(Expression expression) { | 127 void setInitializerExpression(Expression expression) { |
127 assert(initializingExpression.parent is FieldInitializer); | 128 expression.parent.value = expression; |
128 FieldInitializer parent = initializingExpression.parent; | |
129 parent.value = expression; | |
130 expression.parent = parent; | |
131 } | 129 } |
132 } | 130 } |
133 | 131 |
134 class LocalInitializerRewriter extends InitializerRewriter { | 132 class LocalInitializerRewriter extends InitializerRewriter { |
135 LocalInitializerRewriter(Expression initializingExpression) | 133 LocalInitializerRewriter(Expression initializingExpression) |
136 : super(initializingExpression) { | 134 : super(initializingExpression) { |
137 assert(initializingExpression.parent is LocalInitializer); | 135 // The initializer is up two levels because the variable declaration node is |
| 136 // in between. |
| 137 assert(initializingExpression.parent.parent is LocalInitializer); |
138 } | 138 } |
139 | 139 |
140 void setInitializerExpression(Expression expression) { | 140 void setInitializerExpression(Expression expression) { |
141 assert(initializingExpression.parent is LocalInitializer); | 141 expression.parent.initializer = expression; |
142 LocalInitializer parent = initializingExpression.parent; | |
143 parent.variable.initializer = expression; | |
144 expression.parent = parent; | |
145 } | 142 } |
146 } | 143 } |
OLD | NEW |