15 #ifndef LLVM_CLANG_BASIC_FILEMANAGER_H
16 #define LLVM_CLANG_BASIC_FILEMANAGER_H
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/IntrusiveRefCntPtr.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/ADT/StringMap.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/Support/Allocator.h"
36 class FileSystemStatCache;
55 std::string RealPathName;
60 llvm::sys::fs::UniqueID UniqueID;
66 mutable std::unique_ptr<vfs::File> File;
69 void operator=(
const FileEntry &) =
delete;
81 IsNamedPipe(FE.IsNamedPipe), InPCH(FE.InPCH), IsValid(FE.IsValid) {
82 assert(!
isValid() &&
"Cannot copy an initialized FileEntry");
89 unsigned getUID()
const {
return UID; }
90 const llvm::sys::fs::UniqueID &
getUniqueID()
const {
return UniqueID; }
122 std::map<llvm::sys::fs::UniqueID, DirectoryEntry> UniqueRealDirs;
125 std::map<llvm::sys::fs::UniqueID, FileEntry> UniqueRealFiles;
143 llvm::StringMap<DirectoryEntry*, llvm::BumpPtrAllocator> SeenDirEntries;
149 llvm::StringMap<FileEntry*, llvm::BumpPtrAllocator> SeenFileEntries;
152 llvm::DenseMap<const DirectoryEntry *, llvm::StringRef> CanonicalDirNames;
155 llvm::BumpPtrAllocator CanonicalNameStorage;
159 unsigned NextFileUID;
162 unsigned NumDirLookups, NumFileLookups;
163 unsigned NumDirCacheMisses, NumFileCacheMisses;
166 std::unique_ptr<FileSystemStatCache> StatCache;
168 bool getStatValue(
const char *Path,
FileData &Data,
bool isFile,
169 std::unique_ptr<vfs::File> *F);
173 void addAncestorsAsVirtualDirs(StringRef Path);
191 void addStatCache(std::unique_ptr<FileSystemStatCache> statCache,
192 bool AtBeginning =
false);
208 bool CacheFailure =
true);
220 bool CacheFailure =
true);
235 time_t ModificationTime);
239 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
241 bool ShouldCloseOpenFile =
true);
242 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
276 time_t ModificationTime);
Implements support for file system lookup, file system caching, and directory search management...
FileManager(const FileSystemOptions &FileSystemOpts, IntrusiveRefCntPtr< vfs::FileSystem > FS=nullptr)
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
bool makeAbsolutePath(SmallVectorImpl< char > &Path) const
Makes Path absolute taking into account FileSystemOptions and the working directory option...
bool operator<(const FileEntry &RHS) const
Abstract interface for introducing a FileManager cache for 'stat' system calls, which is used by prec...
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
IntrusiveRefCntPtr< vfs::FileSystem > getVirtualFileSystem() const
The result of a status operation.
const FileEntry * getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
const DirectoryEntry * getDirectory(StringRef DirName, bool CacheFailure=true)
Lookup, cache, and verify the specified directory (real or virtual).
const llvm::sys::fs::UniqueID & getUniqueID() const
The result type of a method or function.
bool isNamedPipe() const
Check whether the file is a named pipe (and thus can't be opened by the native FileManager methods)...
void addStatCache(std::unique_ptr< FileSystemStatCache > statCache, bool AtBeginning=false)
Installs the provided FileSystemStatCache object within the FileManager.
const char * getName() const
FileSystemOptions & getFileSystemOpts()
Returns the current file system options.
Cached information about one file (either on disk or in the virtual file system). ...
void clearStatCaches()
Removes all FileSystemStatCache objects from the manager.
const FileEntry * getVirtualFile(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...
StringRef tryGetRealPathName() const
const char * getName() const
StringRef getCanonicalName(const DirectoryEntry *Dir)
Retrieve the canonical name for a given directory.
void removeStatCache(FileSystemStatCache *statCache)
Removes the specified FileSystemStatCache object from the manager.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const FileEntry *Entry, bool isVolatile=false, bool ShouldCloseOpenFile=true)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
Defines the virtual file system interface vfs::FileSystem.
time_t getModificationTime() const
Defines the clang::FileSystemOptions interface.
Cached information about one directory (either on disk or in the virtual file system).
Keeps track of options that affect how file operations are performed.
bool getNoncachedStatValue(StringRef Path, vfs::Status &Result)
Get the 'stat' information for the given Path.
static void modifyFileEntry(FileEntry *File, off_t Size, time_t ModificationTime)
Modifies the size and modification time of a previously created FileEntry.
FileEntry(const FileEntry &FE)
Intentionally does not copy fields that are not set in an uninitialized FileEntry.
void invalidateCache(const FileEntry *Entry)
Remove the real file Entry from the cache.
const FileSystemOptions & getFileSystemOpts() const
const DirectoryEntry * getDir() const
Return the directory the file lives in.
bool FixupRelativePath(SmallVectorImpl< char > &path) const
If path is not absolute and FileSystemOptions set the working directory, the path is modified to be r...
void GetUniqueIDMapping(SmallVectorImpl< const FileEntry * > &UIDToFiles) const
Produce an array mapping from the unique IDs assigned to each file to the corresponding FileEntry poi...