diff options
Diffstat (limited to 'lib/Basic/SourceManager.cpp')
-rw-r--r-- | lib/Basic/SourceManager.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index ce8aa5d112..1b139c6552 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -1,9 +1,8 @@ //===- SourceManager.cpp - Track and cache source files -------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -70,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(); } @@ -83,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); @@ -96,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) { @@ -424,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>(); @@ -619,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); @@ -676,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; @@ -1106,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); @@ -1118,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; @@ -1203,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; @@ -1721,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; |