Skip to content

Commit e52413f

Browse files
committed
ASTScope: Use CharSourceRanges for lookup
1 parent 771fd6e commit e52413f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/AST/ASTScopeLookup.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ bool ASTScopeImpl::checkSourceRangeOfThisASTNode() const {
8383
/// If the \p loc is in a new buffer but \p range is not, consider the location
8484
/// is at the start of replaced range. Otherwise, returns \p loc as is.
8585
static SourceLoc translateLocForReplacedRange(SourceManager &sourceMgr,
86-
SourceRange range,
86+
CharSourceRange range,
8787
SourceLoc loc) {
8888
if (const auto &replacedRange = sourceMgr.getReplacedRange()) {
8989
if (sourceMgr.rangeContainsTokenLoc(replacedRange.New, loc) &&
90-
!sourceMgr.rangeContains(replacedRange.New, range)) {
90+
!sourceMgr.rangeContainsTokenLoc(replacedRange.New, range.getStart())) {
9191
return replacedRange.Original.Start;
9292
}
9393
}
@@ -101,17 +101,19 @@ ASTScopeImpl::findChildContaining(SourceLoc loc,
101101
auto *const *child = llvm::lower_bound(
102102
getChildren(), loc,
103103
[&sourceMgr](const ASTScopeImpl *scope, SourceLoc loc) {
104-
ASTScopeAssert(scope->checkSourceRangeOfThisASTNode(), "Bad range.");
105-
auto rangeOfScope = scope->getSourceRangeOfScope();
104+
auto rangeOfScope = scope->getCharSourceRangeOfScope(sourceMgr);
105+
ASTScopeAssert(!sourceMgr.isBeforeInBuffer(rangeOfScope.getEnd(),
106+
rangeOfScope.getStart()),
107+
"Source range is backwards");
106108
loc = translateLocForReplacedRange(sourceMgr, rangeOfScope, loc);
107-
return -1 == ASTScopeImpl::compare(rangeOfScope, loc, sourceMgr,
108-
/*ensureDisjoint=*/false);
109+
return (rangeOfScope.getEnd() == loc ||
110+
sourceMgr.isBeforeInBuffer(rangeOfScope.getEnd(), loc));
109111
});
110112

111113
if (child != getChildren().end()) {
112-
auto rangeOfScope = (*child)->getSourceRangeOfScope();
114+
auto rangeOfScope = (*child)->getCharSourceRangeOfScope(sourceMgr);
113115
loc = translateLocForReplacedRange(sourceMgr, rangeOfScope, loc);
114-
if (sourceMgr.rangeContainsTokenLoc(rangeOfScope, loc))
116+
if (rangeOfScope.contains(loc))
115117
return *child;
116118
}
117119

0 commit comments

Comments
 (0)