From 043c13affbc7587b87883ebfbf2f64039c24e556 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Tue, 9 Jan 2024 11:41:34 +0100 Subject: [PATCH] Fixed module handling on LLVM versions < 15.0.0 --- src/common/visitor/translation_unit_visitor.cc | 11 +++++++++-- .../visitor/translation_unit_visitor.cc | 12 +++++++++++- tests/t00008/test_case.h | 5 ----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/common/visitor/translation_unit_visitor.cc b/src/common/visitor/translation_unit_visitor.cc index 40441b71..80ddc9db 100644 --- a/src/common/visitor/translation_unit_visitor.cc +++ b/src/common/visitor/translation_unit_visitor.cc @@ -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 "" 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 \ No newline at end of file diff --git a/src/package_diagram/visitor/translation_unit_visitor.cc b/src/package_diagram/visitor/translation_unit_visitor.cc index a48ce9f2..1794bee2 100644 --- a/src/package_diagram/visitor/translation_unit_visitor.cc +++ b/src/package_diagram/visitor/translation_unit_visitor.cc @@ -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); diff --git a/tests/t00008/test_case.h b/tests/t00008/test_case.h index 28fb7676..480500be 100644 --- a/tests/t00008/test_case.h +++ b/tests/t00008/test_case.h @@ -63,12 +63,7 @@ TEST_CASE("t00008", "[test-case][class]") using namespace json; -#if LLVM_VERSION_MAJOR >= 16 REQUIRE(IsClassTemplate(j, "A")); -#else - REQUIRE(IsClassTemplate( - j, "A")); -#endif REQUIRE(IsClassTemplate(j, "E::nested_template")); REQUIRE(IsClass(j, "E::nested_template"));