66#include < clang/Tooling/Tooling.h>
77#include < iostream>
88#include < sstream>
9+ #include < variant>
910#include < llvm/ADT/StringSwitch.h>
1011#include < llvm/Support/Path.h>
1112
@@ -31,9 +32,9 @@ static std::error_code addHeaderInclude(StringRef headerName, std::vector<SmallS
3132 return std::error_code ();
3233}
3334
34- static std::error_code addHeaderInclude (const FileEntry* header, std::vector<SmallString<256 >>& includes)
35+ static std::error_code addHeaderInclude (FileEntryRef header, std::vector<SmallString<256 >>& includes)
3536{
36- return addHeaderInclude (header-> getName (), includes);
37+ return addHeaderInclude (header. getName (), includes);
3738}
3839
3940static std::error_code collectModuleHeaderIncludes (FileManager& fileMgr, ModuleMap& modMap, const Module* module , std::vector<SmallString<256 >>& includes)
@@ -42,17 +43,15 @@ static std::error_code collectModuleHeaderIncludes(FileManager& fileMgr, ModuleM
4243 if (!module ->isAvailable ())
4344 return std::error_code ();
4445
45- if (module ->Umbrella && module ->Umbrella .is <FileEntryRef>()) {
46- const FileEntry* umbrellaHeader = module ->Umbrella .get <FileEntryRef>();
47- if (std::error_code err = addHeaderInclude (umbrellaHeader, includes))
46+ if (const auto * umbrellaHeader = std::get_if<FileEntryRef>(&module ->Umbrella )) {
47+ if (std::error_code err = addHeaderInclude (*umbrellaHeader, includes))
4848 return err;
4949 }
50- else if (module ->Umbrella && module ->Umbrella .is <DirectoryEntryRef>()) {
51- const DirectoryEntryRef umbrellaDir = module ->Umbrella .get <DirectoryEntryRef>();
50+ else if (const auto * umbrellaDir = std::get_if<DirectoryEntryRef>(&module ->Umbrella )) {
5251 // Add all of the headers we find in this subdirectory.
5352 std::error_code ec;
5453 SmallString<128 > dirNative;
55- path::native (umbrellaDir. getName (), dirNative);
54+ path::native (umbrellaDir-> getName (), dirNative);
5655 for (fs::recursive_directory_iterator dir (dirNative.str (), ec), dirEnd; dir != dirEnd && !ec; dir.increment (ec)) {
5756 // Check whether this entry has an extension typically associated with headers.
5857 if (!llvm::StringSwitch<bool >(path::extension (dir->path ()))
@@ -77,8 +76,8 @@ static std::error_code collectModuleHeaderIncludes(FileManager& fileMgr, ModuleM
7776 if (ec)
7877 return ec;
7978 } else {
80- for (auto header : module -> Headers [Module::HK_Normal] ) {
81- if (auto err = addHeaderInclude (header. Entry , includes))
79+ for (FileEntryRef header : const_cast <Module*>( module )-> getTopHeaders (fileMgr) ) {
80+ if (auto err = addHeaderInclude (header, includes))
8281 return err;
8382 }
8483 }
0 commit comments