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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart b/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
index 73cd841f17493a8d41bf5c8e4b788e7bf1e461e7..5e8711a31123b8d5edbd77d0f8edb89f5f9bb513 100644
--- a/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
+++ b/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
@@ -431,7 +431,7 @@ class AstBuilder extends ScopeListener {
push(ast.symbolLiteral(toAnalyzerToken(hashToken), components));
}
- void endType(Token beginToken, Token endToken) {
+ void handleType(Token beginToken, Token endToken) {
debugEvent("Type");
TypeArgumentList arguments = pop();
Identifier name = pop();
@@ -1062,28 +1062,52 @@ class AstBuilder extends ScopeListener {
// keyword up to an element?
handleIdentifier(token, IdentifierContext.typeReference);
handleNoTypeArguments(token);
- endType(token, token);
+ handleType(token, token);
}
@override
- void endFunctionTypeAlias(Token typedefKeyword, Token endToken) {
+ void endFunctionTypeAlias(
+ Token typedefKeyword, Token equals, Token endToken) {
debugEvent("FunctionTypeAlias");
- FormalParameterList parameters = pop();
- TypeParameterList typeParameters = pop();
- SimpleIdentifier name = pop();
- TypeAnnotation returnType = pop();
- List<Annotation> metadata = pop();
- // TODO(paulberry): capture doc comments. See dartbug.com/28851.
- Comment comment = null;
- push(ast.functionTypeAlias(
- comment,
- metadata,
- toAnalyzerToken(typedefKeyword),
- returnType,
- name,
- typeParameters,
- parameters,
- toAnalyzerToken(endToken)));
+ if (equals == null) {
+ FormalParameterList parameters = pop();
+ TypeParameterList typeParameters = pop();
+ SimpleIdentifier name = pop();
+ TypeAnnotation returnType = pop();
+ List<Annotation> metadata = pop();
+ // TODO(paulberry): capture doc comments. See dartbug.com/28851.
+ Comment comment = null;
+ push(ast.functionTypeAlias(
+ comment,
+ metadata,
+ toAnalyzerToken(typedefKeyword),
+ returnType,
+ name,
+ typeParameters,
+ parameters,
+ toAnalyzerToken(endToken)));
+ } else {
+ TypeAnnotation type = pop();
+ TypeParameterList templateParameters = pop();
+ SimpleIdentifier name = pop();
+ List<Annotation> metadata = pop();
+ // TODO(paulberry): capture doc comments. See dartbug.com/28851.
+ Comment comment = null;
+ if (type is! GenericFunctionType) {
+ // TODO(paulberry) Generate an error and recover (better than
+ // this).
+ type = null;
+ }
+ push(ast.genericTypeAlias(
+ comment,
+ metadata,
+ toAnalyzerToken(typedefKeyword),
+ name,
+ templateParameters,
+ toAnalyzerToken(equals),
+ type,
+ toAnalyzerToken(endToken)));
+ }
}
@override

Powered by Google App Engine
This is Rietveld 408576698