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

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

Issue 2916333002: Setup correct scope for initializers and complain about fields initialized more than once. (Closed)
Patch Set: A parenthesized expression doesn't have a name. 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 KernelArguments; 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;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 scopeLookup(Scope scope, String name, Token token, 69 scopeLookup(Scope scope, String name, Token token,
70 {bool isQualified: false, PrefixBuilder prefix}); 70 {bool isQualified: false, PrefixBuilder prefix});
71 71
72 finishSend(Object receiver, Arguments arguments, int offset); 72 finishSend(Object receiver, Arguments arguments, int offset);
73 73
74 Expression buildCompileTimeError(error, [int offset]); 74 Expression buildCompileTimeError(error, [int offset]);
75 75
76 Initializer buildInvalidIntializer(Expression expression, [int offset]); 76 Initializer buildInvalidIntializer(Expression expression, [int offset]);
77 77
78 Initializer buildFieldInitializer(
79 String name, int offset, Expression expression);
80
78 Initializer buildSuperInitializer( 81 Initializer buildSuperInitializer(
79 Constructor constructor, Arguments arguments, 82 Constructor constructor, Arguments arguments,
80 [int offset]); 83 [int offset]);
81 84
82 Initializer buildRedirectingInitializer( 85 Initializer buildRedirectingInitializer(
83 Constructor constructor, Arguments arguments, 86 Constructor constructor, Arguments arguments,
84 [int charOffset = -1]); 87 [int charOffset = -1]);
85 88
86 Expression buildStaticInvocation(Procedure target, Arguments arguments); 89 Expression buildStaticInvocation(Procedure target, Arguments arguments);
87 90
(...skipping 28 matching lines...) Expand all
116 String get plainNameForRead; 119 String get plainNameForRead;
117 120
118 Uri get uri => helper.uri; 121 Uri get uri => helper.uri;
119 122
120 String get plainNameForWrite => plainNameForRead; 123 String get plainNameForWrite => plainNameForRead;
121 124
122 bool get isInitializer => false; 125 bool get isInitializer => false;
123 126
124 Expression buildForEffect() => buildSimpleRead(); 127 Expression buildForEffect() => buildSimpleRead();
125 128
126 Initializer buildFieldInitializer( 129 Initializer buildFieldInitializer(Map<String, int> initializedFields) {
127 Map<String, FieldInitializer> initializers) {
128 int offset = offsetForToken(token); 130 int offset = offsetForToken(token);
129 return helper.buildInvalidIntializer( 131 return helper.buildInvalidIntializer(
130 helper.buildCompileTimeError( 132 helper.buildCompileTimeError(
131 // TODO(ahe): This error message is really bad. 133 // TODO(ahe): This error message is really bad.
132 "Can't use $plainNameForRead here.", 134 "Can't use $plainNameForRead here.",
133 offset), 135 offset),
134 offset); 136 offset);
135 } 137 }
136 138
137 Expression makeInvalidRead() { 139 Expression makeInvalidRead() {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 {bool isGetter: false, bool isSetter: false, int offset}); 187 {bool isGetter: false, bool isSetter: false, int offset});
186 188
187 Name get name => internalError("Unsupported operation."); 189 Name get name => internalError("Unsupported operation.");
188 190
189 @override 191 @override
190 String get plainNameForRead => name.name; 192 String get plainNameForRead => name.name;
191 193
192 withReceiver(Object receiver, int operatorOffset, {bool isNullAware}) => this; 194 withReceiver(Object receiver, int operatorOffset, {bool isNullAware}) => this;
193 195
194 @override 196 @override
195 Initializer buildFieldInitializer( 197 Initializer buildFieldInitializer(Map<String, int> initializedFields) {
196 Map<String, FieldInitializer> initializers) {
197 return helper.buildInvalidIntializer( 198 return helper.buildInvalidIntializer(
198 buildError(new Arguments.empty(), isSetter: true)); 199 buildError(new Arguments.empty(), isSetter: true));
199 } 200 }
200 201
201 @override 202 @override
202 doInvocation(int offset, Arguments arguments) { 203 doInvocation(int offset, Arguments arguments) {
203 return buildError(arguments, offset: offset); 204 return buildError(arguments, offset: offset);
204 } 205 }
205 206
206 @override 207 @override
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 287
287 Expression buildSimpleRead() { 288 Expression buildSimpleRead() {
288 if (!isSuper) { 289 if (!isSuper) {
289 return new ThisExpression(); 290 return new ThisExpression();
290 } else { 291 } else {
291 return helper.buildCompileTimeError( 292 return helper.buildCompileTimeError(
292 "Can't use `super` as an expression.", offsetForToken(token)); 293 "Can't use `super` as an expression.", offsetForToken(token));
293 } 294 }
294 } 295 }
295 296
296 Initializer buildFieldInitializer( 297 @override
297 Map<String, FieldInitializer> initializers) { 298 Initializer buildFieldInitializer(Map<String, int> initializedFields) {
298 String keyword = isSuper ? "super" : "this"; 299 String keyword = isSuper ? "super" : "this";
299 int offset = offsetForToken(token); 300 int offset = offsetForToken(token);
300 return helper.buildInvalidIntializer( 301 return helper.buildInvalidIntializer(
301 helper.buildCompileTimeError( 302 helper.buildCompileTimeError(
302 "Can't use '$keyword' here, did you mean '$keyword()'?", offset), 303 "Can't use '$keyword' here, did you mean '$keyword()'?", offset),
303 offset); 304 offset);
304 } 305 }
305 306
306 buildPropertyAccess( 307 buildPropertyAccess(
307 IncompleteSend send, int operatorOffset, bool isNullAware) { 308 IncompleteSend send, int operatorOffset, bool isNullAware) {
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 773
773 String get plainNameForRead => name.name; 774 String get plainNameForRead => name.name;
774 775
775 Expression doInvocation(int offset, Arguments arguments) { 776 Expression doInvocation(int offset, Arguments arguments) {
776 return internalError("Not implemented yet."); 777 return internalError("Not implemented yet.");
777 } 778 }
778 779
779 toString() => "NullAwarePropertyAccessor()"; 780 toString() => "NullAwarePropertyAccessor()";
780 } 781 }
781 782
783 int adjustForImplicitCall(String name, int offset) {
784 // Normally the offset is at the start of the token, but in this case,
785 // because we insert a '.call', we want it at the end instead.
786 return offset + (name?.length ?? 0);
787 }
788
782 class VariableAccessor extends kernel.VariableAccessor with FastaAccessor { 789 class VariableAccessor extends kernel.VariableAccessor with FastaAccessor {
783 VariableAccessor( 790 VariableAccessor(
784 BuilderHelper helper, Token token, VariableDeclaration variable, 791 BuilderHelper helper, Token token, VariableDeclaration variable,
785 [DartType promotedType]) 792 [DartType promotedType])
786 : super(helper, variable, promotedType, token); 793 : super(helper, variable, promotedType, token);
787 794
788 String get plainNameForRead => variable.name; 795 String get plainNameForRead => variable.name;
789 796
790 Expression doInvocation(int offset, Arguments arguments) { 797 Expression doInvocation(int offset, Arguments arguments) {
791 // Normally the offset is at the start of the token, but in this case,
792 // because we insert a '.call', we want it at the end instead.
793 return helper.buildMethodInvocation(buildSimpleRead(), callName, arguments, 798 return helper.buildMethodInvocation(buildSimpleRead(), callName, arguments,
794 offset + (variable.name?.length ?? 0)); 799 adjustForImplicitCall(plainNameForRead, offset));
795 } 800 }
796 801
797 toString() => "VariableAccessor()"; 802 toString() => "VariableAccessor()";
798 } 803 }
799 804
800 class ReadOnlyAccessor extends kernel.ReadOnlyAccessor with FastaAccessor { 805 class ReadOnlyAccessor extends kernel.ReadOnlyAccessor with FastaAccessor {
801 final String plainNameForRead; 806 final String plainNameForRead;
802 807
803 ReadOnlyAccessor(BuilderHelper helper, Expression expression, 808 ReadOnlyAccessor(BuilderHelper helper, Expression expression,
804 this.plainNameForRead, Token token) 809 this.plainNameForRead, Token token)
805 : super(helper, expression, token); 810 : super(helper, expression, token);
806 811
807 Expression doInvocation(int offset, Arguments arguments) { 812 Expression doInvocation(int offset, Arguments arguments) {
808 return helper.buildMethodInvocation( 813 return helper.buildMethodInvocation(buildSimpleRead(), callName, arguments,
809 buildSimpleRead(), callName, arguments, offset); 814 adjustForImplicitCall(plainNameForRead, offset));
810 } 815 }
811 } 816 }
812 817
813 class ParenthesizedExpression extends ReadOnlyAccessor { 818 class ParenthesizedExpression extends ReadOnlyAccessor {
814 ParenthesizedExpression( 819 ParenthesizedExpression(
815 BuilderHelper helper, Expression expression, Token token) 820 BuilderHelper helper, Expression expression, Token token)
816 : super(helper, expression, "<a parenthesized expression>", token); 821 : super(helper, expression, null, token);
ahe 2017/06/06 09:32:34 This debug name was passed to adjustForImplicitCal
817 822
818 Expression makeInvalidWrite(Expression value) { 823 Expression makeInvalidWrite(Expression value) {
819 return helper.buildCompileTimeError( 824 return helper.buildCompileTimeError(
820 "Can't assign to a parenthesized expression.", offsetForToken(token)); 825 "Can't assign to a parenthesized expression.", offsetForToken(token));
821 } 826 }
822 } 827 }
823 828
824 class TypeDeclarationAccessor extends ReadOnlyAccessor { 829 class TypeDeclarationAccessor extends ReadOnlyAccessor {
825 final TypeDeclarationBuilder declaration; 830 final TypeDeclarationBuilder declaration;
826 831
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 {bool isGetter: false, bool isSetter: false, int offset}) { 935 {bool isGetter: false, bool isSetter: false, int offset}) {
931 return helper.throwNoSuchMethodError( 936 return helper.throwNoSuchMethodError(
932 plainNameForRead, arguments, offset ?? offsetForToken(this.token), 937 plainNameForRead, arguments, offset ?? offsetForToken(this.token),
933 isGetter: isGetter, isSetter: isSetter); 938 isGetter: isGetter, isSetter: isSetter);
934 } 939 }
935 } 940 }
936 941
937 bool isFieldOrGetter(Member member) { 942 bool isFieldOrGetter(Member member) {
938 return member is Field || (member is Procedure && member.isGetter); 943 return member is Field || (member is Procedure && member.isGetter);
939 } 944 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698