21#include "glob/glob.hpp"
70 return "function_template";
76 return "objc_protocol";
78 return "objc_category";
80 return "objc_interface";
106 return "constructor";
129 return "constructor";
143 return "function_template";
147 return "cuda_kernel";
149 return "cuda_device";
242 if (
style.count(to_string(relationship_type)) == 0)
245 return style.at(to_string(relationship_type));
249 const std::string &element_type)
const
251 if (
style.count(element_type) == 0)
254 return style.at(element_type);
335 std::string full_name)
const
342 auto matched_in_iteration{
false};
343 for (
const auto &[pattern, replacement] : aliases) {
344 matched_in_iteration =
346 matched_in_iteration;
348 matched = matched_in_iteration;
361 const std::vector<std::string> &compilation_database_files,
366 std::vector<std::string> compilation_database_paths;
367 compilation_database_paths.reserve(compilation_database_files.size());
368 for (
const auto &cdf : compilation_database_files) {
369 std::filesystem::path p{cdf};
371 compilation_database_paths.emplace_back(p.string());
377 return compilation_database_paths;
381 std::vector<std::string> canonical_compilation_database_paths;
382 canonical_compilation_database_paths.reserve(
383 compilation_database_paths.size());
384 for (
const auto &cdp : compilation_database_paths) {
385 auto canonical_p = weakly_canonical(std::filesystem::path{cdp});
386 canonical_compilation_database_paths.emplace_back(canonical_p.string());
391 std::vector<std::string> glob_matches{};
395 for (
const auto &g :
glob().include) {
397 LOG_DBG(
"Matching inclusive glob regex {}", g.to_string());
399 std::regex regex_pattern(
400 g.to_string(), std::regex_constants::optimize);
402 std::copy_if(compilation_database_paths.begin(),
403 compilation_database_paths.end(),
404 std::back_inserter(glob_matches),
405 [®ex_pattern](
const auto &tu) {
408 return exists(std::filesystem::path{tu}) &&
409 std::regex_search(tu, m, regex_pattern);
413 std::filesystem::path absolute_glob_path{g.to_string()};
416 if (!absolute_glob_path.has_root_name())
418 if (!absolute_glob_path.is_absolute())
422 LOG_DBG(
"Searching glob path {}", absolute_glob_path.string());
424 auto matches = glob::glob(absolute_glob_path.string(),
true,
false);
426 for (
const auto &match : matches) {
430 glob_matches.emplace_back(path.string());
435 if (glob().include.empty())
436 glob_matches = compilation_database_paths;
438 for (
const auto &g : glob().exclude) {
440 LOG_DBG(
"Matching exclusive glob regex {}", g.to_string());
442 std::regex regex_pattern(
443 g.to_string(), std::regex_constants::optimize);
445 for (
const auto &cdf : compilation_database_paths) {
447 if (std::regex_search(cdf, m, regex_pattern)) {
449 remove(begin(glob_matches), end(glob_matches), cdf),
455 std::filesystem::path absolute_glob_path{g.to_string()};
458 if (!absolute_glob_path.has_root_name())
460 if (!absolute_glob_path.is_absolute())
462 absolute_glob_path = root_directory() / absolute_glob_path;
464 LOG_DBG(
"Searching exclusive glob path {}",
465 absolute_glob_path.string());
467 auto matches = glob::glob(absolute_glob_path.string(),
true,
false);
469 for (
const auto &match : matches) {
471 std::filesystem::canonical(root_directory() / match);
473 glob_matches.erase(remove(begin(glob_matches),
474 end(glob_matches), path.string()),
481 std::vector<std::string> result;
482 for (
const auto &gm : glob_matches) {
483 std::filesystem::path gm_path{gm};
484 gm_path.make_preferred();
485 if (is_fixed ||
util::contains(compilation_database_paths, gm_path) ||
488 result.emplace_back(gm_path.string());
495std::filesystem::path diagram::make_path_relative(
496 const std::filesystem::path &p)
const
498 return relative(p, root_directory()).lexically_normal().string();
501std::vector<std::string> diagram::make_module_relative(
502 const std::optional<std::string> &maybe_module)
const
511 if (using_module.has_value) {
524std::optional<std::string> diagram::get_together_group(
525 const std::string &full_name)
const
527 const auto relative_name = using_namespace().relative(full_name);
529 for (
const auto &[hint_target, hints] : layout()) {
530 for (
const auto &hint : hints) {
531 if (hint.hint == hint_t::together) {
532 const auto &together_others =
533 std::get<std::vector<std::string>>(hint.entity);
535 if ((full_name == hint_target) ||
539 if ((relative_name == hint_target) ||
549void diagram::initialize_type_aliases()
551 if (type_aliases().count(
"std::basic_string<char>") == 0U) {
552 type_aliases().insert({
"std::basic_string<char>",
"std::string"});
554 if (type_aliases().count(
"std::basic_string<char,std::char_traits<"
555 "char>,std::allocator<char>>") == 0U) {
556 type_aliases().insert({
"std::basic_string<char,std::char_traits<"
557 "char>,std::allocator<char>>",
560 if (type_aliases().count(
"std::basic_string<wchar_t>") == 0U) {
561 type_aliases().insert({
"std::basic_string<wchar_t>",
"std::wstring"});
563 if (type_aliases().count(
"std::basic_string<char16_t>") == 0U) {
564 type_aliases().insert(
565 {
"std::basic_string<char16_t>",
"std::u16string"});
567 if (type_aliases().count(
"std::basic_string<char32_t>") == 0U) {
568 type_aliases().insert(
569 {
"std::basic_string<char32_t>",
"std::u32string"});
571 if (type_aliases().count(
"std::integral_constant<bool,true>") == 0U) {
572 type_aliases().insert(
573 {
"std::integral_constant<bool,true>",
"std::true_type"});
575 if (type_aliases().count(
"std::integral_constant<bool,false>") == 0U) {
576 type_aliases().insert(
577 {
"std::integral_constant<bool,false>",
"std::false_type"});
579#if LLVM_VERSION_MAJOR >= 16
580 if (type_aliases().count(
"std::basic_string") == 0U) {
581 type_aliases().insert({
"std::basic_string",
"std::string"});
606void class_diagram::initialize_relationship_hints()
610 if (relationship_hints().count(
"std::vector") == 0U) {
611 relationship_hints().insert({
"std::vector", {}});
613 if (relationship_hints().count(
"std::unique_ptr") == 0U) {
614 relationship_hints().insert({
"std::unique_ptr", {}});
616 if (relationship_hints().count(
"std::shared_ptr") == 0U) {
617 relationship_hints().insert(
618 {
"std::shared_ptr", {relationship_t::kAssociation}});
620 if (relationship_hints().count(
"std::weak_ptr") == 0U) {
621 relationship_hints().insert(
622 {
"std::weak_ptr", {relationship_t::kAssociation}});
624 if (relationship_hints().count(
"std::tuple") == 0U) {
625 relationship_hints().insert({
"std::tuple", {}});
627 if (relationship_hints().count(
"std::map") == 0U) {
630 relationship_hints().insert({
"std::tuple", std::move(hint)});