[cfe-commits] r138127 - in /cfe/trunk: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Aug 19 15:34:01 PDT 2011
Author: akirtzidis
Date: Fri Aug 19 17:34:01 2011
New Revision: 138127
URL: http://llvm.org/viewvc/llvm-project?rev=138127&view=rev
Log:
Refactor common functionality into SourceManager::getFileIDSize, no functionality change.
Modified:
cfe/trunk/include/clang/Basic/SourceManager.h
cfe/trunk/lib/Basic/SourceManager.cpp
Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=138127&r1=138126&r2=138127&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Fri Aug 19 17:34:01 2011
@@ -914,6 +914,25 @@
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 @@
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)
Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=138127&r1=138126&r2=138127&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Fri Aug 19 17:34:01 2011
@@ -1498,21 +1498,8 @@
// that was lexed.
SourceLocation SpellLoc = Entry.getExpansion().getSpellingLoc();
- unsigned NextOffset;
- if (ID > 0) {
- if (unsigned(ID+1) == local_sloc_entry_size())
- NextOffset = getNextLocalOffset();
- else
- NextOffset = getLocalSLocEntry(ID+1).getOffset();
- } else {
- if (ID+1 == -1)
- NextOffset = MaxLoadedOffset;
- else
- NextOffset = getSLocEntry(FileID::get(ID+1)).getOffset();
- }
- unsigned EntrySize = NextOffset - Entry.getOffset() - 1;
unsigned BeginOffs = SpellLoc.getOffset();
- unsigned EndOffs = BeginOffs + EntrySize;
+ unsigned EndOffs = BeginOffs + getFileIDSize(FileID::get(ID));
if (BeginOffs <= Loc.getOffset() && Loc.getOffset() < EndOffs) {
SourceLocation ExpandLoc = SourceLocation::getMacroLoc(Entry.getOffset());
// Replace current Loc with the expanded location and continue.
More information about the cfe-commits
mailing list