Skip to content

Commit

Permalink
feat: recursive TypeInfo structure
Browse files Browse the repository at this point in the history
closes #209, closes #343
  • Loading branch information
sdkrystian committed Jun 28, 2023
1 parent 940033e commit af254c3
Show file tree
Hide file tree
Showing 62 changed files with 1,735 additions and 435 deletions.
26 changes: 26 additions & 0 deletions addons/generator/asciidoc/partials/declarator-after.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{#if (eq kind "lvalue-reference")~}}
{{#if (or (eq pointee-type.kind "array") (eq pointee-type.kind "function"))~}}){{~/if~}}
{{~>declarator-after pointee-type~}}
{{~else if (eq kind "rvalue-reference")~}}
{{#if (or (eq pointee-type.kind "array") (eq pointee-type.kind "function"))~}}){{~/if~}}
{{~>declarator-after pointee-type~}}
{{~else if (eq kind "pointer")~}}
{{#if (or (eq pointee-type.kind "array") (eq pointee-type.kind "function"))~}}){{~/if~}}
{{~>declarator-after pointee-type~}}
{{~else if (eq kind "member-pointer")~}}
{{#if (or (eq pointee-type.kind "array") (eq pointee-type.kind "function"))~}}){{~/if~}}
{{~>declarator-after pointee-type~}}
{{~else if (eq kind "pack")~}}
{{~>declarator-after pattern-type~}}
{{~else if (eq kind "array")~}}
[{{bounds-value}}]
{{~>declarator-after element-type~}}
{{~else if (eq kind "function")~}}
({{~#each param-types~}}
{{~>declarator decl-name="" decl-name-targs=""~}}{{~#unless @last}}, {{/unless~}}
{{~/each~}})
{{~#if cv-qualifiers}} {{cv-qualifiers}}{{/if~}}
{{~#if (eq ref-qualifier "lvalue")}} &{{else if (eq ref-qualifier "rvalue")}} &&{{/if~}}
{{~#if exception-spec}} {{exception-spec}}{{~/if~}}
{{~>declarator-after return-type~}}
{{/if}}
34 changes: 34 additions & 0 deletions addons/generator/asciidoc/partials/declarator-before.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{#if (eq kind "builtin")~}}
{{#if cv-qualifiers}}{{cv-qualifiers}} {{/if~}}
{{name~}}
{{~else if (eq kind "tag")~}}
{{#if cv-qualifiers}}{{cv-qualifiers}} {{/if~}}
{{#if parent-type~}}{{>declarator parent-type decl-name="" decl-name-targs=""}}::{{/if~}}
{{#if id}}xref:{{id}}[{{name~}}]{{else}}{{name~}}{{/if}}
{{~else if (eq kind "specialization")~}}
{{#if cv-qualifiers}}{{cv-qualifiers}} {{/if~}}
{{#if parent-type~}}{{>declarator parent-type decl-name="" decl-name-targs=""}}::{{/if~}}
{{#if id}}xref:{{id}}[{{name~}}]{{else}}{{name~}}{{/if}}
{{~>template-args args=template-args~}}
{{~else if (eq kind "lvalue-reference")~}}
{{~>declarator-before pointee-type~}}
{{#if (or (eq pointee-type.kind "array") (eq pointee-type.kind "function"))~}}({{~/if~}}&
{{~else if (eq kind "rvalue-reference")~}}
{{~>declarator-before pointee-type~}}
{{#if (or (eq pointee-type.kind "array") (eq pointee-type.kind "function"))~}}({{~/if~}}&&
{{~else if (eq kind "pointer")~}}
{{~>declarator-before pointee-type~}}
{{#if (or (eq pointee-type.kind "array") (eq pointee-type.kind "function"))~}}({{~/if~}}*
{{~#if cv-qualifiers}} {{cv-qualifiers}}{{/if~}}
{{~else if (eq kind "member-pointer")~}}
{{~>declarator-before pointee-type~}}
{{#if (or (eq pointee-type.kind "array") (eq pointee-type.kind "function"))~}}({{~/if~}}
{{#if parent-type~}}{{>declarator parent-type decl-name="" decl-name-targs=""}}::*{{/if~}}
{{#if cv-qualifiers}} {{cv-qualifiers}}{{/if~}}
{{~else if (eq kind "pack")~}}
{{~>declarator-before pattern-type~}}...
{{~else if (eq kind "array")~}}
{{~>declarator-before element-type~}}
{{~else if (eq kind "function")~}}
{{~>declarator-before return-type~}}
{{/if}}
5 changes: 5 additions & 0 deletions addons/generator/asciidoc/partials/declarator.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{>declarator-before~}}
{{~#if decl-name}} {{decl-name~}}
{{~#if decl-name-targs~}}{{>template-args args=decl-name-targs}}{{~/if~}}
{{~/if~}}
{{~>declarator-after~}}
23 changes: 14 additions & 9 deletions addons/generator/asciidoc/partials/function-sig.adoc.hbs
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
[source,cpp,subs=+macros]
----
{{#if (eq storageClass "static")}}
static
{{/if}}
{{>type-name return}}
{{#if template}}{{>template-head template}}{{/if~}}
{{#if (eq storageClass "static")}}static
{{/if~}}
{{>declarator-before return}}
{{#if params}}
{{name}}(
{{name~}}
{{#if (eq template.kind "explicit")~}}
{{~>template-args args=template.args~}}
{{~/if~}}
{{~#if params}}
(
{{#each params}}
{{>type-name type~}}
{{#if name}} {{name}}{{/if}}
{{>declarator type decl-name=name~}}
{{~#if @last}}){{else}},
{{/if}}
{{~/each}}
{{~else~}}
{{name}}()
()
{{~/if~}}
{{#if (eq exceptionSpec "noexcept")}} noexcept{{/if~}}
{{~>declarator-after return~}}
{{#if isDeleted}} = delete{{/if~}}
;
----
4 changes: 2 additions & 2 deletions addons/generator/asciidoc/partials/record-member.adoc.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{#if (eq kind "function")}}
{{#if (eq storageClass "static")}}static {{/if~}}
{{>type-name return}} {{name}}(
{{>declarator return decl-name=""}} {{name}}(
{{~#each params}}
{{>type-name type}}
{{>declarator type decl-name=""}}
{{#if name}} {{name}}{{/if}}
{{~#unless @last}}, {{/unless}}
{{~/each}})
Expand Down
6 changes: 4 additions & 2 deletions addons/generator/asciidoc/partials/record.adoc.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
{{#if symbol.template}}
{{>template-head symbol.template}}
{{symbol.tag}} {{symbol.name~}}
{{>template-args symbol.template}}
{{#if (neq symbol.template.kind "primary")~}}
{{>template-args args=symbol.template.args}}
{{/if}}
{{else}}
{{symbol.tag}} {{symbol.name~}}
{{/if}}
Expand All @@ -22,7 +24,7 @@
{{#if @first}}:{{else}},{{/if}}
{{~#unless (eq access ../symbol.defaultAccess)}} {{access}}{{/unless}}
{{~#if isVirtual}} virtual{{/if}}
{{~null}} {{type.name}}
{{~null}} {{>declarator type decl-name=""}}
{{~#if @last}};{{/if}}
{{/each}}
{{/unless}}
Expand Down
6 changes: 2 additions & 4 deletions addons/generator/asciidoc/partials/template-args.adoc.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{{#if (neq kind "primary")~}}<
{{~#each args~}}
<{{~#each args~}}
{{value}}
{{~#if (not @last)}}, {{/if}}
{{~/each~}}
>{{/if}}
{{~/each~}}>
10 changes: 7 additions & 3 deletions addons/generator/asciidoc/partials/template-head.adoc.hbs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{{#if params~}}
template<
{{#each params}}
{{#if (eq kind "type")}}
{{>type-tparam~}}
{{>tparam-type~}}
{{else if (eq kind "non-type")}}
{{>nontype-tparam~}}
{{>tparam-nontype~}}
{{else if (eq kind "template")}}
{{>template-tparam~}}
{{>tparam-template~}}
{{/if}}
{{~#unless @last}},
{{else}}
{{/unless}}
{{/each}}>
{{else~}}
template<>
{{/if}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{>type-name type}}
{{>declarator type decl-name=""}}
{{~#if is-pack}}...{{/if}}
{{~#if name}} {{name}}{{/if}}
{{~#if default}} = {{default}}{{/if~}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
typename
{{~#if is-pack}}...{{/if}}
{{~#if name}} {{name}}{{/if}}
{{~#if default}} = {{>type-name default}}{{~/if~}}
{{~#if default}} = {{>declarator default decl-name=""}}{{~/if~}}
4 changes: 0 additions & 4 deletions addons/generator/asciidoc/partials/type-name.adoc.hbs

This file was deleted.

26 changes: 26 additions & 0 deletions addons/generator/asciidoc/partials/typedef.adoc.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
{{!-- typedef --}}
[#{{symbol.id}}]
== {{symbol.name}}

{{symbol.doc.brief}}

=== Synopsis

[source,cpp,subs=+macros]
----
{{#if symbol.isUsing~}}
{{~#if symbol.template}}{{>template-head symbol.template}}{{/if~}}
using {{symbol.name}} = {{>declarator symbol.type}}
{{~else~}}
typedef {{>declarator symbol.type decl-name=symbol.name}}
{{~/if}}
;
----
{{>source symbol.loc}}
{{#if symbol.doc.description}}
=== Description
{{symbol.doc.description}}
{{/if}}
13 changes: 6 additions & 7 deletions addons/generator/asciidoc/partials/variable.adoc.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

[source,cpp,subs=+macros]
----
{{#if symbol.template}}
{{>template-head symbol.template}}
{{symbol.type.name}} {{symbol.name~}}
{{>template-args symbol.template}}
{{else}}
{{symbol.type.name}} {{symbol.name~}}
{{/if}}
{{#if symbol.template}}{{>template-head symbol.template}}{{/if~}}
{{#if (or (eq symbol.template.kind "explicit") (eq symbol.template.kind "partial"))~}}
{{~>declarator symbol.type decl-name=symbol.name decl-name-targs=symbol.template.args~}}
{{~else~}}
{{~>declarator symbol.type decl-name=symbol.name decl-name-targs=""~}}
{{~/if}}
;
----
Expand Down
2 changes: 1 addition & 1 deletion include/mrdox/Metadata/Enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct EnumInfo
// Set to nonempty to the type when this is an explicitly typed enum. For
// enum Foo : short { ... };
// this will be "short".
std::optional<TypeInfo> BaseType;
std::unique_ptr<TypeInfo> BaseType;

// Enumeration members.
std::vector<EnumValueInfo> Members;
Expand Down
2 changes: 1 addition & 1 deletion include/mrdox/Metadata/Field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct FieldInfo
, SourceInfo
{
/** Type of the field */
TypeInfo Type;
std::unique_ptr<TypeInfo> Type;

/** The default member initializer, if any.
*/
Expand Down
6 changes: 3 additions & 3 deletions include/mrdox/Metadata/Function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ union FnFlags1
struct Param
{
/** The type of this parameter */
TypeInfo Type;
std::unique_ptr<TypeInfo> Type;

/** The parameter name.
Expand All @@ -107,7 +107,7 @@ struct Param
Param() = default;

Param(
TypeInfo&& type,
std::unique_ptr<TypeInfo>&& type,
std::string&& name,
std::string&& def_arg)
: Type(std::move(type))
Expand All @@ -125,7 +125,7 @@ struct FunctionInfo
{
friend class ASTVisitor;

TypeInfo ReturnType; // Info about the return type of this function.
std::unique_ptr<TypeInfo> ReturnType; // Info about the return type of this function.
std::vector<Param> Params; // List of parameters.

// When present, this function is a template or specialization.
Expand Down
2 changes: 1 addition & 1 deletion include/mrdox/Metadata/Info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct MRDOX_VISIBLE
//--------------------------------------------

virtual ~Info() = default;
Info(Info const &Other) = delete;
Info(Info const& Other) = delete;
Info(Info&& Other) = default;

explicit
Expand Down
4 changes: 2 additions & 2 deletions include/mrdox/Metadata/Record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ union RecFlags0
*/
struct BaseInfo
{
TypeInfo Type;
std::unique_ptr<TypeInfo> Type;
AccessKind Access = AccessKind::Public;
bool IsVirtual = false;

BaseInfo() = default;

BaseInfo(
TypeInfo&& type,
std::unique_ptr<TypeInfo>&& type,
AccessKind access,
bool is_virtual)
: Type(std::move(type))
Expand Down
20 changes: 2 additions & 18 deletions include/mrdox/Metadata/Template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ struct TParam;
struct TypeTParam
{
/** Default type for the type template parameter */
std::optional<TypeInfo> Default;
std::unique_ptr<TypeInfo> Default;
};

struct NonTypeTParam
{
/** Type of the non-type template parameter */
TypeInfo Type;
std::unique_ptr<TypeInfo> Type;
// Non-type template parameter default value (if any)
Optional<std::string> Default;
};
Expand Down Expand Up @@ -118,22 +118,13 @@ struct TParam
TParam(
TParam&& other) noexcept;

MRDOX_DECL
TParam(
const TParam& other);

MRDOX_DECL
TParam(
std::string&& name,
bool is_pack);

MRDOX_DECL ~TParam();

MRDOX_DECL
TParam&
operator=(
const TParam& other);

MRDOX_DECL
TParam&
operator=(
Expand Down Expand Up @@ -234,13 +225,6 @@ struct TemplateInfo
*/
OptionalSymbolID Primary;

#if 0
/** Stores information for explicit specializations of members
of implicitly instantiated class template specializations
*/
std::vector<SpecializationInfo> Specializations;
#endif

// KRYSTIAN NOTE: using the presence of args/params
// to determine the specialization kind *should* work.
// emphasis on should.
Expand Down
Loading

0 comments on commit af254c3

Please sign in to comment.