Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: pkg/analyzer/lib/src/fasta/ast_builder.dart

Issue 2876813002: Implement generalized function types. (Closed)
Patch Set: Address comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_fasta_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ast/token.dart' show Token, TokenType; 11 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType;
12 import 'package:analyzer/dart/element/element.dart' show Element; 12 import 'package:analyzer/dart/element/element.dart' show Element;
13 import 'package:front_end/src/fasta/parser/parser.dart' 13 import 'package:front_end/src/fasta/parser/parser.dart'
14 show FormalParameterType, Parser; 14 show FormalParameterType, MemberKind, Parser;
15 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; 15 import 'package:front_end/src/fasta/scanner/string_scanner.dart';
16 import 'package:front_end/src/fasta/scanner/token.dart' 16 import 'package:front_end/src/fasta/scanner/token.dart'
17 show BeginGroupToken, CommentToken; 17 show BeginGroupToken, CommentToken;
18 import 'package:front_end/src/scanner/token.dart' as analyzer; 18 import 'package:front_end/src/scanner/token.dart' as analyzer;
19 19
20 import 'package:front_end/src/fasta/errors.dart' show internalError; 20 import 'package:front_end/src/fasta/errors.dart' show internalError;
21 import 'package:front_end/src/fasta/fasta_codes.dart' 21 import 'package:front_end/src/fasta/fasta_codes.dart'
22 show FastaMessage, codeExpectedExpression, codeExpectedFunctionBody; 22 show FastaMessage, codeExpectedExpression, codeExpectedFunctionBody;
23 import 'package:front_end/src/fasta/kernel/kernel_builder.dart' 23 import 'package:front_end/src/fasta/kernel/kernel_builder.dart'
24 show Builder, KernelLibraryBuilder, ProcedureBuilder, Scope; 24 show Builder, KernelLibraryBuilder, ProcedureBuilder, Scope;
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 variableList.keyword, 844 variableList.keyword,
845 variableList.type, 845 variableList.type,
846 variableList.variables.single.name), 846 variableList.variables.single.name),
847 toAnalyzerToken(inKeyword), 847 toAnalyzerToken(inKeyword),
848 iterator, 848 iterator,
849 toAnalyzerToken(rightParenthesis), 849 toAnalyzerToken(rightParenthesis),
850 body)); 850 body));
851 } 851 }
852 } 852 }
853 853
854 void endFormalParameter(Token covariantKeyword, Token thisKeyword, 854 void endFormalParameter(Token thisKeyword, Token nameToken,
855 Token nameToken, FormalParameterType kind) { 855 FormalParameterType kind, MemberKind memberKind) {
856 debugEvent("FormalParameter"); 856 debugEvent("FormalParameter");
857 _ParameterDefaultValue defaultValue = pop(); 857 _ParameterDefaultValue defaultValue = pop();
858 858
859 AstNode nameOrFunctionTypedParameter = pop(); 859 AstNode nameOrFunctionTypedParameter = pop();
860 860
861 FormalParameter node; 861 FormalParameter node;
862 SimpleIdentifier name; 862 SimpleIdentifier name;
863 if (nameOrFunctionTypedParameter is FormalParameter) { 863 if (nameOrFunctionTypedParameter is FormalParameter) {
864 node = nameOrFunctionTypedParameter; 864 node = nameOrFunctionTypedParameter;
865 name = nameOrFunctionTypedParameter.identifier; 865 name = nameOrFunctionTypedParameter.identifier;
866 } else { 866 } else {
867 name = nameOrFunctionTypedParameter; 867 name = nameOrFunctionTypedParameter;
868 TypeAnnotation type = pop(); 868 TypeAnnotation type = pop();
869 _Modifiers modifiers = pop(); 869 _Modifiers modifiers = pop();
870 Token keyword = modifiers?.finalConstOrVarKeyword; 870 Token keyword = modifiers?.finalConstOrVarKeyword;
871 Token covariantKeyword = modifiers?.covariantKeyword;
871 pop(); // TODO(paulberry): Metadata. 872 pop(); // TODO(paulberry): Metadata.
872 Comment comment = pop(); 873 Comment comment = pop();
873 if (thisKeyword == null) { 874 if (thisKeyword == null) {
874 node = ast.simpleFormalParameter2( 875 node = ast.simpleFormalParameter2(
875 comment: comment, 876 comment: comment,
876 covariantKeyword: toAnalyzerToken(covariantKeyword), 877 covariantKeyword: toAnalyzerToken(covariantKeyword),
877 keyword: toAnalyzerToken(keyword), 878 keyword: toAnalyzerToken(keyword),
878 type: type, 879 type: type,
879 identifier: name); 880 identifier: name);
880 } else { 881 } else {
(...skipping 20 matching lines...) Expand all
901 902
902 if (name != null) { 903 if (name != null) {
903 scope[name.name] = 904 scope[name.name] =
904 name.staticElement = new AnalyzerParameterElement(node); 905 name.staticElement = new AnalyzerParameterElement(node);
905 } 906 }
906 push(node); 907 push(node);
907 } 908 }
908 909
909 @override 910 @override
910 void endFunctionTypedFormalParameter( 911 void endFunctionTypedFormalParameter(
911 Token covariantKeyword, Token thisKeyword, FormalParameterType kind) { 912 Token thisKeyword, FormalParameterType kind) {
912 debugEvent("FunctionTypedFormalParameter"); 913 debugEvent("FunctionTypedFormalParameter");
913 914
914 FormalParameterList formalParameters = pop(); 915 FormalParameterList formalParameters = pop();
915 TypeParameterList typeParameters = pop(); 916 TypeParameterList typeParameters = pop();
916 SimpleIdentifier name = pop(); 917 SimpleIdentifier name = pop();
917 TypeAnnotation returnType = pop(); 918 TypeAnnotation returnType = pop();
918 919
919 { 920 _Modifiers modifiers = pop();
920 _Modifiers modifiers = pop(); 921 Token covariantKeyword = modifiers?.covariantKeyword;
921 if (modifiers != null) {
922 // TODO(scheglov): Report error.
923 internalError('Unexpected modifier. Report an error.');
924 }
925 }
926 922
927 pop(); // TODO(paulberry): Metadata. 923 pop(); // TODO(paulberry): Metadata.
928 Comment comment = pop(); 924 Comment comment = pop();
929 925
930 FormalParameter node; 926 FormalParameter node;
931 if (thisKeyword == null) { 927 if (thisKeyword == null) {
932 node = ast.functionTypedFormalParameter2( 928 node = ast.functionTypedFormalParameter2(
933 comment: comment, 929 comment: comment,
934 covariantKeyword: toAnalyzerToken(covariantKeyword), 930 covariantKeyword: toAnalyzerToken(covariantKeyword),
935 returnType: returnType, 931 returnType: returnType,
(...skipping 13 matching lines...) Expand all
949 period: toAnalyzerToken(period), 945 period: toAnalyzerToken(period),
950 identifier: name, 946 identifier: name,
951 typeParameters: typeParameters, 947 typeParameters: typeParameters,
952 parameters: formalParameters); 948 parameters: formalParameters);
953 } 949 }
954 950
955 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node); 951 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node);
956 push(node); 952 push(node);
957 } 953 }
958 954
959 void endFormalParameters(int count, Token beginToken, Token endToken) { 955 void endFormalParameters(
956 int count, Token beginToken, Token endToken, MemberKind kind) {
960 debugEvent("FormalParameters"); 957 debugEvent("FormalParameters");
961 List rawParameters = popList(count) ?? const <Object>[]; 958 List rawParameters = popList(count) ?? const <Object>[];
962 List<FormalParameter> parameters = <FormalParameter>[]; 959 List<FormalParameter> parameters = <FormalParameter>[];
963 Token leftDelimiter; 960 Token leftDelimiter;
964 Token rightDelimiter; 961 Token rightDelimiter;
965 for (Object raw in rawParameters) { 962 for (Object raw in rawParameters) {
966 if (raw is _OptionalFormalParameters) { 963 if (raw is _OptionalFormalParameters) {
967 parameters.addAll(raw.parameters); 964 parameters.addAll(raw.parameters);
968 leftDelimiter = raw.leftDelimiter; 965 leftDelimiter = raw.leftDelimiter;
969 rightDelimiter = raw.rightDelimiter; 966 rightDelimiter = raw.rightDelimiter;
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 1824
1828 @override 1825 @override
1829 void endTypeArguments(int count, Token beginToken, Token endToken) { 1826 void endTypeArguments(int count, Token beginToken, Token endToken) {
1830 debugEvent("TypeArguments"); 1827 debugEvent("TypeArguments");
1831 List<TypeAnnotation> arguments = popList(count); 1828 List<TypeAnnotation> arguments = popList(count);
1832 push(ast.typeArgumentList( 1829 push(ast.typeArgumentList(
1833 toAnalyzerToken(beginToken), arguments, toAnalyzerToken(endToken))); 1830 toAnalyzerToken(beginToken), arguments, toAnalyzerToken(endToken)));
1834 } 1831 }
1835 1832
1836 @override 1833 @override
1837 void endFields( 1834 void endFields(int count, Token beginToken, Token endToken) {
1838 int count, Token covariantKeyword, Token beginToken, Token endToken) {
1839 debugEvent("Fields"); 1835 debugEvent("Fields");
1840 List<VariableDeclaration> variables = popList(count); 1836 List<VariableDeclaration> variables = popList(count);
1841 TypeAnnotation type = pop(); 1837 TypeAnnotation type = pop();
1842 _Modifiers modifiers = pop(); 1838 _Modifiers modifiers = pop();
1843 var variableList = ast.variableDeclarationList(null, null, 1839 var variableList = ast.variableDeclarationList(null, null,
1844 toAnalyzerToken(modifiers?.finalConstOrVarKeyword), type, variables); 1840 toAnalyzerToken(modifiers?.finalConstOrVarKeyword), type, variables);
1841 Token covariantKeyword = modifiers?.covariantKeyword;
1845 List<Annotation> metadata = pop(); 1842 List<Annotation> metadata = pop();
1846 Comment comment = pop(); 1843 Comment comment = pop();
1847 push(ast.fieldDeclaration2( 1844 push(ast.fieldDeclaration2(
1848 comment: comment, 1845 comment: comment,
1849 metadata: metadata, 1846 metadata: metadata,
1850 covariantKeyword: toAnalyzerToken(covariantKeyword), 1847 covariantKeyword: toAnalyzerToken(covariantKeyword),
1851 staticKeyword: toAnalyzerToken(modifiers?.staticKeyword), 1848 staticKeyword: toAnalyzerToken(modifiers?.staticKeyword),
1852 fieldList: variableList, 1849 fieldList: variableList,
1853 semicolon: toAnalyzerToken(endToken))); 1850 semicolon: toAnalyzerToken(endToken)));
1854 } 1851 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 _OperatorName(this.operatorKeyword, this.name); 2059 _OperatorName(this.operatorKeyword, this.name);
2063 } 2060 }
2064 2061
2065 /// Data structure placed on the stack to represent a non-empty sequence 2062 /// Data structure placed on the stack to represent a non-empty sequence
2066 /// of modifiers. 2063 /// of modifiers.
2067 class _Modifiers { 2064 class _Modifiers {
2068 Token abstractKeyword; 2065 Token abstractKeyword;
2069 Token externalKeyword; 2066 Token externalKeyword;
2070 Token finalConstOrVarKeyword; 2067 Token finalConstOrVarKeyword;
2071 Token staticKeyword; 2068 Token staticKeyword;
2069 Token covariantKeyword;
2072 2070
2073 _Modifiers(List<Token> modifierTokens) { 2071 _Modifiers(List<Token> modifierTokens) {
2074 // No need to check the order and uniqueness of the modifiers, or that 2072 // No need to check the order and uniqueness of the modifiers, or that
2075 // disallowed modifiers are not used; the parser should do that. 2073 // disallowed modifiers are not used; the parser should do that.
2076 // TODO(paulberry,ahe): implement the necessary logic in the parser. 2074 // TODO(paulberry,ahe): implement the necessary logic in the parser.
2077 for (var token in modifierTokens) { 2075 for (var token in modifierTokens) {
2078 var s = token.lexeme; 2076 var s = token.lexeme;
2079 if (identical('abstract', s)) { 2077 if (identical('abstract', s)) {
2080 abstractKeyword = token; 2078 abstractKeyword = token;
2081 } else if (identical('const', s)) { 2079 } else if (identical('const', s)) {
2082 finalConstOrVarKeyword = token; 2080 finalConstOrVarKeyword = token;
2083 } else if (identical('external', s)) { 2081 } else if (identical('external', s)) {
2084 externalKeyword = token; 2082 externalKeyword = token;
2085 } else if (identical('final', s)) { 2083 } else if (identical('final', s)) {
2086 finalConstOrVarKeyword = token; 2084 finalConstOrVarKeyword = token;
2087 } else if (identical('static', s)) { 2085 } else if (identical('static', s)) {
2088 staticKeyword = token; 2086 staticKeyword = token;
2089 } else if (identical('var', s)) { 2087 } else if (identical('var', s)) {
2090 finalConstOrVarKeyword = token; 2088 finalConstOrVarKeyword = token;
2089 } else if (identical('covariant', s)) {
2090 covariantKeyword = token;
2091 } else { 2091 } else {
2092 internalError('Unhandled modifier: $s'); 2092 internalError('Unhandled modifier: $s');
2093 } 2093 }
2094 } 2094 }
2095 } 2095 }
2096 } 2096 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_fasta_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698