Refactoring template_parameter model

This commit is contained in:
Bartek Kryza
2023-03-16 01:53:10 +01:00
parent 3a01d8689c
commit 6d4533018b
10 changed files with 393 additions and 254 deletions

View File

@@ -44,15 +44,22 @@ 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["type"] = c.type(); j["kind"] = to_string(c.kind());
j["name"] = c.name();
if (!c.default_value().empty()) if(c.kind() == template_parameter_kind_t::template_type) {
j["default_value"] = c.default_value(); j["name"] = c.name().value();
j["is_template_parameter"] = c.is_template_parameter(); }
j["is_template_template_parameter"] = c.is_template_template_parameter();
if (const auto &constraint = c.concept_constraint(); constraint)
j["concept_constraint"] = constraint.value(); // j["type"] = c.type();
j["is_variadic"] = c.is_variadic(); // j["name"] = c.name();
// if (!c.default_value().empty())
// j["default_value"] = c.default_value();
// j["is_template_parameter"] = c.is_template_parameter();
// j["is_template_template_parameter"] = c.is_template_template_parameter();
// if (const auto &constraint = c.concept_constraint(); constraint)
// j["concept_constraint"] = constraint.value();
// j["is_variadic"] = c.is_variadic();
} }
void to_json(nlohmann::json &j, const relationship &c) void to_json(nlohmann::json &j, const relationship &c)

View File

