Fixed path filtering
This commit is contained in:
@@ -353,13 +353,25 @@ paths_filter::paths_filter(filter_t type, const std::filesystem::path &root,
|
||||
: filter_visitor{type}
|
||||
, root_{root}
|
||||
{
|
||||
for (auto &&path : p) {
|
||||
for (const auto &path : p) {
|
||||
std::filesystem::path absolute_path;
|
||||
|
||||
if (path.is_relative())
|
||||
if (path.string().empty() || path.string() == ".")
|
||||
absolute_path = root;
|
||||
else if (path.is_relative())
|
||||
absolute_path = root / path;
|
||||
else
|
||||
absolute_path = path;
|
||||
|
||||
absolute_path = absolute_path.lexically_normal();
|
||||
try {
|
||||
absolute_path =
|
||||
std::filesystem::canonical(absolute_path.lexically_normal());
|
||||
}
|
||||
catch (std::filesystem::filesystem_error &e) {
|
||||
LOG_WARN("Cannot add non-existent path {} to paths filter",
|
||||
path.string());
|
||||
continue;
|
||||
}
|
||||
|
||||
paths_.emplace_back(std::move(absolute_path));
|
||||
}
|
||||
@@ -430,7 +442,7 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
filter_t::kInclusive, c.include().access));
|
||||
|
||||
add_inclusive_filter(std::make_unique<paths_filter>(
|
||||
filter_t::kInclusive, c.base_directory(), c.include().paths));
|
||||
filter_t::kInclusive, c.relative_to(), c.include().paths));
|
||||
|
||||
// Include any of these matches even if one them does not match
|
||||
std::vector<std::unique_ptr<filter_visitor>> element_filters;
|
||||
@@ -474,21 +486,11 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
|
||||
for (auto &&path : c.include().dependants) {
|
||||
std::filesystem::path dep_path{path};
|
||||
if (dep_path.is_relative()) {
|
||||
dep_path = c.base_directory() / path;
|
||||
dep_path = relative(dep_path, c.relative_to());
|
||||
}
|
||||
|
||||
dependants.emplace_back(dep_path.lexically_normal().string());
|
||||
}
|
||||
|
||||
for (auto &&path : c.include().dependencies) {
|
||||
std::filesystem::path dep_path{path};
|
||||
if (dep_path.is_relative()) {
|
||||
dep_path = c.base_directory() / path;
|
||||
dep_path = relative(dep_path, c.relative_to());
|
||||
}
|
||||
|
||||
dependencies.emplace_back(dep_path.lexically_normal().string());
|
||||
}
|
||||
|
||||
@@ -518,7 +520,7 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
filter_t::kExclusive, c.exclude().namespaces));
|
||||
|
||||
add_exclusive_filter(std::make_unique<paths_filter>(
|
||||
filter_t::kExclusive, c.base_directory(), c.exclude().paths));
|
||||
filter_t::kExclusive, c.relative_to(), c.exclude().paths));
|
||||
|
||||
add_exclusive_filter(std::make_unique<element_filter>(
|
||||
filter_t::kExclusive, c.exclude().elements));
|
||||
|
||||
@@ -595,6 +595,11 @@ template <> struct convert<sequence_diagram> {
|
||||
get_option(node, rhs.combine_free_functions_into_file_participants);
|
||||
get_option(node, rhs.relative_to);
|
||||
get_option(node, rhs.participants_order);
|
||||
get_option(node, rhs.generate_method_arguments);
|
||||
|
||||
// Ensure relative_to has a value
|
||||
if (!rhs.relative_to.has_value)
|
||||
rhs.relative_to.set(std::filesystem::current_path());
|
||||
|
||||
rhs.initialize_type_aliases();
|
||||
|
||||
@@ -630,6 +635,9 @@ template <> struct convert<include_diagram> {
|
||||
get_option(node, rhs.relative_to);
|
||||
get_option(node, rhs.generate_system_headers);
|
||||
|
||||
if (!rhs.relative_to)
|
||||
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
|
||||
if (rhs.relative_to) {
|
||||
|
||||
@@ -58,20 +58,28 @@ void generator::generate_call(const message &m, std::ostream &ostr) const
|
||||
|
||||
std::string message;
|
||||
|
||||
model::function::message_render_mode render_mode =
|
||||
model::function::message_render_mode::full;
|
||||
|
||||
if (m_config.generate_method_arguments() ==
|
||||
config::method_arguments::abbreviated)
|
||||
render_mode = model::function::message_render_mode::abbreviated;
|
||||
else if (m_config.generate_method_arguments() ==
|
||||
config::method_arguments::none)
|
||||
render_mode = model::function::message_render_mode::no_arguments;
|
||||
|
||||
if (to.value().type_name() == "method") {
|
||||
message = dynamic_cast<const model::function &>(to.value())
|
||||
.message_name(model::function::message_render_mode::full);
|
||||
.message_name(render_mode);
|
||||
}
|
||||
else if (m_config.combine_free_functions_into_file_participants()) {
|
||||
if (to.value().type_name() == "function") {
|
||||
message =
|
||||
dynamic_cast<const model::function &>(to.value())
|
||||
.message_name(model::function::message_render_mode::full);
|
||||
message = dynamic_cast<const model::function &>(to.value())
|
||||
.message_name(render_mode);
|
||||
}
|
||||
else if (to.value().type_name() == "function_template") {
|
||||
message =
|
||||
dynamic_cast<const model::function_template &>(to.value())
|
||||
.message_name(model::function::message_render_mode::full);
|
||||
message = dynamic_cast<const model::function_template &>(to.value())
|
||||
.message_name(render_mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +310,7 @@ void generator::generate_participant(
|
||||
if (is_participant_generated(file_id))
|
||||
return;
|
||||
|
||||
[[maybe_unused]] const auto &relative_to =
|
||||
const auto &relative_to =
|
||||
std::filesystem::canonical(m_config.relative_to());
|
||||
|
||||
auto participant_name = std::filesystem::relative(
|
||||
@@ -388,13 +396,22 @@ void generator::generate(std::ostream &ostr) const
|
||||
|
||||
std::string from_alias = generate_alias(from.value());
|
||||
|
||||
model::function::message_render_mode render_mode =
|
||||
model::function::message_render_mode::full;
|
||||
|
||||
if (m_config.generate_method_arguments() ==
|
||||
config::method_arguments::abbreviated)
|
||||
render_mode = model::function::message_render_mode::abbreviated;
|
||||
else if (m_config.generate_method_arguments() ==
|
||||
config::method_arguments::none)
|
||||
render_mode =
|
||||
model::function::message_render_mode::no_arguments;
|
||||
|
||||
if (from.value().type_name() == "method" ||
|
||||
m_config.combine_free_functions_into_file_participants()) {
|
||||
ostr << "[->"
|
||||
<< " " << from_alias << " : "
|
||||
<< from.value().message_name(
|
||||
model::function::message_render_mode::full)
|
||||
<< std::endl;
|
||||
<< from.value().message_name(render_mode) << std::endl;
|
||||
}
|
||||
|
||||
ostr << "activate " << from_alias << std::endl;
|
||||
|
||||
@@ -196,6 +196,12 @@ std::string function::message_name(message_render_mode mode) const
|
||||
if (mode == message_render_mode::no_arguments) {
|
||||
return fmt::format("{}(){}", name(), is_const() ? " const" : "");
|
||||
}
|
||||
else if (mode == message_render_mode::abbreviated) {
|
||||
return fmt::format("{}({}){}", name(),
|
||||
clanguml::util::abbreviate(
|
||||
fmt::format("{}", fmt::join(parameters_, ",")), 15),
|
||||
is_const() ? " const" : "");
|
||||
}
|
||||
|
||||
return fmt::format("{}({}){}", name(), fmt::join(parameters_, ","),
|
||||
is_const() ? " const" : "");
|
||||
@@ -259,6 +265,12 @@ std::string method::message_name(message_render_mode mode) const
|
||||
return fmt::format("{}{}(){}{}", style, method_name(),
|
||||
is_const() ? " const" : "", style);
|
||||
}
|
||||
else if (mode == message_render_mode::abbreviated) {
|
||||
return fmt::format("{}({}){}", name(),
|
||||
clanguml::util::abbreviate(
|
||||
fmt::format("{}", fmt::join(parameters(), ",")), 15),
|
||||
is_const() ? " const" : "");
|
||||
}
|
||||
|
||||
return fmt::format("{}{}({}){}{}", style, method_name(),
|
||||
fmt::join(parameters(), ","), is_const() ? " const" : "", style);
|
||||
@@ -330,6 +342,12 @@ std::string function_template::message_name(message_render_mode mode) const
|
||||
return fmt::format(
|
||||
"{}{}(){}", name(), template_params, is_const() ? " const" : "");
|
||||
}
|
||||
else if (mode == message_render_mode::abbreviated) {
|
||||
return fmt::format("{}({}){}", name(),
|
||||
clanguml::util::abbreviate(
|
||||
fmt::format("{}", fmt::join(parameters(), ",")), 15),
|
||||
is_const() ? " const" : "");
|
||||
}
|
||||
|
||||
return fmt::format("{}{}({}){}", name(), template_params,
|
||||
fmt::join(parameters(), ","), is_const() ? " const" : "");
|
||||
|
||||
@@ -135,7 +135,7 @@ struct lambda : public class_ {
|
||||
};
|
||||
|
||||
struct function : public participant {
|
||||
enum class message_render_mode { full, no_arguments };
|
||||
enum class message_render_mode { full, abbreviated, no_arguments };
|
||||
|
||||
function(const common::model::namespace_ &using_namespace);
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ bool translation_unit_visitor::VisitCXXMethodDecl(clang::CXXMethodDecl *m)
|
||||
LOG_DBG("Getting method's class with local id {}", parent_decl->getID());
|
||||
|
||||
if (!get_participant<model::class_>(parent_decl)) {
|
||||
LOG_INFO("Cannot find parent class_ for method {} in class {}",
|
||||
LOG_DBG("Cannot find parent class_ for method {} in class {}",
|
||||
m->getQualifiedNameAsString(),
|
||||
m->getParent()->getQualifiedNameAsString());
|
||||
return true;
|
||||
@@ -490,10 +490,8 @@ bool translation_unit_visitor::VisitLambdaExpr(clang::LambdaExpr *expr)
|
||||
auto m_ptr = std::make_unique<sequence_diagram::model::method>(
|
||||
config().using_namespace());
|
||||
|
||||
common::model::namespace_ ns{c_ptr->get_namespace()};
|
||||
auto method_name = "operator()";
|
||||
m_ptr->set_method_name(method_name);
|
||||
ns.pop_back();
|
||||
|
||||
m_ptr->set_class_id(cls_id);
|
||||
m_ptr->set_class_full_name(c_ptr->full_name(false));
|
||||
@@ -1158,6 +1156,11 @@ bool translation_unit_visitor::process_function_call_expression(
|
||||
if (!diagram().should_include(callee_name))
|
||||
return false;
|
||||
|
||||
// Skip free functions declared in files outside of included paths
|
||||
if (config().combine_free_functions_into_file_participants() &&
|
||||
!diagram().should_include(common::model::source_file{m.file()}))
|
||||
return false;
|
||||
|
||||
std::unique_ptr<model::function_template> f_ptr;
|
||||
|
||||
if (!get_unique_id(callee_function->getID()).has_value()) {
|
||||
|
||||
Reference in New Issue
Block a user