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

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

Issue 3000333002: Fix several bugs in closure conversion. (Closed)
Patch Set: Fix bugs. Created 3 years, 3 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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
351 if (function.asyncMarker == AsyncMarker.SyncYielding) {
352 function.transformChildren(this);
353 return new FunctionExpression(function);
354 }
350 FunctionNode enclosingFunction = currentFunction; 355 FunctionNode enclosingFunction = currentFunction;
351 Map<TypeParameter, DartType> enclosingTypeSubstitution = typeSubstitution; 356 Map<TypeParameter, DartType> enclosingTypeSubstitution = typeSubstitution;
352 currentFunction = function; 357 currentFunction = function;
353 Statement body = function.body; 358 Statement body = function.body;
354 assert(body != null); 359 assert(body != null);
355 360
356 rewriter = makeRewriterForBody(function); 361 rewriter = makeRewriterForBody(function);
357 362
358 VariableDeclaration contextVariable = 363 VariableDeclaration contextVariable =
359 new VariableDeclaration("#contextParameter", type: const VectorType()); 364 new VariableDeclaration("#contextParameter", type: const VectorType());
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 .forEach(extendContextConditionally(inInitializer: false)); 552 .forEach(extendContextConditionally(inInitializer: false));
548 assert(node.body != null); 553 assert(node.body != null);
549 node.body = node.body.accept(this); 554 node.body = node.body.accept(this);
550 node.body.parent = node; 555 node.body.parent = node;
551 return node; 556 return node;
552 } 557 }
553 558
554 TreeNode visitBlock(Block node) { 559 TreeNode visitBlock(Block node) {
555 return saveContext(() { 560 return saveContext(() {
556 BlockRewriter blockRewriter = rewriter = rewriter.forNestedBlock(node); 561 BlockRewriter blockRewriter = rewriter = rewriter.forNestedBlock(node);
562 if (node.parent is Statement &&
563 (node.parent as Statement).isLoop &&
564 context is! NoContext) {
565 context = context.toNestedContext();
566 }
557 blockRewriter.transformStatements(this); 567 blockRewriter.transformStatements(this);
558 return node; 568 return node;
559 }); 569 });
560 } 570 }
561 571
562 TreeNode visitVariableDeclaration(VariableDeclaration node) { 572 TreeNode visitVariableDeclaration(VariableDeclaration node) {
563 node.transformChildren(this); 573 node.transformChildren(this);
564 574
565 if (!capturedVariables.contains(node)) return node; 575 if (!capturedVariables.contains(node)) return node;
566 if (node.initializer == null && node.parent is FunctionNode) { 576 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; 830 copy.function.body.parent = copy.function;
821 return copy; 831 return copy;
822 } 832 }
823 833
824 void addGetterForwarder(Name name, Procedure getter) { 834 void addGetterForwarder(Name name, Procedure getter) {
825 assert(getter.isGetter); 835 assert(getter.isGetter);
826 newClassMembers 836 newClassMembers
827 .add(copyWithBody(getter, forwardToThisProperty(getter))..name = name); 837 .add(copyWithBody(getter, forwardToThisProperty(getter))..name = name);
828 } 838 }
829 } 839 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698