| 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 library fasta.fasta_accessors; | 5 library fasta.fasta_accessors; |
| 6 | 6 |
| 7 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' | 7 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' |
| 8 show KernelArguments, KernelMethodInvocation; | 8 show KernelArguments; |
| 9 | 9 |
| 10 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; | 10 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; |
| 11 | 11 |
| 12 import 'package:front_end/src/scanner/token.dart' show Token; | 12 import 'package:front_end/src/scanner/token.dart' show Token; |
| 13 | 13 |
| 14 import 'frontend_accessors.dart' show Accessor, buildIsNull, makeLet; | 14 import 'frontend_accessors.dart' show Accessor; |
| 15 | 15 |
| 16 import 'package:front_end/src/fasta/type_inference/type_promotion.dart' | 16 import 'package:front_end/src/fasta/type_inference/type_promotion.dart' |
| 17 show TypePromoter; | 17 show TypePromoter; |
| 18 | 18 |
| 19 import 'package:kernel/ast.dart'; | 19 import 'package:kernel/ast.dart' |
| 20 hide InvalidExpression, InvalidInitializer, InvalidStatement; |
| 20 | 21 |
| 21 import '../errors.dart' show internalError; | 22 import '../errors.dart' show internalError; |
| 22 | 23 |
| 23 import '../scope.dart' show AccessErrorBuilder, ProblemBuilder, Scope; | 24 import '../scope.dart' show AccessErrorBuilder, ProblemBuilder, Scope; |
| 24 | 25 |
| 25 import 'frontend_accessors.dart' as kernel | 26 import 'frontend_accessors.dart' as kernel |
| 26 show | 27 show |
| 27 IndexAccessor, | 28 IndexAccessor, |
| 28 NullAwarePropertyAccessor, | 29 NullAwarePropertyAccessor, |
| 29 PropertyAccessor, | 30 PropertyAccessor, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 48 int get functionNestingLevel; | 49 int get functionNestingLevel; |
| 49 | 50 |
| 50 bool get constantExpressionRequired; | 51 bool get constantExpressionRequired; |
| 51 | 52 |
| 52 Constructor lookupConstructor(Name name, {bool isSuper}); | 53 Constructor lookupConstructor(Name name, {bool isSuper}); |
| 53 | 54 |
| 54 Expression toSuperMethodInvocation(MethodInvocation node); | 55 Expression toSuperMethodInvocation(MethodInvocation node); |
| 55 | 56 |
| 56 Expression toValue(node); | 57 Expression toValue(node); |
| 57 | 58 |
| 58 Member lookupSuperMember(Name name, {bool isSetter: false}); | 59 Member lookupSuperMember(Name name, {bool isSetter}); |
| 59 | 60 |
| 60 scopeLookup(Scope scope, String name, Token token, | 61 scopeLookup(Scope scope, String name, Token token, |
| 61 {bool isQualified: false, PrefixBuilder prefix}); | 62 {bool isQualified: false, PrefixBuilder prefix}); |
| 62 | 63 |
| 63 finishSend(Object receiver, Arguments arguments, int offset); | 64 finishSend(Object receiver, Arguments arguments, int offset); |
| 64 | 65 |
| 65 Expression buildCompileTimeError(error, [int offset]); | 66 Expression buildCompileTimeError(error, [int offset]); |
| 66 | 67 |
| 67 Initializer buildInvalidIntializer(Expression expression, [int offset]); | 68 Initializer buildInvalidIntializer(Expression expression, [int offset]); |
| 68 | 69 |
| 69 Initializer buildSuperInitializer( | 70 Initializer buildSuperInitializer( |
| 70 Constructor constructor, Arguments arguments, | 71 Constructor constructor, Arguments arguments, |
| 71 [int offset]); | 72 [int offset]); |
| 72 | 73 |
| 73 Initializer buildRedirectingInitializer( | 74 Initializer buildRedirectingInitializer( |
| 74 Constructor constructor, Arguments arguments, | 75 Constructor constructor, Arguments arguments, |
| 75 [int charOffset = -1]); | 76 [int charOffset = -1]); |
| 76 | 77 |
| 77 Expression buildStaticInvocation(Procedure target, Arguments arguments); | 78 Expression buildStaticInvocation(Procedure target, Arguments arguments); |
| 78 | 79 |
| 79 Expression buildProblemExpression(ProblemBuilder builder, int offset); | 80 Expression buildProblemExpression(ProblemBuilder builder, int offset); |
| 80 | 81 |
| 81 Expression throwNoSuchMethodError( | 82 Expression throwNoSuchMethodError( |
| 82 String name, Arguments arguments, int offset, | 83 String name, Arguments arguments, int offset, |
| 83 {bool isSuper: false, isGetter: false, isSetter: false}); | 84 {bool isSuper, bool isGetter, bool isSetter}); |
| 84 | 85 |
| 85 bool checkArguments(FunctionNode function, Arguments arguments, | 86 bool checkArguments(FunctionNode function, Arguments arguments, |
| 86 List<TypeParameter> typeParameters); | 87 List<TypeParameter> typeParameters); |
| 87 | 88 |
| 88 StaticGet makeStaticGet(Member readTarget, Token token); | 89 StaticGet makeStaticGet(Member readTarget, Token token); |
| 89 | 90 |
| 90 dynamic addCompileTimeError(int charOffset, String message, | 91 dynamic addCompileTimeError(int charOffset, String message, {bool silent}); |
| 91 {bool silent: false}); | 92 |
| 93 Expression buildMethodInvocation( |
| 94 Expression receiver, Name name, Arguments arguments, int offset, |
| 95 {bool isConstantExpression, bool isNullAware}); |
| 92 } | 96 } |
| 93 | 97 |
| 94 abstract class FastaAccessor implements Accessor { | 98 abstract class FastaAccessor implements Accessor { |
| 95 BuilderHelper get helper; | 99 BuilderHelper get helper; |
| 96 | 100 |
| 97 String get plainNameForRead; | 101 String get plainNameForRead; |
| 98 | 102 |
| 99 Uri get uri => helper.uri; | 103 Uri get uri => helper.uri; |
| 100 | 104 |
| 101 String get plainNameForWrite => plainNameForRead; | 105 String get plainNameForWrite => plainNameForRead; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 123 return buildThrowNoSuchMethodError(new KernelArguments(<Expression>[value]), | 127 return buildThrowNoSuchMethodError(new KernelArguments(<Expression>[value]), |
| 124 isSetter: true); | 128 isSetter: true); |
| 125 } | 129 } |
| 126 | 130 |
| 127 /* Expression | FastaAccessor | Initializer */ doInvocation( | 131 /* Expression | FastaAccessor | Initializer */ doInvocation( |
| 128 int offset, Arguments arguments); | 132 int offset, Arguments arguments); |
| 129 | 133 |
| 130 /* Expression | FastaAccessor */ buildPropertyAccess( | 134 /* Expression | FastaAccessor */ buildPropertyAccess( |
| 131 IncompleteSend send, bool isNullAware) { | 135 IncompleteSend send, bool isNullAware) { |
| 132 if (send is SendAccessor) { | 136 if (send is SendAccessor) { |
| 133 return buildMethodInvocation(buildSimpleRead(), send.name, send.arguments, | 137 return helper.buildMethodInvocation(buildSimpleRead(), send.name, |
| 134 offsetForToken(send.token), | 138 send.arguments, offsetForToken(send.token), |
| 135 isNullAware: isNullAware); | 139 isNullAware: isNullAware); |
| 136 } else { | 140 } else { |
| 137 return PropertyAccessor.make(helper, send.token, buildSimpleRead(), | 141 return PropertyAccessor.make(helper, send.token, buildSimpleRead(), |
| 138 send.name, null, null, isNullAware); | 142 send.name, null, null, isNullAware); |
| 139 } | 143 } |
| 140 } | 144 } |
| 141 | 145 |
| 142 /* Expression | FastaAccessor */ buildThrowNoSuchMethodError( | 146 /* Expression | FastaAccessor */ buildThrowNoSuchMethodError( |
| 143 Arguments arguments, | 147 Arguments arguments, |
| 144 {bool isSuper: false, | 148 {bool isSuper: false, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 } | 282 } |
| 279 | 283 |
| 280 buildPropertyAccess(IncompleteSend send, bool isNullAware) { | 284 buildPropertyAccess(IncompleteSend send, bool isNullAware) { |
| 281 if (isInitializer && send is SendAccessor) { | 285 if (isInitializer && send is SendAccessor) { |
| 282 return buildConstructorInitializer( | 286 return buildConstructorInitializer( |
| 283 offsetForToken(send.token), send.name, send.arguments); | 287 offsetForToken(send.token), send.name, send.arguments); |
| 284 } | 288 } |
| 285 if (send is SendAccessor) { | 289 if (send is SendAccessor) { |
| 286 // Notice that 'this' or 'super' can't be null. So we can ignore the | 290 // Notice that 'this' or 'super' can't be null. So we can ignore the |
| 287 // value of [isNullAware]. | 291 // value of [isNullAware]. |
| 288 MethodInvocation result = buildMethodInvocation(new ThisExpression(), | 292 MethodInvocation result = helper.buildMethodInvocation( |
| 289 send.name, send.arguments, offsetForToken(token)); | 293 new ThisExpression(), |
| 294 send.name, |
| 295 send.arguments, |
| 296 offsetForToken(token)); |
| 290 return isSuper ? helper.toSuperMethodInvocation(result) : result; | 297 return isSuper ? helper.toSuperMethodInvocation(result) : result; |
| 291 } else { | 298 } else { |
| 292 if (isSuper) { | 299 if (isSuper) { |
| 293 Member getter = helper.lookupSuperMember(send.name); | 300 Member getter = helper.lookupSuperMember(send.name); |
| 294 Member setter = helper.lookupSuperMember(send.name, isSetter: true); | 301 Member setter = helper.lookupSuperMember(send.name, isSetter: true); |
| 295 return new SuperPropertyAccessor( | 302 return new SuperPropertyAccessor( |
| 296 helper, send.token, send.name, getter, setter); | 303 helper, send.token, send.name, getter, setter); |
| 297 } else { | 304 } else { |
| 298 return new ThisPropertyAccessor( | 305 return new ThisPropertyAccessor( |
| 299 helper, send.token, send.name, null, null); | 306 helper, send.token, send.name, null, null); |
| 300 } | 307 } |
| 301 } | 308 } |
| 302 } | 309 } |
| 303 | 310 |
| 304 doInvocation(int offset, Arguments arguments) { | 311 doInvocation(int offset, Arguments arguments) { |
| 305 if (isInitializer) { | 312 if (isInitializer) { |
| 306 return buildConstructorInitializer(offset, new Name(""), arguments); | 313 return buildConstructorInitializer(offset, new Name(""), arguments); |
| 307 } else { | 314 } else { |
| 308 return buildMethodInvocation( | 315 return helper.buildMethodInvocation( |
| 309 new ThisExpression(), callName, arguments, offset); | 316 new ThisExpression(), callName, arguments, offset); |
| 310 } | 317 } |
| 311 } | 318 } |
| 312 | 319 |
| 313 Initializer buildConstructorInitializer( | 320 Initializer buildConstructorInitializer( |
| 314 int offset, Name name, Arguments arguments) { | 321 int offset, Name name, Arguments arguments) { |
| 315 Constructor constructor = helper.lookupConstructor(name, isSuper: isSuper); | 322 Constructor constructor = helper.lookupConstructor(name, isSuper: isSuper); |
| 316 if (constructor == null || | 323 if (constructor == null || |
| 317 !helper.checkArguments( | 324 !helper.checkArguments( |
| 318 constructor.function, arguments, <TypeParameter>[])) { | 325 constructor.function, arguments, <TypeParameter>[])) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 receiver.findStaticBuilder(name.name, offsetForToken(token), uri); | 445 receiver.findStaticBuilder(name.name, offsetForToken(token), uri); |
| 439 if (builder == null || builder is AccessErrorBuilder) { | 446 if (builder == null || builder is AccessErrorBuilder) { |
| 440 return buildThrowNoSuchMethodError(arguments); | 447 return buildThrowNoSuchMethodError(arguments); |
| 441 } | 448 } |
| 442 if (builder.hasProblem) { | 449 if (builder.hasProblem) { |
| 443 result = helper.buildProblemExpression(builder, offsetForToken(token)); | 450 result = helper.buildProblemExpression(builder, offsetForToken(token)); |
| 444 } else { | 451 } else { |
| 445 Member target = builder.target; | 452 Member target = builder.target; |
| 446 if (target != null) { | 453 if (target != null) { |
| 447 if (target is Field) { | 454 if (target is Field) { |
| 448 result = buildMethodInvocation( | 455 result = helper.buildMethodInvocation( |
| 449 new StaticGet(target), | 456 new StaticGet(target), |
| 450 callName, | 457 callName, |
| 451 arguments, | 458 arguments, |
| 452 offsetForToken(token) + (target.name?.name?.length ?? 0), | 459 offsetForToken(token) + (target.name?.name?.length ?? 0), |
| 453 isNullAware: isNullAware); | 460 isNullAware: isNullAware); |
| 454 } else { | 461 } else { |
| 455 result = helper.buildStaticInvocation(target, arguments) | 462 result = helper.buildStaticInvocation(target, arguments) |
| 456 ..fileOffset = offsetForToken(token); | 463 ..fileOffset = offsetForToken(token); |
| 457 } | 464 } |
| 458 } else { | 465 } else { |
| 459 result = buildThrowNoSuchMethodError(arguments) | 466 result = buildThrowNoSuchMethodError(arguments) |
| 460 ..fileOffset = offsetForToken(token); | 467 ..fileOffset = offsetForToken(token); |
| 461 } | 468 } |
| 462 } | 469 } |
| 463 } else { | 470 } else { |
| 464 result = buildMethodInvocation( | 471 result = helper.buildMethodInvocation( |
| 465 helper.toValue(receiver), name, arguments, offsetForToken(token), | 472 helper.toValue(receiver), name, arguments, offsetForToken(token), |
| 466 isNullAware: isNullAware); | 473 isNullAware: isNullAware); |
| 467 } | 474 } |
| 468 return result; | 475 return result; |
| 469 } | 476 } |
| 470 | 477 |
| 471 Expression buildNullAwareAssignment(Expression value, DartType type, | 478 Expression buildNullAwareAssignment(Expression value, DartType type, |
| 472 {bool voidContext: false}) { | 479 {bool voidContext: false}) { |
| 473 return internalError("Unhandled"); | 480 return internalError("Unhandled"); |
| 474 } | 481 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 | 591 |
| 585 IndexAccessor.internal(this.helper, Token token, Expression receiver, | 592 IndexAccessor.internal(this.helper, Token token, Expression receiver, |
| 586 Expression index, Procedure getter, Procedure setter) | 593 Expression index, Procedure getter, Procedure setter) |
| 587 : super.internal(helper, receiver, index, getter, setter, token); | 594 : super.internal(helper, receiver, index, getter, setter, token); |
| 588 | 595 |
| 589 String get plainNameForRead => "[]"; | 596 String get plainNameForRead => "[]"; |
| 590 | 597 |
| 591 String get plainNameForWrite => "[]="; | 598 String get plainNameForWrite => "[]="; |
| 592 | 599 |
| 593 Expression doInvocation(int offset, Arguments arguments) { | 600 Expression doInvocation(int offset, Arguments arguments) { |
| 594 return buildMethodInvocation( | 601 return helper.buildMethodInvocation( |
| 595 buildSimpleRead(), callName, arguments, offset); | 602 buildSimpleRead(), |
| 603 callName, |
| 604 arguments, |
| 605 offset, |
| 606 ); |
| 596 } | 607 } |
| 597 | 608 |
| 598 toString() => "IndexAccessor()"; | 609 toString() => "IndexAccessor()"; |
| 599 | 610 |
| 600 static FastaAccessor make( | 611 static FastaAccessor make( |
| 601 BuilderHelper helper, | 612 BuilderHelper helper, |
| 602 Token token, | 613 Token token, |
| 603 Expression receiver, | 614 Expression receiver, |
| 604 Expression index, | 615 Expression index, |
| 605 Procedure getter, | 616 Procedure getter, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 618 | 629 |
| 619 PropertyAccessor.internal(this.helper, Token token, Expression receiver, | 630 PropertyAccessor.internal(this.helper, Token token, Expression receiver, |
| 620 Name name, Member getter, Member setter) | 631 Name name, Member getter, Member setter) |
| 621 : super.internal(helper, receiver, name, getter, setter, token); | 632 : super.internal(helper, receiver, name, getter, setter, token); |
| 622 | 633 |
| 623 String get plainNameForRead => name.name; | 634 String get plainNameForRead => name.name; |
| 624 | 635 |
| 625 bool get isThisPropertyAccessor => receiver is ThisExpression; | 636 bool get isThisPropertyAccessor => receiver is ThisExpression; |
| 626 | 637 |
| 627 Expression doInvocation(int offset, Arguments arguments) { | 638 Expression doInvocation(int offset, Arguments arguments) { |
| 628 return buildMethodInvocation(receiver, name, arguments, offset); | 639 return helper.buildMethodInvocation(receiver, name, arguments, offset); |
| 629 } | 640 } |
| 630 | 641 |
| 631 toString() => "PropertyAccessor()"; | 642 toString() => "PropertyAccessor()"; |
| 632 | 643 |
| 633 static FastaAccessor make( | 644 static FastaAccessor make( |
| 634 BuilderHelper helper, | 645 BuilderHelper helper, |
| 635 Token token, | 646 Token token, |
| 636 Expression receiver, | 647 Expression receiver, |
| 637 Name name, | 648 Name name, |
| 638 Member getter, | 649 Member getter, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 setter = builderSetter.target; | 686 setter = builderSetter.target; |
| 676 } | 687 } |
| 677 } | 688 } |
| 678 return new StaticAccessor(helper, token, getter, setter); | 689 return new StaticAccessor(helper, token, getter, setter); |
| 679 } | 690 } |
| 680 | 691 |
| 681 String get plainNameForRead => (readTarget ?? writeTarget).name.name; | 692 String get plainNameForRead => (readTarget ?? writeTarget).name.name; |
| 682 | 693 |
| 683 Expression doInvocation(int offset, Arguments arguments) { | 694 Expression doInvocation(int offset, Arguments arguments) { |
| 684 if (readTarget == null || isFieldOrGetter(readTarget)) { | 695 if (readTarget == null || isFieldOrGetter(readTarget)) { |
| 685 return buildMethodInvocation(buildSimpleRead(), callName, arguments, | 696 return helper.buildMethodInvocation(buildSimpleRead(), callName, |
| 686 offset + (readTarget?.name?.name?.length ?? 0)); | 697 arguments, offset + (readTarget?.name?.name?.length ?? 0)); |
| 687 } else { | 698 } else { |
| 688 return helper.buildStaticInvocation(readTarget, arguments) | 699 return helper.buildStaticInvocation(readTarget, arguments) |
| 689 ..fileOffset = offset; | 700 ..fileOffset = offset; |
| 690 } | 701 } |
| 691 } | 702 } |
| 692 | 703 |
| 693 toString() => "StaticAccessor()"; | 704 toString() => "StaticAccessor()"; |
| 694 } | 705 } |
| 695 | 706 |
| 696 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor | 707 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor |
| 697 with FastaAccessor { | 708 with FastaAccessor { |
| 698 SuperPropertyAccessor(BuilderHelper helper, Token token, Name name, | 709 SuperPropertyAccessor(BuilderHelper helper, Token token, Name name, |
| 699 Member getter, Member setter) | 710 Member getter, Member setter) |
| 700 : super(helper, name, getter, setter, token); | 711 : super(helper, name, getter, setter, token); |
| 701 | 712 |
| 702 String get plainNameForRead => name.name; | 713 String get plainNameForRead => name.name; |
| 703 | 714 |
| 704 Expression doInvocation(int offset, Arguments arguments) { | 715 Expression doInvocation(int offset, Arguments arguments) { |
| 705 if (getter == null || isFieldOrGetter(getter)) { | 716 if (getter == null || isFieldOrGetter(getter)) { |
| 706 return buildMethodInvocation( | 717 return helper.buildMethodInvocation( |
| 707 buildSimpleRead(), callName, arguments, offset); | 718 buildSimpleRead(), callName, arguments, offset); |
| 708 } else { | 719 } else { |
| 709 return new DirectMethodInvocation(new ThisExpression(), getter, arguments) | 720 return new DirectMethodInvocation(new ThisExpression(), getter, arguments) |
| 710 ..fileOffset = offset; | 721 ..fileOffset = offset; |
| 711 } | 722 } |
| 712 } | 723 } |
| 713 | 724 |
| 714 toString() => "SuperPropertyAccessor()"; | 725 toString() => "SuperPropertyAccessor()"; |
| 715 } | 726 } |
| 716 | 727 |
| 717 class ThisIndexAccessor extends kernel.ThisIndexAccessor with FastaAccessor { | 728 class ThisIndexAccessor extends kernel.ThisIndexAccessor with FastaAccessor { |
| 718 ThisIndexAccessor(BuilderHelper helper, Token token, Expression index, | 729 ThisIndexAccessor(BuilderHelper helper, Token token, Expression index, |
| 719 Procedure getter, Procedure setter) | 730 Procedure getter, Procedure setter) |
| 720 : super(helper, index, getter, setter, token); | 731 : super(helper, index, getter, setter, token); |
| 721 | 732 |
| 722 String get plainNameForRead => "[]"; | 733 String get plainNameForRead => "[]"; |
| 723 | 734 |
| 724 String get plainNameForWrite => "[]="; | 735 String get plainNameForWrite => "[]="; |
| 725 | 736 |
| 726 Expression doInvocation(int offset, Arguments arguments) { | 737 Expression doInvocation(int offset, Arguments arguments) { |
| 727 return buildMethodInvocation( | 738 return helper.buildMethodInvocation( |
| 728 buildSimpleRead(), callName, arguments, offset); | 739 buildSimpleRead(), callName, arguments, offset); |
| 729 } | 740 } |
| 730 | 741 |
| 731 toString() => "ThisIndexAccessor()"; | 742 toString() => "ThisIndexAccessor()"; |
| 732 } | 743 } |
| 733 | 744 |
| 734 class SuperIndexAccessor extends kernel.SuperIndexAccessor with FastaAccessor { | 745 class SuperIndexAccessor extends kernel.SuperIndexAccessor with FastaAccessor { |
| 735 SuperIndexAccessor(BuilderHelper helper, Token token, Expression index, | 746 SuperIndexAccessor(BuilderHelper helper, Token token, Expression index, |
| 736 Member getter, Member setter) | 747 Member getter, Member setter) |
| 737 : super(helper, index, getter, setter, token); | 748 : super(helper, index, getter, setter, token); |
| 738 | 749 |
| 739 String get plainNameForRead => "[]"; | 750 String get plainNameForRead => "[]"; |
| 740 | 751 |
| 741 String get plainNameForWrite => "[]="; | 752 String get plainNameForWrite => "[]="; |
| 742 | 753 |
| 743 Expression doInvocation(int offset, Arguments arguments) { | 754 Expression doInvocation(int offset, Arguments arguments) { |
| 744 return buildMethodInvocation( | 755 return helper.buildMethodInvocation( |
| 745 buildSimpleRead(), callName, arguments, offset); | 756 buildSimpleRead(), callName, arguments, offset); |
| 746 } | 757 } |
| 747 | 758 |
| 748 toString() => "SuperIndexAccessor()"; | 759 toString() => "SuperIndexAccessor()"; |
| 749 } | 760 } |
| 750 | 761 |
| 751 class ThisPropertyAccessor extends kernel.ThisPropertyAccessor | 762 class ThisPropertyAccessor extends kernel.ThisPropertyAccessor |
| 752 with FastaAccessor { | 763 with FastaAccessor { |
| 753 final BuilderHelper helper; | 764 final BuilderHelper helper; |
| 754 | 765 |
| 755 ThisPropertyAccessor( | 766 ThisPropertyAccessor( |
| 756 this.helper, Token token, Name name, Member getter, Member setter) | 767 this.helper, Token token, Name name, Member getter, Member setter) |
| 757 : super(helper, name, getter, setter, token); | 768 : super(helper, name, getter, setter, token); |
| 758 | 769 |
| 759 String get plainNameForRead => name.name; | 770 String get plainNameForRead => name.name; |
| 760 | 771 |
| 761 bool get isThisPropertyAccessor => true; | 772 bool get isThisPropertyAccessor => true; |
| 762 | 773 |
| 763 Expression doInvocation(int offset, Arguments arguments) { | 774 Expression doInvocation(int offset, Arguments arguments) { |
| 764 Member interfaceTarget = getter; | 775 Member interfaceTarget = getter; |
| 765 if (interfaceTarget is Field) { | 776 if (interfaceTarget is Field) { |
| 766 // TODO(ahe): In strong mode we should probably rewrite this to | 777 // TODO(ahe): In strong mode we should probably rewrite this to |
| 767 // `this.name.call(arguments)`. | 778 // `this.name.call(arguments)`. |
| 768 interfaceTarget = null; | 779 interfaceTarget = null; |
| 769 } | 780 } |
| 770 return buildMethodInvocation(new ThisExpression(), name, arguments, offset); | 781 return helper.buildMethodInvocation( |
| 782 new ThisExpression(), name, arguments, offset); |
| 771 } | 783 } |
| 772 | 784 |
| 773 toString() => "ThisPropertyAccessor()"; | 785 toString() => "ThisPropertyAccessor()"; |
| 774 } | 786 } |
| 775 | 787 |
| 776 class NullAwarePropertyAccessor extends kernel.NullAwarePropertyAccessor | 788 class NullAwarePropertyAccessor extends kernel.NullAwarePropertyAccessor |
| 777 with FastaAccessor { | 789 with FastaAccessor { |
| 778 final BuilderHelper helper; | 790 final BuilderHelper helper; |
| 779 | 791 |
| 780 NullAwarePropertyAccessor(this.helper, Token token, Expression receiver, | 792 NullAwarePropertyAccessor(this.helper, Token token, Expression receiver, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 794 VariableAccessor( | 806 VariableAccessor( |
| 795 BuilderHelper helper, Token token, VariableDeclaration variable, | 807 BuilderHelper helper, Token token, VariableDeclaration variable, |
| 796 [DartType promotedType]) | 808 [DartType promotedType]) |
| 797 : super(helper, variable, promotedType, token); | 809 : super(helper, variable, promotedType, token); |
| 798 | 810 |
| 799 String get plainNameForRead => variable.name; | 811 String get plainNameForRead => variable.name; |
| 800 | 812 |
| 801 Expression doInvocation(int offset, Arguments arguments) { | 813 Expression doInvocation(int offset, Arguments arguments) { |
| 802 // Normally the offset is at the start of the token, but in this case, | 814 // Normally the offset is at the start of the token, but in this case, |
| 803 // because we insert a '.call', we want it at the end instead. | 815 // because we insert a '.call', we want it at the end instead. |
| 804 return buildMethodInvocation(buildSimpleRead(), callName, arguments, | 816 return helper.buildMethodInvocation(buildSimpleRead(), callName, arguments, |
| 805 offset + (variable.name?.length ?? 0)); | 817 offset + (variable.name?.length ?? 0)); |
| 806 } | 818 } |
| 807 | 819 |
| 808 toString() => "VariableAccessor()"; | 820 toString() => "VariableAccessor()"; |
| 809 } | 821 } |
| 810 | 822 |
| 811 class ReadOnlyAccessor extends kernel.ReadOnlyAccessor with FastaAccessor { | 823 class ReadOnlyAccessor extends kernel.ReadOnlyAccessor with FastaAccessor { |
| 812 final String plainNameForRead; | 824 final String plainNameForRead; |
| 813 | 825 |
| 814 ReadOnlyAccessor(BuilderHelper helper, Expression expression, | 826 ReadOnlyAccessor(BuilderHelper helper, Expression expression, |
| 815 this.plainNameForRead, Token token) | 827 this.plainNameForRead, Token token) |
| 816 : super(helper, expression, token); | 828 : super(helper, expression, token); |
| 817 | 829 |
| 818 Expression doInvocation(int offset, Arguments arguments) { | 830 Expression doInvocation(int offset, Arguments arguments) { |
| 819 return buildMethodInvocation( | 831 return helper.buildMethodInvocation( |
| 820 buildSimpleRead(), callName, arguments, offset); | 832 buildSimpleRead(), callName, arguments, offset); |
| 821 } | 833 } |
| 822 } | 834 } |
| 823 | 835 |
| 824 class ParenthesizedExpression extends ReadOnlyAccessor { | 836 class ParenthesizedExpression extends ReadOnlyAccessor { |
| 825 ParenthesizedExpression( | 837 ParenthesizedExpression( |
| 826 BuilderHelper helper, Expression expression, Token token) | 838 BuilderHelper helper, Expression expression, Token token) |
| 827 : super(helper, expression, "<a parenthesized expression>", token); | 839 : super(helper, expression, "<a parenthesized expression>", token); |
| 828 | 840 |
| 829 Expression makeInvalidWrite(Expression value) { | 841 Expression makeInvalidWrite(Expression value) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 853 {bool isGetter: false, bool isSetter: false, int offset}) { | 865 {bool isGetter: false, bool isSetter: false, int offset}) { |
| 854 return helper.throwNoSuchMethodError( | 866 return helper.throwNoSuchMethodError( |
| 855 plainNameForRead, arguments, offset ?? offsetForToken(this.token), | 867 plainNameForRead, arguments, offset ?? offsetForToken(this.token), |
| 856 isGetter: isGetter, isSetter: isSetter); | 868 isGetter: isGetter, isSetter: isSetter); |
| 857 } | 869 } |
| 858 } | 870 } |
| 859 | 871 |
| 860 bool isFieldOrGetter(Member member) { | 872 bool isFieldOrGetter(Member member) { |
| 861 return member is Field || (member is Procedure && member.isGetter); | 873 return member is Field || (member is Procedure && member.isGetter); |
| 862 } | 874 } |
| 863 | |
| 864 Expression buildMethodInvocation( | |
| 865 Expression receiver, Name name, Arguments arguments, int offset, | |
| 866 {bool isNullAware: false}) { | |
| 867 if (isNullAware) { | |
| 868 VariableDeclaration variable = new VariableDeclaration.forValue(receiver); | |
| 869 return makeLet( | |
| 870 variable, | |
| 871 new ConditionalExpression( | |
| 872 buildIsNull(new VariableGet(variable)), | |
| 873 new NullLiteral(), | |
| 874 new KernelMethodInvocation( | |
| 875 new VariableGet(variable), name, arguments) | |
| 876 ..fileOffset = offset, | |
| 877 const DynamicType())); | |
| 878 } else { | |
| 879 return new KernelMethodInvocation(receiver, name, arguments) | |
| 880 ..fileOffset = offset; | |
| 881 } | |
| 882 } | |
| OLD | NEW |