Skip to content

Adoc supports templates #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions addons/generator/asciidoc/partials/nontype-tparam.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{>type-name type}}
{{~#if is-pack}}...{{/if}}
{{~#if name}} {{name}}{{/if}}
{{~#if default}} = {{default}}{{/if~}}
5 changes: 5 additions & 0 deletions addons/generator/asciidoc/partials/record.adoc.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

[source,cpp,subs=+macros]
----
{{#if symbol.template}}
{{>template-head symbol.template}}
{{symbol.tag}} {{symbol.name}}{{>template-args symbol.template}}
{{else}}
{{symbol.tag}} {{symbol.name}}
{{/if}}
{
{{#each symbol.members}}
{{>record-member}}
Expand Down
6 changes: 6 additions & 0 deletions addons/generator/asciidoc/partials/template-args.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{~#if (neq kind "primary")~}}<
{{~#each args~}}
{{value}}
{{~#if (not @last)}}, {{/if}}
{{~/each~}}
>{{/if}}
11 changes: 11 additions & 0 deletions addons/generator/asciidoc/partials/template-head.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
template<
{{~#each params~}}
{{~#if (eq kind "type")}}
{{~>type-tparam~}}
{{~else if (eq kind "non-type")}}
{{~>nontype-tparam~}}
{{~else if (eq kind "template")}}
{{~>template-tparam~}}
{{~/if~}}
{{~#if (not @last)~}}, {{/if}}
{{~/each~}}>
5 changes: 5 additions & 0 deletions addons/generator/asciidoc/partials/template-tparam.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{~>template-head~}}
typename
{{~#if is-pack}}...{{/if}}
{{~#if name}} {{name}}{{/if}}
{{~#if default}} = {{default}}{{/if~}}
4 changes: 4 additions & 0 deletions addons/generator/asciidoc/partials/type-tparam.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
typename
{{~#if is-pack}}...{{/if}}
{{~#if name}} {{name}}{{/if}}
{{~#if default}} = {{>type-name default}}{{~/if~}}
136 changes: 136 additions & 0 deletions include/mrdox/Dom/DomTemplate.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2023 Krystian Stasiowski (sdkrystian@gmail.com)
//
// Official repository: https://github.com/cppalliance/mrdox
//

#ifndef MRDOX_API_DOM_DOMTEMPLATE_HPP
#define MRDOX_API_DOM_DOMTEMPLATE_HPP

#include <mrdox/Platform.hpp>
#include <mrdox/Corpus.hpp>
#include <mrdox/Support/Dom.hpp>

namespace clang {
namespace mrdox {

class MRDOX_DECL
DomTParam : public dom::Object
{
TParam const* I_;
Corpus const& corpus_;

public:
DomTParam(
TParam const& I,
Corpus const& corpus) noexcept
: I_(&I)
, corpus_(corpus)
{
}

dom::Value get(std::string_view key) const override;
std::vector<std::string_view> props() const override;
};

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

class MRDOX_DECL
DomTArg : public dom::Object
{
TArg const* I_;
Corpus const& corpus_;

public:
DomTArg(
TArg const& I,
Corpus const& corpus) noexcept
: I_(&I)
, corpus_(corpus)
{
}

dom::Value get(std::string_view key) const override;
std::vector<std::string_view> props() const override;
};

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

/** An array of template parameters
*/
class DomTParamArray : public dom::Array
{
std::vector<TParam> const& list_;
Corpus const& corpus_;

public:
DomTParamArray(
std::vector<TParam> const& list,
Corpus const& corpus) noexcept
: list_(list)
, corpus_(corpus)
{
}

std::size_t length() const noexcept override
{
return list_.size();
}

dom::Value get(std::size_t index) const override;
};

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

/** An array of template arguments
*/
class DomTArgArray : public dom::Array
{
std::vector<TArg> const& list_;
Corpus const& corpus_;

public:
DomTArgArray(
std::vector<TArg> const& list,
Corpus const& corpus) noexcept
: list_(list)
, corpus_(corpus)
{
}

std::size_t length() const noexcept override
{
return list_.size();
}

dom::Value get(std::size_t index) const override;
};

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

/** Template info
*/
class MRDOX_DECL
DomTemplate : public dom::Object
{
TemplateInfo const* I_;
Info const* Primary_;
Corpus const& corpus_;

public:
DomTemplate(
TemplateInfo const& I,
Corpus const& corpus) noexcept;

dom::Value get(std::string_view key) const override;
std::vector<std::string_view> props() const override;
};

} // mrdox
} // clang

#endif
2 changes: 1 addition & 1 deletion include/mrdox/Support/Dom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class MRDOX_DECL
bool getBool() const noexcept
{
MRDOX_ASSERT(kind_ == Kind::Boolean);
return number_ == 0;
return number_ != 0;
}

std::int64_t getInteger() const noexcept
Expand Down
11 changes: 11 additions & 0 deletions source/-adoc/Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ Builder(
return a === b;
});

Handlebars.registerHelper(
'neq', function(a, b)
{
return a !== b;
});

Handlebars.registerHelper(
'not', function(a)
{
return ! a;
});
)");
if(err)
throw err;
Expand Down
40 changes: 38 additions & 2 deletions source/Dom/DomSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
// Copyright (c) 2023 Krystian Stasiowski (sdkrystian@gmail.com)
//
// Official repository: https://github.com/cppalliance/mrdox
//
Expand All @@ -18,6 +19,7 @@
#include <mrdox/Dom/DomSource.hpp>
#include <mrdox/Dom/DomSymbol.hpp>
#include <mrdox/Dom/DomSymbolArray.hpp>
#include <mrdox/Dom/DomTemplate.hpp>
#include <mrdox/Dom/DomType.hpp>

namespace clang {
Expand Down Expand Up @@ -87,6 +89,12 @@ get(std::string_view key) const
if(key == "specializations")
return dom::makePointer<DomSymbolArray>(
I_->Specializations, corpus_);
if(key == "template")
{
if(! I_->Template)
return nullptr;
return dom::makePointer<DomTemplate>(*I_->Template, corpus_);
}
}
if constexpr(T::isFunction())
{
Expand All @@ -99,15 +107,33 @@ get(std::string_view key) const
if(key == "specs")
return dom::makePointer<DomFnSpecs>(
*I_, corpus_);
if(key == "template")
{
if(! I_->Template)
return nullptr;
return dom::makePointer<DomTemplate>(*I_->Template, corpus_);
}
}
if constexpr(T::isEnum())
{
}
if constexpr(T::isTypedef())
{
if(key == "template")
{
if(! I_->Template)
return nullptr;
return dom::makePointer<DomTemplate>(*I_->Template, corpus_);
}
}
if constexpr(T::isVariable())
{
if(key == "template")
{
if(! I_->Template)
return nullptr;
return dom::makePointer<DomTemplate>(*I_->Template, corpus_);
}
}
if constexpr(T::isField())
{
Expand Down Expand Up @@ -149,13 +175,23 @@ props() const ->
"bases",
"friends",
"members",
"specializations"
"specializations",
"template"
});
if constexpr(T::isFunction())
v.insert(v.end(), {
"return",
"params",
"specs"
"specs",
"template"
});
if constexpr(T::isVariable())
v.insert(v.end(), {
"template"
});
if constexpr(T::isTypedef())
v.insert(v.end(), {
"template"
});
return v;
}
Expand Down
Loading