@@ -38,6 +38,14 @@ using namespace ast_scope;
38
38
39
39
static SourceLoc getLocAfterExtendedNominal (const ExtensionDecl *);
40
40
41
+ // / Retrieve the character-based source range for the given source range.
42
+ static SourceRange getCharSourceRange (
43
+ SourceManager &sourceMgr, SourceRange range
44
+ ){
45
+ range.End = Lexer::getLocForEndOfToken (sourceMgr, range.End );
46
+ return range;
47
+ }
48
+
41
49
void ASTScopeImpl::checkSourceRangeBeforeAddingChild (ASTScopeImpl *child,
42
50
const ASTContext &ctx) const {
43
51
// Ignore debugger bindings - they're a special mix of user code and implicit
@@ -51,35 +59,18 @@ void ASTScopeImpl::checkSourceRangeBeforeAddingChild(ASTScopeImpl *child,
51
59
52
60
auto range = getCharSourceRangeOfScope (sourceMgr);
53
61
54
- std::function<bool (CharSourceRange )> containedInParent;
55
- containedInParent = [&](CharSourceRange childCharRange) {
62
+ std::function<bool (SourceRange )> containedInParent;
63
+ containedInParent = [&](SourceRange childCharRange) {
56
64
// HACK: For code completion. Handle replaced range.
57
65
for (const auto &pair : sourceMgr.getReplacedRanges ()) {
58
- auto originalRange =
59
- Lexer::getCharSourceRangeFromSourceRange (sourceMgr, pair.first );
60
- auto newRange =
61
- Lexer::getCharSourceRangeFromSourceRange (sourceMgr, pair.second );
62
- if (range.contains (originalRange) &&
63
- newRange.contains (childCharRange))
66
+ auto originalRange = getCharSourceRange (sourceMgr, pair.first );
67
+ auto newRange = getCharSourceRange (sourceMgr, pair.second );
68
+ if (sourceMgr.encloses (range, originalRange) &&
69
+ sourceMgr.encloses (newRange, childCharRange))
64
70
return true ;
65
71
}
66
72
67
- if (range.contains (childCharRange))
68
- return true ;
69
-
70
- // If this is from a macro expansion, look at the where the expansion
71
- // occurred.
72
- auto childBufferID =
73
- sourceMgr.findBufferContainingLoc (childCharRange.getStart ());
74
- auto generatedInfo = sourceMgr.getGeneratedSourceInfo (childBufferID);
75
- if (!generatedInfo)
76
- return false ;
77
-
78
- CharSourceRange expansionRange = generatedInfo->originalSourceRange ;
79
- if (expansionRange.isInvalid ())
80
- return false ;
81
-
82
- return containedInParent (expansionRange);
73
+ return sourceMgr.encloses (range, childCharRange);
83
74
};
84
75
85
76
auto childCharRange = child->getCharSourceRangeOfScope (sourceMgr);
@@ -95,11 +86,9 @@ void ASTScopeImpl::checkSourceRangeBeforeAddingChild(ASTScopeImpl *child,
95
86
if (!storedChildren.empty ()) {
96
87
auto previousChild = storedChildren.back ();
97
88
auto endOfPreviousChild = previousChild->getCharSourceRangeOfScope (
98
- sourceMgr).getEnd () ;
89
+ sourceMgr).End ;
99
90
100
- if (childCharRange.getStart () != endOfPreviousChild &&
101
- !sourceMgr.isBeforeInBuffer (endOfPreviousChild,
102
- childCharRange.getStart ())) {
91
+ if (!sourceMgr.isAtOrBefore (endOfPreviousChild, childCharRange.Start )) {
103
92
auto &out = verificationError () << " child overlaps previous child:\n " ;
104
93
child->print (out);
105
94
out << " \n ***Previous child\n " ;
@@ -384,18 +373,19 @@ SourceRange GuardStmtBodyScope::getSourceRangeOfThisASTNode(
384
373
385
374
#pragma mark source range caching
386
375
387
- CharSourceRange
376
+ SourceRange
388
377
ASTScopeImpl::getCharSourceRangeOfScope (SourceManager &SM,
389
378
bool omitAssertions) const {
390
379
if (!isCharSourceRangeCached ()) {
391
380
auto range = getSourceRangeOfThisASTNode (omitAssertions);
392
381
ASTScopeAssert (range.isValid (), " scope has invalid source range" );
393
- ASTScopeAssert (SM.isBeforeInBuffer (range.Start , range.End ) ||
382
+ ASTScopeAssert (SM.isBefore (range.Start , range.End ) ||
394
383
range.Start == range.End ,
395
384
" scope source range ends before start" );
396
385
397
- cachedCharSourceRange =
398
- Lexer::getCharSourceRangeFromSourceRange (SM, range);
386
+ range.End = Lexer::getLocForEndOfToken (SM, range.End );
387
+
388
+ cachedCharSourceRange = range;
399
389
}
400
390
401
391
return *cachedCharSourceRange;
0 commit comments