11 #include "clang/Basic/LLVM.h" 12 #include "llvm/ADT/None.h" 13 #include "llvm/Support/Path.h" 19 : MainFilePath(MainFilePath) {
20 assert(llvm::sys::path::is_absolute(MainFilePath));
24 llvm::vfs::Status S) {
25 llvm::SmallString<32> PathStore(S.getName());
26 if (FS.makeAbsolute(PathStore))
29 if (PathStore == MainFilePath)
32 StatCache.insert({PathStore, std::move(S)});
35 llvm::Optional<llvm::vfs::Status>
37 auto I = StatCache.find(File);
38 if (I != StatCache.end())
43 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
45 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) {
48 class CollectFS :
public llvm::vfs::ProxyFileSystem {
50 CollectFS(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
52 : ProxyFileSystem(std::move(FS)), StatCache(StatCache) {}
54 llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
55 openFileForRead(
const llvm::Twine &
Path)
override {
56 auto File = getUnderlyingFS().openFileForRead(Path);
64 if (
auto S =
File->get()->status())
65 StatCache.
update(getUnderlyingFS(), std::move(*S));
69 llvm::ErrorOr<llvm::vfs::Status> status(
const llvm::Twine &Path)
override {
70 auto S = getUnderlyingFS().status(Path);
72 StatCache.
update(getUnderlyingFS(), *S);
79 return llvm::IntrusiveRefCntPtr<CollectFS>(
80 new CollectFS(std::move(FS), *
this));
83 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
85 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
const {
86 class CacheVFS :
public llvm::vfs::ProxyFileSystem {
88 CacheVFS(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
90 : ProxyFileSystem(std::move(FS)), StatCache(StatCache) {}
92 llvm::ErrorOr<llvm::vfs::Status> status(
const llvm::Twine &
Path)
override {
93 if (
auto S = StatCache.
lookup(Path.str()))
95 return getUnderlyingFS().status(Path);
101 return llvm::IntrusiveRefCntPtr<CacheVFS>(
new CacheVFS(std::move(FS), *
this));
void update(const llvm::vfs::FileSystem &FS, llvm::vfs::Status S)
llvm::Optional< llvm::vfs::Status > lookup(llvm::StringRef Path) const
Path is a path stored in preamble.
PreambleFileStatusCache(llvm::StringRef MainFilePath)
MainFilePath is the absolute path of the main source file this preamble corresponds to...
Documents should not be synced at all.
IntrusiveRefCntPtr< llvm::vfs::FileSystem > getConsumingFS(IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS) const
Returns a VFS that uses the cache collected.
IntrusiveRefCntPtr< llvm::vfs::FileSystem > getProducingFS(IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)
Returns a VFS that collects file status.
std::string Path
A typedef to represent a file path.
Records status information for files open()ed or stat()ed during preamble build (except for the main ...
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//