13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/STLExtras.h"
15 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/ADT/StringSet.h"
17 #include "llvm/ADT/iterator_range.h"
18 #include "llvm/Support/Errc.h"
19 #include "llvm/Support/MemoryBuffer.h"
20 #include "llvm/Support/Path.h"
21 #include "llvm/Support/YAMLParser.h"
25 using namespace clang;
26 using namespace clang::vfs;
28 using llvm::sys::fs::file_status;
29 using llvm::sys::fs::file_type;
30 using llvm::sys::fs::perms;
31 using llvm::sys::fs::UniqueID;
34 : UID(Status.getUniqueID()), MTime(Status.getLastModificationTime()),
35 User(Status.getUser()), Group(Status.getGroup()), Size(Status.getSize()),
36 Type(Status.
type()), Perms(Status.permissions()), IsVFSMapped(
false) {}
38 Status::Status(StringRef Name, StringRef ExternalName, UniqueID UID,
39 sys::TimeValue MTime, uint32_t User, uint32_t Group,
40 uint64_t Size, file_type
Type, perms Perms)
41 : Name(Name), UID(UID), MTime(MTime), User(User), Group(Group), Size(Size),
42 Type(Type), Perms(Perms), IsVFSMapped(
false) {}
44 bool Status::equivalent(
const Status &Other)
const {
47 bool Status::isDirectory()
const {
48 return Type == file_type::directory_file;
50 bool Status::isRegularFile()
const {
51 return Type == file_type::regular_file;
53 bool Status::isOther()
const {
54 return exists() && !isRegularFile() && !isDirectory() && !isSymlink();
56 bool Status::isSymlink()
const {
57 return Type == file_type::symlink_file;
59 bool Status::isStatusKnown()
const {
60 return Type != file_type::status_error;
62 bool Status::exists()
const {
63 return isStatusKnown() &&
Type != file_type::file_not_found;
68 FileSystem::~FileSystem() {}
70 ErrorOr<std::unique_ptr<MemoryBuffer>>
71 FileSystem::getBufferForFile(
const llvm::Twine &Name, int64_t FileSize,
72 bool RequiresNullTerminator,
bool IsVolatile) {
73 auto F = openFileForRead(Name);
77 return (*F)->getBuffer(Name, FileSize, RequiresNullTerminator, IsVolatile);
86 class RealFile :
public File {
89 friend class RealFileSystem;
90 RealFile(
int FD) : FD(FD) {
91 assert(FD >= 0 &&
"Invalid or inactive file descriptor");
96 ErrorOr<Status> status()
override;
97 ErrorOr<std::unique_ptr<MemoryBuffer>>
98 getBuffer(
const Twine &Name, int64_t FileSize = -1,
99 bool RequiresNullTerminator =
true,
100 bool IsVolatile =
false)
override;
101 std::error_code close()
override;
102 void setName(StringRef Name)
override;
105 RealFile::~RealFile() { close(); }
107 ErrorOr<Status> RealFile::status() {
108 assert(FD != -1 &&
"cannot stat closed file");
109 if (!
S.isStatusKnown()) {
110 file_status RealStatus;
111 if (std::error_code EC = sys::fs::status(FD, RealStatus))
114 NewS.setName(
S.getName());
120 ErrorOr<std::unique_ptr<MemoryBuffer>>
121 RealFile::getBuffer(
const Twine &Name, int64_t FileSize,
122 bool RequiresNullTerminator,
bool IsVolatile) {
123 assert(FD != -1 &&
"cannot get buffer for closed file");
124 return MemoryBuffer::getOpenFile(FD, Name, FileSize, RequiresNullTerminator,
129 #if !defined(_MSC_VER) && !defined(__MINGW32__)
135 #define S_ISFIFO(x) (0)
138 std::error_code RealFile::close() {
140 return std::error_code(errno, std::generic_category());
142 return std::error_code();
145 void RealFile::setName(StringRef Name) {
153 ErrorOr<Status> status(
const Twine &Path)
override;
154 ErrorOr<std::unique_ptr<File>> openFileForRead(
const Twine &Path)
override;
159 ErrorOr<Status> RealFileSystem::status(
const Twine &Path) {
160 sys::fs::file_status RealStatus;
161 if (std::error_code EC = sys::fs::status(Path, RealStatus))
164 Result.setName(Path.str());
168 ErrorOr<std::unique_ptr<File>>
169 RealFileSystem::openFileForRead(
const Twine &Name) {
171 if (std::error_code EC = sys::fs::openFileForRead(Name, FD))
173 std::unique_ptr<File>
Result(
new RealFile(FD));
174 Result->setName(Name.str());
175 return std::move(Result);
186 llvm::sys::fs::directory_iterator Iter;
188 RealFSDirIter(
const Twine &_Path, std::error_code &EC)
189 : Path(_Path.str()), Iter(Path, EC) {
190 if (!EC && Iter != llvm::sys::fs::directory_iterator()) {
191 llvm::sys::fs::file_status
S;
192 EC = Iter->status(S);
195 CurrentEntry.setName(Iter->path());
200 std::error_code increment()
override {
205 }
else if (Iter == llvm::sys::fs::directory_iterator()) {
208 llvm::sys::fs::file_status
S;
209 EC = Iter->status(S);
211 CurrentEntry.setName(Iter->path());
219 std::error_code &EC) {
231 FSList.push_back(FS);
234 ErrorOr<Status> OverlayFileSystem::status(
const Twine &Path) {
236 for (
iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) {
237 ErrorOr<Status>
Status = (*I)->status(Path);
238 if (Status || Status.getError() != llvm::errc::no_such_file_or_directory)
244 ErrorOr<std::unique_ptr<File>>
245 OverlayFileSystem::openFileForRead(
const llvm::Twine &Path) {
247 for (
iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) {
248 auto Result = (*I)->openFileForRead(Path);
249 if (
Result ||
Result.getError() != llvm::errc::no_such_file_or_directory)
263 llvm::StringSet<> SeenNames;
265 std::error_code incrementFS() {
266 assert(CurrentFS != Overlays.overlays_end() &&
"incrementing past end");
268 for (
auto E = Overlays.overlays_end(); CurrentFS != E; ++CurrentFS) {
270 CurrentDirIter = (*CurrentFS)->dir_begin(Path, EC);
271 if (EC && EC != errc::no_such_file_or_directory)
276 return std::error_code();
279 std::error_code incrementDirIter(
bool IsFirstTime) {
281 "incrementing past end");
284 CurrentDirIter.increment(EC);
290 std::error_code incrementImpl(
bool IsFirstTime) {
292 std::error_code EC = incrementDirIter(IsFirstTime);
297 CurrentEntry = *CurrentDirIter;
298 StringRef Name = llvm::sys::path::filename(CurrentEntry.getName());
299 if (SeenNames.insert(Name).second)
302 llvm_unreachable(
"returned above");
308 : Overlays(FS), Path(Path.str()), CurrentFS(Overlays.overlays_begin()) {
309 CurrentDirIter = (*CurrentFS)->dir_begin(Path, EC);
310 EC = incrementImpl(
true);
313 std::error_code increment()
override {
return incrementImpl(
false); }
318 std::error_code &EC) {
320 std::make_shared<OverlayFSDirIterImpl>(Dir, *
this, EC));
342 StringRef getName()
const {
return Name; }
347 std::vector<Entry *> Contents;
353 : Entry(EK_Directory, Name), Contents(std::move(Contents)),
355 Status getStatus() {
return S; }
356 typedef std::vector<Entry *>::iterator iterator;
357 iterator contents_begin() {
return Contents.begin(); }
358 iterator contents_end() {
return Contents.end(); }
359 static bool classof(
const Entry *E) {
return E->getKind() == EK_Directory; }
370 std::string ExternalContentsPath;
373 FileEntry(StringRef Name, StringRef ExternalContentsPath, NameKind UseName)
374 : Entry(EK_File, Name), ExternalContentsPath(ExternalContentsPath),
376 StringRef getExternalContentsPath()
const {
return ExternalContentsPath; }
378 bool useExternalName(
bool GlobalUseExternalName)
const {
379 return UseName == NK_NotSet ? GlobalUseExternalName
380 : (UseName == NK_External);
382 static bool classof(
const Entry *E) {
return E->getKind() == EK_File; }
392 VFSFromYamlDirIterImpl(
const Twine &Path, VFSFromYAML &FS,
393 DirectoryEntry::iterator Begin,
394 DirectoryEntry::iterator
End, std::error_code &EC);
395 std::error_code increment()
override;
452 std::vector<Entry *> Roots;
466 bool UseExternalNames;
469 friend class VFSFromYAMLParser;
473 : ExternalFS(ExternalFS), CaseSensitive(
true), UseExternalNames(
true) {}
476 ErrorOr<Entry *> lookupPath(
const Twine &Path);
480 ErrorOr<Entry *> lookupPath(sys::path::const_iterator Start,
481 sys::path::const_iterator
End, Entry *From);
484 ErrorOr<Status> status(
const Twine &Path, Entry *E);
487 ~VFSFromYAML()
override;
491 static VFSFromYAML *
create(std::unique_ptr<MemoryBuffer> Buffer,
492 SourceMgr::DiagHandlerTy DiagHandler,
496 ErrorOr<Status> status(
const Twine &Path)
override;
497 ErrorOr<std::unique_ptr<File>> openFileForRead(
const Twine &Path)
override;
500 ErrorOr<Entry *> E = lookupPath(Dir);
505 ErrorOr<Status> S = status(Dir, *E);
510 if (!S->isDirectory()) {
511 EC = std::error_code(static_cast<int>(errc::not_a_directory),
512 std::system_category());
518 *
this, D->contents_begin(), D->contents_end(), EC));
523 class VFSFromYAMLParser {
524 yaml::Stream &Stream;
527 Stream.printError(N, Msg);
533 yaml::ScalarNode *S = dyn_cast<yaml::ScalarNode>(N);
535 error(N,
"expected string");
538 Result = S->getValue(Storage);
543 bool parseScalarBool(
yaml::Node *N,
bool &Result) {
546 if (!parseScalarString(N, Value, Storage))
549 if (Value.equals_lower(
"true") || Value.equals_lower(
"on") ||
550 Value.equals_lower(
"yes") || Value ==
"1") {
553 }
else if (Value.equals_lower(
"false") || Value.equals_lower(
"off") ||
554 Value.equals_lower(
"no") || Value ==
"0") {
559 error(N,
"expected boolean value");
564 KeyStatus(
bool Required=
false) : Required(Required), Seen(
false) {}
568 typedef std::pair<StringRef, KeyStatus> KeyStatusPair;
571 bool checkDuplicateOrUnknownKey(
yaml::Node *KeyNode, StringRef Key,
572 DenseMap<StringRef, KeyStatus> &Keys) {
573 if (!Keys.count(Key)) {
574 error(KeyNode,
"unknown key");
577 KeyStatus &S = Keys[Key];
579 error(KeyNode, Twine(
"duplicate key '") + Key +
"'");
587 bool checkMissingKeys(
yaml::Node *Obj, DenseMap<StringRef, KeyStatus> &Keys) {
588 for (DenseMap<StringRef, KeyStatus>::iterator I = Keys.begin(),
591 if (I->second.Required && !I->second.Seen) {
592 error(Obj, Twine(
"missing key '") + I->first +
"'");
600 yaml::MappingNode *M = dyn_cast<yaml::MappingNode>(N);
602 error(N,
"expected mapping node for file or directory entry");
606 KeyStatusPair Fields[] = {
607 KeyStatusPair(
"name",
true),
608 KeyStatusPair(
"type",
true),
609 KeyStatusPair(
"contents",
false),
610 KeyStatusPair(
"external-contents",
false),
611 KeyStatusPair(
"use-external-name",
false),
614 DenseMap<StringRef, KeyStatus> Keys(
615 &Fields[0], Fields +
sizeof(Fields)/
sizeof(Fields[0]));
617 bool HasContents =
false;
618 std::vector<Entry *> EntryArrayContents;
619 std::string ExternalContentsPath;
621 FileEntry::NameKind UseExternalName = FileEntry::NK_NotSet;
624 for (yaml::MappingNode::iterator I = M->begin(), E = M->end(); I != E;
630 if (!parseScalarString(I->getKey(), Key, Buffer))
633 if (!checkDuplicateOrUnknownKey(I->getKey(), Key, Keys))
638 if (!parseScalarString(I->getValue(),
Value, Buffer))
641 }
else if (Key ==
"type") {
642 if (!parseScalarString(I->getValue(),
Value, Buffer))
646 else if (Value ==
"directory")
649 error(I->getValue(),
"unknown value for 'type'");
652 }
else if (Key ==
"contents") {
655 "entry already has 'contents' or 'external-contents'");
659 yaml::SequenceNode *Contents =
660 dyn_cast<yaml::SequenceNode>(I->getValue());
663 error(I->getValue(),
"expected array");
667 for (yaml::SequenceNode::iterator I = Contents->begin(),
670 if (Entry *E = parseEntry(&*I))
671 EntryArrayContents.push_back(E);
675 }
else if (Key ==
"external-contents") {
678 "entry already has 'contents' or 'external-contents'");
682 if (!parseScalarString(I->getValue(),
Value, Buffer))
684 ExternalContentsPath =
Value;
685 }
else if (Key ==
"use-external-name") {
687 if (!parseScalarBool(I->getValue(), Val))
689 UseExternalName = Val ? FileEntry::NK_External : FileEntry::NK_Virtual;
691 llvm_unreachable(
"key missing from Keys");
700 error(N,
"missing key 'contents' or 'external-contents'");
703 if (!checkMissingKeys(N, Keys))
707 if (Kind == EK_Directory && UseExternalName != FileEntry::NK_NotSet) {
708 error(N,
"'use-external-name' is not supported for directories");
713 StringRef Trimmed(Name);
714 size_t RootPathLen = sys::path::root_path(Trimmed).size();
715 while (Trimmed.size() > RootPathLen &&
716 sys::path::is_separator(Trimmed.back()))
717 Trimmed = Trimmed.slice(0, Trimmed.size()-1);
719 StringRef LastComponent = sys::path::filename(Trimmed);
721 Entry *Result =
nullptr;
724 Result =
new FileEntry(LastComponent, std::move(ExternalContentsPath),
728 Result =
new DirectoryEntry(LastComponent, std::move(EntryArrayContents),
730 0, file_type::directory_file, sys::fs::all_all));
734 StringRef Parent = sys::path::parent_path(Trimmed);
739 for (sys::path::reverse_iterator I = sys::path::rbegin(Parent),
740 E = sys::path::rend(Parent);
744 0, file_type::directory_file, sys::fs::all_all));
750 VFSFromYAMLParser(yaml::Stream &S) : Stream(S) {}
753 bool parse(
yaml::Node *Root, VFSFromYAML *FS) {
754 yaml::MappingNode *Top = dyn_cast<yaml::MappingNode>(Root);
756 error(Root,
"expected mapping node");
760 KeyStatusPair Fields[] = {
761 KeyStatusPair(
"version",
true),
762 KeyStatusPair(
"case-sensitive",
false),
763 KeyStatusPair(
"use-external-names",
false),
764 KeyStatusPair(
"roots",
true),
767 DenseMap<StringRef, KeyStatus> Keys(
768 &Fields[0], Fields +
sizeof(Fields)/
sizeof(Fields[0]));
771 for (yaml::MappingNode::iterator I = Top->begin(), E = Top->end(); I != E;
775 if (!parseScalarString(I->getKey(), Key, KeyBuffer))
778 if (!checkDuplicateOrUnknownKey(I->getKey(), Key, Keys))
781 if (Key ==
"roots") {
782 yaml::SequenceNode *Roots = dyn_cast<yaml::SequenceNode>(I->getValue());
784 error(I->getValue(),
"expected array");
788 for (yaml::SequenceNode::iterator I = Roots->begin(), E = Roots->end();
790 if (Entry *E = parseEntry(&*I))
791 FS->Roots.push_back(E);
795 }
else if (Key ==
"version") {
796 StringRef VersionString;
798 if (!parseScalarString(I->getValue(), VersionString, Storage))
801 if (VersionString.getAsInteger<
int>(10, Version)) {
802 error(I->getValue(),
"expected integer");
806 error(I->getValue(),
"invalid version number");
810 error(I->getValue(),
"version mismatch, expected 0");
813 }
else if (Key ==
"case-sensitive") {
814 if (!parseScalarBool(I->getValue(), FS->CaseSensitive))
816 }
else if (Key ==
"use-external-names") {
817 if (!parseScalarBool(I->getValue(), FS->UseExternalNames))
820 llvm_unreachable(
"key missing from Keys");
827 if (!checkMissingKeys(Top, Keys))
835 DirectoryEntry::~DirectoryEntry() { llvm::DeleteContainerPointers(Contents); }
837 VFSFromYAML::~VFSFromYAML() { llvm::DeleteContainerPointers(Roots); }
840 SourceMgr::DiagHandlerTy DiagHandler,
845 yaml::Stream Stream(Buffer->getMemBufferRef(),
SM);
847 SM.setDiagHandler(DiagHandler, DiagContext);
848 yaml::document_iterator DI = Stream.begin();
850 if (DI == Stream.end() || !Root) {
851 SM.PrintMessage(SMLoc(), SourceMgr::DK_Error,
"expected root node");
855 VFSFromYAMLParser
P(Stream);
857 std::unique_ptr<VFSFromYAML> FS(
new VFSFromYAML(ExternalFS));
858 if (!
P.parse(Root, FS.get()))
864 ErrorOr<Entry *> VFSFromYAML::lookupPath(
const Twine &Path_) {
866 Path_.toVector(Path);
869 if (std::error_code EC = sys::fs::make_absolute(Path))
875 sys::path::const_iterator Start = sys::path::begin(Path);
876 sys::path::const_iterator
End = sys::path::end(Path);
877 for (std::vector<Entry *>::iterator I = Roots.begin(), E = Roots.end();
879 ErrorOr<Entry *> Result = lookupPath(Start, End, *I);
880 if (Result || Result.getError() != llvm::errc::no_such_file_or_directory)
886 ErrorOr<Entry *> VFSFromYAML::lookupPath(sys::path::const_iterator Start,
887 sys::path::const_iterator End,
889 if (Start->equals(
"."))
893 if (CaseSensitive ? !Start->equals(From->getName())
894 : !Start->equals_lower(From->getName()))
909 for (DirectoryEntry::iterator I = DE->contents_begin(),
910 E = DE->contents_end();
912 ErrorOr<Entry *> Result = lookupPath(Start, End, *I);
913 if (Result || Result.getError() != llvm::errc::no_such_file_or_directory)
919 ErrorOr<Status> VFSFromYAML::status(
const Twine &Path, Entry *E) {
920 assert(E !=
nullptr);
921 std::string PathStr(Path.str());
922 if (
FileEntry *F = dyn_cast<FileEntry>(E)) {
923 ErrorOr<Status> S = ExternalFS->status(F->getExternalContentsPath());
924 assert(!S || S->getName() == F->getExternalContentsPath());
925 if (S && !F->useExternalName(UseExternalNames))
928 S->IsVFSMapped =
true;
932 Status S = DE->getStatus();
938 ErrorOr<Status> VFSFromYAML::status(
const Twine &Path) {
939 ErrorOr<Entry *> Result = lookupPath(Path);
941 return Result.getError();
942 return status(Path, *Result);
945 ErrorOr<std::unique_ptr<File>> VFSFromYAML::openFileForRead(
const Twine &Path) {
946 ErrorOr<Entry *> E = lookupPath(Path);
954 auto Result = ExternalFS->openFileForRead(F->getExternalContentsPath());
958 if (!F->useExternalName(UseExternalNames))
959 (*Result)->setName(Path.str());
966 SourceMgr::DiagHandlerTy DiagHandler,
void *DiagContext,
973 static std::atomic<unsigned> UID;
977 return UniqueID(std::numeric_limits<uint64_t>::max(), ID);
982 using namespace llvm::sys;
983 for (StringRef Comp : llvm::make_range(path::begin(Path), path::end(Path)))
984 if (Comp ==
"." || Comp ==
"..")
990 void YAMLVFSWriter::addFileMapping(StringRef VirtualPath, StringRef RealPath) {
991 assert(sys::path::is_absolute(VirtualPath) &&
"virtual path not absolute");
992 assert(sys::path::is_absolute(RealPath) &&
"real path not absolute");
993 assert(!
pathHasTraversal(VirtualPath) &&
"path traversal is not supported");
994 Mappings.emplace_back(VirtualPath, RealPath);
999 llvm::raw_ostream &OS;
1001 inline unsigned getDirIndent() {
return 4 * DirStack.size(); }
1002 inline unsigned getFileIndent() {
return 4 * (DirStack.size() + 1); }
1003 bool containedIn(StringRef Parent, StringRef Path);
1004 StringRef containedPart(StringRef Parent, StringRef Path);
1005 void startDirectory(StringRef Path);
1006 void endDirectory();
1007 void writeEntry(StringRef VPath, StringRef RPath);
1010 JSONWriter(llvm::raw_ostream &OS) : OS(OS) {}
1015 bool JSONWriter::containedIn(StringRef Parent, StringRef Path) {
1016 using namespace llvm::sys;
1018 auto IParent = path::begin(Parent), EParent = path::end(Parent);
1019 for (
auto IChild = path::begin(Path), EChild = path::end(Path);
1020 IParent != EParent && IChild != EChild; ++IParent, ++IChild) {
1021 if (*IParent != *IChild)
1025 return IParent == EParent;
1028 StringRef JSONWriter::containedPart(StringRef Parent, StringRef Path) {
1029 assert(!Parent.empty());
1030 assert(containedIn(Parent, Path));
1031 return Path.slice(Parent.size() + 1, StringRef::npos);
1034 void JSONWriter::startDirectory(StringRef Path) {
1036 DirStack.empty() ? Path : containedPart(DirStack.back(), Path);
1037 DirStack.push_back(Path);
1038 unsigned Indent = getDirIndent();
1039 OS.indent(Indent) <<
"{\n";
1040 OS.indent(Indent + 2) <<
"'type': 'directory',\n";
1041 OS.indent(Indent + 2) <<
"'name': \"" << llvm::yaml::escape(Name) <<
"\",\n";
1042 OS.indent(Indent + 2) <<
"'contents': [\n";
1045 void JSONWriter::endDirectory() {
1046 unsigned Indent = getDirIndent();
1047 OS.indent(Indent + 2) <<
"]\n";
1048 OS.indent(Indent) <<
"}";
1050 DirStack.pop_back();
1053 void JSONWriter::writeEntry(StringRef VPath, StringRef RPath) {
1054 unsigned Indent = getFileIndent();
1055 OS.indent(Indent) <<
"{\n";
1056 OS.indent(Indent + 2) <<
"'type': 'file',\n";
1057 OS.indent(Indent + 2) <<
"'name': \"" << llvm::yaml::escape(VPath) <<
"\",\n";
1058 OS.indent(Indent + 2) <<
"'external-contents': \""
1059 << llvm::yaml::escape(RPath) <<
"\"\n";
1060 OS.indent(Indent) <<
"}";
1065 using namespace llvm::sys;
1069 if (IsCaseSensitive.hasValue())
1070 OS <<
" 'case-sensitive': '"
1071 << (IsCaseSensitive.getValue() ?
"true" :
"false") <<
"',\n";
1072 OS <<
" 'roots': [\n";
1074 if (!Entries.empty()) {
1076 startDirectory(path::parent_path(Entry.
VPath));
1077 writeEntry(path::filename(Entry.
VPath), Entry.
RPath);
1079 for (
const auto &Entry : Entries.slice(1)) {
1080 StringRef Dir = path::parent_path(Entry.
VPath);
1081 if (Dir == DirStack.back())
1084 while (!DirStack.empty() && !containedIn(DirStack.back(), Dir)) {
1089 startDirectory(Dir);
1091 writeEntry(path::filename(Entry.
VPath), Entry.
RPath);
1094 while (!DirStack.empty()) {
1105 void YAMLVFSWriter::write(llvm::raw_ostream &OS) {
1106 std::sort(Mappings.begin(), Mappings.end(),
1108 return LHS.
VPath < RHS.VPath;
1111 JSONWriter(OS).write(Mappings, IsCaseSensitive);
1114 VFSFromYamlDirIterImpl::VFSFromYamlDirIterImpl(
const Twine &_Path,
1116 DirectoryEntry::iterator Begin,
1117 DirectoryEntry::iterator End,
1118 std::error_code &EC)
1119 : Dir(_Path.str()), FS(FS),
Current(Begin), End(End) {
1122 llvm::sys::path::append(PathStr, (*Current)->getName());
1123 llvm::ErrorOr<vfs::Status> S = FS.status(PathStr);
1131 std::error_code VFSFromYamlDirIterImpl::increment() {
1132 assert(
Current != End &&
"cannot iterate past end");
1135 llvm::sys::path::append(PathStr, (*Current)->getName());
1136 llvm::ErrorOr<vfs::Status> S = FS.status(PathStr);
1138 return S.getError();
1143 return std::error_code();
1148 std::error_code &EC)
1152 State = std::make_shared<IterState>();
1159 assert(FS && State && !State->empty() &&
"incrementing past end");
1160 assert(State->top()->isStatusKnown() &&
"non-canonical end iterator");
1162 if (State->top()->isDirectory()) {
1172 while (!State->empty() && State->top().increment(EC) ==
End)
IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
The virtual file system interface.
IntrusiveRefCntPtr< FileSystem > getVFSFromYAML(std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::SourceMgr::DiagHandlerTy DiagHandler, void *DiagContext=nullptr, IntrusiveRefCntPtr< FileSystem > ExternalFS=getRealFileSystem())
Gets a FileSystem for a virtual file system described in YAML format.
An input iterator over the recursive contents of a virtual path, similar to llvm::sys::fs::recursive_...
A file system that allows overlaying one AbstractFileSystem on top of another.
FileSystemList::reverse_iterator iterator
The result of a status operation.
recursive_directory_iterator()
Construct an 'end' iterator.
ID
Defines the set of possible language-specific address spaces.
llvm::sys::fs::UniqueID getUniqueID() const
static bool pathHasTraversal(StringRef Path)
The result type of a method or function.
recursive_directory_iterator & increment(std::error_code &EC)
Equivalent to operator++, with an error code.
Cached information about one file (either on disk or in the virtual file system). ...
ast_type_traits::DynTypedNode Node
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
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 bool classof(const OMPClause *T)
Cached information about one directory (either on disk or in the virtual file system).
An input iterator over the entries in a virtual path, similar to llvm::sys::fs::directory_iterator.
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...