Skip to content

Commit 1a89402

Browse files
sdkrystianvinniefalco
authored andcommitted
feat: adoc support for templates
close #328
1 parent bb6a6d3 commit 1a89402

10 files changed

+436
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{>type-name type}}
2+
{{~#if is-pack}}...{{/if}}
3+
{{~#if name}} {{name}}{{/if}}
4+
{{~#if default}} = {{default}}{{/if~}}

addons/generator/asciidoc/partials/record.adoc.hbs

+5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
[source,cpp,subs=+macros]
1010
----
11+
{{#if symbol.template}}
12+
{{>template-head symbol.template}}
13+
{{symbol.tag}} {{symbol.name}}{{>template-args symbol.template}}
14+
{{else}}
1115
{{symbol.tag}} {{symbol.name}}
16+
{{/if}}
1217
{
1318
{{#each symbol.members}}
1419
{{>record-member}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{~#if (neq kind "primary")~}}<
2+
{{~#each args~}}
3+
{{value}}
4+
{{~#if (not @last)}}, {{/if}}
5+
{{~/each~}}
6+
>{{/if}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
template<
2+
{{~#each params~}}
3+
{{~#if (eq kind "type")}}
4+
{{~>type-tparam~}}
5+
{{~else if (eq kind "non-type")}}
6+
{{~>nontype-tparam~}}
7+
{{~else if (eq kind "template")}}
8+
{{~>template-tparam~}}
9+
{{~/if~}}
10+
{{~#if (not @last)~}}, {{/if}}
11+
{{~/each~}}>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{{~>template-head~}}
2+
typename
3+
{{~#if is-pack}}...{{/if}}
4+
{{~#if name}} {{name}}{{/if}}
5+
{{~#if default}} = {{default}}{{/if~}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
typename
2+
{{~#if is-pack}}...{{/if}}
3+
{{~#if name}} {{name}}{{/if}}
4+
{{~#if default}} = {{>type-name default}}{{~/if~}}

include/mrdox/Dom/DomTemplate.hpp

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2023 Krystian Stasiowski ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdox
9+
//
10+
11+
#ifndef MRDOX_API_DOM_DOMTEMPLATE_HPP
12+
#define MRDOX_API_DOM_DOMTEMPLATE_HPP
13+
14+
#include <mrdox/Platform.hpp>
15+
#include <mrdox/Corpus.hpp>
16+
#include <mrdox/Support/Dom.hpp>
17+
18+
namespace clang {
19+
namespace mrdox {
20+
21+
class MRDOX_DECL
22+
DomTParam : public dom::Object
23+
{
24+
TParam const* I_;
25+
Corpus const& corpus_;
26+
27+
public:
28+
DomTParam(
29+
TParam const& I,
30+
Corpus const& corpus) noexcept
31+
: I_(&I)
32+
, corpus_(corpus)
33+
{
34+
}
35+
36+
dom::Value get(std::string_view key) const override;
37+
std::vector<std::string_view> props() const override;
38+
};
39+
40+
// ----------------------------------------------------------------
41+
42+
class MRDOX_DECL
43+
DomTArg : public dom::Object
44+
{
45+
TArg const* I_;
46+
Corpus const& corpus_;
47+
48+
public:
49+
DomTArg(
50+
TArg const& I,
51+
Corpus const& corpus) noexcept
52+
: I_(&I)
53+
, corpus_(corpus)
54+
{
55+
}
56+
57+
dom::Value get(std::string_view key) const override;
58+
std::vector<std::string_view> props() const override;
59+
};
60+
61+
// ----------------------------------------------------------------
62+
63+
/** An array of template parameters
64+
*/
65+
class DomTParamArray : public dom::Array
66+
{
67+
std::vector<TParam> const& list_;
68+
Corpus const& corpus_;
69+
70+
public:
71+
DomTParamArray(
72+
std::vector<TParam> const& list,
73+
Corpus const& corpus) noexcept
74+
: list_(list)
75+
, corpus_(corpus)
76+
{
77+
}
78+
79+
std::size_t length() const noexcept override
80+
{
81+
return list_.size();
82+
}
83+
84+
dom::Value get(std::size_t index) const override;
85+
};
86+
87+
// ----------------------------------------------------------------
88+
89+
/** An array of template arguments
90+
*/
91+
class DomTArgArray : public dom::Array
92+
{
93+
std::vector<TArg> const& list_;
94+
Corpus const& corpus_;
95+
96+
public:
97+
DomTArgArray(
98+
std::vector<TArg> const& list,
99+
Corpus const& corpus) noexcept
100+
: list_(list)
101+
, corpus_(corpus)
102+
{
103+
}
104+
105+
std::size_t length() const noexcept override
106+
{
107+
return list_.size();
108+
}
109+
110+
dom::Value get(std::size_t index) const override;
111+
};
112+
113+
// ----------------------------------------------------------------
114+
115+
/** Template info
116+
*/
117+
class MRDOX_DECL
118+
DomTemplate : public dom::Object
119+
{
120+
TemplateInfo const* I_;
121+
Info const* Primary_;
122+
Corpus const& corpus_;
123+
124+
public:
125+
DomTemplate(
126+
TemplateInfo const& I,
127+
Corpus const& corpus) noexcept;
128+
129+
dom::Value get(std::string_view key) const override;
130+
std::vector<std::string_view> props() const override;
131+
};
132+
133+
} // mrdox
134+
} // clang
135+
136+
#endif

source/-adoc/Builder.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ Builder(
112112
return a === b;
113113
});
114114
115+
Handlebars.registerHelper(
116+
'neq', function(a, b)
117+
{
118+
return a !== b;
119+
});
120+
121+
Handlebars.registerHelper(
122+
'not', function(a)
123+
{
124+
return ! a;
125+
});
115126
)");
116127
if(err)
117128
throw err;

source/Dom/DomSymbol.cpp

+38-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55
//
66
// Copyright (c) 2023 Vinnie Falco ([email protected])
7+
// Copyright (c) 2023 Krystian Stasiowski ([email protected])
78
//
89
// Official repository: https://github.com/cppalliance/mrdox
910
//
@@ -18,6 +19,7 @@
1819
#include <mrdox/Dom/DomSource.hpp>
1920
#include <mrdox/Dom/DomSymbol.hpp>
2021
#include <mrdox/Dom/DomSymbolArray.hpp>
22+
#include <mrdox/Dom/DomTemplate.hpp>
2123
#include <mrdox/Dom/DomType.hpp>
2224

2325
namespace clang {
@@ -87,6 +89,12 @@ get(std::string_view key) const
8789
if(key == "specializations")
8890
return dom::makePointer<DomSymbolArray>(
8991
I_->Specializations, corpus_);
92+
if(key == "template")
93+
{
94+
if(! I_->Template)
95+
return nullptr;
96+
return dom::makePointer<DomTemplate>(*I_->Template, corpus_);
97+
}
9098
}
9199
if constexpr(T::isFunction())
92100
{
@@ -99,15 +107,33 @@ get(std::string_view key) const
99107
if(key == "specs")
100108
return dom::makePointer<DomFnSpecs>(
101109
*I_, corpus_);
110+
if(key == "template")
111+
{
112+
if(! I_->Template)
113+
return nullptr;
114+
return dom::makePointer<DomTemplate>(*I_->Template, corpus_);
115+
}
102116
}
103117
if constexpr(T::isEnum())
104118
{
105119
}
106120
if constexpr(T::isTypedef())
107121
{
122+
if(key == "template")
123+
{
124+
if(! I_->Template)
125+
return nullptr;
126+
return dom::makePointer<DomTemplate>(*I_->Template, corpus_);
127+
}
108128
}
109129
if constexpr(T::isVariable())
110130
{
131+
if(key == "template")
132+
{
133+
if(! I_->Template)
134+
return nullptr;
135+
return dom::makePointer<DomTemplate>(*I_->Template, corpus_);
136+
}
111137
}
112138
if constexpr(T::isField())
113139
{
@@ -149,13 +175,23 @@ props() const ->
149175
"bases",
150176
"friends",
151177
"members",
152-
"specializations"
178+
"specializations",
179+
"template"
153180
});
154181
if constexpr(T::isFunction())
155182
v.insert(v.end(), {
156183
"return",
157184
"params",
158-
"specs"
185+
"specs",
186+
"template"
187+
});
188+
if constexpr(T::isVariable())
189+
v.insert(v.end(), {
190+
"template"
191+
});
192+
if constexpr(T::isTypedef())
193+
v.insert(v.end(), {
194+
"template"
159195
});
160196
return v;
161197
}

0 commit comments

Comments
 (0)