@@ -300,16 +300,16 @@ class AssignedVariablesNodeInfo<Variable extends Object> {
300
300
/// Non-promotion reason describing the situation where a variable was not
301
301
/// promoted due to an explicit write to the variable appearing somewhere in the
302
302
/// source code.
303
- class DemoteViaExplicitWrite <Variable extends Object , Expression extends Object >
303
+ class DemoteViaExplicitWrite <Variable extends Object >
304
304
extends NonPromotionReason {
305
305
/// The local variable that was not promoted.
306
306
final Variable variable;
307
307
308
- /// The expression that wrote to the variable; this corresponds to an
309
- /// expression that was passed to [FlowAnalysis.write] .
310
- final Expression writeExpression ;
308
+ /// The node that wrote to the variable; this corresponds to a node that was
309
+ /// passed to [FlowAnalysis.write] .
310
+ final Object node ;
311
311
312
- DemoteViaExplicitWrite (this .variable, this .writeExpression );
312
+ DemoteViaExplicitWrite (this .variable, this .node );
313
313
314
314
@override
315
315
String get documentationLink => 'http://dart.dev/go/non-promo-write' ;
@@ -318,46 +318,14 @@ class DemoteViaExplicitWrite<Variable extends Object, Expression extends Object>
318
318
String get shortName => 'explicitWrite' ;
319
319
320
320
@override
321
- R accept< R , Node extends Object , Expression extends Object ,
322
- Variable extends Object , Type extends Object > (
323
- NonPromotionReasonVisitor <R , Node , Expression , Variable , Type >
324
- visitor) =>
321
+ R accept< R , Node extends Object , Variable extends Object ,
322
+ Type extends Object > (
323
+ NonPromotionReasonVisitor <R , Node , Variable , Type > visitor) =>
325
324
visitor.visitDemoteViaExplicitWrite (
326
- this as DemoteViaExplicitWrite <Variable , Expression >);
325
+ this as DemoteViaExplicitWrite <Variable >);
327
326
328
327
@override
329
- String toString () => 'DemoteViaExplicitWrite($writeExpression )' ;
330
- }
331
-
332
- /// Non-promotion reason describing the situation where a variable was not
333
- /// promoted due to the variable appearing before the word `in` in a "for each"
334
- /// statement or a "for each" collection element.
335
- class DemoteViaForEachVariableWrite <Variable extends Object ,
336
- Node extends Object > extends NonPromotionReason {
337
- /// The local variable that was not promoted.
338
- final Variable variable;
339
-
340
- /// The "for each" statement or collection element that wrote to the variable.
341
- final Node node;
342
-
343
- DemoteViaForEachVariableWrite (this .variable, this .node);
344
-
345
- @override
346
- String get documentationLink => 'http://dart.dev/go/non-promo-write' ;
347
-
348
- @override
349
- String get shortName => 'explicitWrite' ;
350
-
351
- @override
352
- R accept< R , Node extends Object , Expression extends Object ,
353
- Variable extends Object , Type extends Object > (
354
- NonPromotionReasonVisitor <R , Node , Expression , Variable , Type >
355
- visitor) =>
356
- visitor.visitDemoteViaForEachVariableWrite (
357
- this as DemoteViaForEachVariableWrite <Variable , Node >);
358
-
359
- @override
360
- String toString () => 'DemoteViaForEachVariableWrite($node )' ;
328
+ String toString () => 'DemoteViaExplicitWrite($node )' ;
361
329
}
362
330
363
331
/// A collection of flow models representing the possible outcomes of evaluating
@@ -565,11 +533,8 @@ abstract class FlowAnalysis<Node extends Object, Statement extends Node,
565
533
/// - Call [forEach_end] .
566
534
///
567
535
/// [node] should be the same node that was passed to
568
- /// [AssignedVariables.endNode] for the for statement. [loopVariable] should
569
- /// be the variable assigned to by the loop (if it is promotable, otherwise
570
- /// null). [writtenType] should be the type written to that variable (i.e.
571
- /// if the loop iterates over `List<Foo>` , it should be `Foo` ).
572
- void forEach_bodyBegin (Node node, Variable ? loopVariable, Type writtenType);
536
+ /// [AssignedVariables.endNode] for the for statement.
537
+ void forEach_bodyBegin (Node node);
573
538
574
539
/// Call this method just before visiting the body of a "for-in" statement or
575
540
/// collection element. See [forEach_bodyBegin] for details.
@@ -982,7 +947,7 @@ abstract class FlowAnalysis<Node extends Object, Statement extends Node,
982
947
983
948
/// Register write of the given [variable] in the current state.
984
949
/// [writtenType] should be the type of the value that was written.
985
- /// [expression ] should be the whole expression performing the write.
950
+ /// [node ] should be the syntactic construct performing the write.
986
951
/// [writtenExpression] should be the expression that was written, or `null`
987
952
/// if the expression that was written is not directly represented in the
988
953
/// source code (this happens, for example, with compound assignments and with
@@ -991,7 +956,7 @@ abstract class FlowAnalysis<Node extends Object, Statement extends Node,
991
956
/// This should also be used for the implicit write to a non-final variable in
992
957
/// its initializer, to ensure that the type is promoted to non-nullable if
993
958
/// necessary; in this case, [viaInitializer] should be `true` .
994
- void write (Expression expression , Variable variable, Type writtenType,
959
+ void write (Node node , Variable variable, Type writtenType,
995
960
Expression ? writtenExpression);
996
961
997
962
/// Prints out a summary of the current state of flow analysis, intended for
@@ -1162,9 +1127,9 @@ class FlowAnalysisDebug<Node extends Object, Statement extends Node,
1162
1127
}
1163
1128
1164
1129
@override
1165
- void forEach_bodyBegin (Node node, Variable ? loopVariable, Type writtenType ) {
1166
- return _wrap ('forEach_bodyBegin($ node , $ loopVariable , $ writtenType )' ,
1167
- () => _wrapped.forEach_bodyBegin (node, loopVariable, writtenType ));
1130
+ void forEach_bodyBegin (Node node) {
1131
+ return _wrap (
1132
+ 'forEach_bodyBegin($ node )' , () => _wrapped.forEach_bodyBegin (node));
1168
1133
}
1169
1134
1170
1135
@override
@@ -1513,12 +1478,10 @@ class FlowAnalysisDebug<Node extends Object, Statement extends Node,
1513
1478
}
1514
1479
1515
1480
@override
1516
- void write (Expression expression , Variable variable, Type writtenType,
1481
+ void write (Node node , Variable variable, Type writtenType,
1517
1482
Expression ? writtenExpression) {
1518
- _wrap (
1519
- 'write($expression , $variable , $writtenType , $writtenExpression )' ,
1520
- () => _wrapped.write (
1521
- expression, variable, writtenType, writtenExpression));
1483
+ _wrap ('write($node , $variable , $writtenType , $writtenExpression )' ,
1484
+ () => _wrapped.write (node, variable, writtenType, writtenExpression));
1522
1485
}
1523
1486
1524
1487
@override
@@ -2348,21 +2311,17 @@ abstract class NonPromotionReason {
2348
2311
String get shortName;
2349
2312
2350
2313
/// Implementation of the visitor pattern for non-promotion reasons.
2351
- R accept< R , Node extends Object , Expression extends Object ,
2352
- Variable extends Object , Type extends Object > (
2353
- NonPromotionReasonVisitor <R , Node , Expression , Variable , Type > visitor);
2314
+ R accept< R , Node extends Object , Variable extends Object ,
2315
+ Type extends Object > (
2316
+ NonPromotionReasonVisitor <R , Node , Variable , Type > visitor);
2354
2317
}
2355
2318
2356
2319
/// Implementation of the visitor pattern for non-promotion reasons.
2357
2320
abstract class NonPromotionReasonVisitor <R , Node extends Object ,
2358
- Expression extends Object , Variable extends Object , Type extends Object > {
2321
+ Variable extends Object , Type extends Object > {
2359
2322
NonPromotionReasonVisitor ._() : assert (false , 'Do not extend this class' );
2360
2323
2361
- R visitDemoteViaExplicitWrite (
2362
- DemoteViaExplicitWrite <Variable , Expression > reason);
2363
-
2364
- R visitDemoteViaForEachVariableWrite (
2365
- DemoteViaForEachVariableWrite <Variable , Node > reason);
2324
+ R visitDemoteViaExplicitWrite (DemoteViaExplicitWrite <Variable > reason);
2366
2325
2367
2326
R visitPropertyNotPromoted (PropertyNotPromoted <Type > reason);
2368
2327
@@ -2389,10 +2348,9 @@ class PropertyNotPromoted<Type extends Object> extends NonPromotionReason {
2389
2348
String get shortName => 'propertyNotPromoted' ;
2390
2349
2391
2350
@override
2392
- R accept< R , Node extends Object , Expression extends Object ,
2393
- Variable extends Object , Type extends Object > (
2394
- NonPromotionReasonVisitor <R , Node , Expression , Variable , Type >
2395
- visitor) =>
2351
+ R accept< R , Node extends Object , Variable extends Object ,
2352
+ Type extends Object > (
2353
+ NonPromotionReasonVisitor <R , Node , Variable , Type > visitor) =>
2396
2354
visitor.visitPropertyNotPromoted (this as PropertyNotPromoted <Type >);
2397
2355
}
2398
2356
@@ -2627,10 +2585,9 @@ class ThisNotPromoted extends NonPromotionReason {
2627
2585
String get shortName => 'thisNotPromoted' ;
2628
2586
2629
2587
@override
2630
- R accept< R , Node extends Object , Expression extends Object ,
2631
- Variable extends Object , Type extends Object > (
2632
- NonPromotionReasonVisitor <R , Node , Expression , Variable , Type >
2633
- visitor) =>
2588
+ R accept< R , Node extends Object , Variable extends Object ,
2589
+ Type extends Object > (
2590
+ NonPromotionReasonVisitor <R , Node , Variable , Type > visitor) =>
2634
2591
visitor.visitThisNotPromoted (this );
2635
2592
}
2636
2593
@@ -3680,22 +3637,14 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
3680
3637
}
3681
3638
3682
3639
@override
3683
- void forEach_bodyBegin (Node node, Variable ? loopVariable, Type writtenType ) {
3640
+ void forEach_bodyBegin (Node node) {
3684
3641
AssignedVariablesNodeInfo <Variable > info =
3685
3642
_assignedVariables._getInfoForNode (node);
3686
3643
_current = _current.conservativeJoin (info._written, info._captured).split ();
3687
3644
_SimpleStatementContext <Variable , Type > context =
3688
3645
new _SimpleStatementContext <Variable , Type >(
3689
3646
_current.reachable.parent! , _current);
3690
3647
_stack.add (context);
3691
- if (loopVariable != null ) {
3692
- _current = _current.write (
3693
- new DemoteViaForEachVariableWrite <Variable , Node >(loopVariable, node),
3694
- loopVariable,
3695
- writtenType,
3696
- new SsaNode <Variable , Type >(null ),
3697
- typeOperations);
3698
- }
3699
3648
}
3700
3649
3701
3650
@override
@@ -4220,15 +4169,15 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
4220
4169
}
4221
4170
4222
4171
@override
4223
- void write (Expression expression , Variable variable, Type writtenType,
4172
+ void write (Node node , Variable variable, Type writtenType,
4224
4173
Expression ? writtenExpression) {
4225
4174
ExpressionInfo <Variable , Type >? expressionInfo = writtenExpression == null
4226
4175
? null
4227
4176
: _getExpressionInfo (writtenExpression);
4228
4177
SsaNode <Variable , Type > newSsaNode = new SsaNode <Variable , Type >(
4229
4178
expressionInfo is _TrivialExpressionInfo ? null : expressionInfo);
4230
4179
_current = _current.write (
4231
- new DemoteViaExplicitWrite <Variable , Expression >(variable, expression ),
4180
+ new DemoteViaExplicitWrite <Variable >(variable, node ),
4232
4181
variable,
4233
4182
writtenType,
4234
4183
newSsaNode,
@@ -4509,8 +4458,7 @@ class _LegacyTypePromotion<Node extends Object, Statement extends Node,
4509
4458
void for_updaterBegin () {}
4510
4459
4511
4460
@override
4512
- void forEach_bodyBegin (
4513
- Node node, Variable ? loopVariable, Type ? writtenType) {}
4461
+ void forEach_bodyBegin (Node node) {}
4514
4462
4515
4463
@override
4516
4464
void forEach_end () {}
@@ -4815,7 +4763,7 @@ class _LegacyTypePromotion<Node extends Object, Statement extends Node,
4815
4763
}
4816
4764
4817
4765
@override
4818
- void write (Expression expression , Variable variable, Type writtenType,
4766
+ void write (Node node , Variable variable, Type writtenType,
4819
4767
Expression ? writtenExpression) {
4820
4768
assert (
4821
4769
_assignedVariables._anywhere._written.contains (variable),
0 commit comments