Skip to content

Commit f479da9

Browse files
kallentuCommit Queue
authored andcommitted
[analyzer] Dot shorthands: Add the isDotShorthand flag to ResolvedAstPrinter.
Follow up to https://dart-review.googlesource.com/c/sdk/+/437881/comment/4d727a25_2a310893/ Print the flag value for dot shorthand invocations and property accesses. Updated relevant tests. Bug: #59835 Change-Id: Ibf25b39474373895b99e2f0833da5dae2b873c2b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438485 Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 67bda7c commit f479da9

File tree

9 files changed

+100
-10
lines changed

9 files changed

+100
-10
lines changed

pkg/analyzer/lib/src/summary2/ast_binary_flags.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ class AstBinaryFlags {
106106

107107
static final _isDeclaration = _checkBit(0, SimpleIdentifier);
108108

109+
static final _isDotShorthand = _checkBit(
110+
0,
111+
DotShorthandConstructorInvocation,
112+
DotShorthandInvocation,
113+
DotShorthandPropertyAccess,
114+
);
115+
109116
static final _isDeferred = _checkBit(0, ImportDirective);
110117

111118
static final _isDelimiterCurly = _checkBit(0, FormalParameterList);
@@ -202,6 +209,7 @@ class AstBinaryFlags {
202209
bool isDeferred = false,
203210
bool isDelimiterCurly = false,
204211
bool isDelimiterSquare = false,
212+
bool isDotShorthand = false,
205213
bool isExternal = false,
206214
bool isFactory = false,
207215
bool isFinal = false,
@@ -283,6 +291,9 @@ class AstBinaryFlags {
283291
if (isDelimiterSquare) {
284292
result |= _isDelimiterSquare;
285293
}
294+
if (isDotShorthand) {
295+
result |= _isDotShorthand;
296+
}
286297
if (isConst) {
287298
result |= _isConst;
288299
}
@@ -425,6 +436,10 @@ class AstBinaryFlags {
425436
return (flags & _isDelimiterSquare) != 0;
426437
}
427438

439+
static bool isDotShorthand(int flags) {
440+
return (flags & _isDotShorthand) != 0;
441+
}
442+
428443
static bool isExternal(int flags) {
429444
return (flags & _isExternal) != 0;
430445
}

pkg/analyzer/lib/src/summary2/ast_binary_reader.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,14 @@ class AstBinaryReader {
478478
constructorName: constructorName,
479479
typeArguments: null,
480480
argumentList: argumentList,
481-
);
481+
)..isDotShorthand = AstBinaryFlags.isDotShorthand(flags);
482482
_readExpressionResolution(node);
483483
_resolveNamedExpressions(node.constructorName.element, node.argumentList);
484484
return node;
485485
}
486486

487487
DotShorthandInvocation _readDotShorthandInvocation() {
488+
var flags = _readByte();
488489
var memberName = readNode() as SimpleIdentifierImpl;
489490
var typeArguments = _readOptionalNode() as TypeArgumentListImpl?;
490491
var arguments = readNode() as ArgumentListImpl;
@@ -493,17 +494,18 @@ class AstBinaryReader {
493494
memberName: memberName,
494495
typeArguments: typeArguments,
495496
argumentList: arguments,
496-
);
497+
)..isDotShorthand = AstBinaryFlags.isDotShorthand(flags);
497498
_readInvocationExpression(node);
498499
return node;
499500
}
500501

501502
DotShorthandPropertyAccess _readDotShorthandPropertyAccess() {
503+
var flags = _readByte();
502504
var propertyName = readNode() as SimpleIdentifierImpl;
503505
var node = DotShorthandPropertyAccessImpl(
504506
period: Tokens.period(),
505507
propertyName: propertyName,
506-
);
508+
)..isDotShorthand = AstBinaryFlags.isDotShorthand(flags);
507509
_readExpressionResolution(node);
508510
return node;
509511
}

