diff options
| author | Ted Kremenek <kremenek@apple.com> | 2008-04-14 21:04:18 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2008-04-14 21:04:18 +0000 |
| commit | 17acadebb493ea4a1227d18a87abf8a56953b205 (patch) | |
| tree | 8ef10f54ea82ccf3d382f5f45b67e9fdfe1e49e7 | |
| parent | 4fff979a434199b1f842fb04f4c5faf5390fffda (diff) | |
| download | bcm5719-llvm-17acadebb493ea4a1227d18a87abf8a56953b205.tar.gz bcm5719-llvm-17acadebb493ea4a1227d18a87abf8a56953b205.zip | |
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.
llvm-svn: 49682
| -rw-r--r-- | clang/include/clang/Basic/SourceLocation.h | 2 | ||||
| -rw-r--r-- | clang/include/clang/Basic/SourceManager.h | 22 | ||||
| -rw-r--r-- | clang/lib/Basic/SourceLocation.cpp | 4 |
3 files changed, 27 insertions, 1 deletions
diff --git a/clang/include/clang/Basic/SourceLocation.h b/clang/include/clang/Basic/SourceLocation.h index 83633ebf856..6bc45057d54 100644 --- a/clang/include/clang/Basic/SourceLocation.h +++ b/clang/include/clang/Basic/SourceLocation.h @@ -249,6 +249,8 @@ public: bool isFileID() const { return Loc.isFileID(); } + unsigned getCanonicalFileID() const; + bool operator==(const FullSourceLoc& RHS) const { return SrcMgr == RHS.SrcMgr && Loc == RHS.Loc; } diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 59f16907783..700dcd31acc 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/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; diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp index c01447567fb..83c264ad0b0 100644 --- a/clang/lib/Basic/SourceLocation.cpp +++ b/clang/lib/Basic/SourceLocation.cpp @@ -88,3 +88,7 @@ const llvm::MemoryBuffer* FullSourceLoc::getBuffer() const { assert (isValid()); return SrcMgr->getBuffer(Loc.getFileID()); } + +unsigned FullSourceLoc::getCanonicalFileID() const { + return SrcMgr->getCanonicalFileID(Loc); +} |

