Skip to content

Commit d353323

Browse files
bwilkersonCommit Bot
authored andcommitted
Initial AST structure for record literals
Change-Id: I225365b90d2e006116b3a91307479839df07ec10 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255140 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 05eb57b commit d353323

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

pkg/analyzer/lib/dart/ast/ast.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4063,6 +4063,25 @@ abstract class PropertyAccess
40634063
Expression? get target;
40644064
}
40654065

4066+
/// A record literal.
4067+
///
4068+
/// recordLiteral ::= '(' recordField (',' recordField)* ','? ')'
4069+
///
4070+
/// recordField ::= (identifier ':')? [Expression]
4071+
///
4072+
/// Clients may not extend, implement or mix-in this class.
4073+
@experimental
4074+
abstract class RecordLiteral implements Literal {
4075+
/// Return the syntactic elements used to compute the fields of the record.
4076+
NodeList<Expression> get fields;
4077+
4078+
/// Return the left parenthesis.
4079+
Token get leftParenthesis;
4080+
4081+
/// Return the right parenthesis.
4082+
Token get rightParenthesis;
4083+
}
4084+
40664085
/// A record type.
40674086
///
40684087
/// recordType ::=

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9644,6 +9644,60 @@ class PropertyAccessImpl extends CommentReferableExpressionImpl
96449644
identical(descendant, _target);
96459645
}
96469646

9647+
class RecordLiteralImpl extends LiteralImpl implements RecordLiteral {
9648+
@override
9649+
Token leftParenthesis;
9650+
9651+
/// The syntactic elements used to compute the fields of the record.
9652+
final NodeListImpl<Expression> _fields = NodeListImpl._();
9653+
9654+
@override
9655+
Token rightParenthesis;
9656+
9657+
/// Initialize a newly created record literal.
9658+
RecordLiteralImpl(
9659+
{required this.leftParenthesis,
9660+
required List<Expression> fields,
9661+
required this.rightParenthesis}) {
9662+
_fields._initialize(this, fields);
9663+
}
9664+
9665+
@override
9666+
Token get beginToken => leftParenthesis;
9667+
9668+
@override
9669+
Token get endToken => rightParenthesis;
9670+
9671+
@override
9672+
NodeList<Expression> get fields => _fields;
9673+
9674+
@override
9675+
// TODO(paulberry): add commas.
9676+
ChildEntities get _childEntities => super._childEntities
9677+
..addToken('leftParenthesis', leftParenthesis)
9678+
..addNodeList('fields', fields)
9679+
..addToken('rightParenthesis', rightParenthesis);
9680+
9681+
@override
9682+
E? accept<E>(AstVisitor<E> visitor) {
9683+
// TODO: implement accept
9684+
throw UnimplementedError();
9685+
// visitor.visitRecordLiteral(this);
9686+
}
9687+
9688+
@override
9689+
void resolveExpression(ResolverVisitor resolver, DartType? contextType) {
9690+
// TODO: implement resolveExpression
9691+
throw UnimplementedError();
9692+
// resolver.visitRecordLiteral(this, contextType: contextType);
9693+
}
9694+
9695+
@override
9696+
void visitChildren(AstVisitor visitor) {
9697+
_fields.accept(visitor);
9698+
}
9699+
}
9700+
96479701
/// The invocation of a constructor in the same class from within a
96489702
/// constructor's initialization list.
96499703
///

0 commit comments

Comments
 (0)