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

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

Issue 3000333002: Fix several bugs in closure conversion. (Closed)
Patch Set: 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.converter; 5 library kernel.transformations.closure.converter;
6 6
7 import '../../ast.dart' 7 import '../../ast.dart'
8 show 8 show
9 AsyncMarker,
9 Arguments, 10 Arguments,
10 Block, 11 Block,
11 Catch, 12 Catch,
12 Class, 13 Class,
13 ClosureCreation, 14 ClosureCreation,
14 Constructor, 15 Constructor,
15 DartType, 16 DartType,
16 EmptyStatement, 17 EmptyStatement,
17 Expression, 18 Expression,
18 ExpressionStatement, 19 ExpressionStatement,
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 340
340 TreeNode visitField(Field node) { 341 TreeNode visitField(Field node) {
341 currentMember = node; 342 currentMember = node;
342 context = new NoContext(this); 343 context = new NoContext(this);
343 node = super.visitField(node); 344 node = super.visitField(node);
344 context = null; 345 context = null;
345 currentMember = null; 346 currentMember = null;
346 return node; 347 return node;
347 } 348 }
348 349
349 Expression handleLocalFunction(FunctionNode function) { 350 Expression handleLocalFunction(FunctionNode function, [bool nope]) {
Dmitry Stefantsov 2017/08/24 09:41:13 Is [nope] used anywhere? If not, I suggest removi
sjindel 2017/08/24 11:11:43 This was just some vestigial debugging code.
351 nope ??= false;
352 if (function.asyncMarker != AsyncMarker.Sync || nope) {
353 function.transformChildren(this);
354 return new FunctionExpression(function);
355 }
350 FunctionNode enclosingFunction = currentFunction; 356 FunctionNode enclosingFunction = currentFunction;
351 Map<TypeParameter, DartType> enclosingTypeSubstitution = typeSubstitution; 357 Map<TypeParameter, DartType> enclosingTypeSubstitution = typeSubstitution;
352 currentFunction = function; 358 currentFunction = function;
353 Statement body = function.body; 359 Statement body = function.body;
354 assert(body != null); 360 assert(body != null);
355 361
356 rewriter = makeRewriterForBody(function); 362 rewriter = makeRewriterForBody(function);
357 363
358 VariableDeclaration contextVariable = 364 VariableDeclaration contextVariable =
359 new VariableDeclaration("#contextParameter", type: const VectorType()); 365 new VariableDeclaration("#contextParameter", type: const VectorType());
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 .forEach(extendContextConditionally(inInitializer: false)); 553 .forEach(extendContextConditionally(inInitializer: false));
548 assert(node.body != null); 554 assert(node.body != null);
549 node.body = node.body.accept(this); 555 node.body = node.body.accept(this);
550 node.body.parent = node; 556 node.body.parent = node;
551 return node; 557 return node;
552 } 558 }
553 559
554 TreeNode visitBlock(Block node) { 560 TreeNode visitBlock(Block node) {
555 return saveContext(() { 561 return saveContext(() {
556 BlockRewriter blockRewriter = rewriter = rewriter.forNestedBlock(node); 562 BlockRewriter blockRewriter = rewriter = rewriter.forNestedBlock(node);
563 if (node.parent is Statement &&
564 (node.parent as Statement).isLoop &&
565 context is! NoContext) {
566 context = context.toNestedContext();
567 }
557 blockRewriter.transformStatements(this); 568 blockRewriter.transformStatements(this);
558 return node; 569 return node;
559 }); 570 });
560 } 571 }
561 572
562 TreeNode visitVariableDeclaration(VariableDeclaration node) { 573 TreeNode visitVariableDeclaration(VariableDeclaration node) {
563 node.transformChildren(this); 574 node.transformChildren(this);
564 575
565 if (!capturedVariables.contains(node)) return node; 576 if (!capturedVariables.contains(node)) return node;
566 if (node.initializer == null && node.parent is FunctionNode) { 577 if (node.initializer == null && node.parent is FunctionNode) {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 copy.function.body.parent = copy.function; 831 copy.function.body.parent = copy.function;
821 return copy; 832 return copy;
822 } 833 }
823 834
824 void addGetterForwarder(Name name, Procedure getter) { 835 void addGetterForwarder(Name name, Procedure getter) {
825 assert(getter.isGetter); 836 assert(getter.isGetter);
826 newClassMembers 837 newClassMembers
827 .add(copyWithBody(getter, forwardToThisProperty(getter))..name = name); 838 .add(copyWithBody(getter, forwardToThisProperty(getter))..name = name);
828 } 839 }
829 } 840 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698