| 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.analyzer.ast_builder; | 5 library fasta.analyzer.ast_builder; |
| 6 | 6 |
| 7 import 'package:front_end/src/fasta/scanner/token.dart' | 7 import 'package:front_end/src/fasta/scanner/token.dart' |
| 8 show BeginGroupToken, Token; | 8 show BeginGroupToken, Token; |
| 9 | 9 |
| 10 import 'package:analyzer/analyzer.dart'; | 10 import 'package:analyzer/analyzer.dart'; |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 FormalParameterList parameters = pop(); | 647 FormalParameterList parameters = pop(); |
| 648 TypeParameterList typeParameters = pop(); | 648 TypeParameterList typeParameters = pop(); |
| 649 SimpleIdentifier name = pop(); | 649 SimpleIdentifier name = pop(); |
| 650 analyzer.Token propertyKeyword = toAnalyzerToken(getOrSet); | 650 analyzer.Token propertyKeyword = toAnalyzerToken(getOrSet); |
| 651 TypeAnnotation returnType = pop(); | 651 TypeAnnotation returnType = pop(); |
| 652 // TODO(paulberry): handle modifiers. | 652 // TODO(paulberry): handle modifiers. |
| 653 var modifiers = pop(); | 653 var modifiers = pop(); |
| 654 assert(modifiers == null); | 654 assert(modifiers == null); |
| 655 analyzer.Token externalKeyword = null; | 655 analyzer.Token externalKeyword = null; |
| 656 List<Annotation> metadata = pop(); | 656 List<Annotation> metadata = pop(); |
| 657 // TODO(paulberry): capture doc comments. | 657 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 658 Comment comment = null; | 658 Comment comment = null; |
| 659 push(ast.functionDeclaration( | 659 push(ast.functionDeclaration( |
| 660 comment, | 660 comment, |
| 661 metadata, | 661 metadata, |
| 662 externalKeyword, | 662 externalKeyword, |
| 663 returnType, | 663 returnType, |
| 664 propertyKeyword, | 664 propertyKeyword, |
| 665 name, | 665 name, |
| 666 ast.functionExpression(typeParameters, parameters, body))); | 666 ast.functionExpression(typeParameters, parameters, body))); |
| 667 } | 667 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 697 Token semicolon) { | 697 Token semicolon) { |
| 698 debugEvent("Import"); | 698 debugEvent("Import"); |
| 699 List<Combinator> combinators = pop(); | 699 List<Combinator> combinators = pop(); |
| 700 SimpleIdentifier prefix; | 700 SimpleIdentifier prefix; |
| 701 if (asKeyword != null) prefix = pop(); | 701 if (asKeyword != null) prefix = pop(); |
| 702 List<Configuration> configurations = pop(); | 702 List<Configuration> configurations = pop(); |
| 703 assert(configurations == null); // TODO(paulberry) | 703 assert(configurations == null); // TODO(paulberry) |
| 704 StringLiteral uri = pop(); | 704 StringLiteral uri = pop(); |
| 705 List<Annotation> metadata = pop(); | 705 List<Annotation> metadata = pop(); |
| 706 assert(metadata == null); | 706 assert(metadata == null); |
| 707 // TODO(paulberry): capture doc comments. | 707 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 708 Comment comment = null; | 708 Comment comment = null; |
| 709 push(ast.importDirective( | 709 push(ast.importDirective( |
| 710 comment, | 710 comment, |
| 711 metadata, | 711 metadata, |
| 712 toAnalyzerToken(importKeyword), | 712 toAnalyzerToken(importKeyword), |
| 713 uri, | 713 uri, |
| 714 configurations, | 714 configurations, |
| 715 toAnalyzerToken(deferredKeyword), | 715 toAnalyzerToken(deferredKeyword), |
| 716 toAnalyzerToken(asKeyword), | 716 toAnalyzerToken(asKeyword), |
| 717 prefix, | 717 prefix, |
| 718 combinators, | 718 combinators, |
| 719 toAnalyzerToken(semicolon))); | 719 toAnalyzerToken(semicolon))); |
| 720 } | 720 } |
| 721 | 721 |
| 722 void endExport(Token exportKeyword, Token semicolon) { | 722 void endExport(Token exportKeyword, Token semicolon) { |
| 723 debugEvent("Export"); | 723 debugEvent("Export"); |
| 724 List<Combinator> combinators = pop(); | 724 List<Combinator> combinators = pop(); |
| 725 List<Configuration> configurations = pop(); | 725 List<Configuration> configurations = pop(); |
| 726 assert(configurations == null); // TODO(paulberry) | 726 assert(configurations == null); // TODO(paulberry) |
| 727 StringLiteral uri = pop(); | 727 StringLiteral uri = pop(); |
| 728 List<Annotation> metadata = pop(); | 728 List<Annotation> metadata = pop(); |
| 729 assert(metadata == null); | 729 assert(metadata == null); |
| 730 // TODO(paulberry): capture doc comments. | 730 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 731 Comment comment = null; | 731 Comment comment = null; |
| 732 push(ast.exportDirective(comment, metadata, toAnalyzerToken(exportKeyword), | 732 push(ast.exportDirective(comment, metadata, toAnalyzerToken(exportKeyword), |
| 733 uri, configurations, combinators, toAnalyzerToken(semicolon))); | 733 uri, configurations, combinators, toAnalyzerToken(semicolon))); |
| 734 } | 734 } |
| 735 | 735 |
| 736 @override | 736 @override |
| 737 void endConditionalUris(int count) { | 737 void endConditionalUris(int count) { |
| 738 debugEvent("ConditionalUris"); | 738 debugEvent("ConditionalUris"); |
| 739 push(popList(count) ?? NullValue.ConditionalUris); | 739 push(popList(count) ?? NullValue.ConditionalUris); |
| 740 } | 740 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 // keyword. | 806 // keyword. |
| 807 if (optional('abstract', beginToken)) { | 807 if (optional('abstract', beginToken)) { |
| 808 classKeyword = beginToken.next; | 808 classKeyword = beginToken.next; |
| 809 } else { | 809 } else { |
| 810 classKeyword = beginToken; | 810 classKeyword = beginToken; |
| 811 } | 811 } |
| 812 var modifiers = pop(); | 812 var modifiers = pop(); |
| 813 assert(modifiers == null); // TODO(paulberry) | 813 assert(modifiers == null); // TODO(paulberry) |
| 814 analyzer.Token abstractKeyword; | 814 analyzer.Token abstractKeyword; |
| 815 List<Annotation> metadata = pop(); | 815 List<Annotation> metadata = pop(); |
| 816 Comment comment = null; // TODO(paulberry) | 816 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 817 Comment comment = null; |
| 817 push(ast.classDeclaration( | 818 push(ast.classDeclaration( |
| 818 comment, | 819 comment, |
| 819 metadata, | 820 metadata, |
| 820 abstractKeyword, | 821 abstractKeyword, |
| 821 toAnalyzerToken(classKeyword), | 822 toAnalyzerToken(classKeyword), |
| 822 name, | 823 name, |
| 823 typeParameters, | 824 typeParameters, |
| 824 extendsClause, | 825 extendsClause, |
| 825 withClause, | 826 withClause, |
| 826 implementsClause, | 827 implementsClause, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 // keyword. | 865 // keyword. |
| 865 if (identical(beginToken.value, 'abstract')) { | 866 if (identical(beginToken.value, 'abstract')) { |
| 866 classKeyword = beginToken.next; | 867 classKeyword = beginToken.next; |
| 867 } else { | 868 } else { |
| 868 classKeyword = beginToken; | 869 classKeyword = beginToken; |
| 869 } | 870 } |
| 870 var modifiers = pop(); | 871 var modifiers = pop(); |
| 871 assert(modifiers == null); // TODO(paulberry) | 872 assert(modifiers == null); // TODO(paulberry) |
| 872 analyzer.Token abstractKeyword; | 873 analyzer.Token abstractKeyword; |
| 873 List<Annotation> metadata = pop(); | 874 List<Annotation> metadata = pop(); |
| 874 Comment comment = null; // TODO(paulberry) | 875 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 876 Comment comment = null; |
| 875 push(ast.classTypeAlias( | 877 push(ast.classTypeAlias( |
| 876 comment, | 878 comment, |
| 877 metadata, | 879 metadata, |
| 878 toAnalyzerToken(classKeyword), | 880 toAnalyzerToken(classKeyword), |
| 879 name, | 881 name, |
| 880 typeParameters, | 882 typeParameters, |
| 881 equals, | 883 equals, |
| 882 abstractKeyword, | 884 abstractKeyword, |
| 883 superclass, | 885 superclass, |
| 884 withClause, | 886 withClause, |
| 885 implementsClause, | 887 implementsClause, |
| 886 toAnalyzerToken(endToken))); | 888 toAnalyzerToken(endToken))); |
| 887 } | 889 } |
| 888 | 890 |
| 889 @override | 891 @override |
| 890 void beginLibraryName(Token token) { | 892 void beginLibraryName(Token token) { |
| 891 accumulateIdentifierComponents = true; | 893 accumulateIdentifierComponents = true; |
| 892 isFirstIdentifier = true; | 894 isFirstIdentifier = true; |
| 893 } | 895 } |
| 894 | 896 |
| 895 @override | 897 @override |
| 896 void endLibraryName(Token libraryKeyword, Token semicolon) { | 898 void endLibraryName(Token libraryKeyword, Token semicolon) { |
| 897 debugEvent("LibraryName"); | 899 debugEvent("LibraryName"); |
| 898 List<SimpleIdentifier> libraryName = pop(); | 900 List<SimpleIdentifier> libraryName = pop(); |
| 899 var name = ast.libraryIdentifier(libraryName); | 901 var name = ast.libraryIdentifier(libraryName); |
| 900 List<Annotation> metadata = pop(); | 902 List<Annotation> metadata = pop(); |
| 901 Comment comment = null; // TODO(paulberry) | 903 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 904 Comment comment = null; |
| 902 push(ast.libraryDirective(comment, metadata, | 905 push(ast.libraryDirective(comment, metadata, |
| 903 toAnalyzerToken(libraryKeyword), name, toAnalyzerToken(semicolon))); | 906 toAnalyzerToken(libraryKeyword), name, toAnalyzerToken(semicolon))); |
| 904 accumulateIdentifierComponents = false; | 907 accumulateIdentifierComponents = false; |
| 905 } | 908 } |
| 906 | 909 |
| 907 @override | 910 @override |
| 908 void handleQualified(Token period) { | 911 void handleQualified(Token period) { |
| 909 if (accumulateIdentifierComponents) { | 912 if (accumulateIdentifierComponents) { |
| 910 SimpleIdentifier identifier = pop(); | 913 SimpleIdentifier identifier = pop(); |
| 911 List<SimpleIdentifier> list = pop(); | 914 List<SimpleIdentifier> list = pop(); |
| 912 list.add(identifier); | 915 list.add(identifier); |
| 913 push(list); | 916 push(list); |
| 914 } else { | 917 } else { |
| 915 // TODO(paulberry): implement. | 918 // TODO(paulberry): implement. |
| 916 logEvent('Qualified'); | 919 logEvent('Qualified'); |
| 917 } | 920 } |
| 918 } | 921 } |
| 919 | 922 |
| 920 @override | 923 @override |
| 921 void endPart(Token partKeyword, Token semicolon) { | 924 void endPart(Token partKeyword, Token semicolon) { |
| 922 debugEvent("Part"); | 925 debugEvent("Part"); |
| 923 StringLiteral uri = pop(); | 926 StringLiteral uri = pop(); |
| 924 List<Annotation> metadata = pop(); | 927 List<Annotation> metadata = pop(); |
| 925 Comment comment = null; // TODO(paulberry) | 928 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 929 Comment comment = null; |
| 926 push(ast.partDirective(comment, metadata, toAnalyzerToken(partKeyword), uri, | 930 push(ast.partDirective(comment, metadata, toAnalyzerToken(partKeyword), uri, |
| 927 toAnalyzerToken(semicolon))); | 931 toAnalyzerToken(semicolon))); |
| 928 } | 932 } |
| 929 | 933 |
| 930 @override | 934 @override |
| 931 void beginPartOf(Token token) { | 935 void beginPartOf(Token token) { |
| 932 accumulateIdentifierComponents = true; | 936 accumulateIdentifierComponents = true; |
| 933 isFirstIdentifier = true; | 937 isFirstIdentifier = true; |
| 934 } | 938 } |
| 935 | 939 |
| 936 @override | 940 @override |
| 937 void endPartOf(Token partKeyword, Token semicolon) { | 941 void endPartOf(Token partKeyword, Token semicolon) { |
| 938 debugEvent("PartOf"); | 942 debugEvent("PartOf"); |
| 939 List<SimpleIdentifier> libraryName = pop(); | 943 List<SimpleIdentifier> libraryName = pop(); |
| 940 var name = ast.libraryIdentifier(libraryName); | 944 var name = ast.libraryIdentifier(libraryName); |
| 941 StringLiteral uri = null; // TODO(paulberry) | 945 StringLiteral uri = null; // TODO(paulberry) |
| 942 // TODO(paulberry,ahe): seems hacky. It would be nice if the parser passed | 946 // TODO(paulberry,ahe): seems hacky. It would be nice if the parser passed |
| 943 // in a reference to the "of" keyword. | 947 // in a reference to the "of" keyword. |
| 944 var ofKeyword = partKeyword.next; | 948 var ofKeyword = partKeyword.next; |
| 945 List<Annotation> metadata = pop(); | 949 List<Annotation> metadata = pop(); |
| 946 Comment comment = null; // TODO(paulberry) | 950 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 951 Comment comment = null; |
| 947 push(ast.partOfDirective(comment, metadata, toAnalyzerToken(partKeyword), | 952 push(ast.partOfDirective(comment, metadata, toAnalyzerToken(partKeyword), |
| 948 toAnalyzerToken(ofKeyword), uri, name, toAnalyzerToken(semicolon))); | 953 toAnalyzerToken(ofKeyword), uri, name, toAnalyzerToken(semicolon))); |
| 949 accumulateIdentifierComponents = false; | 954 accumulateIdentifierComponents = false; |
| 950 } | 955 } |
| 951 | 956 |
| 952 void endUnnamedFunction(Token token) { | 957 void endUnnamedFunction(Token token) { |
| 953 // TODO(paulberry): set up scopes properly to resolve parameters and type | 958 // TODO(paulberry): set up scopes properly to resolve parameters and type |
| 954 // variables. Note that this is tricky due to the handling of initializers | 959 // variables. Note that this is tricky due to the handling of initializers |
| 955 // in constructors, so the logic should be shared with BodyBuilder as much | 960 // in constructors, so the logic should be shared with BodyBuilder as much |
| 956 // as possible. | 961 // as possible. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 984 if (optional('var', beginToken) || | 989 if (optional('var', beginToken) || |
| 985 optional('const', beginToken) || | 990 optional('const', beginToken) || |
| 986 optional('final', beginToken)) { | 991 optional('final', beginToken)) { |
| 987 keyword = beginToken; | 992 keyword = beginToken; |
| 988 } | 993 } |
| 989 var variableList = ast.variableDeclarationList( | 994 var variableList = ast.variableDeclarationList( |
| 990 null, null, toAnalyzerToken(keyword), type, variables); | 995 null, null, toAnalyzerToken(keyword), type, variables); |
| 991 var modifiers = pop(); | 996 var modifiers = pop(); |
| 992 assert(modifiers == null); // TODO(paulberry) | 997 assert(modifiers == null); // TODO(paulberry) |
| 993 List<Annotation> metadata = pop(); | 998 List<Annotation> metadata = pop(); |
| 994 Comment comment = null; // TODO(paulberry) | 999 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 1000 Comment comment = null; |
| 995 push(ast.topLevelVariableDeclaration( | 1001 push(ast.topLevelVariableDeclaration( |
| 996 comment, metadata, variableList, toAnalyzerToken(endToken))); | 1002 comment, metadata, variableList, toAnalyzerToken(endToken))); |
| 997 } | 1003 } |
| 998 | 1004 |
| 999 @override | 1005 @override |
| 1000 void endTypeVariable(Token token, Token extendsOrSuper) { | 1006 void endTypeVariable(Token token, Token extendsOrSuper) { |
| 1001 // TODO(paulberry): set up scopes properly to resolve parameters and type | 1007 // TODO(paulberry): set up scopes properly to resolve parameters and type |
| 1002 // variables. Note that this is tricky due to the handling of initializers | 1008 // variables. Note that this is tricky due to the handling of initializers |
| 1003 // in constructors, so the logic should be shared with BodyBuilder as much | 1009 // in constructors, so the logic should be shared with BodyBuilder as much |
| 1004 // as possible. | 1010 // as possible. |
| 1005 debugEvent("TypeVariable"); | 1011 debugEvent("TypeVariable"); |
| 1006 TypeAnnotation bound = pop(); | 1012 TypeAnnotation bound = pop(); |
| 1007 SimpleIdentifier name = pop(); | 1013 SimpleIdentifier name = pop(); |
| 1008 List<Annotation> metadata = null; // TODO(paulberry) | 1014 List<Annotation> metadata = null; // TODO(paulberry) |
| 1009 Comment comment = null; // TODO(paulberry) | 1015 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 1016 Comment comment = null; |
| 1010 push(ast.typeParameter( | 1017 push(ast.typeParameter( |
| 1011 comment, metadata, name, toAnalyzerToken(extendsOrSuper), bound)); | 1018 comment, metadata, name, toAnalyzerToken(extendsOrSuper), bound)); |
| 1012 } | 1019 } |
| 1013 | 1020 |
| 1014 @override | 1021 @override |
| 1015 void endTypeVariables(int count, Token beginToken, Token endToken) { | 1022 void endTypeVariables(int count, Token beginToken, Token endToken) { |
| 1016 debugEvent("TypeVariables"); | 1023 debugEvent("TypeVariables"); |
| 1017 List<TypeParameter> typeParameters = popList(count); | 1024 List<TypeParameter> typeParameters = popList(count); |
| 1018 push(ast.typeParameterList(toAnalyzerToken(beginToken), typeParameters, | 1025 push(ast.typeParameterList(toAnalyzerToken(beginToken), typeParameters, |
| 1019 toAnalyzerToken(endToken))); | 1026 toAnalyzerToken(endToken))); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1031 var name = pop(); | 1038 var name = pop(); |
| 1032 analyzer.Token propertyKeyword = toAnalyzerToken(getOrSet); | 1039 analyzer.Token propertyKeyword = toAnalyzerToken(getOrSet); |
| 1033 TypeAnnotation returnType = pop(); | 1040 TypeAnnotation returnType = pop(); |
| 1034 // TODO(paulberry): handle modifiers. | 1041 // TODO(paulberry): handle modifiers. |
| 1035 var modifiers = pop(); | 1042 var modifiers = pop(); |
| 1036 assert(modifiers == null); | 1043 assert(modifiers == null); |
| 1037 Token externalKeyword = null; // TODO(paulberry) | 1044 Token externalKeyword = null; // TODO(paulberry) |
| 1038 Token constKeyword = null; // TODO(paulberry) | 1045 Token constKeyword = null; // TODO(paulberry) |
| 1039 Token factoryKeyword = null; // TODO(paulberry) | 1046 Token factoryKeyword = null; // TODO(paulberry) |
| 1040 List<Annotation> metadata = pop(); | 1047 List<Annotation> metadata = pop(); |
| 1041 // TODO(paulberry): capture doc comments. | 1048 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 1042 Comment comment = null; | 1049 Comment comment = null; |
| 1043 SimpleIdentifier returnType2; | 1050 SimpleIdentifier returnType2; |
| 1044 Token period; | 1051 Token period; |
| 1045 SimpleIdentifier name2; | 1052 SimpleIdentifier name2; |
| 1046 if (name is SimpleIdentifier) { | 1053 if (name is SimpleIdentifier) { |
| 1047 SimpleIdentifier returnType2 = name; | 1054 SimpleIdentifier returnType2 = name; |
| 1048 } | 1055 } |
| 1049 push(ast.constructorDeclaration( | 1056 push(ast.constructorDeclaration( |
| 1050 comment, | 1057 comment, |
| 1051 metadata, | 1058 metadata, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1078 } | 1085 } |
| 1079 | 1086 |
| 1080 @override | 1087 @override |
| 1081 void endFunctionTypeAlias(Token typedefKeyword, Token endToken) { | 1088 void endFunctionTypeAlias(Token typedefKeyword, Token endToken) { |
| 1082 debugEvent("FunctionTypeAlias"); | 1089 debugEvent("FunctionTypeAlias"); |
| 1083 FormalParameterList parameters = pop(); | 1090 FormalParameterList parameters = pop(); |
| 1084 TypeParameterList typeParameters = pop(); | 1091 TypeParameterList typeParameters = pop(); |
| 1085 SimpleIdentifier name = pop(); | 1092 SimpleIdentifier name = pop(); |
| 1086 TypeAnnotation returnType = pop(); | 1093 TypeAnnotation returnType = pop(); |
| 1087 List<Annotation> metadata = pop(); | 1094 List<Annotation> metadata = pop(); |
| 1088 // TODO(paulberry): capture doc comments. | 1095 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 1089 Comment comment = null; | 1096 Comment comment = null; |
| 1090 push(ast.functionTypeAlias( | 1097 push(ast.functionTypeAlias( |
| 1091 comment, | 1098 comment, |
| 1092 metadata, | 1099 metadata, |
| 1093 toAnalyzerToken(typedefKeyword), | 1100 toAnalyzerToken(typedefKeyword), |
| 1094 returnType, | 1101 returnType, |
| 1095 name, | 1102 name, |
| 1096 typeParameters, | 1103 typeParameters, |
| 1097 parameters, | 1104 parameters, |
| 1098 toAnalyzerToken(endToken))); | 1105 toAnalyzerToken(endToken))); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1122 /// [ClassDeclaration] or [ClassTypeAlias] object. | 1129 /// [ClassDeclaration] or [ClassTypeAlias] object. |
| 1123 class _MixinApplication { | 1130 class _MixinApplication { |
| 1124 final TypeName supertype; | 1131 final TypeName supertype; |
| 1125 | 1132 |
| 1126 final Token withKeyword; | 1133 final Token withKeyword; |
| 1127 | 1134 |
| 1128 final List<TypeName> mixinTypes; | 1135 final List<TypeName> mixinTypes; |
| 1129 | 1136 |
| 1130 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); | 1137 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); |
| 1131 } | 1138 } |
| OLD | NEW |