diff --git a/src/class_diagram/generators/json/class_diagram_generator.cc b/src/class_diagram/generators/json/class_diagram_generator.cc index bcccc383..451ec035 100644 --- a/src/class_diagram/generators/json/class_diagram_generator.cc +++ b/src/class_diagram/generators/json/class_diagram_generator.cc @@ -45,21 +45,13 @@ void to_json(nlohmann::json &j, const element &c) void to_json(nlohmann::json &j, const template_parameter &c) { j["kind"] = to_string(c.kind()); - - if (c.kind() == template_parameter_kind_t::template_type) { + if (c.type()) + j["type"] = c.type().value(); + if (c.name()) j["name"] = c.name().value(); - } - - // j["type"] = c.type(); - // 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(); + if (c.default_value()) + j["default"] = c.default_value().value(); + j["is_variadic"] = c.is_variadic(); } void to_json(nlohmann::json &j, const relationship &c) diff --git a/src/common/model/template_parameter.cc b/src/common/model/template_parameter.cc index f7c4aca5..662f6286 100644 --- a/src/common/model/template_parameter.cc +++ b/src/common/model/template_parameter.cc @@ -40,16 +40,6 @@ std::string to_string(template_parameter_kind_t k) assert(0); } } -// template_parameter::template_parameter(const std::optional -// &type, -// const std::optional &name, -// const std::optional &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) { diff --git a/src/common/model/template_parameter.h b/src/common/model/template_parameter.h index 7ebba8de..4a8453c2 100644 --- a/src/common/model/template_parameter.h +++ b/src/common/model/template_parameter.h @@ -43,8 +43,6 @@ std::string to_string(template_parameter_kind_t k); /// including variadic parameters and instantiations with /// nested templates class template_parameter { - template_parameter() = default; - public: static template_parameter make_template_type(std::string name, const std::optional &default_value = {}, @@ -107,13 +105,6 @@ public: return p; } - // template_parameter(const std::optional &type = {}, - // const std::optional &name = {}, - // const std::optional &default_value = {}, - // bool is_variadic = false); - - // template_parameter(const template_parameter &right) = default; - void set_type(const std::string &type); std::optional type() const; @@ -129,9 +120,6 @@ public: void is_variadic(bool is_variadic) noexcept; bool is_variadic() const noexcept; - void is_pack(bool is_pack) noexcept; - bool is_pack() const noexcept; - bool is_specialization_of(const template_parameter &ct) const; friend bool operator==( @@ -188,6 +176,8 @@ public: void set_unexposed(bool unexposed) { is_unexposed_ = unexposed; } private: + template_parameter() = default; + template_parameter_kind_t kind_; /// Represents the type of non-type template parameters @@ -211,9 +201,6 @@ private: /// Whether the template parameter is variadic bool is_variadic_{false}; - /// Whether the argument specializes argument pack from parent template - bool is_pack_{false}; - /// Stores optional fully qualified name of constraint for this template /// parameter std::optional concept_constraint_; diff --git a/src/sequence_diagram/visitor/translation_unit_visitor.cc b/src/sequence_diagram/visitor/translation_unit_visitor.cc index 27a7fb8f..b93c1e73 100644 --- a/src/sequence_diagram/visitor/translation_unit_visitor.cc +++ b/src/sequence_diagram/visitor/translation_unit_visitor.cc @@ -1588,7 +1588,6 @@ void translation_unit_visitor:: assert(arg.getKind() == clang::TemplateArgument::Type); argument.is_template_parameter(false); - argument.set_type( common::to_string(arg.getAsType(), template_decl->getASTContext())); } @@ -1603,9 +1602,7 @@ translation_unit_visitor::build_template_instantiation_process_type_argument( { assert(arg.getKind() == clang::TemplateArgument::Type); - auto argument = template_parameter::make_argument({}); - - argument.is_template_parameter(false); + std::optional argument; // If this is a nested template type - add nested templates as // template arguments @@ -1621,27 +1618,27 @@ translation_unit_visitor::build_template_instantiation_process_type_argument( .getAsTemplateDecl() ->getQualifiedNameAsString(); - argument.set_type(nested_template_name); + argument = template_parameter::make_argument(nested_template_name); // Check if this template should be simplified (e.g. system // template aliases such as 'std:basic_string' should // be simply 'std::string') - simplify_system_template( - argument, argument.to_string(config().using_namespace(), false)); + simplify_system_template(*argument, + argument.value().to_string(config().using_namespace(), false)); } else if (arg.getAsType()->getAs() != nullptr) { - argument.is_template_parameter(true); - argument.set_type( + argument = template_parameter::make_template_type( common::to_string(arg.getAsType(), template_decl->getASTContext())); } else { + argument = template_parameter::make_argument({}); // This is just a regular record type build_template_instantiation_process_tag_argument( template_instantiation, full_template_specialization_name, - template_decl, arg, argument); + template_decl, arg, *argument); } - return argument; + return *argument; } std::unique_ptr