summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-10-12 20:24:19 +0000
committerChris Lattner <sabre@nondot.org>2007-10-12 20:24:19 +0000
commit2c06f7ea45843eade8e5428cf13833dc7cd9c242 (patch)
tree122de5d370c020cfaf73506fbed65c998ccd715d /clang
parent371e6ca690a4b6f2fc95d1721dfd29b9fc6cee2b (diff)
downloadbcm5719-llvm-2c06f7ea45843eade8e5428cf13833dc7cd9c242.tar.gz
bcm5719-llvm-2c06f7ea45843eade8e5428cf13833dc7cd9c242.zip
add a new SM::getDecomposedFileLoc method.
llvm-svn: 42931
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/SourceManager.h26
1 files changed, 19 insertions, 7 deletions
diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index 901010b9470..ba731589d63 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -275,6 +275,24 @@ public:
return FileIDs[FileID-1].getInfo()->first;
}
+ /// getDecomposedFileLoc - Decompose the specified file location into a raw
+ /// FileID + Offset pair. The first element is the FileID, the second is the
+ /// offset from the start of the buffer of the location.
+ std::pair<unsigned, unsigned> getDecomposedFileLoc(SourceLocation Loc) const {
+ assert(Loc.isFileID() && "Isn't a File SourceLocation");
+
+ // TODO: Add a flag "is first chunk" to SLOC.
+ const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(Loc.getFileID());
+
+ // If this file has been split up into chunks, factor in the chunk number
+ // that the FileID references.
+ unsigned ChunkNo = FIDInfo->getChunkNo();
+ unsigned Offset = Loc.getRawFilePos();
+ Offset += (ChunkNo << SourceLocation::FilePosBits);
+
+ return std::pair<unsigned,unsigned>(Loc.getFileID()-ChunkNo, Offset);
+ }
+
/// PrintStats - Print statistics to stderr.
///
void PrintStats() const;
@@ -319,13 +337,7 @@ private:
/// returns the location of the physical character data, not the logical file
/// position.
unsigned getFullFilePos(SourceLocation PhysLoc) const {
- // TODO: Add a flag "is first chunk" to SLOC.
- const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(PhysLoc.getFileID());
-
- // If this file has been split up into chunks, factor in the chunk number
- // that the FileID references.
- unsigned ChunkNo = FIDInfo->getChunkNo();
- return PhysLoc.getRawFilePos() + (ChunkNo << SourceLocation::FilePosBits);
+ return getDecomposedFileLoc(PhysLoc).second;
}
};
OpenPOWER on IntegriCloud