| 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; | 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 140 |
| 141 Expression makeInvalidWrite(Expression value) { | 141 Expression makeInvalidWrite(Expression value) { |
| 142 return buildThrowNoSuchMethodError(new KernelArguments(<Expression>[value]), | 142 return buildThrowNoSuchMethodError(new KernelArguments(<Expression>[value]), |
| 143 isSetter: true); | 143 isSetter: true); |
| 144 } | 144 } |
| 145 | 145 |
| 146 /* Expression | FastaAccessor | Initializer */ doInvocation( | 146 /* Expression | FastaAccessor | Initializer */ doInvocation( |
| 147 int offset, Arguments arguments); | 147 int offset, Arguments arguments); |
| 148 | 148 |
| 149 /* Expression | FastaAccessor */ buildPropertyAccess( | 149 /* Expression | FastaAccessor */ buildPropertyAccess( |
| 150 IncompleteSend send, bool isNullAware) { | 150 IncompleteSend send, int operatorOffset, bool isNullAware) { |
| 151 if (send is SendAccessor) { | 151 if (send is SendAccessor) { |
| 152 return helper.buildMethodInvocation(buildSimpleRead(), send.name, | 152 return helper.buildMethodInvocation(buildSimpleRead(), send.name, |
| 153 send.arguments, offsetForToken(send.token), | 153 send.arguments, offsetForToken(send.token), |
| 154 isNullAware: isNullAware); | 154 isNullAware: isNullAware); |
| 155 } else { | 155 } else { |
| 156 if (helper.constantExpressionRequired && send.name != lengthName) { | 156 if (helper.constantExpressionRequired && send.name != lengthName) { |
| 157 helper.addCompileTimeError( | 157 helper.addCompileTimeError( |
| 158 offsetForToken(token), "Not a constant expression."); | 158 offsetForToken(token), "Not a constant expression."); |
| 159 } | 159 } |
| 160 return PropertyAccessor.make(helper, send.token, buildSimpleRead(), | 160 return PropertyAccessor.make(helper, send.token, buildSimpleRead(), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 182 /// most one of [isGetter] and [isSetter] should be true and they're passed | 182 /// most one of [isGetter] and [isSetter] should be true and they're passed |
| 183 /// to [BuilderHelper.buildThrowNoSuchMethodError] if it is used. | 183 /// to [BuilderHelper.buildThrowNoSuchMethodError] if it is used. |
| 184 Expression buildError(Arguments arguments, | 184 Expression buildError(Arguments arguments, |
| 185 {bool isGetter: false, bool isSetter: false, int offset}); | 185 {bool isGetter: false, bool isSetter: false, int offset}); |
| 186 | 186 |
| 187 Name get name => internalError("Unsupported operation."); | 187 Name get name => internalError("Unsupported operation."); |
| 188 | 188 |
| 189 @override | 189 @override |
| 190 String get plainNameForRead => name.name; | 190 String get plainNameForRead => name.name; |
| 191 | 191 |
| 192 withReceiver(Object receiver, {bool isNullAware}) => this; | 192 withReceiver(Object receiver, int operatorOffset, {bool isNullAware}) => this; |
| 193 | 193 |
| 194 @override | 194 @override |
| 195 Initializer buildFieldInitializer( | 195 Initializer buildFieldInitializer( |
| 196 Map<String, FieldInitializer> initializers) { | 196 Map<String, FieldInitializer> initializers) { |
| 197 return helper.buildInvalidIntializer( | 197 return helper.buildInvalidIntializer( |
| 198 buildError(new Arguments.empty(), isSetter: true)); | 198 buildError(new Arguments.empty(), isSetter: true)); |
| 199 } | 199 } |
| 200 | 200 |
| 201 @override | 201 @override |
| 202 doInvocation(int offset, Arguments arguments) { | 202 doInvocation(int offset, Arguments arguments) { |
| 203 return buildError(arguments, offset: offset); | 203 return buildError(arguments, offset: offset); |
| 204 } | 204 } |
| 205 | 205 |
| 206 @override | 206 @override |
| 207 buildPropertyAccess(IncompleteSend send, bool isNullAware) => this; | 207 buildPropertyAccess( |
| 208 IncompleteSend send, int operatorOffset, bool isNullAware) { |
| 209 return this; |
| 210 } |
| 208 | 211 |
| 209 @override | 212 @override |
| 210 buildThrowNoSuchMethodError(Arguments arguments, | 213 buildThrowNoSuchMethodError(Arguments arguments, |
| 211 {bool isSuper: false, | 214 {bool isSuper: false, |
| 212 isGetter: false, | 215 isGetter: false, |
| 213 isSetter: false, | 216 isSetter: false, |
| 214 String name, | 217 String name, |
| 215 int offset}) { | 218 int offset}) { |
| 216 return this; | 219 return this; |
| 217 } | 220 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 Initializer buildFieldInitializer( | 296 Initializer buildFieldInitializer( |
| 294 Map<String, FieldInitializer> initializers) { | 297 Map<String, FieldInitializer> initializers) { |
| 295 String keyword = isSuper ? "super" : "this"; | 298 String keyword = isSuper ? "super" : "this"; |
| 296 int offset = offsetForToken(token); | 299 int offset = offsetForToken(token); |
| 297 return helper.buildInvalidIntializer( | 300 return helper.buildInvalidIntializer( |
| 298 helper.buildCompileTimeError( | 301 helper.buildCompileTimeError( |
| 299 "Can't use '$keyword' here, did you mean '$keyword()'?", offset), | 302 "Can't use '$keyword' here, did you mean '$keyword()'?", offset), |
| 300 offset); | 303 offset); |
| 301 } | 304 } |
| 302 | 305 |
| 303 buildPropertyAccess(IncompleteSend send, bool isNullAware) { | 306 buildPropertyAccess( |
| 307 IncompleteSend send, int operatorOffset, bool isNullAware) { |
| 304 if (isInitializer && send is SendAccessor) { | 308 if (isInitializer && send is SendAccessor) { |
| 305 return buildConstructorInitializer( | 309 return buildConstructorInitializer( |
| 306 offsetForToken(send.token), send.name, send.arguments); | 310 offsetForToken(send.token), send.name, send.arguments); |
| 307 } | 311 } |
| 308 if (send is SendAccessor) { | 312 if (send is SendAccessor) { |
| 309 // Notice that 'this' or 'super' can't be null. So we can ignore the | 313 // Notice that 'this' or 'super' can't be null. So we can ignore the |
| 310 // value of [isNullAware]. | 314 // value of [isNullAware]. |
| 311 MethodInvocation result = helper.buildMethodInvocation( | 315 MethodInvocation result = helper.buildMethodInvocation( |
| 312 new ThisExpression(), | 316 new ThisExpression(), |
| 313 send.name, | 317 send.name, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 abstract class IncompleteSend extends FastaAccessor { | 402 abstract class IncompleteSend extends FastaAccessor { |
| 399 final BuilderHelper helper; | 403 final BuilderHelper helper; |
| 400 | 404 |
| 401 @override | 405 @override |
| 402 final Token token; | 406 final Token token; |
| 403 | 407 |
| 404 final Name name; | 408 final Name name; |
| 405 | 409 |
| 406 IncompleteSend(this.helper, this.token, this.name); | 410 IncompleteSend(this.helper, this.token, this.name); |
| 407 | 411 |
| 408 withReceiver(Object receiver, {bool isNullAware}); | 412 withReceiver(Object receiver, int operatorOffset, {bool isNullAware}); |
| 409 | 413 |
| 410 Arguments get arguments => null; | 414 Arguments get arguments => null; |
| 411 } | 415 } |
| 412 | 416 |
| 413 class IncompleteError extends IncompleteSend with ErrorAccessor { | 417 class IncompleteError extends IncompleteSend with ErrorAccessor { |
| 414 final Object error; | 418 final Object error; |
| 415 | 419 |
| 416 IncompleteError(BuilderHelper helper, Token token, this.error) | 420 IncompleteError(BuilderHelper helper, Token token, this.error) |
| 417 : super(helper, token, null); | 421 : super(helper, token, null); |
| 418 | 422 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 439 String get plainNameForRead => name.name; | 443 String get plainNameForRead => name.name; |
| 440 | 444 |
| 441 Expression buildSimpleRead() { | 445 Expression buildSimpleRead() { |
| 442 return internalError("Unhandled"); | 446 return internalError("Unhandled"); |
| 443 } | 447 } |
| 444 | 448 |
| 445 Expression buildAssignment(Expression value, {bool voidContext: false}) { | 449 Expression buildAssignment(Expression value, {bool voidContext: false}) { |
| 446 return internalError("Unhandled"); | 450 return internalError("Unhandled"); |
| 447 } | 451 } |
| 448 | 452 |
| 449 withReceiver(Object receiver, {bool isNullAware: false}) { | 453 withReceiver(Object receiver, int operatorOffset, {bool isNullAware: false}) { |
| 450 if (receiver is FastaAccessor) { | 454 if (receiver is FastaAccessor) { |
| 451 return receiver.buildPropertyAccess(this, isNullAware); | 455 return receiver.buildPropertyAccess(this, operatorOffset, isNullAware); |
| 452 } | 456 } |
| 453 if (receiver is PrefixBuilder) { | 457 if (receiver is PrefixBuilder) { |
| 454 PrefixBuilder prefix = receiver; | 458 PrefixBuilder prefix = receiver; |
| 455 receiver = helper.scopeLookup(prefix.exports, name.name, token, | 459 receiver = helper.scopeLookup(prefix.exports, name.name, token, |
| 456 isQualified: true, prefix: prefix); | 460 isQualified: true, prefix: prefix); |
| 457 return helper.finishSend(receiver, arguments, offsetForToken(token)); | 461 return helper.finishSend(receiver, arguments, offsetForToken(token)); |
| 458 } | 462 } |
| 459 return helper.buildMethodInvocation( | 463 return helper.buildMethodInvocation( |
| 460 helper.toValue(receiver), name, arguments, offsetForToken(token), | 464 helper.toValue(receiver), name, arguments, offsetForToken(token), |
| 461 isNullAware: isNullAware); | 465 isNullAware: isNullAware); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 : super(helper, token, name); | 500 : super(helper, token, name); |
| 497 | 501 |
| 498 String get plainNameForRead => name.name; | 502 String get plainNameForRead => name.name; |
| 499 | 503 |
| 500 Expression buildSimpleRead() => internalError("Unhandled"); | 504 Expression buildSimpleRead() => internalError("Unhandled"); |
| 501 | 505 |
| 502 Expression buildAssignment(Expression value, {bool voidContext: false}) { | 506 Expression buildAssignment(Expression value, {bool voidContext: false}) { |
| 503 return internalError("Unhandled"); | 507 return internalError("Unhandled"); |
| 504 } | 508 } |
| 505 | 509 |
| 506 withReceiver(Object receiver, {bool isNullAware: false}) { | 510 withReceiver(Object receiver, int operatorOffset, {bool isNullAware: false}) { |
| 507 if (receiver is FastaAccessor) { | 511 if (receiver is FastaAccessor) { |
| 508 return receiver.buildPropertyAccess(this, isNullAware); | 512 return receiver.buildPropertyAccess(this, operatorOffset, isNullAware); |
| 509 } | 513 } |
| 510 if (receiver is PrefixBuilder) { | 514 if (receiver is PrefixBuilder) { |
| 511 PrefixBuilder prefix = receiver; | 515 PrefixBuilder prefix = receiver; |
| 512 return helper.scopeLookup(prefix.exports, name.name, token, | 516 return helper.scopeLookup(prefix.exports, name.name, token, |
| 513 isQualified: true, prefix: prefix); | 517 isQualified: true, prefix: prefix); |
| 514 } | 518 } |
| 515 | 519 |
| 516 return PropertyAccessor.make( | 520 return PropertyAccessor.make( |
| 517 helper, token, helper.toValue(receiver), name, null, null, isNullAware); | 521 helper, token, helper.toValue(receiver), name, null, null, isNullAware); |
| 518 } | 522 } |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 return super.expression; | 849 return super.expression; |
| 846 } | 850 } |
| 847 | 851 |
| 848 Expression makeInvalidWrite(Expression value) { | 852 Expression makeInvalidWrite(Expression value) { |
| 849 return buildThrowNoSuchMethodError( | 853 return buildThrowNoSuchMethodError( |
| 850 new Arguments(<Expression>[value])..fileOffset = value.fileOffset, | 854 new Arguments(<Expression>[value])..fileOffset = value.fileOffset, |
| 851 isSetter: true); | 855 isSetter: true); |
| 852 } | 856 } |
| 853 | 857 |
| 854 @override | 858 @override |
| 855 buildPropertyAccess(IncompleteSend send, bool isNullAware) { | 859 buildPropertyAccess( |
| 860 IncompleteSend send, int operatorOffset, bool isNullAware) { |
| 856 // `SomeType?.toString` is the same as `SomeType.toString`, not | 861 // `SomeType?.toString` is the same as `SomeType.toString`, not |
| 857 // `(SomeType).toString`. | 862 // `(SomeType).toString`. |
| 858 isNullAware = false; | 863 isNullAware = false; |
| 859 | 864 |
| 860 Name name = send.name; | 865 Name name = send.name; |
| 861 Arguments arguments = send.arguments; | 866 Arguments arguments = send.arguments; |
| 862 | 867 |
| 863 if (declaration is KernelClassBuilder) { | 868 if (declaration is KernelClassBuilder) { |
| 864 KernelClassBuilder declaration = this.declaration; | 869 KernelClassBuilder declaration = this.declaration; |
| 865 Builder builder = declaration.findStaticBuilder( | 870 Builder builder = declaration.findStaticBuilder( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 881 setter = builder; | 886 setter = builder; |
| 882 } | 887 } |
| 883 accessor = | 888 accessor = |
| 884 new StaticAccessor.fromBuilder(helper, builder, send.token, setter); | 889 new StaticAccessor.fromBuilder(helper, builder, send.token, setter); |
| 885 } | 890 } |
| 886 | 891 |
| 887 return arguments == null | 892 return arguments == null |
| 888 ? accessor | 893 ? accessor |
| 889 : accessor.doInvocation(offsetForToken(send.token), arguments); | 894 : accessor.doInvocation(offsetForToken(send.token), arguments); |
| 890 } else { | 895 } else { |
| 891 return super.buildPropertyAccess(send, isNullAware); | 896 return super.buildPropertyAccess(send, operatorOffset, isNullAware); |
| 892 } | 897 } |
| 893 } | 898 } |
| 894 | 899 |
| 895 DartType buildType(List<DartType> arguments, | 900 DartType buildType(List<DartType> arguments, |
| 896 {bool nonInstanceAccessIsError: false}) { | 901 {bool nonInstanceAccessIsError: false}) { |
| 897 DartType type = | 902 DartType type = |
| 898 declaration.buildTypesWithBuiltArguments(helper.library, arguments); | 903 declaration.buildTypesWithBuiltArguments(helper.library, arguments); |
| 899 if (type is TypeParameterType) { | 904 if (type is TypeParameterType) { |
| 900 return helper.validatedTypeVariableUse( | 905 return helper.validatedTypeVariableUse( |
| 901 type, offsetForToken(token), nonInstanceAccessIsError); | 906 type, offsetForToken(token), nonInstanceAccessIsError); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 925 {bool isGetter: false, bool isSetter: false, int offset}) { | 930 {bool isGetter: false, bool isSetter: false, int offset}) { |
| 926 return helper.throwNoSuchMethodError( | 931 return helper.throwNoSuchMethodError( |
| 927 plainNameForRead, arguments, offset ?? offsetForToken(this.token), | 932 plainNameForRead, arguments, offset ?? offsetForToken(this.token), |
| 928 isGetter: isGetter, isSetter: isSetter); | 933 isGetter: isGetter, isSetter: isSetter); |
| 929 } | 934 } |
| 930 } | 935 } |
| 931 | 936 |
| 932 bool isFieldOrGetter(Member member) { | 937 bool isFieldOrGetter(Member member) { |
| 933 return member is Field || (member is Procedure && member.isGetter); | 938 return member is Field || (member is Procedure && member.isGetter); |
| 934 } | 939 } |
| OLD | NEW |