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 {
157157 // source range. So include their ranges here
158158 SourceRange sourceRangeOfIgnoredASTNodes;
159159
160+ mutable Optional<CharSourceRange> cachedCharSourceRange;
161+
160162#pragma mark - constructor / destructor
161163public:
162164 ASTScopeImpl (){};
@@ -212,6 +214,10 @@ class ASTScopeImpl {
212214
213215 SourceRange getSourceRangeOfScope (bool omitAssertions = false ) const ;
214216
217+ CharSourceRange getCharSourceRangeOfScope (SourceManager &SM,
218+ bool omitAssertions = false ) const ;
219+ bool isCharSourceRangeCached () const ;
220+
215221 // / InterpolatedStringLiteralExprs and EditorPlaceHolders respond to
216222 // / getSourceRange with the starting point. But we might be asked to lookup an
217223 // / 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(
450450
451451#pragma mark source range caching
452452
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+
453474SourceRange
454475ASTScopeImpl::getSourceRangeOfScope (const bool omitAssertions) const {
455476 if (!isSourceRangeCached (omitAssertions))
You can’t perform that action at this time.
0 commit comments