| 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 '../common/names.dart'; | 8 import '../common/names.dart'; |
| 9 import '../compiler.dart'; | 9 import '../compiler.dart'; |
| 10 import '../constants/expressions.dart'; | 10 import '../constants/expressions.dart'; |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 249 } |
| 250 | 250 |
| 251 @override | 251 @override |
| 252 void visitConstructorInvocation(ir.ConstructorInvocation node) { | 252 void visitConstructorInvocation(ir.ConstructorInvocation node) { |
| 253 handleNew(node, node.target, isConst: node.isConst); | 253 handleNew(node, node.target, isConst: node.isConst); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void handleNew(ir.InvocationExpression node, ir.Member target, | 256 void handleNew(ir.InvocationExpression node, ir.Member target, |
| 257 {bool isConst: false}) { | 257 {bool isConst: false}) { |
| 258 _visitArguments(node.arguments); | 258 _visitArguments(node.arguments); |
| 259 Element element = astAdapter.getElement(target).declaration; | 259 ConstructorElement constructor = astAdapter.getConstructor(target); |
| 260 ClassElement cls = astAdapter.getElement(target.enclosingClass); | 260 ClassElement cls = astAdapter.getClass(target.enclosingClass); |
| 261 List<ResolutionDartType> typeArguments = | 261 List<ResolutionDartType> typeArguments = |
| 262 astAdapter.getDartTypes(node.arguments.types); | 262 astAdapter.getDartTypes(node.arguments.types); |
| 263 ResolutionInterfaceType type = | 263 ResolutionInterfaceType type = |
| 264 new ResolutionInterfaceType(cls, typeArguments); | 264 new ResolutionInterfaceType(cls, typeArguments); |
| 265 CallStructure callStructure = astAdapter.getCallStructure(node.arguments); | 265 CallStructure callStructure = astAdapter.getCallStructure(node.arguments); |
| 266 impactBuilder.registerStaticUse(isConst | 266 impactBuilder.registerStaticUse(isConst |
| 267 ? new StaticUse.constConstructorInvoke(element, callStructure, type) | 267 ? new StaticUse.constConstructorInvoke(constructor, callStructure, type) |
| 268 : new StaticUse.typedConstructorInvoke(element, callStructure, type)); | 268 : new StaticUse.typedConstructorInvoke( |
| 269 constructor, callStructure, type)); |
| 269 if (typeArguments.any((ResolutionDartType type) => !type.isDynamic)) { | 270 if (typeArguments.any((ResolutionDartType type) => !type.isDynamic)) { |
| 270 impactBuilder.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); | 271 impactBuilder.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); |
| 271 } | 272 } |
| 272 } | 273 } |
| 273 | 274 |
| 274 @override | 275 @override |
| 275 void visitSuperInitializer(ir.SuperInitializer node) { | 276 void visitSuperInitializer(ir.SuperInitializer node) { |
| 276 Element target = astAdapter.getElement(node.target).declaration; | 277 ConstructorElement target = astAdapter.getConstructor(node.target); |
| 277 _visitArguments(node.arguments); | 278 _visitArguments(node.arguments); |
| 278 impactBuilder.registerStaticUse(new StaticUse.superConstructorInvoke( | 279 impactBuilder.registerStaticUse(new StaticUse.superConstructorInvoke( |
| 279 target, astAdapter.getCallStructure(node.arguments))); | 280 target, astAdapter.getCallStructure(node.arguments))); |
| 280 } | 281 } |
| 281 | 282 |
| 282 @override | 283 @override |
| 283 void visitStaticInvocation(ir.StaticInvocation node) { | 284 void visitStaticInvocation(ir.StaticInvocation node) { |
| 284 Element target = astAdapter.getElement(node.target).declaration; | 285 MethodElement target = astAdapter.getMethod(node.target); |
| 285 if (target.isFactoryConstructor) { | 286 if (target.isFactoryConstructor) { |
| 286 // TODO(johnniwinther): We should not mark the type as instantiated but | 287 // TODO(johnniwinther): We should not mark the type as instantiated but |
| 287 // rather follow the type arguments directly. | 288 // rather follow the type arguments directly. |
| 288 // | 289 // |
| 289 // Consider this: | 290 // Consider this: |
| 290 // | 291 // |
| 291 // abstract class A<T> { | 292 // abstract class A<T> { |
| 292 // factory A.regular() => new B<T>(); | 293 // factory A.regular() => new B<T>(); |
| 293 // factory A.redirect() = B<T>; | 294 // factory A.redirect() = B<T>; |
| 294 // } | 295 // } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 338 } |
| 338 break; | 339 break; |
| 339 case ForeignKind.NONE: | 340 case ForeignKind.NONE: |
| 340 break; | 341 break; |
| 341 } | 342 } |
| 342 } | 343 } |
| 343 | 344 |
| 344 @override | 345 @override |
| 345 void visitStaticGet(ir.StaticGet node) { | 346 void visitStaticGet(ir.StaticGet node) { |
| 346 ir.Member target = node.target; | 347 ir.Member target = node.target; |
| 347 Element element = astAdapter.getElement(target).declaration; | |
| 348 if (target is ir.Procedure && target.kind == ir.ProcedureKind.Method) { | 348 if (target is ir.Procedure && target.kind == ir.ProcedureKind.Method) { |
| 349 impactBuilder.registerStaticUse(new StaticUse.staticTearOff(element)); | 349 MethodElement method = astAdapter.getMethod(target); |
| 350 impactBuilder.registerStaticUse(new StaticUse.staticTearOff(method)); |
| 350 } else { | 351 } else { |
| 351 impactBuilder.registerStaticUse(new StaticUse.staticGet(element)); | 352 MemberElement member = astAdapter.getMember(target); |
| 353 impactBuilder.registerStaticUse(new StaticUse.staticGet(member)); |
| 352 } | 354 } |
| 353 } | 355 } |
| 354 | 356 |
| 355 @override | 357 @override |
| 356 void visitStaticSet(ir.StaticSet node) { | 358 void visitStaticSet(ir.StaticSet node) { |
| 357 visitNode(node.value); | 359 visitNode(node.value); |
| 358 Element element = astAdapter.getElement(node.target).declaration; | 360 MemberElement member = astAdapter.getMember(node.target); |
| 359 impactBuilder.registerStaticUse(new StaticUse.staticSet(element)); | 361 impactBuilder.registerStaticUse(new StaticUse.staticSet(member)); |
| 360 } | 362 } |
| 361 | 363 |
| 362 void handleSuperInvocation(ir.Node target, ir.Node arguments) { | 364 void handleSuperInvocation(ir.Node target, ir.Node arguments) { |
| 363 Element element = astAdapter.getElement(target).declaration; | 365 MethodElement method = astAdapter.getMethod(target); |
| 364 _visitArguments(arguments); | 366 _visitArguments(arguments); |
| 365 impactBuilder.registerStaticUse(new StaticUse.superInvoke( | 367 impactBuilder.registerStaticUse(new StaticUse.superInvoke( |
| 366 element, astAdapter.getCallStructure(arguments))); | 368 method, astAdapter.getCallStructure(arguments))); |
| 367 } | 369 } |
| 368 | 370 |
| 369 @override | 371 @override |
| 370 void visitDirectMethodInvocation(ir.DirectMethodInvocation node) { | 372 void visitDirectMethodInvocation(ir.DirectMethodInvocation node) { |
| 371 handleSuperInvocation(node.target, node.arguments); | 373 handleSuperInvocation(node.target, node.arguments); |
| 372 } | 374 } |
| 373 | 375 |
| 374 @override | 376 @override |
| 375 void visitSuperMethodInvocation(ir.SuperMethodInvocation node) { | 377 void visitSuperMethodInvocation(ir.SuperMethodInvocation node) { |
| 376 // TODO(johnniwinther): Should we support this or always use the | 378 // TODO(johnniwinther): Should we support this or always use the |
| 377 // [MixinFullResolution] transformer? | 379 // [MixinFullResolution] transformer? |
| 378 handleSuperInvocation(node.interfaceTarget, node.arguments); | 380 handleSuperInvocation(node.interfaceTarget, node.arguments); |
| 379 } | 381 } |
| 380 | 382 |
| 381 void handleSuperGet(ir.Member target) { | 383 void handleSuperGet(ir.Member target) { |
| 382 Element element = astAdapter.getElement(target).declaration; | |
| 383 if (target is ir.Procedure && target.kind == ir.ProcedureKind.Method) { | 384 if (target is ir.Procedure && target.kind == ir.ProcedureKind.Method) { |
| 384 impactBuilder.registerStaticUse(new StaticUse.superTearOff(element)); | 385 MethodElement method = astAdapter.getMethod(target); |
| 386 impactBuilder.registerStaticUse(new StaticUse.superTearOff(method)); |
| 385 } else { | 387 } else { |
| 386 impactBuilder.registerStaticUse(new StaticUse.superGet(element)); | 388 MemberElement member = astAdapter.getMember(target); |
| 389 impactBuilder.registerStaticUse(new StaticUse.superGet(member)); |
| 387 } | 390 } |
| 388 } | 391 } |
| 389 | 392 |
| 390 @override | 393 @override |
| 391 void visitDirectGet(ir.StaticGet node) { | 394 void visitDirectGet(ir.StaticGet node) { |
| 392 handleSuperGet(node.target); | 395 handleSuperGet(node.target); |
| 393 } | 396 } |
| 394 | 397 |
| 395 @override | 398 @override |
| 396 void visitSuperPropertyGet(ir.SuperPropertyGet node) { | 399 void visitSuperPropertyGet(ir.SuperPropertyGet node) { |
| 397 handleSuperGet(node.interfaceTarget); | 400 handleSuperGet(node.interfaceTarget); |
| 398 } | 401 } |
| 399 | 402 |
| 400 void handleSuperSet(ir.Node target, ir.Node value) { | 403 void handleSuperSet(ir.Node target, ir.Node value) { |
| 401 visitNode(value); | 404 visitNode(value); |
| 402 Element element = astAdapter.getElement(target).declaration; | |
| 403 if (target is ir.Field) { | 405 if (target is ir.Field) { |
| 404 impactBuilder.registerStaticUse(new StaticUse.superFieldSet(element)); | 406 FieldElement field = astAdapter.getField(target); |
| 407 impactBuilder.registerStaticUse(new StaticUse.superFieldSet(field)); |
| 405 } else { | 408 } else { |
| 406 impactBuilder.registerStaticUse(new StaticUse.superSetterSet(element)); | 409 MethodElement method = astAdapter.getMethod(target); |
| 410 impactBuilder.registerStaticUse(new StaticUse.superSetterSet(method)); |
| 407 } | 411 } |
| 408 } | 412 } |
| 409 | 413 |
| 410 @override | 414 @override |
| 411 void visitDirectPropertySet(ir.DirectPropertySet node) { | 415 void visitDirectPropertySet(ir.DirectPropertySet node) { |
| 412 handleSuperSet(node.target, node.value); | 416 handleSuperSet(node.target, node.value); |
| 413 } | 417 } |
| 414 | 418 |
| 415 @override | 419 @override |
| 416 void visitSuperPropertySet(ir.SuperPropertySet node) { | 420 void visitSuperPropertySet(ir.SuperPropertySet node) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 555 |
| 552 @override | 556 @override |
| 553 void visitTypeLiteral(ir.TypeLiteral node) { | 557 void visitTypeLiteral(ir.TypeLiteral node) { |
| 554 impactBuilder.registerTypeUse( | 558 impactBuilder.registerTypeUse( |
| 555 new TypeUse.typeLiteral(astAdapter.getDartType(node.type))); | 559 new TypeUse.typeLiteral(astAdapter.getDartType(node.type))); |
| 556 } | 560 } |
| 557 | 561 |
| 558 @override | 562 @override |
| 559 void visitFieldInitializer(ir.FieldInitializer node) { | 563 void visitFieldInitializer(ir.FieldInitializer node) { |
| 560 impactBuilder.registerStaticUse( | 564 impactBuilder.registerStaticUse( |
| 561 new StaticUse.fieldInit(astAdapter.getElement(node.field))); | 565 new StaticUse.fieldInit(astAdapter.getField(node.field))); |
| 562 visitNode(node.value); | 566 visitNode(node.value); |
| 563 } | 567 } |
| 564 | 568 |
| 565 @override | 569 @override |
| 566 void visitRedirectingInitializer(ir.RedirectingInitializer node) { | 570 void visitRedirectingInitializer(ir.RedirectingInitializer node) { |
| 567 _visitArguments(node.arguments); | 571 _visitArguments(node.arguments); |
| 568 Element target = astAdapter.getElement(node.target).declaration; | 572 Element target = astAdapter.getElement(node.target).declaration; |
| 569 impactBuilder.registerStaticUse(new StaticUse.superConstructorInvoke( | 573 impactBuilder.registerStaticUse(new StaticUse.superConstructorInvoke( |
| 570 target, astAdapter.getCallStructure(node.arguments))); | 574 target, astAdapter.getCallStructure(node.arguments))); |
| 571 } | 575 } |
| 572 | 576 |
| 573 // TODO(johnniwinther): Make this throw and visit child nodes explicitly | 577 // TODO(johnniwinther): Make this throw and visit child nodes explicitly |
| 574 // instead to ensure that we don't visit unwanted parts of the ir. | 578 // instead to ensure that we don't visit unwanted parts of the ir. |
| 575 @override | 579 @override |
| 576 void defaultNode(ir.Node node) => node.visitChildren(this); | 580 void defaultNode(ir.Node node) => node.visitChildren(this); |
| 577 } | 581 } |
| OLD | NEW |