@@ -966,19 +966,8 @@ class AttachedPropertyWrapperScope final : public ASTScopeImpl {
966
966
CustomAttr *attr;
967
967
VarDecl *decl;
968
968
969
- // / Because we have to avoid request cycles, we approximate the test for an
970
- // / AttachedPropertyWrapper with one based on source location. We might get
971
- // / false positives, that that doesn't hurt anything. However, the result of
972
- // / the conservative source range computation doesn't seem to be stable. So
973
- // / keep the original here, and use it for source range queries.
974
- const SourceRange sourceRangeWhenCreated;
975
-
976
969
AttachedPropertyWrapperScope (CustomAttr *attr, VarDecl *decl)
977
- : attr(attr), decl(decl),
978
- sourceRangeWhenCreated (attr->getTypeRepr ()->getSourceRange()) {
979
- ASTScopeAssert (sourceRangeWhenCreated.isValid (),
980
- " VarDecls must have ranges to be looked-up" );
981
- }
970
+ : attr(attr), decl(decl) {}
982
971
virtual ~AttachedPropertyWrapperScope () {}
983
972
984
973
protected:
@@ -1093,63 +1082,49 @@ class PatternEntryInitializerScope final : public AbstractPatternEntryScope {
1093
1082
bool lookupLocalsOrMembers (DeclConsumer) const override ;
1094
1083
};
1095
1084
1096
- // / The scope introduced by a conditional clause in an if/guard/while
1097
- // / statement.
1098
- // / Since there may be more than one "let foo = ..." in (e.g.) an "if",
1099
- // / we allocate a matrushka of these.
1100
- class ConditionalClauseScope final : public ASTScopeImpl {
1085
+ // / The scope introduced by a conditional clause initializer in an
1086
+ // / if/while/guard statement.
1087
+ class ConditionalClauseInitializerScope final : public ASTScopeImpl {
1101
1088
public:
1102
- LabeledConditionalStmt *const stmt;
1103
- const unsigned index;
1104
- const SourceLoc endLoc; // cannot get it from the stmt
1105
-
1106
- ConditionalClauseScope (LabeledConditionalStmt *stmt, unsigned index,
1107
- SourceLoc endLoc)
1108
- : stmt(stmt), index(index), endLoc(endLoc) {}
1109
-
1110
- virtual ~ConditionalClauseScope () {}
1089
+ Expr *const initializer;
1090
+ const SourceRange bodyRange;
1111
1091
1112
- protected:
1113
- ASTScopeImpl *expandSpecifically (ScopeCreator &scopeCreator) override ;
1114
-
1115
- private:
1116
- AnnotatedInsertionPoint
1117
- expandAScopeThatCreatesANewInsertionPoint (ScopeCreator &);
1118
-
1119
- public:
1120
- std::string getClassName () const override ;
1121
-
1122
- protected:
1123
- void printSpecifics (llvm::raw_ostream &out) const override ;
1092
+ ConditionalClauseInitializerScope (Expr *initializer)
1093
+ : initializer(initializer) {}
1124
1094
1125
- public:
1095
+ virtual ~ConditionalClauseInitializerScope () {}
1126
1096
SourceRange
1127
1097
getSourceRangeOfThisASTNode (bool omitAssertions = false ) const override ;
1098
+ std::string getClassName () const override ;
1128
1099
1129
1100
private:
1130
- ArrayRef<StmtConditionElement> getCond () const ;
1131
- const StmtConditionElement &getStmtConditionElement () const ;
1101
+ void expandAScopeThatDoesNotCreateANewInsertionPoint (ScopeCreator &);
1132
1102
1133
1103
protected:
1134
- bool isLabeledStmtLookupTerminator () const override ;
1104
+ ASTScopeImpl *expandSpecifically (ScopeCreator &scopeCreator) override ;
1105
+ NullablePtr<const ASTScopeImpl> getLookupParent () const override ;
1135
1106
};
1136
1107
1137
1108
// / If, while, & guard statements all start with a conditional clause, then some
1138
1109
// / later part of the statement, (then, body, or after the guard) circumvents
1139
1110
// / the normal lookup rule to pass the lookup scope into the deepest conditional
1140
1111
// / clause.
1141
1112
class ConditionalClausePatternUseScope final : public ASTScopeImpl {
1142
- Pattern * const pattern ;
1143
- const SourceLoc startLoc ;
1113
+ StmtConditionElement sec ;
1114
+ SourceLoc endLoc ;
1144
1115
1145
1116
public:
1146
- ConditionalClausePatternUseScope (Pattern *pattern , SourceLoc startLoc )
1147
- : pattern(pattern ), startLoc(startLoc ) {}
1117
+ ConditionalClausePatternUseScope (StmtConditionElement sec , SourceLoc endLoc )
1118
+ : sec(sec ), endLoc(endLoc ) {}
1148
1119
1149
1120
SourceRange
1150
1121
getSourceRangeOfThisASTNode (bool omitAssertions = false ) const override ;
1151
1122
std::string getClassName () const override ;
1152
1123
1124
+ private:
1125
+ AnnotatedInsertionPoint
1126
+ expandAScopeThatCreatesANewInsertionPoint (ScopeCreator &);
1127
+
1153
1128
protected:
1154
1129
ASTScopeImpl *expandSpecifically (ScopeCreator &) override ;
1155
1130
bool lookupLocalsOrMembers (DeclConsumer) const override ;
@@ -1214,8 +1189,10 @@ class ClosureParametersScope final : public ASTScopeImpl {
1214
1189
class TopLevelCodeScope final : public ASTScopeImpl {
1215
1190
public:
1216
1191
TopLevelCodeDecl *const decl;
1192
+ SourceLoc endLoc;
1217
1193
1218
- TopLevelCodeScope (TopLevelCodeDecl *e) : decl(e) {}
1194
+ TopLevelCodeScope (TopLevelCodeDecl *e, SourceLoc endLoc)
1195
+ : decl(e), endLoc(endLoc) {}
1219
1196
virtual ~TopLevelCodeScope () {}
1220
1197
1221
1198
protected:
@@ -1361,7 +1338,7 @@ class LabeledConditionalStmtScope : public AbstractStmtScope {
1361
1338
protected:
1362
1339
// / Return the lookupParent required to search these.
1363
1340
ASTScopeImpl *createNestedConditionalClauseScopes (ScopeCreator &,
1364
- const Stmt *afterConds );
1341
+ SourceLoc );
1365
1342
};
1366
1343
1367
1344
class IfStmtScope final : public LabeledConditionalStmtScope {
@@ -1419,28 +1396,24 @@ class GuardStmtScope final : public LabeledConditionalStmtScope {
1419
1396
getSourceRangeOfThisASTNode (bool omitAssertions = false ) const override ;
1420
1397
};
1421
1398
1422
- // / A scope after a guard statement that follows lookups into the conditions
1423
- // / Also for:
1424
- // / The insertion point of the last statement of an active clause in an #if
1425
- // / must be the lookup parent
1426
- // / of any following scopes. But the active clause may not be the last clause.
1427
- // / In short, this is another case where the lookup parent cannot follow the same
1428
- // / nesting as the source order. IfConfigUseScope implements this twist. It
1429
- // / follows the IfConfig, wraps all subsequent scopes, and redirects the lookup.
1430
- class LookupParentDiversionScope final : public ASTScopeImpl {
1399
+ // / A scope for the body of a guard statement. Lookups from the body must
1400
+ // / skip the parent scopes for introducing pattern bindings, since they're
1401
+ // / not visible in the guard body, only after the body ends.
1402
+ class GuardStmtBodyScope final : public ASTScopeImpl {
1431
1403
public:
1432
1404
ASTScopeImpl *const lookupParent;
1433
- const SourceLoc startLoc;
1434
- const SourceLoc endLoc;
1405
+ BraceStmt *const body;
1435
1406
1436
- LookupParentDiversionScope (ASTScopeImpl *lookupParent,
1437
- SourceLoc startLoc, SourceLoc endLoc)
1438
- : lookupParent(lookupParent), startLoc(startLoc), endLoc(endLoc) {}
1407
+ GuardStmtBodyScope (ASTScopeImpl *lookupParent, BraceStmt *body)
1408
+ : lookupParent(lookupParent), body(body) {}
1439
1409
1440
1410
SourceRange
1441
1411
getSourceRangeOfThisASTNode (bool omitAssertions = false ) const override ;
1442
1412
std::string getClassName () const override ;
1443
1413
1414
+ private:
1415
+ void expandAScopeThatDoesNotCreateANewInsertionPoint (ScopeCreator &);
1416
+
1444
1417
protected:
1445
1418
ASTScopeImpl *expandSpecifically (ScopeCreator &) override ;
1446
1419
NullablePtr<const ASTScopeImpl> getLookupParent () const override {
@@ -1672,13 +1645,21 @@ class BraceStmtScope final : public AbstractStmtScope {
1672
1645
// / definition.
1673
1646
SmallVector<VarDecl *, 2 > localVars;
1674
1647
1648
+ // / The end location for bindings introduced in this scope. This can
1649
+ // / extend past the actual end of the BraceStmt in top-level code,
1650
+ // / where every TopLevelCodeDecl introduces a new scope through the
1651
+ // / end of the buffer.
1652
+ SourceLoc endLoc;
1653
+
1675
1654
public:
1676
1655
BraceStmtScope (BraceStmt *e,
1677
1656
SmallVector<ValueDecl *, 2 > localFuncsAndTypes,
1678
- SmallVector<VarDecl *, 2 > localVars)
1657
+ SmallVector<VarDecl *, 2 > localVars,
1658
+ SourceLoc endLoc)
1679
1659
: stmt(e),
1680
1660
localFuncsAndTypes (localFuncsAndTypes),
1681
- localVars(localVars) {}
1661
+ localVars(localVars),
1662
+ endLoc(endLoc) {}
1682
1663
virtual ~BraceStmtScope () {}
1683
1664
1684
1665
protected:
0 commit comments