aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Basic/SourceManager.h
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-04-14 21:04:18 +0000
committerTed Kremenek <kremenek@apple.com>2008-04-14 21:04:18 +0000
commit9fd87b1db485e2f31d0e5687f9168b370d546847 (patch)
treed1570b1589af3dbcfcdf2a608350d3a7c81ef3ca /include/clang/Basic/SourceManager.h
parent70778c85825a00170c8c70ae351252743463d8dd (diff)
Added "getCanonicalID()", "isFromSameFile", and "isFromMainFile" to compare
the files of different SourceLocations. These methods correctly handle the case where a file may have multiple FileIDs due to it being large enough to be spread across several chunks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49682 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r--include/clang/Basic/SourceManager.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h
index 59f1690778..700dcd31ac 100644
--- a/include/clang/Basic/SourceManager.h
+++ b/include/clang/Basic/SourceManager.h
@@ -371,7 +371,15 @@ public:
const FileEntry* getFileEntryForID(unsigned id) const {
return getContentCache(id)->Entry;
}
-
+
+ /// getCanonicalFileID - Return the canonical FileID for a SourceLocation.
+ /// A file can have multiple FileIDs if it is large enough to be broken
+ /// into multiple chunks. This method returns the unique FileID without
+ /// chunk information for a given SourceLocation. Use this method when
+ /// you want to compare FileIDs across SourceLocations.
+ unsigned getCanonicalFileID(SourceLocation PhysLoc) const {
+ return getDecomposedFileLoc(PhysLoc).first;
+ }
/// getDecomposedFileLoc - Decompose the specified file location into a raw
/// FileID + Offset pair. The first element is the FileID, the second is the
@@ -399,6 +407,18 @@ public:
return getDecomposedFileLoc(PhysLoc).second;
}
+ /// isFromSameFile - Returns true if both SourceLocations correspond to
+ /// the same file.
+ bool isFromSameFile(SourceLocation Loc1, SourceLocation Loc2) const {
+ return getCanonicalFileID(Loc1) == getCanonicalFileID(Loc2);
+ }
+
+ /// isFromMainFile - Returns true if the file of provided SourceLocation is
+ /// the main file.
+ bool isFromMainFile(SourceLocation Loc) const {
+ return getCanonicalFileID(Loc) == getMainFileID();
+ }
+
/// PrintStats - Print statistics to stderr.
///
void PrintStats() const;