Skip to content

Commit 572a465

Browse files
committed
support implicit templates
#feat fix #868
1 parent 4550326 commit 572a465

15 files changed

+334
-95
lines changed

src/lib/AST/ASTVisitor.cpp

+28-5
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,7 @@ populate(
562562
std::optional<Javadoc>& javadoc,
563563
Decl const* D)
564564
{
565-
RawComment const* RC =
566-
D->getASTContext().getRawCommentForDeclNoCache(D);
565+
RawComment const* RC = getDocumentation(D);
567566
MRDOCS_CHECK_OR(RC, false);
568567
comments::FullComment* FC =
569568
RC->parse(D->getASTContext(), &sema_.getPreprocessor(), D);
@@ -1232,6 +1231,15 @@ ASTVisitor::
12321231
populate(TemplateInfo& Template, DeclTy const*, TemplateDeclTy const* TD)
12331232
{
12341233
MRDOCS_ASSERT(TD);
1234+
MRDOCS_CHECK_OR(!TD->isImplicit());
1235+
if (TemplateParameterList const* TPL = TD->getTemplateParameters();
1236+
!TPL->empty() &&
1237+
std::ranges::none_of(TPL->asArray(), [](NamedDecl const* ND) {
1238+
return !ND->isImplicit();
1239+
}))
1240+
{
1241+
return;
1242+
}
12351243
TemplateParameterList const* TPL = TD->getTemplateParameters();
12361244
populate(Template, TPL);
12371245
}
@@ -1519,14 +1527,29 @@ populate(
15191527
{
15201528
return;
15211529
}
1522-
if (TPL->size() > TI.Params.size())
1530+
auto TemplateParameters = TPL->asArray();
1531+
auto ExplicitTemplateParameters =
1532+
std::views::filter(
1533+
TemplateParameters,
1534+
[](NamedDecl const* P)
1535+
{
1536+
return !P->isImplicit();
1537+
});
1538+
std::size_t const nExplicit = std::ranges::distance(
1539+
ExplicitTemplateParameters);
1540+
MRDOCS_CHECK_OR(nExplicit);
1541+
if (nExplicit > TI.Params.size())
15231542
{
1524-
TI.Params.resize(TPL->size());
1543+
TI.Params.resize(nExplicit);
15251544
}
1526-
for (std::size_t i = 0; i < TPL->size(); ++i)
1545+
auto explicitIt = ExplicitTemplateParameters.begin();
1546+
std::size_t i = 0;
1547+
while (explicitIt != ExplicitTemplateParameters.end())
15271548
{
15281549
NamedDecl const* P = TPL->getParam(i);
15291550
populate(TI.Params[i], P);
1551+
++explicitIt;
1552+
++i;
15301553
}
15311554
if (auto* RC = TPL->getRequiresClause())
15321555
{

src/lib/AST/ASTVisitor.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,16 @@ class ASTVisitor
626626
void
627627
populate(std::optional<TemplateInfo>& Template, DeclTy const* D, TemplateDeclTy const* VTD)
628628
{
629+
MRDOCS_CHECK_OR(VTD);
630+
MRDOCS_CHECK_OR(!VTD->isImplicit());
631+
if (TemplateParameterList const* TPL = VTD->getTemplateParameters();
632+
!TPL->empty() &&
633+
std::ranges::none_of(TPL->asArray(), [](NamedDecl const* ND) {
634+
return !ND->isImplicit();
635+
}))
636+
{
637+
return;
638+
}
629639
if (!Template)
630640
{
631641
Template.emplace();

src/lib/AST/ClangHelpers.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,26 @@ isStaticFileLevelMember(Decl const* D)
400400
return false;
401401
}
402402

403+
RawComment const*
404+
getDocumentation(Decl const* D)
405+
{
406+
RawComment const* RC =
407+
D->getASTContext().getRawCommentForDeclNoCache(D);
408+
if (!RC)
409+
{
410+
auto const* TD = dyn_cast<TemplateDecl>(D);
411+
MRDOCS_CHECK_OR(TD, nullptr);
412+
NamedDecl const* ND = TD->getTemplatedDecl();
413+
MRDOCS_CHECK_OR(ND, nullptr);
414+
RC = ND->getASTContext().getRawCommentForDeclNoCache(ND);
415+
}
416+
return RC;
417+
}
418+
403419
bool
404420
isDocumented(Decl const* D)
405421
{
406-
return D->getASTContext().getRawCommentForDeclNoCache(D);
422+
return getDocumentation(D) != nullptr;
407423
}
408424

409-
410425
} // clang::mrdocs

src/lib/AST/ClangHelpers.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,10 @@ MRDOCS_DECL
926926
bool
927927
isDocumented(Decl const *D);
928928

929+
MRDOCS_DECL
930+
RawComment const*
931+
getDocumentation(Decl const *D);
932+
929933
template <class DeclTy>
930934
bool
931935
isDefinition(DeclTy* D)

src/lib/Metadata/Finalizers/OverloadsFinalizer.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ findBaseClassPermutation(
5151
MRDOCS_CHECK_OR(info, SymbolID::invalid);
5252
if (auto* record = dynamic_cast<RecordInfo*>(info))
5353
{
54-
bool overloadsFromBase = false;
5554
for (auto const& base: record->Bases)
5655
{
5756
auto const baseInfo = corpus.find(base.Type->namedSymbol());

test-files/golden-tests/javadoc/copydoc/param-types.adoc

+40-24
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,17 @@ void
723723

724724
[.small]#<<g-09c,_» more&period;&period;&period;_>>#
725725

726+
Auto function
727+
728+
729+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
730+
----
731+
void
732+
<<g-0b,g>>(auto a);
733+
----
734+
735+
[.small]#<<g-0b,_» more&period;&period;&period;_>>#
736+
726737
Enum param function
727738

728739

@@ -756,16 +767,6 @@ void
756767

757768
[.small]#<<g-04a,_» more&period;&period;&period;_>>#
758769

759-
760-
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
761-
----
762-
template&lt;class a&colon;auto&gt;
763-
void
764-
<<g-0b,g>>(auto a);
765-
----
766-
767-
[.small]#<<g-0b,_» more&period;&period;&period;_>>#
768-
769770
Decltype function
770771

771772

@@ -849,6 +850,35 @@ Documentation for a function with a qualified identifier parameter&period;
849850
| The first parameter of g
850851
|===
851852

853+
[#g-0b]
854+
== g
855+
856+
Auto function
857+
858+
=== Synopsis
859+
860+
Declared in `&lt;param&hyphen;types&period;cpp&gt;`
861+
862+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
863+
----
864+
void
865+
g(auto a);
866+
----
867+
868+
=== Description
869+
870+
Documentation for a function with an `auto` parameter&period;
871+
872+
=== Parameters
873+
874+
[cols=2]
875+
|===
876+
| Name
877+
| Description
878+
| *a*
879+
| The first parameter of g
880+
|===
881+
852882
[#g-04c]
853883
== g
854884

@@ -936,20 +966,6 @@ Documentation for the non&hyphen;variadic function&period;
936966
| The first parameter of g
937967
|===
938968

939-
[#g-0b]
940-
== g
941-
942-
=== Synopsis
943-
944-
Declared in `&lt;param&hyphen;types&period;cpp&gt;`
945-
946-
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
947-
----
948-
template&lt;class a&colon;auto&gt;
949-
void
950-
g(auto a);
951-
----
952-
953969
[#g-0c]
954970
== g
955971

test-files/golden-tests/javadoc/copydoc/param-types.html

+47-24
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,14 @@ <h3>Synopses</h3>
916916
</code>
917917
</pre><span class="small"><a href="#g-09c"><em>» more...</em></a></span>
918918

919+
<span>Auto function</span>
920+
<pre>
921+
<code class="source-code cpp">
922+
void
923+
<a href="#g-0b">g</a>(auto a);
924+
</code>
925+
</pre><span class="small"><a href="#g-0b"><em>» more...</em></a></span>
926+
919927
<span>Enum param function</span>
920928
<pre>
921929
<code class="source-code cpp">
@@ -940,15 +948,6 @@ <h3>Synopses</h3>
940948
</code>
941949
</pre><span class="small"><a href="#g-04a"><em>» more...</em></a></span>
942950

943-
944-
<pre>
945-
<code class="source-code cpp">
946-
template&lt;class a:auto&gt;
947-
void
948-
<a href="#g-0b">g</a>(auto a);
949-
</code>
950-
</pre><span class="small"><a href="#g-0b"><em>» more...</em></a></span>
951-
952951
<span>Decltype function</span>
953952
<pre>
954953
<code class="source-code cpp">
@@ -1067,9 +1066,9 @@ <h3>Parameters</h3>
10671066
</div>
10681067
<div>
10691068
<div>
1070-
<h2 id="g-04c">g</h2>
1069+
<h2 id="g-0b">g</h2>
10711070
<div>
1072-
<span>Enum param function</span>
1071+
<span>Auto function</span>
10731072

10741073
</div>
10751074
</div>
@@ -1080,13 +1079,13 @@ <h3>Synopsis</h3>
10801079
<pre>
10811080
<code class="source-code cpp">
10821081
void
1083-
g(<a href="#testEnum">testEnum</a> a);
1082+
g(auto a);
10841083
</code>
10851084
</pre>
10861085
</div>
10871086
<div>
10881087
<h3>Description</h3>
1089-
<p>Documentation for a function with an enum parameter.</p>
1088+
<p>Documentation for a function with an <code>auto</code> parameter.</p>
10901089
</div>
10911090
<div>
10921091
<h3>Parameters</h3>
@@ -1108,9 +1107,9 @@ <h3>Parameters</h3>
11081107
</div>
11091108
<div>
11101109
<div>
1111-
<h2 id="g-096">g</h2>
1110+
<h2 id="g-04c">g</h2>
11121111
<div>
1113-
<span>Variadic function</span>
1112+
<span>Enum param function</span>
11141113

11151114
</div>
11161115
</div>
@@ -1121,13 +1120,13 @@ <h3>Synopsis</h3>
11211120
<pre>
11221121
<code class="source-code cpp">
11231122
void
1124-
g(int a, ...);
1123+
g(<a href="#testEnum">testEnum</a> a);
11251124
</code>
11261125
</pre>
11271126
</div>
11281127
<div>
11291128
<h3>Description</h3>
1130-
<p>Documentation for the variadic function.</p>
1129+
<p>Documentation for a function with an enum parameter.</p>
11311130
</div>
11321131
<div>
11331132
<h3>Parameters</h3>
@@ -1149,9 +1148,9 @@ <h3>Parameters</h3>
11491148
</div>
11501149
<div>
11511150
<div>
1152-
<h2 id="g-04a">g</h2>
1151+
<h2 id="g-096">g</h2>
11531152
<div>
1154-
<span>Non-variadic function</span>
1153+
<span>Variadic function</span>
11551154

11561155
</div>
11571156
</div>
@@ -1162,13 +1161,13 @@ <h3>Synopsis</h3>
11621161
<pre>
11631162
<code class="source-code cpp">
11641163
void
1165-
g(int a);
1164+
g(int a, ...);
11661165
</code>
11671166
</pre>
11681167
</div>
11691168
<div>
11701169
<h3>Description</h3>
1171-
<p>Documentation for the non-variadic function.</p>
1170+
<p>Documentation for the variadic function.</p>
11721171
</div>
11731172
<div>
11741173
<h3>Parameters</h3>
@@ -1190,20 +1189,44 @@ <h3>Parameters</h3>
11901189
</div>
11911190
<div>
11921191
<div>
1193-
<h2 id="g-0b">g</h2>
1192+
<h2 id="g-04a">g</h2>
1193+
<div>
1194+
<span>Non-variadic function</span>
1195+
1196+
</div>
11941197
</div>
11951198
<div>
11961199
<h3>Synopsis</h3>
11971200
<div>
11981201
Declared in <code>&lt;param-types.cpp&gt;</code></div>
11991202
<pre>
12001203
<code class="source-code cpp">
1201-
template&lt;class a:auto&gt;
12021204
void
1203-
g(auto a);
1205+
g(int a);
12041206
</code>
12051207
</pre>
12061208
</div>
1209+
<div>
1210+
<h3>Description</h3>
1211+
<p>Documentation for the non-variadic function.</p>
1212+
</div>
1213+
<div>
1214+
<h3>Parameters</h3>
1215+
<table>
1216+
<thead>
1217+
<tr>
1218+
<th>Name</th>
1219+
<th>Description</th>
1220+
</tr>
1221+
</thead>
1222+
<tbody>
1223+
<tr>
1224+
<td><strong>a</strong></td>
1225+
<td><span>The first parameter of g</span></td>
1226+
</tr>
1227+
</tbody>
1228+
</table>
1229+
</div>
12071230
</div>
12081231
<div>
12091232
<div>

0 commit comments

Comments
 (0)