Skip to content

Commit

Permalink
chore: add TParamKeyKind, use TArg to store default template arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Jul 11, 2023
1 parent 8286388 commit 31a6466
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 181 deletions.
8 changes: 8 additions & 0 deletions addons/generator/asciidoc/partials/template-arg.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{#if (eq kind "type")~}}
{{~>declarator type decl-name=""~}}
{{else if (eq kind "non-type")~}}
{{~value~}}
{{else if (eq kind "template")~}}
{{#if template}}xref:{{template}}[{{name~}}]{{else~}}{{name~}}{{/if~}}
{{/if~}}
{{~#if is-pack}}...{{/if~}}
4 changes: 2 additions & 2 deletions addons/generator/asciidoc/partials/template-args.adoc.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<{{~#each args~}}
{{value}}
{{~#if (not @last)}}, {{/if}}
{{~>template-arg .~}}
{{~#if (not @last)}}, {{/if~}}
{{~/each~}}>
2 changes: 1 addition & 1 deletion addons/generator/asciidoc/partials/tparam-nontype.adoc.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{>declarator type decl-name=""}}
{{~#if is-pack}}...{{/if}}
{{~#if name}} {{name}}{{/if}}
{{~#if default}} = {{default}}{{/if~}}
{{~#if default}} = {{>template-arg default~}}{{/if~}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
typename
{{~#if is-pack}}...{{/if}}
{{~#if name}} {{name}}{{/if}}
{{~#if default}} = {{default}}{{/if~}}
{{~#if default}} = {{>template-arg default~}}{{/if~}}
4 changes: 2 additions & 2 deletions addons/generator/asciidoc/partials/tparam-type.adoc.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
typename
{{key}}
{{~#if is-pack}}...{{/if}}
{{~#if name}} {{name}}{{/if}}
{{~#if default}} = {{>declarator default decl-name=""}}{{~/if~}}
{{~#if default}} = {{>template-arg default~}}{{~/if~}}
54 changes: 29 additions & 25 deletions include/mrdox/Metadata/Template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum class TArgKind : int
Template
};

MRDOX_DECL dom::String toString(TArgKind kind) noexcept;
MRDOX_DECL std::string_view toString(TArgKind kind) noexcept;

struct TArg
{
Expand Down Expand Up @@ -131,6 +131,8 @@ visit(
}
}

MRDOX_DECL std::string toString(const TArg& arg) noexcept;

// ----------------------------------------------------------------

enum class TParamKind : int
Expand All @@ -143,20 +145,23 @@ enum class TParamKind : int
Template
};

MRDOX_DECL dom::String toString(TParamKind kind) noexcept;
MRDOX_DECL std::string_view toString(TParamKind kind) noexcept;

struct TParam
{
/** The kind of template parameter this is. */
/** The kind of template parameter this is */
TParamKind Kind;

/** The template parameters name, if any */
std::string Name;

/** Whether this template parameter is a parameter pack. */
/** Whether this template parameter is a parameter pack */
bool IsParameterPack = false;

constexpr virtual ~TParam() = default;
/** The default template argument, if any */
std::unique_ptr<TArg> Default;

virtual ~TParam() = default;

constexpr bool isType() const noexcept { return Kind == TParamKind::Type; }
constexpr bool isNonType() const noexcept { return Kind == TParamKind::NonType; }
Expand Down Expand Up @@ -188,29 +193,42 @@ struct IsTParam : TParam
}
};

/** The keyword a template parameter was declared with */
enum class TParamKeyKind : int
{
Class = 0,
Typename
};

MRDOX_DECL std::string_view toString(TParamKeyKind kind) noexcept;

struct TypeTParam
: IsTParam<TParamKind::Type>
{
/** Default type for the type template parameter */
std::unique_ptr<TypeInfo> Default;
/** Keyword (class/typename) the parameter uses **/
TParamKeyKind KeyKind = TParamKeyKind::Class;
/** Type template parameter default argument (if any) */
// std::unique_ptr<TypeInfo> Default;
};

struct NonTypeTParam
: IsTParam<TParamKind::NonType>
{
/** Type of the non-type template parameter */
std::unique_ptr<TypeInfo> Type;
// Non-type template parameter default value (if any)
Optional<std::string> Default;
/** Non-type template parameter default argument (if any) */
// std::unique_ptr<NonTypeTArg> Default;
// Optional<std::string> Default;
};

struct TemplateTParam
: IsTParam<TParamKind::Template>
{
/** Template parameters for the template template parameter */
std::vector<std::unique_ptr<TParam>> Params;
/** Non-type template parameter default value (if any) */
Optional<std::string> Default;
/** Template template parameter default argument (if any) */
// std::unique_ptr<TemplateTArg> Default;
// Optional<std::string> Default;
};

template<
Expand Down Expand Up @@ -246,20 +264,6 @@ visit(

// ----------------------------------------------------------------

#if 0
struct TArg
{
std::string Value;

TArg() = default;

MRDOX_DECL
TArg(std::string&& value);
};
#endif

// ----------------------------------------------------------------

enum class TemplateSpecKind
{
Primary = 0, // for bitstream
Expand Down
12 changes: 1 addition & 11 deletions lib/-XML/CXXTags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,7 @@ inline void writeTemplateParam(const TParam& I, XMLTags& tags)
attrs.push({"type", toString(*P.Type)});

if(P.Default)
{
std::string default_val;
if constexpr(T::isType())
default_val = toString(*P.Default);
else if constexpr(T::isNonType())
default_val = *P.Default;
else if constexpr(T::isTemplate())
default_val = *P.Default;

attrs.push({"default", std::move(default_val)});
}
attrs.push({"default", toString(*P.Default)});

if constexpr(T::isTemplate())
{
Expand Down
Loading

0 comments on commit 31a6466

Please sign in to comment.