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);
330 std::string full_name)
const
337 auto matched_in_iteration{
false};
338 for (
const auto &[pattern, replacement] : aliases) {
339 matched_in_iteration =
341 matched_in_iteration;
343 matched = matched_in_iteration;
356 const std::vector<std::string> &compilation_database_files)
const
361 std::vector<std::string> compilation_database_paths;
362 compilation_database_paths.reserve(compilation_database_files.size());
363 for (
const auto &cdf : compilation_database_files) {
364 std::filesystem::path p{cdf};
366 compilation_database_paths.emplace_back(p.string());
372 return compilation_database_paths;
377 std::vector<std::string> glob_matches{};
381 for (
const auto &g :
glob().include) {
383 LOG_DBG(
"Matching inclusive glob regex {}", g.to_string());
385 std::regex regex_pattern(
386 g.to_string(), std::regex_constants::optimize);
388 std::copy_if(compilation_database_paths.begin(),
389 compilation_database_paths.end(),
390 std::back_inserter(glob_matches),
391 [®ex_pattern](
const auto &tu) {
394 return exists(std::filesystem::path{tu}) &&
395 std::regex_search(tu, m, regex_pattern);
399 std::filesystem::path absolute_glob_path{g.to_string()};
402 if (!absolute_glob_path.has_root_name())
404 if (!absolute_glob_path.is_absolute())
408 LOG_DBG(
"Searching glob path {}", absolute_glob_path.string());
410 auto matches = glob::glob(absolute_glob_path.string(),
true,
false);
412 for (
const auto &match : matches) {
416 glob_matches.emplace_back(path.string());
421 if (glob().include.empty())
422 glob_matches = compilation_database_paths;
424 for (
const auto &g : glob().exclude) {
426 LOG_DBG(
"Matching exclusive glob regex {}", g.to_string());
428 std::regex regex_pattern(
429 g.to_string(), std::regex_constants::optimize);
431 for (
const auto &cdf : compilation_database_paths) {
433 if (std::regex_search(cdf, m, regex_pattern)) {
435 remove(begin(glob_matches), end(glob_matches), cdf),
441 std::filesystem::path absolute_glob_path{g.to_string()};
444 if (!absolute_glob_path.has_root_name())
446 if (!absolute_glob_path.is_absolute())
448 absolute_glob_path = root_directory() / absolute_glob_path;
450 LOG_DBG(
"Searching exclusive glob path {}",
451 absolute_glob_path.string());
453 auto matches = glob::glob(absolute_glob_path.string(),
true,
false);
455 for (
const auto &match : matches) {
457 std::filesystem::canonical(root_directory() / match);
459 glob_matches.erase(remove(begin(glob_matches),
460 end(glob_matches), path.string()),
467 std::vector<std::string> result;
468 for (
const auto &gm : glob_matches) {
469 std::filesystem::path gm_path{gm};
470 gm_path.make_preferred();
473 result.emplace_back(gm_path.string());
480std::filesystem::path diagram::make_path_relative(
481 const std::filesystem::path &p)
const
483 return relative(p, root_directory()).lexically_normal().string();
486std::vector<std::string> diagram::make_module_relative(
487 const std::optional<std::string> &maybe_module)
const
496 if (using_module.has_value) {
509std::optional<std::string> diagram::get_together_group(
510 const std::string &full_name)
const
512 const auto relative_name = using_namespace().relative(full_name);
514 for (
const auto &[hint_target, hints] : layout()) {
515 for (
const auto &hint : hints) {
516 if (hint.hint == hint_t::together) {
517 const auto &together_others =
518 std::get<std::vector<std::string>>(hint.entity);
520 if ((full_name == hint_target) ||
524 if ((relative_name == hint_target) ||
534void diagram::initialize_type_aliases()
536 if (type_aliases().count(
"std::basic_string<char>") == 0U) {
537 type_aliases().insert({
"std::basic_string<char>",
"std::string"});
539 if (type_aliases().count(
"std::basic_string<char,std::char_traits<"
540 "char>,std::allocator<char>>") == 0U) {
541 type_aliases().insert({
"std::basic_string<char,std::char_traits<"
542 "char>,std::allocator<char>>",
545 if (type_aliases().count(
"std::basic_string<wchar_t>") == 0U) {
546 type_aliases().insert({
"std::basic_string<wchar_t>",
"std::wstring"});
548 if (type_aliases().count(
"std::basic_string<char16_t>") == 0U) {
549 type_aliases().insert(
550 {
"std::basic_string<char16_t>",
"std::u16string"});
552 if (type_aliases().count(
"std::basic_string<char32_t>") == 0U) {
553 type_aliases().insert(
554 {
"std::basic_string<char32_t>",
"std::u32string"});
556 if (type_aliases().count(
"std::integral_constant<bool,true>") == 0U) {
557 type_aliases().insert(
558 {
"std::integral_constant<bool,true>",
"std::true_type"});
560 if (type_aliases().count(
"std::integral_constant<bool,false>") == 0U) {
561 type_aliases().insert(
562 {
"std::integral_constant<bool,false>",
"std::false_type"});
564#if LLVM_VERSION_MAJOR >= 16
565 if (type_aliases().count(
"std::basic_string") == 0U) {
566 type_aliases().insert({
"std::basic_string",
"std::string"});
591void class_diagram::initialize_relationship_hints()
595 if (relationship_hints().count(
"std::vector") == 0U) {
596 relationship_hints().insert({
"std::vector", {}});
598 if (relationship_hints().count(
"std::unique_ptr") == 0U) {
599 relationship_hints().insert({
"std::unique_ptr", {}});
601 if (relationship_hints().count(
"std::shared_ptr") == 0U) {
602 relationship_hints().insert(
603 {
"std::shared_ptr", {relationship_t::kAssociation}});
605 if (relationship_hints().count(
"std::weak_ptr") == 0U) {
606 relationship_hints().insert(
607 {
"std::weak_ptr", {relationship_t::kAssociation}});
609 if (relationship_hints().count(
"std::tuple") == 0U) {
610 relationship_hints().insert({
"std::tuple", {}});
612 if (relationship_hints().count(
"std::map") == 0U) {
615 relationship_hints().insert({
"std::tuple", std::move(hint)});