Skip to content

Commit

Permalink
Frontend: Migrate to FileEntryRef in CompilerInstance::InitializeSour…
Browse files Browse the repository at this point in the history
…ceManager, NFC

Use `FileManager::getVirtualFileRef` to get the virtual file for stdin,
and add an overload of `SourceManager::overrideFileContents` that takes
a `FileEntryRef`, migrating `CompilerInstance::InitializeSourceManager`.

Differential Revision: https://reviews.llvm.org/D92680
  • Loading branch information
dexonsmith committed Dec 9, 2020
1 parent 8b23b3a commit a5c89bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/SourceManager.h
Expand Up @@ -958,6 +958,10 @@ class SourceManager : public RefCountedBase<SourceManager> {
/// data in the given source file.
void overrideFileContents(const FileEntry *SourceFile,
std::unique_ptr<llvm::MemoryBuffer> Buffer);
void overrideFileContents(FileEntryRef SourceFile,
std::unique_ptr<llvm::MemoryBuffer> Buffer) {
overrideFileContents(&SourceFile.getFileEntry(), std::move(Buffer));
}

/// Override the given source file with another one.
///
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Frontend/CompilerInstance.cpp
Expand Up @@ -891,8 +891,8 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
}
std::unique_ptr<llvm::MemoryBuffer> SB = std::move(SBOrErr.get());

const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
FileEntryRef File = FileMgr.getVirtualFileRef(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
SourceMgr.setMainFileID(
SourceMgr.createFileID(File, SourceLocation(), Kind));
SourceMgr.overrideFileContents(File, std::move(SB));
Expand Down

0 comments on commit a5c89bb

Please sign in to comment.