16 #include "llvm/ADT/ArrayRef.h" 17 #include "llvm/ADT/DenseMap.h" 18 #include "llvm/ADT/IntrusiveRefCntPtr.h" 19 #include "llvm/ADT/Optional.h" 20 #include "llvm/ADT/STLExtras.h" 21 #include "llvm/ADT/SmallString.h" 22 #include "llvm/ADT/SmallVector.h" 23 #include "llvm/ADT/StringRef.h" 24 #include "llvm/ADT/StringSet.h" 25 #include "llvm/ADT/Twine.h" 26 #include "llvm/ADT/iterator_range.h" 27 #include "llvm/Config/llvm-config.h" 28 #include "llvm/Support/Compiler.h" 29 #include "llvm/Support/Casting.h" 30 #include "llvm/Support/Chrono.h" 31 #include "llvm/Support/Debug.h" 32 #include "llvm/Support/Errc.h" 33 #include "llvm/Support/ErrorHandling.h" 34 #include "llvm/Support/ErrorOr.h" 35 #include "llvm/Support/FileSystem.h" 36 #include "llvm/Support/MemoryBuffer.h" 37 #include "llvm/Support/Path.h" 38 #include "llvm/Support/Process.h" 39 #include "llvm/Support/SMLoc.h" 40 #include "llvm/Support/SourceMgr.h" 41 #include "llvm/Support/YAMLParser.h" 42 #include "llvm/Support/raw_ostream.h" 52 #include <system_error> 56 using namespace clang;
60 using llvm::sys::fs::file_status;
61 using llvm::sys::fs::file_type;
62 using llvm::sys::fs::perms;
63 using llvm::sys::fs::UniqueID;
66 : UID(Status.getUniqueID()), MTime(Status.getLastModificationTime()),
67 User(Status.getUser()), Group(Status.getGroup()), Size(Status.getSize()),
68 Type(Status.
type()), Perms(Status.permissions()) {}
70 Status::Status(StringRef Name, UniqueID UID, sys::TimePoint<> MTime,
71 uint32_t User, uint32_t Group, uint64_t Size, file_type
Type,
73 : Name(Name), UID(UID), MTime(MTime), User(User), Group(Group), Size(Size),
74 Type(Type), Perms(Perms) {}
76 Status Status::copyWithNewName(
const Status &In, StringRef NewName) {
82 Status Status::copyWithNewName(
const file_status &In, StringRef NewName) {
83 return Status(NewName, In.getUniqueID(), In.getLastModificationTime(),
84 In.getUser(), In.getGroup(), In.getSize(), In.type(),
88 bool Status::equivalent(
const Status &Other)
const {
93 bool Status::isDirectory()
const {
94 return Type == file_type::directory_file;
97 bool Status::isRegularFile()
const {
98 return Type == file_type::regular_file;
101 bool Status::isOther()
const {
102 return exists() && !isRegularFile() && !isDirectory() && !isSymlink();
105 bool Status::isSymlink()
const {
106 return Type == file_type::symlink_file;
109 bool Status::isStatusKnown()
const {
110 return Type != file_type::status_error;
113 bool Status::exists()
const {
114 return isStatusKnown() &&
Type != file_type::file_not_found;
117 File::~File() =
default;
119 FileSystem::~FileSystem() =
default;
121 ErrorOr<std::unique_ptr<MemoryBuffer>>
122 FileSystem::getBufferForFile(
const llvm::Twine &Name, int64_t FileSize,
123 bool RequiresNullTerminator,
bool IsVolatile) {
124 auto F = openFileForRead(Name);
128 return (*F)->getBuffer(Name, FileSize, RequiresNullTerminator, IsVolatile);
132 if (llvm::sys::path::is_absolute(Path))
135 auto WorkingDir = getCurrentWorkingDirectory();
137 return WorkingDir.getError();
139 return llvm::sys::fs::make_absolute(WorkingDir.get(), Path);
142 std::error_code FileSystem::getRealPath(
const Twine &Path,
144 return errc::operation_not_permitted;
147 bool FileSystem::exists(
const Twine &Path) {
148 auto Status = status(Path);
154 return Component.equals(
"..") || Component.equals(
".");
160 for (StringRef Comp : llvm::make_range(path::begin(Path), path::end(Path)))
174 class RealFile :
public File {
175 friend class RealFileSystem;
179 std::string RealName;
181 RealFile(
int FD, StringRef NewName, StringRef NewRealPathName)
182 : FD(FD), S(NewName, {}, {}, {}, {}, {},
183 llvm::sys::fs::file_type::status_error, {}),
184 RealName(NewRealPathName.str()) {
185 assert(FD >= 0 &&
"Invalid or inactive file descriptor");
189 ~RealFile()
override;
191 ErrorOr<Status> status()
override;
192 ErrorOr<std::string>
getName()
override;
193 ErrorOr<std::unique_ptr<MemoryBuffer>> getBuffer(
const Twine &Name,
195 bool RequiresNullTerminator,
196 bool IsVolatile)
override;
197 std::error_code close()
override;
202 RealFile::~RealFile() { close(); }
204 ErrorOr<Status> RealFile::status() {
205 assert(FD != -1 &&
"cannot stat closed file");
206 if (!S.isStatusKnown()) {
207 file_status RealStatus;
208 if (std::error_code EC = sys::fs::status(FD, RealStatus))
210 S = Status::copyWithNewName(RealStatus, S.getName());
216 return RealName.empty() ? S.getName().str() : RealName;
219 ErrorOr<std::unique_ptr<MemoryBuffer>>
220 RealFile::getBuffer(
const Twine &Name, int64_t FileSize,
221 bool RequiresNullTerminator,
bool IsVolatile) {
222 assert(FD != -1 &&
"cannot get buffer for closed file");
223 return MemoryBuffer::getOpenFile(FD, Name, FileSize, RequiresNullTerminator,
227 std::error_code RealFile::close() {
228 std::error_code EC = sys::Process::SafelyCloseFileDescriptor(FD);
238 ErrorOr<Status> status(
const Twine &Path)
override;
239 ErrorOr<std::unique_ptr<File>> openFileForRead(
const Twine &Path)
override;
242 llvm::ErrorOr<std::string> getCurrentWorkingDirectory()
const override;
243 std::error_code setCurrentWorkingDirectory(
const Twine &Path)
override;
244 std::error_code getRealPath(
const Twine &Path,
250 ErrorOr<Status> RealFileSystem::status(
const Twine &Path) {
251 sys::fs::file_status RealStatus;
252 if (std::error_code EC = sys::fs::status(Path, RealStatus))
254 return Status::copyWithNewName(RealStatus, Path.str());
257 ErrorOr<std::unique_ptr<File>>
258 RealFileSystem::openFileForRead(
const Twine &Name) {
261 if (std::error_code EC =
262 sys::fs::openFileForRead(Name, FD, sys::fs::OF_None, &RealName))
264 return std::unique_ptr<File>(
new RealFile(FD, Name.str(), RealName.str()));
267 llvm::ErrorOr<std::string> RealFileSystem::getCurrentWorkingDirectory()
const {
269 if (std::error_code EC = llvm::sys::fs::current_path(Dir))
271 return Dir.str().str();
274 std::error_code RealFileSystem::setCurrentWorkingDirectory(
const Twine &Path) {
282 return llvm::sys::fs::set_current_path(Path);
286 RealFileSystem::getRealPath(
const Twine &Path,
299 llvm::sys::fs::directory_iterator Iter;
302 RealFSDirIter(
const Twine &Path, std::error_code &EC) : Iter(Path, EC) {
303 if (Iter != llvm::sys::fs::directory_iterator()) {
304 llvm::sys::fs::file_status S;
305 std::error_code ErrorCode = llvm::sys::fs::status(Iter->path(), S,
true);
306 CurrentEntry = Status::copyWithNewName(S, Iter->path());
312 std::error_code increment()
override {
315 if (Iter == llvm::sys::fs::directory_iterator()) {
318 llvm::sys::fs::file_status S;
319 std::error_code ErrorCode = llvm::sys::fs::status(Iter->path(), S,
true);
320 CurrentEntry = Status::copyWithNewName(S, Iter->path());
331 std::error_code &EC) {
340 FSList.push_back(std::move(BaseFS));
344 FSList.push_back(FS);
347 FS->setCurrentWorkingDirectory(getCurrentWorkingDirectory().
get());
350 ErrorOr<Status> OverlayFileSystem::status(
const Twine &Path) {
352 for (
iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) {
353 ErrorOr<Status>
Status = (*I)->status(Path);
354 if (Status || Status.getError() != llvm::errc::no_such_file_or_directory)
360 ErrorOr<std::unique_ptr<File>>
361 OverlayFileSystem::openFileForRead(
const llvm::Twine &Path) {
363 for (
iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) {
364 auto Result = (*I)->openFileForRead(Path);
365 if (
Result ||
Result.getError() != llvm::errc::no_such_file_or_directory)
371 llvm::ErrorOr<std::string>
372 OverlayFileSystem::getCurrentWorkingDirectory()
const {
374 return FSList.front()->getCurrentWorkingDirectory();
378 OverlayFileSystem::setCurrentWorkingDirectory(
const Twine &Path) {
379 for (
auto &FS : FSList)
380 if (std::error_code EC = FS->setCurrentWorkingDirectory(Path))
386 OverlayFileSystem::getRealPath(
const Twine &Path,
388 for (
auto &FS : FSList)
389 if (FS->exists(Path))
390 return FS->getRealPath(Path, Output);
391 return errc::no_such_file_or_directory;
403 llvm::StringSet<> SeenNames;
405 std::error_code incrementFS() {
406 assert(CurrentFS != Overlays.
overlays_end() &&
"incrementing past end");
408 for (
auto E = Overlays.
overlays_end(); CurrentFS != E; ++CurrentFS) {
410 CurrentDirIter = (*CurrentFS)->dir_begin(Path, EC);
411 if (EC && EC != errc::no_such_file_or_directory)
419 std::error_code incrementDirIter(
bool IsFirstTime) {
421 "incrementing past end");
430 std::error_code incrementImpl(
bool IsFirstTime) {
432 std::error_code EC = incrementDirIter(IsFirstTime);
437 CurrentEntry = *CurrentDirIter;
438 StringRef Name = llvm::sys::path::filename(CurrentEntry.getName());
439 if (SeenNames.insert(Name).second)
442 llvm_unreachable(
"returned above");
448 : Overlays(FS), Path(Path.str()), CurrentFS(Overlays.
overlays_begin()) {
449 CurrentDirIter = (*CurrentFS)->dir_begin(Path, EC);
450 EC = incrementImpl(
true);
453 std::error_code increment()
override {
return incrementImpl(
false); }
459 std::error_code &EC) {
461 std::make_shared<OverlayFSDirIterImpl>(Dir, *
this, EC));
479 : Stat(
std::move(Stat)), Kind(Kind) {}
484 virtual std::string
toString(
unsigned Indent)
const = 0;
490 std::unique_ptr<llvm::MemoryBuffer> Buffer;
493 InMemoryFile(
Status Stat, std::unique_ptr<llvm::MemoryBuffer> Buffer)
496 llvm::MemoryBuffer *getBuffer() {
return Buffer.get(); }
498 std::string
toString(
unsigned Indent)
const override {
499 return (std::string(Indent,
' ') + getStatus().
getName() +
"\n").str();
508 class InMemoryFileAdaptor :
public File {
512 explicit InMemoryFileAdaptor(InMemoryFile &Node) :
Node(Node) {}
514 llvm::ErrorOr<Status> status()
override {
return Node.getStatus(); }
516 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
517 getBuffer(
const Twine &Name, int64_t FileSize,
bool RequiresNullTerminator,
518 bool IsVolatile)
override {
519 llvm::MemoryBuffer *Buf = Node.getBuffer();
520 return llvm::MemoryBuffer::getMemBuffer(
521 Buf->getBuffer(), Buf->getBufferIdentifier(), RequiresNullTerminator);
524 std::error_code close()
override {
return {}; }
530 std::map<std::string, std::unique_ptr<InMemoryNode>> Entries;
537 auto I = Entries.find(Name);
538 if (I != Entries.end())
539 return I->second.get();
544 return Entries.insert(make_pair(Name, std::move(Child)))
545 .first->second.get();
553 std::string
toString(
unsigned Indent)
const override {
555 (std::string(Indent,
' ') + getStatus().getName() +
"\n").str();
556 for (
const auto &Entry : Entries)
557 Result += Entry.second->toString(Indent + 2);
568 InMemoryFileSystem::InMemoryFileSystem(
bool UseNormalizedPaths)
569 : Root(new detail::InMemoryDirectory(
571 0,
llvm::sys::fs::file_type::directory_file,
572 llvm::sys::fs::perms::all_all))),
573 UseNormalizedPaths(UseNormalizedPaths) {}
578 return Root->toString(0);
582 std::unique_ptr<llvm::MemoryBuffer> Buffer,
596 llvm::sys::path::remove_dots(Path,
true);
602 auto I = llvm::sys::path::begin(Path), E = sys::path::end(Path);
603 const auto ResolvedUser = User.getValueOr(0);
604 const auto ResolvedGroup = Group.getValueOr(0);
605 const auto ResolvedType = Type.getValueOr(sys::fs::file_type::regular_file);
606 const auto ResolvedPerms = Perms.getValueOr(sys::fs::all_all);
609 const auto NewDirectoryPerms = ResolvedPerms | sys::fs::owner_all;
618 llvm::sys::toTimePoint(ModificationTime), ResolvedUser,
619 ResolvedGroup, Buffer->getBufferSize(), ResolvedType,
621 std::unique_ptr<detail::InMemoryNode> Child;
622 if (ResolvedType == sys::fs::file_type::directory_file) {
625 Child.reset(
new detail::InMemoryFile(std::move(Stat),
628 Dir->
addChild(Name, std::move(Child));
634 StringRef(Path.str().begin(), Name.end() - Path.str().begin()),
636 ResolvedUser, ResolvedGroup, Buffer->getBufferSize(),
637 sys::fs::file_type::directory_file, NewDirectoryPerms);
638 Dir = cast<detail::InMemoryDirectory>(Dir->addChild(
639 Name, llvm::make_unique<detail::InMemoryDirectory>(std::move(Stat))));
643 if (
auto *NewDir = dyn_cast<detail::InMemoryDirectory>(Node)) {
646 assert(isa<detail::InMemoryFile>(Node) &&
647 "Must be either file or directory!");
654 return cast<detail::InMemoryFile>(
Node)->getBuffer()->getBuffer() ==
661 llvm::MemoryBuffer *Buffer,
666 return addFile(P, ModificationTime,
667 llvm::MemoryBuffer::getMemBuffer(
668 Buffer->getBuffer(), Buffer->getBufferIdentifier()),
669 std::move(User), std::move(Group), std::move(Type),
673 static ErrorOr<detail::InMemoryNode *>
685 llvm::sys::path::remove_dots(Path,
true);
690 auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path);
695 return errc::no_such_file_or_directory;
698 if (
auto File = dyn_cast<detail::InMemoryFile>(Node)) {
701 return errc::no_such_file_or_directory;
705 Dir = cast<detail::InMemoryDirectory>(
Node);
714 return (*Node)->getStatus();
715 return Node.getError();
718 llvm::ErrorOr<std::unique_ptr<File>>
722 return Node.getError();
726 if (
auto *F = dyn_cast<detail::InMemoryFile>(*
Node))
727 return std::unique_ptr<File>(
new detail::InMemoryFileAdaptor(*F));
741 InMemoryDirIterator() =
default;
746 CurrentEntry = I->second->getStatus();
749 std::error_code increment()
override {
753 CurrentEntry = I != E ? I->second->getStatus() :
Status();
761 std::error_code &EC) {
764 EC =
Node.getError();
768 if (
auto *DirNode = dyn_cast<detail::InMemoryDirectory>(*
Node))
785 llvm::sys::path::remove_dots(Path,
true);
788 WorkingDirectory = Path.str();
796 if (!CWD || CWD->empty())
797 return errc::operation_not_permitted;
798 Path.toVector(Output);
801 llvm::sys::path::remove_dots(Output,
true);
826 virtual ~Entry() =
default;
828 StringRef
getName()
const {
return Name; }
832 class RedirectingDirectoryEntry :
public Entry {
833 std::vector<std::unique_ptr<Entry>> Contents;
837 RedirectingDirectoryEntry(StringRef Name,
838 std::vector<std::unique_ptr<Entry>> Contents,
840 : Entry(EK_Directory, Name), Contents(std::move(Contents)),
842 RedirectingDirectoryEntry(StringRef Name,
Status S)
843 : Entry(EK_Directory, Name), S(std::move(S)) {}
845 Status getStatus() {
return S; }
847 void addContent(std::unique_ptr<Entry> Content) {
848 Contents.push_back(std::move(Content));
851 Entry *getLastContent()
const {
return Contents.back().get(); }
853 using iterator = decltype(Contents)::iterator;
855 iterator contents_begin() {
return Contents.begin(); }
856 iterator contents_end() {
return Contents.end(); }
858 static bool classof(
const Entry *E) {
return E->getKind() == EK_Directory; }
861 class RedirectingFileEntry :
public Entry {
870 std::string ExternalContentsPath;
874 RedirectingFileEntry(StringRef Name, StringRef ExternalContentsPath,
876 : Entry(EK_File, Name), ExternalContentsPath(ExternalContentsPath),
879 StringRef getExternalContentsPath()
const {
return ExternalContentsPath; }
882 bool useExternalName(
bool GlobalUseExternalName)
const {
883 return UseName == NK_NotSet ? GlobalUseExternalName
884 : (UseName == NK_External);
887 NameKind getUseName()
const {
return UseName; }
889 static bool classof(
const Entry *E) {
return E->getKind() == EK_File; }
892 class RedirectingFileSystem;
896 RedirectingFileSystem &FS;
897 RedirectingDirectoryEntry::iterator Current,
End;
900 VFSFromYamlDirIterImpl(
const Twine &Path, RedirectingFileSystem &FS,
901 RedirectingDirectoryEntry::iterator
Begin,
902 RedirectingDirectoryEntry::iterator End,
903 std::error_code &EC);
905 std::error_code increment()
override;
964 friend class RedirectingFileSystemParser;
967 std::vector<std::unique_ptr<Entry>> Roots;
975 std::string ExternalContentsPrefixDir;
983 bool CaseSensitive =
true;
987 bool IsRelativeOverlay =
false;
991 bool UseExternalNames =
true;
999 bool IgnoreNonExistentContents =
true;
1005 bool UseCanonicalizedPaths =
1014 : ExternalFS(std::move(ExternalFS)) {}
1018 ErrorOr<Entry *> lookupPath(sys::path::const_iterator Start,
1019 sys::path::const_iterator
End, Entry *From);
1022 ErrorOr<Status>
status(
const Twine &Path, Entry *E);
1026 ErrorOr<Entry *> lookupPath(
const Twine &Path);
1030 static RedirectingFileSystem *
1031 create(std::unique_ptr<MemoryBuffer> Buffer,
1032 SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath,
1035 ErrorOr<Status>
status(
const Twine &Path)
override;
1036 ErrorOr<std::unique_ptr<File>>
openFileForRead(
const Twine &Path)
override;
1039 return ExternalFS->getCurrentWorkingDirectory();
1043 return ExternalFS->setCurrentWorkingDirectory(Path);
1047 ErrorOr<Entry *> E = lookupPath(Dir);
1052 ErrorOr<Status> S =
status(Dir, *E);
1057 if (!S->isDirectory()) {
1058 EC = std::error_code(static_cast<int>(errc::not_a_directory),
1059 std::system_category());
1063 auto *D = cast<RedirectingDirectoryEntry>(*E);
1065 *
this, D->contents_begin(), D->contents_end(), EC));
1068 void setExternalContentsPrefixDir(StringRef PrefixDir) {
1069 ExternalContentsPrefixDir = PrefixDir.str();
1072 StringRef getExternalContentsPrefixDir()
const {
1073 return ExternalContentsPrefixDir;
1076 bool ignoreNonExistentContents()
const {
1077 return IgnoreNonExistentContents;
1080 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 1081 LLVM_DUMP_METHOD
void dump()
const {
1082 for (
const auto &Root : Roots)
1083 dumpEntry(Root.get());
1086 LLVM_DUMP_METHOD
void dumpEntry(Entry *E,
int NumSpaces = 0)
const {
1087 StringRef Name = E->getName();
1088 for (
int i = 0, e = NumSpaces; i < e; ++i)
1090 dbgs() <<
"'" << Name.str().c_str() <<
"'" <<
"\n";
1092 if (E->getKind() == EK_Directory) {
1093 auto *DE = dyn_cast<RedirectingDirectoryEntry>(E);
1094 assert(DE &&
"Should be a directory");
1096 for (std::unique_ptr<Entry> &SubEntry :
1097 llvm::make_range(DE->contents_begin(), DE->contents_end()))
1098 dumpEntry(SubEntry.get(), NumSpaces+2);
1105 class RedirectingFileSystemParser {
1106 yaml::Stream &Stream;
1108 void error(
yaml::Node *N,
const Twine &Msg) {
1109 Stream.printError(N, Msg);
1113 bool parseScalarString(
yaml::Node *N, StringRef &Result,
1115 const auto *S = dyn_cast<yaml::ScalarNode>(N);
1118 error(N,
"expected string");
1121 Result = S->getValue(Storage);
1126 bool parseScalarBool(
yaml::Node *N,
bool &Result) {
1129 if (!parseScalarString(N, Value, Storage))
1132 if (Value.equals_lower(
"true") || Value.equals_lower(
"on") ||
1133 Value.equals_lower(
"yes") || Value ==
"1") {
1136 }
else if (Value.equals_lower(
"false") || Value.equals_lower(
"off") ||
1137 Value.equals_lower(
"no") || Value ==
"0") {
1142 error(N,
"expected boolean value");
1150 KeyStatus(
bool Required =
false) : Required(Required) {}
1153 using KeyStatusPair = std::pair<StringRef, KeyStatus>;
1156 bool checkDuplicateOrUnknownKey(
yaml::Node *KeyNode, StringRef Key,
1157 DenseMap<StringRef, KeyStatus> &Keys) {
1158 if (!Keys.count(Key)) {
1159 error(KeyNode,
"unknown key");
1162 KeyStatus &S = Keys[Key];
1164 error(KeyNode, Twine(
"duplicate key '") + Key +
"'");
1172 bool checkMissingKeys(
yaml::Node *Obj, DenseMap<StringRef, KeyStatus> &Keys) {
1173 for (
const auto &I : Keys) {
1174 if (I.second.Required && !I.second.Seen) {
1175 error(Obj, Twine(
"missing key '") + I.first +
"'");
1182 Entry *lookupOrCreateEntry(RedirectingFileSystem *FS, StringRef Name,
1183 Entry *ParentEntry =
nullptr) {
1185 for (
const auto &Root : FS->Roots) {
1186 if (Name.equals(Root->getName())) {
1187 ParentEntry = Root.get();
1192 auto *DE = dyn_cast<RedirectingDirectoryEntry>(ParentEntry);
1193 for (std::unique_ptr<Entry> &Content :
1194 llvm::make_range(DE->contents_begin(), DE->contents_end())) {
1195 auto *DirContent = dyn_cast<RedirectingDirectoryEntry>(Content.get());
1196 if (DirContent && Name.equals(Content->getName()))
1202 std::unique_ptr<Entry> E = llvm::make_unique<RedirectingDirectoryEntry>(
1205 0, 0, 0, file_type::directory_file, sys::fs::all_all));
1208 FS->Roots.push_back(std::move(E));
1209 ParentEntry = FS->Roots.back().get();
1213 auto *DE = dyn_cast<RedirectingDirectoryEntry>(ParentEntry);
1214 DE->addContent(std::move(E));
1215 return DE->getLastContent();
1218 void uniqueOverlayTree(RedirectingFileSystem *FS, Entry *SrcE,
1219 Entry *NewParentE =
nullptr) {
1220 StringRef Name = SrcE->getName();
1221 switch (SrcE->getKind()) {
1222 case EK_Directory: {
1223 auto *DE = dyn_cast<RedirectingDirectoryEntry>(SrcE);
1224 assert(DE &&
"Must be a directory");
1229 NewParentE = lookupOrCreateEntry(FS, Name, NewParentE);
1230 for (std::unique_ptr<Entry> &SubEntry :
1231 llvm::make_range(DE->contents_begin(), DE->contents_end()))
1232 uniqueOverlayTree(FS, SubEntry.get(), NewParentE);
1236 auto *FE = dyn_cast<RedirectingFileEntry>(SrcE);
1237 assert(FE &&
"Must be a file");
1238 assert(NewParentE &&
"Parent entry must exist");
1239 auto *DE = dyn_cast<RedirectingDirectoryEntry>(NewParentE);
1240 DE->addContent(llvm::make_unique<RedirectingFileEntry>(
1241 Name, FE->getExternalContentsPath(), FE->getUseName()));
1247 std::unique_ptr<Entry> parseEntry(
yaml::Node *N, RedirectingFileSystem *FS) {
1248 auto *M = dyn_cast<yaml::MappingNode>(N);
1250 error(N,
"expected mapping node for file or directory entry");
1254 KeyStatusPair Fields[] = {
1255 KeyStatusPair(
"name",
true),
1256 KeyStatusPair(
"type",
true),
1257 KeyStatusPair(
"contents",
false),
1258 KeyStatusPair(
"external-contents",
false),
1259 KeyStatusPair(
"use-external-name",
false),
1262 DenseMap<StringRef, KeyStatus> Keys(std::begin(Fields), std::end(Fields));
1264 bool HasContents =
false;
1265 std::vector<std::unique_ptr<Entry>> EntryArrayContents;
1266 std::string ExternalContentsPath;
1268 auto UseExternalName = RedirectingFileEntry::NK_NotSet;
1271 for (
auto &I : *M) {
1276 if (!parseScalarString(I.getKey(), Key, Buffer))
1279 if (!checkDuplicateOrUnknownKey(I.getKey(), Key, Keys))
1283 if (Key ==
"name") {
1284 if (!parseScalarString(I.getValue(),
Value, Buffer))
1287 if (FS->UseCanonicalizedPaths) {
1291 Path = sys::path::remove_leading_dotslash(Path);
1292 sys::path::remove_dots(Path,
true);
1297 }
else if (Key ==
"type") {
1298 if (!parseScalarString(I.getValue(),
Value, Buffer))
1300 if (Value ==
"file")
1302 else if (Value ==
"directory")
1303 Kind = EK_Directory;
1305 error(I.getValue(),
"unknown value for 'type'");
1308 }
else if (Key ==
"contents") {
1311 "entry already has 'contents' or 'external-contents'");
1315 auto *Contents = dyn_cast<yaml::SequenceNode>(I.getValue());
1318 error(I.getValue(),
"expected array");
1322 for (
auto &I : *Contents) {
1323 if (std::unique_ptr<Entry> E = parseEntry(&I, FS))
1324 EntryArrayContents.push_back(std::move(E));
1328 }
else if (Key ==
"external-contents") {
1331 "entry already has 'contents' or 'external-contents'");
1335 if (!parseScalarString(I.getValue(),
Value, Buffer))
1339 if (FS->IsRelativeOverlay) {
1340 FullPath = FS->getExternalContentsPrefixDir();
1341 assert(!FullPath.empty() &&
1342 "External contents prefix directory must exist");
1343 llvm::sys::path::append(FullPath, Value);
1348 if (FS->UseCanonicalizedPaths) {
1351 FullPath = sys::path::remove_leading_dotslash(FullPath);
1352 sys::path::remove_dots(FullPath,
true);
1354 ExternalContentsPath = FullPath.str();
1355 }
else if (Key ==
"use-external-name") {
1357 if (!parseScalarBool(I.getValue(), Val))
1359 UseExternalName = Val ? RedirectingFileEntry::NK_External
1360 : RedirectingFileEntry::NK_Virtual;
1362 llvm_unreachable(
"key missing from Keys");
1366 if (Stream.failed())
1371 error(N,
"missing key 'contents' or 'external-contents'");
1374 if (!checkMissingKeys(N, Keys))
1378 if (Kind == EK_Directory &&
1379 UseExternalName != RedirectingFileEntry::NK_NotSet) {
1380 error(N,
"'use-external-name' is not supported for directories");
1385 StringRef Trimmed(Name);
1386 size_t RootPathLen = sys::path::root_path(Trimmed).size();
1387 while (Trimmed.size() > RootPathLen &&
1388 sys::path::is_separator(Trimmed.back()))
1389 Trimmed = Trimmed.slice(0, Trimmed.size()-1);
1391 StringRef LastComponent = sys::path::filename(Trimmed);
1393 std::unique_ptr<Entry> Result;
1396 Result = llvm::make_unique<RedirectingFileEntry>(
1397 LastComponent, std::move(ExternalContentsPath), UseExternalName);
1400 Result = llvm::make_unique<RedirectingDirectoryEntry>(
1401 LastComponent, std::move(EntryArrayContents),
1403 0, 0, 0, file_type::directory_file, sys::fs::all_all));
1407 StringRef
Parent = sys::path::parent_path(Trimmed);
1412 for (sys::path::reverse_iterator I = sys::path::rbegin(Parent),
1413 E = sys::path::rend(Parent);
1415 std::vector<std::unique_ptr<Entry>> Entries;
1416 Entries.push_back(std::move(Result));
1417 Result = llvm::make_unique<RedirectingDirectoryEntry>(
1418 *I, std::move(Entries),
1420 0, 0, 0, file_type::directory_file, sys::fs::all_all));
1426 RedirectingFileSystemParser(yaml::Stream &S) : Stream(S) {}
1429 bool parse(
yaml::Node *Root, RedirectingFileSystem *FS) {
1430 auto *Top = dyn_cast<yaml::MappingNode>(Root);
1432 error(Root,
"expected mapping node");
1436 KeyStatusPair Fields[] = {
1437 KeyStatusPair(
"version",
true),
1438 KeyStatusPair(
"case-sensitive",
false),
1439 KeyStatusPair(
"use-external-names",
false),
1440 KeyStatusPair(
"overlay-relative",
false),
1441 KeyStatusPair(
"ignore-non-existent-contents",
false),
1442 KeyStatusPair(
"roots",
true),
1445 DenseMap<StringRef, KeyStatus> Keys(std::begin(Fields), std::end(Fields));
1446 std::vector<std::unique_ptr<Entry>> RootEntries;
1449 for (
auto &I : *Top) {
1452 if (!parseScalarString(I.getKey(), Key, KeyBuffer))
1455 if (!checkDuplicateOrUnknownKey(I.getKey(), Key, Keys))
1458 if (Key ==
"roots") {
1459 auto *Roots = dyn_cast<yaml::SequenceNode>(I.getValue());
1461 error(I.getValue(),
"expected array");
1465 for (
auto &I : *Roots) {
1466 if (std::unique_ptr<Entry> E = parseEntry(&I, FS))
1467 RootEntries.push_back(std::move(E));
1471 }
else if (Key ==
"version") {
1472 StringRef VersionString;
1474 if (!parseScalarString(I.getValue(), VersionString, Storage))
1477 if (VersionString.getAsInteger<
int>(10, Version)) {
1478 error(I.getValue(),
"expected integer");
1482 error(I.getValue(),
"invalid version number");
1486 error(I.getValue(),
"version mismatch, expected 0");
1489 }
else if (Key ==
"case-sensitive") {
1490 if (!parseScalarBool(I.getValue(), FS->CaseSensitive))
1492 }
else if (Key ==
"overlay-relative") {
1493 if (!parseScalarBool(I.getValue(), FS->IsRelativeOverlay))
1495 }
else if (Key ==
"use-external-names") {
1496 if (!parseScalarBool(I.getValue(), FS->UseExternalNames))
1498 }
else if (Key ==
"ignore-non-existent-contents") {
1499 if (!parseScalarBool(I.getValue(), FS->IgnoreNonExistentContents))
1502 llvm_unreachable(
"key missing from Keys");
1506 if (Stream.failed())
1509 if (!checkMissingKeys(Top, Keys))
1515 for (
auto &E : RootEntries)
1516 uniqueOverlayTree(FS, E.get());
1524 RedirectingFileSystem *
1526 SourceMgr::DiagHandlerTy DiagHandler,
1527 StringRef YAMLFilePath,
void *DiagContext,
1530 yaml::Stream Stream(Buffer->getMemBufferRef(),
SM);
1532 SM.setDiagHandler(DiagHandler, DiagContext);
1533 yaml::document_iterator DI = Stream.begin();
1535 if (DI == Stream.end() || !Root) {
1536 SM.PrintMessage(SMLoc(), SourceMgr::DK_Error,
"expected root node");
1540 RedirectingFileSystemParser
P(Stream);
1542 std::unique_ptr<RedirectingFileSystem> FS(
1543 new RedirectingFileSystem(std::move(ExternalFS)));
1545 if (!YAMLFilePath.empty()) {
1555 std::error_code EC = llvm::sys::fs::make_absolute(OverlayAbsDir);
1556 assert(!EC &&
"Overlay dir final path must be absolute");
1558 FS->setExternalContentsPrefixDir(OverlayAbsDir);
1561 if (!P.parse(Root, FS.get()))
1564 return FS.release();
1567 ErrorOr<Entry *> RedirectingFileSystem::lookupPath(
const Twine &Path_) {
1569 Path_.toVector(Path);
1578 if (UseCanonicalizedPaths) {
1579 Path = sys::path::remove_leading_dotslash(Path);
1580 sys::path::remove_dots(Path,
true);
1586 sys::path::const_iterator Start = sys::path::begin(Path);
1587 sys::path::const_iterator
End = sys::path::end(Path);
1588 for (
const auto &Root : Roots) {
1589 ErrorOr<Entry *> Result = lookupPath(Start, End, Root.get());
1590 if (Result || Result.getError() != llvm::errc::no_such_file_or_directory)
1597 RedirectingFileSystem::lookupPath(sys::path::const_iterator Start,
1598 sys::path::const_iterator
End, Entry *From) {
1602 "Paths should not contain traversal components");
1606 if (Start->equals(
"."))
1610 StringRef FromName = From->getName();
1613 if (!FromName.empty()) {
1614 if (CaseSensitive ? !Start->equals(FromName)
1615 : !Start->equals_lower(FromName))
1627 auto *DE = dyn_cast<RedirectingDirectoryEntry>(From);
1631 for (
const std::unique_ptr<Entry> &DirEntry :
1632 llvm::make_range(DE->contents_begin(), DE->contents_end())) {
1633 ErrorOr<Entry *> Result = lookupPath(Start, End, DirEntry.get());
1634 if (Result || Result.getError() != llvm::errc::no_such_file_or_directory)
1642 Status S = ExternalStatus;
1643 if (!UseExternalNames)
1649 ErrorOr<Status> RedirectingFileSystem::status(
const Twine &Path, Entry *E) {
1650 assert(E !=
nullptr);
1651 if (
auto *F = dyn_cast<RedirectingFileEntry>(E)) {
1652 ErrorOr<Status> S = ExternalFS->status(F->getExternalContentsPath());
1653 assert(!S || S->getName() == F->getExternalContentsPath());
1659 auto *DE = cast<RedirectingDirectoryEntry>(E);
1664 ErrorOr<Status> RedirectingFileSystem::status(
const Twine &Path) {
1665 ErrorOr<Entry *> Result = lookupPath(Path);
1667 return Result.getError();
1668 return status(Path, *Result);
1674 class FileWithFixedStatus :
public File {
1675 std::unique_ptr<File> InnerFile;
1679 FileWithFixedStatus(std::unique_ptr<File> InnerFile,
Status S)
1680 : InnerFile(std::move(InnerFile)), S(std::move(S)) {}
1682 ErrorOr<Status>
status()
override {
return S; }
1683 ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
1685 getBuffer(
const Twine &Name, int64_t FileSize,
bool RequiresNullTerminator,
1686 bool IsVolatile)
override {
1687 return InnerFile->getBuffer(Name, FileSize, RequiresNullTerminator,
1691 std::error_code close()
override {
return InnerFile->close(); }
1696 ErrorOr<std::unique_ptr<File>>
1697 RedirectingFileSystem::openFileForRead(
const Twine &Path) {
1698 ErrorOr<Entry *> E = lookupPath(Path);
1700 return E.getError();
1702 auto *F = dyn_cast<RedirectingFileEntry>(*E);
1706 auto Result = ExternalFS->openFileForRead(F->getExternalContentsPath());
1710 auto ExternalStatus = (*Result)->status();
1711 if (!ExternalStatus)
1712 return ExternalStatus.getError();
1717 return std::unique_ptr<File>(
1718 llvm::make_unique<FileWithFixedStatus>(std::move(*Result), S));
1723 SourceMgr::DiagHandlerTy DiagHandler,
1724 StringRef YAMLFilePath,
1728 YAMLFilePath, DiagContext,
1729 std::move(ExternalFS));
1734 auto Kind = SrcE->getKind();
1735 if (
Kind == EK_Directory) {
1736 auto *DE = dyn_cast<RedirectingDirectoryEntry>(SrcE);
1737 assert(DE &&
"Must be a directory");
1738 for (std::unique_ptr<Entry> &SubEntry :
1739 llvm::make_range(DE->contents_begin(), DE->contents_end())) {
1740 Path.push_back(SubEntry->getName());
1747 assert(
Kind == EK_File &&
"Must be a EK_File");
1748 auto *FE = dyn_cast<RedirectingFileEntry>(SrcE);
1749 assert(FE &&
"Must be a file");
1751 for (
auto &Comp : Path)
1752 llvm::sys::path::append(VPath, Comp);
1753 Entries.push_back(
YAMLVFSEntry(VPath.c_str(), FE->getExternalContentsPath()));
1757 SourceMgr::DiagHandlerTy DiagHandler,
1758 StringRef YAMLFilePath,
1763 std::move(Buffer), DiagHandler, YAMLFilePath, DiagContext,
1764 std::move(ExternalFS));
1765 ErrorOr<Entry *> RootE = VFS->lookupPath(
"/");
1769 Components.push_back(
"/");
1774 static std::atomic<unsigned> UID;
1775 unsigned ID = ++UID;
1782 assert(sys::path::is_absolute(VirtualPath) &&
"virtual path not absolute");
1783 assert(sys::path::is_absolute(RealPath) &&
"real path not absolute");
1784 assert(!
pathHasTraversal(VirtualPath) &&
"path traversal is not supported");
1785 Mappings.emplace_back(VirtualPath, RealPath);
1791 llvm::raw_ostream &OS;
1794 unsigned getDirIndent() {
return 4 * DirStack.size(); }
1795 unsigned getFileIndent() {
return 4 * (DirStack.size() + 1); }
1796 bool containedIn(StringRef
Parent, StringRef Path);
1797 StringRef containedPart(StringRef Parent, StringRef Path);
1798 void startDirectory(StringRef Path);
1799 void endDirectory();
1800 void writeEntry(StringRef VPath, StringRef RPath);
1803 JSONWriter(llvm::raw_ostream &OS) : OS(OS) {}
1812 bool JSONWriter::containedIn(StringRef
Parent, StringRef Path) {
1816 auto IParent = path::begin(Parent), EParent = path::end(Parent);
1817 for (
auto IChild = path::begin(Path), EChild = path::end(Path);
1818 IParent != EParent && IChild != EChild; ++IParent, ++IChild) {
1819 if (*IParent != *IChild)
1823 return IParent == EParent;
1826 StringRef JSONWriter::containedPart(StringRef Parent, StringRef Path) {
1827 assert(!Parent.empty());
1828 assert(containedIn(Parent, Path));
1829 return Path.slice(Parent.size() + 1, StringRef::npos);
1832 void JSONWriter::startDirectory(StringRef Path) {
1834 DirStack.empty() ? Path : containedPart(DirStack.back(), Path);
1835 DirStack.push_back(Path);
1836 unsigned Indent = getDirIndent();
1837 OS.indent(Indent) <<
"{\n";
1838 OS.indent(Indent + 2) <<
"'type': 'directory',\n";
1839 OS.indent(Indent + 2) <<
"'name': \"" << llvm::yaml::escape(Name) <<
"\",\n";
1840 OS.indent(Indent + 2) <<
"'contents': [\n";
1843 void JSONWriter::endDirectory() {
1844 unsigned Indent = getDirIndent();
1845 OS.indent(Indent + 2) <<
"]\n";
1846 OS.indent(Indent) <<
"}";
1848 DirStack.pop_back();
1851 void JSONWriter::writeEntry(StringRef VPath, StringRef RPath) {
1852 unsigned Indent = getFileIndent();
1853 OS.indent(Indent) <<
"{\n";
1854 OS.indent(Indent + 2) <<
"'type': 'file',\n";
1855 OS.indent(Indent + 2) <<
"'name': \"" << llvm::yaml::escape(VPath) <<
"\",\n";
1856 OS.indent(Indent + 2) <<
"'external-contents': \"" 1857 << llvm::yaml::escape(RPath) <<
"\"\n";
1858 OS.indent(Indent) <<
"}";
1866 StringRef OverlayDir) {
1871 if (IsCaseSensitive.hasValue())
1872 OS <<
" 'case-sensitive': '" 1873 << (IsCaseSensitive.getValue() ?
"true" :
"false") <<
"',\n";
1874 if (UseExternalNames.hasValue())
1875 OS <<
" 'use-external-names': '" 1876 << (UseExternalNames.getValue() ?
"true" :
"false") <<
"',\n";
1877 bool UseOverlayRelative =
false;
1878 if (IsOverlayRelative.hasValue()) {
1879 UseOverlayRelative = IsOverlayRelative.getValue();
1880 OS <<
" 'overlay-relative': '" 1881 << (UseOverlayRelative ?
"true" :
"false") <<
"',\n";
1883 if (IgnoreNonExistentContents.hasValue())
1884 OS <<
" 'ignore-non-existent-contents': '" 1885 << (IgnoreNonExistentContents.getValue() ?
"true" :
"false") <<
"',\n";
1886 OS <<
" 'roots': [\n";
1888 if (!Entries.empty()) {
1890 startDirectory(path::parent_path(Entry.
VPath));
1892 StringRef RPath = Entry.
RPath;
1893 if (UseOverlayRelative) {
1894 unsigned OverlayDirLen = OverlayDir.size();
1895 assert(RPath.substr(0, OverlayDirLen) == OverlayDir &&
1896 "Overlay dir must be contained in RPath");
1897 RPath = RPath.slice(OverlayDirLen, RPath.size());
1900 writeEntry(path::filename(Entry.
VPath), RPath);
1902 for (
const auto &Entry : Entries.slice(1)) {
1903 StringRef Dir = path::parent_path(Entry.
VPath);
1904 if (Dir == DirStack.back())
1907 while (!DirStack.empty() && !containedIn(DirStack.back(), Dir)) {
1912 startDirectory(Dir);
1914 StringRef RPath = Entry.
RPath;
1915 if (UseOverlayRelative) {
1916 unsigned OverlayDirLen = OverlayDir.size();
1917 assert(RPath.substr(0, OverlayDirLen) == OverlayDir &&
1918 "Overlay dir must be contained in RPath");
1919 RPath = RPath.slice(OverlayDirLen, RPath.size());
1921 writeEntry(path::filename(Entry.
VPath), RPath);
1924 while (!DirStack.empty()) {
1936 llvm::sort(Mappings.begin(), Mappings.end(),
1938 return LHS.
VPath < RHS.VPath;
1941 JSONWriter(OS).write(Mappings, UseExternalNames, IsCaseSensitive,
1942 IsOverlayRelative, IgnoreNonExistentContents,
1946 VFSFromYamlDirIterImpl::VFSFromYamlDirIterImpl(
1947 const Twine &_Path, RedirectingFileSystem &FS,
1948 RedirectingDirectoryEntry::iterator
Begin,
1949 RedirectingDirectoryEntry::iterator End, std::error_code &EC)
1950 : Dir(_Path.str()), FS(FS), Current(Begin),
End(End) {
1951 while (Current != End) {
1953 llvm::sys::path::append(PathStr, (*Current)->getName());
1954 llvm::ErrorOr<vfs::Status> S = FS.status(PathStr);
1960 if (FS.ignoreNonExistentContents() &&
1961 S.getError() == llvm::errc::no_such_file_or_directory) {
1971 std::error_code VFSFromYamlDirIterImpl::increment() {
1972 assert(Current != End &&
"cannot iterate past end");
1973 while (++Current != End) {
1975 llvm::sys::path::append(PathStr, (*Current)->getName());
1976 llvm::ErrorOr<vfs::Status> S = FS.status(PathStr);
1979 if (FS.ignoreNonExistentContents() &&
1980 S.getError() == llvm::errc::no_such_file_or_directory) {
1983 return S.getError();
1997 std::error_code &EC)
2001 State = std::make_shared<IterState>();
2008 assert(FS && State && !State->empty() &&
"incrementing past end");
2009 assert(State->top()->isStatusKnown() &&
"non-canonical end iterator");
2011 if (State->top()->isDirectory()) {
2019 while (!State->empty() && State->top().increment(EC) ==
End)
static Status getRedirectedFileStatus(const Twine &Path, bool UseExternalNames, Status ExternalStatus)
static bool classof(const InMemoryNode *N)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
llvm::sys::fs::perms getPermissions() const
The base class of the type hierarchy.
InMemoryNode * getChild(StringRef Name)
std::string getName(ArrayRef< StringRef > Parts) const
Get the platform-specific name separator.
The virtual file system interface.
llvm::ErrorOr< std::string > getCurrentWorkingDirectory() const override
Get the working directory of this file system.
void write(llvm::raw_ostream &OS)
IntrusiveRefCntPtr< FileSystem > getVFSFromYAML(std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath, void *DiagContext=nullptr, IntrusiveRefCntPtr< FileSystem > ExternalFS=getRealFileSystem())
Gets a FileSystem for a virtual file system described in YAML format.
bool isStatusKnown() const
An input iterator over the recursive contents of a virtual path, similar to llvm::sys::fs::recursive_...
const_iterator end() const
An in-memory file system.
bool useNormalizedPaths() const
Return true if this file system normalizes . and .. in paths.
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.
std::error_code make_error_code(BuildPreambleError Error)
directory_iterator & increment(std::error_code &EC)
Equivalent to operator++, with an error code.
InMemoryDirectory(Status Stat)
static void getVFSEntries(Entry *SrcE, SmallVectorImpl< StringRef > &Path, SmallVectorImpl< YAMLVFSEntry > &Entries)
void addFileMapping(StringRef VirtualPath, StringRef RealPath)
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
InMemoryNode(Status Stat, InMemoryNodeKind Kind)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
std::error_code getRealPath(const Twine &Path, SmallVectorImpl< char > &Output) const override
Canonicalizes Path by combining with the current working directory and normalizing the path (e...
llvm::ErrorOr< std::unique_ptr< File > > openFileForRead(const Twine &Path) override
Get a File object for the file at Path, if one exists.
The result of a status operation.
const_iterator begin() const
The in memory file system is a tree of Nodes.
static Status copyWithNewName(const Status &In, StringRef NewName)
Get a copy of a Status with a different name.
iterator overlays_end()
Get an iterator pointing one-past the least recently added file system.
static bool pathHasTraversal(StringRef Path)
static bool isTraversalComponent(StringRef Component)
std::string toString() const
The result type of a method or function.
~InMemoryFileSystem() override
FileSystemList::reverse_iterator iterator
const Status & getStatus() const
llvm::sys::fs::file_type getType() const
decltype(Entries)::const_iterator const_iterator
recursive_directory_iterator & increment(std::error_code &EC)
Equivalent to operator++, with an error code.
void collectVFSFromYAML(std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath, SmallVectorImpl< YAMLVFSEntry > &CollectedEntries, void *DiagContext=nullptr, IntrusiveRefCntPtr< FileSystem > ExternalFS=getRealFileSystem())
Collect all pairs of <virtual path, real path> entries from the YAMLFilePath.
iterator overlays_begin()
Get an iterator pointing to the most recently added file system.
llvm::sys::TimePoint getLastModificationTime() const
std::error_code makeAbsolute(SmallVectorImpl< char > &Path) const
Make Path an absolute path.
recursive_directory_iterator()=default
Construct an 'end' iterator.
InMemoryNode * addChild(StringRef Name, std::unique_ptr< InMemoryNode > Child)
ast_type_traits::DynTypedNode Node
Dataflow Directional Tag Classes.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Defines the virtual file system interface vfs::FileSystem.
llvm::sys::fs::UniqueID getNextVirtualUniqueID()
Get a globally unique ID for a virtual file or directory.
static ErrorOr< detail::InMemoryNode * > lookupInMemoryNode(const InMemoryFileSystem &FS, detail::InMemoryDirectory *Dir, const Twine &P)
std::string toString(const til::SExpr *E)
static bool classof(const OMPClause *T)
llvm::sys::fs::UniqueID getUniqueID() const
std::string toString(unsigned Indent) const override
An input iterator over the entries in a virtual path, similar to llvm::sys::fs::directory_iterator.
llvm::ErrorOr< Status > status(const Twine &Path) override
Get the status of the entry at Path, if one exists.
std::error_code setCurrentWorkingDirectory(const Twine &Path) override
Set the working directory.
__DEVICE__ int max(int __a, int __b)
static Decl::Kind getKind(const Decl *D)
An interface for virtual file systems to provide an iterator over the (non-recursive) contents of a d...
bool addFileNoOwn(const Twine &Path, time_t ModificationTime, llvm::MemoryBuffer *Buffer, Optional< uint32_t > User=None, Optional< uint32_t > Group=None, Optional< llvm::sys::fs::file_type > Type=None, Optional< llvm::sys::fs::perms > Perms=None)
Add a buffer to the VFS with a path.
uint32_t getGroup() const
InMemoryNodeKind getKind() const
bool addFile(const Twine &Path, time_t ModificationTime, std::unique_ptr< llvm::MemoryBuffer > Buffer, Optional< uint32_t > User=None, Optional< uint32_t > Group=None, Optional< llvm::sys::fs::file_type > Type=None, Optional< llvm::sys::fs::perms > Perms=None)
Add a file containing a buffer or a directory to the VFS with a path.
static bool real_path(StringRef SrcPath, SmallVectorImpl< char > &RealPath)