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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/transformations/argument_extraction.dart
diff --git a/pkg/kernel/lib/transformations/argument_extraction.dart b/pkg/kernel/lib/transformations/argument_extraction.dart
new file mode 100644
index 0000000000000000000000000000000000000000..699f87e5eca66d2d16ae3ab9304082f0ad7084e2
--- /dev/null
+++ b/pkg/kernel/lib/transformations/argument_extraction.dart
@@ -0,0 +1,64 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library kernel.transformations.argument_extraction;
+
+import '../ast.dart'
+ show
+ Constructor,
+ FieldInitializer,
+ Initializer,
+ Library,
+ LocalInitializer,
+ Program,
+ VariableDeclaration,
+ VariableGet;
+import '../core_types.dart' show CoreTypes;
+import '../visitor.dart' show Transformer;
+
+Program transformProgram(CoreTypes coreTypes, Program program) {
+ new ArgumentExtractionForTesting().visitProgram(program);
+ return program;
+}
+
+void transformLibraries(CoreTypes coreTypes, List<Library> libraries) {
+ var transformer = new ArgumentExtractionForTesting();
+ for (var library in libraries) {
+ transformer.visitLibrary(library);
+ }
+}
+
+class ArgumentExtractionForTesting extends Transformer {
+ visitConstructor(Constructor node) {
+ var newInits = <Initializer>[];
+
+ int nameCounter = 0;
+ for (var fieldInit in node.initializers) {
+ if (fieldInit is FieldInitializer &&
+ !fieldInit.field.name.name.endsWith("_li")) {
+ // Move the body of the initializer to a new local initializer, and
+ // eta-expand the reference to the local initializer in the body of the
+ // field initializer.
+ var value = fieldInit.value;
+
+ var decl = new VariableDeclaration('#li_$nameCounter');
+ decl.initializer = value;
+ var localInit = new LocalInitializer(decl);
+ localInit.parent = node;
+ newInits.add(localInit);
+
+ fieldInit.value = new VariableGet(decl);
+ fieldInit.value.parent = fieldInit;
+
+ ++nameCounter;
+ newInits.add(fieldInit);
+ } else {
+ newInits.add(fieldInit);
+ }
+ }
+
+ node.initializers = newInits;
+ return super.visitConstructor(node);
+ }
+}
« 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