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

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

Issue 2939043002: Remove unnecessary contexts in closure conversion (Closed)
Patch Set: Don't treat constructor parameters in initializers as captured Created 3 years, 6 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.info; 5 library kernel.transformations.closure.info;
6 6
7 import '../../ast.dart' 7 import '../../ast.dart'
8 show 8 show
9 Class, 9 Class,
10 Constructor, 10 Constructor,
11 Field, 11 Field,
12 FieldInitializer,
12 FunctionDeclaration, 13 FunctionDeclaration,
13 FunctionNode, 14 FunctionNode,
15 LocalInitializer,
14 Member, 16 Member,
15 Name, 17 Name,
16 Procedure, 18 Procedure,
17 ProcedureKind, 19 ProcedureKind,
18 PropertyGet, 20 PropertyGet,
21 RedirectingInitializer,
22 SuperInitializer,
19 ThisExpression, 23 ThisExpression,
20 TypeParameter, 24 TypeParameter,
21 TypeParameterType, 25 TypeParameterType,
22 VariableDeclaration, 26 VariableDeclaration,
23 VariableGet, 27 VariableGet,
24 VariableSet; 28 VariableSet;
25 29
26 import '../../visitor.dart' show RecursiveVisitor; 30 import '../../visitor.dart' show RecursiveVisitor;
27 31
28 class ClosureInfo extends RecursiveVisitor { 32 class ClosureInfo extends RecursiveVisitor {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (!isOuterMostContext) { 206 if (!isOuterMostContext) {
203 thisAccess.putIfAbsent( 207 thisAccess.putIfAbsent(
204 currentMemberFunction, () => new VariableDeclaration("#self")); 208 currentMemberFunction, () => new VariableDeclaration("#self"));
205 } 209 }
206 } 210 }
207 211
208 visitPropertyGet(PropertyGet node) { 212 visitPropertyGet(PropertyGet node) {
209 invokedGetters.add(node.name); 213 invokedGetters.add(node.name);
210 super.visitPropertyGet(node); 214 super.visitPropertyGet(node);
211 } 215 }
216
217 visitFieldInitializer(FieldInitializer node) {
karlklose 2017/06/16 07:54:43 Consider adding a helper and move the comment ther
Dmitry Stefantsov 2017/06/16 08:30:00 Thanks! I agree, an example could help with under
218 // Set [currentFunction] to [currentMemberFunction] during visiting the
219 // initializer. Effectively it means that [currentFunction] is set to
220 // [function] field of the constructor, and constructor parameters
221 // encountered in the initializer won't be treated as captured.
222 // Same trick is used in [visitSuperInitializer],
223 // [visitRedirectingInitializer], and [visitLocalInitializer].
224 var saved = currentFunction;
225 currentFunction = currentMemberFunction;
226 super.visitFieldInitializer(node);
227 currentFunction = saved;
228 }
229
230 visitSuperInitializer(SuperInitializer node) {
231 var saved = currentFunction;
232 currentFunction = currentMemberFunction;
233 super.visitSuperInitializer(node);
234 currentFunction = saved;
235 }
236
237 visitRedirectingInitializer(RedirectingInitializer node) {
238 var saved = currentFunction;
239 currentFunction = currentMemberFunction;
240 super.visitRedirectingInitializer(node);
241 currentFunction = saved;
242 }
243
244 visitLocalInitializer(LocalInitializer node) {
245 var saved = currentFunction;
246 currentFunction = currentMemberFunction;
247 super.visitLocalInitializer(node);
248 currentFunction = saved;
249 }
212 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698