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..cceef2d6ad4d6a775c9492dfbb813107e656f52d |
--- /dev/null |
+++ b/pkg/kernel/lib/transformations/argument_extraction.dart |
@@ -0,0 +1,69 @@ |
+// 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_for_redirecting; |
+ |
+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 ArgumentExtractionForRedirecting().visitProgram(program); |
+ return program; |
+} |
+ |
+void transformLibraries(CoreTypes coreTypes, List<Library> libraries) { |
+ var transformer = new ArgumentExtractionForRedirecting(); |
+ for (var library in libraries) { |
+ transformer.visitLibrary(library); |
+ } |
+} |
+ |
+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.
|
+ visitConstructor(Constructor node) { |
+ var newInits = <Initializer>[]; |
+ |
+ int i = 0; |
+ for (var fi in node.initializers) { |
+ if (fi is FieldInitializer) { |
+ if (!fi.field.name.name.endsWith("_li")) { |
+ newInits.add(fi); |
+ continue; |
+ } |
+ |
+ // 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 = fi.value; |
+ |
+ var decl = new VariableDeclaration('#li_$i'); |
+ decl.initializer = value; |
+ var li = new LocalInitializer(decl); |
+ li.parent = node; |
+ newInits.add(li); |
+ |
+ fi.value = new VariableGet(decl); |
+ fi.value.parent = fi; |
+ |
+ ++i; |
+ newInits.add(fi); |
+ } else { |
+ newInits.add(fi); |
+ } |
+ } |
+ |
+ node.initializers = newInits; |
+ return super.visitConstructor(node); |
+ } |
+} |