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

Unified Diff: pkg/kernel/lib/transformations/reify/transformation/transformer.dart

Issue 2713163002: Pass type arguments as a list in generic methods invocations (Closed)
Patch Set: Created 3 years, 10 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
Index: pkg/kernel/lib/transformations/reify/transformation/transformer.dart
diff --git a/pkg/kernel/lib/transformations/reify/transformation/transformer.dart b/pkg/kernel/lib/transformations/reify/transformation/transformer.dart
index 867248510fc833bc62779501b704cf075f34d517..43e8f3db2ba07edc9a7935da5a54a733bda89d67 100644
--- a/pkg/kernel/lib/transformations/reify/transformation/transformer.dart
+++ b/pkg/kernel/lib/transformations/reify/transformation/transformer.dart
@@ -103,6 +103,8 @@ class ReifyVisitor extends Transformer with DebugTrace {
// TODO(karlklose): find a way to get rid of this state in the visitor.
TransformationContext context;
+ String get genericMethodTypeParametersName => "\$typeParameters";
karlklose 2017/02/24 12:07:23 This could also be a constant.
Dmitry Stefantsov 2017/02/28 11:32:15 Done.
+
bool libraryShouldBeTransformed(Library library) {
return libraryToTransform == null || libraryToTransform == library;
}
@@ -180,6 +182,9 @@ class ReifyVisitor extends Transformer with DebugTrace {
// Intercept calls to factories of classes we do not transform
return interceptInstantiation(invocation, target);
}
+
+ addTypeArgumentToGenericInvocation(invocation);
+
return invocation;
}
@@ -419,6 +424,8 @@ class ReifyVisitor extends Transformer with DebugTrace {
FunctionNode visitFunctionNode(FunctionNode node) {
trace(node);
+ addTypeArgumentToGenericDeclaration(node);
+
// If we have a [TransformationContext] with a runtime type field and we
// translate a constructor or factory, we need a parameter that the code of
// initializers or the factory body can use to access type arguments.
@@ -572,4 +579,30 @@ class ReifyVisitor extends Transformer with DebugTrace {
new InterfaceType(builder.coreTypes.mapClass,
<DartType>[node.keyType, node.valueType]));
}
+
+ Expression visitMethodInvocation(MethodInvocation node) {
+ node.transformChildren(this);
+ addTypeArgumentToGenericInvocation(node);
+ return node;
+ }
+
+ void addTypeArgumentToGenericInvocation(InvocationExpression expression) {
+ if (expression.arguments.types.length > 0) {
+ ListLiteral genericMethodTypeParameters = new ListLiteral(new List.from(
karlklose 2017/02/24 12:07:23 You could also call '.toList(growable: false)' on
Dmitry Stefantsov 2017/02/28 11:32:15 Done.
+ expression.arguments.types
+ .map((DartType type) => createRuntimeType(type))),
karlklose 2017/02/24 12:07:23 How about .map(createRuntimeType) ?
Dmitry Stefantsov 2017/02/28 11:32:15 Sure! :)
+ typeArgument: rtiLibrary.typeType);
+ expression.arguments.named.add(new NamedExpression(
+ genericMethodTypeParametersName, genericMethodTypeParameters)..parent = expression.arguments);
karlklose 2017/02/24 12:07:23 Long line, break before '..'. You could also run d
Dmitry Stefantsov 2017/02/28 11:32:15 Done.
+ }
+ }
+
+ void addTypeArgumentToGenericDeclaration(FunctionNode node) {
+ VariableDeclaration genericMethodTypeParameters = new VariableDeclaration(
+ genericMethodTypeParametersName,
+ type: new InterfaceType(
karlklose 2017/02/24 12:07:23 Not sure we need this type, but feel free to keep
Dmitry Stefantsov 2017/02/28 11:32:15 OK
+ builder.coreTypes.listClass, <DartType>[rtiLibrary.typeType]));
+ genericMethodTypeParameters.parent = node;
+ node.namedParameters.insert(0, genericMethodTypeParameters);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698