@@ -949,12 +949,15 @@ bool translation_unit_visitor::process_template_parameters(
nullptr) { nullptr) {
const auto *template_type_parameter = const auto *template_type_parameter =
clang::dyn_cast_or_null<clang::TemplateTypeParmDecl>(parameter); clang::dyn_cast_or_null<clang::TemplateTypeParmDecl>(parameter);
template_parameter ct;
ct.set_type(""); std::optional<std::string> default_arg;
ct.is_template_parameter(true); if (template_type_parameter->hasDefaultArgument()) {
ct.set_name(template_type_parameter->getNameAsString()); default_arg =
ct.set_default_value(""); template_type_parameter->getDefaultArgument().getAsString();
ct.is_variadic(template_type_parameter->isParameterPack()); }
auto ct = template_parameter::make_template_type(
template_type_parameter->getNameAsString(), default_arg,
template_type_parameter->isParameterPack());
if (template_type_parameter->getTypeConstraint() != nullptr) { if (template_type_parameter->getTypeConstraint() != nullptr) {
util::apply_if_not_null( util::apply_if_not_null(
@@ -970,7 +973,7 @@ bool translation_unit_visitor::process_template_parameters(
{relationship_t::kConstraint, {relationship_t::kConstraint,
get_ast_local_id(named_concept->getID()) get_ast_local_id(named_concept->getID())
.value(), .value(),
access_t::kNone, ct.name()}); access_t::kNone, ct.name().value()});
} }
}); });
} }
@@ -982,12 +985,14 @@ bool translation_unit_visitor::process_template_parameters(
const auto *template_nontype_parameter = const auto *template_nontype_parameter =
clang::dyn_cast_or_null<clang::NonTypeTemplateParmDecl>( clang::dyn_cast_or_null<clang::NonTypeTemplateParmDecl>(
parameter); parameter);
template_parameter ct; std::optional<std::string> default_arg;
ct.set_type(template_nontype_parameter->getType().getAsString()); if (template_nontype_parameter->hasDefaultArgument())
ct.set_name(template_nontype_parameter->getNameAsString()); default_arg = common::to_string(
ct.is_template_parameter(false); template_nontype_parameter->getDefaultArgument());
ct.set_default_value(""); auto ct = template_parameter::make_non_type_template(
ct.is_variadic(template_nontype_parameter->isParameterPack()); template_nontype_parameter->getType().getAsString(),
template_nontype_parameter->getNameAsString(), default_arg,
template_nontype_parameter->isParameterPack());
c.add_template(std::move(ct)); c.add_template(std::move(ct));
} }
@@ -996,12 +1001,15 @@ bool translation_unit_visitor::process_template_parameters(
const auto *template_template_parameter = const auto *template_template_parameter =
clang::dyn_cast_or_null<clang::TemplateTemplateParmDecl>( clang::dyn_cast_or_null<clang::TemplateTemplateParmDecl>(
parameter); parameter);
template_parameter ct; std::optional<std::string> default_arg;
ct.set_type(""); if (template_template_parameter->hasDefaultArgument())
ct.set_name(template_template_parameter->getNameAsString() + "<>"); default_arg = common::to_string(
ct.is_template_parameter(true); template_template_parameter->getDefaultArgument()
ct.set_default_value(""); .getArgument()
ct.is_variadic(template_template_parameter->isParameterPack()); .getAsExpr());
auto ct = template_parameter::make_template_template_type(
template_template_parameter->getNameAsString(), default_arg,
template_template_parameter->isParameterPack());
c.add_template(std::move(ct)); c.add_template(std::move(ct));
} }
@@ -1798,8 +1806,7 @@ void translation_unit_visitor::process_template_specialization_argument(
const auto argument_kind = arg.getKind(); const auto argument_kind = arg.getKind();
if (argument_kind == clang::TemplateArgument::Type) { if (argument_kind == clang::TemplateArgument::Type) {
template_parameter argument; auto argument = template_parameter::make_argument({});
argument.is_template_parameter(false);
// 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
@@ -1812,7 +1819,7 @@ void translation_unit_visitor::process_template_specialization_argument(
.getAsTemplateDecl() .getAsTemplateDecl()
->getQualifiedNameAsString(); ->getQualifiedNameAsString();
argument.set_name(nested_template_name); argument.set_type(nested_template_name);
auto nested_template_instantiation = build_template_instantiation( auto nested_template_instantiation = build_template_instantiation(
*nested_template_type, {&template_instantiation}); *nested_template_type, {&template_instantiation});
@@ -1821,12 +1828,6 @@ void translation_unit_visitor::process_template_specialization_argument(
for (const auto &t : nested_template_instantiation->templates()) for (const auto &t : nested_template_instantiation->templates())
argument.add_template_param(t); argument.add_template_param(t);
// Check if this template should be simplified (e.g. system
// template aliases such as 'std:basic_string<char>' should be
// simply 'std::string')
simplify_system_template(argument,
argument.to_string(config().using_namespace(), false));
} }
else if (arg.getAsType()->getAs<clang::TemplateTypeParmType>() != else if (arg.getAsType()->getAs<clang::TemplateTypeParmType>() !=
nullptr) { nullptr) {
@@ -1857,7 +1858,7 @@ void translation_unit_visitor::process_template_specialization_argument(
} }
} }
argument.set_name(type_name); argument.set_type(type_name);
} }
else { else {
auto type_name = auto type_name =
@@ -1879,7 +1880,7 @@ void translation_unit_visitor::process_template_specialization_argument(
type_name.substr(0, type_name.find('<')); type_name.substr(0, type_name.find('<'));
ensure_lambda_type_is_relative(unexposed_type_name); ensure_lambda_type_is_relative(unexposed_type_name);
argument.set_name(unexposed_type_name); argument.set_type(unexposed_type_name);
} }
else if (type_name.find("type-parameter-") == 0) { else if (type_name.find("type-parameter-") == 0) {
auto declaration_text = common::get_source_text_raw( auto declaration_text = common::get_source_text_raw(
@@ -1903,10 +1904,10 @@ void translation_unit_visitor::process_template_specialization_argument(
// Otherwise just set the name for the template argument to // Otherwise just set the name for the template argument to
// whatever clang says // whatever clang says
argument.set_name(type_name); argument.set_type(type_name);
} }
else { else {
argument.set_name(type_name); argument.set_type(type_name);
} }
} }
@@ -1919,23 +1920,18 @@ void translation_unit_visitor::process_template_specialization_argument(
template_instantiation.add_template(std::move(argument)); template_instantiation.add_template(std::move(argument));
} }
else if (argument_kind == clang::TemplateArgument::Integral) { else if (argument_kind == clang::TemplateArgument::Integral) {
template_parameter argument; auto argument = template_parameter::make_argument(
argument.is_template_parameter(false); std::to_string(arg.getAsIntegral().getExtValue()));
argument.set_type(std::to_string(arg.getAsIntegral().getExtValue()));
template_instantiation.add_template(std::move(argument)); template_instantiation.add_template(std::move(argument));
} }
else if (argument_kind == clang::TemplateArgument::Expression) { else if (argument_kind == clang::TemplateArgument::Expression) {
template_parameter argument; auto argument =
argument.is_template_parameter(false); template_parameter::make_argument(common::get_source_text(
argument.set_type(common::get_source_text( arg.getAsExpr()->getSourceRange(), source_manager()));
arg.getAsExpr()->getSourceRange(), source_manager()));
template_instantiation.add_template(std::move(argument)); template_instantiation.add_template(std::move(argument));
} }
else if (argument_kind == clang::TemplateArgument::TemplateExpansion) { else if (argument_kind == clang::TemplateArgument::TemplateExpansion) {
template_parameter argument; // TODO
argument.is_template_parameter(true);
cls->getLocation().dump(source_manager());
} }
else if (argument_kind == clang::TemplateArgument::Pack) { else if (argument_kind == clang::TemplateArgument::Pack) {
// This will only work for now if pack is at the end // This will only work for now if pack is at the end
@@ -1973,17 +1969,18 @@ 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());
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 = ctx.get_name_with_namespace(ct.type());
auto type_with_namespace = auto type_with_namespace =
std::make_optional<common::model::namespace_>(ct.type()); std::make_optional<common::model::namespace_>(ct.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()}; type_with_namespace = common::model::namespace_{ct.type().value()};
} }
auto element_opt = diagram().get(type_with_namespace.value().to_string()); auto element_opt = diagram().get(type_with_namespace.value().to_string());
@@ -2293,26 +2290,27 @@ void translation_unit_visitor::
auto arg_index = 0; auto arg_index = 0;
for (const auto &arg : template_args) { for (const auto &arg : template_args) {
const auto argument_kind = arg.getKind(); const auto argument_kind = arg.getKind();
template_parameter argument; std::optional<template_parameter> argument;
if (argument_kind == clang::TemplateArgument::Template) { if (argument_kind == clang::TemplateArgument::Template) {
build_template_instantiation_process_template_argument( argument =
arg, argument); build_template_instantiation_process_template_argument(arg);
} }
else if (argument_kind == clang::TemplateArgument::Type) { else if (argument_kind == clang::TemplateArgument::Type) {
build_template_instantiation_process_type_argument(parent, argument = build_template_instantiation_process_type_argument(
full_template_specialization_name, template_decl, arg, parent, full_template_specialization_name, template_decl, arg,
template_instantiation, argument); template_instantiation);
} }
else if (argument_kind == clang::TemplateArgument::Integral) { else if (argument_kind == clang::TemplateArgument::Integral) {
build_template_instantiation_process_integral_argument( argument =
arg, argument); build_template_instantiation_process_integral_argument(arg);
} }
else if (argument_kind == clang::TemplateArgument::Expression) { else if (argument_kind == clang::TemplateArgument::Expression) {
build_template_instantiation_process_expression_argument( argument =
arg, argument); build_template_instantiation_process_expression_argument(arg);
} }
else { else {
LOG_ERROR("Unsupported argument type {}", arg.getKind()); LOG_ERROR("Unsupported argument type {}", arg.getKind());
continue;
} }
// We can figure this only when we encounter variadic param in // We can figure this only when we encounter variadic param in
@@ -2326,43 +2324,42 @@ void translation_unit_visitor::
if (!template_base_params.empty()) { if (!template_base_params.empty()) {
variadic_params = build_template_instantiation_add_base_classes( variadic_params = build_template_instantiation_add_base_classes(
template_instantiation, template_base_params, arg_index, template_instantiation, template_base_params, arg_index,
variadic_params, argument); variadic_params, argument.value());
} }
LOG_DBG("Adding template argument {} to template " LOG_DBG("Adding template argument {} to template "
"specialization/instantiation {}", "specialization/instantiation {}",
argument.name(), template_instantiation.name()); argument.value().to_string(config().using_namespace(), false),
template_instantiation.name());
simplify_system_template( simplify_system_template(argument.value(),
argument, argument.to_string(config().using_namespace(), false)); argument.value().to_string(config().using_namespace(), false));
template_instantiation.add_template(std::move(argument)); template_instantiation.add_template(std::move(argument.value()));
arg_index++; arg_index++;
} }
} }
void translation_unit_visitor:: template_parameter translation_unit_visitor::
build_template_instantiation_process_template_argument( build_template_instantiation_process_template_argument(
const clang::TemplateArgument &arg, template_parameter &argument) const const clang::TemplateArgument &arg) const
{ {
argument.is_template_parameter(true);
auto arg_name = auto arg_name =
arg.getAsTemplate().getAsTemplateDecl()->getQualifiedNameAsString(); arg.getAsTemplate().getAsTemplateDecl()->getQualifiedNameAsString();
argument.set_type(arg_name); return template_parameter::make_template_type(arg_name);
} }
void translation_unit_visitor:: template_parameter
build_template_instantiation_process_type_argument( translation_unit_visitor::build_template_instantiation_process_type_argument(
std::optional<clanguml::class_diagram::model::class_ *> &parent, std::optional<clanguml::class_diagram::model::class_ *> &parent,
const std::string &full_template_specialization_name, const std::string &full_template_specialization_name,
const clang::TemplateDecl *template_decl, const clang::TemplateDecl *template_decl,
const clang::TemplateArgument &arg, class_ &template_instantiation, const clang::TemplateArgument &arg, class_ &template_instantiation)
template_parameter &argument)
{ {
assert(arg.getKind() == clang::TemplateArgument::Type); assert(arg.getKind() == clang::TemplateArgument::Type);
argument.is_template_parameter(false); auto argument = template_parameter::make_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
@@ -2414,12 +2411,11 @@ void translation_unit_visitor::
arg.getAsType()->getAs<clang::TemplateSpecializationType>(); arg.getAsType()->getAs<clang::TemplateSpecializationType>();
nested_template_type != nullptr) { nested_template_type != nullptr) {
const auto nested_template_name = const auto nested_type_name = nested_template_type->getTemplateName()
nested_template_type->getTemplateName() .getAsTemplateDecl()
.getAsTemplateDecl() ->getQualifiedNameAsString();
->getQualifiedNameAsString();
argument.set_name(nested_template_name); argument.set_type(nested_type_name);
auto nested_template_instantiation = auto nested_template_instantiation =
build_template_instantiation(*nested_template_type, build_template_instantiation(*nested_template_type,
@@ -2462,7 +2458,7 @@ void translation_unit_visitor::
} }
else if (arg.getAsType()->getAs<clang::TemplateTypeParmType>() != nullptr) { else if (arg.getAsType()->getAs<clang::TemplateTypeParmType>() != nullptr) {
argument.is_template_parameter(true); argument.is_template_parameter(true);
argument.set_name( argument.set_type(
common::to_string(arg.getAsType(), template_decl->getASTContext())); common::to_string(arg.getAsType(), template_decl->getASTContext()));
} }
else { else {
@@ -2471,26 +2467,26 @@ void translation_unit_visitor::
template_instantiation, full_template_specialization_name, template_instantiation, full_template_specialization_name,
template_decl, arg, argument); template_decl, arg, argument);
} }
return argument;
} }
void translation_unit_visitor:: template_parameter translation_unit_visitor::
build_template_instantiation_process_integral_argument( build_template_instantiation_process_integral_argument(
const clang::TemplateArgument &arg, template_parameter &argument) const const clang::TemplateArgument &arg) const
{ {
assert(arg.getKind() == clang::TemplateArgument::Integral); assert(arg.getKind() == clang::TemplateArgument::Integral);
argument.is_template_parameter(false); return template_parameter::make_argument(
argument.set_type(std::to_string(arg.getAsIntegral().getExtValue())); std::to_string(arg.getAsIntegral().getExtValue()));
} }
void translation_unit_visitor:: template_parameter translation_unit_visitor::
build_template_instantiation_process_expression_argument( build_template_instantiation_process_expression_argument(
const clang::TemplateArgument &arg, template_parameter &argument) const const clang::TemplateArgument &arg) const
{ {
assert(arg.getKind() == clang::TemplateArgument::Expression); assert(arg.getKind() == clang::TemplateArgument::Expression);
return template_parameter::make_argument(common::get_source_text(
argument.is_template_parameter(false);
argument.set_type(common::get_source_text(
arg.getAsExpr()->getSourceRange(), source_manager())); arg.getAsExpr()->getSourceRange(), source_manager()));
} }
@@ -2505,7 +2501,7 @@ void translation_unit_visitor::
argument.is_template_parameter(false); argument.is_template_parameter(false);
argument.set_name( argument.set_type(
common::to_string(arg.getAsType(), template_decl->getASTContext())); common::to_string(arg.getAsType(), template_decl->getASTContext()));
if (const auto *record_type = arg.getAsType()->getAs<clang::RecordType>(); if (const auto *record_type = arg.getAsType()->getAs<clang::RecordType>();
@@ -2688,7 +2684,7 @@ void translation_unit_visitor::process_field(
for (const auto &template_argument : for (const auto &template_argument :
template_specialization.templates()) { template_specialization.templates()) {
LOG_DBG("Looking for nested relationships from {}:{} in " LOG_DBG("Looking for nested relationships from {}::{} in "
"template {}", "template {}",
c.full_name(false), field_name, c.full_name(false), field_name,
template_argument.to_string( template_argument.to_string(
@@ -2792,7 +2788,7 @@ bool translation_unit_visitor::simplify_system_template(
template_parameter &ct, const std::string &full_name) const template_parameter &ct, const std::string &full_name) const
{ {
if (config().type_aliases().count(full_name) > 0) { if (config().type_aliases().count(full_name) > 0) {
ct.set_name(config().type_aliases().at(full_name)); ct.set_type(config().type_aliases().at(full_name));
ct.clear_params(); ct.clear_params();
return true; return true;
} }

View File

@@ -218,25 +218,22 @@ private:
const clang::TemplateArgument &arg, const clang::TemplateArgument &arg,
common::model::template_parameter &argument); common::model::template_parameter &argument);
void build_template_instantiation_process_expression_argument( template_parameter build_template_instantiation_process_expression_argument(
const clang::TemplateArgument &arg, const clang::TemplateArgument &arg) const;
common::model::template_parameter &argument) const;
void build_template_instantiation_process_integral_argument( template_parameter build_template_instantiation_process_integral_argument(
const clang::TemplateArgument &arg, const clang::TemplateArgument &arg) const;
common::model::template_parameter &argument) const;
void build_template_instantiation_process_type_argument( template_parameter build_template_instantiation_process_type_argument(
std::optional<clanguml::class_diagram::model::class_ *> &parent, std::optional<clanguml::class_diagram::model::class_ *> &parent,
const std::string &full_template_specialization_name, const std::string &full_template_specialization_name,
const clang::TemplateDecl *template_decl, const clang::TemplateDecl *template_decl,
const clang::TemplateArgument &arg, const clang::TemplateArgument &arg,
model::class_ &template_instantiation, model::class_ &template_instantiation);
common::model::template_parameter &argument);
void build_template_instantiation_process_template_argument( common::model::template_parameter
const clang::TemplateArgument &arg, build_template_instantiation_process_template_argument(
common::model::template_parameter &argument) const; const clang::TemplateArgument &arg) const;
void ensure_lambda_type_is_relative(std::string &parameter_type) const; void ensure_lambda_type_is_relative(std::string &parameter_type) const;

View File

@@ -368,8 +368,14 @@ std::vector<common::model::template_parameter> parse_unexposed_template_params(
nested_params = parse_unexposed_template_params( nested_params = parse_unexposed_template_params(
nested_params_str, ns_resolve, depth + 1); nested_params_str, ns_resolve, depth + 1);
if (nested_params.empty()) if (nested_params.empty()) {
nested_params.emplace_back(nested_params_str); // We couldn't extract any nested template parameters from
// `nested_params_str` so just add it as type of template
// argument as is
nested_params.emplace_back(
template_parameter::make_unexposed_argument(
nested_params_str));
}
it = bracket_match_end - 1; it = bracket_match_end - 1;
} }
@@ -386,8 +392,8 @@ std::vector<common::model::template_parameter> parse_unexposed_template_params(
type += *it; type += *it;
} }
if (complete_class_template_argument) { if (complete_class_template_argument) {
template_parameter t; auto t = template_parameter::make_unexposed_argument(
t.set_type(ns_resolve(clanguml::util::trim(type))); ns_resolve(clanguml::util::trim(type)));
type = ""; type = "";
for (auto &&param : nested_params) for (auto &&param : nested_params)
t.add_template_param(std::move(param)); t.add_template_param(std::move(param));
@@ -399,8 +405,8 @@ std::vector<common::model::template_parameter> parse_unexposed_template_params(
} }
if (!type.empty()) { if (!type.empty()) {
template_parameter t; auto t = template_parameter::make_unexposed_argument(
t.set_type(ns_resolve(clanguml::util::trim(type))); ns_resolve(clanguml::util::trim(type)));
type = ""; type = "";
for (auto &&param : nested_params) for (auto &&param : nested_params)
t.add_template_param(std::move(param)); t.add_template_param(std::move(param));

View File

@@ -23,18 +23,38 @@
#include <utility> #include <utility>
namespace clanguml::common::model { namespace clanguml::common::model {
std::string to_string(template_parameter_kind_t k)
template_parameter::template_parameter(const std::string &type,
const std::string &name, std::string default_value, bool is_variadic)
: default_value_{std::move(default_value)}
, is_variadic_{is_variadic}
{ {
set_name(name); switch (k) {
set_type(type); case template_parameter_kind_t::template_type:
return "template_type";
case template_parameter_kind_t::template_template_type:
return "template_template_type";
case template_parameter_kind_t::non_type_template:
return "non_type_template";
case template_parameter_kind_t::argument:
return "argument";
case template_parameter_kind_t::concept_constraint:
return "concept_constraint";
default:
assert(0);
}
} }
// template_parameter::template_parameter(const std::optional<std::string>
// &type,
// const std::optional<std::string> &name,
// const std::optional<std::string> &default_value, bool is_variadic)
// : type_{type}
// , name_{name}
// , default_value_{std::move(default_value)}
// , is_variadic_{is_variadic}
//{
// }
void template_parameter::set_type(const std::string &type) void template_parameter::set_type(const std::string &type)
{ {
assert(kind_ != template_parameter_kind_t::template_type);
if (util::ends_with(type, std::string{"..."})) { if (util::ends_with(type, std::string{"..."})) {
type_ = type.substr(0, type.size() - 3); type_ = type.substr(0, type.size() - 3);
is_variadic_ = true; is_variadic_ = true;
@@ -43,16 +63,24 @@ void template_parameter::set_type(const std::string &type)
type_ = type; type_ = type;
} }
std::string template_parameter::type() const std::optional<std::string> template_parameter::type() const
{ {
if (is_variadic_ && !type_.empty()) if (!type_)
return type_ + "..."; return {};
if (is_variadic_)
return type_.value() + "...";
return type_; return type_;
} }
void template_parameter::set_name(const std::string &name) void template_parameter::set_name(const std::string &name)
{ {
assert(kind_ != template_parameter_kind_t::argument);
if (name.empty())
return;
if (util::ends_with(name, std::string{"..."})) { if (util::ends_with(name, std::string{"..."})) {
name_ = name.substr(0, name.size() - 3); name_ = name.substr(0, name.size() - 3);
is_variadic_ = true; is_variadic_ = true;
@@ -61,10 +89,13 @@ void template_parameter::set_name(const std::string &name)
name_ = name; name_ = name;
} }
std::string template_parameter::name() const std::optional<std::string> template_parameter::name() const
{ {
if (is_variadic_ && type_.empty()) if (!name_)
return name_ + "..."; return {};
if (is_variadic_ && (kind_ != template_parameter_kind_t::non_type_template))
return name_.value() + "...";
return name_; return name_;
} }
@@ -74,7 +105,10 @@ void template_parameter::set_default_value(const std::string &value)
default_value_ = value; default_value_ = value;
} }
std::string template_parameter::default_value() const { return default_value_; } const std::optional<std::string> &template_parameter::default_value() const
{
return default_value_;
}
void template_parameter::is_variadic(bool is_variadic) noexcept void template_parameter::is_variadic(bool is_variadic) noexcept
{ {
@@ -138,14 +172,17 @@ std::string template_parameter::to_string(
{ {
using clanguml::common::model::namespace_; using clanguml::common::model::namespace_;
assert(!(!type().empty() && concept_constraint().has_value())); assert(!(type().has_value() && concept_constraint().has_value()));
std::string res; std::string res;
if (!type().empty()) { const auto maybe_type = type();
if (maybe_type) {
if (!relative) if (!relative)
res += namespace_{type()}.to_string(); res += namespace_{*maybe_type}.to_string();
else else
res += namespace_{type()}.relative_to(using_namespace).to_string(); res += namespace_{*maybe_type}
.relative_to(using_namespace)
.to_string();
} }
const auto &maybe_concept_constraint = concept_constraint(); const auto &maybe_concept_constraint = concept_constraint();
@@ -159,14 +196,19 @@ std::string template_parameter::to_string(
.to_string(); .to_string();
} }
if (!name().empty()) { const auto maybe_name = name();
if (!type().empty() || maybe_concept_constraint)
if (maybe_name) {
if ((maybe_type && !maybe_type.value().empty()) ||
maybe_concept_constraint)
res += " "; res += " ";
if (!relative) if (!relative)
res += namespace_{name()}.to_string(); res += namespace_{*maybe_name}.to_string();
else else
res += namespace_{name()}.relative_to(using_namespace).to_string(); res += namespace_{*maybe_name}
.relative_to(using_namespace)
.to_string();
} }
// Render nested template params // Render nested template params
@@ -181,9 +223,10 @@ std::string template_parameter::to_string(
res += fmt::format("<{}>", fmt::join(params, ",")); res += fmt::format("<{}>", fmt::join(params, ","));
} }
if (!default_value().empty()) { const auto &maybe_default_value = default_value();
if (maybe_default_value) {
res += "="; res += "=";
res += default_value(); res += maybe_default_value.value();
} }
return res; return res;
@@ -200,7 +243,8 @@ bool template_parameter::find_nested_relationships(
// If this type argument should be included in the relationship // If this type argument should be included in the relationship
// just add it and skip recursion (e.g. this is a user defined type) // just add it and skip recursion (e.g. this is a user defined type)
if (should_include(name())) { const auto maybe_type = type();
if (maybe_type && should_include(maybe_type.value())) {
const auto maybe_id = id(); const auto maybe_id = id();
if (maybe_id) { if (maybe_id) {
nested_relationships.emplace_back(maybe_id.value(), hint); nested_relationships.emplace_back(maybe_id.value(), hint);
@@ -212,8 +256,11 @@ bool template_parameter::find_nested_relationships(
// interested what is stored inside it // interested what is stored inside it
else { else {
for (const auto &template_argument : template_params()) { for (const auto &template_argument : template_params()) {
const auto maybe_id = template_argument.id(); const auto maybe_id = template_argument.id();
if (should_include(template_argument.name()) && maybe_id) { const auto maybe_arg_type = template_argument.type();
if (maybe_id && maybe_arg_type && should_include(*maybe_arg_type)) {
nested_relationships.emplace_back(maybe_id.value(), hint); nested_relationships.emplace_back(maybe_id.value(), hint);

View File

@@ -26,30 +26,105 @@
namespace clanguml::common::model { namespace clanguml::common::model {
/// @brief Represents template parameter or template argument enum class template_parameter_kind_t {
template_type,
template_template_type,
non_type_template,
argument, // a.k.a. type parameter specialization
concept_constraint
};
std::string to_string(template_parameter_kind_t k);
/// @brief Represents template parameter, template arguments or concept
/// constraints
/// ///
/// This class can represent both template parameter and template arguments, /// This class can represent both template parameter and template arguments,
/// including variadic parameters and instantiations with /// including variadic parameters and instantiations with
/// nested templates /// nested templates
class template_parameter { class template_parameter {
public: template_parameter() = default;
template_parameter(const std::string &type = "",
const std::string &name = "", std::string default_value = "",
bool is_variadic = false);
template_parameter(const template_parameter &right) = default; public:
static template_parameter make_template_type(std::string name,
const std::optional<std::string> &default_value = {},
bool is_variadic = false)
{
template_parameter p;
p.set_kind(template_parameter_kind_t::template_type);
p.set_name(std::move(name));
p.is_variadic(is_variadic);
if (default_value)
p.set_default_value(default_value.value());
return p;
}
static template_parameter make_template_template_type(std::string name,
const std::optional<std::string> &default_value = {},
bool is_variadic = false)
{
template_parameter p;
p.set_kind(template_parameter_kind_t::template_template_type);
p.set_name(name + "<>");
if (default_value)
p.set_default_value(default_value.value());
p.is_variadic(is_variadic);
return p;
}
static template_parameter make_non_type_template(std::string type,
const std::optional<std::string> &name,
const std::optional<std::string> &default_value = {},
bool is_variadic = false)
{
template_parameter p;
p.set_kind(template_parameter_kind_t::non_type_template);
p.set_type(std::move(type));
if (name)
p.set_name(name.value());
if (default_value)
p.set_default_value(default_value.value());
p.is_variadic(is_variadic);
return p;
}
static template_parameter make_argument(
std::string type, const std::optional<std::string> &default_value = {})
{
template_parameter p;
p.set_kind(template_parameter_kind_t::argument);
p.set_type(std::move(type));
if (default_value)
p.set_default_value(default_value.value());
return p;
}
static template_parameter make_unexposed_argument(
std::string type, const std::optional<std::string> &default_value = {})
{
template_parameter p = make_argument(std::move(type), default_value);
p.set_unexposed(true);
return p;
}
// template_parameter(const std::optional<std::string> &type = {},
// const std::optional<std::string> &name = {},
// const std::optional<std::string> &default_value = {},
// bool is_variadic = false);
// template_parameter(const template_parameter &right) = default;
void set_type(const std::string &type); void set_type(const std::string &type);
std::string type() const; std::optional<std::string> type() const;
void set_id(const int64_t id) { id_ = id; } void set_id(const int64_t id) { id_ = id; }
std::optional<int64_t> id() const { return id_; } const std::optional<int64_t> &id() const { return id_; }
void set_name(const std::string &name); void set_name(const std::string &name);
std::string name() const; std::optional<std::string> name() const;
void set_default_value(const std::string &value); void set_default_value(const std::string &value);
std::string default_value() const; const std::optional<std::string> &default_value() const;
void is_variadic(bool is_variadic) noexcept; void is_variadic(bool is_variadic) noexcept;
bool is_variadic() const noexcept; bool is_variadic() const noexcept;
@@ -101,18 +176,29 @@ public:
const; const;
void set_concept_constraint(std::string constraint); void set_concept_constraint(std::string constraint);
const std::optional<std::string> &concept_constraint() const; const std::optional<std::string> &concept_constraint() const;
template_parameter_kind_t kind() const { return kind_; }
void set_kind(template_parameter_kind_t kind) { kind_ = kind; }
bool is_unexposed() const { return is_unexposed_; }
void set_unexposed(bool unexposed) { is_unexposed_ = unexposed; }
private: private:
template_parameter_kind_t kind_;
/// Represents the type of non-type template parameters /// Represents the type of non-type template parameters
/// e.g. 'int' /// e.g. 'int' or type of template arguments
std::string type_; std::optional<std::string> type_;
/// The name of the parameter (e.g. 'T' or 'N') /// The name of the parameter (e.g. 'T' or 'N')
std::string name_; std::optional<std::string> name_;
/// Default value of the template parameter /// Default value of the template parameter
std::string default_value_; std::optional<std::string> default_value_;
/// Whether the template parameter is a regular template parameter /// Whether the template parameter is a regular template parameter
/// When false, it is a non-type template parameter /// When false, it is a non-type template parameter
@@ -136,5 +222,7 @@ private:
std::vector<template_parameter> template_params_; std::vector<template_parameter> template_params_;
std::optional<int64_t> id_; std::optional<int64_t> id_;
bool is_unexposed_{false};
}; };
} // namespace clanguml::common::model } // namespace clanguml::common::model

View File

@@ -1353,12 +1353,14 @@ bool translation_unit_visitor::process_template_parameters(
nullptr) { nullptr) {
const auto *template_type_parameter = const auto *template_type_parameter =
clang::dyn_cast_or_null<clang::TemplateTypeParmDecl>(parameter); clang::dyn_cast_or_null<clang::TemplateTypeParmDecl>(parameter);
template_parameter ct; std::optional<std::string> default_arg;
ct.set_type(""); if (template_type_parameter->hasDefaultArgument()) {
ct.is_template_parameter(true); default_arg =
ct.set_name(template_type_parameter->getNameAsString()); template_type_parameter->getDefaultArgument().getAsString();
ct.set_default_value(""); }
ct.is_variadic(template_type_parameter->isParameterPack()); auto ct = template_parameter::make_template_type(
template_type_parameter->getNameAsString(), default_arg,
template_type_parameter->isParameterPack());
c.add_template(std::move(ct)); c.add_template(std::move(ct));
} }
@@ -1367,12 +1369,13 @@ bool translation_unit_visitor::process_template_parameters(
const auto *template_nontype_parameter = const auto *template_nontype_parameter =
clang::dyn_cast_or_null<clang::NonTypeTemplateParmDecl>( clang::dyn_cast_or_null<clang::NonTypeTemplateParmDecl>(
parameter); parameter);
template_parameter ct; std::optional<std::string> default_arg;
ct.set_type(template_nontype_parameter->getType().getAsString()); if (template_nontype_parameter->hasDefaultArgument())
ct.set_name(template_nontype_parameter->getNameAsString()); default_arg = common::to_string(
ct.is_template_parameter(false); template_nontype_parameter->getDefaultArgument());
ct.set_default_value(""); auto ct = template_parameter::make_non_type_template(
ct.is_variadic(template_nontype_parameter->isParameterPack()); template_nontype_parameter->getType().getAsString(),
template_nontype_parameter->getNameAsString(), default_arg);
c.add_template(std::move(ct)); c.add_template(std::move(ct));
} }
@@ -1381,12 +1384,15 @@ bool translation_unit_visitor::process_template_parameters(
const auto *template_template_parameter = const auto *template_template_parameter =
clang::dyn_cast_or_null<clang::TemplateTemplateParmDecl>( clang::dyn_cast_or_null<clang::TemplateTemplateParmDecl>(
parameter); parameter);
template_parameter ct; std::optional<std::string> default_arg;
ct.set_type(""); if (template_template_parameter->hasDefaultArgument())
ct.set_name(template_template_parameter->getNameAsString() + "<>"); default_arg = common::to_string(
ct.is_template_parameter(true); template_template_parameter->getDefaultArgument()
ct.set_default_value(""); .getArgument()
ct.is_variadic(template_template_parameter->isParameterPack()); .getAsExpr());
auto ct = template_parameter::make_template_template_type(
template_template_parameter->getNameAsString(), default_arg,
template_template_parameter->isParameterPack());
c.add_template(std::move(ct)); c.add_template(std::move(ct));
} }
@@ -1513,66 +1519,61 @@ void translation_unit_visitor::
{ {
for (const auto &arg : template_args) { for (const auto &arg : template_args) {
const auto argument_kind = arg.getKind(); const auto argument_kind = arg.getKind();
common::model::template_parameter argument; std::optional<common::model::template_parameter> argument;
if (argument_kind == clang::TemplateArgument::Template) { if (argument_kind == clang::TemplateArgument::Template) {
build_template_instantiation_process_template_argument( argument =
arg, argument); build_template_instantiation_process_template_argument(arg);
} }
else if (argument_kind == clang::TemplateArgument::Type) { else if (argument_kind == clang::TemplateArgument::Type) {
build_template_instantiation_process_type_argument(parent, argument = build_template_instantiation_process_type_argument(
full_template_specialization_name, template_decl, arg, parent, full_template_specialization_name, template_decl, arg,
template_instantiation, argument); template_instantiation);
} }
else if (argument_kind == clang::TemplateArgument::Integral) { else if (argument_kind == clang::TemplateArgument::Integral) {
build_template_instantiation_process_integral_argument( argument =
arg, argument); build_template_instantiation_process_integral_argument(arg);
} }
else if (argument_kind == clang::TemplateArgument::Expression) { else if (argument_kind == clang::TemplateArgument::Expression) {
build_template_instantiation_process_expression_argument( argument =
arg, argument); build_template_instantiation_process_expression_argument(arg);
} }
else { else {
LOG_INFO("Unsupported argument type {}", arg.getKind()); LOG_INFO("Unsupported argument type {}", arg.getKind());
continue;
} }
simplify_system_template( simplify_system_template(argument.value(),
argument, argument.to_string(config().using_namespace(), false)); argument.value().to_string(config().using_namespace(), false));
template_instantiation.add_template(std::move(argument)); template_instantiation.add_template(std::move(argument.value()));
} }
} }
void translation_unit_visitor:: template_parameter translation_unit_visitor::
build_template_instantiation_process_template_argument( build_template_instantiation_process_template_argument(
const clang::TemplateArgument &arg, const clang::TemplateArgument &arg) const
common::model::template_parameter &argument) const
{ {
argument.is_template_parameter(true);
auto arg_name = auto arg_name =
arg.getAsTemplate().getAsTemplateDecl()->getQualifiedNameAsString(); arg.getAsTemplate().getAsTemplateDecl()->getQualifiedNameAsString();
argument.set_type(arg_name); return template_parameter::make_template_type(arg_name);
} }
void translation_unit_visitor:: template_parameter translation_unit_visitor::
build_template_instantiation_process_integral_argument( build_template_instantiation_process_integral_argument(
const clang::TemplateArgument &arg, const clang::TemplateArgument &arg) const
common::model::template_parameter &argument) const
{ {
assert(arg.getKind() == clang::TemplateArgument::Integral); assert(arg.getKind() == clang::TemplateArgument::Integral);
argument.is_template_parameter(false); return template_parameter::make_argument(
argument.set_type(std::to_string(arg.getAsIntegral().getExtValue())); std::to_string(arg.getAsIntegral().getExtValue()));
} }
void translation_unit_visitor:: template_parameter translation_unit_visitor::
build_template_instantiation_process_expression_argument( build_template_instantiation_process_expression_argument(
const clang::TemplateArgument &arg, const clang::TemplateArgument &arg) const
common::model::template_parameter &argument) const
{ {
assert(arg.getKind() == clang::TemplateArgument::Expression); assert(arg.getKind() == clang::TemplateArgument::Expression);
return template_parameter::make_argument(common::get_source_text(
argument.is_template_parameter(false);
argument.set_type(common::get_source_text(
arg.getAsExpr()->getSourceRange(), source_manager())); arg.getAsExpr()->getSourceRange(), source_manager()));
} }
@@ -1592,17 +1593,18 @@ void translation_unit_visitor::
common::to_string(arg.getAsType(), template_decl->getASTContext())); common::to_string(arg.getAsType(), template_decl->getASTContext()));
} }
void translation_unit_visitor:: common::model::template_parameter
build_template_instantiation_process_type_argument( translation_unit_visitor::build_template_instantiation_process_type_argument(
model::template_trait * /*parent*/, model::template_trait * /*parent*/,
const std::string &full_template_specialization_name, const std::string &full_template_specialization_name,
const clang::TemplateDecl *template_decl, const clang::TemplateDecl *template_decl,
const clang::TemplateArgument &arg, const clang::TemplateArgument &arg,
model::template_trait &template_instantiation, model::template_trait &template_instantiation)
common::model::template_parameter &argument)
{ {
assert(arg.getKind() == clang::TemplateArgument::Type); assert(arg.getKind() == clang::TemplateArgument::Type);
auto argument = template_parameter::make_argument({});
argument.is_template_parameter(false); argument.is_template_parameter(false);
// If this is a nested template type - add nested templates as // If this is a nested template type - add nested templates as
@@ -1619,7 +1621,7 @@ void translation_unit_visitor::
.getAsTemplateDecl() .getAsTemplateDecl()
->getQualifiedNameAsString(); ->getQualifiedNameAsString();
argument.set_name(nested_template_name); argument.set_type(nested_template_name);
// Check if this template should be simplified (e.g. system // Check if this template should be simplified (e.g. system
// template aliases such as 'std:basic_string<char>' should // template aliases such as 'std:basic_string<char>' should
@@ -1629,7 +1631,7 @@ void translation_unit_visitor::
} }
else if (arg.getAsType()->getAs<clang::TemplateTypeParmType>() != nullptr) { else if (arg.getAsType()->getAs<clang::TemplateTypeParmType>() != nullptr) {
argument.is_template_parameter(true); argument.is_template_parameter(true);
argument.set_name( argument.set_type(
common::to_string(arg.getAsType(), template_decl->getASTContext())); common::to_string(arg.getAsType(), template_decl->getASTContext()));
} }
else { else {
@@ -1638,6 +1640,8 @@ void translation_unit_visitor::
template_instantiation, full_template_specialization_name, template_instantiation, full_template_specialization_name,
template_decl, arg, argument); template_decl, arg, argument);
} }
return argument;
} }
std::unique_ptr<model::class_> std::unique_ptr<model::class_>
@@ -1688,7 +1692,7 @@ void translation_unit_visitor::process_template_specialization_argument(
const auto argument_kind = arg.getKind(); const auto argument_kind = arg.getKind();
if (argument_kind == clang::TemplateArgument::Type) { if (argument_kind == clang::TemplateArgument::Type) {
common::model::template_parameter argument; auto argument = template_parameter::make_argument({});
argument.is_template_parameter(false); argument.is_template_parameter(false);
// If this is a nested template type - add nested templates as // If this is a nested template type - add nested templates as
@@ -1817,23 +1821,18 @@ void translation_unit_visitor::process_template_specialization_argument(
template_instantiation.add_template(std::move(argument)); template_instantiation.add_template(std::move(argument));
} }
else if (argument_kind == clang::TemplateArgument::Integral) { else if (argument_kind == clang::TemplateArgument::Integral) {
common::model::template_parameter argument; auto argument = template_parameter::make_argument(
argument.is_template_parameter(false); std::to_string(arg.getAsIntegral().getExtValue()));
argument.set_type(std::to_string(arg.getAsIntegral().getExtValue()));
template_instantiation.add_template(std::move(argument)); template_instantiation.add_template(std::move(argument));
} }
else if (argument_kind == clang::TemplateArgument::Expression) { else if (argument_kind == clang::TemplateArgument::Expression) {
common::model::template_parameter argument; auto argument =
argument.is_template_parameter(false); template_parameter::make_argument(common::get_source_text(
argument.set_type(common::get_source_text( arg.getAsExpr()->getSourceRange(), source_manager()));
arg.getAsExpr()->getSourceRange(), source_manager()));
template_instantiation.add_template(std::move(argument)); template_instantiation.add_template(std::move(argument));
} }
else if (argument_kind == clang::TemplateArgument::TemplateExpansion) { else if (argument_kind == clang::TemplateArgument::TemplateExpansion) {
common::model::template_parameter argument; // TODO
argument.is_template_parameter(true);
cls->getLocation().dump(source_manager());
} }
else if (argument_kind == clang::TemplateArgument::Pack) { else if (argument_kind == clang::TemplateArgument::Pack) {
// This will only work for now if pack is at the end // This will only work for now if pack is at the end

View File

@@ -202,17 +202,17 @@ private:
const std::string &full_template_specialization_name, const std::string &full_template_specialization_name,
const clang::TemplateDecl *template_decl); const clang::TemplateDecl *template_decl);
void build_template_instantiation_process_template_argument( common::model::template_parameter
const clang::TemplateArgument &arg, build_template_instantiation_process_template_argument(
common::model::template_parameter &argument) const; const clang::TemplateArgument &arg) const;
void build_template_instantiation_process_integral_argument( common::model::template_parameter
const clang::TemplateArgument &arg, build_template_instantiation_process_integral_argument(
common::model::template_parameter &argument) const; const clang::TemplateArgument &arg) const;
void build_template_instantiation_process_expression_argument( common::model::template_parameter
const clang::TemplateArgument &arg, build_template_instantiation_process_expression_argument(
common::model::template_parameter &argument) const; const clang::TemplateArgument &arg) const;
void build_template_instantiation_process_tag_argument( void build_template_instantiation_process_tag_argument(
model::template_trait &template_instantiation, model::template_trait &template_instantiation,
@@ -221,13 +221,12 @@ private:
const clang::TemplateArgument &arg, const clang::TemplateArgument &arg,
common::model::template_parameter &argument) const; common::model::template_parameter &argument) const;
void build_template_instantiation_process_type_argument( common::model::template_parameter build_template_instantiation_process_type_argument(
model::template_trait *parent, model::template_trait *parent,
const std::string &full_template_specialization_name, const std::string &full_template_specialization_name,
const clang::TemplateDecl *template_decl, const clang::TemplateDecl *template_decl,
const clang::TemplateArgument &arg, const clang::TemplateArgument &arg,
model::template_trait &template_instantiation, model::template_trait &template_instantiation);
common::model::template_parameter &argument);
std::unique_ptr<model::class_> process_template_specialization( std::unique_ptr<model::class_> process_template_specialization(
clang::ClassTemplateSpecializationDecl *cls); clang::ClassTemplateSpecializationDecl *cls);

View File

@@ -36,7 +36,7 @@ TEST_CASE("t00008", "[test-case][class]")
// TODO: add option to resolve using declared types // TODO: add option to resolve using declared types
// REQUIRE_THAT(puml, IsClassTemplate("A", "T, P, bool (*)(int, int), int // REQUIRE_THAT(puml, IsClassTemplate("A", "T, P, bool (*)(int, int), int
// N")); // N"));
REQUIRE_THAT(puml, IsClassTemplate("A", "T,P,CMP,int N")); REQUIRE_THAT(puml, IsClassTemplate("A", "T,P=T,CMP=nullptr,int N=3"));
REQUIRE_THAT(puml, IsClassTemplate("B", "T,C<>")); REQUIRE_THAT(puml, IsClassTemplate("B", "T,C<>"));
REQUIRE_THAT(puml, (IsField<Public>("value", "T"))); REQUIRE_THAT(puml, (IsField<Public>("value", "T")));

View File

@@ -105,8 +105,8 @@ TEST_CASE("Test parse_unexposed_template_params", "[unit-test]")
CHECK(int_template.size() == 1); CHECK(int_template.size() == 1);
CHECK(int_template[0].template_params().size() == 1); CHECK(int_template[0].template_params().size() == 1);
CHECK(int_template[0].type() == "ns1::ns2::class1"); CHECK(int_template[0].type().value() == "ns1::ns2::class1");
CHECK(int_template[0].template_params()[0].type() == "int"); CHECK(int_template[0].template_params()[0].type().value() == "int");
const std::string int_int_template_str{"ns1::ns2::class1<int, int>"}; const std::string int_int_template_str{"ns1::ns2::class1<int, int>"};
@@ -115,9 +115,9 @@ TEST_CASE("Test parse_unexposed_template_params", "[unit-test]")
CHECK(int_int_template.size() == 1); CHECK(int_int_template.size() == 1);
CHECK(int_int_template[0].template_params().size() == 2); CHECK(int_int_template[0].template_params().size() == 2);
CHECK(int_int_template[0].type() == "ns1::ns2::class1"); CHECK(int_int_template[0].type().value() == "ns1::ns2::class1");
CHECK(int_int_template[0].template_params()[0].type() == "int"); CHECK(int_int_template[0].template_params()[0].type().value() == "int");
CHECK(int_int_template[0].template_params()[1].type() == "int"); CHECK(int_int_template[0].template_params()[1].type().value() == "int");
const std::string nested_template_str{ const std::string nested_template_str{
"class1<int, ns1::class2<int, std::vector<std::string>>>"}; "class1<int, ns1::class2<int, std::vector<std::string>>>"};
@@ -127,13 +127,13 @@ TEST_CASE("Test parse_unexposed_template_params", "[unit-test]")
CHECK(nested_template.size() == 1); CHECK(nested_template.size() == 1);
CHECK(nested_template[0].template_params().size() == 2); CHECK(nested_template[0].template_params().size() == 2);
CHECK(nested_template[0].type() == "class1"); CHECK(nested_template[0].type().value() == "class1");
CHECK(nested_template[0].template_params()[0].type() == "int"); CHECK(nested_template[0].template_params()[0].type().value() == "int");
const auto &class2 = nested_template[0].template_params()[1]; const auto &class2 = nested_template[0].template_params()[1];
CHECK(class2.type() == "ns1::class2"); CHECK(class2.type() == "ns1::class2");
CHECK(class2.template_params()[0].type() == "int"); CHECK(class2.template_params()[0].type().value() == "int");
CHECK(class2.template_params()[1].type() == "std::vector"); CHECK(class2.template_params()[1].type().value() == "std::vector");
CHECK(class2.template_params()[1].template_params()[0].type() == CHECK(class2.template_params()[1].template_params()[0].type().value() ==
"std::string"); "std::string");
const std::string empty_string = R"( const std::string empty_string = R"(
@@ -153,7 +153,7 @@ TEST_CASE("Test parse_unexposed_template_params", "[unit-test]")
single_template_string, [](const auto &n) { return n; }); single_template_string, [](const auto &n) { return n; });
CHECK(single_template.size() == 1); CHECK(single_template.size() == 1);
CHECK(single_template[0].type() == "Else"); CHECK(single_template[0].type().value() == "Else");
const std::string declaration_string = R"( const std::string declaration_string = R"(
@@ -165,9 +165,9 @@ TEST_CASE("Test parse_unexposed_template_params", "[unit-test]")
declaration_string, [](const auto &n) { return n; }); declaration_string, [](const auto &n) { return n; });
CHECK(declaration_template.size() == 3); CHECK(declaration_template.size() == 3);
CHECK(declaration_template[0].type() == "std::true_type"); CHECK(declaration_template[0].type().value() == "std::true_type");
CHECK(declaration_template[1].type() == "Result"); CHECK(declaration_template[1].type().value() == "Result");
CHECK(declaration_template[2].type() == "Tail"); CHECK(declaration_template[2].type().value() == "Tail");
} }
TEST_CASE("Test remove_prefix", "[unit-test]") TEST_CASE("Test remove_prefix", "[unit-test]")