Fixed clang-tidy warnings

This commit is contained in:
Bartek Kryza
2023-03-25 22:49:47 +01:00
parent 90307793d8
commit fc3110fd4e
9 changed files with 44 additions and 42 deletions

View File

@@ -1981,18 +1981,21 @@ void translation_unit_visitor::
bool translation_unit_visitor::find_relationships_in_unexposed_template_params( bool translation_unit_visitor::find_relationships_in_unexposed_template_params(
const template_parameter &ct, found_relationships_t &relationships) const template_parameter &ct, found_relationships_t &relationships)
{ {
assert(ct.type()); const auto &type = ct.type();
if (!type)
return false;
bool found{false}; bool found{false};
LOG_DBG("Finding relationships in user defined type: {}", LOG_DBG("Finding relationships in user defined type: {}",
ct.to_string(config().using_namespace(), false)); ct.to_string(config().using_namespace(), false));
auto type_with_namespace = auto type_with_namespace =
std::make_optional<common::model::namespace_>(ct.type().value()); std::make_optional<common::model::namespace_>(type.value());
if (!type_with_namespace.has_value()) { if (!type_with_namespace.has_value()) {
// Couldn't find declaration of this type // Couldn't find declaration of this type
type_with_namespace = common::model::namespace_{ct.type().value()}; type_with_namespace = common::model::namespace_{type.value()};
} }
auto element_opt = diagram().get(type_with_namespace.value().to_string()); auto element_opt = diagram().get(type_with_namespace.value().to_string());
@@ -2007,6 +2010,7 @@ bool translation_unit_visitor::find_relationships_in_unexposed_template_params(
nested_template_params, relationships) || nested_template_params, relationships) ||
found; found;
} }
return found; return found;
} }

View File

@@ -54,12 +54,12 @@ void to_json(nlohmann::json &j, const element &c)
void to_json(nlohmann::json &j, const template_parameter &c) void to_json(nlohmann::json &j, const template_parameter &c)
{ {
j["kind"] = to_string(c.kind()); j["kind"] = to_string(c.kind());
if (c.type()) if (const auto &t = c.type(); t)
j["type"] = c.type().value(); j["type"] = t.value();
if (c.name()) if (const auto &n = c.name(); n)
j["name"] = c.name().value(); j["name"] = n.value();
if (c.default_value()) if (const auto &d = c.default_value(); d)
j["default"] = c.default_value().value(); j["default"] = d.value();
j["is_variadic"] = c.is_variadic(); j["is_variadic"] = c.is_variadic();
j["template_parameters"] = c.template_params(); j["template_parameters"] = c.template_params();
} }

View File

@@ -81,7 +81,7 @@ std::string to_string(message_t m);
std::string to_string(diagram_t r); std::string to_string(diagram_t r);
std::string to_string(message_scope_t); std::string to_string(message_scope_t t);
diagram_t from_string(const std::string &s); diagram_t from_string(const std::string &s);

View File

