mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
SourceManager: add functions that compare SourceLocs and SourceRanges
Swift SVN r6994
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user