forked from OSchip/llvm-project
clang/Basic: Replace SourceManager::getMemoryBufferForFile, NFC
Replace `SourceManager::getMemoryBufferForFile`, which returned a dereferenceable `MemoryBuffer*` and had a `bool*Invalid` out parameter, with `getMemoryBufferForFileOrNone` (returning `Optional<MemoryBufferRef>`) and `getMemoryBufferForFileOrFake` (returning `MemoryBufferRef`). Differential Revision: https://reviews.llvm.org/D89429
This commit is contained in:
parent
e557b6a66d
commit
2dc7e0c6a5
|
@ -901,10 +901,18 @@ public:
|
|||
|
||||
/// Retrieve the memory buffer associated with the given file.
|
||||
///
|
||||
/// \param Invalid If non-NULL, will be set \c true if an error
|
||||
/// occurs while retrieving the memory buffer.
|
||||
const llvm::MemoryBuffer *getMemoryBufferForFile(const FileEntry *File,
|
||||
bool *Invalid = nullptr);
|
||||
/// Returns None if the buffer is not valid.
|
||||
llvm::Optional<llvm::MemoryBufferRef>
|
||||
getMemoryBufferForFileOrNone(const FileEntry *File);
|
||||
|
||||
/// Retrieve the memory buffer associated with the given file.
|
||||
///
|
||||
/// Returns a fake buffer if there isn't a real one.
|
||||
llvm::MemoryBufferRef getMemoryBufferForFileOrFake(const FileEntry *File) {
|
||||
if (auto B = getMemoryBufferForFileOrNone(File))
|
||||
return *B;
|
||||
return getFakeBufferForRecovery()->getMemBufferRef();
|
||||
}
|
||||
|
||||
/// Override the contents of the given source file by providing an
|
||||
/// already-allocated buffer.
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
namespace llvm {
|
||||
class MemoryBuffer;
|
||||
class MemoryBufferRef;
|
||||
namespace vfs {
|
||||
class FileSystem;
|
||||
}
|
||||
|
@ -216,7 +217,7 @@ private:
|
|||
|
||||
static PreambleFileHash createForFile(off_t Size, time_t ModTime);
|
||||
static PreambleFileHash
|
||||
createForMemoryBuffer(const llvm::MemoryBuffer *Buffer);
|
||||
createForMemoryBuffer(const llvm::MemoryBufferRef &Buffer);
|
||||
|
||||
friend bool operator==(const PreambleFileHash &LHS,
|
||||
const PreambleFileHash &RHS) {
|
||||
|
|
|
@ -701,14 +701,11 @@ SourceManager::createExpansionLocImpl(const ExpansionInfo &Info,
|
|||
return SourceLocation::getMacroLoc(NextLocalOffset - (TokLength + 1));
|
||||
}
|
||||
|
||||
const llvm::MemoryBuffer *
|
||||
SourceManager::getMemoryBufferForFile(const FileEntry *File, bool *Invalid) {
|
||||
llvm::Optional<llvm::MemoryBufferRef>
|
||||
SourceManager::getMemoryBufferForFileOrNone(const FileEntry *File) {
|
||||
const SrcMgr::ContentCache *IR = getOrCreateContentCache(File);
|
||||
assert(IR && "getOrCreateContentCache() cannot return NULL");
|
||||
auto *B = IR->getBufferPointer(Diag, getFileManager(), SourceLocation());
|
||||
if (Invalid)
|
||||
*Invalid = !B;
|
||||
return B ? B : getFakeBufferForRecovery();
|
||||
return IR->getBufferOrNone(Diag, getFileManager(), SourceLocation());
|
||||
}
|
||||
|
||||
void SourceManager::overrideFileContents(const FileEntry *SourceFile,
|
||||
|
|
|
@ -463,7 +463,8 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
|
|||
PrecompiledPreamble::PreambleFileHash::createForFile(File->getSize(),
|
||||
ModTime);
|
||||
} else {
|
||||
const llvm::MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File);
|
||||
llvm::MemoryBufferRef Buffer =
|
||||
SourceMgr.getMemoryBufferForFileOrFake(File);
|
||||
FilesInPreamble[File->getName()] =
|
||||
PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer(Buffer);
|
||||
}
|
||||
|
@ -549,7 +550,7 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation,
|
|||
llvm::StringMap<PreambleFileHash> OverridenFileBuffers;
|
||||
for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) {
|
||||
const PrecompiledPreamble::PreambleFileHash PreambleHash =
|
||||
PreambleFileHash::createForMemoryBuffer(RB.second);
|
||||
PreambleFileHash::createForMemoryBuffer(RB.second->getMemBufferRef());
|
||||
llvm::vfs::Status Status;
|
||||
if (moveOnNoError(VFS->status(RB.first), Status))
|
||||
OverriddenFiles[Status.getUniqueID()] = PreambleHash;
|
||||
|
@ -783,13 +784,13 @@ PrecompiledPreamble::PreambleFileHash::createForFile(off_t Size,
|
|||
|
||||
PrecompiledPreamble::PreambleFileHash
|
||||
PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer(
|
||||
const llvm::MemoryBuffer *Buffer) {
|
||||
const llvm::MemoryBufferRef &Buffer) {
|
||||
PreambleFileHash Result;
|
||||
Result.Size = Buffer->getBufferSize();
|
||||
Result.Size = Buffer.getBufferSize();
|
||||
Result.ModTime = 0;
|
||||
|
||||
llvm::MD5 MD5Ctx;
|
||||
MD5Ctx.update(Buffer->getBuffer().data());
|
||||
MD5Ctx.update(Buffer.getBuffer().data());
|
||||
MD5Ctx.final(Result.MD5);
|
||||
|
||||
return Result;
|
||||
|
|
|
@ -395,12 +395,10 @@ bool Preprocessor::SetCodeCompletionPoint(const FileEntry *File,
|
|||
assert(CompleteLine && CompleteColumn && "Starts from 1:1");
|
||||
assert(!CodeCompletionFile && "Already set");
|
||||
|
||||
using llvm::MemoryBuffer;
|
||||
|
||||
// Load the actual file's contents.
|
||||
bool Invalid = false;
|
||||
const MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File, &Invalid);
|
||||
if (Invalid)
|
||||
Optional<llvm::MemoryBufferRef> Buffer =
|
||||
SourceMgr.getMemoryBufferForFileOrNone(File);
|
||||
if (!Buffer)
|
||||
return true;
|
||||
|
||||
// Find the byte position of the truncation point.
|
||||
|
|
Loading…
Reference in New Issue