aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Basic/SourceLocation.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-10-16 21:07:07 +0000
committerChris Lattner <sabre@nondot.org>2007-10-16 21:07:07 +0000
commit2c64b7b9381be4ff62fbdc404ed3f14c8086898d (patch)
treea4dd4a59b52807e30f844438f9a7957490a77de4 /include/clang/Basic/SourceLocation.h
parent10864b47250df7ae039fe9932bdf7a5b0c21280e (diff)
Push the rewriter forward a bit more. Now it rewrites
#import to #include's as a test. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43041 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceLocation.h')
-rw-r--r--include/clang/Basic/SourceLocation.h19
1 files changed, 14 insertions, 5 deletions
diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h
index 420d5012f0..1ebb0ff3f8 100644
--- a/include/clang/Basic/SourceLocation.h
+++ b/include/clang/Basic/SourceLocation.h
@@ -30,7 +30,9 @@ public:
MacroIDBits = 20,
MacroPhysOffsBits = 9,
- MacroLogOffBits = 2
+ MacroLogOffBits = 2,
+
+ ChunkSize = (1 << FilePosBits)
};
SourceLocation() : ID(0) {} // 0 is an invalid FileID.
@@ -42,9 +44,9 @@ public:
SourceLocation L;
// If a FilePos is larger than (1<<FilePosBits), the SourceManager makes
// enough consequtive FileIDs that we have one for each chunk.
- if (FilePos >= (1 << FilePosBits)) {
+ if (FilePos >= ChunkSize) {
FileID += FilePos >> FilePosBits;
- FilePos &= (1 << FilePosBits)-1;
+ FilePos &= ChunkSize-1;
}
// FIXME: Find a way to handle out of FileID bits! Maybe MaxFileID is an
@@ -98,7 +100,7 @@ public:
/// SourceManager::getFilePos. This method will be incorrect for large files.
unsigned getRawFilePos() const {
assert(isFileID() && "can't get the file id of a non-file sloc!");
- return ID & ((1 << FilePosBits)-1);
+ return ID & (ChunkSize-1);
}
unsigned getMacroID() const {
@@ -122,7 +124,14 @@ public:
/// getFileLocWithOffset - Return a source location with the specified offset
/// from this file SourceLocation.
SourceLocation getFileLocWithOffset(int Offset) const {
- return getFileLoc(getFileID(), getRawFilePos()+Offset);
+ unsigned FileID = getFileID();
+ Offset += getRawFilePos();
+ // Handle negative offsets correctly.
+ while (Offset < 0) {
+ --FileID;
+ Offset += ChunkSize;
+ }
+ return getFileLoc(FileID, Offset);
}
/// getRawEncoding - When a SourceLocation itself cannot be used, this returns