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 '../fasta_codes.dart' | 7 import '../fasta_codes.dart' |
8 show | 8 show |
9 FastaMessage, | 9 FastaMessage, |
10 codeConstFieldWithoutInitializer, | 10 codeConstFieldWithoutInitializer, |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 void doDotOrCascadeExpression(Token token) { | 894 void doDotOrCascadeExpression(Token token) { |
895 // TODO(ahe): Handle null-aware. | 895 // TODO(ahe): Handle null-aware. |
896 IncompleteSend send = pop(); | 896 IncompleteSend send = pop(); |
897 Object receiver = optional(".", token) ? pop() : popForValue(); | 897 Object receiver = optional(".", token) ? pop() : popForValue(); |
898 push(send.withReceiver(receiver, token.charOffset)); | 898 push(send.withReceiver(receiver, token.charOffset)); |
899 } | 899 } |
900 | 900 |
901 @override | 901 @override |
902 Expression toSuperMethodInvocation(MethodInvocation node) { | 902 Expression toSuperMethodInvocation(MethodInvocation node) { |
903 Member target = lookupSuperMember(node.name); | 903 Member target = lookupSuperMember(node.name); |
904 bool isNoSuchMethod = target == null; | 904 if (target == null || (target is Procedure && !target.isAccessor)) { |
905 if (target is Procedure) { | 905 if (target == null) { |
906 if (!target.isAccessor) { | 906 warnUnresolvedSuperMethod(node.name, node.fileOffset); |
907 if (areArgumentsCompatible(target.function, node.arguments)) { | 907 } else if (!areArgumentsCompatible(target.function, node.arguments)) { |
908 Expression result = new KernelDirectMethodInvocation( | 908 target = null; |
909 new KernelThisExpression()..fileOffset = node.fileOffset, | 909 warning( |
910 target, | 910 "Super class doesn't have a method named '${node.name.name}' " |
911 node.arguments) | 911 "with matching arguments.", |
912 ..fileOffset = node.fileOffset; | 912 node.fileOffset); |
913 // TODO(ahe): Use [DirectMethodInvocation] when possible, that is, | |
914 // remove the next line: | |
915 result = | |
916 new KernelSuperMethodInvocation(node.name, node.arguments, target) | |
917 ..fileOffset = node.fileOffset; | |
918 return result; | |
919 } else { | |
920 isNoSuchMethod = true; | |
921 } | |
922 } | 913 } |
| 914 Expression result; |
| 915 if (target != null) { |
| 916 result = new KernelDirectMethodInvocation( |
| 917 new KernelThisExpression()..fileOffset = node.fileOffset, |
| 918 target, |
| 919 node.arguments); |
| 920 } |
| 921 // TODO(ahe): Use [DirectMethodInvocation] when possible, that is, |
| 922 // make the next line conditional: |
| 923 result = |
| 924 new KernelSuperMethodInvocation(node.name, node.arguments, target); |
| 925 return result..fileOffset = node.fileOffset; |
923 } | 926 } |
924 if (isNoSuchMethod) { | 927 |
925 return invokeSuperNoSuchMethod( | |
926 node.name.name, node.arguments, node.fileOffset); | |
927 } | |
928 Expression receiver = new KernelDirectPropertyGet( | 928 Expression receiver = new KernelDirectPropertyGet( |
929 new KernelThisExpression()..fileOffset = node.fileOffset, target) | 929 new KernelThisExpression()..fileOffset = node.fileOffset, target) |
930 ..fileOffset = node.fileOffset; | 930 ..fileOffset = node.fileOffset; |
931 // TODO(ahe): Use [DirectPropertyGet] when possible, that is, remove the | 931 // TODO(ahe): Use [DirectPropertyGet] when possible, that is, make the next |
932 // next line: | 932 // line conditional: |
933 receiver = new KernelSuperPropertyGet(node.name, target) | 933 receiver = new KernelSuperPropertyGet(node.name, target) |
934 ..fileOffset = node.fileOffset; | 934 ..fileOffset = node.fileOffset; |
935 return buildMethodInvocation( | 935 return buildMethodInvocation( |
936 receiver, callName, node.arguments, node.arguments.fileOffset, | 936 receiver, callName, node.arguments, node.arguments.fileOffset, |
937 isImplicitCall: true); | 937 isImplicitCall: true); |
938 } | 938 } |
939 | 939 |
940 bool areArgumentsCompatible(FunctionNode function, Arguments arguments) { | 940 bool areArgumentsCompatible(FunctionNode function, Arguments arguments) { |
941 // TODO(ahe): Implement this. | 941 // TODO(ahe): Implement this. |
942 return true; | 942 return true; |
(...skipping 27 matching lines...) Expand all Loading... |
970 isGetter: isGetter, | 970 isGetter: isGetter, |
971 isSetter: isSetter, | 971 isSetter: isSetter, |
972 isStatic: isStatic, | 972 isStatic: isStatic, |
973 isTopLevel: !isStatic && !isSuper); | 973 isTopLevel: !isStatic && !isSuper); |
974 warning(message, charOffset); | 974 warning(message, charOffset); |
975 return new Throw(error); | 975 return new Throw(error); |
976 } | 976 } |
977 } | 977 } |
978 | 978 |
979 @override | 979 @override |
980 Expression invokeSuperNoSuchMethod( | 980 void warnUnresolvedSuperGet(Name name, int charOffset) { |
981 String name, Arguments arguments, int charOffset, | 981 warning("Super class has no getter named '${name.name}'.", charOffset); |
982 {bool isGetter: false, bool isSetter: false}) { | |
983 String errorName = "super.$name"; | |
984 String message; | |
985 if (isGetter) { | |
986 message = "Getter not found: '$errorName'."; | |
987 name = "get:$name"; | |
988 } else if (isSetter) { | |
989 message = "Setter not found: '$errorName'."; | |
990 name = "set:$name"; | |
991 } else { | |
992 message = "Method not found: '$errorName'."; | |
993 } | |
994 warning(message, charOffset); | |
995 VariableDeclaration value; | |
996 if (isSetter) { | |
997 value = new VariableDeclaration.forValue(arguments.positional.single, | |
998 isFinal: true) | |
999 ..fileOffset = charOffset; | |
1000 arguments = new Arguments(<Expression>[ | |
1001 new VariableGet(value)..fileOffset = arguments.fileOffset | |
1002 ]); | |
1003 } | |
1004 Expression result = new SuperMethodInvocation( | |
1005 noSuchMethodName, | |
1006 new Arguments(<Expression>[ | |
1007 library.loader.instantiateInvocation( | |
1008 new KernelThisExpression()..fileOffset = charOffset, | |
1009 name, | |
1010 arguments, | |
1011 charOffset, | |
1012 true) | |
1013 ]) | |
1014 ..fileOffset = arguments.fileOffset); | |
1015 if (isSetter) { | |
1016 result = new Let( | |
1017 value, | |
1018 new Let( | |
1019 new VariableDeclaration.forValue(result, isFinal: true) | |
1020 ..fileOffset = charOffset, | |
1021 new VariableGet(value)..fileOffset = value.fileOffset)) | |
1022 ..fileOffset = charOffset; | |
1023 } | |
1024 return result; | |
1025 } | 982 } |
1026 | 983 |
1027 @override | 984 @override |
| 985 void warnUnresolvedSuperSet(Name name, int charOffset) { |
| 986 warning("Super class has no setter named '${name.name}'.", charOffset); |
| 987 } |
| 988 |
| 989 @override |
| 990 void warnUnresolvedSuperMethod(Name name, int charOffset) { |
| 991 warning("Super class has no method named '${name.name}'.", charOffset); |
| 992 } |
| 993 |
| 994 @override |
1028 Member lookupSuperMember(Name name, {bool isSetter: false}) { | 995 Member lookupSuperMember(Name name, {bool isSetter: false}) { |
1029 Class superclass = classBuilder.cls.superclass; | 996 Class superclass = classBuilder.cls.superclass; |
1030 return superclass == null | 997 return superclass == null |
1031 ? null | 998 ? null |
1032 : hierarchy.getDispatchTarget(superclass, name, setter: isSetter); | 999 : hierarchy.getDispatchTarget(superclass, name, setter: isSetter); |
1033 } | 1000 } |
1034 | 1001 |
1035 @override | 1002 @override |
1036 Constructor lookupConstructor(Name name, {bool isSuper}) { | 1003 Constructor lookupConstructor(Name name, {bool isSuper}) { |
1037 Class cls = classBuilder.cls; | 1004 Class cls = classBuilder.cls; |
(...skipping 2666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3704 if (starToken == null) { | 3671 if (starToken == null) { |
3705 return AsyncMarker.Async; | 3672 return AsyncMarker.Async; |
3706 } else { | 3673 } else { |
3707 assert(identical(starToken.stringValue, "*")); | 3674 assert(identical(starToken.stringValue, "*")); |
3708 return AsyncMarker.AsyncStar; | 3675 return AsyncMarker.AsyncStar; |
3709 } | 3676 } |
3710 } else { | 3677 } else { |
3711 return internalError("Unknown async modifier: $asyncToken"); | 3678 return internalError("Unknown async modifier: $asyncToken"); |
3712 } | 3679 } |
3713 } | 3680 } |
OLD | NEW |