diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-08-19 22:34:01 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-08-19 22:34:01 +0000 |
commit | 54232ade44d31e98ea83f43ca066128e315dcbda (patch) | |
tree | 31129e143caf9b7718abf23ec9aaa670b8cb999b /include/clang/Basic/SourceManager.h | |
parent | 50bbc165b063155cc23c360deb7b865502e068e2 (diff) |
Refactor common functionality into SourceManager::getFileIDSize, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138127 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 68293a7887..9a1fff7919 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -914,6 +914,25 @@ public: return getFileCharacteristic(Loc) == SrcMgr::C_ExternCSystem; } + /// \brief The size of the SLocEnty that \arg FID represents. + unsigned getFileIDSize(FileID FID) const { + bool Invalid = false; + const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); + if (Invalid) + return 0; + + int ID = FID.ID; + unsigned NextOffset; + if ((ID > 0 && unsigned(ID+1) == local_sloc_entry_size())) + NextOffset = getNextLocalOffset(); + else if (ID+1 == -1) + NextOffset = MaxLoadedOffset; + else + NextOffset = getSLocEntry(FileID::get(ID+1)).getOffset(); + + return NextOffset - Entry.getOffset() - 1; + } + /// \brief Given a specific chunk of a FileID (FileID with offset+length), /// returns true if \arg Loc is inside that chunk and sets relative offset /// (offset of \arg Loc from beginning of chunk) to \arg relativeOffset. @@ -924,21 +943,13 @@ public: if (Loc.isInvalid()) return false; - unsigned start = getSLocEntry(FID).getOffset() + offset; + unsigned FIDOffs = getSLocEntry(FID).getOffset(); + unsigned start = FIDOffs + offset; unsigned end = start + length; -#ifndef NDEBUG // Make sure offset/length describe a chunk inside the given FileID. - unsigned NextOffset; - if (FID.ID == -2) - NextOffset = 1U << 31U; - else if (FID.ID+1 == (int)LocalSLocEntryTable.size()) - NextOffset = getNextLocalOffset(); - else - NextOffset = getSLocEntryByID(FID.ID+1).getOffset(); - assert(start < NextOffset); - assert(end < NextOffset); -#endif + assert(start < FIDOffs + getFileIDSize(FID)); + assert(end <= FIDOffs + getFileIDSize(FID)); if (Loc.getOffset() >= start && Loc.getOffset() < end) { if (relativeOffset) |