Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: pkg/kernel/lib/transformations/closure/context.dart

Issue 2998803002: [kernel] Support for top-level generic functions. (Closed)
Patch Set: Fix test. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 library kernel.transformations.closure.context; 5 library kernel.transformations.closure.context;
6 6
7 import '../../ast.dart' 7 import '../../ast.dart'
8 show 8 show
9 Expression, 9 Expression,
10 NullLiteral, 10 NullLiteral,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 parent, 122 parent,
123 converter.rewriter.contextDeclaration, 123 converter.rewriter.contextDeclaration,
124 converter.rewriter.vectorCreation); 124 converter.rewriter.vectorCreation);
125 } 125 }
126 126
127 Expression get expression => accessor.buildSimpleRead(); 127 Expression get expression => accessor.buildSimpleRead();
128 128
129 Accessor get accessor => new VariableAccessor(self, null, TreeNode.noOffset); 129 Accessor get accessor => new VariableAccessor(self, null, TreeNode.noOffset);
130 130
131 void extend(VariableDeclaration variable, Expression value) { 131 void extend(VariableDeclaration variable, Expression value) {
132 // Increase index by 1, because the parent occupies item 0, and all other 132 // Increase index by 2, because the type arguments vector occupies position
133 // variables are therefore shifted by 1. 133 // 0, the parent occupies position 1, and all other variables are therefore
134 // shifted by 2.
134 VectorSet initializer = 135 VectorSet initializer =
135 new VectorSet(expression, variables.length + 1, value); 136 new VectorSet(expression, variables.length + 2, value);
136 value.parent = initializer; 137 value.parent = initializer;
137 138
138 converter.rewriter.insertExtendContext(initializer); 139 converter.rewriter.insertExtendContext(initializer);
139 140
140 ++vectorCreation.length; 141 ++vectorCreation.length;
141 variables.add(variable); 142 variables.add(variable);
142 initializers[variable] = initializer; 143 initializers[variable] = initializer;
143 } 144 }
144 145
145 void update(VariableDeclaration variable, Expression value) { 146 void update(VariableDeclaration variable, Expression value) {
146 VectorSet initializer = initializers[variable]; 147 VectorSet initializer = initializers[variable];
147 initializer.value = value; 148 initializer.value = value;
148 value.parent = initializer; 149 value.parent = initializer;
149 } 150 }
150 151
151 Expression lookup(VariableDeclaration variable) { 152 Expression lookup(VariableDeclaration variable) {
152 var index = variables.indexOf(variable); 153 var index = variables.indexOf(variable);
153 // Increase index by 1 in case of success, because the parent occupies 154 // Increase index by 2 in case of success, because the type arguments vector
154 // item 0, and all other variables are therefore shifted by 1. 155 // occupies position 0, the parent occupies position 1, and all other
156 // variables are therefore shifted by 2.
155 return index == -1 157 return index == -1
156 ? parent.lookup(variable) 158 ? parent.lookup(variable)
157 : new VectorGet(expression, index + 1); 159 : new VectorGet(expression, index + 2);
158 } 160 }
159 161
160 Expression assign(VariableDeclaration variable, Expression value, 162 Expression assign(VariableDeclaration variable, Expression value,
161 {bool voidContext: false}) { 163 {bool voidContext: false}) {
162 var index = variables.indexOf(variable); 164 var index = variables.indexOf(variable);
163 // Increase index by 1 in case of success, because the parent occupies 165 // Increase index by 2 in case of success, because the type arguments vector
164 // item 0, and all other variables are therefore shifted by 1. 166 // occupies position 0, the parent occupies position 1, and all other
167 // variables are therefore shifted by 2.
165 return index == -1 168 return index == -1
166 ? parent.assign(variable, value, voidContext: voidContext) 169 ? parent.assign(variable, value, voidContext: voidContext)
167 : new VectorSet(expression, index + 1, value); 170 : new VectorSet(expression, index + 2, value);
168 } 171 }
169 172
170 Context toNestedContext([Accessor accessor]) { 173 Context toNestedContext([Accessor accessor]) {
171 accessor ??= this.accessor; 174 accessor ??= this.accessor;
172 List<List<VariableDeclaration>> variabless = <List<VariableDeclaration>>[]; 175 List<List<VariableDeclaration>> variabless = <List<VariableDeclaration>>[];
173 var current = this; 176 var current = this;
174 while (current != null && current is! NoContext) { 177 while (current != null && current is! NoContext) {
175 if (current is LocalContext) { 178 if (current is LocalContext) {
176 variabless.add(current.variables); 179 variabless.add(current.variables);
177 current = current.parent; 180 current = current.parent;
(...skipping 25 matching lines...) Expand all
203 void extend(VariableDeclaration variable, Expression value) { 206 void extend(VariableDeclaration variable, Expression value) {
204 converter.context = new LocalContext(converter, this) 207 converter.context = new LocalContext(converter, this)
205 ..extend(variable, value); 208 ..extend(variable, value);
206 } 209 }
207 210
208 Expression lookup(VariableDeclaration variable) { 211 Expression lookup(VariableDeclaration variable) {
209 Expression context = expression; 212 Expression context = expression;
210 for (var variables in variabless) { 213 for (var variables in variabless) {
211 var index = variables.indexOf(variable); 214 var index = variables.indexOf(variable);
212 if (index != -1) { 215 if (index != -1) {
213 // Increase index by 1, because the parent occupies item 0, and all 216 // Increase index by 2 in case of success, because the type arguments
214 // other variables are therefore shifted by 1. 217 // vector occupies position 0, the parent occupies item 1, and all other
215 return new VectorGet(context, index + 1); 218 // variables are therefore shifted by 2.
219 return new VectorGet(context, index + 2);
216 } 220 }
217 // Item 0 of a context always points to its parent. 221 // Item 1 of a context always points to its parent.
218 context = new VectorGet(context, 0); 222 context = new VectorGet(context, 1);
219 } 223 }
220 throw 'Unbound NestedContext.lookup($variable)'; 224 throw 'Unbound NestedContext.lookup($variable)';
221 } 225 }
222 226
223 Expression assign(VariableDeclaration variable, Expression value, 227 Expression assign(VariableDeclaration variable, Expression value,
224 {bool voidContext: false}) { 228 {bool voidContext: false}) {
225 Expression context = expression; 229 Expression context = expression;
226 for (List<VariableDeclaration> variables in variabless) { 230 for (List<VariableDeclaration> variables in variabless) {
227 var index = variables.indexOf(variable); 231 var index = variables.indexOf(variable);
228 if (index != -1) { 232 if (index != -1) {
229 // Increase index by 1, because the parent occupies item 0, and all 233 // Increase index by 2 in case of success, because the type arguments
230 // other variables are therefore shifted by 1. 234 // vector occupies position 0, the parent occupies item 1, and all other
231 return new VectorSet(context, index + 1, value); 235 // variables are therefore shifted by 2.
236 return new VectorSet(context, index + 2, value);
232 } 237 }
233 // Item 0 of a context always points to its parent. 238 // Item 1 of a context always points to its parent.
234 context = new VectorGet(context, 0); 239 context = new VectorGet(context, 1);
235 } 240 }
236 throw 'Unbound NestedContext.lookup($variable)'; 241 throw 'Unbound NestedContext.lookup($variable)';
237 } 242 }
238 243
239 Context toNestedContext([Accessor accessor]) { 244 Context toNestedContext([Accessor accessor]) {
240 return new NestedContext(converter, accessor ?? this.accessor, variabless); 245 return new NestedContext(converter, accessor ?? this.accessor, variabless);
241 } 246 }
242 } 247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698