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

Side by Side Diff: pkg/kernel/lib/transformations/argument_extraction.dart

Issue 2981603002: Convert closures in all initializers, and share the context between them. (Closed)
Patch Set: Change name of the argument extraction pass. Created 3 years, 5 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library kernel.transformations.argument_extraction_for_redirecting;
6
7 import '../ast.dart'
8 show
9 Constructor,
10 FieldInitializer,
11 Initializer,
12 Library,
13 LocalInitializer,
14 Program,
15 VariableDeclaration,
16 VariableGet;
17 import '../core_types.dart' show CoreTypes;
18 import '../visitor.dart' show Transformer;
19
20 Program transformProgram(CoreTypes coreTypes, Program program) {
21 new ArgumentExtractionForRedirecting().visitProgram(program);
22 return program;
23 }
24
25 void transformLibraries(CoreTypes coreTypes, List<Library> libraries) {
26 var transformer = new ArgumentExtractionForRedirecting();
27 for (var library in libraries) {
28 transformer.visitLibrary(library);
29 }
30 }
31
32 class ArgumentExtractionForRedirecting extends Transformer {
Dmitry Stefantsov 2017/07/14 00:34:17 Please, see the comments for argument_extraction_f
sjindel 2017/07/14 08:49:45 I meant to delete this file.
33 visitConstructor(Constructor node) {
34 var newInits = <Initializer>[];
35
36 int i = 0;
37 for (var fi in node.initializers) {
38 if (fi is FieldInitializer) {
39 if (!fi.field.name.name.endsWith("_li")) {
40 newInits.add(fi);
41 continue;
42 }
43
44 // Move the body of the initializer to a new local initializer, and
45 // eta-expand the reference to the local initializer in the body of the
46 // field initializer.
47
48 var value = fi.value;
49
50 var decl = new VariableDeclaration('#li_$i');
51 decl.initializer = value;
52 var li = new LocalInitializer(decl);
53 li.parent = node;
54 newInits.add(li);
55
56 fi.value = new VariableGet(decl);
57 fi.value.parent = fi;
58
59 ++i;
60 newInits.add(fi);
61 } else {
62 newInits.add(fi);
63 }
64 }
65
66 node.initializers = newInits;
67 return super.visitConstructor(node);
68 }
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698