Fixed module handling on LLVM versions < 15.0.0

This commit is contained in:
Bartek Kryza
2024-01-09 11:41:34 +01:00
parent d8a49f4ac5
commit 043c13affb
3 changed files with 20 additions and 8 deletions

View File

@@ -171,12 +171,19 @@ void translation_unit_visitor::set_owning_module(
if (const clang::Module *module = decl.getOwningModule();
module != nullptr) {
std::string module_name = module->Name;
if (module->isPrivateModule()) {
bool is_private{false};
#if LLVM_VERSION_MAJOR < 15
is_private =
module->Kind == clang::Module::ModuleKind::PrivateModuleFragment;
#else
is_private = module->isPrivateModule();
#endif
if (is_private) {
// Clang just maps private modules names to "<private>"
module_name = module->getTopLevelModule()->Name;
}
element.set_module(module_name);
element.set_module_private(module->isPrivateModule());
element.set_module_private(is_private);
}
}
} // namespace clanguml::common::visitor

View File

@@ -247,8 +247,13 @@ void translation_unit_visitor::add_relationships(
}
std::string module_path_str = module->Name;
if (module->isPrivateModule())
#if LLVM_VERSION_MAJOR < 15
if (module->Kind == clang::Module::ModuleKind::PrivateModuleFragment) {
#else
if (module->isPrivateModule()) {
#endif
module_path_str = module->getTopLevelModule()->Name;
}
common::model::path module_path{
module_path_str, common::model::path_type::kModule};
@@ -326,7 +331,12 @@ common::id_t translation_unit_visitor::get_package_id(const clang::Decl *cls)
const auto *module = cls->getOwningModule();
if (module != nullptr) {
std::string module_path = module->Name;
#if LLVM_VERSION_MAJOR < 15
if (module->Kind ==
clang::Module::ModuleKind::PrivateModuleFragment) {
#else
if (module->isPrivateModule()) {
#endif
module_path = module->getTopLevelModule()->Name;
}
return common::to_id(module_path);