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.body_builder; | 5 library fasta.body_builder; |
6 | 6 |
7 import '../parser/parser.dart' show FormalParameterType, optional; | 7 import '../parser/parser.dart' show FormalParameterType, optional; |
8 | 8 |
9 import '../parser/error_kind.dart' show ErrorKind; | 9 import '../parser/error_kind.dart' show ErrorKind; |
10 | 10 |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 } | 510 } |
511 } else if (arguments == null) { | 511 } else if (arguments == null) { |
512 push(receiver); | 512 push(receiver); |
513 } else { | 513 } else { |
514 push(finishSend(receiver, arguments, beginToken.charOffset)); | 514 push(finishSend(receiver, arguments, beginToken.charOffset)); |
515 } | 515 } |
516 } | 516 } |
517 | 517 |
518 @override | 518 @override |
519 finishSend(Object receiver, Arguments arguments, int charOffset) { | 519 finishSend(Object receiver, Arguments arguments, int charOffset) { |
| 520 bool isIdentical(Object receiver) { |
| 521 return receiver is StaticAccessor && |
| 522 receiver.readTarget == |
| 523 coreTypes.tryGetTopLevelMember("dart:core", null, "identical"); |
| 524 } |
| 525 |
520 if (receiver is BuilderAccessor) { | 526 if (receiver is BuilderAccessor) { |
521 if (constantExpressionRequired) { | 527 if (constantExpressionRequired && !isIdentical(receiver)) { |
522 addCompileTimeError(charOffset, "Not a constant expression."); | 528 addCompileTimeError(charOffset, "Not a constant expression."); |
523 } | 529 } |
524 return receiver.doInvocation(charOffset, arguments); | 530 return receiver.doInvocation(charOffset, arguments); |
525 } else if (receiver is UnresolvedIdentifier) { | 531 } else if (receiver is UnresolvedIdentifier) { |
526 return throwNoSuchMethodError( | 532 return throwNoSuchMethodError( |
527 receiver.name.name, arguments, receiver.fileOffset); | 533 receiver.name.name, arguments, receiver.fileOffset); |
528 } else { | 534 } else { |
529 return buildMethodInvocation( | 535 return buildMethodInvocation( |
530 toValue(receiver), callName, arguments, charOffset); | 536 toValue(receiver), callName, arguments, charOffset); |
531 } | 537 } |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 setter = builder; | 798 setter = builder; |
793 } else if (builder.isGetter) { | 799 } else if (builder.isGetter) { |
794 setter = scope.lookupSetter(name, charOffset, uri); | 800 setter = scope.lookupSetter(name, charOffset, uri); |
795 } else if (builder.isField && !builder.isFinal) { | 801 } else if (builder.isField && !builder.isFinal) { |
796 setter = builder; | 802 setter = builder; |
797 } | 803 } |
798 StaticAccessor accessor = | 804 StaticAccessor accessor = |
799 new StaticAccessor.fromBuilder(this, builder, charOffset, setter); | 805 new StaticAccessor.fromBuilder(this, builder, charOffset, setter); |
800 if (constantExpressionRequired) { | 806 if (constantExpressionRequired) { |
801 Member readTarget = accessor.readTarget; | 807 Member readTarget = accessor.readTarget; |
802 if (!(readTarget is Field && readTarget.isConst)) { | 808 if (!(readTarget is Field && readTarget.isConst || |
| 809 // Static tear-offs are also compile time constants. |
| 810 readTarget is Procedure)) { |
803 addCompileTimeError(charOffset, "Not a constant expression."); | 811 addCompileTimeError(charOffset, "Not a constant expression."); |
804 } | 812 } |
805 } | 813 } |
806 return accessor; | 814 return accessor; |
807 } | 815 } |
808 } | 816 } |
809 | 817 |
810 @override | 818 @override |
811 void handleQualified(Token period) { | 819 void handleQualified(Token period) { |
812 debugEvent("Qualified"); | 820 debugEvent("Qualified"); |
(...skipping 2036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2849 } else if (node is PrefixBuilder) { | 2857 } else if (node is PrefixBuilder) { |
2850 return node.name; | 2858 return node.name; |
2851 } else if (node is ThisAccessor) { | 2859 } else if (node is ThisAccessor) { |
2852 return node.isSuper ? "super" : "this"; | 2860 return node.isSuper ? "super" : "this"; |
2853 } else if (node is BuilderAccessor) { | 2861 } else if (node is BuilderAccessor) { |
2854 return node.plainNameForRead; | 2862 return node.plainNameForRead; |
2855 } else { | 2863 } else { |
2856 return internalError("Unhandled: ${node.runtimeType}"); | 2864 return internalError("Unhandled: ${node.runtimeType}"); |
2857 } | 2865 } |
2858 } | 2866 } |
OLD | NEW |