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

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

Issue 2567133002: Add support for the new function-type syntax. (Closed)
Patch Set: Fixes after rebase. Created 3 years, 10 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
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;
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 void endLiteralSymbol(Token hashToken, int identifierCount) { 424 void endLiteralSymbol(Token hashToken, int identifierCount) {
425 debugEvent("LiteralSymbol"); 425 debugEvent("LiteralSymbol");
426 List<analyzer.Token> components = new List<analyzer.Token>(identifierCount); 426 List<analyzer.Token> components = new List<analyzer.Token>(identifierCount);
427 for (int i = identifierCount - 1; i >= 0; i--) { 427 for (int i = identifierCount - 1; i >= 0; i--) {
428 SimpleIdentifier identifier = pop(); 428 SimpleIdentifier identifier = pop();
429 components[i] = identifier.token; 429 components[i] = identifier.token;
430 } 430 }
431 push(ast.symbolLiteral(toAnalyzerToken(hashToken), components)); 431 push(ast.symbolLiteral(toAnalyzerToken(hashToken), components));
432 } 432 }
433 433
434 void endType(Token beginToken, Token endToken) { 434 void handleType(Token beginToken, Token endToken) {
435 debugEvent("Type"); 435 debugEvent("Type");
436 TypeArgumentList arguments = pop(); 436 TypeArgumentList arguments = pop();
437 Identifier name = pop(); 437 Identifier name = pop();
438 // TODO(paulberry,ahe): what if the type doesn't resolve to a class 438 // TODO(paulberry,ahe): what if the type doesn't resolve to a class
439 // element? Try to share code with BodyBuilder.builderToFirstExpression. 439 // element? Try to share code with BodyBuilder.builderToFirstExpression.
440 KernelClassElement cls = name.staticElement; 440 KernelClassElement cls = name.staticElement;
441 push(ast.typeName(name, arguments)..type = cls?.rawType); 441 push(ast.typeName(name, arguments)..type = cls?.rawType);
442 } 442 }
443 443
444 void handleAsOperator(Token operator, Token endToken) { 444 void handleAsOperator(Token operator, Token endToken) {
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 debugEvent("Member"); 1055 debugEvent("Member");
1056 } 1056 }
1057 1057
1058 @override 1058 @override
1059 void handleVoidKeyword(Token token) { 1059 void handleVoidKeyword(Token token) {
1060 debugEvent("VoidKeyword"); 1060 debugEvent("VoidKeyword");
1061 // TODO(paulberry): is this sufficient, or do we need to hook the "void" 1061 // TODO(paulberry): is this sufficient, or do we need to hook the "void"
1062 // keyword up to an element? 1062 // keyword up to an element?
1063 handleIdentifier(token, IdentifierContext.typeReference); 1063 handleIdentifier(token, IdentifierContext.typeReference);
1064 handleNoTypeArguments(token); 1064 handleNoTypeArguments(token);
1065 endType(token, token); 1065 handleType(token, token);
1066 } 1066 }
1067 1067
1068 @override 1068 @override
1069 void endFunctionTypeAlias(Token typedefKeyword, Token endToken) { 1069 void endFunctionTypeAlias(
1070 Token typedefKeyword, Token equals, Token endToken) {
1070 debugEvent("FunctionTypeAlias"); 1071 debugEvent("FunctionTypeAlias");
1071 FormalParameterList parameters = pop(); 1072 if (equals == null) {
1072 TypeParameterList typeParameters = pop(); 1073 FormalParameterList parameters = pop();
1073 SimpleIdentifier name = pop(); 1074 TypeParameterList typeParameters = pop();
1074 TypeAnnotation returnType = pop(); 1075 SimpleIdentifier name = pop();
1075 List<Annotation> metadata = pop(); 1076 TypeAnnotation returnType = pop();
1076 // TODO(paulberry): capture doc comments. See dartbug.com/28851. 1077 List<Annotation> metadata = pop();
1077 Comment comment = null; 1078 // TODO(paulberry): capture doc comments. See dartbug.com/28851.
1078 push(ast.functionTypeAlias( 1079 Comment comment = null;
1079 comment, 1080 push(ast.functionTypeAlias(
1080 metadata, 1081 comment,
1081 toAnalyzerToken(typedefKeyword), 1082 metadata,
1082 returnType, 1083 toAnalyzerToken(typedefKeyword),
1083 name, 1084 returnType,
1084 typeParameters, 1085 name,
1085 parameters, 1086 typeParameters,
1086 toAnalyzerToken(endToken))); 1087 parameters,
1088 toAnalyzerToken(endToken)));
1089 } else {
1090 TypeAnnotation type = pop();
1091 TypeParameterList templateParameters = pop();
1092 SimpleIdentifier name = pop();
1093 List<Annotation> metadata = pop();
1094 // TODO(paulberry): capture doc comments. See dartbug.com/28851.
1095 Comment comment = null;
1096 if (type is! GenericFunctionType) {
1097 // TODO(paulberry) Generate an error and recover (better than
1098 // this).
1099 type = null;
1100 }
1101 push(ast.genericTypeAlias(
1102 comment,
1103 metadata,
1104 toAnalyzerToken(typedefKeyword),
1105 name,
1106 templateParameters,
1107 toAnalyzerToken(equals),
1108 type,
1109 toAnalyzerToken(endToken)));
1110 }
1087 } 1111 }
1088 1112
1089 @override 1113 @override
1090 void endEnum(Token enumKeyword, Token endBrace, int count) { 1114 void endEnum(Token enumKeyword, Token endBrace, int count) {
1091 debugEvent("Enum"); 1115 debugEvent("Enum");
1092 List<EnumConstantDeclaration> constants = popList(count); 1116 List<EnumConstantDeclaration> constants = popList(count);
1093 // TODO(paulberry,ahe): the parser should pass in the openBrace token. 1117 // TODO(paulberry,ahe): the parser should pass in the openBrace token.
1094 var openBrace = enumKeyword.next.next as BeginGroupToken; 1118 var openBrace = enumKeyword.next.next as BeginGroupToken;
1095 // TODO(paulberry): what if the '}' is missing and the parser has performed 1119 // TODO(paulberry): what if the '}' is missing and the parser has performed
1096 // error recovery? 1120 // error recovery?
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 /// [ClassDeclaration] or [ClassTypeAlias] object. 1183 /// [ClassDeclaration] or [ClassTypeAlias] object.
1160 class _MixinApplication { 1184 class _MixinApplication {
1161 final TypeName supertype; 1185 final TypeName supertype;
1162 1186
1163 final Token withKeyword; 1187 final Token withKeyword;
1164 1188
1165 final List<TypeName> mixinTypes; 1189 final List<TypeName> mixinTypes;
1166 1190
1167 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); 1191 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes);
1168 } 1192 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698