@@ -610,6 +610,7 @@ NO_EXPANSION(GenericParamScope)
610
610
NO_EXPANSION(ASTSourceFileScope)
611
611
NO_EXPANSION(ClosureParametersScope)
612
612
NO_EXPANSION(SpecializeAttributeScope)
613
+ // no accessors, unlike PatternEntryUseScope
613
614
NO_EXPANSION(ConditionalClauseUseScope)
614
615
NO_EXPANSION(AttachedPropertyWrapperScope)
615
616
NO_EXPANSION(StatementConditionElementPatternScope)
@@ -673,14 +674,27 @@ ASTScopeImpl *PatternEntryUseScope::expandAScopeThatCreatesANewInsertionPoint(
673
674
}
674
675
675
676
ASTScopeImpl *ConditionalClauseScope::expandAScopeThatCreatesANewInsertionPoint (
676
- ScopeCreator &scopeCreator) {
677
- createSubtreeForCondition (scopeCreator);
678
- return this ;
677
+ ScopeCreator &scopeCreator) {
678
+ const auto &cond = enclosingStmt->getCond ()[index ];
679
+ switch (cond.getKind ()) {
680
+ case StmtConditionElement::CK_Availability:
681
+ return this ;
682
+ case StmtConditionElement::CK_Boolean:
683
+ ASTVisitorForScopeCreation ().visitExpr (cond.getBoolean (), this ,
684
+ scopeCreator);
685
+ return this ;
686
+ case StmtConditionElement::CK_PatternBinding:
687
+ pattern = cond.getPattern ());
688
+ ASTVisitorForScopeCreation ().visitExpr (cond.getInitializer (), this ,
689
+ scopeCreator);
690
+ return scopeCreator.createSubtree <ConditionalClauseUseScope>(this , this , cond.getEndLoc ());
691
+ }
679
692
}
680
693
681
694
ASTScopeImpl *GuardStmtScope::expandAScopeThatCreatesANewInsertionPoint (
682
695
ScopeCreator &scopeCreator) {
683
- ASTScopeImpl *lookupParent = createCondScopes (scopeCreator);
696
+
697
+ ASTScopeImpl *lookupParent = createNestedConditionalClauseScopes (scopeCreator, stmt->getBody ()->getEndLoc ();
684
698
// Add a child for the 'guard' body, which always exits.
685
699
// Parent is whole guard stmt scope, NOT the cond scopes
686
700
scopeCreator.createScopeFor (stmt->getBody (), this );
@@ -746,19 +760,19 @@ void AbstractFunctionBodyScope::expandAScopeThatDoesNotCreateANewInsertionPoint(
746
760
747
761
void IfStmtScope::expandAScopeThatDoesNotCreateANewInsertionPoint (
748
762
ScopeCreator &scopeCreator) {
749
- ASTScopeImpl *lookupParent = createCondScopes (scopeCreator);
763
+ ASTScopeImpl *insertionPoint = createNestedConditionalClauseScopes (scopeCreator, stmt-> getThenStmt ()-> getStartLoc () );
750
764
751
765
// The 'then' branch
752
- scopeCreator.createScopeFor (stmt->getThenStmt (), lookupParent );
766
+ scopeCreator.createScopeFor (stmt->getThenStmt (), insertionPoint );
753
767
754
768
// Add the 'else' branch, if needed.
755
769
scopeCreator.createScopeFor (stmt->getElseStmt (), this );
756
770
}
757
771
758
772
void WhileStmtScope::expandAScopeThatDoesNotCreateANewInsertionPoint (
759
773
ScopeCreator &scopeCreator) {
760
- ASTScopeImpl *lookupParent = createCondScopes (scopeCreator);
761
- scopeCreator.createScopeFor (stmt->getBody (), lookupParent );
774
+ ASTScopeImpl *insertionPoint = createNestedConditionalClauseScopes (scopeCreator, stmt-> getBody ()-> getStartLoc () );
775
+ scopeCreator.createScopeFor (stmt->getBody (), insertionPoint );
762
776
}
763
777
764
778
void RepeatWhileScope::expandAScopeThatDoesNotCreateANewInsertionPoint (
@@ -964,21 +978,16 @@ TypeAliasScope::createTrailingWhereClauseScope(ASTScopeImpl *parent,
964
978
#pragma mark misc
965
979
966
980
ASTScopeImpl *
967
- LabeledConditionalStmtScope::createCondScopes (ScopeCreator &scopeCreator) {
981
+ LabeledConditionalStmtScope::createNestedConditionalClauseScopes (ScopeCreator &scopeCreator, SourceLoc lastUseScopeStart ) {
968
982
auto *stmt = getLabeledConditionalStmt ();
969
983
ASTScopeImpl *insertionPoint = this ;
970
- for (unsigned i = 0 ; i < stmt->getCond ().size (); ++i)
984
+ for (unsigned i = 0 ; i < stmt->getCond ().size (); ++i) {
985
+ // If cond has a pattern, it needs to know where to start the use scope
986
+ const SourceLoc useScopeStart = i + 1 < stmt->getCond ().size () ? stmt->getCond ()[i+1 ].getStartLoc () : lastUseStart;
971
987
insertionPoint = scopeCreator.createSubtree <ConditionalClauseScope>(
972
- insertionPoint, stmt, i, getStmtAfterTheConditions ());
973
- return insertionPoint->getStatementConditionIfAny ();
974
- }
975
-
976
- ASTScopeImpl *ASTScopeImpl::getStatementConditionIfAny () { return this ; }
977
-
978
- ASTScopeImpl *ConditionalClauseScope::getStatementConditionIfAny () {
979
- return statementConditionElementPatternScope
980
- ? statementConditionElementPatternScope.get ()
981
- : this ;
988
+ insertionPoint, stmt, i, useScopeStart);
989
+ }
990
+ return insertionPoint;
982
991
}
983
992
984
993
AbstractPatternEntryScope::AbstractPatternEntryScope (
@@ -1002,27 +1011,6 @@ void AbstractPatternEntryScope::forEachVarDeclWithExplicitAccessors(
1002
1011
});
1003
1012
}
1004
1013
1005
-
1006
- void ConditionalClauseScope::createSubtreeForCondition (
1007
- ScopeCreator &scopeCreator) {
1008
- const auto &cond = enclosingStmt->getCond ()[index ];
1009
- switch (cond.getKind ()) {
1010
- case StmtConditionElement::CK_Availability:
1011
- return ;
1012
- case StmtConditionElement::CK_Boolean:
1013
- ASTVisitorForScopeCreation ().visitExpr (cond.getBoolean (), this ,
1014
- scopeCreator);
1015
- return ;
1016
- case StmtConditionElement::CK_PatternBinding:
1017
- statementConditionElementPatternScope =
1018
- scopeCreator.createSubtree <StatementConditionElementPatternScope>(
1019
- this , cond.getPattern ());
1020
- ASTVisitorForScopeCreation ().visitExpr (cond.getInitializer (), this ,
1021
- scopeCreator);
1022
- return ;
1023
- }
1024
- }
1025
-
1026
1014
bool AbstractPatternEntryScope::isLastEntry () const {
1027
1015
return patternEntryIndex + 1 == decl->getPatternList ().size ();
1028
1016
}
0 commit comments