================
@@ -1619,15 +1619,116 @@ StringRef HeaderSearch::getIncludeNameForHeader(const
FileEntry *File) const {
return It->second;
}
+void HeaderSearch::buildHeaderCache(DirectoryEntryRef Dir,
+ ModuleMapDirectoryState &MMState) {
+ if (!MMState.ModuleMapFile)
+ return;
+ const modulemap::ModuleMapFile *ParsedMM =
+ ModMap.getParsedModuleMap(*MMState.ModuleMapFile);
+ if (!ParsedMM)
+ return;
+ const modulemap::ModuleMapFile *ParsedPrivateMM = nullptr;
+ if (MMState.PrivateModuleMapFile)
+ ParsedPrivateMM = ModMap.getParsedModuleMap(*MMState.PrivateModuleMapFile);
+
+ std::function<void(const modulemap::ModuleMapFile &, DirectoryEntryRef,
+ StringRef)>
+ ProcessModuleMapFile = [&](const modulemap::ModuleMapFile &MMF,
+ DirectoryEntryRef MMDir,
+ StringRef PathPrefix) {
+ auto AddToCache = [&](StringRef RelPath, StringRef ModuleName) {
+ if (PathPrefix.empty()) {
+ MMState.HeaderToModules[RelPath].push_back(ModuleName);
+ } else {
+ SmallString<128> FullPath(PathPrefix);
+ llvm::sys::path::append(FullPath, RelPath);
+ MMState.HeaderToModules[FullPath].push_back(ModuleName);
+ }
+ };
+
+ auto ProcessExternModuleDecl =
+ [&](const modulemap::ExternModuleDecl &EMD) {
+ StringRef FileNameRef = EMD.Path;
+ SmallString<128> ModuleMapFileName;
+ if (llvm::sys::path::is_relative(FileNameRef)) {
+ ModuleMapFileName = MMDir.getName();
+ llvm::sys::path::append(ModuleMapFileName, EMD.Path);
+ FileNameRef = ModuleMapFileName;
+ }
+ if (auto EFile = FileMgr.getOptionalFileRef(FileNameRef)) {
+ if (auto *ExtMMF = ModMap.getParsedModuleMap(*EFile)) {
+ // Compute the new prefix by appending the extern module's
+ // directory (from the extern declaration path) to the
current
+ // prefix.
+ SmallString<128> NewPrefix(PathPrefix);
+ StringRef ExternDir = llvm::sys::path::parent_path(EMD.Path);
+ if (!ExternDir.empty())
+ llvm::sys::path::append(NewPrefix, ExternDir);
+ ProcessModuleMapFile(*ExtMMF, EFile->getDir(), NewPrefix);
+ }
+ }
+ };
+
+ std::function<void(const modulemap::ModuleDecl &, StringRef)>
+ ProcessModule = [&](const modulemap::ModuleDecl &MD,
+ StringRef ModuleName) {
+ // Skip inferred submodules (module *)
+ if (MD.Id.front().first == "*")
+ return;
+ for (const auto &Decl : MD.Decls) {
+ std::visit(
+ llvm::makeVisitor(
+ [&](const modulemap::HeaderDecl &HD) {
+ if (HD.Umbrella) {
+
MMState.UmbrellaHeaderModules.push_back(ModuleName);
+ } else {
+ AddToCache(HD.Path, ModuleName);
+ }
+ },
+ [&](const modulemap::UmbrellaDirDecl &UDD) {
+ SmallString<128> FullPath(PathPrefix);
+ llvm::sys::path::append(FullPath, UDD.Path);
+ MMState.UmbrellaDirModules.push_back(std::make_pair(
+ std::string(FullPath), ModuleName));
----------------
jansvoboda11 wrote:
Documentation for `MMState.UmbrellaDirModules` says the first element in the
pair is a relative path. I guess `FullPath` here is not an absolute path, but a
(relative) path from the top-level module map that (transitively) includes the
current module map? Might be worth finding more descriptive name.
https://github.com/llvm/llvm-project/pull/181916
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits