Go to the documentation of this file.
14 #ifndef LLVM_CLANG_BASIC_FILEMANAGER_H
15 #define LLVM_CLANG_BASIC_FILEMANAGER_H
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/IntrusiveRefCntPtr.h"
23 #include "llvm/ADT/PointerUnion.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/StringMap.h"
26 #include "llvm/ADT/StringRef.h"
27 #include "llvm/Support/Allocator.h"
28 #include "llvm/Support/ErrorOr.h"
29 #include "llvm/Support/FileSystem.h"
30 #include "llvm/Support/VirtualFileSystem.h"
44 class FileSystemStatCache;
56 llvm::SpecificBumpPtrAllocator<FileEntry> FilesAlloc;
57 llvm::SpecificBumpPtrAllocator<DirectoryEntry> DirsAlloc;
60 llvm::DenseMap<llvm::sys::fs::UniqueID, DirectoryEntry *> UniqueRealDirs;
63 llvm::DenseMap<llvm::sys::fs::UniqueID, FileEntry *> UniqueRealFiles;
86 llvm::StringMap<llvm::ErrorOr<DirectoryEntry &>, llvm::BumpPtrAllocator>
94 llvm::StringMap<llvm::ErrorOr<FileEntryRef::MapValue>, llvm::BumpPtrAllocator>
101 std::unique_ptr<llvm::StringMap<llvm::ErrorOr<FileEntryRef::MapValue>>>
102 SeenBypassFileEntries;
108 llvm::DenseMap<const void *, llvm::StringRef> CanonicalNames;
111 llvm::BumpPtrAllocator CanonicalNameStorage;
115 unsigned NextFileUID;
118 std::unique_ptr<FileSystemStatCache> StatCache;
120 std::error_code getStatValue(StringRef Path, llvm::vfs::Status &Status,
122 std::unique_ptr<llvm::vfs::File> *F);
126 void addAncestorsAsVirtualDirs(StringRef Path);
129 void fillRealPathName(
FileEntry *UFE, llvm::StringRef FileName);
147 void setStatCache(std::unique_ptr<FileSystemStatCache> statCache);
166 bool CacheFailure =
true);
170 bool CacheFailure =
true) {
171 return llvm::expectedToOptional(
getDirectoryRef(DirName, CacheFailure));
187 llvm::ErrorOr<const DirectoryEntry *>
188 getDirectory(StringRef DirName,
bool CacheFailure =
true);
204 llvm::ErrorOr<const FileEntry *>
205 getFile(StringRef
Filename,
bool OpenFile =
false,
bool CacheFailure =
true);
222 bool OpenFile =
false,
223 bool CacheFailure =
true);
235 bool OpenFile =
false,
236 bool CacheFailure =
true) {
237 return llvm::expectedToOptional(
252 this->FS = std::move(FS);
260 time_t ModificationTime);
263 time_t ModificationTime);
277 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
279 bool RequiresNullTerminator =
true);
280 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
282 bool RequiresNullTerminator =
true) {
283 return getBufferForFileImpl(
Filename, -1, isVolatile,
284 RequiresNullTerminator);
288 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
289 getBufferForFileImpl(StringRef
Filename,
int64_t FileSize,
bool isVolatile,
290 bool RequiresNullTerminator);
300 llvm::vfs::Status &Result);
337 #endif // LLVM_CLANG_BASIC_FILEMANAGER_H
std::error_code getNoncachedStatValue(StringRef Path, llvm::vfs::Status &Result)
Get the 'stat' information for the given Path.
YAML serialization mapping.
FileManager(const FileSystemOptions &FileSystemOpts, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS=nullptr)
Construct a file manager, optionally with a custom VFS.
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
void GetUniqueIDMapping(SmallVectorImpl< const FileEntry * > &UIDToFiles) const
Produce an array mapping from the unique IDs assigned to each file to the corresponding FileEntry poi...
void setStatCache(std::unique_ptr< FileSystemStatCache > statCache)
Installs the provided FileSystemStatCache object within the FileManager.
void clearStatCache()
Removes the FileSystemStatCache object from the manager.
llvm::Expected< FileEntryRef > getFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Get a FileEntryRef if it exists, without doing anything on error.
Keeps track of options that affect how file operations are performed.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(StringRef Filename, bool isVolatile=false, bool RequiresNullTerminator=true)
const FileSystemOptions & getFileSystemOpts() const
llvm::vfs::FileSystem & getVirtualFileSystem() const
Cached information about one directory (either on disk or in the virtual file system).
void setVirtualFileSystem(IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > getVirtualFileSystemPtr() const
llvm::Expected< DirectoryEntryRef > getDirectoryRef(StringRef DirName, bool CacheFailure=true)
Lookup, cache, and verify the specified directory (real or virtual).
bool FixupRelativePath(SmallVectorImpl< char > &path) const
If path is not absolute and FileSystemOptions set the working directory, the path is modified to be r...
FileSystemOptions & getFileSystemOpts()
Returns the current file system options.
Cached information about one file (either on disk or in the virtual file system).
FileEntryRef getVirtualFileRef(StringRef Filename, off_t Size, time_t ModificationTime)
Retrieve a file entry for a "virtual" file that acts as if there were a file with the given name on d...
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const FileEntry *Entry, bool isVolatile=false, bool RequiresNullTerminator=true)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
size_t getNumUniqueRealFiles() const
Returns the number of unique real file entries cached by the file manager.
OptionalDirectoryEntryRef getOptionalDirectoryRef(StringRef DirName, bool CacheFailure=true)
Get a DirectoryEntryRef if it exists, without doing anything on error.
bool makeAbsolutePath(SmallVectorImpl< char > &Path) const
Makes Path absolute taking into account FileSystemOptions and the working directory option.
Implements support for file system lookup, file system caching, and directory search management.
StringRef getCanonicalName(const DirectoryEntry *Dir)
Retrieve the canonical name for a given directory.
llvm::Expected< FileEntryRef > getSTDIN()
Get the FileEntryRef for stdin, returning an error if stdin cannot be read.
llvm::ErrorOr< const DirectoryEntry * > getDirectory(StringRef DirName, bool CacheFailure=true)
Lookup, cache, and verify the specified directory (real or virtual).
llvm::ErrorOr< const FileEntry * > getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
OptionalFileEntryRef getBypassFile(FileEntryRef VFE)
Retrieve a FileEntry that bypasses VFE, which is expected to be a virtual file entry,...
const FileEntry * getVirtualFile(StringRef Filename, off_t Size, time_t ModificationTime)