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, KernelThisExpression; | 8 show KernelArguments, KernelThisExpression; |
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; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 List<TypeParameter> typeParameters); | 98 List<TypeParameter> typeParameters); |
99 | 99 |
100 StaticGet makeStaticGet(Member readTarget, Token token); | 100 StaticGet makeStaticGet(Member readTarget, Token token); |
101 | 101 |
102 dynamic addCompileTimeError(int charOffset, String message, {bool silent}); | 102 dynamic addCompileTimeError(int charOffset, String message, {bool silent}); |
103 | 103 |
104 bool isIdentical(Member member); | 104 bool isIdentical(Member member); |
105 | 105 |
106 Expression buildMethodInvocation( | 106 Expression buildMethodInvocation( |
107 Expression receiver, Name name, Arguments arguments, int offset, | 107 Expression receiver, Name name, Arguments arguments, int offset, |
108 {bool isConstantExpression, bool isNullAware}); | 108 {bool isConstantExpression, bool isNullAware, bool isImplicitCall}); |
109 | 109 |
110 DartType validatedTypeVariableUse( | 110 DartType validatedTypeVariableUse( |
111 TypeParameterType type, int offset, bool nonInstanceAccessIsError); | 111 TypeParameterType type, int offset, bool nonInstanceAccessIsError); |
112 | 112 |
113 void warning(String message, [int charOffset]); | 113 void warning(String message, [int charOffset]); |
114 } | 114 } |
115 | 115 |
116 abstract class FastaAccessor implements Accessor { | 116 abstract class FastaAccessor implements Accessor { |
117 BuilderHelper get helper; | 117 BuilderHelper get helper; |
118 | 118 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 helper, send.token, send.name, null, null); | 330 helper, send.token, send.name, null, null); |
331 } | 331 } |
332 } | 332 } |
333 } | 333 } |
334 | 334 |
335 doInvocation(int offset, Arguments arguments) { | 335 doInvocation(int offset, Arguments arguments) { |
336 if (isInitializer) { | 336 if (isInitializer) { |
337 return buildConstructorInitializer(offset, new Name(""), arguments); | 337 return buildConstructorInitializer(offset, new Name(""), arguments); |
338 } else { | 338 } else { |
339 return helper.buildMethodInvocation( | 339 return helper.buildMethodInvocation( |
340 new KernelThisExpression(), callName, arguments, offset); | 340 new KernelThisExpression(), callName, arguments, offset, |
| 341 isImplicitCall: true); |
341 } | 342 } |
342 } | 343 } |
343 | 344 |
344 Initializer buildConstructorInitializer( | 345 Initializer buildConstructorInitializer( |
345 int offset, Name name, Arguments arguments) { | 346 int offset, Name name, Arguments arguments) { |
346 Constructor constructor = helper.lookupConstructor(name, isSuper: isSuper); | 347 Constructor constructor = helper.lookupConstructor(name, isSuper: isSuper); |
347 if (constructor == null || | 348 if (constructor == null || |
348 !helper.checkArguments( | 349 !helper.checkArguments( |
349 constructor.function, arguments, <TypeParameter>[])) { | 350 constructor.function, arguments, <TypeParameter>[])) { |
350 return helper.buildInvalidInitializer( | 351 return helper.buildInvalidInitializer( |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 IndexAccessor.internal(this.helper, Token token, Expression receiver, | 559 IndexAccessor.internal(this.helper, Token token, Expression receiver, |
559 Expression index, Procedure getter, Procedure setter) | 560 Expression index, Procedure getter, Procedure setter) |
560 : super.internal(helper, receiver, index, getter, setter, token); | 561 : super.internal(helper, receiver, index, getter, setter, token); |
561 | 562 |
562 String get plainNameForRead => "[]"; | 563 String get plainNameForRead => "[]"; |
563 | 564 |
564 String get plainNameForWrite => "[]="; | 565 String get plainNameForWrite => "[]="; |
565 | 566 |
566 Expression doInvocation(int offset, Arguments arguments) { | 567 Expression doInvocation(int offset, Arguments arguments) { |
567 return helper.buildMethodInvocation( | 568 return helper.buildMethodInvocation( |
568 buildSimpleRead(), | 569 buildSimpleRead(), callName, arguments, offset, |
569 callName, | 570 isImplicitCall: true); |
570 arguments, | |
571 offset, | |
572 ); | |
573 } | 571 } |
574 | 572 |
575 toString() => "IndexAccessor()"; | 573 toString() => "IndexAccessor()"; |
576 | 574 |
577 static FastaAccessor make( | 575 static FastaAccessor make( |
578 BuilderHelper helper, | 576 BuilderHelper helper, |
579 Token token, | 577 Token token, |
580 Expression receiver, | 578 Expression receiver, |
581 Expression index, | 579 Expression index, |
582 Procedure getter, | 580 Procedure getter, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 | 657 |
660 Expression doInvocation(int offset, Arguments arguments) { | 658 Expression doInvocation(int offset, Arguments arguments) { |
661 if (helper.constantExpressionRequired && !helper.isIdentical(readTarget)) { | 659 if (helper.constantExpressionRequired && !helper.isIdentical(readTarget)) { |
662 helper.addCompileTimeError(offset, "Not a constant expression."); | 660 helper.addCompileTimeError(offset, "Not a constant expression."); |
663 } | 661 } |
664 if (readTarget == null || isFieldOrGetter(readTarget)) { | 662 if (readTarget == null || isFieldOrGetter(readTarget)) { |
665 return helper.buildMethodInvocation(buildSimpleRead(), callName, | 663 return helper.buildMethodInvocation(buildSimpleRead(), callName, |
666 arguments, offset + (readTarget?.name?.name?.length ?? 0), | 664 arguments, offset + (readTarget?.name?.name?.length ?? 0), |
667 // This isn't a constant expression, but we have checked if a | 665 // This isn't a constant expression, but we have checked if a |
668 // constant expression error should be emitted already. | 666 // constant expression error should be emitted already. |
669 isConstantExpression: true); | 667 isConstantExpression: true, |
| 668 isImplicitCall: true); |
670 } else { | 669 } else { |
671 return helper.buildStaticInvocation(readTarget, arguments) | 670 return helper.buildStaticInvocation(readTarget, arguments) |
672 ..fileOffset = offset; | 671 ..fileOffset = offset; |
673 } | 672 } |
674 } | 673 } |
675 | 674 |
676 toString() => "StaticAccessor()"; | 675 toString() => "StaticAccessor()"; |
677 } | 676 } |
678 | 677 |
679 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor | 678 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor |
680 with FastaAccessor { | 679 with FastaAccessor { |
681 SuperPropertyAccessor(BuilderHelper helper, Token token, Name name, | 680 SuperPropertyAccessor(BuilderHelper helper, Token token, Name name, |
682 Member getter, Member setter) | 681 Member getter, Member setter) |
683 : super(helper, name, getter, setter, token); | 682 : super(helper, name, getter, setter, token); |
684 | 683 |
685 String get plainNameForRead => name.name; | 684 String get plainNameForRead => name.name; |
686 | 685 |
687 Expression doInvocation(int offset, Arguments arguments) { | 686 Expression doInvocation(int offset, Arguments arguments) { |
688 if (helper.constantExpressionRequired) { | 687 if (helper.constantExpressionRequired) { |
689 helper.addCompileTimeError(offset, "Not a constant expression."); | 688 helper.addCompileTimeError(offset, "Not a constant expression."); |
690 } | 689 } |
691 if (getter == null || isFieldOrGetter(getter)) { | 690 if (getter == null || isFieldOrGetter(getter)) { |
692 return helper.buildMethodInvocation( | 691 return helper.buildMethodInvocation( |
693 buildSimpleRead(), callName, arguments, offset, | 692 buildSimpleRead(), callName, arguments, offset, |
694 // This isn't a constant expression, but we have checked if a | 693 // This isn't a constant expression, but we have checked if a |
695 // constant expression error should be emitted already. | 694 // constant expression error should be emitted already. |
696 isConstantExpression: true); | 695 isConstantExpression: true, |
| 696 isImplicitCall: true); |
697 } else { | 697 } else { |
698 return new DirectMethodInvocation(new ThisExpression(), getter, arguments) | 698 return new DirectMethodInvocation(new ThisExpression(), getter, arguments) |
699 ..fileOffset = offset; | 699 ..fileOffset = offset; |
700 } | 700 } |
701 } | 701 } |
702 | 702 |
703 toString() => "SuperPropertyAccessor()"; | 703 toString() => "SuperPropertyAccessor()"; |
704 } | 704 } |
705 | 705 |
706 class ThisIndexAccessor extends kernel.ThisIndexAccessor with FastaAccessor { | 706 class ThisIndexAccessor extends kernel.ThisIndexAccessor with FastaAccessor { |
707 ThisIndexAccessor(BuilderHelper helper, Token token, Expression index, | 707 ThisIndexAccessor(BuilderHelper helper, Token token, Expression index, |
708 Procedure getter, Procedure setter) | 708 Procedure getter, Procedure setter) |
709 : super(helper, index, getter, setter, token); | 709 : super(helper, index, getter, setter, token); |
710 | 710 |
711 String get plainNameForRead => "[]"; | 711 String get plainNameForRead => "[]"; |
712 | 712 |
713 String get plainNameForWrite => "[]="; | 713 String get plainNameForWrite => "[]="; |
714 | 714 |
715 Expression doInvocation(int offset, Arguments arguments) { | 715 Expression doInvocation(int offset, Arguments arguments) { |
716 return helper.buildMethodInvocation( | 716 return helper.buildMethodInvocation( |
717 buildSimpleRead(), callName, arguments, offset); | 717 buildSimpleRead(), callName, arguments, offset, |
| 718 isImplicitCall: true); |
718 } | 719 } |
719 | 720 |
720 toString() => "ThisIndexAccessor()"; | 721 toString() => "ThisIndexAccessor()"; |
721 } | 722 } |
722 | 723 |
723 class SuperIndexAccessor extends kernel.SuperIndexAccessor with FastaAccessor { | 724 class SuperIndexAccessor extends kernel.SuperIndexAccessor with FastaAccessor { |
724 SuperIndexAccessor(BuilderHelper helper, Token token, Expression index, | 725 SuperIndexAccessor(BuilderHelper helper, Token token, Expression index, |
725 Member getter, Member setter) | 726 Member getter, Member setter) |
726 : super(helper, index, getter, setter, token); | 727 : super(helper, index, getter, setter, token); |
727 | 728 |
728 String get plainNameForRead => "[]"; | 729 String get plainNameForRead => "[]"; |
729 | 730 |
730 String get plainNameForWrite => "[]="; | 731 String get plainNameForWrite => "[]="; |
731 | 732 |
732 Expression doInvocation(int offset, Arguments arguments) { | 733 Expression doInvocation(int offset, Arguments arguments) { |
733 return helper.buildMethodInvocation( | 734 return helper.buildMethodInvocation( |
734 buildSimpleRead(), callName, arguments, offset); | 735 buildSimpleRead(), callName, arguments, offset, |
| 736 isImplicitCall: true); |
735 } | 737 } |
736 | 738 |
737 toString() => "SuperIndexAccessor()"; | 739 toString() => "SuperIndexAccessor()"; |
738 } | 740 } |
739 | 741 |
740 class ThisPropertyAccessor extends kernel.ThisPropertyAccessor | 742 class ThisPropertyAccessor extends kernel.ThisPropertyAccessor |
741 with FastaAccessor { | 743 with FastaAccessor { |
742 final BuilderHelper helper; | 744 final BuilderHelper helper; |
743 | 745 |
744 ThisPropertyAccessor( | 746 ThisPropertyAccessor( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 class VariableAccessor extends kernel.VariableAccessor with FastaAccessor { | 791 class VariableAccessor extends kernel.VariableAccessor with FastaAccessor { |
790 VariableAccessor( | 792 VariableAccessor( |
791 BuilderHelper helper, Token token, VariableDeclaration variable, | 793 BuilderHelper helper, Token token, VariableDeclaration variable, |
792 [DartType promotedType]) | 794 [DartType promotedType]) |
793 : super(helper, variable, promotedType, token); | 795 : super(helper, variable, promotedType, token); |
794 | 796 |
795 String get plainNameForRead => variable.name; | 797 String get plainNameForRead => variable.name; |
796 | 798 |
797 Expression doInvocation(int offset, Arguments arguments) { | 799 Expression doInvocation(int offset, Arguments arguments) { |
798 return helper.buildMethodInvocation(buildSimpleRead(), callName, arguments, | 800 return helper.buildMethodInvocation(buildSimpleRead(), callName, arguments, |
799 adjustForImplicitCall(plainNameForRead, offset)); | 801 adjustForImplicitCall(plainNameForRead, offset), |
| 802 isImplicitCall: true); |
800 } | 803 } |
801 | 804 |
802 toString() => "VariableAccessor()"; | 805 toString() => "VariableAccessor()"; |
803 } | 806 } |
804 | 807 |
805 class ReadOnlyAccessor extends kernel.ReadOnlyAccessor with FastaAccessor { | 808 class ReadOnlyAccessor extends kernel.ReadOnlyAccessor with FastaAccessor { |
806 final String plainNameForRead; | 809 final String plainNameForRead; |
807 | 810 |
808 ReadOnlyAccessor(BuilderHelper helper, Expression expression, | 811 ReadOnlyAccessor(BuilderHelper helper, Expression expression, |
809 this.plainNameForRead, Token token) | 812 this.plainNameForRead, Token token) |
810 : super(helper, expression, token); | 813 : super(helper, expression, token); |
811 | 814 |
812 Expression doInvocation(int offset, Arguments arguments) { | 815 Expression doInvocation(int offset, Arguments arguments) { |
813 return helper.buildMethodInvocation(buildSimpleRead(), callName, arguments, | 816 return helper.buildMethodInvocation(buildSimpleRead(), callName, arguments, |
814 adjustForImplicitCall(plainNameForRead, offset)); | 817 adjustForImplicitCall(plainNameForRead, offset), |
| 818 isImplicitCall: true); |
815 } | 819 } |
816 } | 820 } |
817 | 821 |
818 class ParenthesizedExpression extends ReadOnlyAccessor { | 822 class ParenthesizedExpression extends ReadOnlyAccessor { |
819 ParenthesizedExpression( | 823 ParenthesizedExpression( |
820 BuilderHelper helper, Expression expression, Token token) | 824 BuilderHelper helper, Expression expression, Token token) |
821 : super(helper, expression, null, token); | 825 : super(helper, expression, null, token); |
822 | 826 |
823 Expression makeInvalidWrite(Expression value) { | 827 Expression makeInvalidWrite(Expression value) { |
824 return helper.buildCompileTimeError( | 828 return helper.buildCompileTimeError( |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 {bool isGetter: false, bool isSetter: false, int offset}) { | 939 {bool isGetter: false, bool isSetter: false, int offset}) { |
936 return helper.throwNoSuchMethodError( | 940 return helper.throwNoSuchMethodError( |
937 plainNameForRead, arguments, offset ?? offsetForToken(this.token), | 941 plainNameForRead, arguments, offset ?? offsetForToken(this.token), |
938 isGetter: isGetter, isSetter: isSetter); | 942 isGetter: isGetter, isSetter: isSetter); |
939 } | 943 } |
940 } | 944 } |
941 | 945 |
942 bool isFieldOrGetter(Member member) { | 946 bool isFieldOrGetter(Member member) { |
943 return member is Field || (member is Procedure && member.isGetter); | 947 return member is Field || (member is Procedure && member.isGetter); |
944 } | 948 } |
OLD | NEW |