Fixed building on MSVC

This commit is contained in:
Bartek Kryza
2023-05-28 22:17:21 +02:00
parent 0028cf6f3d
commit 8e801fe31d
11 changed files with 47 additions and 66 deletions

View File

@@ -43,7 +43,7 @@ using nested_trait_ns =
clanguml::common::model::nested_trait<clanguml::common::model::element,
clanguml::common::model::namespace_>;
class diagram : public common::model::diagram::diagram,
class diagram : public common::model::diagram,
public element_view<class_>,
public element_view<enum_>,
public element_view<concept_>,

View File

@@ -1090,7 +1090,7 @@ std::optional<template_parameter> template_builder::try_as_template_parm_type(
argument.is_variadic(is_variadic);
ensure_lambda_type_is_relative(type_parameter_name);
visitor_.ensure_lambda_type_is_relative(type_parameter_name);
return argument;
}
@@ -1109,7 +1109,7 @@ std::optional<template_parameter> template_builder::try_as_lambda(
auto argument = template_parameter::make_argument("");
type = consume_context(type, argument);
ensure_lambda_type_is_relative(type_name);
visitor_.ensure_lambda_type_is_relative(type_name);
argument.set_type(type_name);
return argument;
@@ -1257,40 +1257,4 @@ bool template_builder::add_base_classes(class_ &tinst,
return variadic_params;
}
void template_builder::ensure_lambda_type_is_relative(
std::string &parameter_type) const
{
#ifdef _MSC_VER
auto root_name = fmt::format(
"{}\\", std::filesystem::current_path().root_name().string());
if (root_name.back() == '\\') {
root_name.pop_back();
root_name.push_back('/');
}
#else
auto root_name = std::string{"/"};
#endif
std::string lambda_prefix{fmt::format("(lambda at {}", root_name)};
while (parameter_type.find(lambda_prefix) != std::string::npos) {
auto lambda_begin = parameter_type.find(lambda_prefix);
auto absolute_lambda_path_end =
parameter_type.find(':', lambda_begin + lambda_prefix.size());
auto absolute_lambda_path =
parameter_type.substr(lambda_begin + lambda_prefix.size() - 1,
absolute_lambda_path_end -
(lambda_begin + lambda_prefix.size() - 1));
auto relative_lambda_path = util::path_to_url(std::filesystem::relative(
absolute_lambda_path, config().relative_to())
.string());
parameter_type = fmt::format("{}(lambda at {}{}",
parameter_type.substr(0, lambda_begin), relative_lambda_path,
parameter_type.substr(absolute_lambda_path_end));
}
}
} // namespace clanguml::class_diagram::visitor

View File

@@ -181,8 +181,6 @@ public:
clang::SourceManager &source_manager() const;
private:
void ensure_lambda_type_is_relative(std::string &parameter_type) const;
// Reference to the output diagram model
clanguml::class_diagram::model::diagram &diagram_;

View File

