OLD | NEW |
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 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../compiler.dart'; | 8 import '../compiler.dart'; |
9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } | 188 } |
189 for (ir.NamedExpression argument in arguments.named) { | 189 for (ir.NamedExpression argument in arguments.named) { |
190 argument.value.accept(this); | 190 argument.value.accept(this); |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 @override | 194 @override |
195 void visitStaticInvocation(ir.StaticInvocation invocation) { | 195 void visitStaticInvocation(ir.StaticInvocation invocation) { |
196 _visitArguments(invocation.arguments); | 196 _visitArguments(invocation.arguments); |
197 Element target = astAdapter.getElement(invocation.target).declaration; | 197 Element target = astAdapter.getElement(invocation.target).declaration; |
198 impactBuilder.registerStaticUse(new StaticUse.staticInvoke( | 198 if (target.isFactoryConstructor) { |
199 target, astAdapter.getCallStructure(invocation.arguments))); | 199 impactBuilder.registerStaticUse(new StaticUse.constructorInvoke( |
| 200 target, astAdapter.getCallStructure(invocation.arguments))); |
| 201 // TODO(johnniwinther): We should not mark the type as instantiated but |
| 202 // rather follow the type arguments directly. |
| 203 // |
| 204 // Consider this: |
| 205 // |
| 206 // abstract class A<T> { |
| 207 // factory A.regular() => new B<T>(); |
| 208 // factory A.redirect() = B<T>; |
| 209 // } |
| 210 // |
| 211 // class B<T> implements A<T> {} |
| 212 // |
| 213 // main() { |
| 214 // print(new A<int>.regular() is B<int>); |
| 215 // print(new A<String>.redirect() is B<String>); |
| 216 // } |
| 217 // |
| 218 // To track that B is actually instantiated as B<int> and B<String> we |
| 219 // need to follow the type arguments passed to A.regular and A.redirect |
| 220 // to B. Currently, we only do this soundly if we register A<int> and |
| 221 // A<String> as instantiated. We should instead register that A.T is |
| 222 // instantiated as int and String. |
| 223 ClassElement cls = |
| 224 astAdapter.getElement(invocation.target.enclosingClass); |
| 225 List<DartType> typeArguments = |
| 226 astAdapter.getDartTypes(invocation.arguments.types); |
| 227 impactBuilder.registerTypeUse( |
| 228 new TypeUse.instantiation(new InterfaceType(cls, typeArguments))); |
| 229 if (typeArguments.any((DartType type) => !type.isDynamic)) { |
| 230 impactBuilder.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); |
| 231 } |
| 232 } else { |
| 233 impactBuilder.registerStaticUse(new StaticUse.staticInvoke( |
| 234 target, astAdapter.getCallStructure(invocation.arguments))); |
| 235 } |
200 } | 236 } |
201 | 237 |
202 @override | 238 @override |
203 void visitStaticGet(ir.StaticGet node) { | 239 void visitStaticGet(ir.StaticGet node) { |
204 Element target = astAdapter.getElement(node.target).declaration; | 240 Element target = astAdapter.getElement(node.target).declaration; |
205 impactBuilder.registerStaticUse(new StaticUse.staticGet(target)); | 241 impactBuilder.registerStaticUse(new StaticUse.staticGet(target)); |
206 } | 242 } |
207 | 243 |
208 @override | 244 @override |
209 void visitMethodInvocation(ir.MethodInvocation invocation) { | 245 void visitMethodInvocation(ir.MethodInvocation invocation) { |
(...skipping 26 matching lines...) Expand all Loading... |
236 @override | 272 @override |
237 void visitAssertStatement(ir.AssertStatement node) { | 273 void visitAssertStatement(ir.AssertStatement node) { |
238 impactBuilder.registerFeature( | 274 impactBuilder.registerFeature( |
239 node.message != null ? Feature.ASSERT_WITH_MESSAGE : Feature.ASSERT); | 275 node.message != null ? Feature.ASSERT_WITH_MESSAGE : Feature.ASSERT); |
240 node.visitChildren(this); | 276 node.visitChildren(this); |
241 } | 277 } |
242 | 278 |
243 @override | 279 @override |
244 void defaultNode(ir.Node node) => node.visitChildren(this); | 280 void defaultNode(ir.Node node) => node.visitChildren(this); |
245 } | 281 } |
OLD | NEW |