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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart

Issue 2931363003: Add type inference for assignments to properties. (Closed)
Patch Set: Created 3 years, 6 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 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 8 show
9 KernelArguments, 9 KernelArguments,
10 KernelComplexAssignment, 10 KernelComplexAssignment,
11 KernelIndexAssign, 11 KernelIndexAssign,
12 KernelPropertyAssign,
12 KernelStaticAssignment, 13 KernelStaticAssignment,
13 KernelThisExpression, 14 KernelThisExpression,
14 KernelVariableAssignment; 15 KernelVariableAssignment;
15 16
16 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; 17 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken;
17 18
18 import 'package:front_end/src/scanner/token.dart' show Token; 19 import 'package:front_end/src/scanner/token.dart' show Token;
19 20
20 import 'frontend_accessors.dart' show Accessor; 21 import 'frontend_accessors.dart' show Accessor;
21 22
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 if (receiver is ThisExpression) { 669 if (receiver is ThisExpression) {
669 return new ThisPropertyAccessor(helper, token, name, getter, setter); 670 return new ThisPropertyAccessor(helper, token, name, getter, setter);
670 } else { 671 } else {
671 return isNullAware 672 return isNullAware
672 ? new NullAwarePropertyAccessor( 673 ? new NullAwarePropertyAccessor(
673 helper, token, receiver, name, getter, setter, null) 674 helper, token, receiver, name, getter, setter, null)
674 : new PropertyAccessor.internal( 675 : new PropertyAccessor.internal(
675 helper, token, receiver, name, getter, setter); 676 helper, token, receiver, name, getter, setter);
676 } 677 }
677 } 678 }
679
680 @override
681 KernelComplexAssignment startComplexAssignment(Expression rhs) =>
682 new KernelPropertyAssign(receiver, rhs);
678 } 683 }
679 684
680 class StaticAccessor extends kernel.StaticAccessor with FastaAccessor { 685 class StaticAccessor extends kernel.StaticAccessor with FastaAccessor {
681 StaticAccessor( 686 StaticAccessor(
682 BuilderHelper helper, Token token, Member readTarget, Member writeTarget) 687 BuilderHelper helper, Token token, Member readTarget, Member writeTarget)
683 : super(helper, readTarget, writeTarget, token) { 688 : super(helper, readTarget, writeTarget, token) {
684 assert(readTarget != null || writeTarget != null); 689 assert(readTarget != null || writeTarget != null);
685 } 690 }
686 691
687 factory StaticAccessor.fromBuilder(BuilderHelper helper, Builder builder, 692 factory StaticAccessor.fromBuilder(BuilderHelper helper, Builder builder,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 770
766 Expression makeInvalidWrite(Expression value) { 771 Expression makeInvalidWrite(Expression value) {
767 return helper.invokeSuperNoSuchMethod( 772 return helper.invokeSuperNoSuchMethod(
768 plainNameForRead, 773 plainNameForRead,
769 new Arguments(<Expression>[value])..fileOffset = value.fileOffset, 774 new Arguments(<Expression>[value])..fileOffset = value.fileOffset,
770 offsetForToken(token), 775 offsetForToken(token),
771 isSetter: true); 776 isSetter: true);
772 } 777 }
773 778
774 toString() => "SuperPropertyAccessor()"; 779 toString() => "SuperPropertyAccessor()";
780
781 @override
782 KernelComplexAssignment startComplexAssignment(Expression rhs) =>
783 new KernelPropertyAssign(null, rhs, isSuper: true);
775 } 784 }
776 785
777 class ThisIndexAccessor extends kernel.ThisIndexAccessor with FastaAccessor { 786 class ThisIndexAccessor extends kernel.ThisIndexAccessor with FastaAccessor {
778 ThisIndexAccessor(BuilderHelper helper, Token token, Expression index, 787 ThisIndexAccessor(BuilderHelper helper, Token token, Expression index,
779 Procedure getter, Procedure setter) 788 Procedure getter, Procedure setter)
780 : super(helper, index, getter, setter, token); 789 : super(helper, index, getter, setter, token);
781 790
782 String get plainNameForRead => "[]"; 791 String get plainNameForRead => "[]";
783 792
784 String get plainNameForWrite => "[]="; 793 String get plainNameForWrite => "[]=";
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 if (interfaceTarget is Field) { 836 if (interfaceTarget is Field) {
828 // TODO(ahe): In strong mode we should probably rewrite this to 837 // TODO(ahe): In strong mode we should probably rewrite this to
829 // `this.name.call(arguments)`. 838 // `this.name.call(arguments)`.
830 interfaceTarget = null; 839 interfaceTarget = null;
831 } 840 }
832 return helper.buildMethodInvocation( 841 return helper.buildMethodInvocation(
833 new KernelThisExpression(), name, arguments, offset); 842 new KernelThisExpression(), name, arguments, offset);
834 } 843 }
835 844
836 toString() => "ThisPropertyAccessor()"; 845 toString() => "ThisPropertyAccessor()";
846
847 @override
848 KernelComplexAssignment startComplexAssignment(Expression rhs) =>
849 new KernelPropertyAssign(null, rhs);
837 } 850 }
838 851
839 class NullAwarePropertyAccessor extends kernel.NullAwarePropertyAccessor 852 class NullAwarePropertyAccessor extends kernel.NullAwarePropertyAccessor
840 with FastaAccessor { 853 with FastaAccessor {
841 final BuilderHelper helper; 854 final BuilderHelper helper;
842 855
843 NullAwarePropertyAccessor(this.helper, Token token, Expression receiver, 856 NullAwarePropertyAccessor(this.helper, Token token, Expression receiver,
844 Name name, Member getter, Member setter, DartType type) 857 Name name, Member getter, Member setter, DartType type)
845 : super(helper, receiver, name, getter, setter, type, token); 858 : super(helper, receiver, name, getter, setter, type, token);
846 859
847 String get plainNameForRead => name.name; 860 String get plainNameForRead => name.name;
848 861
849 Expression doInvocation(int offset, Arguments arguments) { 862 Expression doInvocation(int offset, Arguments arguments) {
850 return internalError("Not implemented yet."); 863 return internalError("Not implemented yet.");
851 } 864 }
852 865
853 toString() => "NullAwarePropertyAccessor()"; 866 toString() => "NullAwarePropertyAccessor()";
867
868 @override
869 KernelComplexAssignment startComplexAssignment(Expression rhs) =>
870 new KernelPropertyAssign(receiverExpression, rhs);
854 } 871 }
855 872
856 int adjustForImplicitCall(String name, int offset) { 873 int adjustForImplicitCall(String name, int offset) {
857 // Normally the offset is at the start of the token, but in this case, 874 // Normally the offset is at the start of the token, but in this case,
858 // because we insert a '.call', we want it at the end instead. 875 // because we insert a '.call', we want it at the end instead.
859 return offset + (name?.length ?? 0); 876 return offset + (name?.length ?? 0);
860 } 877 }
861 878
862 class VariableAccessor extends kernel.VariableAccessor with FastaAccessor { 879 class VariableAccessor extends kernel.VariableAccessor with FastaAccessor {
863 VariableAccessor( 880 VariableAccessor(
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 offset ??= offsetForToken(this.token); 1033 offset ??= offsetForToken(this.token);
1017 return helper.throwNoSuchMethodError(new NullLiteral()..fileOffset = offset, 1034 return helper.throwNoSuchMethodError(new NullLiteral()..fileOffset = offset,
1018 plainNameForRead, arguments, offset, 1035 plainNameForRead, arguments, offset,
1019 isGetter: isGetter, isSetter: isSetter); 1036 isGetter: isGetter, isSetter: isSetter);
1020 } 1037 }
1021 } 1038 }
1022 1039
1023 bool isFieldOrGetter(Member member) { 1040 bool isFieldOrGetter(Member member) {
1024 return member is Field || (member is Procedure && member.isGetter); 1041 return member is Field || (member is Procedure && member.isGetter);
1025 } 1042 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698