@@ -1690,11 +1690,7 @@ void translation_unit_visitor::ensure_lambda_type_is_relative(
{
#ifdef _MSC_VER
auto root_name = fmt::format(
"{}\\", std::filesystem::current_path().root_name().string());
if (root_name.back() == '\\') {
root_name.pop_back();
root_name.push_back('/');
}
"{}", std::filesystem::current_path().root_name().string());
#else
auto root_name = std::string{"/"};
#endif
@@ -1703,13 +1699,17 @@ void translation_unit_visitor::ensure_lambda_type_is_relative(
while (parameter_type.find(lambda_prefix) != std::string::npos) {
auto lambda_begin = parameter_type.find(lambda_prefix);
auto lambda_prefix_size = lambda_prefix.size();
#ifdef _MSC_VER
// Skip the `\` or `/` after drive letter and semicolon
lambda_prefix_size++;
#endif
auto absolute_lambda_path_end =
parameter_type.find(':', lambda_begin + lambda_prefix.size());
parameter_type.find(':', lambda_begin + lambda_prefix_size);
auto absolute_lambda_path =
parameter_type.substr(lambda_begin + lambda_prefix.size() - 1,
parameter_type.substr(lambda_begin + lambda_prefix_size - 1,
absolute_lambda_path_end -
(lambda_begin + lambda_prefix.size() - 1));
(lambda_begin + lambda_prefix_size - 1));
auto relative_lambda_path = util::path_to_url(
config().make_path_relative(absolute_lambda_path).string());
@@ -2102,7 +2102,7 @@ void translation_unit_visitor::add_class(std::unique_ptr<class_> &&c)
const auto file = config().make_path_relative(c->file());
common::model::path p{file, common::model::path_type::kFilesystem};
common::model::path p{file.string(), common::model::path_type::kFilesystem};
p.pop_back();
diagram().add(p, std::move(c));
@@ -2120,7 +2120,7 @@ void translation_unit_visitor::add_enum(std::unique_ptr<enum_> &&e)
const auto file = config().make_path_relative(e->file());
common::model::path p{file, common::model::path_type::kFilesystem};
common::model::path p{file.string(), common::model::path_type::kFilesystem};
p.pop_back();
diagram().add(p, std::move(e));
@@ -2138,7 +2138,7 @@ void translation_unit_visitor::add_concept(std::unique_ptr<concept_> &&c)
const auto file = config().make_path_relative(c->file());
common::model::path p{file, common::model::path_type::kFilesystem};
common::model::path p{file.string(), common::model::path_type::kFilesystem};
p.pop_back();
diagram().add(p, std::move(c));

View File

@@ -125,6 +125,8 @@ public:
void add_enum(std::unique_ptr<enum_> &&e);
void add_concept(std::unique_ptr<concept_> &&c);
void ensure_lambda_type_is_relative(std::string &parameter_type) const;
private:
bool should_include(const clang::NamedDecl *decl);
@@ -189,8 +191,6 @@ private:
const found_relationships_t &relationships,
bool break_on_first_aggregation = false);
void ensure_lambda_type_is_relative(std::string &parameter_type) const;
void process_record_parent(
clang::RecordDecl *cls, class_ &c, const namespace_ &ns);

View File

@@ -745,8 +745,19 @@ bool parse_source_location(const std::string &location_str, std::string &file,
return false;
file = tokens.at(0);
line = std::stoi(tokens.at(1));
column = std::stoi(tokens.at(2));
try {
line = std::stoi(tokens.at(1));
}
catch(std::invalid_argument &e) {
line = 0;
}
try {
column = std::stoi(tokens.at(2));
}
catch(std::invalid_argument &e) {
column = 0;
}
return true;
}

View File

@@ -207,11 +207,12 @@ void translation_unit_visitor::add_relationships(
// package for current directory is already in the model
if (config().package_type() == config::package_type_t::kDirectory) {
auto file = source_manager().getFilename(cls->getLocation()).str();
auto relative_file =
util::path_to_url(config().make_path_relative(file));
auto relative_file = config().make_path_relative(file);
relative_file.make_preferred();
common::model::path parent_path{
relative_file, common::model::path_type::kFilesystem};
relative_file.string(), common::model::path_type::kFilesystem};
parent_path.pop_back();
auto pkg_name = parent_path.name();
parent_path.pop_back();
@@ -261,9 +262,10 @@ common::model::diagram_element::id_t translation_unit_visitor::get_package_id(
auto file =
source_manager().getFilename(cls->getSourceRange().getBegin()).str();
auto relative_file = util::path_to_url(config().make_path_relative(file));
auto relative_file = config().make_path_relative(file);
relative_file.make_preferred();
common::model::path parent_path{
relative_file, common::model::path_type::kFilesystem};
relative_file.string(), common::model::path_type::kFilesystem};
parent_path.pop_back();
return common::to_id(parent_path.to_string());