Skip to content

Commit

Permalink
Version 3.5.0-27.0.dev
Browse files Browse the repository at this point in the history
Merge 240d60c into dev
  • Loading branch information
Dart CI committed Apr 5, 2024
2 parents 67ad2d6 + 240d60c commit c259016
Show file tree
Hide file tree
Showing 12 changed files with 1,152 additions and 15 deletions.
2 changes: 2 additions & 0 deletions pkg/analyzer/lib/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export 'package:analyzer/src/dart/ast/ast.dart'
AstNode,
AstVisitor,
AugmentationImportDirective,
AugmentedExpression,
AugmentedInvocation,
AwaitExpression,
BinaryExpression,
Block,
Expand Down
54 changes: 54 additions & 0 deletions pkg/analyzer/lib/dart/ast/visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ class GeneralizingAstVisitor<R> implements AstVisitor<R> {
R? visitAugmentationImportDirective(AugmentationImportDirective node) =>
visitUriBasedDirective(node);

@override
R? visitAugmentedExpression(AugmentedExpression node) =>
visitExpression(node);

@override
R? visitAugmentedInvocation(AugmentedInvocation node) =>
visitExpression(node);

@override
R? visitAwaitExpression(AwaitExpression node) => visitExpression(node);

Expand Down Expand Up @@ -857,6 +865,18 @@ class RecursiveAstVisitor<R> implements AstVisitor<R> {
return null;
}

@override
R? visitAugmentedExpression(AugmentedExpression node) {
node.visitChildren(this);
return null;
}

@override
R? visitAugmentedInvocation(AugmentedInvocation node) {
node.visitChildren(this);
return null;
}

@override
R? visitAwaitExpression(AwaitExpression node) {
node.visitChildren(this);
Expand Down Expand Up @@ -1878,6 +1898,12 @@ class SimpleAstVisitor<R> implements AstVisitor<R> {
@override
R? visitAugmentationImportDirective(AugmentationImportDirective node) => null;

@override
R? visitAugmentedExpression(AugmentedExpression node) => null;

@override
R? visitAugmentedInvocation(AugmentedInvocation node) => null;

@override
R? visitAwaitExpression(AwaitExpression node) => null;

Expand Down Expand Up @@ -2427,6 +2453,12 @@ class ThrowingAstVisitor<R> implements AstVisitor<R> {
R? visitAugmentationImportDirective(AugmentationImportDirective node) =>
_throw(node);

@override
R? visitAugmentedExpression(AugmentedExpression node) => _throw(node);

@override
R? visitAugmentedInvocation(AugmentedInvocation node) => _throw(node);

@override
R? visitAwaitExpression(AwaitExpression node) => _throw(node);

Expand Down Expand Up @@ -3042,6 +3074,22 @@ class TimedAstVisitor<T> implements AstVisitor<T> {
return result;
}

@override
T? visitAugmentedExpression(AugmentedExpression node) {
stopwatch.start();
T? result = _baseVisitor.visitAugmentedExpression(node);
stopwatch.stop();
return result;
}

@override
T? visitAugmentedInvocation(AugmentedInvocation node) {
stopwatch.start();
T? result = _baseVisitor.visitAugmentedInvocation(node);
stopwatch.stop();
return result;
}

@override
T? visitAwaitExpression(AwaitExpression node) {
stopwatch.start();
Expand Down Expand Up @@ -4394,6 +4442,12 @@ class UnifyingAstVisitor<R> implements AstVisitor<R> {
R? visitAugmentationImportDirective(AugmentationImportDirective node) =>
visitNode(node);

@override
R? visitAugmentedExpression(AugmentedExpression node) => visitNode(node);

@override
R? visitAugmentedInvocation(AugmentedInvocation node) => visitNode(node);

@override
R? visitAwaitExpression(AwaitExpression node) => visitNode(node);

Expand Down
164 changes: 164 additions & 0 deletions pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,10 @@ abstract class AstVisitor<R> {

R? visitAugmentationImportDirective(AugmentationImportDirective node);

R? visitAugmentedExpression(AugmentedExpression node);

R? visitAugmentedInvocation(AugmentedInvocation node);

R? visitAwaitExpression(AwaitExpression node);

R? visitBinaryExpression(BinaryExpression node);
Expand Down Expand Up @@ -1623,6 +1627,166 @@ final class AugmentationImportDirectiveImpl extends UriBasedDirectiveImpl
}
}

/// The augmented expression.
///
/// It is created only inside an augmentation.
/// The exact meaning depends on what is augmented, and where it is used.
///
/// Augmenting getters: `augmented` invokes the getter and evaluates to the
/// return value.
/// The [element] is the augmented getter.
/// The [staticType] is the return type of the getter.
///
/// Augmenting setters: `augmented` must be followed by an `=`, and will
/// directly invoke the augmented setter.
/// The [element] is the augmented setter.
/// The [staticType] is meaningless, and set to `null`.
///
/// Augmenting fields: `augmented` can only be used in an initializer
/// expression, and refers to the original field's initializer expression.
/// The [element] is the augmented field.
/// The [staticType] is the type of the field.
///
/// Augmenting binary operators: `augmented` must be the LHS, and followed by
/// the argument, e.g. `augmented + 1`.
/// The [element] is the augmented [MethodElement].
/// The [staticType] is the type of `this`.
///
/// Augmenting index operators: `augmented` must be the index target,
/// e.g. `augmented[0]`.
/// The [element] is the augmented [MethodElement].
/// The [staticType] is the type of `this`.
///
/// Augmenting prefix operators: `augmented` must be the target, e.g.
/// `~augmented`.
/// The [element] is the augmented [MethodElement].
/// The [staticType] is the type of `this`.
abstract final class AugmentedExpression implements Expression {
/// The 'augmented' keyword.
Token get augmentedKeyword;

/// The referenced augmented element: getter, setter, variable.
Element? get element;
}

final class AugmentedExpressionImpl extends ExpressionImpl
implements AugmentedExpression {
@override
final Token augmentedKeyword;

@override
Element? element;

AugmentedExpressionImpl({
required this.augmentedKeyword,
});

@override
Token get beginToken => augmentedKeyword;

@override
Token get endToken => augmentedKeyword;

@override
bool get isAssignable => true;

@override
Precedence get precedence => Precedence.primary;

@override
ChildEntities get _childEntities =>
ChildEntities()..addToken('augmentedKeyword', augmentedKeyword);

@override
E? accept<E>(AstVisitor<E> visitor) => visitor.visitAugmentedExpression(this);

@override
void resolveExpression(ResolverVisitor resolver, DartType contextType) {
resolver.visitAugmentedExpression(this);
}

@override
void visitChildren(AstVisitor visitor) {
// There are no children to visit.
}
}

/// Invocation of the augmented function, constructor, or method.
///
/// augmentedInvocation ::=
/// 'augmented' [TypeArgumentList]? [ArgumentList]
abstract final class AugmentedInvocation implements Expression {
/// The list of value arguments.
ArgumentList get arguments;

/// The 'augmented' keyword.
Token get augmentedKeyword;

/// The referenced augmented element: function, constructor, or method.
ExecutableElement? get element;

/// The list of type arguments.
///
/// In valid code cannot be provided for augmented constructor invocation.
TypeArgumentList? get typeArguments;
}

final class AugmentedInvocationImpl extends ExpressionImpl
implements AugmentedInvocation {
@override
final Token augmentedKeyword;

@override
ExecutableElement? element;

@override
final TypeArgumentListImpl? typeArguments;

@override
final ArgumentListImpl arguments;

AugmentedInvocationImpl({
required this.augmentedKeyword,
required this.typeArguments,
required this.arguments,
}) {
_becomeParentOf(typeArguments);
_becomeParentOf(arguments);
}

@override
Token get beginToken => augmentedKeyword;

@override
Token get endToken => arguments.endToken;

@override
Precedence get precedence => Precedence.postfix;

@override
ChildEntities get _childEntities => ChildEntities()
..addToken('augmentedKeyword', augmentedKeyword)
..addNode('typeArguments', typeArguments)
..addNode('arguments', arguments);

@override
E? accept<E>(AstVisitor<E> visitor) {
return visitor.visitAugmentedInvocation(this);
}

@override
void resolveExpression(ResolverVisitor resolver, DartType contextType) {
// TODO(scheglov): implement
throw UnimplementedError();
}

@override
void visitChildren(AstVisitor visitor) {
typeArguments?.accept(visitor);
arguments.accept(visitor);
}
}

/// An await expression.
///
/// awaitExpression ::=
Expand Down
12 changes: 12 additions & 0 deletions pkg/analyzer/lib/src/dart/ast/to_source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ class ToSourceVisitor implements AstVisitor<void> {
sink.write(';');
}

@override
void visitAugmentedExpression(AugmentedExpression node) {
sink.write('augmented');
}

@override
void visitAugmentedInvocation(AugmentedInvocation node) {
_visitToken(node.augmentedKeyword);
_visitNode(node.typeArguments);
_visitNode(node.arguments);
}

@override
void visitAwaitExpression(AwaitExpression node) {
sink.write('await ');
Expand Down
14 changes: 14 additions & 0 deletions pkg/analyzer/lib/src/dart/ast/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ class AstComparator implements AstVisitor<bool> {
isEqualTokens(node.semicolon, other.semicolon);
}

@override
bool visitAugmentedExpression(AugmentedExpression node) {
final other = _other as AugmentedExpression;
return isEqualTokens(node.augmentedKeyword, other.augmentedKeyword);
}

@override
bool visitAugmentedInvocation(AugmentedInvocation node) {
final other = _other as AugmentedInvocation;
return isEqualTokens(node.augmentedKeyword, other.augmentedKeyword) &&
isEqualNodes(node.typeArguments, other.typeArguments) &&
isEqualNodes(node.arguments, other.arguments);
}

@override
bool visitAwaitExpression(AwaitExpression node) {
AwaitExpression other = _other as AwaitExpression;
Expand Down
Loading

0 comments on commit c259016

Please sign in to comment.