pkg/analyzer/lib/src/summary2/ast_binary_writer.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,27 +228,34 @@ class AstBinaryWriter extends ThrowingAstVisitor<void> {
228228

229229
@override
230230
void visitDotShorthandConstructorInvocation(
231-
DotShorthandConstructorInvocation node,
231+
covariant DotShorthandConstructorInvocationImpl node,
232232
) {
233233
_writeByte(Tag.DotShorthandConstructorInvocation);
234234
_writeByte(
235-
AstBinaryFlags.encode(isConst: node.constKeyword?.type == Keyword.CONST),
235+
AstBinaryFlags.encode(
236+
isConst: node.constKeyword?.type == Keyword.CONST,
237+
isDotShorthand: node.isDotShorthand,
238+
),
236239
);
237240
_writeNode(node.constructorName);
238241
_writeNode(node.argumentList);
239242
_storeExpression(node);
240243
}
241244

242245
@override
243-
void visitDotShorthandInvocation(DotShorthandInvocation node) {
246+
void visitDotShorthandInvocation(covariant DotShorthandInvocationImpl node) {
244247
_writeByte(Tag.DotShorthandInvocation);
248+
_writeByte(AstBinaryFlags.encode(isDotShorthand: node.isDotShorthand));
245249
_writeNode(node.memberName);
246250
_storeInvocationExpression(node);
247251
}
248252

249253
@override
250-
void visitDotShorthandPropertyAccess(DotShorthandPropertyAccess node) {
254+
void visitDotShorthandPropertyAccess(
255+
covariant DotShorthandPropertyAccessImpl node,
256+
) {
251257
_writeByte(Tag.DotShorthandPropertyAccess);
258+
_writeByte(AstBinaryFlags.encode(isDotShorthand: node.isDotShorthand));
252259
_writeNode(node.propertyName);
253260
_storeExpression(node);
254261
}

pkg/analyzer/test/src/dart/resolution/dot_shorthand_constructor_invocation_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ DotShorthandConstructorInvocation
6161
element: iter@26
6262
staticType: List<int>
6363
rightParenthesis: )
64+
isDotShorthand: true
6465
staticType: Stream<int>
6566
''');
6667
}
@@ -95,6 +96,7 @@ DotShorthandConstructorInvocation
9596
correspondingParameter: <testLibrary>::@class::C::@constructor::new::@formalParameter::x
9697
staticType: int
9798
rightParenthesis: )
99+
isDotShorthand: false
98100
staticType: C
99101
''');
100102
}
@@ -129,6 +131,7 @@ DotShorthandConstructorInvocation
129131
correspondingParameter: <testLibrary>::@class::C::@constructor::new::@formalParameter::x
130132
staticType: int
131133
rightParenthesis: )
134+
isDotShorthand: false
132135
staticType: C
133136
''');
134137
}
@@ -163,6 +166,7 @@ DotShorthandConstructorInvocation
163166
correspondingParameter: <testLibrary>::@class::C::@constructor::named::@formalParameter::x
164167
staticType: int
165168
rightParenthesis: )
169+
isDotShorthand: true
166170
correspondingParameter: dart:core::@class::Object::@method::==::@formalParameter::other
167171
staticType: C
168172
''');
@@ -197,6 +201,7 @@ DotShorthandConstructorInvocation
197201
correspondingParameter: <testLibrary>::@class::C::@constructor::named::@formalParameter::x
198202
staticType: int
199203
rightParenthesis: )
204+
isDotShorthand: true
200205
staticType: C
201206
''');
202207
}
@@ -231,6 +236,7 @@ DotShorthandConstructorInvocation
231236
correspondingParameter: <testLibrary>::@class::C::@constructor::named::@formalParameter::x
232237
staticType: int
233238
rightParenthesis: )
239+
isDotShorthand: true
234240
staticType: C
235241
''');
236242
}
@@ -299,6 +305,7 @@ DotShorthandConstructorInvocation
299305
correspondingParameter: <testLibrary>::@class::C::@constructor::named::@formalParameter::x
300306
staticType: int
301307
rightParenthesis: )
308+
isDotShorthand: true
302309
staticType: C
303310
''');
304311
}
@@ -338,6 +345,7 @@ DotShorthandConstructorInvocation
338345
substitution: {T: dynamic}
339346
staticType: int
340347
rightParenthesis: )
348+
isDotShorthand: true
341349
staticType: C<dynamic>
342350
''');
343351
}
@@ -396,6 +404,7 @@ DotShorthandConstructorInvocation
396404
correspondingParameter: <testLibrary>::@class::C::@constructor::named::@formalParameter::x
397405
staticType: int
398406
rightParenthesis: )
407+
isDotShorthand: true
399408
correspondingParameter: dart:core::@class::Object::@method::==::@formalParameter::other
400409
staticType: C
401410
''');
@@ -431,6 +440,7 @@ DotShorthandConstructorInvocation
431440
SimpleStringLiteral
432441
literal: '2'
433442
rightParenthesis: )
443+
isDotShorthand: true
434444
correspondingParameter: dart:core::@class::Object::@method::==::@formalParameter::other
435445
staticType: List<String>
436446
''');
@@ -466,6 +476,7 @@ DotShorthandConstructorInvocation
466476
correspondingParameter: <testLibrary>::@class::C::@constructor::named::@formalParameter::x
467477
staticType: int
468478
rightParenthesis: )
479+
isDotShorthand: true
469480
staticType: C
470481
''');
471482
}
@@ -506,12 +517,14 @@ DotShorthandConstructorInvocation
506517
argumentList: ArgumentList
507518
leftParenthesis: (
508519
rightParenthesis: )
520+
isDotShorthand: true
509521
correspondingParameter: FieldFormalParameterMember
510522
baseElement: <testLibrary>::@class::C::@constructor::new::@formalParameter::x
511523
substitution: {T: C<dynamic>}
512524
staticInvokeType: C<dynamic> Function()
513525
staticType: C<dynamic>
514526
rightParenthesis: )
527+
isDotShorthand: true
515528
staticType: C<C<dynamic>>
516529
''');
517530
}
@@ -549,11 +562,13 @@ DotShorthandConstructorInvocation
549562
token: member
550563
element: <testLibrary>::@class::C::@getter::member
551564
staticType: C<dynamic>
565+
isDotShorthand: true
552566
correspondingParameter: FieldFormalParameterMember
553567
baseElement: <testLibrary>::@class::C::@constructor::new::@formalParameter::x
554568
substitution: {T: C<dynamic>}
555569
staticType: C<dynamic>
556570
rightParenthesis: )
571+
isDotShorthand: true
557572
staticType: C<C<dynamic>>
558573
''');
559574
}
@@ -587,6 +602,7 @@ DotShorthandConstructorInvocation
587602
correspondingParameter: <testLibrary>::@class::C::@constructor::new::@formalParameter::x
588603
staticType: int
589604
rightParenthesis: )
605+
isDotShorthand: true
590606
staticType: C
591607
''');
592608
}

