Added handling of template methods

This commit is contained in:
Bartek Kryza
2021-03-28 23:36:13 +02:00
parent b61143a5b2
commit 928e5f5baa
4 changed files with 57 additions and 4 deletions

View File

@@ -232,13 +232,18 @@ struct diagram {
auto it = std::find(classes.begin(), classes.end(), c);
if (it == classes.end())
classes.emplace_back(std::move(c));
else
spdlog::debug("Class {} already in the model", c.name);
}
void add_enum(enum_ &&e)
{
spdlog::debug("Adding enum: {}", e.name);
auto it = std::find(enums.begin(), enums.end(), e);
if (it == enums.end())
enums.emplace_back(std::move(e));
else
spdlog::debug("Enum {} already in the model", e.name);
}
std::string to_alias(const std::vector<std::string> &using_namespaces,

View File

@@ -81,9 +81,18 @@ void tu_visitor::operator()(const cppast::cpp_entity &file)
cx::util::full_name(e), cppast::to_string(e.kind()));
auto &cls = static_cast<const cppast::cpp_class &>(e);
if (ctx.config.should_include(cx::util::fully_prefixed(cls)))
process_class_declaration(cls);
if (cls.begin() == cls.end()) {
auto &clsdef = static_cast<const cppast::cpp_class &>(
cppast::get_definition(ctx.entity_index, cls).value());
if (ctx.config.should_include(
cx::util::fully_prefixed(clsdef)))
process_class_declaration(clsdef);
}
else {
if (ctx.config.should_include(
cx::util::fully_prefixed(cls)))
process_class_declaration(cls);
}
}
else if (e.kind() == cppast::cpp_entity_kind::enum_t) {
spdlog::debug("========== Visiting '{}' - {}",
@@ -161,6 +170,11 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls)
auto &mf = static_cast<const cppast::cpp_function &>(child);
process_static_method(mf, c, last_access_specifier);
}
else if (child.kind() == cppast::cpp_entity_kind::function_template_t) {
auto &tm =
static_cast<const cppast::cpp_function_template &>(child);
process_template_method(tm, c, last_access_specifier);
}
else if (child.kind() == cppast::cpp_entity_kind::constructor_t) {
auto &mc = static_cast<const cppast::cpp_constructor &>(child);
process_constructor(mc, c, last_access_specifier);
@@ -397,6 +411,34 @@ void tu_visitor::process_method(const cppast::cpp_member_function &mf,
for (auto &param : mf.parameters())
process_function_parameter(param, m);
spdlog::debug("Adding method: {}", m.name);
c.methods.emplace_back(std::move(m));
}
void tu_visitor::process_template_method(
const cppast::cpp_function_template &mf, class_ &c,
cppast::cpp_access_specifier_kind as)
{
class_method m;
m.name = util::trim(mf.name());
m.type = cppast::to_string(
static_cast<const cppast::cpp_member_function &>(mf.function())
.return_type());
m.is_pure_virtual = false; // cppast::is_pure(mf.virtual_info());
m.is_virtual = false; // cppast::is_virtual(mf.virtual_info());
m.is_const = cppast::is_const(
static_cast<const cppast::cpp_member_function &>(mf.function())
.cv_qualifier());
m.is_defaulted = false; // cursor.is_method_defaulted();
m.is_static = false; // cppast::is_static(mf.storage_class());
m.scope = detail::cpp_access_specifier_to_scope(as);
for (auto &param : mf.function().parameters())
process_function_parameter(param, m);
spdlog::debug("Adding template method: {}", m.name);
c.methods.emplace_back(std::move(m));
}
@@ -416,6 +458,8 @@ void tu_visitor::process_static_method(const cppast::cpp_function &mf,
for (auto &param : mf.parameters())
process_function_parameter(param, m);
spdlog::debug("Adding static method: {}", m.name);
c.methods.emplace_back(std::move(m));
}

View File

@@ -24,6 +24,7 @@
#include <clang-c/CXCompilationDatabase.h>
#include <clang-c/Index.h>
#include <cppast/cpp_friend.hpp>
#include <cppast/cpp_function_template.hpp>
#include <cppast/cpp_member_function.hpp>
#include <cppast/cpp_member_variable.hpp>
#include <cppast/cpp_template_parameter.hpp>
@@ -94,6 +95,10 @@ public:
clanguml::model::class_diagram::class_ &c,
cppast::cpp_access_specifier_kind as);
void process_template_method(const cppast::cpp_function_template &mf,
clanguml::model::class_diagram::class_ &c,
cppast::cpp_access_specifier_kind as);
void process_static_method(const cppast::cpp_function &mf,
clanguml::model::class_diagram::class_ &c,
cppast::cpp_access_specifier_kind as);

View File

@@ -2,7 +2,6 @@
#include <map>
#include <numeric>
#include <string>
#include <variant>
namespace ABCD {
template <typename T> struct F {