Fixed class template parameter generation in sequence visitor

This commit is contained in:
Bartek Kryza
2023-03-16 23:45:05 +01:00
parent e0447f28c1
commit f13ce56840
4 changed files with 16 additions and 50 deletions

View File

@@ -45,21 +45,13 @@ 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 (c.kind() == template_parameter_kind_t::template_type) { j["type"] = c.type().value();
if (c.name())
j["name"] = c.name().value(); j["name"] = c.name().value();
} if (c.default_value())
j["default"] = c.default_value().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

@@ -40,16 +40,6 @@ std::string to_string(template_parameter_kind_t k)
assert(0); 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)
{ {

View File

@@ -43,8 +43,6 @@ std::string to_string(template_parameter_kind_t k);
/// including variadic parameters and instantiations with /// including variadic parameters and instantiations with
/// nested templates /// nested templates
class template_parameter { class template_parameter {
template_parameter() = default;
public: public:
static template_parameter make_template_type(std::string name, static template_parameter make_template_type(std::string name,
const std::optional<std::string> &default_value = {}, const std::optional<std::string> &default_value = {},
@@ -107,13 +105,6 @@ public:
return p; 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::optional<std::string> type() const; std::optional<std::string> type() const;
@@ -129,9 +120,6 @@ public:
void is_variadic(bool is_variadic) noexcept; void is_variadic(bool is_variadic) noexcept;
bool is_variadic() const 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; bool is_specialization_of(const template_parameter &ct) const;
friend bool operator==( friend bool operator==(
@@ -188,6 +176,8 @@ public:
void set_unexposed(bool unexposed) { is_unexposed_ = unexposed; } void set_unexposed(bool unexposed) { is_unexposed_ = unexposed; }
private: private:
template_parameter() = default;
template_parameter_kind_t kind_; template_parameter_kind_t kind_;
/// Represents the type of non-type template parameters /// Represents the type of non-type template parameters
@@ -211,9 +201,6 @@ private:
/// Whether the template parameter is variadic /// Whether the template parameter is variadic
bool is_variadic_{false}; 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 /// Stores optional fully qualified name of constraint for this template
/// parameter /// parameter
std::optional<std::string> concept_constraint_; std::optional<std::string> concept_constraint_;

View File

@@ -1588,7 +1588,6 @@ void translation_unit_visitor::
assert(arg.getKind() == clang::TemplateArgument::Type); assert(arg.getKind() == clang::TemplateArgument::Type);
argument.is_template_parameter(false); argument.is_template_parameter(false);
argument.set_type( argument.set_type(
common::to_string(arg.getAsType(), template_decl->getASTContext())); 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); assert(arg.getKind() == clang::TemplateArgument::Type);
auto argument = template_parameter::make_argument({}); std::optional<template_parameter> 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
@@ -1621,27 +1618,27 @@ translation_unit_visitor::build_template_instantiation_process_type_argument(
.getAsTemplateDecl() .getAsTemplateDecl()
->getQualifiedNameAsString(); ->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 // 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
// be simply 'std::string') // be simply 'std::string')
simplify_system_template( simplify_system_template(*argument,
argument, argument.to_string(config().using_namespace(), false)); argument.value().to_string(config().using_namespace(), false));
} }
else if (arg.getAsType()->getAs<clang::TemplateTypeParmType>() != nullptr) { else if (arg.getAsType()->getAs<clang::TemplateTypeParmType>() != nullptr) {
argument.is_template_parameter(true); argument = template_parameter::make_template_type(
argument.set_type(
common::to_string(arg.getAsType(), template_decl->getASTContext())); common::to_string(arg.getAsType(), template_decl->getASTContext()));
} }
else { else {
argument = template_parameter::make_argument({});
// This is just a regular record type // This is just a regular record type
build_template_instantiation_process_tag_argument( build_template_instantiation_process_tag_argument(
template_instantiation, full_template_specialization_name, template_instantiation, full_template_specialization_name,
template_decl, arg, argument); template_decl, arg, *argument);
} }
return argument; return *argument;
} }
std::unique_ptr<model::class_> std::unique_ptr<model::class_>