Added method type diagram filter (#145)
This commit is contained in:
@@ -186,7 +186,7 @@ void generator::generate(const class_ &c, std::ostream &ostr) const
|
||||
ostr << "__\n";
|
||||
|
||||
for (const auto &m : members) {
|
||||
if (!m_model.should_include(m.access()))
|
||||
if (!m_model.should_include(m))
|
||||
continue;
|
||||
|
||||
if (!m_config.include_relations_also_as_members() &&
|
||||
@@ -232,7 +232,7 @@ void generator::generate_methods(
|
||||
sort_class_elements(sorted_methods);
|
||||
|
||||
for (const auto &m : sorted_methods) {
|
||||
if (!m_model.should_include(m.access()))
|
||||
if (!m_model.should_include(m))
|
||||
continue;
|
||||
|
||||
generate_method(m, ostr);
|
||||
@@ -250,7 +250,7 @@ generator::method_groups_t generator::group_methods(
|
||||
std::vector<class_method> filtered_methods;
|
||||
std::copy_if(methods.cbegin(), methods.cend(),
|
||||
std::back_inserter(filtered_methods),
|
||||
[this](auto &m) { return m_model.should_include(m.access()); });
|
||||
[this](auto &m) { return m_model.should_include(m); });
|
||||
|
||||
for (const auto &g : method_groups_) {
|
||||
result[g] = {};
|
||||
|
||||
@@ -18,11 +18,22 @@
|
||||
|
||||
#include "diagram.h"
|
||||
|
||||
#include "common/model/diagram_filter.h"
|
||||
#include "util/error.h"
|
||||
#include "util/util.h"
|
||||
|
||||
namespace clanguml::class_diagram::model {
|
||||
|
||||
bool diagram::should_include(const class_member &m) const
|
||||
{
|
||||
return filter().should_include(m);
|
||||
}
|
||||
|
||||
bool diagram::should_include(const class_method &m) const
|
||||
{
|
||||
return filter().should_include(m);
|
||||
}
|
||||
|
||||
const common::reference_vector<class_> &diagram::classes() const
|
||||
{
|
||||
return element_view<class_>::view();
|
||||
|
||||
@@ -58,6 +58,12 @@ public:
|
||||
|
||||
diagram_t type() const override;
|
||||
|
||||
using common::model::diagram::should_include;
|
||||
|
||||
bool should_include(const class_member &m) const;
|
||||
|
||||
bool should_include(const class_method &m) const;
|
||||
|
||||
opt_ref<diagram_element> get(const std::string &full_name) const override;
|
||||
|
||||
opt_ref<diagram_element> get(diagram_element::id_t id) const override;
|
||||
|
||||
@@ -1354,10 +1354,13 @@ void translation_unit_visitor::process_method(
|
||||
process_function_parameter_find_relationships_in_autotype(c, atsp);
|
||||
}
|
||||
|
||||
LOG_DBG("Adding method: {}", method.name());
|
||||
if (diagram().should_include(method)) {
|
||||
LOG_DBG("Adding method: {}", method.name());
|
||||
|
||||
c.add_method(std::move(method));
|
||||
c.add_method(std::move(method));
|
||||
}
|
||||
}
|
||||
|
||||
void translation_unit_visitor::process_method_properties(
|
||||
const clang::CXXMethodDecl &mf, const class_ &c,
|
||||
const std::string &method_name, class_method &method) const
|
||||
@@ -1471,9 +1474,11 @@ void translation_unit_visitor::process_template_method(
|
||||
process_function_parameter(*param, method, c);
|
||||
}
|
||||
|
||||
LOG_DBG("Adding method: {}", method.name());
|
||||
if (diagram().should_include(method)) {
|
||||
LOG_DBG("Adding method: {}", method.name());
|
||||
|
||||
c.add_method(std::move(method));
|
||||
c.add_method(std::move(method));
|
||||
}
|
||||
}
|
||||
|
||||
bool translation_unit_visitor::find_relationships(const clang::QualType &type,
|
||||
|
||||
@@ -59,6 +59,7 @@ public:
|
||||
std::string name() const;
|
||||
|
||||
void set_filter(std::unique_ptr<diagram_filter> filter);
|
||||
const diagram_filter &filter() const { return *filter_; }
|
||||
|
||||
void set_complete(bool complete);
|
||||
bool complete() const;
|
||||
|
||||
@@ -127,6 +127,18 @@ tvl::value_t filter_visitor::match(
|
||||
return {};
|
||||
}
|
||||
|
||||
tvl::value_t filter_visitor::match(
|
||||
const diagram &d, const class_diagram::model::class_method &m) const
|
||||
{
|
||||
return match(d, m.access());
|
||||
}
|
||||
|
||||
tvl::value_t filter_visitor::match(
|
||||
const diagram &d, const class_diagram::model::class_member &m) const
|
||||
{
|
||||
return match(d, m.access());
|
||||
}
|
||||
|
||||
bool filter_visitor::is_inclusive() const
|
||||
{
|
||||
return type_ == filter_t::kInclusive;
|
||||
@@ -236,6 +248,37 @@ tvl::value_t element_type_filter::match(
|
||||
});
|
||||
}
|
||||
|
||||
method_type_filter::method_type_filter(
|
||||
filter_t type, std::vector<config::method_type> method_types)
|
||||
: filter_visitor{type}
|
||||
, method_types_{std::move(method_types)}
|
||||
{
|
||||
}
|
||||
|
||||
tvl::value_t method_type_filter::match(
|
||||
const diagram &d, const class_diagram::model::class_method &m) const
|
||||
{
|
||||
return tvl::any_of(
|
||||
method_types_.begin(), method_types_.end(), [&m](auto mt) {
|
||||
switch (mt) {
|
||||
case config::method_type::constructor:
|
||||
return m.is_constructor() || m.is_destructor();
|
||||
case config::method_type::assignment:
|
||||
return m.is_copy_assignment() || m.is_move_assignment();
|
||||
case config::method_type::operator_:
|
||||
return m.is_operator();
|
||||
case config::method_type::defaulted:
|
||||
return m.is_defaulted();
|
||||
case config::method_type::deleted:
|
||||
return m.is_deleted();
|
||||
case config::method_type::static_:
|
||||
return m.is_static();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
subclass_filter::subclass_filter(filter_t type, std::vector<std::string> roots)
|
||||
: filter_visitor{type}
|
||||
, roots_{std::move(roots)}
|
||||
@@ -494,6 +537,36 @@ tvl::value_t paths_filter::match(
|
||||
return false;
|
||||
}
|
||||
|
||||
class_method_filter::class_method_filter(filter_t type,
|
||||
std::unique_ptr<access_filter> af, std::unique_ptr<method_type_filter> mtf)
|
||||
: filter_visitor{type}
|
||||
, access_filter_{std::move(af)}
|
||||
, method_type_filter_{std::move(mtf)}
|
||||
{
|
||||
}
|
||||
|
||||
tvl::value_t class_method_filter::match(
|
||||
const diagram &d, const class_diagram::model::class_method &m) const
|
||||
{
|
||||
tvl::value_t res = tvl::or_(
|
||||
access_filter_->match(d, m.access()), method_type_filter_->match(d, m));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
class_member_filter::class_member_filter(
|
||||
filter_t type, std::unique_ptr<access_filter> af)
|
||||
: filter_visitor{type}
|
||||
, access_filter_{std::move(af)}
|
||||
{
|
||||
}
|
||||
|
||||
tvl::value_t class_member_filter::match(
|
||||
const diagram &d, const class_diagram::model::class_member &m) const
|
||||
{
|
||||
return access_filter_->match(d, m.access());
|
||||
}
|
||||
|
||||
diagram_filter::diagram_filter(
|
||||
const common::model::diagram &d, const config::diagram &c)
|
||||
: diagram_{d}
|
||||
@@ -541,6 +614,18 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
add_inclusive_filter(std::make_unique<paths_filter>(
|
||||
filter_t::kInclusive, c.root_directory(), c.include().paths));
|
||||
|
||||
add_inclusive_filter(
|
||||
std::make_unique<class_method_filter>(filter_t::kInclusive,
|
||||
std::make_unique<access_filter>(
|
||||
filter_t::kInclusive, c.include().access),
|
||||
std::make_unique<method_type_filter>(
|
||||
filter_t::kInclusive, c.include().method_types)));
|
||||
|
||||
add_inclusive_filter(
|
||||
std::make_unique<class_member_filter>(filter_t::kInclusive,
|
||||
std::make_unique<access_filter>(
|
||||
filter_t::kInclusive, c.include().access)));
|
||||
|
||||
// Include any of these matches even if one them does not match
|
||||
std::vector<std::unique_ptr<filter_visitor>> element_filters;
|
||||
|
||||
@@ -637,6 +722,18 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
add_exclusive_filter(std::make_unique<access_filter>(
|
||||
filter_t::kExclusive, c.exclude().access));
|
||||
|
||||
add_exclusive_filter(
|
||||
std::make_unique<class_method_filter>(filter_t::kExclusive,
|
||||
std::make_unique<access_filter>(
|
||||
filter_t::kExclusive, c.exclude().access),
|
||||
std::make_unique<method_type_filter>(
|
||||
filter_t::kExclusive, c.exclude().method_types)));
|
||||
|
||||
add_exclusive_filter(
|
||||
std::make_unique<class_member_filter>(filter_t::kExclusive,
|
||||
std::make_unique<access_filter>(
|
||||
filter_t::kExclusive, c.exclude().access)));
|
||||
|
||||
add_exclusive_filter(std::make_unique<subclass_filter>(
|
||||
filter_t::kExclusive, c.exclude().subclasses));
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "class_diagram/model/class_member.h"
|
||||
#include "class_diagram/model/class_method.h"
|
||||
#include "class_diagram/model/diagram.h"
|
||||
#include "common/clang_utils.h"
|
||||
#include "common/model/diagram.h"
|
||||
@@ -78,6 +80,12 @@ public:
|
||||
virtual tvl::value_t match(
|
||||
const diagram &d, const common::model::source_location &f) const;
|
||||
|
||||
virtual tvl::value_t match(
|
||||
const diagram &d, const class_diagram::model::class_method &m) const;
|
||||
|
||||
virtual tvl::value_t match(
|
||||
const diagram &d, const class_diagram::model::class_member &m) const;
|
||||
|
||||
bool is_inclusive() const;
|
||||
bool is_exclusive() const;
|
||||
|
||||
@@ -138,6 +146,19 @@ private:
|
||||
std::vector<std::string> element_types_;
|
||||
};
|
||||
|
||||
struct method_type_filter : public filter_visitor {
|
||||
method_type_filter(
|
||||
filter_t type, std::vector<config::method_type> method_types);
|
||||
|
||||
~method_type_filter() override = default;
|
||||
|
||||
tvl::value_t match(const diagram &d,
|
||||
const class_diagram::model::class_method &e) const override;
|
||||
|
||||
private:
|
||||
std::vector<config::method_type> method_types_;
|
||||
};
|
||||
|
||||
struct subclass_filter : public filter_visitor {
|
||||
subclass_filter(filter_t type, std::vector<std::string> roots);
|
||||
|
||||
@@ -354,6 +375,32 @@ private:
|
||||
std::filesystem::path root_;
|
||||
};
|
||||
|
||||
struct class_method_filter : public filter_visitor {
|
||||
class_method_filter(filter_t type, std::unique_ptr<access_filter> af,
|
||||
std::unique_ptr<method_type_filter> mtf);
|
||||
|
||||
~class_method_filter() override = default;
|
||||
|
||||
tvl::value_t match(const diagram &d,
|
||||
const class_diagram::model::class_method &m) const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<access_filter> access_filter_;
|
||||
std::unique_ptr<method_type_filter> method_type_filter_;
|
||||
};
|
||||
|
||||
struct class_member_filter : public filter_visitor {
|
||||
class_member_filter(filter_t type, std::unique_ptr<access_filter> af);
|
||||
|
||||
~class_member_filter() override = default;
|
||||
|
||||
tvl::value_t match(const diagram &d,
|
||||
const class_diagram::model::class_member &m) const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<access_filter> access_filter_;
|
||||
};
|
||||
|
||||
class diagram_filter {
|
||||
public:
|
||||
diagram_filter(const common::model::diagram &d, const config::diagram &c);
|
||||
|
||||
@@ -24,6 +24,31 @@ namespace clanguml::common::model::tvl {
|
||||
|
||||
using value_t = std::optional<bool>;
|
||||
|
||||
inline value_t and_(const value_t &l, const value_t &r)
|
||||
{
|
||||
if (!l.has_value())
|
||||
return r;
|
||||
|
||||
if (!r.has_value())
|
||||
return l;
|
||||
|
||||
return r.value() && l.value();
|
||||
}
|
||||
|
||||
inline value_t or_(const value_t &l, const value_t &r)
|
||||
{
|
||||
if (!l.has_value() && !r.has_value())
|
||||
return {};
|
||||
|
||||
if (l.has_value() && l.value())
|
||||
return true;
|
||||
|
||||
if (r.has_value() && r.value())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool is_true(const value_t &v) { return v.has_value() && v.value(); }
|
||||
|
||||
inline bool is_false(const value_t &v) { return v.has_value() && !v.value(); }
|
||||
|
||||
@@ -62,6 +62,27 @@ std::string to_string(const method_arguments ma)
|
||||
}
|
||||
}
|
||||
|
||||
std::string to_string(method_type mt)
|
||||
{
|
||||
switch (mt) {
|
||||
case method_type::constructor:
|
||||
return "constructor";
|
||||
case method_type::assignment:
|
||||
return "assignment";
|
||||
case method_type::operator_:
|
||||
return "operator";
|
||||
case method_type::defaulted:
|
||||
return "defaulted";
|
||||
case method_type::deleted:
|
||||
return "deleted";
|
||||
case method_type::static_:
|
||||
return "static";
|
||||
default:
|
||||
assert(false);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string to_string(const comment_parser_t cp)
|
||||
{
|
||||
switch (cp) {
|
||||
|
||||
@@ -37,6 +37,17 @@ namespace config {
|
||||
|
||||
enum class method_arguments { full, abbreviated, none };
|
||||
|
||||
enum class method_type {
|
||||
constructor,
|
||||
assignment,
|
||||
operator_,
|
||||
defaulted,
|
||||
deleted,
|
||||
static_
|
||||
};
|
||||
|
||||
std::string to_string(method_type mt);
|
||||
|
||||
enum class package_type_t { kNamespace, kDirectory };
|
||||
|
||||
enum class member_order_t { lexical, as_is };
|
||||
@@ -96,6 +107,8 @@ struct filter {
|
||||
std::vector<std::string> context;
|
||||
|
||||
std::vector<std::filesystem::path> paths;
|
||||
|
||||
std::vector<method_type> method_types;
|
||||
};
|
||||
|
||||
enum class hint_t { up, down, left, right, together, row, column };
|
||||
|
||||
@@ -34,6 +34,7 @@ using clanguml::config::layout_hint;
|
||||
using clanguml::config::location_t;
|
||||
using clanguml::config::member_order_t;
|
||||
using clanguml::config::method_arguments;
|
||||
using clanguml::config::method_type;
|
||||
using clanguml::config::package_diagram;
|
||||
using clanguml::config::package_type_t;
|
||||
using clanguml::config::plantuml;
|
||||
@@ -221,6 +222,32 @@ template <> struct convert<access_t> {
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// config method_type decoder
|
||||
//
|
||||
template <> struct convert<method_type> {
|
||||
static bool decode(const Node &node, method_type &rhs)
|
||||
{
|
||||
const auto &val = node.as<std::string>();
|
||||
if (val == to_string(method_type::constructor))
|
||||
rhs = method_type::constructor;
|
||||
else if (val == to_string(method_type::assignment))
|
||||
rhs = method_type::assignment;
|
||||
else if (val == to_string(method_type::operator_))
|
||||
rhs = method_type::operator_;
|
||||
else if (val == to_string(method_type::defaulted))
|
||||
rhs = method_type::defaulted;
|
||||
else if (val == to_string(method_type::deleted))
|
||||
rhs = method_type::deleted;
|
||||
else if (val == to_string(method_type::static_))
|
||||
rhs = method_type::static_;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// config relationship_t decoder
|
||||
//
|
||||
@@ -337,6 +364,10 @@ template <> struct convert<filter> {
|
||||
rhs.element_types =
|
||||
node["element_types"].as<decltype(rhs.element_types)>();
|
||||
|
||||
if (node["method_types"])
|
||||
rhs.method_types =
|
||||
node["method_types"].as<decltype(rhs.method_types)>();
|
||||
|
||||
if (node["access"])
|
||||
rhs.access = node["access"].as<decltype(rhs.access)>();
|
||||
|
||||
@@ -515,7 +546,8 @@ template <> struct convert<include_diagram> {
|
||||
rhs.relative_to.set(std::filesystem::current_path());
|
||||
|
||||
// Convert the path in relative_to to an absolute path, with respect
|
||||
// to the directory where the `.clang-uml` configuration file is located
|
||||
// to the directory where the `.clang-uml` configuration file is
|
||||
// located
|
||||
if (rhs.relative_to) {
|
||||
auto absolute_relative_to =
|
||||
std::filesystem::path{node["__parent_path"].as<std::string>()} /
|
||||
|
||||
@@ -45,6 +45,13 @@ YAML::Emitter &operator<<(YAML::Emitter &out, const diagram_t &d)
|
||||
} // namespace clanguml::common::model
|
||||
|
||||
namespace clanguml::config {
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const method_type &m)
|
||||
{
|
||||
out << to_string(m);
|
||||
return out;
|
||||
}
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const filter &f)
|
||||
{
|
||||
out << YAML::BeginMap;
|
||||
@@ -62,6 +69,8 @@ YAML::Emitter &operator<<(YAML::Emitter &out, const filter &f)
|
||||
out << YAML::Key << "elements" << YAML::Value << f.elements;
|
||||
if (!f.element_types.empty())
|
||||
out << YAML::Key << "element_types" << YAML::Value << f.element_types;
|
||||
if (!f.method_types.empty())
|
||||
out << YAML::Key << "method_types" << YAML::Value << f.method_types;
|
||||
if (!f.paths.empty())
|
||||
out << YAML::Key << "paths" << YAML::Value << f.paths;
|
||||
if (!f.relationships.empty())
|
||||
|
||||
Reference in New Issue
Block a user