diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-07-02 19:58:25 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-07-13 12:40:22 (GMT) |
commit | c9df4568da7155d2c333e19f1b649a391633ccf0 (patch) | |
tree | a6298a43c9f21f57e05fb412666de41732289572 /Source | |
parent | 71f1483aac64ccb3341376558f943021b1195e80 (diff) | |
download | CMake-c9df4568da7155d2c333e19f1b649a391633ccf0.zip CMake-c9df4568da7155d2c333e19f1b649a391633ccf0.tar.gz CMake-c9df4568da7155d2c333e19f1b649a391633ccf0.tar.bz2 |
cmCxxModuleMapper: factor out transitive usage computation
Clang will need this in the future.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCxxModuleMapper.cxx | 87 |
1 files changed, 57 insertions, 30 deletions
diff --git a/Source/cmCxxModuleMapper.cxx b/Source/cmCxxModuleMapper.cxx index bb650ea..63e6702 100644 --- a/Source/cmCxxModuleMapper.cxx +++ b/Source/cmCxxModuleMapper.cxx @@ -74,6 +74,59 @@ CxxBmiLocation CxxModuleLocations::BmiGeneratorPathForModule( namespace { +struct TransitiveUsage +{ + TransitiveUsage(std::string name, std::string location, LookupMethod method) + : LogicalName(std::move(name)) + , Location(std::move(location)) + , Method(method) + { + } + + std::string LogicalName; + std::string Location; + LookupMethod Method; +}; + +std::vector<TransitiveUsage> GetTransitiveUsages( + CxxModuleLocations const& loc, std::vector<cmSourceReqInfo> const& required, + CxxModuleUsage const& usages) +{ + std::set<std::string> transitive_usage_directs; + std::set<std::string> transitive_usage_names; + + std::vector<TransitiveUsage> all_usages; + + for (auto const& r : required) { + auto bmi_loc = loc.BmiGeneratorPathForModule(r.LogicalName); + if (bmi_loc.IsKnown()) { + all_usages.emplace_back(r.LogicalName, bmi_loc.Location(), r.Method); + transitive_usage_directs.insert(r.LogicalName); + + // Insert transitive usages. + auto transitive_usages = usages.Usage.find(r.LogicalName); + if (transitive_usages != usages.Usage.end()) { + transitive_usage_names.insert(transitive_usages->second.begin(), + transitive_usages->second.end()); + } + } + } + + for (auto const& transitive_name : transitive_usage_names) { + if (transitive_usage_directs.count(transitive_name)) { + continue; + } + + auto module_ref = usages.Reference.find(transitive_name); + if (module_ref != usages.Reference.end()) { + all_usages.emplace_back(transitive_name, module_ref->second.Path, + module_ref->second.Method); + } + } + + return all_usages; +} + std::string CxxModuleMapContentClang(CxxModuleLocations const& loc, cmScanDepInfo const& obj) { @@ -180,37 +233,11 @@ std::string CxxModuleMapContentMsvc(CxxModuleLocations const& loc, } } - std::set<std::string> transitive_usage_directs; - std::set<std::string> transitive_usage_names; + auto all_usages = GetTransitiveUsages(loc, obj.Requires, usages); + for (auto const& usage : all_usages) { + auto flag = flag_for_method(usage.Method); - for (auto const& r : obj.Requires) { - auto bmi_loc = loc.BmiGeneratorPathForModule(r.LogicalName); - if (bmi_loc.IsKnown()) { - auto flag = flag_for_method(r.Method); - - mm << flag << ' ' << r.LogicalName << '=' << bmi_loc.Location() << "\n"; - transitive_usage_directs.insert(r.LogicalName); - - // Insert transitive usages. - auto transitive_usages = usages.Usage.find(r.LogicalName); - if (transitive_usages != usages.Usage.end()) { - transitive_usage_names.insert(transitive_usages->second.begin(), - transitive_usages->second.end()); - } - } - } - - for (auto const& transitive_name : transitive_usage_names) { - if (transitive_usage_directs.count(transitive_name)) { - continue; - } - - auto module_ref = usages.Reference.find(transitive_name); - if (module_ref != usages.Reference.end()) { - auto flag = flag_for_method(module_ref->second.Method); - mm << flag << ' ' << transitive_name << '=' << module_ref->second.Path - << "\n"; - } + mm << flag << ' ' << usage.LogicalName << '=' << usage.Location << '\n'; } return mm.str(); |