diff options
author | Nico Weber <nicolasweber@gmx.de> | 2019-04-04 21:06:41 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2019-04-04 21:06:41 +0000 |
commit | 04347d848d270737b183060b2ba488eef84d3a16 (patch) | |
tree | ffaf4b92f3c7f02498e4b188ecd4476a566f62e9 /clang/lib/Basic/SourceManager.cpp | |
parent | ce2b61b2994bb08d3c45b958894ebff1ad4929f3 (diff) | |
download | llvm-04347d848d270737b183060b2ba488eef84d3a16.zip llvm-04347d848d270737b183060b2ba488eef84d3a16.tar.gz llvm-04347d848d270737b183060b2ba488eef84d3a16.tar.bz2 |
Make SourceManager::createFileID(UnownedTag, ...) take a const llvm::MemoryBuffer*
Requires making the llvm::MemoryBuffer* stored by SourceManager const,
which in turn requires making the accessors for that return const
llvm::MemoryBuffer*s and updating all call sites.
The original motivation for this was to use it and fix the TODO in
CodeGenAction.cpp's ConvertBackendLocation() by using the UnownedTag
version of createFileID, and since llvm::SourceMgr* hands out a const
llvm::MemoryBuffer* this is required. I'm not sure if fixing the TODO
this way actually works, but this seems like a good change on its own
anyways.
No intended behavior change.
Differential Revision: https://reviews.llvm.org/D60247
llvm-svn: 357724
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 57b0bbd..1b139c6 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -69,7 +69,7 @@ llvm::MemoryBuffer::BufferKind ContentCache::getMemoryBufferKind() const { if (!Buffer.getPointer()) return llvm::MemoryBuffer::MemoryBuffer_Malloc; - llvm::MemoryBuffer *buf = Buffer.getPointer(); + const llvm::MemoryBuffer *buf = Buffer.getPointer(); return buf->getBufferKind(); } @@ -82,7 +82,7 @@ unsigned ContentCache::getSize() const { : (unsigned) ContentsEntry->getSize(); } -void ContentCache::replaceBuffer(llvm::MemoryBuffer *B, bool DoNotFree) { +void ContentCache::replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree) { if (B && B == Buffer.getPointer()) { assert(0 && "Replacing with the same buffer"); Buffer.setInt(DoNotFree? DoNotFreeFlag : 0); @@ -95,10 +95,10 @@ void ContentCache::replaceBuffer(llvm::MemoryBuffer *B, bool DoNotFree) { Buffer.setInt((B && DoNotFree) ? DoNotFreeFlag : 0); } -llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag, - const SourceManager &SM, - SourceLocation Loc, - bool *Invalid) const { +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) { @@ -423,7 +423,7 @@ SourceManager::getOrCreateContentCache(const FileEntry *FileEnt, /// Create a new ContentCache for the specified memory buffer. /// This does no caching. const ContentCache * -SourceManager::createMemBufferContentCache(llvm::MemoryBuffer *Buffer, +SourceManager::createMemBufferContentCache(const llvm::MemoryBuffer *Buffer, bool DoNotFree) { // Add a new ContentCache to the MemBufferInfos list and return it. ContentCache *Entry = ContentCacheAlloc.Allocate<ContentCache>(); @@ -618,8 +618,8 @@ SourceManager::createExpansionLocImpl(const ExpansionInfo &Info, return SourceLocation::getMacroLoc(NextLocalOffset - (TokLength + 1)); } -llvm::MemoryBuffer *SourceManager::getMemoryBufferForFile(const FileEntry *File, - bool *Invalid) { +const 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); @@ -675,7 +675,7 @@ StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const { return "<<<<<INVALID SOURCE LOCATION>>>>>"; } - llvm::MemoryBuffer *Buf = SLoc.getFile().getContentCache()->getBuffer( + const llvm::MemoryBuffer *Buf = SLoc.getFile().getContentCache()->getBuffer( Diag, *this, SourceLocation(), &MyInvalid); if (Invalid) *Invalid = MyInvalid; @@ -1105,8 +1105,9 @@ const char *SourceManager::getCharacterData(SourceLocation SL, return "<<<<INVALID BUFFER>>>>"; } - llvm::MemoryBuffer *Buffer = Entry.getFile().getContentCache()->getBuffer( - Diag, *this, SourceLocation(), &CharDataInvalid); + const llvm::MemoryBuffer *Buffer = + Entry.getFile().getContentCache()->getBuffer( + Diag, *this, SourceLocation(), &CharDataInvalid); if (Invalid) *Invalid = CharDataInvalid; return Buffer->getBufferStart() + (CharDataInvalid? 0 : LocInfo.second); @@ -1117,7 +1118,7 @@ const char *SourceManager::getCharacterData(SourceLocation SL, unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid) const { bool MyInvalid = false; - llvm::MemoryBuffer *MemBuf = getBuffer(FID, &MyInvalid); + const llvm::MemoryBuffer *MemBuf = getBuffer(FID, &MyInvalid); if (Invalid) *Invalid = MyInvalid; @@ -1202,7 +1203,8 @@ 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. - MemoryBuffer *Buffer = FI->getBuffer(Diag, SM, SourceLocation(), &Invalid); + const MemoryBuffer *Buffer = + FI->getBuffer(Diag, SM, SourceLocation(), &Invalid); if (Invalid) return; @@ -1720,7 +1722,7 @@ SourceLocation SourceManager::translateLineCol(FileID FID, return FileLoc.getLocWithOffset(Size); } - llvm::MemoryBuffer *Buffer = Content->getBuffer(Diag, *this); + const llvm::MemoryBuffer *Buffer = Content->getBuffer(Diag, *this); unsigned FilePos = Content->SourceLineCache[Line - 1]; const char *Buf = Buffer->getBufferStart() + FilePos; unsigned BufLength = Buffer->getBufferSize() - FilePos; |