Fixed clang-tidy warnings
This commit is contained in:
@@ -48,6 +48,7 @@ Checks: >-
|
||||
-readability-function-cognitive-complexity,
|
||||
-readability-const-return-type,
|
||||
-readability-simplify-boolean-expr,
|
||||
-readability-make-member-function-const,
|
||||
-darwin*,
|
||||
-zircon*
|
||||
WarningsAsErrors: '*'
|
||||
|
||||
@@ -383,10 +383,12 @@ void template_builder::process_template_arguments(
|
||||
const auto *maybe_type_parm_decl =
|
||||
clang::dyn_cast<clang::TemplateTypeParmDecl>(
|
||||
template_decl->getTemplateParameters()->getParam(
|
||||
std::min<int>(arg_index,
|
||||
template_decl->getTemplateParameters()->size() -
|
||||
std::min<unsigned>(arg_index,
|
||||
static_cast<unsigned>(
|
||||
template_decl->getTemplateParameters()
|
||||
->size()) -
|
||||
1)));
|
||||
if (maybe_type_parm_decl &&
|
||||
if (maybe_type_parm_decl != nullptr &&
|
||||
maybe_type_parm_decl->hasDefaultArgument()) {
|
||||
continue;
|
||||
}
|
||||
@@ -528,9 +530,12 @@ clang::QualType template_builder::consume_context(
|
||||
ctx.pr = common::model::rpqualifier::kRValueReference;
|
||||
try_again = true;
|
||||
}
|
||||
else if (type->isMemberFunctionPointerType()) {
|
||||
const auto ref_qualifier = type->getPointeeType()
|
||||
->getAs<clang::FunctionProtoType>()
|
||||
else if (type->isMemberFunctionPointerType() &&
|
||||
type->getPointeeType()->getAs<clang::FunctionProtoType>() !=
|
||||
nullptr) {
|
||||
const auto ref_qualifier =
|
||||
type->getPointeeType() // NOLINT
|
||||
->getAs<clang::FunctionProtoType>() // NOLINT
|
||||
->getRefQualifier();
|
||||
|
||||
if (ref_qualifier == clang::RefQualifierKind::RQ_RValue) {
|
||||
@@ -569,7 +574,7 @@ clang::QualType template_builder::consume_context(
|
||||
ctx.is_volatile = type.isVolatileQualified();
|
||||
}
|
||||
|
||||
tp.push_context(std::move(ctx));
|
||||
tp.push_context(ctx);
|
||||
|
||||
if (type->isMemberFunctionPointerType())
|
||||
return type;
|
||||
@@ -587,7 +592,7 @@ template_parameter template_builder::process_type_argument(
|
||||
std::optional<template_parameter> argument;
|
||||
|
||||
if (type->getAs<clang::ElaboratedType>() != nullptr) {
|
||||
type = type->getAs<clang::ElaboratedType>()->getNamedType();
|
||||
type = type->getAs<clang::ElaboratedType>()->getNamedType(); // NOLINT
|
||||
}
|
||||
|
||||
auto type_name = common::to_string(type, &cls->getASTContext());
|
||||
@@ -715,7 +720,7 @@ std::string map_type_parameter_to_template_parameter(
|
||||
return tp;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
std::string map_type_parameter_to_template_parameter_name(
|
||||
const clang::Decl *decl, const std::string &type_parameter)
|
||||
@@ -784,13 +789,13 @@ std::vector<template_parameter> template_builder::process_pack_argument(
|
||||
const clang::NamedDecl *cls, class_ &template_instantiation,
|
||||
const clang::TemplateDecl *base_template_decl,
|
||||
const clang::TemplateArgument &arg, size_t argument_index,
|
||||
std::vector<template_parameter> &argument)
|
||||
std::vector<template_parameter> & /*argument*/)
|
||||
{
|
||||
assert(arg.getKind() == clang::TemplateArgument::Pack);
|
||||
|
||||
std::vector<template_parameter> res;
|
||||
|
||||
int pack_argument_index = argument_index;
|
||||
auto pack_argument_index = argument_index;
|
||||
|
||||
for (const auto &a : arg.getPackAsArray()) {
|
||||
argument_process_dispatch(parent, cls, template_instantiation,
|
||||
@@ -900,13 +905,14 @@ std::optional<template_parameter> template_builder::try_as_array(
|
||||
if (array_type->isDependentSizedArrayType() &&
|
||||
array_type->getDependence() ==
|
||||
clang::TypeDependence::DependentInstantiation) {
|
||||
argument.add_template_param(template_parameter::make_template_type(
|
||||
common::to_string(((clang::DependentSizedArrayType *)array_type)
|
||||
argument.add_template_param(
|
||||
template_parameter::make_template_type(common::to_string(
|
||||
((clang::DependentSizedArrayType *)array_type) // NOLINT
|
||||
->getSizeExpr())));
|
||||
}
|
||||
else if (array_type->isConstantArrayType()) {
|
||||
argument.add_template_param(template_parameter::make_argument(
|
||||
std::to_string(((clang::ConstantArrayType *)array_type)
|
||||
std::to_string(((clang::ConstantArrayType *)array_type) // NOLINT
|
||||
->getSize()
|
||||
.getLimitedValue())));
|
||||
}
|
||||
@@ -1037,23 +1043,23 @@ template_builder::try_as_template_specialization_type(
|
||||
}
|
||||
|
||||
std::optional<template_parameter> template_builder::try_as_template_parm_type(
|
||||
const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl,
|
||||
const clang::NamedDecl *cls, const clang::TemplateDecl * /*template_decl*/,
|
||||
clang::QualType &type)
|
||||
{
|
||||
auto is_variadic{false};
|
||||
|
||||
auto type_parameter =
|
||||
const auto *type_parameter =
|
||||
common::dereference(type)->getAs<clang::TemplateTypeParmType>();
|
||||
|
||||
auto type_name = common::to_string(type, &cls->getASTContext());
|
||||
|
||||
if (type_parameter == nullptr) {
|
||||
if (common::dereference(type)->getAs<clang::PackExpansionType>()) {
|
||||
if (const auto *pet =
|
||||
common::dereference(type)->getAs<clang::PackExpansionType>();
|
||||
pet != nullptr) {
|
||||
is_variadic = true;
|
||||
type_parameter = common::dereference(type)
|
||||
->getAs<clang::PackExpansionType>()
|
||||
->getPattern()
|
||||
->getAs<clang::TemplateTypeParmType>();
|
||||
type_parameter =
|
||||
pet->getPattern()->getAs<clang::TemplateTypeParmType>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1076,7 +1082,7 @@ std::optional<template_parameter> template_builder::try_as_template_parm_type(
|
||||
}
|
||||
|
||||
std::optional<template_parameter> template_builder::try_as_lambda(
|
||||
const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl,
|
||||
const clang::NamedDecl *cls, const clang::TemplateDecl * /*template_decl*/,
|
||||
clang::QualType &type)
|
||||
{
|
||||
auto type_name = common::to_string(type, &cls->getASTContext());
|
||||
@@ -1095,9 +1101,9 @@ std::optional<template_parameter> template_builder::try_as_lambda(
|
||||
|
||||
std::optional<template_parameter> template_builder::try_as_record_type(
|
||||
std::optional<clanguml::class_diagram::model::class_ *> &parent,
|
||||
const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl,
|
||||
const clang::NamedDecl * /*cls*/, const clang::TemplateDecl *template_decl,
|
||||
clang::QualType &type, class_ &template_instantiation,
|
||||
size_t argument_index)
|
||||
size_t /*argument_index*/)
|
||||
{
|
||||
const auto *record_type =
|
||||
common::dereference(type)->getAs<clang::RecordType>();
|
||||
@@ -1152,8 +1158,8 @@ std::optional<template_parameter> template_builder::try_as_record_type(
|
||||
}
|
||||
|
||||
std::optional<template_parameter> template_builder::try_as_enum_type(
|
||||
std::optional<clanguml::class_diagram::model::class_ *> &parent,
|
||||
const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl,
|
||||
std::optional<clanguml::class_diagram::model::class_ *> & /*parent*/,
|
||||
const clang::NamedDecl * /*cls*/, const clang::TemplateDecl *template_decl,
|
||||
clang::QualType &type, class_ &template_instantiation)
|
||||
{
|
||||
const auto *enum_type = type->getAs<clang::EnumType>();
|
||||
@@ -1177,7 +1183,7 @@ std::optional<template_parameter> template_builder::try_as_enum_type(
|
||||
}
|
||||
|
||||
std::optional<template_parameter> template_builder::try_as_builtin_type(
|
||||
std::optional<clanguml::class_diagram::model::class_ *> &parent,
|
||||
std::optional<clanguml::class_diagram::model::class_ *> & /*parent*/,
|
||||
clang::QualType &type, const clang::TemplateDecl *template_decl)
|
||||
{
|
||||
const auto *builtin_type = type->getAs<clang::BuiltinType>();
|
||||
|
||||
@@ -182,4 +182,4 @@ private:
|
||||
clang::SourceManager &source_manager_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace clanguml::class_diagram::visitor
|
||||
@@ -480,7 +480,10 @@ bool is_bracket(const std::string &b)
|
||||
return b == "(" || b == ")" || b == "[" || b == "]";
|
||||
}
|
||||
|
||||
bool is_identifier_character(char c) { return std::isalnum(c) || c == '_'; }
|
||||
bool is_identifier_character(char c)
|
||||
{
|
||||
return std::isalnum(c) != 0 || c == '_';
|
||||
}
|
||||
|
||||
bool is_identifier(const std::string &t)
|
||||
{
|
||||
@@ -509,7 +512,7 @@ bool is_keyword(const std::string &t)
|
||||
|
||||
bool is_qualified_identifier(const std::string &t)
|
||||
{
|
||||
return std::isalpha(t.at(0)) &&
|
||||
return std::isalpha(t.at(0)) != 0 &&
|
||||
std::all_of(t.begin(), t.end(), [](const char c) {
|
||||
return is_identifier_character(c) || c == ':';
|
||||
});
|
||||
@@ -547,7 +550,7 @@ std::vector<std::string> tokenize_unexposed_template_parameter(
|
||||
for (const auto &word : spaced_out) {
|
||||
if (is_qualified_identifier(word)) {
|
||||
if (word != "class" && word != "templated" && word != "struct")
|
||||
result.push_back(word);
|
||||
result.emplace_back(word);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -557,17 +560,17 @@ std::vector<std::string> tokenize_unexposed_template_parameter(
|
||||
if (c == '(' || c == ')' || c == '[' || c == ']' || c == '<' ||
|
||||
c == '>') {
|
||||
if (!tok.empty())
|
||||
result.push_back(tok);
|
||||
result.push_back(std::string{c});
|
||||
result.emplace_back(tok);
|
||||
result.emplace_back(std::string{c});
|
||||
tok.clear();
|
||||
}
|
||||
else if (c == ':') {
|
||||
if (!tok.empty() && tok != ":") {
|
||||
result.push_back(tok);
|
||||
result.emplace_back(tok);
|
||||
tok = ":";
|
||||
}
|
||||
else if (tok == ":") {
|
||||
result.push_back("::");
|
||||
result.emplace_back("::");
|
||||
tok = "";
|
||||
}
|
||||
else {
|
||||
@@ -576,30 +579,30 @@ std::vector<std::string> tokenize_unexposed_template_parameter(
|
||||
}
|
||||
else if (c == ',') {
|
||||
if (!tok.empty()) {
|
||||
result.push_back(tok);
|
||||
result.emplace_back(tok);
|
||||
}
|
||||
result.push_back(",");
|
||||
result.emplace_back(",");
|
||||
tok.clear();
|
||||
}
|
||||
else if (c == '*') {
|
||||
if (!tok.empty()) {
|
||||
result.push_back(tok);
|
||||
result.emplace_back(tok);
|
||||
}
|
||||
result.push_back("*");
|
||||
result.emplace_back("*");
|
||||
tok.clear();
|
||||
}
|
||||
else if (c == '.') {
|
||||
// This can only be the case if we have a variadic template,
|
||||
// right?
|
||||
if (tok == "..") {
|
||||
result.push_back("...");
|
||||
result.emplace_back("...");
|
||||
tok.clear();
|
||||
}
|
||||
else if (tok == ".") {
|
||||
tok = "..";
|
||||
}
|
||||
else if (!tok.empty()) {
|
||||
result.push_back(tok);
|
||||
result.emplace_back(tok);
|
||||
tok = ".";
|
||||
}
|
||||
}
|
||||
@@ -612,7 +615,7 @@ std::vector<std::string> tokenize_unexposed_template_parameter(
|
||||
|
||||
if (!tok.empty()) {
|
||||
if (tok != "class" && tok != "typename" && word != "struct")
|
||||
result.push_back(tok);
|
||||
result.emplace_back(tok);
|
||||
tok.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ std::string context::to_string() const
|
||||
{
|
||||
std::vector<std::string> cv_qualifiers;
|
||||
if (is_const)
|
||||
cv_qualifiers.push_back("const");
|
||||
cv_qualifiers.emplace_back("const");
|
||||
if (is_volatile)
|
||||
cv_qualifiers.push_back("volatile");
|
||||
cv_qualifiers.emplace_back("volatile");
|
||||
|
||||
auto res = fmt::format("{}", fmt::join(cv_qualifiers, " "));
|
||||
|
||||
@@ -303,7 +303,8 @@ int template_parameter::calculate_specialization_match(
|
||||
!base_template_parameter.deduced_context().empty() &&
|
||||
util::starts_with(
|
||||
deduced_context(), base_template_parameter.deduced_context()))
|
||||
res += base_template_parameter.deduced_context().size();
|
||||
res += static_cast<int>(
|
||||
base_template_parameter.deduced_context().size());
|
||||
}
|
||||
|
||||
return res;
|
||||
@@ -410,10 +411,9 @@ std::string template_parameter::to_string(
|
||||
|
||||
if (skip_qualifiers)
|
||||
return unqualified;
|
||||
else {
|
||||
|
||||
return util::join(" ", unqualified, deduced_context_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (is_member_pointer()) {
|
||||
assert(template_params().size() > 1);
|
||||
@@ -433,10 +433,9 @@ std::string template_parameter::to_string(
|
||||
"{} ({}::*)({})", return_type, class_type, fmt::join(args, ","));
|
||||
if (skip_qualifiers)
|
||||
return unqualified;
|
||||
else {
|
||||
|
||||
return util::join(" ", unqualified, deduced_context_str());
|
||||
}
|
||||
}
|
||||
|
||||
std::string res;
|
||||
const auto maybe_type = type();
|
||||
@@ -627,7 +626,7 @@ bool template_parameter::is_data_pointer() const { return is_data_pointer_; }
|
||||
void template_parameter::is_array(bool a) { is_array_ = a; }
|
||||
bool template_parameter::is_array() const { return is_array_; }
|
||||
|
||||
void template_parameter::push_context(const context q)
|
||||
void template_parameter::push_context(const context &q)
|
||||
{
|
||||
context_.push_front(q);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
void is_array(bool a);
|
||||
bool is_array() const;
|
||||
|
||||
void push_context(const context q);
|
||||
void push_context(const context &q);
|
||||
const std::deque<context> &deduced_context() const;
|
||||
void deduced_context(const std::deque<context> &c);
|
||||
|
||||
|
||||
@@ -40,4 +40,4 @@ private:
|
||||
id_map_;
|
||||
};
|
||||
|
||||
} // namespace clanguml::class_diagram::visitor
|
||||
} // namespace clanguml::common::visitor
|
||||
Reference in New Issue
Block a user