[cfe-commits] r42931 - /cfe/trunk/include/clang/Basic/SourceManager.h
Chris Lattner
sabre at nondot.org
Fri Oct 12 13:24:19 PDT 2007
Author: lattner
Date: Fri Oct 12 15:24:19 2007
New Revision: 42931
URL: http://llvm.org/viewvc/llvm-project?rev=42931&view=rev
Log:
add a new SM::getDecomposedFileLoc method.
Modified:
cfe/trunk/include/clang/Basic/SourceManager.h
Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=42931&r1=42930&r2=42931&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Fri Oct 12 15:24:19 2007
@@ -275,6 +275,24 @@
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 @@
/// 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;
}
};
More information about the cfe-commits
mailing list