diff options
Diffstat (limited to 'include/clang/Basic/VirtualFileSystem.h')
-rw-r--r-- | include/clang/Basic/VirtualFileSystem.h | 63 |
1 files changed, 55 insertions, 8 deletions
diff --git a/include/clang/Basic/VirtualFileSystem.h b/include/clang/Basic/VirtualFileSystem.h index 6ac0812dbb17..39dab6cbf045 100644 --- a/include/clang/Basic/VirtualFileSystem.h +++ b/include/clang/Basic/VirtualFileSystem.h @@ -16,15 +16,30 @@ #include "clang/Basic/LLVM.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" +#include "llvm/Support/Chrono.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" +#include <algorithm> +#include <cassert> +#include <cstdint> +#include <ctime> +#include <memory> +#include <stack> +#include <string> +#include <system_error> #include <utility> +#include <vector> namespace llvm { + class MemoryBuffer; -} + +} // end namespace llvm namespace clang { namespace vfs { @@ -33,7 +48,7 @@ namespace vfs { class Status { std::string Name; llvm::sys::fs::UniqueID UID; - llvm::sys::TimeValue MTime; + llvm::sys::TimePoint<> MTime; uint32_t User; uint32_t Group; uint64_t Size; @@ -47,7 +62,7 @@ public: Status() : Type(llvm::sys::fs::file_type::status_error) {} Status(const llvm::sys::fs::file_status &Status); Status(StringRef Name, llvm::sys::fs::UniqueID UID, - llvm::sys::TimeValue MTime, uint32_t User, uint32_t Group, + llvm::sys::TimePoint<> MTime, uint32_t User, uint32_t Group, uint64_t Size, llvm::sys::fs::file_type Type, llvm::sys::fs::perms Perms); @@ -63,7 +78,7 @@ public: /// @{ llvm::sys::fs::file_type getType() const { return Type; } llvm::sys::fs::perms getPermissions() const { return Perms; } - llvm::sys::TimeValue getLastModificationTime() const { return MTime; } + llvm::sys::TimePoint<> getLastModificationTime() const { return MTime; } llvm::sys::fs::UniqueID getUniqueID() const { return UID; } uint32_t getUser() const { return User; } uint32_t getGroup() const { return Group; } @@ -89,8 +104,10 @@ public: /// Sub-classes should generally call close() inside their destructors. We /// cannot do that from the base class, since close is virtual. virtual ~File(); + /// \brief Get the status of the file. virtual llvm::ErrorOr<Status> status() = 0; + /// \brief Get the name of the file virtual llvm::ErrorOr<std::string> getName() { if (auto Status = status()) @@ -98,24 +115,30 @@ public: else return Status.getError(); } + /// \brief Get the contents of the file as a \p MemoryBuffer. virtual llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> getBuffer(const Twine &Name, int64_t FileSize = -1, bool RequiresNullTerminator = true, bool IsVolatile = false) = 0; + /// \brief Closes the file. virtual std::error_code close() = 0; }; namespace detail { + /// \brief An interface for virtual file systems to provide an iterator over the /// (non-recursive) contents of a directory. struct DirIterImpl { virtual ~DirIterImpl(); + /// \brief Sets \c CurrentEntry to the next entry in the directory on success, /// or returns a system-defined \c error_code. virtual std::error_code increment() = 0; + Status CurrentEntry; }; + } // end namespace detail /// \brief An input iterator over the entries in a virtual path, similar to @@ -132,7 +155,7 @@ public: } /// \brief Construct an 'end' iterator. - directory_iterator() { } + directory_iterator() = default; /// \brief Equivalent to operator++, with an error code. directory_iterator &increment(std::error_code &EC) { @@ -171,7 +194,7 @@ public: recursive_directory_iterator(FileSystem &FS, const Twine &Path, std::error_code &EC); /// \brief Construct an 'end' iterator. - recursive_directory_iterator() { } + recursive_directory_iterator() = default; /// \brief Equivalent to operator++, with an error code. recursive_directory_iterator &increment(std::error_code &EC); @@ -185,6 +208,7 @@ public: bool operator!=(const recursive_directory_iterator &RHS) const { return !(*this == RHS); } + /// \brief Gets the current level. Starting path is at level 0. int level() const { assert(State->size() && "Cannot get level without any iteration state"); @@ -280,7 +304,9 @@ public: }; namespace detail { + class InMemoryDirectory; + } // end namespace detail /// An in-memory file system. @@ -292,6 +318,7 @@ class InMemoryFileSystem : public FileSystem { public: explicit InMemoryFileSystem(bool UseNormalizedPaths = true); ~InMemoryFileSystem() override; + /// Add a buffer to the VFS with a path. The VFS owns the buffer. /// \return true if the file was successfully added, false if the file already /// exists in the file system with different contents. @@ -335,22 +362,41 @@ struct YAMLVFSEntry { std::string RPath; }; +/// \brief Collect all pairs of <virtual path, real path> entries from the +/// \p YAMLFilePath. This is used by the module dependency collector to forward +/// the entries into the reproducer output VFS YAML file. +void collectVFSFromYAML( + std::unique_ptr<llvm::MemoryBuffer> Buffer, + llvm::SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath, + SmallVectorImpl<YAMLVFSEntry> &CollectedEntries, + void *DiagContext = nullptr, + IntrusiveRefCntPtr<FileSystem> ExternalFS = getRealFileSystem()); + class YAMLVFSWriter { std::vector<YAMLVFSEntry> Mappings; Optional<bool> IsCaseSensitive; Optional<bool> IsOverlayRelative; Optional<bool> UseExternalNames; + Optional<bool> IgnoreNonExistentContents; std::string OverlayDir; public: - YAMLVFSWriter() {} + YAMLVFSWriter() = default; + void addFileMapping(StringRef VirtualPath, StringRef RealPath); + void setCaseSensitivity(bool CaseSensitive) { IsCaseSensitive = CaseSensitive; } + void setUseExternalNames(bool UseExtNames) { UseExternalNames = UseExtNames; } + + void setIgnoreNonExistentContents(bool IgnoreContents) { + IgnoreNonExistentContents = IgnoreContents; + } + void setOverlayDir(StringRef OverlayDirectory) { IsOverlayRelative = true; OverlayDir.assign(OverlayDirectory.str()); @@ -361,4 +407,5 @@ public: } // end namespace vfs } // end namespace clang -#endif + +#endif // LLVM_CLANG_BASIC_VIRTUALFILESYSTEM_H |