@@ -44,20 +44,21 @@ std::string to_string(template_parameter_kind_t k);
/// nested templates /// nested templates
class template_parameter { class template_parameter {
public: public:
static template_parameter make_template_type(std::string name, static template_parameter make_template_type(const std::string &name,
const std::optional<std::string> &default_value = {}, const std::optional<std::string> &default_value = {},
bool is_variadic = false) bool is_variadic = false)
{ {
template_parameter p; template_parameter p;
p.set_kind(template_parameter_kind_t::template_type); p.set_kind(template_parameter_kind_t::template_type);
p.set_name(std::move(name)); p.set_name(name);
p.is_variadic(is_variadic); p.is_variadic(is_variadic);
if (default_value) if (default_value)
p.set_default_value(default_value.value()); p.set_default_value(default_value.value());
return p; return p;
} }
static template_parameter make_template_template_type(std::string name, static template_parameter make_template_template_type(
const std::string &name,
const std::optional<std::string> &default_value = {}, const std::optional<std::string> &default_value = {},
bool is_variadic = false) bool is_variadic = false)
{ {
@@ -70,14 +71,14 @@ public:
return p; return p;
} }
static template_parameter make_non_type_template(std::string type, static template_parameter make_non_type_template(const std::string &type,
const std::optional<std::string> &name, const std::optional<std::string> &name,
const std::optional<std::string> &default_value = {}, const std::optional<std::string> &default_value = {},
bool is_variadic = false) bool is_variadic = false)
{ {
template_parameter p; template_parameter p;
p.set_kind(template_parameter_kind_t::non_type_template); p.set_kind(template_parameter_kind_t::non_type_template);
p.set_type(std::move(type)); p.set_type(type);
if (name) if (name)
p.set_name(name.value()); p.set_name(name.value());
if (default_value) if (default_value)
@@ -86,21 +87,21 @@ public:
return p; return p;
} }
static template_parameter make_argument( static template_parameter make_argument(const std::string &type,
std::string type, const std::optional<std::string> &default_value = {}) const std::optional<std::string> &default_value = {})
{ {
template_parameter p; template_parameter p;
p.set_kind(template_parameter_kind_t::argument); p.set_kind(template_parameter_kind_t::argument);
p.set_type(std::move(type)); p.set_type(type);
if (default_value) if (default_value)
p.set_default_value(default_value.value()); p.set_default_value(default_value.value());
return p; return p;
} }
static template_parameter make_unexposed_argument( static template_parameter make_unexposed_argument(const std::string &type,
std::string type, const std::optional<std::string> &default_value = {}) const std::optional<std::string> &default_value = {})
{ {
template_parameter p = make_argument(std::move(type), default_value); template_parameter p = make_argument(type, default_value);
p.set_unexposed(true); p.set_unexposed(true);
return p; return p;
} }
@@ -178,7 +179,7 @@ public:
private: private:
template_parameter() = default; template_parameter() = default;
template_parameter_kind_t kind_; template_parameter_kind_t kind_{template_parameter_kind_t::template_type};
/// Represents the type of non-type template parameters /// Represents the type of non-type template parameters
/// e.g. 'int' or type of template arguments /// e.g. 'int' or type of template arguments

View File

@@ -32,8 +32,6 @@ void generator::generate_relationships(
{ {
LOG_DBG("Generating relationships for file {}", f.full_name(true)); LOG_DBG("Generating relationships for file {}", f.full_name(true));
namespace json_common = clanguml::common::generators::json;
if (f.type() == common::model::source_file_t::kDirectory) { if (f.type() == common::model::source_file_t::kDirectory) {
util::for_each(f, [this, &parent](const auto &file) { util::for_each(f, [this, &parent](const auto &file) {
generate_relationships( generate_relationships(
@@ -93,7 +91,7 @@ void generator::generate(std::ostream &ostr) const
// Generate files and folders // Generate files and folders
util::for_each_if( util::for_each_if(
m_model, [](const auto & /*f*/) { return true; }, m_model, [](const auto & /*f*/) { return true; },
[this, &ostr](const auto &f) { [this](const auto &f) {
generate(dynamic_cast<source_file &>(*f), json_); generate(dynamic_cast<source_file &>(*f), json_);
}); });

View File

@@ -48,7 +48,7 @@ void to_json(nlohmann::json &j, const activity &c)
j["participant_id"] = std::to_string(c.from()); j["participant_id"] = std::to_string(c.from());
} }
} // namespace clanguml::class_diagram::model } // namespace clanguml::sequence_diagram::model
namespace clanguml::sequence_diagram::generators::json { namespace clanguml::sequence_diagram::generators::json {
@@ -172,11 +172,8 @@ void generator::generate_call(const message &m, nlohmann::json &parent) const
m.from(), to, m.to()); m.from(), to, m.to());
} }
void generator::generate_activity( void generator::generate_activity(const activity &a,
common::model::diagram_element::id_t activity_id, const activity &a, std::vector<common::model::diagram_element::id_t> &visited) const
nlohmann::json &unused,
std::vector<common::model::diagram_element::id_t> &visited,
std::optional<nlohmann::json> nested_block) const
{ {
// Generate calls from this activity to other activities // Generate calls from this activity to other activities
for (const auto &m : a.messages()) { for (const auto &m : a.messages()) {
@@ -265,8 +262,7 @@ void generator::process_call_message(const model::message &m,
LOG_DBG("Creating activity {} --> {} - missing sequence {}", LOG_DBG("Creating activity {} --> {} - missing sequence {}",
m.from(), m.to(), m.to()); m.from(), m.to(), m.to());
generate_activity(m.to(), m_model.get_activity(m.to()), generate_activity(m_model.get_activity(m.to()), visited);
current_block_statement(), visited, {});
} }
} }
else else
@@ -644,8 +640,8 @@ void generator::generate(std::ostream &ostr) const
block_statements_stack_.push_back(std::ref(sequence)); block_statements_stack_.push_back(std::ref(sequence));
generate_activity(start_from, m_model.get_activity(start_from), generate_activity(
sequence, visited_participants, {}); m_model.get_activity(start_from), visited_participants);
json_["sequences"].push_back(std::move(sequence)); json_["sequences"].push_back(std::move(sequence));
@@ -666,4 +662,4 @@ void generator::generate(std::ostream &ostr) const
ostr << json_; ostr << json_;
} }
} // namespace clanguml::sequence_diagram::generators::plantuml } // namespace clanguml::sequence_diagram::generators::json

View File

@@ -53,10 +53,8 @@ public:
void generate_participant( void generate_participant(
nlohmann::json &parent, const std::string &name) const; nlohmann::json &parent, const std::string &name) const;
void generate_activity(common::model::diagram_element::id_t activity_id, void generate_activity(const sequence_diagram::model::activity &a,
const sequence_diagram::model::activity &a, nlohmann::json &parent, std::vector<common::model::diagram_element::id_t> &visited) const;
std::vector<common::model::diagram_element::id_t> &visited,
std::optional<nlohmann::json> nested_block) const;
void generate(std::ostream &ostr) const override; void generate(std::ostream &ostr) const override;

View File

@@ -185,7 +185,7 @@ std::string method::message_name(message_render_mode mode) const
{ {
constexpr auto kAbbreviatedMethodArgumentsLength{15}; constexpr auto kAbbreviatedMethodArgumentsLength{15};
const std::string style = ""; const std::string style{};
if (mode == message_render_mode::no_arguments) { if (mode == message_render_mode::no_arguments) {
return fmt::format("{}{}(){}{}", style, method_name(), return fmt::format("{}{}(){}{}", style, method_name(),

View File

@@ -1606,8 +1606,13 @@ translation_unit_visitor::build_template_instantiation_process_type_argument(
// If this is a nested template type - add nested templates as // If this is a nested template type - add nested templates as
// template arguments // template arguments
if (arg.getAsType()->getAs<clang::FunctionType>() != nullptr) { if (const auto *function_template_type =
arg.getAsType()->getAs<clang::FunctionType>();
function_template_type != nullptr) {
// TODO // TODO
argument = template_parameter::make_argument(
common::to_string(function_template_type->getReturnType(),
template_decl->getASTContext()));
} }
else if (const auto *nested_template_type = else if (const auto *nested_template_type =
arg.getAsType()->getAs<clang::TemplateSpecializationType>(); arg.getAsType()->getAs<clang::TemplateSpecializationType>();