Skip to content

Commit 21ec7ae

Browse files
sdkrystianvinniefalco
authored andcommitted
chore: add TParamKeyKind, use TArg to store default template arguments
closes #196
1 parent c0fd3fc commit 21ec7ae

File tree

15 files changed

+237
-184
lines changed

15 files changed

+237
-184
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{#if (eq kind "type")~}}
2+
{{~>declarator type decl-name=""~}}
3+
{{else if (eq kind "non-type")~}}
4+
{{~value~}}
5+
{{else if (eq kind "template")~}}
6+
{{#if template}}xref:{{template}}[{{name~}}]{{else~}}{{name~}}{{/if~}}
7+
{{/if~}}
8+
{{~#if is-pack}}...{{/if~}}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<{{~#each args~}}
2-
{{value}}
3-
{{~#if (not @last)}}, {{/if}}
2+
{{~>template-arg .~}}
3+
{{~#if (not @last)}}, {{/if~}}
44
{{~/each~}}>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{{>declarator type decl-name=""}}
22
{{~#if is-pack}}...{{/if}}
33
{{~#if name}} {{name}}{{/if}}
4-
{{~#if default}} = {{default}}{{/if~}}
4+
{{~#if default}} = {{>template-arg default~}}{{/if~}}

addons/generator/asciidoc/partials/tparam-template.adoc.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
typename
33
{{~#if is-pack}}...{{/if}}
44
{{~#if name}} {{name}}{{/if}}
5-
{{~#if default}} = {{default}}{{/if~}}
5+
{{~#if default}} = {{>template-arg default~}}{{/if~}}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
typename
1+
{{key}}
22
{{~#if is-pack}}...{{/if}}
33
{{~#if name}} {{name}}{{/if}}
4-
{{~#if default}} = {{>declarator default decl-name=""}}{{~/if~}}
4+
{{~#if default}} = {{>template-arg default~}}{{~/if~}}

include/mrdox/Metadata/Template.hpp

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enum class TArgKind : int
3434
Template
3535
};
3636

37-
MRDOX_DECL dom::String toString(TArgKind kind) noexcept;
37+
MRDOX_DECL std::string_view toString(TArgKind kind) noexcept;
3838

3939
struct TArg
4040
{
@@ -131,6 +131,8 @@ visit(
131131
}
132132
}
133133

134+
MRDOX_DECL std::string toString(const TArg& arg) noexcept;
135+
134136
// ----------------------------------------------------------------
135137

136138
enum class TParamKind : int
@@ -143,20 +145,23 @@ enum class TParamKind : int
143145
Template
144146
};
145147

146-
MRDOX_DECL dom::String toString(TParamKind kind) noexcept;
148+
MRDOX_DECL std::string_view toString(TParamKind kind) noexcept;
147149

148150
struct TParam
149151
{
150-
/** The kind of template parameter this is. */
152+
/** The kind of template parameter this is */
151153
TParamKind Kind;
152154

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

156-
/** Whether this template parameter is a parameter pack. */
158+
/** Whether this template parameter is a parameter pack */
157159
bool IsParameterPack = false;
158160

159-
constexpr virtual ~TParam() = default;
161+
/** The default template argument, if any */
162+
std::unique_ptr<TArg> Default;
163+
164+
virtual ~TParam() = default;
160165

161166
constexpr bool isType() const noexcept { return Kind == TParamKind::Type; }
162167
constexpr bool isNonType() const noexcept { return Kind == TParamKind::NonType; }
@@ -188,29 +193,34 @@ struct IsTParam : TParam
188193
}
189194
};
190195

196+
/** The keyword a template parameter was declared with */
197+
enum class TParamKeyKind : int
198+
{
199+
Class = 0,
200+
Typename
201+
};
202+
203+
MRDOX_DECL std::string_view toString(TParamKeyKind kind) noexcept;
204+
191205
struct TypeTParam
192206
: IsTParam<TParamKind::Type>
193207
{
194-
/** Default type for the type template parameter */
195-
std::unique_ptr<TypeInfo> Default;
208+
/** Keyword (class/typename) the parameter uses **/
209+
TParamKeyKind KeyKind = TParamKeyKind::Class;
196210
};
197211

198212
struct NonTypeTParam
199213
: IsTParam<TParamKind::NonType>
200214
{
201215
/** Type of the non-type template parameter */
202216
std::unique_ptr<TypeInfo> Type;
203-
// Non-type template parameter default value (if any)
204-
Optional<std::string> Default;
205217
};
206218

207219
struct TemplateTParam
208220
: IsTParam<TParamKind::Template>
209221
{
210222
/** Template parameters for the template template parameter */
211223
std::vector<std::unique_ptr<TParam>> Params;
212-
/** Non-type template parameter default value (if any) */
213-
Optional<std::string> Default;
214224
};
215225

216226
template<
@@ -246,20 +256,6 @@ visit(
246256

247257
// ----------------------------------------------------------------
248258

249-
#if 0
250-
struct TArg
251-
{
252-
std::string Value;
253-
254-
TArg() = default;
255-
256-
MRDOX_DECL
257-
TArg(std::string&& value);
258-
};
259-
#endif
260-
261-
// ----------------------------------------------------------------
262-
263259
enum class TemplateSpecKind
264260
{
265261
Primary = 0, // for bitstream

mrdox.rnc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ grammar
205205
TemplateArg =
206206
element targ
207207
{
208-
attribute value { text }
208+
attribute class { "type"|"non-type"|"template" },
209+
attribute name { text } ?,
210+
ID ?,
211+
attribute type { text } ?,
212+
attribute value { text } ?
209213
}
210214

211215
TemplateParam =

src/lib/-XML/CXXTags.hpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,7 @@ inline void writeTemplateParam(const TParam& I, XMLTags& tags)
335335
attrs.push({"type", toString(*P.Type)});
336336

337337
if(P.Default)
338-
{
339-
std::string default_val;
340-
if constexpr(T::isType())
341-
default_val = toString(*P.Default);
342-
else if constexpr(T::isNonType())
343-
default_val = *P.Default;
344-
else if constexpr(T::isTemplate())
345-
default_val = *P.Default;
346-
347-
attrs.push({"default", std::move(default_val)});
348-
}
338+
attrs.push({"default", toString(*P.Default)});
349339

350340
if constexpr(T::isTemplate())
351341
{
@@ -372,11 +362,18 @@ inline void writeTemplateArg(const TArg& I, XMLTags& tags)
372362
};
373363

374364
if constexpr(T::isType())
365+
{
375366
attrs.push({"type", toString(*A.Type)});
376-
else if constexpr(T::isNonType())
367+
}
368+
if constexpr(T::isNonType())
369+
{
377370
attrs.push({"value", A.Value.Written});
378-
else if constexpr(T::isTemplate())
371+
}
372+
if constexpr(T::isTemplate())
373+
{
374+
attrs.push({"name", A.Name});
379375
attrs.push({A.Template});
376+
}
380377

381378
tags.write(targTagName, {},
382379
std::move(attrs));

0 commit comments

Comments
 (0)