Skip to content

Commit 9ae6e6a

Browse files
committed
[clang] NFC: Extract lower-level SourceManager functions
This is a prep-patch for D136624 which allows querying `SourceManager` with raw offsets instead of `SourceLocation`s. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D137215
1 parent 0bfc97e commit 9ae6e6a

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

clang/include/clang/Basic/SourceManager.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,13 +1114,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
11141114
/// the entry in SLocEntryTable which contains the specified location.
11151115
///
11161116
FileID getFileID(SourceLocation SpellingLoc) const {
1117-
SourceLocation::UIntTy SLocOffset = SpellingLoc.getOffset();
1118-
1119-
// If our one-entry cache covers this offset, just return it.
1120-
if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
1121-
return LastFileIDLookup;
1122-
1123-
return getFileIDSlow(SLocOffset);
1117+
return getFileID(SpellingLoc.getOffset());
11241118
}
11251119

11261120
/// Return the filename of the file containing a SourceLocation.
@@ -1747,12 +1741,12 @@ class SourceManager : public RefCountedBase<SourceManager> {
17471741

17481742
/// Returns true if \p Loc came from a PCH/Module.
17491743
bool isLoadedSourceLocation(SourceLocation Loc) const {
1750-
return Loc.getOffset() >= CurrentLoadedOffset;
1744+
return isLoadedOffset(Loc.getOffset());
17511745
}
17521746

17531747
/// Returns true if \p Loc did not come from a PCH/Module.
17541748
bool isLocalSourceLocation(SourceLocation Loc) const {
1755-
return Loc.getOffset() < NextLocalOffset;
1749+
return isLocalOffset(Loc.getOffset());
17561750
}
17571751

17581752
/// Returns true if \p FID came from a PCH/Module.
@@ -1822,6 +1816,22 @@ class SourceManager : public RefCountedBase<SourceManager> {
18221816
return getLoadedSLocEntry(static_cast<unsigned>(-ID - 2), Invalid);
18231817
}
18241818

1819+
FileID getFileID(SourceLocation::UIntTy SLocOffset) const {
1820+
// If our one-entry cache covers this offset, just return it.
1821+
if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
1822+
return LastFileIDLookup;
1823+
1824+
return getFileIDSlow(SLocOffset);
1825+
}
1826+
1827+
bool isLocalOffset(SourceLocation::UIntTy SLocOffset) const {
1828+
return SLocOffset < CurrentLoadedOffset;
1829+
}
1830+
1831+
bool isLoadedOffset(SourceLocation::UIntTy SLocOffset) const {
1832+
return SLocOffset >= CurrentLoadedOffset;
1833+
}
1834+
18251835
/// Implements the common elements of storing an expansion info struct into
18261836
/// the SLocEntry table and producing a source location that refers to it.
18271837
SourceLocation

0 commit comments

Comments
 (0)