11#include "llvm/ADT/SmallString.h"
12#include "llvm/ADT/StringRef.h"
13#include "llvm/Support/Path.h"
14#include "llvm/Support/VirtualFileSystem.h"
26class VolatileFileSystem :
public llvm::vfs::ProxyFileSystem {
28 explicit VolatileFileSystem(llvm::IntrusiveRefCntPtr<FileSystem> FS)
29 : ProxyFileSystem(std::move(FS)) {}
31 llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
32 openFileForRead(
const llvm::Twine &InPath)
override {
33 llvm::SmallString<128>
Path;
34 InPath.toVector(
Path);
36 auto File = getUnderlyingFS().openFileForRead(
Path);
41 llvm::StringRef
FileName = llvm::sys::path::filename(
Path);
44 return std::make_unique<VolatileFile>(std::move(*
File));
48 class VolatileFile :
public llvm::vfs::File {
50 VolatileFile(std::unique_ptr<llvm::vfs::File> Wrapped)
51 : Wrapped(std::move(Wrapped)) {
52 assert(this->Wrapped);
55 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
56 getBuffer(
const llvm::Twine &
Name, int64_t FileSize,
57 bool RequiresNullTerminator,
bool )
override {
58 return Wrapped->getBuffer(
Name, FileSize, RequiresNullTerminator,
62 llvm::ErrorOr<llvm::vfs::Status> status()
override {
63 return Wrapped->status();
65 llvm::ErrorOr<std::string> getName()
override {
return Wrapped->getName(); }
66 std::error_code close()
override {
return Wrapped->close(); }
69 std::unique_ptr<File> Wrapped;
74llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
76 auto FS =
view(std::nullopt);
77 if (
auto EC = FS->setCurrentWorkingDirectory(CWD))
78 elog(
"VFS: failed to set CWD to {0}: {1}", CWD, EC.message());
82llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
83RealThreadsafeFS::viewImpl()
const {
87 return new VolatileFileSystem(llvm::vfs::createPhysicalFileSystem());
llvm::SmallString< 256U > Name
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > view(std::nullopt_t CWD) const
Obtain a vfs::FileSystem with an arbitrary initial working directory.
std::string Path
A typedef to represent a file path.
llvm::StringRef PathRef
A typedef to represent a ref to file path.
void elog(const char *Fmt, Ts &&... Vals)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//