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

Unified Diff: pkg/compiler/lib/src/parser/node_listener.dart

Issue 2567133002: Add support for the new function-type syntax. (Closed)
Patch Set: Remove obsolete named argument. Created 3 years, 12 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/compiler/lib/src/parser/node_listener.dart
diff --git a/pkg/compiler/lib/src/parser/node_listener.dart b/pkg/compiler/lib/src/parser/node_listener.dart
index 4dc325cef5becfcb281cae7f5dc8aaa55653dc84..e11a5f1a1bb64898df0b715ffcd08fbb1603140b 100644
--- a/pkg/compiler/lib/src/parser/node_listener.dart
+++ b/pkg/compiler/lib/src/parser/node_listener.dart
@@ -12,7 +12,6 @@ import '../tokens/token.dart' show ErrorToken, StringToken, Token;
import '../tree/tree.dart';
import '../util/util.dart' show Link;
import 'element_listener.dart' show ElementListener, ScannerOptions;
-import 'partial_elements.dart' show PartialFunctionElement;
class NodeListener extends ElementListener {
NodeListener(ScannerOptions scannerOptions, DiagnosticReporter reporter,
@@ -115,13 +114,58 @@ class NodeListener extends ElementListener {
pushNode(makeNodeList(count, null, null, '\n'));
}
- void endFunctionTypeAlias(Token typedefKeyword, Token endToken) {
+ void endTypedef(Token typedefKeyword, Token equals, Token endToken) {
+ bool isGeneralizedTypeAlias;
+ NodeList templateParameters;
+ TypeAnnotation returnType;
+ Identifier name;
+ NodeList typeParameters;
+ NodeList formals;
+ if (equals == null) {
+ isGeneralizedTypeAlias = false;
+ formals = popNode();
+ templateParameters = popNode();
+ name = popNode();
+ returnType = popNode();
+ } else {
+ // TODO(floitsch): keep using the `FunctionTypeAnnotation' node.
+ isGeneralizedTypeAlias = true;
+ Node type = popNode();
+ if (type.asFunctionTypeAnnotation() == null) {
+ // TODO(floitsch): The parser should diagnose this problem, not
+ // this listener.
+ // However, this problem goes away, when we allow aliases for
+ // non-function types too.
+ reportFatalError(type, 'Expected a function type.');
+ }
+ FunctionTypeAnnotation functionType = type;
+ templateParameters = popNode();
+ name = popNode();
+ returnType = functionType.returnType;
+ typeParameters = functionType.typeParameters;
+ formals = functionType.formals;
+ }
+ pushNode(new Typedef(
+ isGeneralizedTypeAlias,
+ templateParameters,
+ returnType,
+ name,
+ typeParameters,
+ formals,
+ typedefKeyword,
+ endToken));
+ }
+
+ void handleNoName(Token token) {
+ pushNode(null);
+ }
+
+ void endFunctionType(Token functionToken, Token endToken) {
NodeList formals = popNode();
NodeList typeParameters = popNode();
- Identifier name = popNode();
TypeAnnotation returnType = popNode();
- pushNode(new Typedef(
- returnType, name, typeParameters, formals, typedefKeyword, endToken));
+ pushNode(new FunctionTypeAnnotation(
+ returnType, functionToken, typeParameters, formals));
}
void endNamedMixinApplication(
@@ -206,7 +250,7 @@ class NodeListener extends ElementListener {
NodeList typeArguments = popNode();
Node classReference = popNode();
if (typeArguments != null) {
- classReference = new TypeAnnotation(classReference, typeArguments);
+ classReference = new NominalTypeAnnotation(classReference, typeArguments);
} else {
Identifier identifier = classReference.asIdentifier();
Send send = classReference.asSend();
@@ -791,7 +835,7 @@ class NodeListener extends ElementListener {
NodeList typeArguments = popNode();
Node receiver = popNode();
if (typeArguments != null) {
- receiver = new TypeAnnotation(receiver, typeArguments);
+ receiver = new NominalTypeAnnotation(receiver, typeArguments);
recoverableError(typeArguments, 'Type arguments are not allowed here.');
} else {
Identifier identifier = receiver.asIdentifier();

Powered by Google App Engine
This is Rietveld 408576698