Skip generation of empty or invalid relationships in PlantUML output

This commit is contained in:
Bartek Kryza
2021-05-22 14:09:39 +02:00
parent 6cc49c2660
commit 08f00889e2
6 changed files with 145 additions and 63 deletions

View File

@@ -17,6 +17,7 @@
*/
#pragma once
#include "util/error.h"
#include "util/util.h"
#include <clang-c/CXCompilationDatabase.h>
@@ -174,6 +175,13 @@ public:
void add_relationship(class_relationship &&cr)
{
if (cr.destination.empty() || type_aliases.count(cr.destination) == 0) {
LOG_WARN(
"Skipping relationship '{}' - {} - '{}' due to missing alias",
cr.destination, to_string(cr.type), usr);
return;
}
auto it = std::find(relationships.begin(), relationships.end(), cr);
if (it == relationships.end())
relationships.emplace_back(std::move(cr));
@@ -281,7 +289,8 @@ struct diagram {
}
}
return full_name;
throw error::uml_alias_missing(
fmt::format("Missing alias for {}", full_name));
}
std::string usr_to_name(const std::vector<std::string> &using_namespaces,

View File

@@ -659,9 +659,12 @@ void tu_visitor::process_template_method(
{
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());
if (mf.function().kind() == cppast::cpp_entity_kind::constructor_t)
m.type = "void";
else
m.type = cppast::to_string(
static_cast<const cppast::cpp_member_function &>(mf.function())
.return_type());
m.is_pure_virtual = false;
m.is_virtual = false;
m.is_const = cppast::is_const(
@@ -747,16 +750,6 @@ void tu_visitor::process_function_parameter(
// so we have to deduce the correct namespace prefix of the
// template which is being instantiated
mp.type = cppast::to_string(param.type());
auto &template_instantiation_type =
static_cast<const cppast::cpp_template_instantiation_type &>(
param_type);
auto &primary_template_entity =
template_instantiation_type.primary_template();
auto trawname = cppast::to_string(template_instantiation_type);
auto pte = cx::util::fully_prefixed(ctx.namespace_,
primary_template_entity.get(ctx.entity_index)[0].get());
}
else {
mp.type = cppast::to_string(param.type());
@@ -885,6 +878,13 @@ void tu_visitor::process_template_template_parameter(
void tu_visitor::process_friend(const cppast::cpp_friend &f, class_ &parent)
{
// Only process friends to other classes or class templates
if (!f.entity() ||
(f.entity().value().kind() != cppast::cpp_entity_kind::class_t) &&
(f.entity().value().kind() !=
cppast::cpp_entity_kind::class_template_t))
return;
class_relationship r;
r.type = relationship_t::kFriendship;
r.label = "<<friend>>";