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

Side by Side Diff: pkg/kernel/lib/transformations/reify/transformation/remove_generics.dart

Issue 2713163002: Pass type arguments as a list in generic methods invocations (Closed)
Patch Set: Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library kernel.transformations.reify.transformation.remove_generics; 5 library kernel.transformations.reify.transformation.remove_generics;
6 6
7 import 'package:kernel/ast.dart'; 7 import 'package:kernel/ast.dart';
8 import 'transformer.dart'; 8 import 'transformer.dart';
9 9
10 class Erasure extends Transformer with DartTypeVisitor<DartType> { 10 class Erasure extends Transformer with DartTypeVisitor<DartType> {
11 final ReifyVisitor reifyVisitor; 11 final ReifyVisitor reifyVisitor;
12 12
13 Erasure(this.reifyVisitor); 13 Erasure(this.reifyVisitor);
14 14
15 bool removeTypeParameters(Class cls) { 15 bool removeTypeParameters(Class cls) {
16 return reifyVisitor.needsTypeInformation(cls); 16 return reifyVisitor.needsTypeInformation(cls);
17 } 17 }
18 18
19 TreeNode removeTypeArgumentsOfConstructorCall(ConstructorInvocation node) { 19 TreeNode removeTypeArgumentsOfConstructorCall(ConstructorInvocation node) {
20 Class cls = node.target.parent; 20 Class cls = node.target.parent;
21 if (removeTypeParameters(cls)) { 21 if (removeTypeParameters(cls)) {
22 node.arguments.types.clear(); 22 node.arguments.types.clear();
23 Constructor target = node.target; 23 Constructor target = node.target;
24 target.enclosingClass.typeParameters.clear(); 24 target.enclosingClass.typeParameters.clear();
25 } 25 }
26 return node; 26 return node;
27 } 27 }
28 28
29 TreeNode removeTypeArgumentsOfStaticCall(StaticInvocation node) { 29 TreeNode removeTypeArgumentsOfStaticCall(StaticInvocation node) {
30 Class cls = node.target.parent; 30 if (node.target.parent is Class) {
31 if (removeTypeParameters(cls)) { 31 Class cls = node.target.parent;
32 node.arguments.types.clear(); 32 if (!removeTypeParameters(cls)) {
33 Procedure target = node.target; 33 return node;
34 target.function.typeParameters.clear(); 34 }
35 } else {
36 // If parent is a Library, then a global procedure is invoked, and it may
37 // be a generic function, so we need to remove type arguments anyway.
38 assert(node.target.parent is Library);
35 } 39 }
40 node.arguments.types.clear();
41 Procedure target = node.target;
42 target.function.typeParameters.clear();
36 return node; 43 return node;
37 } 44 }
38 45
46 TreeNode removeTypeArgumentOfMethodInvocation(MethodInvocation node) {
47 node.arguments.types.clear();
48 // Procedure target = node.interfaceTarget;
karlklose 2017/02/24 12:07:23 Why is this commented out?
Dmitry Stefantsov 2017/02/28 11:32:15 I should have removed that. The idea is actually t
49 // target.function.typeParameters.clear();
50 return node;
51 }
52
39 @override 53 @override
40 defaultDartType(DartType type) => type; 54 defaultDartType(DartType type) => type;
41 55
42 @override 56 @override
43 InterfaceType visitInterfaceType(InterfaceType type) { 57 InterfaceType visitInterfaceType(InterfaceType type) {
44 if (removeTypeParameters(type.classNode)) { 58 if (removeTypeParameters(type.classNode)) {
45 return new InterfaceType(type.classNode, const <DartType>[]); 59 return new InterfaceType(type.classNode, const <DartType>[]);
46 } 60 }
47 return type; 61 return type;
48 } 62 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 DynamicType visitTypeParameterType(_) => const DynamicType(); 103 DynamicType visitTypeParameterType(_) => const DynamicType();
90 104
91 @override 105 @override
92 DartType visitDartType(DartType type) { 106 DartType visitDartType(DartType type) {
93 return type.accept(this); 107 return type.accept(this);
94 } 108 }
95 109
96 @override 110 @override
97 StaticInvocation visitStaticInvocation(StaticInvocation node) { 111 StaticInvocation visitStaticInvocation(StaticInvocation node) {
98 node.transformChildren(this); 112 node.transformChildren(this);
99 if (node.target.kind == ProcedureKind.Factory) { 113 if (node.target.kind == ProcedureKind.Factory ||
114 node.target.kind == ProcedureKind.Method) {
100 node = removeTypeArgumentsOfStaticCall(node); 115 node = removeTypeArgumentsOfStaticCall(node);
101 } 116 }
102 return node; 117 return node;
103 } 118 }
104 119
105 @override 120 @override
106 ConstructorInvocation visitConstructorInvocation(ConstructorInvocation node) { 121 ConstructorInvocation visitConstructorInvocation(ConstructorInvocation node) {
107 node.transformChildren(this); 122 node.transformChildren(this);
108 return removeTypeArgumentsOfConstructorCall(node); 123 return removeTypeArgumentsOfConstructorCall(node);
109 } 124 }
110 125
111 @override 126 @override
112 Class visitClass(Class node) { 127 Class visitClass(Class node) {
113 node.transformChildren(this); 128 node.transformChildren(this);
114 if (removeTypeParameters(node)) { 129 if (removeTypeParameters(node)) {
115 node.typeParameters.clear(); 130 node.typeParameters.clear();
116 } 131 }
117 return node; 132 return node;
118 } 133 }
134
135 @override
136 Expression visitMethodInvocation(MethodInvocation node) {
137 node.transformChildren(this);
138 return removeTypeArgumentOfMethodInvocation(node);
139 }
119 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698