pkg/analyzer/test/src/dart/resolution/dot_shorthand_invocation_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ DotShorthandInvocation
6060
argumentList: ArgumentList
6161
leftParenthesis: (
6262
rightParenthesis: )
63+
isDotShorthand: true
6364
staticInvokeType: C Function()
6465
staticType: C
6566
''');
@@ -105,6 +106,7 @@ DotShorthandInvocation
105106
substitution: {U: int}
106107
staticType: int
107108
rightParenthesis: )
109+
isDotShorthand: true
108110
staticInvokeType: C<dynamic> Function(int)
109111
staticType: C<dynamic>
110112
typeArgumentTypes
@@ -142,6 +144,7 @@ DotShorthandInvocation
142144
correspondingParameter: <testLibrary>::@class::C::@method::member::@formalParameter::x
143145
staticType: int
144146
rightParenthesis: )
147+
isDotShorthand: true
145148
staticInvokeType: C Function(int)
146149
staticType: C
147150
''');
@@ -172,6 +175,7 @@ FunctionExpressionInvocation
172175
token: id1
173176
element: <testLibrary>::@class::C::@getter::id1
174177
staticType: C
178+
isDotShorthand: false
175179
staticType: C
176180
argumentList: ArgumentList
177181
leftParenthesis: (
@@ -230,6 +234,7 @@ FunctionExpressionInvocation
230234
token: id1
231235
element: <testLibrary>::@class::C::@getter::id1
232236
staticType: C
237+
isDotShorthand: false
233238
staticType: C
234239
argumentList: ArgumentList
235240
leftParenthesis: (
@@ -266,6 +271,7 @@ DotShorthandInvocation
266271
argumentList: ArgumentList
267272
leftParenthesis: (
268273
rightParenthesis: )
274+
isDotShorthand: false
269275
staticInvokeType: C Function()
270276
staticType: C
271277
''');
@@ -297,6 +303,7 @@ DotShorthandInvocation
297303
argumentList: ArgumentList
298304
leftParenthesis: (
299305
rightParenthesis: )
306+
isDotShorthand: false
300307
staticInvokeType: C Function()
301308
staticType: C
302309
''');
@@ -333,6 +340,7 @@ DotShorthandInvocation
333340
correspondingParameter: <testLibrary>::@class::C::@method::member::@formalParameter::x
334341
staticType: int
335342
rightParenthesis: )
343+
isDotShorthand: true
336344
correspondingParameter: dart:core::@class::Object::@method::==::@formalParameter::other
337345
staticInvokeType: C Function(int)
338346
staticType: C
@@ -363,6 +371,7 @@ DotShorthandInvocation
363371
argumentList: ArgumentList
364372
leftParenthesis: (
365373
rightParenthesis: )
374+
isDotShorthand: false
366375
staticInvokeType: List<C> Function()
367376
staticType: List<C>
368377
''');
@@ -447,6 +456,7 @@ DotShorthandInvocation
447456
argumentList: ArgumentList
448457
leftParenthesis: (
449458
rightParenthesis: )
459+
isDotShorthand: true
450460
staticInvokeType: C Function()
451461
staticType: C
452462
''');
@@ -479,6 +489,7 @@ DotShorthandInvocation
479489
argumentList: ArgumentList
480490
leftParenthesis: (
481491
rightParenthesis: )
492+
isDotShorthand: true
482493
staticInvokeType: C Function()
483494
staticType: C
484495
''');
@@ -511,6 +522,7 @@ DotShorthandInvocation
511522
argumentList: ArgumentList
512523
leftParenthesis: (
513524
rightParenthesis: )
525+
isDotShorthand: true
514526
staticInvokeType: C Function()
515527
staticType: C
516528
''');
@@ -550,6 +562,7 @@ DotShorthandInvocation
550562
argumentList: ArgumentList
551563
leftParenthesis: (
552564
rightParenthesis: )
565+
isDotShorthand: true
553566
staticInvokeType: CMixin Function()
554567
staticType: CMixin
555568
''');
@@ -601,17 +614,20 @@ DotShorthandInvocation
601614
argumentList: ArgumentList
602615
leftParenthesis: (
603616
rightParenthesis: )
617+
isDotShorthand: true
604618
correspondingParameter: FieldFormalParameterMember
605619
baseElement: <testLibrary>::@class::C::@constructor::new::@formalParameter::x
606620
substitution: {T: C<dynamic>}
607621
staticInvokeType: C<int> Function()
608622
staticType: C<int>
609623
rightParenthesis: )
624+
isDotShorthand: true
610625
correspondingParameter: ParameterMember
611626
baseElement: <testLibrary>::@class::C::@method::memberType::@formalParameter::u
612627
substitution: {U: C<C<dynamic>>, V: dynamic}
613628
staticType: C<C<dynamic>>
614629
rightParenthesis: )
630+
isDotShorthand: true
615631
staticInvokeType: C<C<C<dynamic>>> Function(C<C<dynamic>>)
616632
staticType: C<C<C<dynamic>>>
617633
typeArgumentTypes
@@ -706,6 +722,7 @@ DotShorthandInvocation
706722
SimpleStringLiteral
707723
literal: "String"
708724
rightParenthesis: )
725+
isDotShorthand: false
709726
staticInvokeType: C<String> Function(String)
710727
staticType: C<String>
711728
typeArgumentTypes

0 commit comments

Comments
 (0)