| 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, 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; |
| 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; | 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 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 279 |
| 280 final bool isSuper; | 280 final bool isSuper; |
| 281 | 281 |
| 282 ThisAccessor(this.helper, this.token, this.isInitializer, | 282 ThisAccessor(this.helper, this.token, this.isInitializer, |
| 283 {this.isSuper: false}); | 283 {this.isSuper: false}); |
| 284 | 284 |
| 285 String get plainNameForRead => internalError(isSuper ? "super" : "this"); | 285 String get plainNameForRead => internalError(isSuper ? "super" : "this"); |
| 286 | 286 |
| 287 Expression buildSimpleRead() { | 287 Expression buildSimpleRead() { |
| 288 if (!isSuper) { | 288 if (!isSuper) { |
| 289 return new ThisExpression(); | 289 return new KernelThisExpression(); |
| 290 } else { | 290 } else { |
| 291 return helper.buildCompileTimeError( | 291 return helper.buildCompileTimeError( |
| 292 "Can't use `super` as an expression.", offsetForToken(token)); | 292 "Can't use `super` as an expression.", offsetForToken(token)); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 Initializer buildFieldInitializer( | 296 Initializer buildFieldInitializer( |
| 297 Map<String, FieldInitializer> initializers) { | 297 Map<String, FieldInitializer> initializers) { |
| 298 String keyword = isSuper ? "super" : "this"; | 298 String keyword = isSuper ? "super" : "this"; |
| 299 int offset = offsetForToken(token); | 299 int offset = offsetForToken(token); |
| 300 return helper.buildInvalidIntializer( | 300 return helper.buildInvalidIntializer( |
| 301 helper.buildCompileTimeError( | 301 helper.buildCompileTimeError( |
| 302 "Can't use '$keyword' here, did you mean '$keyword()'?", offset), | 302 "Can't use '$keyword' here, did you mean '$keyword()'?", offset), |
| 303 offset); | 303 offset); |
| 304 } | 304 } |
| 305 | 305 |
| 306 buildPropertyAccess( | 306 buildPropertyAccess( |
| 307 IncompleteSend send, int operatorOffset, bool isNullAware) { | 307 IncompleteSend send, int operatorOffset, bool isNullAware) { |
| 308 if (isInitializer && send is SendAccessor) { | 308 if (isInitializer && send is SendAccessor) { |
| 309 return buildConstructorInitializer( | 309 return buildConstructorInitializer( |
| 310 offsetForToken(send.token), send.name, send.arguments); | 310 offsetForToken(send.token), send.name, send.arguments); |
| 311 } | 311 } |
| 312 if (send is SendAccessor) { | 312 if (send is SendAccessor) { |
| 313 // 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 |
| 314 // value of [isNullAware]. | 314 // value of [isNullAware]. |
| 315 MethodInvocation result = helper.buildMethodInvocation( | 315 MethodInvocation result = helper.buildMethodInvocation( |
| 316 new ThisExpression(), | 316 new KernelThisExpression(), |
| 317 send.name, | 317 send.name, |
| 318 send.arguments, | 318 send.arguments, |
| 319 offsetForToken(token)); | 319 offsetForToken(token)); |
| 320 return isSuper ? helper.toSuperMethodInvocation(result) : result; | 320 return isSuper ? helper.toSuperMethodInvocation(result) : result; |
| 321 } else { | 321 } else { |
| 322 if (isSuper) { | 322 if (isSuper) { |
| 323 Member getter = helper.lookupSuperMember(send.name); | 323 Member getter = helper.lookupSuperMember(send.name); |
| 324 Member setter = helper.lookupSuperMember(send.name, isSetter: true); | 324 Member setter = helper.lookupSuperMember(send.name, isSetter: true); |
| 325 return new SuperPropertyAccessor( | 325 return new SuperPropertyAccessor( |
| 326 helper, send.token, send.name, getter, setter); | 326 helper, send.token, send.name, getter, setter); |
| 327 } else { | 327 } else { |
| 328 return new ThisPropertyAccessor( | 328 return new ThisPropertyAccessor( |
| 329 helper, send.token, send.name, null, null); | 329 helper, send.token, send.name, null, null); |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 doInvocation(int offset, Arguments arguments) { | 334 doInvocation(int offset, Arguments arguments) { |
| 335 if (isInitializer) { | 335 if (isInitializer) { |
| 336 return buildConstructorInitializer(offset, new Name(""), arguments); | 336 return buildConstructorInitializer(offset, new Name(""), arguments); |
| 337 } else { | 337 } else { |
| 338 return helper.buildMethodInvocation( | 338 return helper.buildMethodInvocation( |
| 339 new ThisExpression(), callName, arguments, offset); | 339 new KernelThisExpression(), callName, arguments, offset); |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 | 342 |
| 343 Initializer buildConstructorInitializer( | 343 Initializer buildConstructorInitializer( |
| 344 int offset, Name name, Arguments arguments) { | 344 int offset, Name name, Arguments arguments) { |
| 345 Constructor constructor = helper.lookupConstructor(name, isSuper: isSuper); | 345 Constructor constructor = helper.lookupConstructor(name, isSuper: isSuper); |
| 346 if (constructor == null || | 346 if (constructor == null || |
| 347 !helper.checkArguments( | 347 !helper.checkArguments( |
| 348 constructor.function, arguments, <TypeParameter>[])) { | 348 constructor.function, arguments, <TypeParameter>[])) { |
| 349 return helper.buildInvalidIntializer( | 349 return helper.buildInvalidIntializer( |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 bool get isThisPropertyAccessor => true; | 749 bool get isThisPropertyAccessor => true; |
| 750 | 750 |
| 751 Expression doInvocation(int offset, Arguments arguments) { | 751 Expression doInvocation(int offset, Arguments arguments) { |
| 752 Member interfaceTarget = getter; | 752 Member interfaceTarget = getter; |
| 753 if (interfaceTarget is Field) { | 753 if (interfaceTarget is Field) { |
| 754 // TODO(ahe): In strong mode we should probably rewrite this to | 754 // TODO(ahe): In strong mode we should probably rewrite this to |
| 755 // `this.name.call(arguments)`. | 755 // `this.name.call(arguments)`. |
| 756 interfaceTarget = null; | 756 interfaceTarget = null; |
| 757 } | 757 } |
| 758 return helper.buildMethodInvocation( | 758 return helper.buildMethodInvocation( |
| 759 new ThisExpression(), name, arguments, offset); | 759 new KernelThisExpression(), name, arguments, offset); |
| 760 } | 760 } |
| 761 | 761 |
| 762 toString() => "ThisPropertyAccessor()"; | 762 toString() => "ThisPropertyAccessor()"; |
| 763 } | 763 } |
| 764 | 764 |
| 765 class NullAwarePropertyAccessor extends kernel.NullAwarePropertyAccessor | 765 class NullAwarePropertyAccessor extends kernel.NullAwarePropertyAccessor |
| 766 with FastaAccessor { | 766 with FastaAccessor { |
| 767 final BuilderHelper helper; | 767 final BuilderHelper helper; |
| 768 | 768 |
| 769 NullAwarePropertyAccessor(this.helper, Token token, Expression receiver, | 769 NullAwarePropertyAccessor(this.helper, Token token, Expression receiver, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 {bool isGetter: false, bool isSetter: false, int offset}) { | 930 {bool isGetter: false, bool isSetter: false, int offset}) { |
| 931 return helper.throwNoSuchMethodError( | 931 return helper.throwNoSuchMethodError( |
| 932 plainNameForRead, arguments, offset ?? offsetForToken(this.token), | 932 plainNameForRead, arguments, offset ?? offsetForToken(this.token), |
| 933 isGetter: isGetter, isSetter: isSetter); | 933 isGetter: isGetter, isSetter: isSetter); |
| 934 } | 934 } |
| 935 } | 935 } |
| 936 | 936 |
| 937 bool isFieldOrGetter(Member member) { | 937 bool isFieldOrGetter(Member member) { |
| 938 return member is Field || (member is Procedure && member.isGetter); | 938 return member is Field || (member is Procedure && member.isGetter); |
| 939 } | 939 } |
| OLD | NEW |