File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,8 @@ class ASTScopeImpl {
157
157
// source range. So include their ranges here
158
158
SourceRange sourceRangeOfIgnoredASTNodes;
159
159
160
+ mutable Optional<CharSourceRange> cachedCharSourceRange;
161
+
160
162
#pragma mark - constructor / destructor
161
163
public:
162
164
ASTScopeImpl (){};
@@ -212,6 +214,10 @@ class ASTScopeImpl {
212
214
213
215
SourceRange getSourceRangeOfScope (bool omitAssertions = false ) const ;
214
216
217
+ CharSourceRange getCharSourceRangeOfScope (SourceManager &SM,
218
+ bool omitAssertions = false ) const ;
219
+ bool isCharSourceRangeCached () const ;
220
+
215
221
// / InterpolatedStringLiteralExprs and EditorPlaceHolders respond to
216
222
// / getSourceRange with the starting point. But we might be asked to lookup an
217
223
// / identifer within one of them. So, find the real source range of them here.
Original file line number Diff line number Diff line change @@ -450,6 +450,27 @@ SourceRange GuardStmtBodyScope::getSourceRangeOfThisASTNode(
450
450
451
451
#pragma mark source range caching
452
452
453
+ CharSourceRange
454
+ ASTScopeImpl::getCharSourceRangeOfScope (SourceManager &SM,
455
+ bool omitAssertions) const {
456
+ if (!isCharSourceRangeCached ()) {
457
+ auto range = getSourceRangeOfThisASTNode (omitAssertions);
458
+ ASTScopeAssert (range.isValid (), " scope has invalid source range" );
459
+ ASTScopeAssert (SM.isBeforeInBuffer (range.Start , range.End ) ||
460
+ range.Start == range.End ,
461
+ " scope source range ends before start" );
462
+
463
+ cachedCharSourceRange =
464
+ Lexer::getCharSourceRangeFromSourceRange (SM, range);
465
+ }
466
+
467
+ return *cachedCharSourceRange;
468
+ }
469
+
470
+ bool ASTScopeImpl::isCharSourceRangeCached () const {
471
+ return cachedCharSourceRange.hasValue ();
472
+ }
473
+
453
474
SourceRange
454
475
ASTScopeImpl::getSourceRangeOfScope (const bool omitAssertions) const {
455
476
if (!isSourceRangeCached (omitAssertions))
You can’t perform that action at this time.
0 commit comments