14 #ifndef LLVM_CLANG_BASIC_FILEMANAGER_H 15 #define LLVM_CLANG_BASIC_FILEMANAGER_H 19 #include "llvm/ADT/DenseMap.h" 20 #include "llvm/ADT/IntrusiveRefCntPtr.h" 21 #include "llvm/ADT/SmallVector.h" 22 #include "llvm/ADT/StringMap.h" 23 #include "llvm/ADT/StringRef.h" 24 #include "llvm/Support/Allocator.h" 25 #include "llvm/Support/ErrorOr.h" 26 #include "llvm/Support/FileSystem.h" 27 #include "llvm/Support/VirtualFileSystem.h" 41 class FileSystemStatCache;
52 StringRef
getName()
const {
return Name; }
61 StringRef
getName()
const {
return Entry->getKey(); }
67 llvm::StringMapEntry<llvm::ErrorOr<DirectoryEntry &>> *Entry)
70 const llvm::StringMapEntry<llvm::ErrorOr<DirectoryEntry &>> *Entry;
82 std::string RealPathName;
86 llvm::sys::fs::UniqueID UniqueID;
92 mutable std::unique_ptr<llvm::vfs::File> File;
96 : UniqueID(0, 0), IsNamedPipe(
false), IsValid(
false)
107 const llvm::sys::fs::UniqueID &
getUniqueID()
const {
return UniqueID; }
134 : Name(Name), Entry(&Entry) {}
136 const StringRef
getName()
const {
return Name; }
138 bool isValid()
const {
return Entry->isValid(); }
142 off_t
getSize()
const {
return Entry->getSize(); }
144 unsigned getUID()
const {
return Entry->getUID(); }
147 return Entry->getUniqueID();
153 return LHS.Entry == RHS.Entry && LHS.Name == RHS.Name;
156 return !(LHS == RHS);
176 std::map<llvm::sys::fs::UniqueID, DirectoryEntry> UniqueRealDirs;
179 std::map<llvm::sys::fs::UniqueID, FileEntry> UniqueRealFiles;
202 llvm::StringMap<llvm::ErrorOr<DirectoryEntry &>, llvm::BumpPtrAllocator>
213 using SeenFileEntryOrRedirect =
214 llvm::PointerUnion<FileEntry *, const StringRef *>;
221 llvm::StringMap<llvm::ErrorOr<SeenFileEntryOrRedirect>,
222 llvm::BumpPtrAllocator>
226 llvm::DenseMap<const void *, llvm::StringRef> CanonicalNames;
229 llvm::BumpPtrAllocator CanonicalNameStorage;
233 unsigned NextFileUID;
236 std::unique_ptr<FileSystemStatCache> StatCache;
238 std::error_code getStatValue(StringRef Path, llvm::vfs::Status &Status,
240 std::unique_ptr<llvm::vfs::File> *F);
244 void addAncestorsAsVirtualDirs(StringRef Path);
247 void fillRealPathName(
FileEntry *UFE, llvm::StringRef FileName);
265 void setStatCache(std::unique_ptr<FileSystemStatCache> statCache);
268 void clearStatCache();
284 bool CacheFailure =
true);
289 return llvm::expectedToOptional(getDirectoryRef(DirName, CacheFailure));
305 llvm::ErrorOr<const DirectoryEntry *>
306 getDirectory(StringRef DirName,
bool CacheFailure =
true);
322 llvm::ErrorOr<const FileEntry *>
323 getFile(StringRef
Filename,
bool OpenFile =
false,
bool CacheFailure =
true);
340 bool OpenFile =
false,
341 bool CacheFailure =
true);
345 bool OpenFile =
false,
346 bool CacheFailure =
true) {
347 return llvm::expectedToOptional(
348 getFileRef(Filename, OpenFile, CacheFailure));
358 this->FS = std::move(FS);
365 const FileEntry *getVirtualFile(StringRef Filename, off_t Size,
366 time_t ModificationTime);
380 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
381 getBufferForFile(
const FileEntry *Entry,
bool isVolatile =
false);
382 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
384 return getBufferForFileImpl(Filename, -1, isVolatile);
388 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
389 getBufferForFileImpl(StringRef Filename, int64_t FileSize,
bool isVolatile);
398 std::error_code getNoncachedStatValue(StringRef Path,
399 llvm::vfs::Status &Result);
414 void GetUniqueIDMapping(
429 StringRef getCanonicalName(
const FileEntry *File);
431 void PrintStats()
const;
436 #endif // LLVM_CLANG_BASIC_FILEMANAGER_H StringRef tryGetRealPathName() const
Implements support for file system lookup, file system caching, and directory search management...
time_t getModificationTime() const
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
StringRef getName() const
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
time_t getModificationTime() const
const llvm::sys::fs::UniqueID & getUniqueID() const
llvm::Optional< DirectoryEntryRef > getOptionalDirectoryRef(StringRef DirName, bool CacheFailure=true)
Get a DirectoryEntryRef if it exists, without doing anything on error.
const StringRef getName() const
const DirectoryEntry & getDirEntry() const
llvm::Optional< FileEntryRef > getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Get a FileEntryRef if it exists, without doing anything on error.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
FileEntryRef(StringRef Name, const FileEntry &Entry)
size_t getNumUniqueRealFiles() const
Returns the number of unique real file entries cached by the file manager.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(StringRef Filename, bool isVolatile=false)
const DirectoryEntry * getDir() const
Return the directory the file lives in.
StringRef getName() const
FileSystemOptions & getFileSystemOpts()
Returns the current file system options.
bool isNamedPipe() const
Check whether the file is a named pipe (and thus can't be opened by the native FileManager methods)...
bool operator<(const FileEntry &RHS) const
Cached information about one file (either on disk or in the virtual file system). ...
const llvm::sys::fs::UniqueID & getUniqueID() const
const FileSystemOptions & getFileSystemOpts() const
void setVirtualFileSystem(IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)
friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS)
Dataflow Directional Tag Classes.
A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...
bool isOpenForTests() const
friend bool operator==(const FileEntryRef &LHS, const FileEntryRef &RHS)
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.
llvm::vfs::FileSystem & getVirtualFileSystem() const
StringRef getName() const
const FileEntry & getFileEntry() const