@@ -141,21 +141,14 @@ class ASTScopeImpl {
141
141
ASTScopeImpl *parent = nullptr ; // null at the root
142
142
143
143
// / Child scopes, sorted by source range.
144
- // / Must clear source range change whenever this changes
145
144
Children storedChildren;
146
145
147
146
bool wasExpanded = false ;
148
147
149
148
// / Can clear storedChildren, so must remember this
150
149
bool haveAddedCleanup = false ;
151
150
152
- // Must be updated after last child is added and after last child's source
153
- // position is known
154
- mutable Optional<SourceRange> cachedSourceRange;
155
-
156
- // When ignoring ASTNodes in a scope, they still must count towards a scope's
157
- // source range. So include their ranges here
158
- SourceRange sourceRangeOfIgnoredASTNodes;
151
+ mutable Optional<CharSourceRange> cachedCharSourceRange;
159
152
160
153
#pragma mark - constructor / destructor
161
154
public:
@@ -192,9 +185,6 @@ class ASTScopeImpl {
192
185
public:
193
186
void addChild (ASTScopeImpl *child, ASTContext &);
194
187
195
- private:
196
- NullablePtr<ASTScopeImpl> getPriorSibling () const ;
197
-
198
188
public:
199
189
void preOrderDo (function_ref<void (ASTScopeImpl *)>);
200
190
// / Like preorderDo but without myself.
@@ -203,78 +193,26 @@ class ASTScopeImpl {
203
193
204
194
#pragma mark - source ranges
205
195
206
- #pragma mark - source range queries
207
-
208
196
public:
209
197
// / Return signum of ranges. Centralize the invariant that ASTScopes use ends.
210
198
static int compare (SourceRange, SourceRange, const SourceManager &,
211
199
bool ensureDisjoint);
212
200
213
- SourceRange getSourceRangeOfScope (bool omitAssertions = false ) const ;
214
-
215
- // / InterpolatedStringLiteralExprs and EditorPlaceHolders respond to
216
- // / getSourceRange with the starting point. But we might be asked to lookup an
217
- // / identifer within one of them. So, find the real source range of them here.
218
- SourceRange getEffectiveSourceRange (ASTNode) const ;
219
-
220
- void computeAndCacheSourceRangeOfScope (bool omitAssertions = false ) const ;
221
- bool isSourceRangeCached (bool omitAssertions = false ) const ;
222
-
223
- bool checkSourceRangeOfThisASTNode () const ;
224
-
225
- // / For debugging
226
- bool doesRangeMatch (unsigned start, unsigned end, StringRef file = " " ,
227
- StringRef className = " " );
228
-
229
- unsigned countDescendants () const ;
230
-
231
- // / Make sure that when the argument is executed, there are as many
232
- // / descendants after as before.
233
- void assertThatTreeDoesNotShrink (function_ref<void ()>);
234
-
235
- private:
236
- SourceRange computeSourceRangeOfScope (bool omitAssertions = false ) const ;
237
- SourceRange
238
- computeSourceRangeOfScopeWithChildASTNodes (bool omitAssertions = false ) const ;
239
- bool ensureNoAncestorsSourceRangeIsCached () const ;
240
-
241
- #pragma mark - source range adjustments
242
- private:
243
- SourceRange widenSourceRangeForIgnoredASTNodes (SourceRange range) const ;
244
-
245
- // / If the scope refers to a Decl whose source range tells the whole story,
246
- // / for example a NominalTypeScope, it is not necessary to widen the source
247
- // / range by examining the children. In that case we could just return
248
- // / the childlessRange here.
249
- // / But, we have not marked such scopes yet. Doing so would be an
250
- // / optimization.
251
- SourceRange widenSourceRangeForChildren (SourceRange range,
252
- bool omitAssertions) const ;
253
-
254
- // / Even ASTNodes that do not form scopes must be included in a Scope's source
255
- // / range. Widen the source range of the receiver to include the (ignored)
256
- // / node.
257
- void widenSourceRangeForIgnoredASTNode (ASTNode);
258
-
259
- private:
260
- void clearCachedSourceRangesOfMeAndAncestors ();
201
+ CharSourceRange getCharSourceRangeOfScope (SourceManager &SM,
202
+ bool omitAssertions = false ) const ;
203
+ bool isCharSourceRangeCached () const ;
261
204
262
- public: // public for debugging
263
205
// / Returns source range of this node alone, without factoring in any
264
206
// / children.
265
207
virtual SourceRange
266
208
getSourceRangeOfThisASTNode (bool omitAssertions = false ) const = 0 ;
267
209
268
210
protected:
269
211
SourceManager &getSourceManager () const ;
270
- bool hasValidSourceRange () const ;
271
- bool hasValidSourceRangeOfIgnoredASTNodes () const ;
272
- bool precedesInSource (const ASTScopeImpl *) const ;
273
- bool verifyThatChildrenAreContainedWithin (SourceRange) const ;
274
- bool verifyThatThisNodeComeAfterItsPriorSibling () const ;
275
212
276
213
private:
277
- bool checkSourceRangeAfterExpansion (const ASTContext &) const ;
214
+ void checkSourceRangeBeforeAddingChild (ASTScopeImpl *child,
215
+ const ASTContext &ctx) const ;
278
216
279
217
#pragma mark common queries
280
218
public:
@@ -329,19 +267,11 @@ class ASTScopeImpl {
329
267
void setWasExpanded () { wasExpanded = true ; }
330
268
virtual ASTScopeImpl *expandSpecifically (ScopeCreator &) = 0;
331
269
332
- private:
333
- // / Compare the pre-expasion range with the post-expansion range and return
334
- // / false if lazyiness couild miss lookups.
335
- bool checkLazySourceRange (const ASTContext &) const ;
336
-
337
270
public:
338
271
// / Some scopes can be expanded lazily.
339
- // / Such scopes must: not change their source ranges after expansion, and
340
- // / their expansion must return an insertion point outside themselves.
341
- // / After a node is expanded, its source range (getSourceRangeofThisASTNode
342
- // / union children's ranges) must be same as this.
272
+ // / Such scopes must return an insertion point outside themselves when
273
+ // / expanded.
343
274
virtual NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion ();
344
- virtual SourceRange sourceRangeForDeferredExpansion () const ;
345
275
346
276
private:
347
277
virtual ScopeCreator &getScopeCreator ();
@@ -545,8 +475,6 @@ class Portion {
545
475
546
476
virtual NullablePtr<ASTScopeImpl>
547
477
insertionPointForDeferredExpansion (IterableTypeScope *) const = 0 ;
548
- virtual SourceRange
549
- sourceRangeForDeferredExpansion (const IterableTypeScope *) const = 0 ;
550
478
};
551
479
552
480
// For the whole Decl scope of a GenericType or an Extension
@@ -570,8 +498,6 @@ class Portion {
570
498
571
499
NullablePtr<ASTScopeImpl>
572
500
insertionPointForDeferredExpansion (IterableTypeScope *) const override ;
573
- SourceRange
574
- sourceRangeForDeferredExpansion (const IterableTypeScope *) const override ;
575
501
};
576
502
577
503
// / GenericTypeOrExtension = GenericType or Extension
@@ -603,8 +529,6 @@ class GenericTypeOrExtensionWherePortion final
603
529
604
530
NullablePtr<ASTScopeImpl>
605
531
insertionPointForDeferredExpansion (IterableTypeScope *) const override ;
606
- SourceRange
607
- sourceRangeForDeferredExpansion (const IterableTypeScope *) const override ;
608
532
};
609
533
610
534
// / Behavior specific to representing the Body of a NominalTypeDecl or
@@ -622,8 +546,6 @@ class IterableTypeBodyPortion final
622
546
623
547
NullablePtr<ASTScopeImpl>
624
548
insertionPointForDeferredExpansion (IterableTypeScope *) const override ;
625
- SourceRange
626
- sourceRangeForDeferredExpansion (const IterableTypeScope *) const override ;
627
549
};
628
550
629
551
// / GenericType or Extension scope
@@ -720,7 +642,6 @@ class IterableTypeScope : public GenericTypeScope {
720
642
721
643
public:
722
644
NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion () override ;
723
- SourceRange sourceRangeForDeferredExpansion () const override ;
724
645
725
646
void countBodies (ScopeCreator &) const ;
726
647
};
@@ -929,7 +850,6 @@ class FunctionBodyScope : public ASTScopeImpl {
929
850
public:
930
851
std::string getClassName () const override ;
931
852
NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion () override ;
932
- SourceRange sourceRangeForDeferredExpansion () const override ;
933
853
};
934
854
935
855
class DefaultArgumentInitializerScope final : public ASTScopeImpl {
0 commit comments