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

Unified Diff: pkg/compiler/lib/src/tree/nodes.dart

Issue 2567133002: Add support for the new function-type syntax. (Closed)
Patch Set: Update status files and update test-generator for checked mode. Created 4 years 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/tree/nodes.dart
diff --git a/pkg/compiler/lib/src/tree/nodes.dart b/pkg/compiler/lib/src/tree/nodes.dart
index 1e5f9ddbdd41e6e4b2cf65bb0957ce6282f35458..980bff6ca87f9682abf396d6402d5aba47e8f699 100644
--- a/pkg/compiler/lib/src/tree/nodes.dart
+++ b/pkg/compiler/lib/src/tree/nodes.dart
@@ -48,6 +48,10 @@ abstract class Visitor<R> {
R visitForIn(ForIn node) => visitLoop(node);
R visitFunctionDeclaration(FunctionDeclaration node) => visitStatement(node);
R visitFunctionExpression(FunctionExpression node) => visitExpression(node);
+ R visitFunctionTypeAnnotation(FunctionTypeAnnotation node) {
+ return visitTypeAnnotation(node);
+ }
+
R visitGotoStatement(GotoStatement node) => visitStatement(node);
R visitIdentifier(Identifier node) => visitExpression(node);
R visitImport(Import node) => visitLibraryDependency(node);
@@ -79,6 +83,10 @@ abstract class Visitor<R> {
R visitNewExpression(NewExpression node) => visitExpression(node);
R visitNodeList(NodeList node) => visitNode(node);
+ R visitNominalTypeAnnotation(NominalTypeAnnotation node) {
+ return visitTypeAnnotation(node);
+ }
+
R visitOperator(Operator node) => visitIdentifier(node);
R visitParenthesizedExpression(ParenthesizedExpression node) {
return visitExpression(node);
@@ -176,6 +184,10 @@ abstract class Visitor1<R, A> {
return visitExpression(node, arg);
}
+ R visitFunctionTypeAnnotation(FunctionTypeAnnotation node, A arg) {
+ return visitTypeAnnotation(node, arg);
+ }
+
R visitGotoStatement(GotoStatement node, A arg) {
return visitStatement(node, arg);
}
@@ -225,6 +237,10 @@ abstract class Visitor1<R, A> {
R visitNewExpression(NewExpression node, A arg) => visitExpression(node, arg);
R visitNodeList(NodeList node, A arg) => visitNode(node, arg);
+ R visitNominalTypeAnnotation(NominalTypeAnnotation node, A arg) {
+ visitTypeAnnotation(node, arg);
+ }
+
R visitOperator(Operator node, A arg) => visitIdentifier(node, arg);
R visitParenthesizedExpression(ParenthesizedExpression node, A arg) {
return visitExpression(node, arg);
@@ -260,8 +276,8 @@ abstract class Visitor1<R, A> {
R visitLiteralSymbol(LiteralSymbol node, A arg) => visitExpression(node, arg);
R visitThrow(Throw node, A arg) => visitExpression(node, arg);
R visitTryStatement(TryStatement node, A arg) => visitStatement(node, arg);
- R visitTypeAnnotation(TypeAnnotation node, A arg) => visitNode(node, arg);
R visitTypedef(Typedef node, A arg) => visitNode(node, arg);
+ R visitTypeAnnotation(TypeAnnotation node, A arg) => visistNode(node, arg);
R visitTypeVariable(TypeVariable node, A arg) => visitNode(node, arg);
R visitVariableDefinitions(VariableDefinitions node, A arg) {
return visitStatement(node, arg);
@@ -360,6 +376,7 @@ abstract class Node extends NullTreeElementMixin implements Spannable {
ForIn asForIn() => null;
FunctionDeclaration asFunctionDeclaration() => null;
FunctionExpression asFunctionExpression() => null;
+ FunctionTypeAnnotation asFunctionTypeAnnotation() => null;
Identifier asIdentifier() => null;
If asIf() => null;
Import asImport() => null;
@@ -383,6 +400,7 @@ abstract class Node extends NullTreeElementMixin implements Spannable {
NamedMixinApplication asNamedMixinApplication() => null;
NewExpression asNewExpression() => null;
NodeList asNodeList() => null;
+ NominalTypeAnnotation asNominalTypeAnnotation() => null;
Operator asOperator() => null;
ParenthesizedExpression asParenthesizedExpression() => null;
Part asPart() => null;
@@ -401,7 +419,6 @@ abstract class Node extends NullTreeElementMixin implements Spannable {
SwitchStatement asSwitchStatement() => null;
Throw asThrow() => null;
TryStatement asTryStatement() => null;
- TypeAnnotation asTypeAnnotation() => null;
TypeVariable asTypeVariable() => null;
Typedef asTypedef() => null;
VariableDefinitions asVariableDefinitions() => null;
@@ -486,7 +503,7 @@ class ClassNode extends Node {
}
class MixinApplication extends Node {
- final TypeAnnotation superclass;
+ final NominalTypeAnnotation superclass;
final NodeList mixins;
MixinApplication(this.superclass, this.mixins);
@@ -511,8 +528,6 @@ class MixinApplication extends Node {
Token getEndToken() => mixins.getEndToken();
}
-// TODO(kasperl): Let this share some structure with the typedef for function
-// type aliases?
class NamedMixinApplication extends Node implements MixinApplication {
final Identifier name;
final NodeList typeParameters;
@@ -527,7 +542,7 @@ class NamedMixinApplication extends Node implements MixinApplication {
NamedMixinApplication(this.name, this.typeParameters, this.modifiers,
this.mixinApplication, this.interfaces, this.classKeyword, this.endToken);
- TypeAnnotation get superclass => mixinApplication.superclass;
+ NominalTypeAnnotation get superclass => mixinApplication.superclass;
NodeList get mixins => mixinApplication.mixins;
MixinApplication asMixinApplication() => this;
@@ -1412,6 +1427,38 @@ class LiteralSymbol extends Expression {
}
}
+/// A class that represents a non-existing identifier.
+///
+/// The singleton instance of this class should be used in places, where
+/// no identifier was given.
+class NoIdentifier extends Identifier {
+ static NoIdentifier _singleton = new NoIdentifier._();
+
+ factory NoIdentifier() => _singleton;
+ NoIdentifier._() : super(null);
+
+ String get source => throw new UnsupportedError("source");
+
+ bool isThis() => false;
+
+ bool isSuper() => false;
+
+ Identifier asIdentifier() => null;
+
+ accept(Visitor visitor) => throw new UnsupportedError("accept");
+
+ accept1(Visitor1 visitor, arg) => throw new UnsupportedError("accept1");
+
+ visitChildren(Visitor visitor) => throw new UnsupportedError("visitChildren");
+
+ visitChildren1(Visitor1 visitor, arg)
+ => throw new UnsupportedError("visitChildren1");
+
+ Token getBeginToken() => throw new UnsupportedError("getBeginToken");
+
+ Token getEndToken() => throw new UnsupportedError("getEndToken");
+}
+
class Identifier extends Expression with StoredTreeElementMixin {
final Token token;
@@ -1720,17 +1767,22 @@ class Rethrow extends Statement {
Token getEndToken() => endToken;
}
-class TypeAnnotation extends Node {
- final Expression typeName;
+abstract class TypeAnnotation extends Node {
+}
+
+class NominalTypeAnnotation extends TypeAnnotation {
+ final Node typeName;
Siggi Cherem (dart-lang) 2016/12/29 22:46:58 Any reason this changed to Node?
floitsch 2016/12/30 14:55:48 Old change, when I hadn't subclassed `TypeAnnotati
final NodeList typeArguments;
- TypeAnnotation(Expression this.typeName, NodeList this.typeArguments);
+ NominalTypeAnnotation(this.typeName, this.typeArguments);
- TypeAnnotation asTypeAnnotation() => this;
+ NominalTypeAnnotation asNominalTypeAnnotation() => this;
- accept(Visitor visitor) => visitor.visitTypeAnnotation(this);
+ accept(Visitor visitor) => visitor.visitNominalTypeAnnotation(this);
- accept1(Visitor1 visitor, arg) => visitor.visitTypeAnnotation(this, arg);
+ accept1(Visitor1 visitor, arg) {
+ return visitor.visitNominalTypeAnnotation(this, arg);
+ }
visitChildren(Visitor visitor) {
typeName.accept(visitor);
@@ -1826,7 +1878,13 @@ class VariableDefinitions extends Statement {
return token;
}
- Token getEndToken() => definitions.getEndToken();
+ Token getEndToken() {
+ var result = definitions.getEndToken();
+ if (result != null) return result;
+ assert(definitions.nodes.length == 1);
+ assert(definitions.nodes.last == new NoIdentifier());
+ return type.getEndToken();
+ }
}
abstract class Loop extends Statement {
@@ -2854,6 +2912,10 @@ class Combinator extends Node {
}
class Typedef extends Node {
+ final bool isGeneralizedTypeAlias;
+
+ final NodeList templateParameters;
Siggi Cherem (dart-lang) 2016/12/29 22:46:58 nit: +dartdoc, I'm not sure what is the distinctio
floitsch 2016/12/30 14:55:48 Done.
+
final TypeAnnotation returnType;
final Identifier name;
final NodeList typeParameters;
@@ -2862,8 +2924,9 @@ class Typedef extends Node {
final Token typedefKeyword;
final Token endToken;
- Typedef(this.returnType, this.name, this.typeParameters, this.formals,
- this.typedefKeyword, this.endToken);
+ Typedef(this.isGeneralizedTypeAlias, this.templateParameters, this.returnType,
+ this.name, this.typeParameters, this.formals, this.typedefKeyword,
+ this.endToken);
Typedef asTypedef() => this;
@@ -2872,6 +2935,7 @@ class Typedef extends Node {
accept1(Visitor1 visitor, arg) => visitor.visitTypedef(this, arg);
visitChildren(Visitor visitor) {
+ if (templateParameters != null) templateParameters.accept(visitor);
if (returnType != null) returnType.accept(visitor);
name.accept(visitor);
if (typeParameters != null) typeParameters.accept(visitor);
@@ -2879,6 +2943,7 @@ class Typedef extends Node {
}
visitChildren1(Visitor1 visitor, arg) {
+ if (templateParameters != null) templateParameters.accept1(visitor, arg);
if (returnType != null) returnType.accept1(visitor, arg);
name.accept1(visitor, arg);
if (typeParameters != null) typeParameters.accept1(visitor, arg);
@@ -2890,6 +2955,43 @@ class Typedef extends Node {
Token getEndToken() => endToken;
}
+class FunctionTypeAnnotation extends TypeAnnotation {
+ final TypeAnnotation returnType;
+ final Token functionToken;
+ final NodeList typeParameters;
+ final NodeList formals;
+
+ FunctionTypeAnnotation(
+ this.returnType, this.functionToken, this.typeParameters, this.formals);
+
+ FunctionTypeAnnotation asFunctionTypeAnnotation() => this;
+
+ accept(Visitor visitor) => visitor.visitFunctionTypeAnnotation(this);
+
+ accept1(Visitor1 visitor, arg) {
+ return visitor.visitFunctionTypeAnnotation(this, arg);
+ }
+
+ visitChildren(Visitor visitor) {
+ if (returnType != null) returnType.accept(visitor);
+ if (typeParameters != null) typeParameters.accept(visitor);
+ formals.accept(visitor);
+ }
+
+ visitChildren1(Visitor1 visitor, arg) {
+ if (returnType != null) returnType.accept1(visitor, arg);
+ if (typeParameters != null) typeParameters.accept1(visitor, arg);
+ formals.accept1(visitor, arg);
+ }
+
+ Token getBeginToken() {
+ if (returnType != null) return returnType.getBeginToken();
+ return functionToken;
+ }
+
+ Token getEndToken() => formals.getEndToken();
+}
+
class TryStatement extends Statement {
final Block tryBlock;
final NodeList catchBlocks;
@@ -3134,7 +3236,8 @@ class ErrorNode extends Node
get type => null;
// Typedef.
- get typeParameters => null;
+ get isGeneralizedTypeAlias => null;
+ get templateParameters => null;
get formals => null;
get typedefKeyword => null;
}

Powered by Google App Engine
This is Rietveld 408576698