Chromium Code Reviews| 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 FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; | 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; |
| 9 | 9 |
| 10 import '../parser/parser.dart' show FormalParameterType, optional; | 10 import '../parser/parser.dart' show FormalParameterType, optional; |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 | 570 |
| 571 @override | 571 @override |
| 572 finishSend(Object receiver, Arguments arguments, int charOffset) { | 572 finishSend(Object receiver, Arguments arguments, int charOffset) { |
| 573 bool isIdentical(Object receiver) { | 573 bool isIdentical(Object receiver) { |
| 574 return receiver is StaticAccessor && | 574 return receiver is StaticAccessor && |
| 575 receiver.readTarget == | 575 receiver.readTarget == |
| 576 coreTypes.tryGetTopLevelMember("dart:core", null, "identical"); | 576 coreTypes.tryGetTopLevelMember("dart:core", null, "identical"); |
| 577 } | 577 } |
| 578 | 578 |
| 579 if (receiver is FastaAccessor) { | 579 if (receiver is FastaAccessor) { |
| 580 if (constantExpressionRequired && !isIdentical(receiver)) { | 580 if (constantExpressionRequired && |
| 581 !isIdentical(receiver) && | |
| 582 !receiver.isInitializer) { | |
|
Paul Berry
2017/04/07 15:59:19
It looks like isInitializer isn't defined on Fasta
ahe
2017/04/07 18:11:15
That part got included in CL 2800083002 by acciden
| |
| 581 addCompileTimeError(charOffset, "Not a constant expression."); | 583 addCompileTimeError(charOffset, "Not a constant expression."); |
| 582 } | 584 } |
| 583 return receiver.doInvocation(charOffset, arguments); | 585 return receiver.doInvocation(charOffset, arguments); |
| 584 } else { | 586 } else { |
| 585 return buildMethodInvocation( | 587 return buildMethodInvocation( |
| 586 toValue(receiver), callName, arguments, charOffset); | 588 toValue(receiver), callName, arguments, charOffset); |
| 587 } | 589 } |
| 588 } | 590 } |
| 589 | 591 |
| 590 @override | 592 @override |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 bool areArgumentsCompatible(FunctionNode function, Arguments arguments) { | 719 bool areArgumentsCompatible(FunctionNode function, Arguments arguments) { |
| 718 // TODO(ahe): Implement this. | 720 // TODO(ahe): Implement this. |
| 719 return true; | 721 return true; |
| 720 } | 722 } |
| 721 | 723 |
| 722 @override | 724 @override |
| 723 Expression throwNoSuchMethodError( | 725 Expression throwNoSuchMethodError( |
| 724 String name, Arguments arguments, int charOffset, | 726 String name, Arguments arguments, int charOffset, |
| 725 {bool isSuper: false, isGetter: false, isSetter: false}) { | 727 {bool isSuper: false, isGetter: false, isSetter: false}) { |
| 726 String errorName = isSuper ? "super.$name" : name; | 728 String errorName = isSuper ? "super.$name" : name; |
| 729 String message; | |
| 727 if (isGetter) { | 730 if (isGetter) { |
| 728 warning("Getter not found: '$errorName'.", charOffset); | 731 message = "Getter not found: '$errorName'."; |
| 729 } else if (isSetter) { | 732 } else if (isSetter) { |
| 730 warning("Setter not found: '$errorName'.", charOffset); | 733 message = "Setter not found: '$errorName'."; |
| 731 } else { | 734 } else { |
| 732 warning("Method not found: '$errorName'.", charOffset); | 735 message = "Method not found: '$errorName'."; |
| 733 } | 736 } |
| 737 if (constantExpressionRequired) { | |
| 738 return buildCompileTimeError(message, charOffset); | |
| 739 } | |
| 740 warning(message, charOffset); | |
| 734 Constructor constructor = | 741 Constructor constructor = |
| 735 coreTypes.getClass("dart:core", "NoSuchMethodError").constructors.first; | 742 coreTypes.getClass("dart:core", "NoSuchMethodError").constructors.first; |
| 736 return new Throw(new ConstructorInvocation( | 743 return new Throw(new ConstructorInvocation( |
| 737 constructor, | 744 constructor, |
| 738 new Arguments(<Expression>[ | 745 new Arguments(<Expression>[ |
| 739 new NullLiteral(), | 746 new NullLiteral(), |
| 740 new SymbolLiteral(name), | 747 new SymbolLiteral(name), |
| 741 new ListLiteral(arguments.positional), | 748 new ListLiteral(arguments.positional), |
| 742 new MapLiteral(arguments.named.map((arg) { | 749 new MapLiteral(arguments.named.map((arg) { |
| 743 return new MapEntry(new SymbolLiteral(arg.name), arg.value); | 750 return new MapEntry(new SymbolLiteral(arg.name), arg.value); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 } else if (isDartLibrary && | 828 } else if (isDartLibrary && |
| 822 name == "main" && | 829 name == "main" && |
| 823 library.uri.path == "_builtin" && | 830 library.uri.path == "_builtin" && |
| 824 member?.name == "_getMainClosure") { | 831 member?.name == "_getMainClosure") { |
| 825 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28989 | 832 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28989 |
| 826 return new NullLiteral()..fileOffset = charOffset; | 833 return new NullLiteral()..fileOffset = charOffset; |
| 827 } else { | 834 } else { |
| 828 return new UnresolvedAccessor(this, n, charOffset); | 835 return new UnresolvedAccessor(this, n, charOffset); |
| 829 } | 836 } |
| 830 } else if (builder.isTypeDeclaration) { | 837 } else if (builder.isTypeDeclaration) { |
| 831 if (constantExpressionRequired && builder.isTypeVariable) { | 838 if (constantExpressionRequired && |
| 839 builder.isTypeVariable && | |
| 840 !member.isConstructor) { | |
| 832 addCompileTimeError(charOffset, "Not a constant expression."); | 841 addCompileTimeError(charOffset, "Not a constant expression."); |
| 833 } | 842 } |
| 834 return builder; | 843 return builder; |
| 835 } else if (builder.isLocal) { | 844 } else if (builder.isLocal) { |
| 836 if (constantExpressionRequired && !builder.isConst) { | 845 if (constantExpressionRequired && |
| 846 !builder.isConst && | |
| 847 !member.isConstructor) { | |
| 837 addCompileTimeError(charOffset, "Not a constant expression."); | 848 addCompileTimeError(charOffset, "Not a constant expression."); |
| 838 } | 849 } |
| 839 return new VariableAccessor(this, charOffset, builder.target); | 850 return new VariableAccessor(this, charOffset, builder.target); |
| 840 } else if (builder.isInstanceMember) { | 851 } else if (builder.isInstanceMember) { |
| 841 if (constantExpressionRequired) { | 852 if (constantExpressionRequired && |
| 853 !inInitializer && | |
| 854 // TODO(ahe): This is a hack because Fasta sets up the scope | |
| 855 // "this.field" parameters according to old semantics. Under the new | |
| 856 // semantics, such parameters introduces a new parameter with that | |
| 857 // name that should be resolved here. | |
| 858 !member.isConstructor) { | |
| 842 addCompileTimeError(charOffset, "Not a constant expression."); | 859 addCompileTimeError(charOffset, "Not a constant expression."); |
| 843 } | 860 } |
| 844 return new ThisPropertyAccessor( | 861 return new ThisPropertyAccessor( |
| 845 this, charOffset, new Name(name, library.library), null, null); | 862 this, charOffset, new Name(name, library.library), null, null); |
| 846 } else if (builder.isRegularMethod) { | 863 } else if (builder.isRegularMethod) { |
| 847 assert(builder.isStatic || builder.isTopLevel); | 864 assert(builder.isStatic || builder.isTopLevel); |
| 848 return new StaticAccessor(this, charOffset, builder.target, null); | 865 return new StaticAccessor(this, charOffset, builder.target, null); |
| 849 } else if (builder is PrefixBuilder) { | 866 } else if (builder is PrefixBuilder) { |
| 850 if (constantExpressionRequired && builder.deferred) { | 867 if (constantExpressionRequired && builder.deferred) { |
| 851 addCompileTimeError( | 868 addCompileTimeError( |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1364 return; | 1381 return; |
| 1365 } | 1382 } |
| 1366 } | 1383 } |
| 1367 if (name is Identifier) { | 1384 if (name is Identifier) { |
| 1368 name = name.name; | 1385 name = name.name; |
| 1369 } | 1386 } |
| 1370 if (name is FastaAccessor) { | 1387 if (name is FastaAccessor) { |
| 1371 warningNotError( | 1388 warningNotError( |
| 1372 "'${beginToken.lexeme}' isn't a type.", beginToken.charOffset); | 1389 "'${beginToken.lexeme}' isn't a type.", beginToken.charOffset); |
| 1373 push(const DynamicType()); | 1390 push(const DynamicType()); |
| 1374 } else if (name is TypeVariableBuilder) { | 1391 } else if (name is TypeVariableBuilder && !member.isConstructor) { |
| 1375 if (constantExpressionRequired) { | 1392 if (constantExpressionRequired) { |
| 1376 addCompileTimeError( | 1393 addCompileTimeError( |
| 1377 beginToken.charOffset, "Not a constant expression."); | 1394 beginToken.charOffset, "Not a constant expression."); |
| 1378 } | 1395 } |
| 1379 push(name.buildTypesWithBuiltArguments(library, arguments)); | 1396 push(name.buildTypesWithBuiltArguments(library, arguments)); |
| 1380 } else if (name is TypeDeclarationBuilder) { | 1397 } else if (name is TypeDeclarationBuilder) { |
| 1381 push(name.buildTypesWithBuiltArguments(library, arguments)); | 1398 push(name.buildTypesWithBuiltArguments(library, arguments)); |
| 1382 } else if (name is TypeBuilder) { | 1399 } else if (name is TypeBuilder) { |
| 1383 push(name.build(library)); | 1400 push(name.build(library)); |
| 1384 } else if (name is Builder) { | 1401 } else if (name is Builder) { |
| (...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3040 } else if (node is PrefixBuilder) { | 3057 } else if (node is PrefixBuilder) { |
| 3041 return node.name; | 3058 return node.name; |
| 3042 } else if (node is ThisAccessor) { | 3059 } else if (node is ThisAccessor) { |
| 3043 return node.isSuper ? "super" : "this"; | 3060 return node.isSuper ? "super" : "this"; |
| 3044 } else if (node is FastaAccessor) { | 3061 } else if (node is FastaAccessor) { |
| 3045 return node.plainNameForRead; | 3062 return node.plainNameForRead; |
| 3046 } else { | 3063 } else { |
| 3047 return internalError("Unhandled: ${node.runtimeType}"); | 3064 return internalError("Unhandled: ${node.runtimeType}"); |
| 3048 } | 3065 } |
| 3049 } | 3066 } |
| OLD | NEW |