aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2023-05-30 22:58:49 -0700
committerJan Svoboda <jan_svoboda@apple.com>2023-06-01 10:11:26 -0700
commit2e1ec4c737f93925e29e4037e758b940c6fef448 (patch)
tree2082852d1bf0ce8e547e060068ad53077625f2fa
parentf09729042d8f99e1b896f6a04ebf6f842f6cc7ad (diff)
downloadllvm-2e1ec4c737f93925e29e4037e758b940c6fef448.zip
llvm-2e1ec4c737f93925e29e4037e758b940c6fef448.tar.gz
llvm-2e1ec4c737f93925e29e4037e758b940c6fef448.tar.bz2
[clang] NFCI: Split `HeaderSearch::findAllModulesForHeader()`
This mimics the `ModuleMap` API and enables D151854, where the `AllowCreation = true` function needs `FileEntryRef` but `AllowCreation = false` functions is happy with plain `FileEntry`. No functional change intended. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D151853
-rw-r--r--clang/include/clang/Lex/HeaderSearch.h8
-rw-r--r--clang/include/clang/Lex/ModuleMap.h6
-rw-r--r--clang/lib/Lex/HeaderSearch.cpp15
-rw-r--r--clang/lib/Lex/ModuleMap.cpp4
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp3
5 files changed, 22 insertions, 14 deletions
diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h
index 5386b7a..947fb83 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -670,8 +670,12 @@ public:
///
/// \ref findModuleForHeader should typically be used instead of this.
ArrayRef<ModuleMap::KnownHeader>
- findAllModulesForHeader(const FileEntry *File,
- bool AllowCreation = true) const;
+ findAllModulesForHeader(const FileEntry *File) const;
+
+ /// Like \ref findAllModulesForHeader, but do not attempt to infer module
+ /// ownership from umbrella headers if we've not already done so.
+ ArrayRef<ModuleMap::KnownHeader>
+ findResolvedModulesForHeader(const FileEntry *File) const;
/// Read the contents of the given module map file.
///
diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h
index 6f584ca..55797a3 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -446,13 +446,9 @@ public:
/// and does not consult the external source. (Those checks are the
/// responsibility of \ref HeaderSearch.)
///
- /// \param AllowCreation Whether to allow inference of a new submodule, or to
- /// only return existing known modules.
- ///
/// Typically, \ref findModuleForHeader should be used instead, as it picks
/// the preferred module for the header.
- ArrayRef<KnownHeader> findAllModulesForHeader(const FileEntry *File,
- bool AllowCreation = true);
+ ArrayRef<KnownHeader> findAllModulesForHeader(const FileEntry *File);
/// Like \ref findAllModulesForHeader, but do not attempt to infer module
/// ownership from umbrella headers if we've not already done so.
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 16d64be..0ee61aa 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1570,14 +1570,23 @@ HeaderSearch::findModuleForHeader(const FileEntry *File, bool AllowTextual,
}
ArrayRef<ModuleMap::KnownHeader>
-HeaderSearch::findAllModulesForHeader(const FileEntry *File,
- bool AllowCreation) const {
+HeaderSearch::findAllModulesForHeader(const FileEntry *File) const {
if (ExternalSource) {
// Make sure the external source has handled header info about this file,
// which includes whether the file is part of a module.
(void)getExistingFileInfo(File);
}
- return ModMap.findAllModulesForHeader(File, AllowCreation);
+ return ModMap.findAllModulesForHeader(File);
+}
+
+ArrayRef<ModuleMap::KnownHeader>
+HeaderSearch::findResolvedModulesForHeader(const FileEntry *File) const {
+ if (ExternalSource) {
+ // Make sure the external source has handled header info about this file,
+ // which includes whether the file is part of a module.
+ (void)getExistingFileInfo(File);
+ }
+ return ModMap.findResolvedModulesForHeader(File);
}
static bool suggestModule(HeaderSearch &HS, const FileEntry *File,
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 93f770f..7fc810f 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -684,12 +684,12 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File) {
}
ArrayRef<ModuleMap::KnownHeader>
-ModuleMap::findAllModulesForHeader(const FileEntry *File, bool AllowCreation) {
+ModuleMap::findAllModulesForHeader(const FileEntry *File) {
HeadersMap::iterator Known = findKnownHeader(File);
if (Known != Headers.end())
return Known->second;
- if (AllowCreation && findOrCreateModuleForHeaderInUmbrellaDir(File))
+ if (findOrCreateModuleForHeaderInUmbrellaDir(File))
return Headers.find(File)->second;
return std::nullopt;
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 6fa2cd6..ee63602 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -185,8 +185,7 @@ std::set<const FileEntry *> GetAffectingModuleMaps(const Preprocessor &PP,
if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
continue;
- for (const auto &KH :
- HS.findAllModulesForHeader(File, /*AllowCreation=*/false)) {
+ for (const auto &KH : HS.findResolvedModulesForHeader(File)) {
if (!KH.getModule())
continue;
ModulesToProcess.push_back(KH.getModule());