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

Unified Diff: pkg/analyzer/lib/dart/ast/ast.dart

Issue 2622303006: Reapply "Add support for generic function type syntax, part 1" (Closed)
Patch Set: Created 3 years, 11 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/analyzer/lib/dart/ast/ast.dart
diff --git a/pkg/analyzer/lib/dart/ast/ast.dart b/pkg/analyzer/lib/dart/ast/ast.dart
index 4e53fbf4a806259eb906bddbda00a72eafad3567..ba966a3287fa38e2443e4c7a89b671ca68ebed5c 100644
--- a/pkg/analyzer/lib/dart/ast/ast.dart
+++ b/pkg/analyzer/lib/dart/ast/ast.dart
@@ -254,7 +254,7 @@ abstract class ArgumentList extends AstNode {
* An as expression.
*
* asExpression ::=
- * [Expression] 'as' [TypeName]
+ * [Expression] 'as' [TypeAnnotation]
*
* Clients may not extend, implement or mix-in this class.
*/
@@ -281,14 +281,14 @@ abstract class AsExpression extends Expression {
void set expression(Expression expression);
/**
- * Return the name of the type being cast to.
+ * Return the type being cast to.
*/
- TypeName get type;
+ TypeAnnotation get type;
/**
- * Set the name of the type being cast to to the given [name].
+ * Set the type being cast to to the given [type].
*/
- void set type(TypeName name);
+ void set type(TypeAnnotation type);
}
/**
@@ -666,6 +666,10 @@ abstract class AstVisitor<R> {
R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node);
+ R visitGenericFunctionType(GenericFunctionType node);
+
+ R visitGenericTypeAlias(GenericTypeAlias node);
+
R visitHideCombinator(HideCombinator node);
R visitIfStatement(IfStatement node);
@@ -1104,13 +1108,13 @@ abstract class CatchClause extends AstNode {
* Return the type of exceptions caught by this catch clause, or `null` if
* this catch clause catches every type of exception.
*/
- TypeName get exceptionType;
+ TypeAnnotation get exceptionType;
/**
* Set the type of exceptions caught by this catch clause to the given
* [exceptionType].
*/
- void set exceptionType(TypeName exceptionType);
+ void set exceptionType(TypeAnnotation exceptionType);
/**
* Return the left parenthesis, or `null` if there is no 'catch' keyword.
@@ -2194,12 +2198,12 @@ abstract class DeclaredIdentifier extends Declaration {
* Return the name of the declared type of the parameter, or `null` if the
* parameter does not have a declared type.
*/
- TypeName get type;
+ TypeAnnotation get type;
/**
- * Set the name of the declared type of the parameter to the given [typeName].
+ * Set the declared type of the parameter to the given [type].
*/
- void set type(TypeName typeName);
+ void set type(TypeAnnotation type);
}
/**
@@ -2796,7 +2800,7 @@ abstract class FieldDeclaration extends ClassMember {
* A field formal parameter.
*
* fieldFormalParameter ::=
- * ('final' [TypeName] | 'const' [TypeName] | 'var' | [TypeName])?
+ * ('final' [TypeAnnotation] | 'const' [TypeAnnotation] | 'var' | [TypeAnnotation])?
* 'this' '.' [SimpleIdentifier] ([TypeParameterList]? [FormalParameterList])?
*
* Clients may not extend, implement or mix-in this class.
@@ -2847,17 +2851,16 @@ abstract class FieldFormalParameter extends NormalFormalParameter {
void set thisKeyword(Token token);
/**
- * Return the name of the declared type of the parameter, or `null` if the
- * parameter does not have a declared type. Note that if this is a
- * function-typed field formal parameter this is the return type of the
- * function.
+ * Return the declared type of the parameter, or `null` if the parameter does
+ * not have a declared type. Note that if this is a function-typed field
+ * formal parameter this is the return type of the function.
*/
- TypeName get type;
+ TypeAnnotation get type;
/**
- * Set the name of the declared type of the parameter to the given [typeName].
+ * Set the declared type of the parameter to the given [type].
*/
- void set type(TypeName typeName);
+ void set type(TypeAnnotation type);
/**
* Return the type parameters associated with this method, or `null` if this
@@ -3355,12 +3358,12 @@ abstract class FunctionDeclaration extends NamedCompilationUnitMember {
* Return the return type of the function, or `null` if no return type was
* declared.
*/
- TypeName get returnType;
+ TypeAnnotation get returnType;
/**
- * Set the return type of the function to the given [returnType].
+ * Set the return type of the function to the given [type].
*/
- void set returnType(TypeName returnType);
+ void set returnType(TypeAnnotation type);
}
/**
@@ -3513,7 +3516,7 @@ abstract class FunctionExpressionInvocation extends InvocationExpression {
* functionPrefix [TypeParameterList]? [FormalParameterList] ';'
*
* functionPrefix ::=
- * [TypeName]? [SimpleIdentifier]
+ * [TypeAnnotation]? [SimpleIdentifier]
*
* Clients may not extend, implement or mix-in this class.
*/
@@ -3530,16 +3533,15 @@ abstract class FunctionTypeAlias extends TypeAlias {
void set parameters(FormalParameterList parameters);
/**
- * Return the name of the return type of the function type being defined, or
- * `null` if no return type was given.
+ * Return the return type of the function type being defined, or `null` if no
+ * return type was given.
*/
- TypeName get returnType;
+ TypeAnnotation get returnType;
/**
- * Set the name of the return type of the function type being defined to the
- * given [typeName].
+ * Set the return type of the function type being defined to the given [type].
*/
- void set returnType(TypeName typeName);
+ void set returnType(TypeAnnotation type);
/**
* Return the type parameters for the function type, or `null` if the function
@@ -3558,7 +3560,7 @@ abstract class FunctionTypeAlias extends TypeAlias {
* A function-typed formal parameter.
*
* functionSignature ::=
- * [TypeName]? [SimpleIdentifier] [TypeParameterList]? [FormalParameterList]
+ * [TypeAnnotation]? [SimpleIdentifier] [TypeParameterList]? [FormalParameterList]
*
* Clients may not extend, implement or mix-in this class.
*/
@@ -3590,12 +3592,12 @@ abstract class FunctionTypedFormalParameter extends NormalFormalParameter {
* Return the return type of the function, or `null` if the function does not
* have a return type.
*/
- TypeName get returnType;
+ TypeAnnotation get returnType;
/**
* Set the return type of the function to the given [type].
*/
- void set returnType(TypeName type);
+ void set returnType(TypeAnnotation type);
/**
* Return the type parameters associated with this function, or `null` if
@@ -3611,6 +3613,128 @@ abstract class FunctionTypedFormalParameter extends NormalFormalParameter {
}
/**
+ * An anonymous function type.
+ *
+ * functionType ::=
+ * [TypeAnnotation]? 'Function' [TypeParameterList]? [FormalParameterList]
+ *
+ * where the FormalParameterList is being used to represent the following
+ * grammar, despite the fact that FormalParameterList can represent a much
+ * larger grammar than the one below. This is done in order to simplify the
+ * implementation.
+ *
+ * parameterTypeList ::=
+ * () |
+ * ( normalParameterTypes ,? ) |
+ * ( normalParameterTypes , optionalParameterTypes ) |
+ * ( optionalParameterTypes )
+ * namedParameterTypes ::=
+ * { namedParameterType (, namedParameterType)* ,? }
+ * namedParameterType ::=
+ * [TypeAnnotation]? [SimpleIdentifier]
+ * normalParameterTypes ::=
+ * normalParameterType (, normalParameterType)*
+ * normalParameterType ::=
+ * [TypeAnnotation] [SimpleIdentifier]?
+ * optionalParameterTypes ::=
+ * optionalPositionalParameterTypes | namedParameterTypes
+ * optionalPositionalParameterTypes ::=
+ * [ normalParameterTypes ,? ]
+ *
+ * Clients may not extend, implement or mix-in this class.
+ */
+abstract class GenericFunctionType extends TypeAnnotation {
+ /**
+ * Return the keyword 'Function'.
+ */
+ Token get functionKeyword;
+
+ /**
+ * Set the keyword 'Function' to the given [token].
+ */
+ void set functionKeyword(Token token);
+
+ /**
+ * Return the parameters associated with the function type.
+ */
+ FormalParameterList get parameters;
+
+ /**
+ * Set the parameters associated with the function type to the given list of
+ * [parameters].
+ */
+ void set parameters(FormalParameterList parameters);
+
+ /**
+ * Return the return type of the function type being defined, or `null` if
+ * no return type was given.
+ */
+ TypeAnnotation get returnType;
+
+ /**
+ * Set the return type of the function type being defined to the given[type].
+ */
+ void set returnType(TypeAnnotation type);
+
+ /**
+ * Return the type parameters for the function type, or `null` if the function
+ * type does not have any type parameters.
+ */
+ TypeParameterList get typeParameters;
+
+ /**
+ * Set the type parameters for the function type to the given list of
+ * [typeParameters].
+ */
+ void set typeParameters(TypeParameterList typeParameters);
+}
+
+/**
+ * A generic type alias.
+ *
+ * functionTypeAlias ::=
+ * metadata 'typedef' [SimpleIdentifier] [TypeParameterList]? = [FunctionType] ';'
+ *
+ * Clients may not extend, implement or mix-in this class.
+ */
+abstract class GenericTypeAlias extends TypeAlias {
+ /**
+ * Return the equal sign separating the name being defined from the function
+ * type.
+ */
+ Token get equals;
+
+ /**
+ * Set the equal sign separating the name being defined from the function type
+ * to the given [token].
+ */
+ void set equals(Token token);
+
+ /**
+ * Return the type of function being defined by the alias.
+ */
+ GenericFunctionType get functionType;
+
+ /**
+ * Set the type of function being defined by the alias to the given
+ * [functionType].
+ */
+ void set functionType(GenericFunctionType functionType);
+
+ /**
+ * Return the type parameters for the function type, or `null` if the function
+ * type does not have any type parameters.
+ */
+ TypeParameterList get typeParameters;
+
+ /**
+ * Set the type parameters for the function type to the given list of
+ * [typeParameters].
+ */
+ void set typeParameters(TypeParameterList typeParameters);
+}
+
+/**
* A combinator that restricts the names being imported to those that are not in
* a given list.
*
@@ -4310,7 +4434,7 @@ abstract class InvocationExpression extends Expression {
* An is expression.
*
* isExpression ::=
- * [Expression] 'is' '!'? [TypeName]
+ * [Expression] 'is' '!'? [TypeAnnotation]
*
* Clients may not extend, implement or mix-in this class.
*/
@@ -4347,14 +4471,14 @@ abstract class IsExpression extends Expression {
void set notOperator(Token token);
/**
- * Return the name of the type being tested for.
+ * Return the type being tested for.
*/
- TypeName get type;
+ TypeAnnotation get type;
/**
- * Set the name of the type being tested for to the given [name].
+ * Set the type being tested for to the given [type].
*/
- void set type(TypeName name);
+ void set type(TypeAnnotation type);
}
/**
@@ -4473,7 +4597,7 @@ abstract class LibraryIdentifier extends Identifier {
* A list literal.
*
* listLiteral ::=
- * 'const'? ('<' [TypeName] '>')? '[' ([Expression] ','?)? ']'
+ * 'const'? ('<' [TypeAnnotation] '>')? '[' ([Expression] ','?)? ']'
*
* Clients may not extend, implement or mix-in this class.
*/
@@ -4524,7 +4648,7 @@ abstract class Literal extends Expression {}
* A literal map.
*
* mapLiteral ::=
- * 'const'? ('<' [TypeName] (',' [TypeName])* '>')?
+ * 'const'? ('<' [TypeAnnotation] (',' [TypeAnnotation])* '>')?
* '{' ([MapLiteralEntry] (',' [MapLiteralEntry])* ','?)? '}'
*
* Clients may not extend, implement or mix-in this class.
@@ -4726,12 +4850,12 @@ abstract class MethodDeclaration extends ClassMember {
* Return the return type of the method, or `null` if no return type was
* declared.
*/
- TypeName get returnType;
+ TypeAnnotation get returnType;
/**
- * Set the return type of the method to the given [typeName].
+ * Set the return type of the method to the given [type].
*/
- void set returnType(TypeName typeName);
+ void set returnType(TypeAnnotation type);
/**
* Return the type parameters associated with this method, or `null` if this
@@ -5643,7 +5767,7 @@ abstract class ShowCombinator extends Combinator {
* A simple formal parameter.
*
* simpleFormalParameter ::=
- * ('final' [TypeName] | 'var' | [TypeName])? [SimpleIdentifier]
+ * ('final' [TypeAnnotation] | 'var' | [TypeAnnotation])? [SimpleIdentifier]
*
* Clients may not extend, implement or mix-in this class.
*/
@@ -5661,15 +5785,15 @@ abstract class SimpleFormalParameter extends NormalFormalParameter {
void set keyword(Token token);
/**
- * Return the name of the declared type of the parameter, or `null` if the
- * parameter does not have a declared type.
+ * Return the declared type of the parameter, or `null` if the parameter does
+ * not have a declared type.
*/
- TypeName get type;
+ TypeAnnotation get type;
/**
- * Set the name of the declared type of the parameter to the given [typeName].
+ * Set the declared type of the parameter to the given [type].
*/
- void set type(TypeName typeName);
+ void set type(TypeAnnotation type);
}
/**
@@ -6336,6 +6460,23 @@ abstract class TypeAlias extends NamedCompilationUnitMember {
}
/**
+ * A type annotation.
+ *
+ * type ::=
+ * [NamedType]
+ * | [GenericFunctionType]
+ *
+ * Clients may not extend, implement or mix-in this class.
+ */
+abstract class TypeAnnotation extends AstNode {
+ /**
+ * Return the type being named, or `null` if the AST structure has not been
+ * resolved.
+ */
+ DartType get type;
+}
+
+/**
* A list of type arguments.
*
* typeArguments ::=
@@ -6347,7 +6488,7 @@ abstract class TypeArgumentList extends AstNode {
/**
* Return the type arguments associated with the type.
*/
- NodeList<TypeName> get arguments;
+ NodeList<TypeAnnotation> get arguments;
/**
* Return the left bracket.
@@ -6412,7 +6553,7 @@ abstract class TypedLiteral extends Literal {
*
* Clients may not extend, implement or mix-in this class.
*/
-abstract class TypeName extends AstNode {
+abstract class TypeName extends TypeAnnotation {
/**
* Return `true` if this type is a deferred type.
*
@@ -6444,12 +6585,6 @@ abstract class TypeName extends AstNode {
void set question(Token question);
/**
- * Return the type being named, or `null` if the AST structure has not been
- * resolved.
- */
- DartType get type;
-
- /**
* Set the type being named to the given [type].
*/
void set type(DartType type);
@@ -6471,22 +6606,21 @@ abstract class TypeName extends AstNode {
* A type parameter.
*
* typeParameter ::=
- * [SimpleIdentifier] ('extends' [TypeName])?
+ * [SimpleIdentifier] ('extends' [TypeAnnotation])?
*
* Clients may not extend, implement or mix-in this class.
*/
abstract class TypeParameter extends Declaration {
/**
- * Return the name of the upper bound for legal arguments, or `null` if there
- * is no explicit upper bound.
+ * Return the upper bound for legal arguments, or `null` if there is no
+ * explicit upper bound.
*/
- TypeName get bound;
+ TypeAnnotation get bound;
/**
- * Set the name of the upper bound for legal arguments to the given
- * [typeName].
+ * Set the upper bound for legal arguments to the given [type].
*/
- void set bound(TypeName typeName);
+ void set bound(TypeAnnotation type);
/**
* Return the token representing the 'extends' keyword, or `null` if there is
@@ -6669,10 +6803,10 @@ abstract class VariableDeclaration extends Declaration {
* finalConstVarOrType [VariableDeclaration] (',' [VariableDeclaration])*
*
* finalConstVarOrType ::=
- * | 'final' [TypeName]?
- * | 'const' [TypeName]?
+ * | 'final' [TypeAnnotation]?
+ * | 'const' [TypeAnnotation]?
* | 'var'
- * | [TypeName]
+ * | [TypeAnnotation]
*
* Clients may not extend, implement or mix-in this class.
*/
@@ -6707,12 +6841,12 @@ abstract class VariableDeclarationList extends AnnotatedNode {
* Return the type of the variables being declared, or `null` if no type was
* provided.
*/
- TypeName get type;
+ TypeAnnotation get type;
/**
- * Set the type of the variables being declared to the given [typeName].
+ * Set the type of the variables being declared to the given [type].
*/
- void set type(TypeName typeName);
+ void set type(TypeAnnotation type);
/**
* Return a list containing the individual variables being declared.

Powered by Google App Engine
This is Rietveld 408576698