@@ -71,7 +71,10 @@ class SyntacticElementTarget {
71
71
caseLabelItem,
72
72
patternBinding,
73
73
uninitializedVar,
74
- forEachStmt,
74
+
75
+ // / The preamble of a for-in statement, including everything except the
76
+ // / body.
77
+ forEachPreamble,
75
78
} kind;
76
79
77
80
private:
@@ -245,7 +248,7 @@ class SyntacticElementTarget {
245
248
SyntacticElementTarget (ForEachStmt *stmt, DeclContext *dc,
246
249
bool ignoreWhereClause,
247
250
GenericEnvironment *packElementEnv)
248
- : kind(Kind::forEachStmt ) {
251
+ : kind(Kind::forEachPreamble ) {
249
252
forEachStmt.stmt = stmt;
250
253
forEachStmt.dc = dc;
251
254
forEachStmt.ignoreWhereClause = ignoreWhereClause;
@@ -268,11 +271,11 @@ class SyntacticElementTarget {
268
271
static SyntacticElementTarget
269
272
forReturn (ReturnStmt *returnStmt, Type contextTy, DeclContext *dc);
270
273
271
- // / Form a target for a for-in loop.
274
+ // / Form a target for the preamble of a for-in loop, excluding its body .
272
275
static SyntacticElementTarget
273
- forForEachStmt (ForEachStmt *stmt, DeclContext *dc,
274
- bool ignoreWhereClause = false ,
275
- GenericEnvironment *packElementEnv = nullptr );
276
+ forForEachPreamble (ForEachStmt *stmt, DeclContext *dc,
277
+ bool ignoreWhereClause = false ,
278
+ GenericEnvironment *packElementEnv = nullptr );
276
279
277
280
// / Form a target for a property with an attached property wrapper that is
278
281
// / initialized out-of-line.
@@ -311,7 +314,7 @@ class SyntacticElementTarget {
311
314
return ref.getAbstractClosureExpr ();
312
315
}
313
316
314
- case Kind::forEachStmt :
317
+ case Kind::forEachPreamble :
315
318
return getAsForEachStmt ();
316
319
317
320
case Kind::stmtCondition:
@@ -339,7 +342,7 @@ class SyntacticElementTarget {
339
342
case Kind::caseLabelItem:
340
343
case Kind::patternBinding:
341
344
case Kind::uninitializedVar:
342
- case Kind::forEachStmt :
345
+ case Kind::forEachPreamble :
343
346
return nullptr ;
344
347
}
345
348
llvm_unreachable (" invalid expression type" );
@@ -372,7 +375,7 @@ class SyntacticElementTarget {
372
375
return uninitializedVar.binding ->getInitContext (uninitializedVar.index );
373
376
}
374
377
375
- case Kind::forEachStmt :
378
+ case Kind::forEachPreamble :
376
379
return forEachStmt.dc ;
377
380
}
378
381
llvm_unreachable (" invalid decl context type" );
@@ -477,8 +480,8 @@ class SyntacticElementTarget {
477
480
// / For a pattern initialization target, retrieve the contextual pattern.
478
481
ContextualPattern getContextualPattern () const ;
479
482
480
- // / Whether this target is for a for-in statement .
481
- bool isForEachStmt () const { return kind == Kind::forEachStmt ; }
483
+ // / Whether this target is for a for-in preamble, excluding the body .
484
+ bool isForEachPreamble () const { return kind == Kind::forEachPreamble ; }
482
485
483
486
// / Whether this is an initialization for an Optional.Some pattern.
484
487
bool isOptionalSomePatternInit () const {
@@ -502,7 +505,7 @@ class SyntacticElementTarget {
502
505
bool shouldBindPatternVarsOneWay () const {
503
506
if (kind == Kind::expression)
504
507
return expression.bindPatternVarsOneWay ;
505
- if (kind == Kind::forEachStmt )
508
+ if (kind == Kind::forEachPreamble )
506
509
return !ignoreForEachWhereClause () && forEachStmt.stmt ->getWhere ();
507
510
return false ;
508
511
}
@@ -553,22 +556,22 @@ class SyntacticElementTarget {
553
556
}
554
557
555
558
bool ignoreForEachWhereClause () const {
556
- assert (isForEachStmt ());
559
+ assert (isForEachPreamble ());
557
560
return forEachStmt.ignoreWhereClause ;
558
561
}
559
562
560
563
GenericEnvironment *getPackElementEnv () const {
561
- assert (isForEachStmt ());
564
+ assert (isForEachPreamble ());
562
565
return forEachStmt.packElementEnv ;
563
566
}
564
567
565
568
const ForEachStmtInfo &getForEachStmtInfo () const {
566
- assert (isForEachStmt ());
569
+ assert (isForEachPreamble ());
567
570
return forEachStmt.info ;
568
571
}
569
572
570
573
ForEachStmtInfo &getForEachStmtInfo () {
571
- assert (isForEachStmt ());
574
+ assert (isForEachPreamble ());
572
575
return forEachStmt.info ;
573
576
}
574
577
@@ -595,7 +598,7 @@ class SyntacticElementTarget {
595
598
return ;
596
599
}
597
600
598
- if (kind == Kind::forEachStmt ) {
601
+ if (kind == Kind::forEachPreamble ) {
599
602
forEachStmt.pattern = pattern;
600
603
return ;
601
604
}
@@ -621,7 +624,7 @@ class SyntacticElementTarget {
621
624
case Kind::caseLabelItem:
622
625
case Kind::patternBinding:
623
626
case Kind::uninitializedVar:
624
- case Kind::forEachStmt :
627
+ case Kind::forEachPreamble :
625
628
return std::nullopt;
626
629
627
630
case Kind::function:
@@ -638,7 +641,7 @@ class SyntacticElementTarget {
638
641
case Kind::caseLabelItem:
639
642
case Kind::patternBinding:
640
643
case Kind::uninitializedVar:
641
- case Kind::forEachStmt :
644
+ case Kind::forEachPreamble :
642
645
return std::nullopt;
643
646
644
647
case Kind::stmtCondition:
@@ -655,7 +658,7 @@ class SyntacticElementTarget {
655
658
case Kind::stmtCondition:
656
659
case Kind::patternBinding:
657
660
case Kind::uninitializedVar:
658
- case Kind::forEachStmt :
661
+ case Kind::forEachPreamble :
659
662
return std::nullopt;
660
663
661
664
case Kind::caseLabelItem:
@@ -672,7 +675,7 @@ class SyntacticElementTarget {
672
675
case Kind::stmtCondition:
673
676
case Kind::caseLabelItem:
674
677
case Kind::uninitializedVar:
675
- case Kind::forEachStmt :
678
+ case Kind::forEachPreamble :
676
679
return nullptr ;
677
680
678
681
case Kind::patternBinding:
@@ -689,7 +692,7 @@ class SyntacticElementTarget {
689
692
case Kind::stmtCondition:
690
693
case Kind::caseLabelItem:
691
694
case Kind::patternBinding:
692
- case Kind::forEachStmt :
695
+ case Kind::forEachPreamble :
693
696
return nullptr ;
694
697
695
698
case Kind::uninitializedVar:
@@ -706,7 +709,7 @@ class SyntacticElementTarget {
706
709
case Kind::stmtCondition:
707
710
case Kind::caseLabelItem:
708
711
case Kind::patternBinding:
709
- case Kind::forEachStmt :
712
+ case Kind::forEachPreamble :
710
713
return nullptr ;
711
714
712
715
case Kind::uninitializedVar:
@@ -726,7 +729,7 @@ class SyntacticElementTarget {
726
729
case Kind::uninitializedVar:
727
730
return nullptr ;
728
731
729
- case Kind::forEachStmt :
732
+ case Kind::forEachPreamble :
730
733
return forEachStmt.stmt ;
731
734
}
732
735
llvm_unreachable (" invalid case label type" );
@@ -740,7 +743,7 @@ class SyntacticElementTarget {
740
743
case Kind::stmtCondition:
741
744
case Kind::caseLabelItem:
742
745
case Kind::patternBinding:
743
- case Kind::forEachStmt :
746
+ case Kind::forEachPreamble :
744
747
return nullptr ;
745
748
746
749
case Kind::uninitializedVar:
@@ -757,7 +760,7 @@ class SyntacticElementTarget {
757
760
case Kind::stmtCondition:
758
761
case Kind::caseLabelItem:
759
762
case Kind::patternBinding:
760
- case Kind::forEachStmt :
763
+ case Kind::forEachPreamble :
761
764
return nullptr ;
762
765
763
766
case Kind::uninitializedVar:
@@ -774,7 +777,7 @@ class SyntacticElementTarget {
774
777
case Kind::stmtCondition:
775
778
case Kind::caseLabelItem:
776
779
case Kind::patternBinding:
777
- case Kind::forEachStmt :
780
+ case Kind::forEachPreamble :
778
781
return 0 ;
779
782
780
783
case Kind::uninitializedVar:
@@ -837,8 +840,8 @@ class SyntacticElementTarget {
837
840
return uninitializedVar.declaration .get <Pattern *>()->getSourceRange ();
838
841
}
839
842
840
- // For-in statement target doesn't cover the body.
841
- case Kind::forEachStmt :
843
+ // For-in preamble target doesn't cover the body.
844
+ case Kind::forEachPreamble :
842
845
auto *stmt = forEachStmt.stmt ;
843
846
SourceLoc startLoc = stmt->getForLoc ();
844
847
SourceLoc endLoc = stmt->getParsedSequence ()->getEndLoc ();
@@ -881,7 +884,7 @@ class SyntacticElementTarget {
881
884
return uninitializedVar.declaration .get <Pattern *>()->getLoc ();
882
885
}
883
886
884
- case Kind::forEachStmt :
887
+ case Kind::forEachPreamble :
885
888
return forEachStmt.stmt ->getStartLoc ();
886
889
}
887
890
llvm_unreachable (" invalid target type" );
0 commit comments