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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 int offset = offsetForToken(token); | 314 int offset = offsetForToken(token); |
315 return helper.buildInvalidInitializer( | 315 return helper.buildInvalidInitializer( |
316 helper.buildCompileTimeError( | 316 helper.buildCompileTimeError( |
317 "Can't use '$keyword' here, did you mean '$keyword()'?", offset), | 317 "Can't use '$keyword' here, did you mean '$keyword()'?", offset), |
318 offset); | 318 offset); |
319 } | 319 } |
320 | 320 |
321 buildPropertyAccess( | 321 buildPropertyAccess( |
322 IncompleteSend send, int operatorOffset, bool isNullAware) { | 322 IncompleteSend send, int operatorOffset, bool isNullAware) { |
323 if (isInitializer && send is SendAccessor) { | 323 if (isInitializer && send is SendAccessor) { |
| 324 if (isNullAware) { |
| 325 helper.addCompileTimeError( |
| 326 operatorOffset, "Expected '.'\nTry removing '?'."); |
| 327 } |
324 return buildConstructorInitializer( | 328 return buildConstructorInitializer( |
325 offsetForToken(send.token), send.name, send.arguments); | 329 offsetForToken(send.token), send.name, send.arguments); |
326 } | 330 } |
327 if (send is SendAccessor) { | 331 if (send is SendAccessor) { |
328 // Notice that 'this' or 'super' can't be null. So we can ignore the | 332 // Notice that 'this' or 'super' can't be null. So we can ignore the |
329 // value of [isNullAware]. | 333 // value of [isNullAware]. |
330 MethodInvocation result = helper.buildMethodInvocation( | 334 MethodInvocation result = helper.buildMethodInvocation( |
331 new KernelThisExpression(), | 335 new KernelThisExpression(), |
332 send.name, | 336 send.name, |
333 send.arguments, | 337 send.arguments, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 Expression buildAssignment(Expression value, {bool voidContext: false}) { | 470 Expression buildAssignment(Expression value, {bool voidContext: false}) { |
467 return internalError("Unhandled"); | 471 return internalError("Unhandled"); |
468 } | 472 } |
469 | 473 |
470 withReceiver(Object receiver, int operatorOffset, {bool isNullAware: false}) { | 474 withReceiver(Object receiver, int operatorOffset, {bool isNullAware: false}) { |
471 if (receiver is FastaAccessor) { | 475 if (receiver is FastaAccessor) { |
472 return receiver.buildPropertyAccess(this, operatorOffset, isNullAware); | 476 return receiver.buildPropertyAccess(this, operatorOffset, isNullAware); |
473 } | 477 } |
474 if (receiver is PrefixBuilder) { | 478 if (receiver is PrefixBuilder) { |
475 PrefixBuilder prefix = receiver; | 479 PrefixBuilder prefix = receiver; |
| 480 if (isNullAware) { |
| 481 helper.addCompileTimeError( |
| 482 offsetForToken(token), |
| 483 "Library prefix '${prefix.name}' can't be used with null-aware " |
| 484 "operator.\nTry removing '?'."); |
| 485 } |
476 receiver = helper.scopeLookup(prefix.exports, name.name, token, | 486 receiver = helper.scopeLookup(prefix.exports, name.name, token, |
477 isQualified: true, prefix: prefix); | 487 isQualified: true, prefix: prefix); |
478 return helper.finishSend(receiver, arguments, offsetForToken(token)); | 488 return helper.finishSend(receiver, arguments, offsetForToken(token)); |
479 } | 489 } |
480 return helper.buildMethodInvocation( | 490 return helper.buildMethodInvocation( |
481 helper.toValue(receiver), name, arguments, offsetForToken(token), | 491 helper.toValue(receiver), name, arguments, offsetForToken(token), |
482 isNullAware: isNullAware); | 492 isNullAware: isNullAware); |
483 } | 493 } |
484 | 494 |
485 Expression buildNullAwareAssignment(Expression value, DartType type, | 495 Expression buildNullAwareAssignment(Expression value, DartType type, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 Expression buildAssignment(Expression value, {bool voidContext: false}) { | 533 Expression buildAssignment(Expression value, {bool voidContext: false}) { |
524 return internalError("Unhandled"); | 534 return internalError("Unhandled"); |
525 } | 535 } |
526 | 536 |
527 withReceiver(Object receiver, int operatorOffset, {bool isNullAware: false}) { | 537 withReceiver(Object receiver, int operatorOffset, {bool isNullAware: false}) { |
528 if (receiver is FastaAccessor) { | 538 if (receiver is FastaAccessor) { |
529 return receiver.buildPropertyAccess(this, operatorOffset, isNullAware); | 539 return receiver.buildPropertyAccess(this, operatorOffset, isNullAware); |
530 } | 540 } |
531 if (receiver is PrefixBuilder) { | 541 if (receiver is PrefixBuilder) { |
532 PrefixBuilder prefix = receiver; | 542 PrefixBuilder prefix = receiver; |
| 543 if (isNullAware) { |
| 544 helper.addCompileTimeError( |
| 545 offsetForToken(token), |
| 546 "Library prefix '${prefix.name}' can't be used with null-aware " |
| 547 "operator.\nTry removing '?'."); |
| 548 } |
533 return helper.scopeLookup(prefix.exports, name.name, token, | 549 return helper.scopeLookup(prefix.exports, name.name, token, |
534 isQualified: true, prefix: prefix); | 550 isQualified: true, prefix: prefix); |
535 } | 551 } |
536 | 552 |
537 return PropertyAccessor.make( | 553 return PropertyAccessor.make( |
538 helper, token, helper.toValue(receiver), name, null, null, isNullAware); | 554 helper, token, helper.toValue(receiver), name, null, null, isNullAware); |
539 } | 555 } |
540 | 556 |
541 Expression buildNullAwareAssignment(Expression value, DartType type, | 557 Expression buildNullAwareAssignment(Expression value, DartType type, |
542 {bool voidContext: false}) { | 558 {bool voidContext: false}) { |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 offset ??= offsetForToken(this.token); | 987 offset ??= offsetForToken(this.token); |
972 return helper.throwNoSuchMethodError(new NullLiteral()..fileOffset = offset, | 988 return helper.throwNoSuchMethodError(new NullLiteral()..fileOffset = offset, |
973 plainNameForRead, arguments, offset, | 989 plainNameForRead, arguments, offset, |
974 isGetter: isGetter, isSetter: isSetter); | 990 isGetter: isGetter, isSetter: isSetter); |
975 } | 991 } |
976 } | 992 } |
977 | 993 |
978 bool isFieldOrGetter(Member member) { | 994 bool isFieldOrGetter(Member member) { |
979 return member is Field || (member is Procedure && member.isGetter); | 995 return member is Field || (member is Procedure && member.isGetter); |
980 } | 996 } |
OLD | NEW |