SourceManager: add functions that compare SourceLocs and SourceRanges

Swift SVN r6994
This commit is contained in:
Dmitri Hrybenko
2013-08-07 20:06:12 +00:00
parent 1659de21a1
commit 686f9ec7fc
6 changed files with 56 additions and 36 deletions

View File

@@ -63,6 +63,23 @@ public:
unsigned getHashbangBufferID() const {
return HashbangBufferID;
}
/// Returns true if \c LHS is before \c RHS in the source buffer.
bool isBeforeInBuffer(SourceLoc LHS, SourceLoc RHS) const {
return LHS.Value.getPointer() < RHS.Value.getPointer();
}
/// Returns true if range \c R contains the location \c Loc.
bool rangeContainsLoc(SourceRange R, SourceLoc Loc) const {
return Loc == R.Start || Loc == R.End ||
(isBeforeInBuffer(R.Start, Loc) && isBeforeInBuffer(Loc, R.End));
}
/// Returns true if range \c Enclosing contains the range \c Inner.
bool rangeContains(SourceRange Enclosing, SourceRange Inner) const {
return rangeContainsLoc(Enclosing, Inner.Start) &&
rangeContainsLoc(Enclosing, Inner.End);
}
};
} // namespace swift