| 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:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; | 8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; |
| 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; | 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; |
| 10 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token; | 10 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token; |
| 11 import 'package:analyzer/dart/element/element.dart' show Element; | 11 import 'package:analyzer/dart/element/element.dart' show Element; |
| 12 import '../parser/parser.dart' show FormalParameterType; | 12 import '../parser/parser.dart' show FormalParameterType; |
| 13 import '../scanner/token.dart' show BeginGroupToken, Token; | 13 import '../scanner/token.dart' show BeginGroupToken, Token; |
| 14 | 14 |
| 15 import '../errors.dart' show internalError; | 15 import '../errors.dart' show internalError; |
| 16 import '../kernel/kernel_builder.dart' | 16 import '../kernel/kernel_builder.dart' |
| 17 show Builder, KernelLibraryBuilder, ProcedureBuilder; | 17 show Builder, KernelLibraryBuilder, ProcedureBuilder; |
| 18 import '../parser/identifier_context.dart' show IdentifierContext; | 18 import '../parser/identifier_context.dart' show IdentifierContext; |
| 19 import '../quote.dart'; | 19 import '../quote.dart'; |
| 20 import '../source/scope_listener.dart' | 20 import '../source/scope_listener.dart' |
| 21 show JumpTargetKind, NullValue, Scope, ScopeListener; | 21 show JumpTargetKind, NullValue, Scope, ScopeListener; |
| 22 import 'analyzer.dart' show toKernel; | 22 import 'analyzer.dart' show toKernel; |
| 23 import 'element_store.dart' | 23 import 'element_store.dart' |
| 24 show | 24 show |
| 25 AnalyzerLocalVariableElemment, | 25 AnalyzerLocalVariableElemment, |
| 26 AnalyzerParameterElement, | 26 AnalyzerParameterElement, |
| 27 ElementStore, | 27 ElementStore, |
| 28 KernelClassElement; | 28 KernelClassElement; |
| 29 import 'token_utils.dart' show toAnalyzerToken; | 29 import 'token_utils.dart' show toAnalyzerToken, toAnalyzerCommentToken; |
| 30 | 30 |
| 31 class AstBuilder extends ScopeListener { | 31 class AstBuilder extends ScopeListener { |
| 32 final AstFactory ast = standard.astFactory; | 32 final AstFactory ast = standard.astFactory; |
| 33 | 33 |
| 34 final KernelLibraryBuilder library; | 34 final KernelLibraryBuilder library; |
| 35 | 35 |
| 36 final Builder member; | 36 final Builder member; |
| 37 | 37 |
| 38 final ElementStore elementStore; | 38 final ElementStore elementStore; |
| 39 | 39 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 if (context.inLibraryOrPartOfDeclaration) { | 175 if (context.inLibraryOrPartOfDeclaration) { |
| 176 if (!context.isContinuation) { | 176 if (!context.isContinuation) { |
| 177 push([identifier]); | 177 push([identifier]); |
| 178 } else { | 178 } else { |
| 179 push(identifier); | 179 push(identifier); |
| 180 } | 180 } |
| 181 } else if (context == IdentifierContext.enumValueDeclaration) { | 181 } else if (context == IdentifierContext.enumValueDeclaration) { |
| 182 // TODO(paulberry): analyzer's ASTs allow for enumerated values to have | 182 // TODO(paulberry): analyzer's ASTs allow for enumerated values to have |
| 183 // metadata, but the spec doesn't permit it. | 183 // metadata, but the spec doesn't permit it. |
| 184 List<Annotation> metadata; | 184 List<Annotation> metadata; |
| 185 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 185 Comment comment = _toAnalyzerComment(token.precedingComments); |
| 186 Comment comment = null; | |
| 187 push(ast.enumConstantDeclaration(comment, metadata, identifier)); | 186 push(ast.enumConstantDeclaration(comment, metadata, identifier)); |
| 188 } else { | 187 } else { |
| 189 if (context.isScopeReference) { | 188 if (context.isScopeReference) { |
| 190 String name = token.value; | 189 String name = token.value; |
| 191 Builder builder = scope.lookup(name, token.charOffset, uri); | 190 Builder builder = scope.lookup(name, token.charOffset, uri); |
| 192 if (builder != null) { | 191 if (builder != null) { |
| 193 Element element = elementStore[builder]; | 192 Element element = elementStore[builder]; |
| 194 assert(element != null); | 193 assert(element != null); |
| 195 identifier.staticElement = element; | 194 identifier.staticElement = element; |
| 196 } | 195 } |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 SimpleIdentifier name; | 622 SimpleIdentifier name; |
| 624 if (nameOrFunctionTypedParameter is FormalParameter) { | 623 if (nameOrFunctionTypedParameter is FormalParameter) { |
| 625 node = nameOrFunctionTypedParameter; | 624 node = nameOrFunctionTypedParameter; |
| 626 name = nameOrFunctionTypedParameter.identifier; | 625 name = nameOrFunctionTypedParameter.identifier; |
| 627 } else { | 626 } else { |
| 628 name = nameOrFunctionTypedParameter; | 627 name = nameOrFunctionTypedParameter; |
| 629 TypeAnnotation type = pop(); | 628 TypeAnnotation type = pop(); |
| 630 _Modifiers modifiers = pop(); | 629 _Modifiers modifiers = pop(); |
| 631 Token keyword = modifiers?.finalConstOrVarKeyword; | 630 Token keyword = modifiers?.finalConstOrVarKeyword; |
| 632 pop(); // TODO(paulberry): Metadata. | 631 pop(); // TODO(paulberry): Metadata. |
| 632 Comment comment = pop(); |
| 633 if (thisKeyword == null) { | 633 if (thisKeyword == null) { |
| 634 node = ast.simpleFormalParameter2( | 634 node = ast.simpleFormalParameter2( |
| 635 comment: comment, |
| 635 covariantKeyword: toAnalyzerToken(covariantKeyword), | 636 covariantKeyword: toAnalyzerToken(covariantKeyword), |
| 636 keyword: toAnalyzerToken(keyword), | 637 keyword: toAnalyzerToken(keyword), |
| 637 type: type, | 638 type: type, |
| 638 identifier: name); | 639 identifier: name); |
| 639 } else { | 640 } else { |
| 640 // TODO(scheglov): Ideally the period token should be passed in. | 641 // TODO(scheglov): Ideally the period token should be passed in. |
| 641 Token period = identical('.', thisKeyword.next?.stringValue) | 642 Token period = identical('.', thisKeyword.next?.stringValue) |
| 642 ? thisKeyword.next | 643 ? thisKeyword.next |
| 643 : null; | 644 : null; |
| 644 node = ast.fieldFormalParameter2( | 645 node = ast.fieldFormalParameter2( |
| 646 comment: comment, |
| 645 covariantKeyword: toAnalyzerToken(covariantKeyword), | 647 covariantKeyword: toAnalyzerToken(covariantKeyword), |
| 646 keyword: toAnalyzerToken(keyword), | 648 keyword: toAnalyzerToken(keyword), |
| 647 type: type, | 649 type: type, |
| 648 thisKeyword: toAnalyzerToken(thisKeyword), | 650 thisKeyword: toAnalyzerToken(thisKeyword), |
| 649 period: toAnalyzerToken(period), | 651 period: toAnalyzerToken(period), |
| 650 identifier: name); | 652 identifier: name); |
| 651 } | 653 } |
| 652 } | 654 } |
| 653 | 655 |
| 654 ParameterKind analyzerKind = _toAnalyzerParameterKind(kind); | 656 ParameterKind analyzerKind = _toAnalyzerParameterKind(kind); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 676 | 678 |
| 677 { | 679 { |
| 678 _Modifiers modifiers = pop(); | 680 _Modifiers modifiers = pop(); |
| 679 if (modifiers != null) { | 681 if (modifiers != null) { |
| 680 // TODO(scheglov): Report error. | 682 // TODO(scheglov): Report error. |
| 681 internalError('Unexpected modifier. Report an error.'); | 683 internalError('Unexpected modifier. Report an error.'); |
| 682 } | 684 } |
| 683 } | 685 } |
| 684 | 686 |
| 685 pop(); // TODO(paulberry): Metadata. | 687 pop(); // TODO(paulberry): Metadata. |
| 688 Comment comment = pop(); |
| 686 | 689 |
| 687 FormalParameter node; | 690 FormalParameter node; |
| 688 if (thisKeyword == null) { | 691 if (thisKeyword == null) { |
| 689 node = ast.functionTypedFormalParameter2( | 692 node = ast.functionTypedFormalParameter2( |
| 693 comment: comment, |
| 690 covariantKeyword: toAnalyzerToken(covariantKeyword), | 694 covariantKeyword: toAnalyzerToken(covariantKeyword), |
| 691 returnType: returnType, | 695 returnType: returnType, |
| 692 identifier: name, | 696 identifier: name, |
| 693 typeParameters: typeParameters, | 697 typeParameters: typeParameters, |
| 694 parameters: formalParameters); | 698 parameters: formalParameters); |
| 695 } else { | 699 } else { |
| 696 // TODO(scheglov): Ideally the period token should be passed in. | 700 // TODO(scheglov): Ideally the period token should be passed in. |
| 697 Token period = identical('.', thisKeyword?.next?.stringValue) | 701 Token period = identical('.', thisKeyword?.next?.stringValue) |
| 698 ? thisKeyword.next | 702 ? thisKeyword.next |
| 699 : null; | 703 : null; |
| 700 node = ast.fieldFormalParameter2( | 704 node = ast.fieldFormalParameter2( |
| 705 comment: comment, |
| 701 covariantKeyword: toAnalyzerToken(covariantKeyword), | 706 covariantKeyword: toAnalyzerToken(covariantKeyword), |
| 702 type: returnType, | 707 type: returnType, |
| 703 thisKeyword: toAnalyzerToken(thisKeyword), | 708 thisKeyword: toAnalyzerToken(thisKeyword), |
| 704 period: toAnalyzerToken(period), | 709 period: toAnalyzerToken(period), |
| 705 identifier: name, | 710 identifier: name, |
| 706 typeParameters: typeParameters, | 711 typeParameters: typeParameters, |
| 707 parameters: formalParameters); | 712 parameters: formalParameters); |
| 708 } | 713 } |
| 709 | 714 |
| 710 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node); | 715 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 debugEvent("TopLevelMethod"); | 843 debugEvent("TopLevelMethod"); |
| 839 FunctionBody body = pop(); | 844 FunctionBody body = pop(); |
| 840 FormalParameterList parameters = pop(); | 845 FormalParameterList parameters = pop(); |
| 841 TypeParameterList typeParameters = pop(); | 846 TypeParameterList typeParameters = pop(); |
| 842 SimpleIdentifier name = pop(); | 847 SimpleIdentifier name = pop(); |
| 843 analyzer.Token propertyKeyword = toAnalyzerToken(getOrSet); | 848 analyzer.Token propertyKeyword = toAnalyzerToken(getOrSet); |
| 844 TypeAnnotation returnType = pop(); | 849 TypeAnnotation returnType = pop(); |
| 845 _Modifiers modifiers = pop(); | 850 _Modifiers modifiers = pop(); |
| 846 Token externalKeyword = modifiers?.externalKeyword; | 851 Token externalKeyword = modifiers?.externalKeyword; |
| 847 List<Annotation> metadata = pop(); | 852 List<Annotation> metadata = pop(); |
| 848 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 853 Comment comment = pop(); |
| 849 Comment comment = null; | |
| 850 push(ast.functionDeclaration( | 854 push(ast.functionDeclaration( |
| 851 comment, | 855 comment, |
| 852 metadata, | 856 metadata, |
| 853 toAnalyzerToken(externalKeyword), | 857 toAnalyzerToken(externalKeyword), |
| 854 returnType, | 858 returnType, |
| 855 propertyKeyword, | 859 propertyKeyword, |
| 856 name, | 860 name, |
| 857 ast.functionExpression(typeParameters, parameters, body))); | 861 ast.functionExpression(typeParameters, parameters, body))); |
| 858 } | 862 } |
| 859 | 863 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 | 895 |
| 892 void endImport(Token importKeyword, Token deferredKeyword, Token asKeyword, | 896 void endImport(Token importKeyword, Token deferredKeyword, Token asKeyword, |
| 893 Token semicolon) { | 897 Token semicolon) { |
| 894 debugEvent("Import"); | 898 debugEvent("Import"); |
| 895 List<Combinator> combinators = pop(); | 899 List<Combinator> combinators = pop(); |
| 896 SimpleIdentifier prefix; | 900 SimpleIdentifier prefix; |
| 897 if (asKeyword != null) prefix = pop(); | 901 if (asKeyword != null) prefix = pop(); |
| 898 List<Configuration> configurations = pop(); | 902 List<Configuration> configurations = pop(); |
| 899 StringLiteral uri = pop(); | 903 StringLiteral uri = pop(); |
| 900 List<Annotation> metadata = pop(); | 904 List<Annotation> metadata = pop(); |
| 901 assert(metadata == null); | 905 assert(metadata == null); // TODO(paulberry): fix. |
| 902 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 906 Comment comment = pop(); |
| 903 Comment comment = null; | |
| 904 push(ast.importDirective( | 907 push(ast.importDirective( |
| 905 comment, | 908 comment, |
| 906 metadata, | 909 metadata, |
| 907 toAnalyzerToken(importKeyword), | 910 toAnalyzerToken(importKeyword), |
| 908 uri, | 911 uri, |
| 909 configurations, | 912 configurations, |
| 910 toAnalyzerToken(deferredKeyword), | 913 toAnalyzerToken(deferredKeyword), |
| 911 toAnalyzerToken(asKeyword), | 914 toAnalyzerToken(asKeyword), |
| 912 prefix, | 915 prefix, |
| 913 combinators, | 916 combinators, |
| 914 toAnalyzerToken(semicolon))); | 917 toAnalyzerToken(semicolon))); |
| 915 } | 918 } |
| 916 | 919 |
| 917 void endExport(Token exportKeyword, Token semicolon) { | 920 void endExport(Token exportKeyword, Token semicolon) { |
| 918 debugEvent("Export"); | 921 debugEvent("Export"); |
| 919 List<Combinator> combinators = pop(); | 922 List<Combinator> combinators = pop(); |
| 920 List<Configuration> configurations = pop(); | 923 List<Configuration> configurations = pop(); |
| 921 StringLiteral uri = pop(); | 924 StringLiteral uri = pop(); |
| 922 List<Annotation> metadata = pop(); | 925 List<Annotation> metadata = pop(); |
| 923 assert(metadata == null); | 926 assert(metadata == null); |
| 924 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 927 Comment comment = pop(); |
| 925 Comment comment = null; | |
| 926 push(ast.exportDirective(comment, metadata, toAnalyzerToken(exportKeyword), | 928 push(ast.exportDirective(comment, metadata, toAnalyzerToken(exportKeyword), |
| 927 uri, configurations, combinators, toAnalyzerToken(semicolon))); | 929 uri, configurations, combinators, toAnalyzerToken(semicolon))); |
| 928 } | 930 } |
| 929 | 931 |
| 930 @override | 932 @override |
| 931 void endDottedName(int count, Token firstIdentifier) { | 933 void endDottedName(int count, Token firstIdentifier) { |
| 932 debugEvent("DottedName"); | 934 debugEvent("DottedName"); |
| 933 List<SimpleIdentifier> components = popList(count); | 935 List<SimpleIdentifier> components = popList(count); |
| 934 push(ast.dottedName(components)); | 936 push(ast.dottedName(components)); |
| 935 } | 937 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 } else { | 1033 } else { |
| 1032 internalError('Unexpected kind of supertype ${supertype.runtimeType}'); | 1034 internalError('Unexpected kind of supertype ${supertype.runtimeType}'); |
| 1033 } | 1035 } |
| 1034 TypeParameterList typeParameters = pop(); | 1036 TypeParameterList typeParameters = pop(); |
| 1035 SimpleIdentifier name = pop(); | 1037 SimpleIdentifier name = pop(); |
| 1036 assert(className == name.name); | 1038 assert(className == name.name); |
| 1037 className = null; | 1039 className = null; |
| 1038 _Modifiers modifiers = pop(); | 1040 _Modifiers modifiers = pop(); |
| 1039 Token abstractKeyword = modifiers?.abstractKeyword; | 1041 Token abstractKeyword = modifiers?.abstractKeyword; |
| 1040 List<Annotation> metadata = pop(); | 1042 List<Annotation> metadata = pop(); |
| 1041 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1043 Comment comment = pop(); |
| 1042 Comment comment = null; | |
| 1043 push(ast.classDeclaration( | 1044 push(ast.classDeclaration( |
| 1044 comment, | 1045 comment, |
| 1045 metadata, | 1046 metadata, |
| 1046 toAnalyzerToken(abstractKeyword), | 1047 toAnalyzerToken(abstractKeyword), |
| 1047 toAnalyzerToken(classKeyword), | 1048 toAnalyzerToken(classKeyword), |
| 1048 name, | 1049 name, |
| 1049 typeParameters, | 1050 typeParameters, |
| 1050 extendsClause, | 1051 extendsClause, |
| 1051 withClause, | 1052 withClause, |
| 1052 implementsClause, | 1053 implementsClause, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1077 var superclass = mixinApplication.supertype; | 1078 var superclass = mixinApplication.supertype; |
| 1078 var withClause = ast.withClause( | 1079 var withClause = ast.withClause( |
| 1079 toAnalyzerToken(mixinApplication.withKeyword), | 1080 toAnalyzerToken(mixinApplication.withKeyword), |
| 1080 mixinApplication.mixinTypes); | 1081 mixinApplication.mixinTypes); |
| 1081 analyzer.Token equals = toAnalyzerToken(equalsToken); | 1082 analyzer.Token equals = toAnalyzerToken(equalsToken); |
| 1082 TypeParameterList typeParameters = pop(); | 1083 TypeParameterList typeParameters = pop(); |
| 1083 SimpleIdentifier name = pop(); | 1084 SimpleIdentifier name = pop(); |
| 1084 _Modifiers modifiers = pop(); | 1085 _Modifiers modifiers = pop(); |
| 1085 Token abstractKeyword = modifiers?.abstractKeyword; | 1086 Token abstractKeyword = modifiers?.abstractKeyword; |
| 1086 List<Annotation> metadata = pop(); | 1087 List<Annotation> metadata = pop(); |
| 1087 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1088 Comment comment = pop(); |
| 1088 Comment comment = null; | |
| 1089 push(ast.classTypeAlias( | 1089 push(ast.classTypeAlias( |
| 1090 comment, | 1090 comment, |
| 1091 metadata, | 1091 metadata, |
| 1092 toAnalyzerToken(classKeyword), | 1092 toAnalyzerToken(classKeyword), |
| 1093 name, | 1093 name, |
| 1094 typeParameters, | 1094 typeParameters, |
| 1095 equals, | 1095 equals, |
| 1096 toAnalyzerToken(abstractKeyword), | 1096 toAnalyzerToken(abstractKeyword), |
| 1097 superclass, | 1097 superclass, |
| 1098 withClause, | 1098 withClause, |
| 1099 implementsClause, | 1099 implementsClause, |
| 1100 toAnalyzerToken(endToken))); | 1100 toAnalyzerToken(endToken))); |
| 1101 } | 1101 } |
| 1102 | 1102 |
| 1103 @override | 1103 @override |
| 1104 void endLibraryName(Token libraryKeyword, Token semicolon) { | 1104 void endLibraryName(Token libraryKeyword, Token semicolon) { |
| 1105 debugEvent("LibraryName"); | 1105 debugEvent("LibraryName"); |
| 1106 List<SimpleIdentifier> libraryName = pop(); | 1106 List<SimpleIdentifier> libraryName = pop(); |
| 1107 var name = ast.libraryIdentifier(libraryName); | 1107 var name = ast.libraryIdentifier(libraryName); |
| 1108 List<Annotation> metadata = pop(); | 1108 List<Annotation> metadata = pop(); |
| 1109 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1109 Comment comment = pop(); |
| 1110 Comment comment = null; | |
| 1111 push(ast.libraryDirective(comment, metadata, | 1110 push(ast.libraryDirective(comment, metadata, |
| 1112 toAnalyzerToken(libraryKeyword), name, toAnalyzerToken(semicolon))); | 1111 toAnalyzerToken(libraryKeyword), name, toAnalyzerToken(semicolon))); |
| 1113 } | 1112 } |
| 1114 | 1113 |
| 1115 @override | 1114 @override |
| 1116 void handleQualified(Token period) { | 1115 void handleQualified(Token period) { |
| 1117 SimpleIdentifier identifier = pop(); | 1116 SimpleIdentifier identifier = pop(); |
| 1118 var prefix = pop(); | 1117 var prefix = pop(); |
| 1119 if (prefix is List) { | 1118 if (prefix is List) { |
| 1120 // We're just accumulating components into a list. | 1119 // We're just accumulating components into a list. |
| 1121 prefix.add(identifier); | 1120 prefix.add(identifier); |
| 1122 push(prefix); | 1121 push(prefix); |
| 1123 } else if (prefix is SimpleIdentifier) { | 1122 } else if (prefix is SimpleIdentifier) { |
| 1124 // TODO(paulberry): resolve [identifier]. Note that BodyBuilder handles | 1123 // TODO(paulberry): resolve [identifier]. Note that BodyBuilder handles |
| 1125 // this situation using SendAccessor. | 1124 // this situation using SendAccessor. |
| 1126 push(ast.prefixedIdentifier(prefix, toAnalyzerToken(period), identifier)); | 1125 push(ast.prefixedIdentifier(prefix, toAnalyzerToken(period), identifier)); |
| 1127 } else { | 1126 } else { |
| 1128 // TODO(paulberry): implement. | 1127 // TODO(paulberry): implement. |
| 1129 logEvent('Qualified with >1 dot'); | 1128 logEvent('Qualified with >1 dot'); |
| 1130 } | 1129 } |
| 1131 } | 1130 } |
| 1132 | 1131 |
| 1133 @override | 1132 @override |
| 1134 void endPart(Token partKeyword, Token semicolon) { | 1133 void endPart(Token partKeyword, Token semicolon) { |
| 1135 debugEvent("Part"); | 1134 debugEvent("Part"); |
| 1136 StringLiteral uri = pop(); | 1135 StringLiteral uri = pop(); |
| 1137 List<Annotation> metadata = pop(); | 1136 List<Annotation> metadata = pop(); |
| 1138 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1137 Comment comment = pop(); |
| 1139 Comment comment = null; | |
| 1140 push(ast.partDirective(comment, metadata, toAnalyzerToken(partKeyword), uri, | 1138 push(ast.partDirective(comment, metadata, toAnalyzerToken(partKeyword), uri, |
| 1141 toAnalyzerToken(semicolon))); | 1139 toAnalyzerToken(semicolon))); |
| 1142 } | 1140 } |
| 1143 | 1141 |
| 1144 @override | 1142 @override |
| 1145 void endPartOf(Token partKeyword, Token semicolon) { | 1143 void endPartOf(Token partKeyword, Token semicolon) { |
| 1146 debugEvent("PartOf"); | 1144 debugEvent("PartOf"); |
| 1147 List<SimpleIdentifier> libraryName = pop(); | 1145 List<SimpleIdentifier> libraryName = pop(); |
| 1148 var name = ast.libraryIdentifier(libraryName); | 1146 var name = ast.libraryIdentifier(libraryName); |
| 1149 StringLiteral uri = null; // TODO(paulberry) | 1147 StringLiteral uri = null; // TODO(paulberry) |
| 1150 // TODO(paulberry,ahe): seems hacky. It would be nice if the parser passed | 1148 // TODO(paulberry,ahe): seems hacky. It would be nice if the parser passed |
| 1151 // in a reference to the "of" keyword. | 1149 // in a reference to the "of" keyword. |
| 1152 var ofKeyword = partKeyword.next; | 1150 var ofKeyword = partKeyword.next; |
| 1153 List<Annotation> metadata = pop(); | 1151 List<Annotation> metadata = pop(); |
| 1154 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1152 Comment comment = pop(); |
| 1155 Comment comment = null; | |
| 1156 push(ast.partOfDirective(comment, metadata, toAnalyzerToken(partKeyword), | 1153 push(ast.partOfDirective(comment, metadata, toAnalyzerToken(partKeyword), |
| 1157 toAnalyzerToken(ofKeyword), uri, name, toAnalyzerToken(semicolon))); | 1154 toAnalyzerToken(ofKeyword), uri, name, toAnalyzerToken(semicolon))); |
| 1158 } | 1155 } |
| 1159 | 1156 |
| 1160 void endUnnamedFunction(Token token) { | 1157 void endUnnamedFunction(Token token) { |
| 1161 // TODO(paulberry): set up scopes properly to resolve parameters and type | 1158 // TODO(paulberry): set up scopes properly to resolve parameters and type |
| 1162 // variables. Note that this is tricky due to the handling of initializers | 1159 // variables. Note that this is tricky due to the handling of initializers |
| 1163 // in constructors, so the logic should be shared with BodyBuilder as much | 1160 // in constructors, so the logic should be shared with BodyBuilder as much |
| 1164 // as possible. | 1161 // as possible. |
| 1165 debugEvent("UnnamedFunction"); | 1162 debugEvent("UnnamedFunction"); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1186 | 1183 |
| 1187 void endTopLevelFields(int count, Token beginToken, Token endToken) { | 1184 void endTopLevelFields(int count, Token beginToken, Token endToken) { |
| 1188 debugEvent("TopLevelFields"); | 1185 debugEvent("TopLevelFields"); |
| 1189 List<VariableDeclaration> variables = popList(count); | 1186 List<VariableDeclaration> variables = popList(count); |
| 1190 TypeAnnotation type = pop(); | 1187 TypeAnnotation type = pop(); |
| 1191 _Modifiers modifiers = pop(); | 1188 _Modifiers modifiers = pop(); |
| 1192 Token keyword = modifiers?.finalConstOrVarKeyword; | 1189 Token keyword = modifiers?.finalConstOrVarKeyword; |
| 1193 var variableList = ast.variableDeclarationList( | 1190 var variableList = ast.variableDeclarationList( |
| 1194 null, null, toAnalyzerToken(keyword), type, variables); | 1191 null, null, toAnalyzerToken(keyword), type, variables); |
| 1195 List<Annotation> metadata = pop(); | 1192 List<Annotation> metadata = pop(); |
| 1196 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1193 Comment comment = pop(); |
| 1197 Comment comment = null; | |
| 1198 push(ast.topLevelVariableDeclaration( | 1194 push(ast.topLevelVariableDeclaration( |
| 1199 comment, metadata, variableList, toAnalyzerToken(endToken))); | 1195 comment, metadata, variableList, toAnalyzerToken(endToken))); |
| 1200 } | 1196 } |
| 1201 | 1197 |
| 1202 @override | 1198 @override |
| 1203 void endTypeVariable(Token token, Token extendsOrSuper) { | 1199 void endTypeVariable(Token token, Token extendsOrSuper) { |
| 1204 // TODO(paulberry): set up scopes properly to resolve parameters and type | 1200 // TODO(paulberry): set up scopes properly to resolve parameters and type |
| 1205 // variables. Note that this is tricky due to the handling of initializers | 1201 // variables. Note that this is tricky due to the handling of initializers |
| 1206 // in constructors, so the logic should be shared with BodyBuilder as much | 1202 // in constructors, so the logic should be shared with BodyBuilder as much |
| 1207 // as possible. | 1203 // as possible. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1229 FunctionBody body = pop(); | 1225 FunctionBody body = pop(); |
| 1230 ConstructorName redirectedConstructor = null; // TODO(paulberry) | 1226 ConstructorName redirectedConstructor = null; // TODO(paulberry) |
| 1231 List<ConstructorInitializer> initializers = null; // TODO(paulberry) | 1227 List<ConstructorInitializer> initializers = null; // TODO(paulberry) |
| 1232 Token separator = null; // TODO(paulberry) | 1228 Token separator = null; // TODO(paulberry) |
| 1233 FormalParameterList parameters = pop(); | 1229 FormalParameterList parameters = pop(); |
| 1234 TypeParameterList typeParameters = pop(); // TODO(paulberry) | 1230 TypeParameterList typeParameters = pop(); // TODO(paulberry) |
| 1235 var name = pop(); | 1231 var name = pop(); |
| 1236 TypeAnnotation returnType = pop(); // TODO(paulberry) | 1232 TypeAnnotation returnType = pop(); // TODO(paulberry) |
| 1237 _Modifiers modifiers = pop(); | 1233 _Modifiers modifiers = pop(); |
| 1238 List<Annotation> metadata = pop(); | 1234 List<Annotation> metadata = pop(); |
| 1239 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1235 Comment comment = pop(); |
| 1240 Comment comment = null; | |
| 1241 Token period; | 1236 Token period; |
| 1242 void unnamedConstructor( | 1237 void unnamedConstructor( |
| 1243 SimpleIdentifier returnType, SimpleIdentifier name) { | 1238 SimpleIdentifier returnType, SimpleIdentifier name) { |
| 1244 push(ast.constructorDeclaration( | 1239 push(ast.constructorDeclaration( |
| 1245 comment, | 1240 comment, |
| 1246 metadata, | 1241 metadata, |
| 1247 toAnalyzerToken(modifiers?.externalKeyword), | 1242 toAnalyzerToken(modifiers?.externalKeyword), |
| 1248 toAnalyzerToken(modifiers?.finalConstOrVarKeyword), | 1243 toAnalyzerToken(modifiers?.finalConstOrVarKeyword), |
| 1249 null, // TODO(paulberry): factoryKeyword | 1244 null, // TODO(paulberry): factoryKeyword |
| 1250 returnType, | 1245 returnType, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 @override | 1299 @override |
| 1305 void endFunctionTypeAlias( | 1300 void endFunctionTypeAlias( |
| 1306 Token typedefKeyword, Token equals, Token endToken) { | 1301 Token typedefKeyword, Token equals, Token endToken) { |
| 1307 debugEvent("FunctionTypeAlias"); | 1302 debugEvent("FunctionTypeAlias"); |
| 1308 if (equals == null) { | 1303 if (equals == null) { |
| 1309 FormalParameterList parameters = pop(); | 1304 FormalParameterList parameters = pop(); |
| 1310 TypeParameterList typeParameters = pop(); | 1305 TypeParameterList typeParameters = pop(); |
| 1311 SimpleIdentifier name = pop(); | 1306 SimpleIdentifier name = pop(); |
| 1312 TypeAnnotation returnType = pop(); | 1307 TypeAnnotation returnType = pop(); |
| 1313 List<Annotation> metadata = pop(); | 1308 List<Annotation> metadata = pop(); |
| 1314 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1309 Comment comment = pop(); |
| 1315 Comment comment = null; | |
| 1316 push(ast.functionTypeAlias( | 1310 push(ast.functionTypeAlias( |
| 1317 comment, | 1311 comment, |
| 1318 metadata, | 1312 metadata, |
| 1319 toAnalyzerToken(typedefKeyword), | 1313 toAnalyzerToken(typedefKeyword), |
| 1320 returnType, | 1314 returnType, |
| 1321 name, | 1315 name, |
| 1322 typeParameters, | 1316 typeParameters, |
| 1323 parameters, | 1317 parameters, |
| 1324 toAnalyzerToken(endToken))); | 1318 toAnalyzerToken(endToken))); |
| 1325 } else { | 1319 } else { |
| 1326 TypeAnnotation type = pop(); | 1320 TypeAnnotation type = pop(); |
| 1327 TypeParameterList templateParameters = pop(); | 1321 TypeParameterList templateParameters = pop(); |
| 1328 SimpleIdentifier name = pop(); | 1322 SimpleIdentifier name = pop(); |
| 1329 List<Annotation> metadata = pop(); | 1323 List<Annotation> metadata = pop(); |
| 1330 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1324 Comment comment = pop(); |
| 1331 Comment comment = null; | |
| 1332 if (type is! GenericFunctionType) { | 1325 if (type is! GenericFunctionType) { |
| 1333 // TODO(paulberry) Generate an error and recover (better than | 1326 // TODO(paulberry) Generate an error and recover (better than |
| 1334 // this). | 1327 // this). |
| 1335 type = null; | 1328 type = null; |
| 1336 } | 1329 } |
| 1337 push(ast.genericTypeAlias( | 1330 push(ast.genericTypeAlias( |
| 1338 comment, | 1331 comment, |
| 1339 metadata, | 1332 metadata, |
| 1340 toAnalyzerToken(typedefKeyword), | 1333 toAnalyzerToken(typedefKeyword), |
| 1341 name, | 1334 name, |
| 1342 templateParameters, | 1335 templateParameters, |
| 1343 toAnalyzerToken(equals), | 1336 toAnalyzerToken(equals), |
| 1344 type, | 1337 type, |
| 1345 toAnalyzerToken(endToken))); | 1338 toAnalyzerToken(endToken))); |
| 1346 } | 1339 } |
| 1347 } | 1340 } |
| 1348 | 1341 |
| 1349 @override | 1342 @override |
| 1350 void endEnum(Token enumKeyword, Token endBrace, int count) { | 1343 void endEnum(Token enumKeyword, Token endBrace, int count) { |
| 1351 debugEvent("Enum"); | 1344 debugEvent("Enum"); |
| 1352 List<EnumConstantDeclaration> constants = popList(count); | 1345 List<EnumConstantDeclaration> constants = popList(count); |
| 1353 // TODO(paulberry,ahe): the parser should pass in the openBrace token. | 1346 // TODO(paulberry,ahe): the parser should pass in the openBrace token. |
| 1354 var openBrace = enumKeyword.next.next as BeginGroupToken; | 1347 var openBrace = enumKeyword.next.next as BeginGroupToken; |
| 1355 // TODO(paulberry): what if the '}' is missing and the parser has performed | 1348 // TODO(paulberry): what if the '}' is missing and the parser has performed |
| 1356 // error recovery? | 1349 // error recovery? |
| 1357 Token closeBrace = openBrace.endGroup; | 1350 Token closeBrace = openBrace.endGroup; |
| 1358 SimpleIdentifier name = pop(); | 1351 SimpleIdentifier name = pop(); |
| 1359 List<Annotation> metadata = pop(); | 1352 List<Annotation> metadata = pop(); |
| 1360 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1353 Comment comment = pop(); |
| 1361 Comment comment = null; | |
| 1362 push(ast.enumDeclaration( | 1354 push(ast.enumDeclaration( |
| 1363 comment, | 1355 comment, |
| 1364 metadata, | 1356 metadata, |
| 1365 toAnalyzerToken(enumKeyword), | 1357 toAnalyzerToken(enumKeyword), |
| 1366 name, | 1358 name, |
| 1367 toAnalyzerToken(openBrace), | 1359 toAnalyzerToken(openBrace), |
| 1368 constants, | 1360 constants, |
| 1369 toAnalyzerToken(closeBrace))); | 1361 toAnalyzerToken(closeBrace))); |
| 1370 } | 1362 } |
| 1371 | 1363 |
| 1372 @override | 1364 @override |
| 1373 void endTypeArguments(int count, Token beginToken, Token endToken) { | 1365 void endTypeArguments(int count, Token beginToken, Token endToken) { |
| 1374 debugEvent("TypeArguments"); | 1366 debugEvent("TypeArguments"); |
| 1375 List<TypeAnnotation> arguments = popList(count); | 1367 List<TypeAnnotation> arguments = popList(count); |
| 1376 push(ast.typeArgumentList( | 1368 push(ast.typeArgumentList( |
| 1377 toAnalyzerToken(beginToken), arguments, toAnalyzerToken(endToken))); | 1369 toAnalyzerToken(beginToken), arguments, toAnalyzerToken(endToken))); |
| 1378 } | 1370 } |
| 1379 | 1371 |
| 1380 @override | 1372 @override |
| 1381 void endFields( | 1373 void endFields( |
| 1382 int count, Token covariantKeyword, Token beginToken, Token endToken) { | 1374 int count, Token covariantKeyword, Token beginToken, Token endToken) { |
| 1383 debugEvent("Fields"); | 1375 debugEvent("Fields"); |
| 1384 List<VariableDeclaration> variables = popList(count); | 1376 List<VariableDeclaration> variables = popList(count); |
| 1385 TypeAnnotation type = pop(); | 1377 TypeAnnotation type = pop(); |
| 1386 _Modifiers modifiers = pop(); | 1378 _Modifiers modifiers = pop(); |
| 1387 var variableList = ast.variableDeclarationList(null, null, | 1379 var variableList = ast.variableDeclarationList(null, null, |
| 1388 toAnalyzerToken(modifiers?.finalConstOrVarKeyword), type, variables); | 1380 toAnalyzerToken(modifiers?.finalConstOrVarKeyword), type, variables); |
| 1389 List<Annotation> metadata = pop(); | 1381 List<Annotation> metadata = pop(); |
| 1390 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1382 Comment comment = pop(); |
| 1391 Comment comment = null; | |
| 1392 push(ast.fieldDeclaration2( | 1383 push(ast.fieldDeclaration2( |
| 1393 comment: comment, | 1384 comment: comment, |
| 1394 metadata: metadata, | 1385 metadata: metadata, |
| 1395 covariantKeyword: toAnalyzerToken(covariantKeyword), | 1386 covariantKeyword: toAnalyzerToken(covariantKeyword), |
| 1396 staticKeyword: toAnalyzerToken(modifiers?.staticKeyword), | 1387 staticKeyword: toAnalyzerToken(modifiers?.staticKeyword), |
| 1397 fieldList: variableList, | 1388 fieldList: variableList, |
| 1398 semicolon: toAnalyzerToken(endToken))); | 1389 semicolon: toAnalyzerToken(endToken))); |
| 1399 } | 1390 } |
| 1400 | 1391 |
| 1401 @override | 1392 @override |
| 1402 void handleOperatorName(Token operatorKeyword, Token token) { | 1393 void handleOperatorName(Token operatorKeyword, Token token) { |
| 1403 debugEvent("OperatorName"); | 1394 debugEvent("OperatorName"); |
| 1404 push(new _OperatorName(operatorKeyword, | 1395 push(new _OperatorName(operatorKeyword, |
| 1405 ast.simpleIdentifier(toAnalyzerToken(token), isDeclaration: true))); | 1396 ast.simpleIdentifier(toAnalyzerToken(token), isDeclaration: true))); |
| 1406 } | 1397 } |
| 1407 | 1398 |
| 1399 @override |
| 1400 void beginMetadataStar(Token token) { |
| 1401 debugEvent("beginMetadataStar"); |
| 1402 if (token.precedingComments != null) { |
| 1403 push(_toAnalyzerComment(token.precedingComments)); |
| 1404 } else { |
| 1405 push(NullValue.Comments); |
| 1406 } |
| 1407 } |
| 1408 |
| 1408 ParameterKind _toAnalyzerParameterKind(FormalParameterType type) { | 1409 ParameterKind _toAnalyzerParameterKind(FormalParameterType type) { |
| 1409 if (type == FormalParameterType.POSITIONAL) { | 1410 if (type == FormalParameterType.POSITIONAL) { |
| 1410 return ParameterKind.POSITIONAL; | 1411 return ParameterKind.POSITIONAL; |
| 1411 } else if (type == FormalParameterType.NAMED) { | 1412 } else if (type == FormalParameterType.NAMED) { |
| 1412 return ParameterKind.NAMED; | 1413 return ParameterKind.NAMED; |
| 1413 } else { | 1414 } else { |
| 1414 return ParameterKind.REQUIRED; | 1415 return ParameterKind.REQUIRED; |
| 1415 } | 1416 } |
| 1416 } | 1417 } |
| 1418 |
| 1419 Comment _toAnalyzerComment(Token comments) { |
| 1420 if (comments == null) return null; |
| 1421 |
| 1422 // This is temporary placeholder code to get tests to pass. |
| 1423 // TODO(paulberry): after analyzer and fasta token representations are |
| 1424 // unified, refactor the code in analyzer's parser that handles |
| 1425 // documentation comments so that it is reusable, and reuse it here. |
| 1426 // See Parser.parseCommentAndMetadata |
| 1427 var tokens = <analyzer.Token>[toAnalyzerCommentToken(comments)]; |
| 1428 var references = <CommentReference>[]; |
| 1429 return ast.documentationComment(tokens, references); |
| 1430 } |
| 1417 } | 1431 } |
| 1418 | 1432 |
| 1419 /// Data structure placed on the stack to represent a class body. | 1433 /// Data structure placed on the stack to represent a class body. |
| 1420 /// | 1434 /// |
| 1421 /// This is needed because analyzer has no separate AST representation of a | 1435 /// This is needed because analyzer has no separate AST representation of a |
| 1422 /// class body; it simply stores all of the relevant data in the | 1436 /// class body; it simply stores all of the relevant data in the |
| 1423 /// [ClassDeclaration] object. | 1437 /// [ClassDeclaration] object. |
| 1424 class _ClassBody { | 1438 class _ClassBody { |
| 1425 final Token beginToken; | 1439 final Token beginToken; |
| 1426 | 1440 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 } else if (identical('static', s)) { | 1514 } else if (identical('static', s)) { |
| 1501 staticKeyword = token; | 1515 staticKeyword = token; |
| 1502 } else if (identical('var', s)) { | 1516 } else if (identical('var', s)) { |
| 1503 finalConstOrVarKeyword = token; | 1517 finalConstOrVarKeyword = token; |
| 1504 } else { | 1518 } else { |
| 1505 internalError('Unhandled modifier: $s'); | 1519 internalError('Unhandled modifier: $s'); |
| 1506 } | 1520 } |
| 1507 } | 1521 } |
| 1508 } | 1522 } |
| 1509 } | 1523 } |
| OLD | NEW |