Added test case for configurable type aliases

This commit is contained in:
Bartek Kryza
2022-09-05 23:34:42 +02:00
parent f311aa37af
commit 381994df99
10 changed files with 137 additions and 13 deletions

View File

@@ -73,7 +73,8 @@ void generator::generate_alias(const class_ &c, std::ostream &ostr) const
assert(!full_name.empty());
ostr << class_type << " \"" << render_name(full_name);
ostr << class_type << " \""
<< m_config.simplify_template_type(render_name(full_name));
ostr << "\" as " << c.alias() << '\n';
@@ -130,7 +131,8 @@ void generator::generate(const class_ &c, std::ostream &ostr) const
if (m.is_static())
ostr << "{static} ";
std::string type{m.type()};
std::string type{
uns.relative(m_config.simplify_template_type(m.type()))};
ostr << plantuml_common::to_plantuml(m.access()) << m.name();
@@ -140,7 +142,8 @@ void generator::generate(const class_ &c, std::ostream &ostr) const
std::vector<std::string> params;
std::transform(m.parameters().cbegin(), m.parameters().cend(),
std::back_inserter(params), [this](const auto &mp) {
return mp.to_string(m_config.using_namespace());
return m_config.simplify_template_type(
mp.to_string(m_config.using_namespace()));
});
auto args_string = fmt::format("{}", fmt::join(params, ", "));
if (m_config.generate_method_arguments() ==
@@ -162,7 +165,7 @@ void generator::generate(const class_ &c, std::ostream &ostr) const
if (m.is_defaulted())
ostr << " = default";
ostr << " : " << uns.relative(type);
ostr << " : " << type;
if (m_config.generate_links) {
generate_link(ostr, m);
@@ -231,7 +234,8 @@ void generator::generate(const class_ &c, std::ostream &ostr) const
ostr << "{static} ";
ostr << plantuml_common::to_plantuml(m.access()) << m.name() << " : "
<< render_name(uns.relative(m.type()));
<< render_name(
uns.relative(m_config.simplify_template_type(m.type())));
if (m_config.generate_links) {
generate_link(ostr, m);

View File

@@ -701,7 +701,8 @@ void translation_unit_visitor::process_method(
return;
class_method method{detail::access_specifier_to_access_t(mf.getAccess()),
util::trim(mf.getNameAsString()), mf.getReturnType().getAsString()};
util::trim(mf.getNameAsString()),
common::to_string(mf.getReturnType(), mf.getASTContext())};
method.is_pure_virtual(mf.isPure());
method.is_virtual(mf.isVirtual());
@@ -865,7 +866,7 @@ void translation_unit_visitor::process_function_parameter(
if (parameter.skip())
return;
parameter.set_type(p.getType().getAsString());
parameter.set_type(common::to_string(p.getType(), p.getASTContext()));
if (p.hasDefaultArg()) {
const auto *default_arg = p.getDefaultArg();

View File

@@ -105,6 +105,7 @@ std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx,
// Remove trailing spaces after commas in template arguments
clanguml::util::replace_all(result, ", ", ",");
clanguml::util::replace_all(result, "> >", ">>");
return result;
}

View File

@@ -102,6 +102,18 @@ void inheritable_diagram_options::inherit(
relative_to.override(parent.relative_to);
}
std::string inheritable_diagram_options::simplify_template_type(
std::string full_name) const
{
const auto &aliases = template_aliases();
for (const auto &[pattern, replacement] : aliases) {
util::replace_all(full_name, pattern, replacement);
}
return full_name;
}
std::vector<std::string> diagram::get_translation_units(
const std::filesystem::path &root_directory) const
{

View File

@@ -140,6 +140,8 @@ struct inheritable_diagram_options {
option<template_aliases_t> template_aliases{"template_aliases"};
void inherit(const inheritable_diagram_options &parent);
std::string simplify_template_type(std::string full_name) const;
};
struct diagram : public inheritable_diagram_options {