13 #ifndef LLVM_CLANG_BASIC_VIRTUALFILESYSTEM_H
14 #define LLVM_CLANG_BASIC_VIRTUALFILESYSTEM_H
17 #include "llvm/ADT/IntrusiveRefCntPtr.h"
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/Support/ErrorOr.h"
20 #include "llvm/Support/FileSystem.h"
21 #include "llvm/Support/SourceMgr.h"
22 #include "llvm/Support/raw_ostream.h"
34 llvm::sys::fs::UniqueID UID;
35 llvm::sys::TimeValue MTime;
39 llvm::sys::fs::file_type
Type;
40 llvm::sys::fs::perms Perms;
46 Status() :
Type(llvm::sys::fs::file_type::status_error) {}
48 Status(StringRef Name, StringRef RealName, llvm::sys::fs::UniqueID UID,
49 llvm::sys::TimeValue MTime, uint32_t User, uint32_t Group,
50 uint64_t Size, llvm::sys::fs::file_type
Type,
51 llvm::sys::fs::perms Perms);
54 StringRef
getName()
const {
return Name; }
90 virtual llvm::ErrorOr<Status>
status() = 0;
92 virtual llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
93 getBuffer(
const Twine &Name, int64_t FileSize = -1,
94 bool RequiresNullTerminator =
true,
bool IsVolatile =
false) = 0;
96 virtual std::error_code
close() = 0;
98 virtual void setName(StringRef Name) = 0;
116 std::shared_ptr<detail::DirIterImpl> Impl;
120 assert(Impl.get() !=
nullptr &&
"requires non-null implementation");
121 if (!Impl->CurrentEntry.isStatusKnown())
130 assert(Impl &&
"attempting to increment past end");
131 EC = Impl->increment();
132 if (EC || !Impl->CurrentEntry.isStatusKnown())
141 if (Impl && RHS.Impl)
142 return Impl->CurrentEntry.equivalent(RHS.Impl->CurrentEntry);
143 return !Impl && !RHS.Impl;
146 return !(*
this == RHS);
155 typedef std::stack<directory_iterator, std::vector<directory_iterator>>
159 std::shared_ptr<IterState> State;
163 std::error_code &EC);
174 return State == Other.State;
177 return !(*
this == RHS);
182 class FileSystem :
public llvm::ThreadSafeRefCountedBase<FileSystem> {
187 virtual llvm::ErrorOr<Status>
status(
const Twine &Path) = 0;
189 virtual llvm::ErrorOr<std::unique_ptr<File>>
194 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
196 bool RequiresNullTerminator =
true,
bool IsVolatile =
false);
201 std::error_code &EC) = 0;
229 llvm::ErrorOr<Status>
status(
const Twine &Path)
override;
230 llvm::ErrorOr<std::unique_ptr<File>>
251 llvm::SourceMgr::DiagHandlerTy DiagHandler,
252 void *DiagContext =
nullptr,
263 std::vector<YAMLVFSEntry> Mappings;
270 IsCaseSensitive = CaseSensitive;
272 void write(llvm::raw_ostream &OS);
virtual void setName(StringRef Name)=0
Sets the name to use for this file.
const Status * operator->() const
const Status * operator->() const
IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
void setName(StringRef N)
virtual llvm::ErrorOr< Status > status()=0
Get the status of the file.
bool equivalent(const Status &Other) const
bool isStatusKnown() const
llvm::sys::TimeValue getLastModificationTime() const
virtual llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBuffer(const Twine &Name, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)=0
Get the contents of the file as a MemoryBuffer.
virtual llvm::ErrorOr< std::unique_ptr< File > > openFileForRead(const Twine &Path)=0
Get a File object for the file at Path, if one exists.
virtual directory_iterator dir_begin(const Twine &Dir, std::error_code &EC)=0
Get a directory_iterator for Dir.
The virtual file system interface.
IntrusiveRefCntPtr< FileSystem > getVFSFromYAML(std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::SourceMgr::DiagHandlerTy DiagHandler, void *DiagContext=nullptr, IntrusiveRefCntPtr< FileSystem > ExternalFS=getRealFileSystem())
Gets a FileSystem for a virtual file system described in YAML format.
void write(llvm::raw_ostream &OS)
virtual std::error_code close()=0
Closes the file.
An input iterator over the recursive contents of a virtual path, similar to llvm::sys::fs::recursive_...
directory_iterator(std::shared_ptr< detail::DirIterImpl > I)
directory_iterator()
Construct an 'end' iterator.
directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override
Get a directory_iterator for Dir.
A file system that allows overlaying one AbstractFileSystem on top of another.
virtual llvm::ErrorOr< Status > status(const Twine &Path)=0
Get the status of the entry at Path, if one exists.
directory_iterator & increment(std::error_code &EC)
Equivalent to operator++, with an error code.
llvm::sys::fs::file_type getType() const
void addFileMapping(StringRef VirtualPath, StringRef RealPath)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
bool operator!=(const recursive_directory_iterator &RHS) const
FileSystemList::reverse_iterator iterator
The result of a status operation.
void pushOverlay(IntrusiveRefCntPtr< FileSystem > FS)
Pushes a file system on top of the stack.
recursive_directory_iterator()
Construct an 'end' iterator.
llvm::sys::fs::UniqueID getUniqueID() const
iterator overlays_end()
Get an iterator pointing one-past the least recently added file system.
void setType(llvm::sys::fs::file_type v)
void setCaseSensitivity(bool CaseSensitive)
recursive_directory_iterator & increment(std::error_code &EC)
Equivalent to operator++, with an error code.
bool operator!=(const directory_iterator &RHS) const
llvm::ErrorOr< std::unique_ptr< File > > openFileForRead(const Twine &Path) override
Get a File object for the file at Path, if one exists.
uint32_t getGroup() const
iterator overlays_begin()
Get an iterator pointing to the most recently added file system.
YAMLVFSEntry(T1 &&VPath, T2 &&RPath)
static __inline__ uint32_t volatile uint32_t * p
bool isRegularFile() const
bool operator==(const directory_iterator &RHS) const
llvm::sys::fs::perms getPermissions() const
void setPermissions(llvm::sys::fs::perms p)
OverlayFileSystem(IntrusiveRefCntPtr< FileSystem > Base)
llvm::sys::fs::UniqueID getNextVirtualUniqueID()
Get a globally unique ID for a virtual file or directory.
const Status & operator*() const
const Status & operator*() const
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const Twine &Name, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
StringRef getName() const
Returns the name that should be used for this file or directory.
virtual ~File()
Destroy the file after closing it (if open). Sub-classes should generally call close() inside their d...
An input iterator over the entries in a virtual path, similar to llvm::sys::fs::directory_iterator.
bool operator==(const recursive_directory_iterator &Other) const
An interface for virtual file systems to provide an iterator over the (non-recursive) contents of a d...
llvm::ErrorOr< Status > status(const Twine &Path) override
Get the status of the entry at Path, if one exists.
virtual std::error_code increment()=0
Sets CurrentEntry to the next entry in the directory on success, or returns a system-defined error_co...