forked from OSchip/llvm-project
clang/Basic: Remove ContentCache::getRawBuffer, NFC
Replace `ContentCache::getRawBuffer` with `getBufferDataIfLoaded` and `getBufferIfLoaded`, excising another accessor for the underlying `MemoryBuffer*` in favour of `StringRef` and `MemoryBufferRef`. Differential Revision: https://reviews.llvm.org/D89445
This commit is contained in:
parent
b9eecbfada
commit
156e8b3702
|
@ -30,12 +30,12 @@ public:
|
|||
return;
|
||||
|
||||
// FIXME: Why is this happening? We might be losing contents here.
|
||||
if (!ContentCache.getRawBuffer())
|
||||
llvm::Optional<StringRef> Data = ContentCache.getBufferDataIfLoaded();
|
||||
if (!Data)
|
||||
return;
|
||||
|
||||
InMemoryFs.addFile(File->getName(), /*ModificationTime=*/0,
|
||||
llvm::MemoryBuffer::getMemBufferCopy(
|
||||
ContentCache.getRawBuffer()->getBuffer()));
|
||||
llvm::MemoryBuffer::getMemBufferCopy(*Data));
|
||||
// Remove the file from the set of necessary files.
|
||||
FilesToRecord.erase(File);
|
||||
}
|
||||
|
|
|
@ -194,9 +194,23 @@ namespace SrcMgr {
|
|||
/// this content cache. This is used for performance analysis.
|
||||
llvm::MemoryBuffer::BufferKind getMemoryBufferKind() const;
|
||||
|
||||
/// Get the underlying buffer, returning NULL if the buffer is not
|
||||
/// yet available.
|
||||
const llvm::MemoryBuffer *getRawBuffer() const { return Buffer.get(); }
|
||||
/// Return the buffer, only if it has been loaded.
|
||||
/// specified FileID, returning None if it's not yet loaded.
|
||||
///
|
||||
/// \param FID The file ID whose contents will be returned.
|
||||
llvm::Optional<llvm::MemoryBufferRef> getBufferIfLoaded() const {
|
||||
if (Buffer)
|
||||
return Buffer->getMemBufferRef();
|
||||
return None;
|
||||
}
|
||||
|
||||
/// Return a StringRef to the source buffer data, only if it has already
|
||||
/// been loaded.
|
||||
llvm::Optional<StringRef> getBufferDataIfLoaded() const {
|
||||
if (Buffer)
|
||||
return Buffer->getBuffer();
|
||||
return None;
|
||||
}
|
||||
|
||||
/// Set the buffer.
|
||||
void setBuffer(std::unique_ptr<llvm::MemoryBuffer> B) {
|
||||
|
@ -207,10 +221,10 @@ namespace SrcMgr {
|
|||
/// Set the buffer to one that's not owned (or to nullptr).
|
||||
///
|
||||
/// \pre Buffer cannot already be set.
|
||||
void setUnownedBuffer(const llvm::MemoryBuffer *B) {
|
||||
void setUnownedBuffer(llvm::Optional<llvm::MemoryBufferRef> B) {
|
||||
assert(!Buffer && "Expected to be called right after construction");
|
||||
if (B)
|
||||
setBuffer(llvm::MemoryBuffer::getMemBuffer(B->getMemBufferRef()));
|
||||
setBuffer(llvm::MemoryBuffer::getMemBuffer(*B));
|
||||
}
|
||||
|
||||
// If BufStr has an invalid BOM, returns the BOM name; otherwise, returns
|
||||
|
|
|
@ -155,7 +155,7 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
|
|||
|
||||
// Check that the file's size is the same as in the file entry (which may
|
||||
// have come from a stat cache).
|
||||
if (getRawBuffer()->getBufferSize() != (size_t)ContentsEntry->getSize()) {
|
||||
if (Buffer->getBufferSize() != (size_t)ContentsEntry->getSize()) {
|
||||
if (Diag.isDiagnosticInFlight())
|
||||
Diag.SetDelayedDiagnostic(diag::err_file_modified,
|
||||
ContentsEntry->getName());
|
||||
|
@ -363,7 +363,7 @@ void SourceManager::initializeForReplay(const SourceManager &Old) {
|
|||
Clone->BufferOverridden = Cache->BufferOverridden;
|
||||
Clone->IsFileVolatile = Cache->IsFileVolatile;
|
||||
Clone->IsTransient = Cache->IsTransient;
|
||||
Clone->setUnownedBuffer(Cache->getRawBuffer());
|
||||
Clone->setUnownedBuffer(Cache->getBufferIfLoaded());
|
||||
return Clone;
|
||||
};
|
||||
|
||||
|
@ -476,7 +476,8 @@ const SrcMgr::ContentCache *
|
|||
SourceManager::getFakeContentCacheForRecovery() const {
|
||||
if (!FakeContentCacheForRecovery) {
|
||||
FakeContentCacheForRecovery = std::make_unique<SrcMgr::ContentCache>();
|
||||
FakeContentCacheForRecovery->setUnownedBuffer(getFakeBufferForRecovery());
|
||||
FakeContentCacheForRecovery->setUnownedBuffer(
|
||||
getFakeBufferForRecovery()->getMemBufferRef());
|
||||
}
|
||||
return FakeContentCacheForRecovery.get();
|
||||
}
|
||||
|
@ -751,10 +752,7 @@ SourceManager::getBufferDataIfLoaded(FileID FID) const {
|
|||
if (!SLoc.isFile() || MyInvalid)
|
||||
return None;
|
||||
|
||||
if (const llvm::MemoryBuffer *Buf =
|
||||
SLoc.getFile().getContentCache()->getRawBuffer())
|
||||
return Buf->getBuffer();
|
||||
return None;
|
||||
return SLoc.getFile().getContentCache()->getBufferDataIfLoaded();
|
||||
}
|
||||
|
||||
llvm::Optional<StringRef> SourceManager::getBufferDataOrNone(FileID FID) const {
|
||||
|
|
|
@ -1542,7 +1542,7 @@ bool ASTReader::ReadSLocEntry(int ID) {
|
|||
= SourceMgr.getOrCreateContentCache(File, isSystem(FileCharacter));
|
||||
if (OverriddenBuffer && !ContentCache->BufferOverridden &&
|
||||
ContentCache->ContentsEntry == ContentCache->OrigEntry &&
|
||||
!ContentCache->getRawBuffer()) {
|
||||
!ContentCache->getBufferIfLoaded()) {
|
||||
auto Buffer = ReadBuffer(SLocEntryCursor, File->getName());
|
||||
if (!Buffer)
|
||||
return true;
|
||||
|
|
|
@ -1468,7 +1468,7 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
|
|||
if (PP->getHeaderSearchInfo()
|
||||
.getHeaderSearchOpts()
|
||||
.ValidateASTInputFilesContent) {
|
||||
auto *MemBuff = Cache->getRawBuffer();
|
||||
auto MemBuff = Cache->getBufferIfLoaded();
|
||||
if (MemBuff)
|
||||
ContentHash = hash_value(MemBuff->getBuffer());
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue