Skip to content

Commit dc4dada

Browse files
committed
auto-relates option
#feat
1 parent f069410 commit dc4dada

File tree

111 files changed

+7013
-73
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+7013
-73
lines changed

docs/mrdocs.schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
"title": "Use the first line of the comment as the brief",
1818
"type": "boolean"
1919
},
20+
"auto-relates": {
21+
"default": true,
22+
"description": "When set to `true`, MrDocs automatically finds non-member functions that are related to the current class.",
23+
"enum": [
24+
true,
25+
false
26+
],
27+
"title": "Automatically find non-member functions",
28+
"type": "boolean"
29+
},
2030
"base-url": {
2131
"default": "",
2232
"description": "Base URL for links to source code. The base URL is used to create links to the source code in the documentation. The base URL is combined with the path to the source file to create the link.",

include/mrdocs/Corpus.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,35 @@ class MRDOCS_VISIBLE
350350
return temp;
351351
}
352352

353+
/** Return a qualified name from the specified context.
354+
355+
This function returns the qualified name
356+
of the specified Info `I` from the context
357+
specified by the SymbolID `context`.
358+
359+
If the context is a parent of `I`, the
360+
qualified name is constructed relative to
361+
the context. For instance, if `I` is `A::B::C::D`
362+
and context is `A::B`, the result is `C::D`.
363+
364+
If the context is not a parent of `I`, the
365+
qualified name is constructed relative to
366+
the global namespace with the prefix `::`.
367+
*/
368+
virtual
369+
void
370+
qualifiedName(
371+
Info const& I,
372+
SymbolID const& context,
373+
std::string& result) const = 0;
374+
375+
std::string
376+
qualifiedName(Info const& I, SymbolID const& context) const
377+
{
378+
std::string temp;
379+
qualifiedName(I, context, temp);
380+
return temp;
381+
}
353382
};
354383

355384
//------------------------------------------------

include/mrdocs/Metadata/Info/Record.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ struct RecordInfo final
291291
*/
292292
std::vector<BaseInfo> Bases;
293293

294+
/** List of derived classes
295+
*/
296+
std::vector<SymbolID> Derived;
297+
294298
RecordInterface Interface;
295299

296300
//--------------------------------------------
@@ -347,6 +351,7 @@ tag_invoke(
347351
io.map("defaultAccess", getDefaultAccessString(I.KeyKind));
348352
io.map("isTypedef", I.IsTypeDef);
349353
io.map("bases", dom::LazyArray(I.Bases, domCorpus));
354+
io.map("derived", dom::LazyArray(I.Derived, domCorpus));
350355
io.map("interface", I.Interface);
351356
io.map("template", I.Template);
352357
}

include/mrdocs/Metadata/Javadoc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ tag_invoke(
18081808
io.defer("description", [&I, domCorpus] {
18091809
return dom::LazyArray(I.blocks, domCorpus);
18101810
});
1811-
if (I.brief)
1811+
if (I.brief && !I.brief->children.empty())
18121812
{
18131813
io.map("brief", I.brief);
18141814
}

include/mrdocs/Metadata/Type.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,15 +562,20 @@ innerTypePtr(TypeInfo& TI) noexcept;
562562
The innermost type is the type which is not
563563
modified by any specifiers (e.g. "int" in
564564
"pointer to const int").
565+
566+
If the type has an inner type, we recursively
567+
call this function until we reach the innermost
568+
type. If the type has no inner type, we return
569+
the current type.
565570
*/
566571
MRDOCS_DECL
567-
std::optional<std::reference_wrapper<Polymorphic<TypeInfo> const>>
568-
innermostType(TypeInfo const& TI) noexcept;
572+
Polymorphic<TypeInfo> const&
573+
innermostType(Polymorphic<TypeInfo> const& TI) noexcept;
569574

570-
/// @copydoc innermostType(TypeInfo const&)
575+
/// @copydoc innermostType(Polymorphic<TypeInfo> const&)
571576
MRDOCS_DECL
572-
std::optional<std::reference_wrapper<Polymorphic<TypeInfo>>>
573-
innermostType(TypeInfo& TI) noexcept;
577+
Polymorphic<TypeInfo>&
578+
innermostType(Polymorphic<TypeInfo>& TI) noexcept;
574579

575580
// VFALCO maybe we should rename this to `renderType` or something?
576581
MRDOCS_DECL

share/mrdocs/addons/generator/adoc/partials/symbol.adoc.hbs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,20 @@
7979
|===
8080

8181
{{/if}}
82-
{{! Relates symbols }}
83-
{{#if symbol.doc.relates }}
84-
{{#> markup/dynamic-level-h }}Non-Member Of{{/markup/dynamic-level-h}}
82+
{{! Derived classes }}
83+
{{#if symbol.derived}}
84+
{{#> markup/dynamic-level-h }}Derived Classes{{/markup/dynamic-level-h}}
8585
[,cols=2]
8686
|===
8787
| Name
8888
| Description
89-
{{#each symbol.doc.relates }}
90-
| {{> javadoc/reference }}
91-
| {{> javadoc/inline-brief symbol.doc.brief }}
89+
{{#each symbol.derived}}
90+
| {{#if url~}}
91+
{{#>markup/a href=url}}{{#>markup/code}}{{> symbol/name-info . nolink=true}}{{/markup/code}}{{/markup/a}}
92+
{{else~}}
93+
{{> symbol/name-info . nolink=true}}
94+
{{/if}}
95+
| {{> javadoc/inline-brief doc.brief }}
9296
{{/each}}
9397
|===
9498

@@ -101,7 +105,7 @@
101105
{{! Using symbols }}
102106
{{#if symbol.shadows}}
103107
{{#> markup/dynamic-level-h }}Introduced Symbols{{/markup/dynamic-level-h}}
104-
108+
[cols=2]
105109
|===
106110
| Name
107111
{{#each symbol.shadows}}
@@ -113,6 +117,7 @@
113117
{{! Exceptions }}
114118
{{#if symbol.doc.exceptions}}
115119
{{#> markup/dynamic-level-h }}Exceptions{{/markup/dynamic-level-h}}
120+
[cols=2]
116121
|===
117122
| Name
118123
| Thrown on
@@ -140,6 +145,7 @@
140145
{{! Template Parameters }}
141146
{{#if symbol.doc.tparams}}
142147
{{#> markup/dynamic-level-h }}Template Parameters{{/markup/dynamic-level-h}}
148+
[cols=2]
143149
|===
144150
| Name
145151
| Description
@@ -153,6 +159,7 @@
153159
{{! Parameters }}
154160
{{#if symbol.doc.params}}
155161
{{#> markup/dynamic-level-h }}Parameters{{/markup/dynamic-level-h}}
162+
[cols=2]
156163
|===
157164
| Name
158165
| Description

share/mrdocs/addons/generator/html/partials/symbol.html.hbs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@
106106
</table>
107107
</div>
108108
{{/if}}
109-
{{! Relates symbols }}
110-
{{#if symbol.doc.relates }}
109+
{{! Derived classes }}
110+
{{#if symbol.derived}}
111111
<div>
112-
{{#> markup/dynamic-level-h }}Non-Member Of{{/markup/dynamic-level-h}}
112+
{{#> markup/dynamic-level-h }}Derived Classes{{/markup/dynamic-level-h}}
113113
<table>
114114
<thead>
115115
<tr>
@@ -118,8 +118,12 @@
118118
</tr>
119119
</thead>
120120
<tbody>
121-
{{#each symbol.doc.relates }}
122-
<tr><td>{{> javadoc/reference }}</td><td>{{> javadoc/inline-brief symbol.doc.brief }}</td></tr>
121+
{{#each symbol.derived}}
122+
<tr><td>{{#if url~}}
123+
{{#>markup/a href=url}}{{#>markup/code}}{{> symbol/name-info . nolink=true}}{{/markup/code}}{{/markup/a}}
124+
{{else~}}
125+
{{> symbol/name-info . nolink=true}}
126+
{{/if}}</td><td>{{> javadoc/inline-brief doc.brief }}</td></tr>
123127
{{/each}}
124128
</tbody>
125129
</table>

src/lib/Lib/ConfigOptions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@
170170
"details": "When set to `true`, MrDocs uses the first line (until the first dot, question mark, or exclamation mark) of the comment as the brief of the symbol. When set to `false`, a explicit @brief command is required.",
171171
"type": "bool",
172172
"default": true
173+
},
174+
{
175+
"name": "auto-relates",
176+
"brief": "Automatically find non-member functions",
177+
"details": "When set to `true`, MrDocs automatically finds non-member functions that are related to the current class.",
178+
"type": "bool",
179+
"default": true
173180
}
174181
]
175182
},

src/lib/Lib/CorpusImpl.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
#include "lib/Metadata/Finalizers/SortMembersFinalizer.hpp"
1919
#include "lib/Metadata/Finalizers/JavadocFinalizer.hpp"
2020
#include "lib/Metadata/Finalizers/NamespacesFinalizer.hpp"
21+
#include "lib/Metadata/Finalizers/DerivedFinalizer.hpp"
2122
#include "lib/Support/Report.hpp"
2223
#include "lib/Support/Chrono.hpp"
2324
#include <mrdocs/Metadata.hpp>
2425
#include <mrdocs/Support/Error.hpp>
2526
#include <mrdocs/Support/ThreadPool.hpp>
27+
#include <mrdocs/Support/Algorithm.hpp>
2628
#include <chrono>
2729

2830
namespace clang::mrdocs {
@@ -869,6 +871,57 @@ qualifiedName(Info const& I, std::string& result) const
869871
}
870872
}
871873

874+
void
875+
CorpusImpl::
876+
qualifiedName(
877+
Info const& I,
878+
SymbolID const& context,
879+
std::string& result) const
880+
{
881+
if (context == SymbolID::global)
882+
{
883+
qualifiedName(I, result);
884+
return;
885+
}
886+
887+
result.clear();
888+
if (!I.id || I.id == SymbolID::global)
889+
{
890+
return;
891+
}
892+
893+
if (I.Parent &&
894+
!is_one_of(I.Parent, {SymbolID::global, context}) &&
895+
I.id != context)
896+
{
897+
if (Info const* PI = find(I.Parent))
898+
{
899+
qualifiedName(*PI, context, result);
900+
result += "::";
901+
}
902+
}
903+
904+
if (I.id == context)
905+
{
906+
return;
907+
}
908+
909+
if (I.Parent == SymbolID::global)
910+
{
911+
result += "::";
912+
}
913+
if (!I.Name.empty())
914+
{
915+
result += I.Name;
916+
}
917+
else
918+
{
919+
result += "<unnamed ";
920+
result += toString(I.Kind);
921+
result += ">";
922+
}
923+
}
924+
872925
void
873926
CorpusImpl::finalize()
874927
{
@@ -892,6 +945,12 @@ CorpusImpl::finalize()
892945
finalizer.build();
893946
}
894947

948+
{
949+
report::debug("Finalizing auto-relates");
950+
DerivedFinalizer finalizer(*this);
951+
finalizer.build();
952+
}
953+
895954
if (config->sortMembers)
896955
{
897956
report::debug("Finalizing sorted members");

src/lib/Lib/CorpusImpl.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class CorpusImpl final : public Corpus
6161
friend class SortMembersFinalizer;
6262
friend class JavadocFinalizer;
6363
friend class NamespacesFinalizer;
64+
friend class DerivedFinalizer;
6465

6566
public:
6667
/** Constructor.
@@ -175,6 +176,12 @@ class CorpusImpl final : public Corpus
175176
Info const& I,
176177
std::string& result) const override;
177178

179+
void
180+
qualifiedName(
181+
Info const& I,
182+
SymbolID const& context,
183+
std::string& result) const override;
184+
178185
/** Finalize the corpus.
179186
*/
180187
void

0 commit comments

Comments
 (0)