diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Basic/CMakeLists.txt | 1 | ||||
-rw-r--r-- | clang/lib/Basic/FileManager.cpp | 86 | ||||
-rw-r--r-- | clang/lib/Basic/FileSystemStatCache.cpp | 44 | ||||
-rw-r--r-- | clang/lib/Basic/VirtualFileSystem.cpp | 193 | ||||
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Frontend/CacheTokens.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Lex/PTHLexer.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Serialization/ModuleManager.cpp | 2 |
10 files changed, 270 insertions, 83 deletions
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt index 43622eb33de..2efe8127b9a 100644 --- a/clang/lib/Basic/CMakeLists.txt +++ b/clang/lib/Basic/CMakeLists.txt @@ -23,6 +23,7 @@ add_clang_library(clangBasic TokenKinds.cpp Version.cpp VersionTuple.cpp + VirtualFileSystem.cpp ) # Determine Subversion revision. diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index af9b2663cbf..08f19fb2006 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -30,19 +30,6 @@ #include <set> #include <string> -// FIXME: This is terrible, we need this for ::close. -#if !defined(_MSC_VER) && !defined(__MINGW32__) -#include <unistd.h> -#include <sys/uio.h> -#else -#include <io.h> -#ifndef S_ISFIFO -#define S_ISFIFO(x) (0) -#endif -#endif -#if defined(LLVM_ON_UNIX) -#include <limits.h> -#endif using namespace clang; // FIXME: Enhance libsystem to support inode and other fields. @@ -57,12 +44,6 @@ using namespace clang; #define NON_EXISTENT_FILE reinterpret_cast<FileEntry*>((intptr_t)-1) -FileEntry::~FileEntry() { - // If this FileEntry owns an open file descriptor that never got used, close - // it. - if (FD != -1) ::close(FD); -} - class FileManager::UniqueDirContainer { /// UniqueDirs - Cache from ID's to existing directories/files. std::map<llvm::sys::fs::UniqueID, DirectoryEntry> UniqueDirs; @@ -101,13 +82,19 @@ public: // Common logic. //===----------------------------------------------------------------------===// -FileManager::FileManager(const FileSystemOptions &FSO) - : FileSystemOpts(FSO), +FileManager::FileManager(const FileSystemOptions &FSO, + IntrusiveRefCntPtr<vfs::FileSystem> FS) + : FS(FS), FileSystemOpts(FSO), UniqueRealDirs(*new UniqueDirContainer()), UniqueRealFiles(*new UniqueFileContainer()), SeenDirEntries(64), SeenFileEntries(64), NextFileUID(0) { NumDirLookups = NumFileLookups = 0; NumDirCacheMisses = NumFileCacheMisses = 0; + + // If the caller doesn't provide a virtual file system, just grab the real + // file system. + if (!FS) + this->FS = vfs::getRealFileSystem(); } FileManager::~FileManager() { @@ -309,10 +296,9 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile, // FIXME: This will reduce the # syscalls. // Nope, there isn't. Check to see if the file exists. - int FileDescriptor = -1; + vfs::File *F = 0; FileData Data; - if (getStatValue(InterndFileName, Data, true, - openFile ? &FileDescriptor : 0)) { + if (getStatValue(InterndFileName, Data, true, openFile ? &F : 0)) { // There's no real file at the given path. if (!CacheFailure) SeenFileEntries.erase(Filename); @@ -320,10 +306,7 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile, return 0; } - if (FileDescriptor != -1 && !openFile) { - close(FileDescriptor); - FileDescriptor = -1; - } + assert(openFile || !F && "undesired open file"); // It exists. See if we have already opened a file with the same inode. // This occurs when one dir is symlinked to another, for example. @@ -333,8 +316,8 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile, NamedFileEnt.setValue(&UFE); if (UFE.getName()) { // Already have an entry with this inode, return it. // If the stat process opened the file, close it to avoid a FD leak. - if (FileDescriptor != -1) - close(FileDescriptor); + if (F) + delete F; return &UFE; } @@ -347,7 +330,7 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile, UFE.ModTime = Data.ModTime; UFE.Dir = DirInfo; UFE.UID = NextFileUID++; - UFE.FD = FileDescriptor; + UFE.File.reset(F); return &UFE; } @@ -393,10 +376,8 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size, // If we had already opened this file, close it now so we don't // leak the descriptor. We're not going to use the file // descriptor anyway, since this is a virtual file. - if (UFE->FD != -1) { - close(UFE->FD); - UFE->FD = -1; - } + if (UFE->File) + UFE->closeFile(); // If we already have an entry with this inode, return it. if (UFE->getName()) @@ -414,7 +395,7 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size, UFE->ModTime = ModificationTime; UFE->Dir = DirInfo; UFE->UID = NextFileUID++; - UFE->FD = -1; + UFE->File.reset(); return UFE; } @@ -444,20 +425,18 @@ getBufferForFile(const FileEntry *Entry, std::string *ErrorStr, const char *Filename = Entry->getName(); // If the file is already open, use the open file descriptor. - if (Entry->FD != -1) { - ec = llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, Result, FileSize); + if (Entry->File) { + ec = Entry->File->getBuffer(Filename, Result, FileSize); if (ErrorStr) *ErrorStr = ec.message(); - - close(Entry->FD); - Entry->FD = -1; + Entry->closeFile(); return Result.take(); } // Otherwise, open the file. if (FileSystemOpts.WorkingDir.empty()) { - ec = llvm::MemoryBuffer::getFile(Filename, Result, FileSize); + ec = FS->getBufferForFile(Filename, Result, FileSize); if (ec && ErrorStr) *ErrorStr = ec.message(); return Result.take(); @@ -465,7 +444,7 @@ getBufferForFile(const FileEntry *Entry, std::string *ErrorStr, SmallString<128> FilePath(Entry->getName()); FixupRelativePath(FilePath); - ec = llvm::MemoryBuffer::getFile(FilePath.str(), Result, FileSize); + ec = FS->getBufferForFile(FilePath.str(), Result, FileSize); if (ec && ErrorStr) *ErrorStr = ec.message(); return Result.take(); @@ -476,7 +455,7 @@ getBufferForFile(StringRef Filename, std::string *ErrorStr) { OwningPtr<llvm::MemoryBuffer> Result; llvm::error_code ec; if (FileSystemOpts.WorkingDir.empty()) { - ec = llvm::MemoryBuffer::getFile(Filename, Result); + ec = FS->getBufferForFile(Filename, Result); if (ec && ErrorStr) *ErrorStr = ec.message(); return Result.take(); @@ -484,7 +463,7 @@ getBufferForFile(StringRef Filename, std::string *ErrorStr) { SmallString<128> FilePath(Filename); FixupRelativePath(FilePath); - ec = llvm::MemoryBuffer::getFile(FilePath.c_str(), Result); + ec = FS->getBufferForFile(FilePath.c_str(), Result); if (ec && ErrorStr) *ErrorStr = ec.message(); return Result.take(); @@ -496,26 +475,29 @@ getBufferForFile(StringRef Filename, std::string *ErrorStr) { /// false if it's an existent real file. If FileDescriptor is NULL, /// do directory look-up instead of file look-up. bool FileManager::getStatValue(const char *Path, FileData &Data, bool isFile, - int *FileDescriptor) { + vfs::File **F) { // FIXME: FileSystemOpts shouldn't be passed in here, all paths should be // absolute! if (FileSystemOpts.WorkingDir.empty()) - return FileSystemStatCache::get(Path, Data, isFile, FileDescriptor, - StatCache.get()); + return FileSystemStatCache::get(Path, Data, isFile, F,StatCache.get(), *FS); SmallString<128> FilePath(Path); FixupRelativePath(FilePath); - return FileSystemStatCache::get(FilePath.c_str(), Data, isFile, - FileDescriptor, StatCache.get()); + return FileSystemStatCache::get(FilePath.c_str(), Data, isFile, F, + StatCache.get(), *FS); } bool FileManager::getNoncachedStatValue(StringRef Path, - llvm::sys::fs::file_status &Result) { + vfs::Status &Result) { SmallString<128> FilePath(Path); FixupRelativePath(FilePath); - return llvm::sys::fs::status(FilePath.c_str(), Result); + llvm::ErrorOr<vfs::Status> S = FS->status(FilePath.c_str()); + if (!S) + return true; + Result = *S; + return false; } void FileManager::invalidateCache(const FileEntry *Entry) { diff --git a/clang/lib/Basic/FileSystemStatCache.cpp b/clang/lib/Basic/FileSystemStatCache.cpp index 7a01bffcd95..b225facbad9 100644 --- a/clang/lib/Basic/FileSystemStatCache.cpp +++ b/clang/lib/Basic/FileSystemStatCache.cpp @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/Basic/FileSystemStatCache.h" -#include "llvm/Support/FileSystem.h" +#include "clang/Basic/VirtualFileSystem.h" #include "llvm/Support/Path.h" // FIXME: This is terrible, we need this for ::close. @@ -30,13 +30,13 @@ using namespace clang; void FileSystemStatCache::anchor() { } -static void copyStatusToFileData(const llvm::sys::fs::file_status &Status, +static void copyStatusToFileData(const vfs::Status &Status, FileData &Data) { Data.Size = Status.getSize(); Data.ModTime = Status.getLastModificationTime().toEpochTime(); Data.UniqueID = Status.getUniqueID(); - Data.IsDirectory = is_directory(Status); - Data.IsNamedPipe = Status.type() == llvm::sys::fs::file_type::fifo_file; + Data.IsDirectory = Status.isDirectory(); + Data.IsNamedPipe = Status.getType() == llvm::sys::fs::file_type::fifo_file; Data.InPCH = false; } @@ -50,22 +50,23 @@ static void copyStatusToFileData(const llvm::sys::fs::file_status &Status, /// implementation can optionally fill in FileDescriptor with a valid /// descriptor and the client guarantees that it will close it. bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile, - int *FileDescriptor, FileSystemStatCache *Cache) { + vfs::File **F, FileSystemStatCache *Cache, + vfs::FileSystem &FS) { LookupResult R; bool isForDir = !isFile; // If we have a cache, use it to resolve the stat query. if (Cache) - R = Cache->getStat(Path, Data, isFile, FileDescriptor); - else if (isForDir || !FileDescriptor) { + R = Cache->getStat(Path, Data, isFile, F, FS); + else if (isForDir || !F) { // If this is a directory or a file descriptor is not needed and we have // no cache, just go to the file system. - llvm::sys::fs::file_status Status; - if (llvm::sys::fs::status(Path, Status)) { + llvm::ErrorOr<vfs::Status> Status = FS.status(Path); + if (!Status) { R = CacheMissing; } else { R = CacheExists; - copyStatusToFileData(Status, Data); + copyStatusToFileData(*Status, Data); } } else { // Otherwise, we have to go to the filesystem. We can always just use @@ -75,7 +76,8 @@ bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile, // // Because of this, check to see if the file exists with 'open'. If the // open succeeds, use fstat to get the stat info. - llvm::error_code EC = llvm::sys::fs::openFileForRead(Path, *FileDescriptor); + llvm::OwningPtr<vfs::File> OwnedFile; + llvm::error_code EC = FS.openFileForRead(Path, OwnedFile); if (EC) { // If the open fails, our "stat" fails. @@ -84,16 +86,16 @@ bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile, // Otherwise, the open succeeded. Do an fstat to get the information // about the file. We'll end up returning the open file descriptor to the // client to do what they please with it. - llvm::sys::fs::file_status Status; - if (!llvm::sys::fs::status(*FileDescriptor, Status)) { + llvm::ErrorOr<vfs::Status> Status = OwnedFile->status(); + if (Status) { R = CacheExists; - copyStatusToFileData(Status, Data); + copyStatusToFileData(*Status, Data); + *F = OwnedFile.take(); } else { // fstat rarely fails. If it does, claim the initial open didn't // succeed. R = CacheMissing; - ::close(*FileDescriptor); - *FileDescriptor = -1; + *F = 0; } } } @@ -105,9 +107,9 @@ bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile, // demands. if (Data.IsDirectory != isForDir) { // If not, close the file if opened. - if (FileDescriptor && *FileDescriptor != -1) { - ::close(*FileDescriptor); - *FileDescriptor = -1; + if (F && *F) { + (*F)->close(); + *F = 0; } return true; @@ -118,8 +120,8 @@ bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile, MemorizeStatCalls::LookupResult MemorizeStatCalls::getStat(const char *Path, FileData &Data, bool isFile, - int *FileDescriptor) { - LookupResult Result = statChained(Path, Data, isFile, FileDescriptor); + vfs::File **F, vfs::FileSystem &FS) { + LookupResult Result = statChained(Path, Data, isFile, F, FS); // Do not cache failed stats, it is easy to construct common inconsistent // situations if we do, and they are not important for PCH performance (which diff --git a/clang/lib/Basic/VirtualFileSystem.cpp b/clang/lib/Basic/VirtualFileSystem.cpp new file mode 100644 index 00000000000..3fedf27f970 --- /dev/null +++ b/clang/lib/Basic/VirtualFileSystem.cpp @@ -0,0 +1,193 @@ +//===- VirtualFileSystem.cpp - Virtual File System Layer --------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// This file implements the VirtualFileSystem interface. +//===----------------------------------------------------------------------===// + +#include "clang/Basic/VirtualFileSystem.h" +#include "llvm/ADT/OwningPtr.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/Path.h" + +using namespace clang; +using namespace clang::vfs; +using namespace llvm; +using llvm::sys::fs::file_status; +using llvm::sys::fs::file_type; +using llvm::sys::fs::perms; +using llvm::sys::fs::UniqueID; + +Status::Status(const file_status &Status) + : UID(Status.getUniqueID()), MTime(Status.getLastModificationTime()), + User(Status.getUser()), Group(Status.getGroup()), Size(Status.getSize()), + Type(Status.type()), Perms(Status.permissions()) {} + +Status::Status(StringRef Name, StringRef ExternalName, UniqueID UID, + sys::TimeValue MTime, uint32_t User, uint32_t Group, + uint64_t Size, file_type Type, perms Perms) + : Name(Name), ExternalName(ExternalName), UID(UID), MTime(MTime), + User(User), Group(Group), Size(Size), Type(Type), Perms(Perms) {} + +bool Status::equivalent(const Status &Other) const { + return getUniqueID() == Other.getUniqueID(); +} +bool Status::isDirectory() const { + return Type == file_type::directory_file; +} +bool Status::isRegularFile() const { + return Type == file_type::regular_file; +} +bool Status::isOther() const { + return exists() && !isRegularFile() && !isDirectory() && !isSymlink(); +} +bool Status::isSymlink() const { + return Type == file_type::symlink_file; +} +bool Status::isStatusKnown() const { + return Type != file_type::status_error; +} +bool Status::exists() const { + return isStatusKnown() && Type != file_type::file_not_found; +} + +File::~File() {} + +FileSystem::~FileSystem() {} + +error_code FileSystem::getBufferForFile(const llvm::Twine &Name, + OwningPtr<MemoryBuffer> &Result, + int64_t FileSize, + bool RequiresNullTerminator) { + llvm::OwningPtr<File> F; + if (error_code EC = openFileForRead(Name, F)) + return EC; + + error_code EC = F->getBuffer(Name, Result, FileSize, RequiresNullTerminator); + return EC; +} + +//===-----------------------------------------------------------------------===/ +// RealFileSystem implementation +//===-----------------------------------------------------------------------===/ + +/// \brief Wrapper around a raw file descriptor. +class RealFile : public File { + int FD; + friend class RealFileSystem; + RealFile(int FD) : FD(FD) { + assert(FD >= 0 && "Invalid or inactive file descriptor"); + } +public: + ~RealFile(); + ErrorOr<Status> status() LLVM_OVERRIDE; + error_code getBuffer(const Twine &Name, OwningPtr<MemoryBuffer> &Result, + int64_t FileSize = -1, + bool RequiresNullTerminator = true) LLVM_OVERRIDE; + error_code close() LLVM_OVERRIDE; +}; +RealFile::~RealFile() { + close(); +} + +ErrorOr<Status> RealFile::status() { + assert(FD != -1 && "cannot stat closed file"); + file_status RealStatus; + if (error_code EC = sys::fs::status(FD, RealStatus)) + return EC; + return Status(RealStatus); +} + +error_code RealFile::getBuffer(const Twine &Name, + OwningPtr<MemoryBuffer> &Result, + int64_t FileSize, bool RequiresNullTerminator) { + assert(FD != -1 && "cannot get buffer for closed file"); + return MemoryBuffer::getOpenFile(FD, Name.str().c_str(), Result, FileSize, + RequiresNullTerminator); +} + +// FIXME: This is terrible, we need this for ::close. +#if !defined(_MSC_VER) && !defined(__MINGW32__) +#include <unistd.h> +#include <sys/uio.h> +#else +#include <io.h> +#ifndef S_ISFIFO +#define S_ISFIFO(x) (0) +#endif +#endif +error_code RealFile::close() { + if (::close(FD)) + return error_code(errno, system_category()); + FD = -1; + return error_code::success(); +} + +/// \brief The file system according to your operating system. +class RealFileSystem : public FileSystem { +public: + ErrorOr<Status> status(const Twine &Path) LLVM_OVERRIDE; + error_code openFileForRead(const Twine &Path, + OwningPtr<File> &Result) LLVM_OVERRIDE; +}; + +ErrorOr<Status> RealFileSystem::status(const Twine &Path) { + sys::fs::file_status RealStatus; + if (error_code EC = sys::fs::status(Path, RealStatus)) + return EC; + Status Result(RealStatus); + Result.setName(Path.str()); + Result.setExternalName(Path.str()); + return Result; +} + +error_code RealFileSystem::openFileForRead(const Twine &Name, + OwningPtr<File> &Result) { + int FD; + if (error_code EC = sys::fs::openFileForRead(Name, FD)) + return EC; + Result.reset(new RealFile(FD)); + return error_code::success(); +} + +IntrusiveRefCntPtr<FileSystem> vfs::getRealFileSystem() { + static IntrusiveRefCntPtr<FileSystem> FS = new RealFileSystem(); + return FS; +} + +//===-----------------------------------------------------------------------===/ +// OverlayFileSystem implementation +//===-----------------------------------------------------------------------===/ +OverlayFileSystem::OverlayFileSystem(IntrusiveRefCntPtr<FileSystem> BaseFS) { + pushOverlay(BaseFS); +} + +void OverlayFileSystem::pushOverlay(IntrusiveRefCntPtr<FileSystem> FS) { + FSList.push_back(FS); +} + +ErrorOr<Status> OverlayFileSystem::status(const Twine &Path) { + // FIXME: handle symlinks that cross file systems + for (iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) { + ErrorOr<Status> Status = (*I)->status(Path); + if (Status || Status.getError() != errc::no_such_file_or_directory) + return Status; + } + return error_code(errc::no_such_file_or_directory, system_category()); +} + +error_code OverlayFileSystem::openFileForRead(const llvm::Twine &Path, + OwningPtr<File> &Result) { + // FIXME: handle symlinks that cross file systems + for (iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) { + error_code EC = (*I)->openFileForRead(Path, Result); + if (!EC || EC != errc::no_such_file_or_directory) + return EC; + } + return error_code(errc::no_such_file_or_directory, system_category()); +} diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 3fca309102a..8d46a8f4a5d 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -20,6 +20,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" +#include "clang/Basic/VirtualFileSystem.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Frontend/FrontendDiagnostic.h" @@ -37,7 +38,6 @@ #include "llvm/ADT/StringSet.h" #include "llvm/Support/Atomic.h" #include "llvm/Support/CrashRecoveryContext.h" -#include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Mutex.h" @@ -1418,7 +1418,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( REnd = PreprocessorOpts.remapped_file_end(); !AnyFileChanged && R != REnd; ++R) { - llvm::sys::fs::file_status Status; + vfs::Status Status; if (FileMgr->getNoncachedStatValue(R->second, Status)) { // If we can't stat the file we're remapping to, assume that something // horrible happened. @@ -1454,7 +1454,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( } // The file was not remapped; check whether it has changed on disk. - llvm::sys::fs::file_status Status; + vfs::Status Status; if (FileMgr->getNoncachedStatValue(F->first(), Status)) { // If we can't stat the file, assume that something horrible happened. AnyFileChanged = true; diff --git a/clang/lib/Frontend/CacheTokens.cpp b/clang/lib/Frontend/CacheTokens.cpp index 0c30b049579..5cb364e3f5c 100644 --- a/clang/lib/Frontend/CacheTokens.cpp +++ b/clang/lib/Frontend/CacheTokens.cpp @@ -516,8 +516,8 @@ public: ~StatListener() {} LookupResult getStat(const char *Path, FileData &Data, bool isFile, - int *FileDescriptor) { - LookupResult Result = statChained(Path, Data, isFile, FileDescriptor); + vfs::File **F, vfs::FileSystem &FS) { + LookupResult Result = statChained(Path, Data, isFile, F, FS); if (Result == CacheMissing) // Failed 'stat'. PM.insert(PTHEntryKeyVariant(Path), PTHEntry()); diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 61fe26c9222..df0095205c3 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -79,6 +79,10 @@ void CompilerInstance::setTarget(TargetInfo *Value) { void CompilerInstance::setFileManager(FileManager *Value) { FileMgr = Value; + if (Value) + VirtualFileSystem = Value->getVirtualFileSystem(); + else + VirtualFileSystem.reset(); } void CompilerInstance::setSourceManager(SourceManager *Value) { @@ -197,7 +201,11 @@ CompilerInstance::createDiagnostics(DiagnosticOptions *Opts, // File Manager void CompilerInstance::createFileManager() { - FileMgr = new FileManager(getFileSystemOpts()); + if (!hasVirtualFileSystem()) { + // TODO: choose the virtual file system based on the CompilerInvocation. + setVirtualFileSystem(vfs::getRealFileSystem()); + } + FileMgr = new FileManager(getFileSystemOpts(), VirtualFileSystem); } // Source Manager @@ -867,6 +875,8 @@ static void compileModule(CompilerInstance &ImportingInstance, ImportingInstance.getDiagnosticClient()), /*ShouldOwnClient=*/true); + Instance.setVirtualFileSystem(&ImportingInstance.getVirtualFileSystem()); + // Note that this module is part of the module build stack, so that we // can detect cycles in the module graph. Instance.createFileManager(); // FIXME: Adopt file manager from importer? diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 0baf3e5e1fb..72377d84572 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -159,7 +159,6 @@ ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, return new MultiplexConsumer(Consumers); } - bool FrontendAction::BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input) { assert(!Instance && "Already processing a source file!"); diff --git a/clang/lib/Lex/PTHLexer.cpp b/clang/lib/Lex/PTHLexer.cpp index e174222ece3..cdc5d7e3381 100644 --- a/clang/lib/Lex/PTHLexer.cpp +++ b/clang/lib/Lex/PTHLexer.cpp @@ -675,13 +675,13 @@ public: ~PTHStatCache() {} LookupResult getStat(const char *Path, FileData &Data, bool isFile, - int *FileDescriptor) { + vfs::File **F, vfs::FileSystem &FS) { // Do the lookup for the file's data in the PTH file. CacheTy::iterator I = Cache.find(Path); // If we don't get a hit in the PTH file just forward to 'stat'. if (I == Cache.end()) - return statChained(Path, Data, isFile, FileDescriptor); + return statChained(Path, Data, isFile, F, FS); const PTHStatData &D = *I; diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index 711afcd2dca..ce7e7af3d13 100644 --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -89,7 +89,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type, New->InputFilesValidationTimestamp = 0; if (New->Kind == MK_Module) { std::string TimestampFilename = New->getTimestampFilename(); - llvm::sys::fs::file_status Status; + vfs::Status Status; // A cached stat value would be fine as well. if (!FileMgr.getNoncachedStatValue(TimestampFilename, Status)) New->InputFilesValidationTimestamp = |