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

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: Review comments. 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
« no previous file with comments | « no previous file | pkg/kernel/lib/transformations/argument_extraction_for_redirecting.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
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 ArgumentExtractionForTesting().visitProgram(program);
22 return program;
23 }
24
25 void transformLibraries(CoreTypes coreTypes, List<Library> libraries) {
26 var transformer = new ArgumentExtractionForTesting();
27 for (var library in libraries) {
28 transformer.visitLibrary(library);
29 }
30 }
31
32 class ArgumentExtractionForTesting extends Transformer {
33 visitConstructor(Constructor node) {
34 var newInits = <Initializer>[];
35
36 int nameCounter = 0;
37 for (var fieldInit in node.initializers) {
38 if (fieldInit is FieldInitializer &&
39 !fieldInit.field.name.name.endsWith("_li")) {
40 // Move the body of the initializer to a new local initializer, and
41 // eta-expand the reference to the local initializer in the body of the
42 // field initializer.
43 var value = fieldInit.value;
44
45 var decl = new VariableDeclaration('#li_$nameCounter');
46 decl.initializer = value;
47 var localInit = new LocalInitializer(decl);
48 localInit.parent = node;
49 newInits.add(localInit);
50
51 fieldInit.value = new VariableGet(decl);
52 fieldInit.value.parent = fieldInit;
53
54 ++nameCounter;
55 newInits.add(fieldInit);
56 } else {
57 newInits.add(fieldInit);
58 }
59 }
60
61 node.initializers = newInits;
62 return super.visitConstructor(node);
63 }
64 }
OLDNEW
« no previous file with comments | « no previous file | pkg/kernel/lib/transformations/argument_extraction_for_redirecting.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698