diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-06-27 17:40:03 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-06-27 17:40:03 +0000 |
commit | 66cc07b4f72ca630846395dbbc60ebee7a5e0104 (patch) | |
tree | b02668e8a7183333470bc5e34ff591e347e54f5c /clang/lib/Basic/SourceManager.cpp | |
parent | 6c75b3a3c0a8350dd15181e9824d6d76e689ec3a (diff) | |
download | bcm5719-llvm-66cc07b4f72ca630846395dbbc60ebee7a5e0104.tar.gz bcm5719-llvm-66cc07b4f72ca630846395dbbc60ebee7a5e0104.zip |
Remove 'const' from MemoryBuffers used through the SourceManager
This removes a const_cast added in r211884 that occurred due to an
inconsistency in how MemoryBuffers are handled between some parts of
clang and LLVM.
MemoryBuffers are immutable and the general convention in the LLVM
project is to omit const from immutable types as it's simply
redundant/verbose (see llvm::Type, for example). While this change
doesn't remove "const" from /every/ MemoryBuffer, it at least makes this
chain of ownership/usage consistent.
llvm-svn: 211915
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index d2d556288d6..5d36f6c8a04 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -55,8 +55,8 @@ llvm::MemoryBuffer::BufferKind ContentCache::getMemoryBufferKind() const { // Should be unreachable, but keep for sanity. if (!Buffer.getPointer()) return llvm::MemoryBuffer::MemoryBuffer_Malloc; - - const llvm::MemoryBuffer *buf = Buffer.getPointer(); + + llvm::MemoryBuffer *buf = Buffer.getPointer(); return buf->getBufferKind(); } @@ -69,8 +69,7 @@ unsigned ContentCache::getSize() const { : (unsigned) ContentsEntry->getSize(); } -void ContentCache::replaceBuffer(const llvm::MemoryBuffer *B, - bool DoNotFree) { +void ContentCache::replaceBuffer(llvm::MemoryBuffer *B, bool DoNotFree) { if (B && B == Buffer.getPointer()) { assert(0 && "Replacing with the same buffer"); Buffer.setInt(DoNotFree? DoNotFreeFlag : 0); @@ -83,10 +82,10 @@ void ContentCache::replaceBuffer(const llvm::MemoryBuffer *B, Buffer.setInt(DoNotFree? DoNotFreeFlag : 0); } -const llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag, - const SourceManager &SM, - SourceLocation Loc, - bool *Invalid) const { +llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag, + const SourceManager &SM, + SourceLocation Loc, + bool *Invalid) const { // Lazily create the Buffer for ContentCaches that wrap files. If we already // computed it, just return what we have. if (Buffer.getPointer() || !ContentsEntry) { @@ -462,8 +461,8 @@ SourceManager::getOrCreateContentCache(const FileEntry *FileEnt, /// createMemBufferContentCache - Create a new ContentCache for the specified /// memory buffer. This does no caching. -const ContentCache* -SourceManager::createMemBufferContentCache(const MemoryBuffer *Buffer) { +const ContentCache * +SourceManager::createMemBufferContentCache(llvm::MemoryBuffer *Buffer) { // Add a new ContentCache to the MemBufferInfos list and return it. ContentCache *Entry = ContentCacheAlloc.Allocate<ContentCache>(); new (Entry) ContentCache(); @@ -505,7 +504,7 @@ SourceManager::AllocateLoadedSLocEntries(unsigned NumSLocEntries, /// \brief As part of recovering from missing or changed content, produce a /// fake, non-empty buffer. -const llvm::MemoryBuffer *SourceManager::getFakeBufferForRecovery() const { +llvm::MemoryBuffer *SourceManager::getFakeBufferForRecovery() const { if (!FakeBufferForRecovery) FakeBufferForRecovery = llvm::MemoryBuffer::getMemBuffer("<<<INVALID BUFFER>>"); @@ -644,16 +643,15 @@ SourceManager::createExpansionLocImpl(const ExpansionInfo &Info, return SourceLocation::getMacroLoc(NextLocalOffset - (TokLength + 1)); } -const llvm::MemoryBuffer * -SourceManager::getMemoryBufferForFile(const FileEntry *File, - bool *Invalid) { +llvm::MemoryBuffer *SourceManager::getMemoryBufferForFile(const FileEntry *File, + bool *Invalid) { const SrcMgr::ContentCache *IR = getOrCreateContentCache(File); assert(IR && "getOrCreateContentCache() cannot return NULL"); return IR->getBuffer(Diag, *this, SourceLocation(), Invalid); } void SourceManager::overrideFileContents(const FileEntry *SourceFile, - const llvm::MemoryBuffer *Buffer, + llvm::MemoryBuffer *Buffer, bool DoNotFree) { const SrcMgr::ContentCache *IR = getOrCreateContentCache(SourceFile); assert(IR && "getOrCreateContentCache() cannot return NULL"); @@ -696,10 +694,9 @@ StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const { *Invalid = true; return "<<<<<INVALID SOURCE LOCATION>>>>>"; } - - const llvm::MemoryBuffer *Buf - = SLoc.getFile().getContentCache()->getBuffer(Diag, *this, SourceLocation(), - &MyInvalid); + + llvm::MemoryBuffer *Buf = SLoc.getFile().getContentCache()->getBuffer( + Diag, *this, SourceLocation(), &MyInvalid); if (Invalid) *Invalid = MyInvalid; @@ -1117,9 +1114,8 @@ const char *SourceManager::getCharacterData(SourceLocation SL, return "<<<<INVALID BUFFER>>>>"; } - const llvm::MemoryBuffer *Buffer - = Entry.getFile().getContentCache() - ->getBuffer(Diag, *this, SourceLocation(), &CharDataInvalid); + llvm::MemoryBuffer *Buffer = Entry.getFile().getContentCache()->getBuffer( + Diag, *this, SourceLocation(), &CharDataInvalid); if (Invalid) *Invalid = CharDataInvalid; return Buffer->getBufferStart() + (CharDataInvalid? 0 : LocInfo.second); @@ -1131,7 +1127,7 @@ const char *SourceManager::getCharacterData(SourceLocation SL, unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid) const { bool MyInvalid = false; - const llvm::MemoryBuffer *MemBuf = getBuffer(FID, &MyInvalid); + llvm::MemoryBuffer *MemBuf = getBuffer(FID, &MyInvalid); if (Invalid) *Invalid = MyInvalid; @@ -1205,8 +1201,7 @@ static void ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI, llvm::BumpPtrAllocator &Alloc, const SourceManager &SM, bool &Invalid) { // Note that calling 'getBuffer()' may lazily page in the file. - const MemoryBuffer *Buffer = FI->getBuffer(Diag, SM, SourceLocation(), - &Invalid); + MemoryBuffer *Buffer = FI->getBuffer(Diag, SM, SourceLocation(), &Invalid); if (Invalid) return; @@ -1763,7 +1758,7 @@ SourceLocation SourceManager::translateLineCol(FileID FID, return FileLoc.getLocWithOffset(Size); } - const llvm::MemoryBuffer *Buffer = Content->getBuffer(Diag, *this); + llvm::MemoryBuffer *Buffer = Content->getBuffer(Diag, *this); unsigned FilePos = Content->SourceLineCache[Line - 1]; const char *Buf = Buffer->getBufferStart() + FilePos; unsigned BufLength = Buffer->getBufferSize() - FilePos; |