10#include "clang/Basic/LLVM.h"
11#include "llvm/Support/Path.h"
12#include "llvm/Support/VirtualFileSystem.h"
20 assert(llvm::sys::path::is_absolute(MainFilePath));
21 llvm::SmallString<256> MainFileCanonical(MainFilePath);
22 llvm::sys::path::remove_dots(MainFileCanonical,
true);
23 this->MainFilePath = std::string(MainFileCanonical);
28 llvm::StringRef
File) {
30 llvm::SmallString<32> PathStore(
File);
31 if (FS.makeAbsolute(PathStore))
33 llvm::sys::path::remove_dots(PathStore,
true);
35 if (PathStore == MainFilePath)
38 StatCache.insert({PathStore, std::move(S)});
41std::optional<llvm::vfs::Status>
45 llvm::SmallString<256> PathLookup(
File);
46 llvm::sys::path::remove_dots(PathLookup,
true);
48 auto I = StatCache.find(PathLookup);
49 if (I != StatCache.end())
51 return llvm::vfs::Status::copyWithNewName(I->getValue(),
File);
55llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
57 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) {
60 class CollectFS :
public llvm::vfs::ProxyFileSystem {
62 CollectFS(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
64 : ProxyFileSystem(std::move(FS)), StatCache(StatCache) {}
66 llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
67 openFileForRead(
const llvm::Twine &
Path)
override {
68 auto File = getUnderlyingFS().openFileForRead(
Path);
76 if (
auto S = File->get()->status())
77 StatCache.
update(getUnderlyingFS(), std::move(*S),
Path.str());
81 llvm::ErrorOr<llvm::vfs::Status> status(
const llvm::Twine &
Path)
override {
82 auto S = getUnderlyingFS().status(
Path);
84 StatCache.
update(getUnderlyingFS(), *S,
Path.str());
91 return llvm::IntrusiveRefCntPtr<CollectFS>(
92 new CollectFS(std::move(FS), *
this));
95llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
97 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
const {
98 class CacheVFS :
public llvm::vfs::ProxyFileSystem {
100 CacheVFS(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
102 : ProxyFileSystem(std::move(FS)), StatCache(StatCache) {}
104 llvm::ErrorOr<llvm::vfs::Status> status(
const llvm::Twine &
Path)
override {
107 return getUnderlyingFS().status(
Path);
113 return llvm::IntrusiveRefCntPtr<CacheVFS>(
new CacheVFS(std::move(FS), *
this));
117 llvm::SmallString<128> CanonPath(
File);
118 llvm::sys::path::remove_dots(CanonPath,
true);
119 return CanonPath.str().str();
Records status information for files open()ed or stat()ed during preamble build (except for the main ...
IntrusiveRefCntPtr< llvm::vfs::FileSystem > getProducingFS(IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)
Returns a VFS that collects file status.
void update(const llvm::vfs::FileSystem &FS, llvm::vfs::Status S, llvm::StringRef File)
std::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.
IntrusiveRefCntPtr< llvm::vfs::FileSystem > getConsumingFS(IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS) const
Returns a VFS that uses the cache collected.
std::string Path
A typedef to represent a file path.
Path removeDots(PathRef File)
Returns a version of File that doesn't contain dots and dot dots.
llvm::StringRef PathRef
A typedef to represent a ref to file path.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//