Index: pkg/kernel/lib/transformations/argument_extraction_for_redirecting.dart |
diff --git a/pkg/kernel/lib/transformations/argument_extraction_for_redirecting.dart b/pkg/kernel/lib/transformations/argument_extraction_for_redirecting.dart |
index 39cb7e230c674bcf61d301fdfeb58642214170bd..a1a41427dcbede3351115125489eae841ba96d65 100644 |
--- a/pkg/kernel/lib/transformations/argument_extraction_for_redirecting.dart |
+++ b/pkg/kernel/lib/transformations/argument_extraction_for_redirecting.dart |
@@ -2,65 +2,68 @@ |
// 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; |
+library kernel.transformations.argument_extraction; |
import '../ast.dart' |
show |
- Program, |
Constructor, |
- RedirectingInitializer, |
+ FieldInitializer, |
+ Initializer, |
Library, |
LocalInitializer, |
+ Program, |
VariableDeclaration, |
- VariableGet, |
- Expression, |
- NamedExpression; |
+ VariableGet; |
import '../core_types.dart' show CoreTypes; |
import '../visitor.dart' show Transformer; |
Program transformProgram(CoreTypes coreTypes, Program program) { |
- new ArgumentExtractionForRedirecting().visitProgram(program); |
+ new ArgumentExtractionForTesting().visitProgram(program); |
return program; |
} |
void transformLibraries(CoreTypes coreTypes, List<Library> libraries) { |
- var transformer = new ArgumentExtractionForRedirecting(); |
+ var transformer = new ArgumentExtractionForTesting(); |
for (var library in libraries) { |
transformer.visitLibrary(library); |
} |
} |
-class ArgumentExtractionForRedirecting extends Transformer { |
+class ArgumentExtractionForTesting extends Transformer { |
visitConstructor(Constructor node) { |
- if (node.initializers.length == 1 && |
- node.initializers[0] is RedirectingInitializer) { |
- int index = 0; |
- RedirectingInitializer redirectingInitializer = node.initializers[0]; |
- List<Expression> positionalArguments = |
- redirectingInitializer.arguments.positional; |
- List<NamedExpression> namedArguments = |
- redirectingInitializer.arguments.named; |
- for (int i = 0; i < positionalArguments.length; i++) { |
- Expression argument = positionalArguments[i]; |
- VariableDeclaration extractedArgument = |
- new VariableDeclaration("extracted#$index", initializer: argument); |
- LocalInitializer initializer = new LocalInitializer(extractedArgument) |
- ..parent = node; |
- node.initializers.insert(index++, initializer); |
- positionalArguments[i] = new VariableGet(extractedArgument) |
- ..parent = redirectingInitializer.arguments; |
- } |
- for (int i = 0; i < namedArguments.length; i++) { |
- Expression argument = namedArguments[i].value; |
- VariableDeclaration extractedArgument = |
- new VariableDeclaration("extracted#$index", initializer: argument); |
- LocalInitializer initializer = new LocalInitializer(extractedArgument) |
- ..parent = node; |
- node.initializers.insert(index++, initializer); |
- namedArguments[i].value = new VariableGet(extractedArgument) |
- ..parent = redirectingInitializer.arguments; |
+ var newInits = <Initializer>[]; |
+ |
+ int i = 0; |
Dmitry Stefantsov
2017/07/14 00:34:17
[i] is not a counter of a loop, so I guess it shou
sjindel
2017/07/14 08:49:45
Done.
|
+ for (var fi in node.initializers) { |
Dmitry Stefantsov
2017/07/14 00:34:17
Please, use a more descriptive name in place of [f
sjindel
2017/07/14 08:49:45
Done.
|
+ if (fi is FieldInitializer) { |
+ if (!fi.field.name.name.endsWith("_li")) { |
+ newInits.add(fi); |
+ continue; |
Dmitry Stefantsov
2017/07/14 00:34:17
I think `continue` here doesn't help to eliminate
sjindel
2017/07/14 08:49:45
Done.
|
+ } |
+ |
+ // 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); |
Dmitry Stefantsov
2017/07/14 00:34:17
Please, use a more descriptive name in place of [l
sjindel
2017/07/14 08:49:45
Done.
|
+ 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); |
} |
} |