@@ -177,8 +177,10 @@ class ASTScopeImpl {
177
177
void addChild (ASTScopeImpl *child, ASTContext &);
178
178
std::vector<ASTScopeImpl *> rescueYoungestChildren (unsigned count);
179
179
180
- virtual std::vector<ASTScopeImpl *> rescueScopesToReuse ();
181
- virtual void addReusedScopes (ArrayRef<ASTScopeImpl *>);
180
+ // / When reexpanding, do we always create a new body?
181
+ virtual NullablePtr<ASTScopeImpl> getParentOfRescuedScopes ();
182
+ std::vector<ASTScopeImpl *> rescueScopesToReuse ();
183
+ void addReusedScopes (ArrayRef<ASTScopeImpl *>);
182
184
183
185
private:
184
186
void removeChildren ();
@@ -201,7 +203,8 @@ class ASTScopeImpl {
201
203
// / InterpolatedStringLiteralExprs and EditorPlaceHolders respond to
202
204
// / getSourceRange with the starting point. But we might be asked to lookup an
203
205
// / identifer within one of them. So, find the real source range of them here.
204
- // / /// FIXME: Alter how these are parsed so getSourceRange is enough.
206
+ // /
207
+ // / FIXME: Alter how these are parsed so getSourceRange is enough.
205
208
SourceRange getEffectiveSourceRange (ASTNode) const ;
206
209
207
210
void cacheSourceRangeOfMeAndDescendants (bool omitAssertions = false ) const ;
@@ -303,6 +306,12 @@ class ASTScopeImpl {
303
306
virtual void beCurrent ();
304
307
virtual bool isCurrent () const ;
305
308
309
+ // / Some scopes can be expanded lazily.
310
+ // / Such scopes must: not change their source ranges after expansion, and
311
+ // / their expansion must return an insertion point outside themselves.
312
+ virtual NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion ();
313
+ virtual SourceRange sourceRangeForDeferredExpansion () const ;
314
+
306
315
public:
307
316
// Some nodes (VarDecls and Accessors) are created directly from
308
317
// pattern scope code and should neither be deferred nor should
@@ -548,6 +557,10 @@ class Portion {
548
557
549
558
virtual void beCurrent (IterableTypeScope *) const ;
550
559
virtual bool isCurrent (const IterableTypeScope *) const ;
560
+ virtual NullablePtr<ASTScopeImpl>
561
+ insertionPointForDeferredExpansion (IterableTypeScope *) const ;
562
+ virtual SourceRange
563
+ sourceRangeForDeferredExpansion (const IterableTypeScope *) const ;
551
564
};
552
565
553
566
// For the whole Decl scope of a GenericType or an Extension
@@ -623,6 +636,10 @@ class IterableTypeBodyPortion final
623
636
624
637
void beCurrent (IterableTypeScope *) const override ;
625
638
bool isCurrent (const IterableTypeScope *) const override ;
639
+ NullablePtr<ASTScopeImpl>
640
+ insertionPointForDeferredExpansion (IterableTypeScope *) const override ;
641
+ SourceRange
642
+ sourceRangeForDeferredExpansion (const IterableTypeScope *) const override ;
626
643
};
627
644
628
645
// / GenericType or Extension scope
@@ -702,7 +719,6 @@ class IterableTypeScope : public GenericTypeScope {
702
719
// / Because of \c parseDelayedDecl members can get added after the tree is
703
720
// / constructed, and they can be out of order. Detect this happening by
704
721
// / remembering the member count.
705
- // / TODO: unify with \c numberOfDeclsAlreadySeen
706
722
unsigned memberCount = 0 ;
707
723
708
724
public:
@@ -721,6 +737,8 @@ class IterableTypeScope : public GenericTypeScope {
721
737
public:
722
738
void makeBodyCurrent ();
723
739
bool isBodyCurrent () const ;
740
+ NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion () override ;
741
+ SourceRange sourceRangeForDeferredExpansion () const override ;
724
742
};
725
743
726
744
class NominalTypeScope final : public IterableTypeScope {
@@ -958,8 +976,7 @@ class AbstractFunctionBodyScope : public ASTScopeImpl {
958
976
Decl *getDecl () const { return decl; }
959
977
static bool isAMethod (const AbstractFunctionDecl *);
960
978
961
- std::vector<ASTScopeImpl *> rescueScopesToReuse () override ;
962
- void addReusedScopes (ArrayRef<ASTScopeImpl *>) override ;
979
+ NullablePtr<ASTScopeImpl> getParentOfRescuedScopes () override ;
963
980
964
981
protected:
965
982
bool lookupLocalsOrMembers (ArrayRef<const ASTScopeImpl *>,
@@ -1122,7 +1139,6 @@ class PatternEntryDeclScope final : public AbstractPatternEntryScope {
1122
1139
SourceRange
1123
1140
getChildlessSourceRange (bool omitAssertions = false ) const override ;
1124
1141
1125
- static bool isHandledSpecially (const ASTNode n);
1126
1142
NullablePtr<const void > getReferrent () const override ;
1127
1143
1128
1144
protected:
@@ -1372,8 +1388,7 @@ class TopLevelCodeScope final : public ASTScopeImpl {
1372
1388
Decl *getDecl () const { return decl; }
1373
1389
NullablePtr<const void > getReferrent () const override ;
1374
1390
1375
- std::vector<ASTScopeImpl *> rescueScopesToReuse () override ;
1376
- void addReusedScopes (ArrayRef<ASTScopeImpl *>) override ;
1391
+ NullablePtr<ASTScopeImpl> getParentOfRescuedScopes () override ;
1377
1392
};
1378
1393
1379
1394
// / The \c _@specialize attribute.
0 commit comments