Skip to content

Commit 3e9c1aa

Browse files
committed
feat: extract-friends option
fix #910
1 parent 474032d commit 3e9c1aa

13 files changed

+649
-1
lines changed

docs/mrdocs.schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@
131131
"title": "Extraction policy for empty namespaces",
132132
"type": "boolean"
133133
},
134+
"extract-friends": {
135+
"default": true,
136+
"description": "Determine whether friend functions and classes should be extracted. When set to `true`, MrDocs extracts friend functions and classes. When set to `false`, friend functions and classes are not extracted.",
137+
"enum": [
138+
true,
139+
false
140+
],
141+
"title": "Extraction policy for friend functions and classes",
142+
"type": "boolean"
143+
},
134144
"extract-implicit-specializations": {
135145
"default": true,
136146
"description": "When set to `true`, MrDocs extracts implicit template specializations used as base classes as dependencies. This allows MrDocs to extract metadata that can later be used to determine the members of the derived class, as specified by the `inherit-base-members` option.",

src/lib/AST/ASTVisitor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,9 @@ populate(
715715
}
716716

717717
// Iterate over the friends of the class
718-
if (D->hasDefinition() && D->hasFriends())
718+
if (config_->extractFriends &&
719+
D->hasDefinition() &&
720+
D->hasFriends())
719721
{
720722
for (FriendDecl const* FD : D->friends())
721723
{

src/lib/ConfigOptions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@
268268
"type": "bool",
269269
"default": true
270270
},
271+
{
272+
"name": "extract-friends",
273+
"brief": "Extraction policy for friend functions and classes",
274+
"details": "Determine whether friend functions and classes should be extracted. When set to `true`, MrDocs extracts friend functions and classes. When set to `false`, friend functions and classes are not extracted.",
275+
"type": "bool",
276+
"default": true
277+
},
271278
{
272279
"name": "sort-members",
273280
"brief": "Sort the members of a record or namespace",
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
= Reference
2+
:mrdocs:
3+
4+
[#index]
5+
== Global namespace
6+
7+
=== Namespaces
8+
9+
[cols=1]
10+
|===
11+
| Name
12+
| link:#std[`std`]
13+
|===
14+
15+
=== Types
16+
17+
[cols=1]
18+
|===
19+
| Name
20+
| link:#A[`A`]
21+
|===
22+
23+
[#std]
24+
== std
25+
26+
=== Types
27+
28+
[cols=1]
29+
|===
30+
| Name
31+
| link:#std-hash-03[`hash`]
32+
| link:#std-hash-08[`hash<A>`]
33+
|===
34+
35+
[#std-hash-03]
36+
== link:#std[std]::hash
37+
38+
=== Synopsis
39+
40+
Declared in `<extract‐friends.cpp>`
41+
42+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
43+
----
44+
template<class T>
45+
class hash;
46+
----
47+
48+
[#std-hash-08]
49+
== link:#std[std]::link:#std-hash-03[hash]<link:#A[A]>
50+
51+
=== Synopsis
52+
53+
Declared in `<extract‐friends.cpp>`
54+
55+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
56+
----
57+
template<>
58+
class link:#std-hash-03[hash]<link:#A[A]>;
59+
----
60+
61+
=== Member Functions
62+
63+
[cols=1]
64+
|===
65+
| Name
66+
| link:#std-hash-08-operator_call[`operator()`]
67+
|===
68+
69+
[#std-hash-08-operator_call]
70+
== link:#std[std]::link:#std-hash-08[hash<A>]::operator()
71+
72+
=== Synopsis
73+
74+
Declared in `<extract‐friends.cpp>`
75+
76+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
77+
----
78+
unsigned long long
79+
operator()(link:#A[A] const& rhs) const noexcept;
80+
----
81+
82+
[#A]
83+
== A
84+
85+
=== Synopsis
86+
87+
Declared in `<extract‐friends.cpp>`
88+
89+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
90+
----
91+
class A;
92+
----
93+
94+
=== Friends
95+
96+
[cols=2]
97+
|===
98+
| Name
99+
| Description
100+
| `link:#std-hash-08[std::hash<A>]`
101+
|
102+
|===
103+
104+
105+
[.small]#Created with https://www.mrdocs.com[MrDocs]#
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace std {
2+
template <class T>
3+
class hash;
4+
}
5+
6+
class A {
7+
friend std::hash<A>;
8+
};
9+
10+
namespace std {
11+
template <>
12+
class hash<A> {
13+
public:
14+
unsigned long long
15+
operator()(const A&) const noexcept
16+
{
17+
return 0;
18+
}
19+
};
20+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<html lang="en">
2+
<head>
3+
<title>Reference</title>
4+
</head>
5+
<body>
6+
<div>
7+
<h1>Reference</h1>
8+
<div>
9+
<div>
10+
<h2 id="index"><a href="#index"></a></h2>
11+
</div>
12+
<h2>Namespaces</h2>
13+
<table style="table-layout: fixed; width: 100%;">
14+
<thead>
15+
<tr>
16+
<th>Name</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr>
21+
<td><a href="#std"><code>std</code></a> </td></tr>
22+
</tbody>
23+
</table>
24+
25+
<h2>Types</h2>
26+
<table style="table-layout: fixed; width: 100%;">
27+
<thead>
28+
<tr>
29+
<th>Name</th>
30+
</tr>
31+
</thead>
32+
<tbody>
33+
<tr>
34+
<td><a href="#A"><code>A</code></a> </td></tr>
35+
</tbody>
36+
</table>
37+
38+
</div>
39+
<div>
40+
<div>
41+
<h2 id="std"><a href="#std">std</a></h2>
42+
</div>
43+
<h2>Types</h2>
44+
<table style="table-layout: fixed; width: 100%;">
45+
<thead>
46+
<tr>
47+
<th>Name</th>
48+
</tr>
49+
</thead>
50+
<tbody>
51+
<tr>
52+
<td><a href="#std-hash-03"><code>hash</code></a> </td></tr><tr>
53+
<td><a href="#std-hash-08"><code>hash&lt;A&gt;</code></a> </td></tr>
54+
</tbody>
55+
</table>
56+
57+
</div>
58+
<div>
59+
<div>
60+
<h2 id="std-hash-03"><a href="#std-hash-03">std::hash</a></h2>
61+
</div>
62+
<div>
63+
<h3>Synopsis</h3>
64+
<div>
65+
Declared in <code>&lt;extract-friends.cpp&gt;</code></div>
66+
<pre>
67+
<code class="source-code cpp">
68+
template&lt;class T&gt;
69+
class hash;
70+
</code>
71+
</pre>
72+
</div>
73+
74+
75+
</div>
76+
<div>
77+
<div>
78+
<h2 id="std-hash-08"><a href="#std-hash-08">std::hash&lt;A&gt;</a></h2>
79+
</div>
80+
<div>
81+
<h3>Synopsis</h3>
82+
<div>
83+
Declared in <code>&lt;extract-friends.cpp&gt;</code></div>
84+
<pre>
85+
<code class="source-code cpp">
86+
template&lt;&gt;
87+
class <a href="#std-hash-03">hash</a>&lt;<a href="#A">A</a>&gt;;
88+
</code>
89+
</pre>
90+
</div>
91+
<h2>Member Functions</h2>
92+
<table style="table-layout: fixed; width: 100%;">
93+
<thead>
94+
<tr>
95+
<th>Name</th>
96+
</tr>
97+
</thead>
98+
<tbody>
99+
<tr>
100+
<td><a href="#std-hash-08-operator_call"><code>operator()</code></a> </td></tr>
101+
</tbody>
102+
</table>
103+
104+
105+
106+
</div>
107+
<div>
108+
<div>
109+
<h2 id="std-hash-08-operator_call"><a href="#std-hash-08-operator_call">std::hash&lt;A&gt;::operator()</a></h2>
110+
</div>
111+
<div>
112+
<h3>Synopsis</h3>
113+
<div>
114+
Declared in <code>&lt;extract-friends.cpp&gt;</code></div>
115+
<pre>
116+
<code class="source-code cpp">
117+
unsigned long long
118+
operator()(<a href="#A">A</a> const& rhs) const noexcept;
119+
</code>
120+
</pre>
121+
</div>
122+
</div>
123+
<div>
124+
<div>
125+
<h2 id="A"><a href="#A">A</a></h2>
126+
</div>
127+
<div>
128+
<h3>Synopsis</h3>
129+
<div>
130+
Declared in <code>&lt;extract-friends.cpp&gt;</code></div>
131+
<pre>
132+
<code class="source-code cpp">
133+
class A;
134+
</code>
135+
</pre>
136+
</div>
137+
138+
139+
<div>
140+
<h2>Friends</h2>
141+
<table>
142+
<thead>
143+
<tr>
144+
<th>Name</th>
145+
<th>Description</th>
146+
</tr>
147+
</thead>
148+
<tbody>
149+
<tr>
150+
<td><code><a href="#std-hash-08">hash&lt;A&gt;</a></code></td>
151+
<td><span></span></td>
152+
</tr>
153+
|===
154+
</tbody>
155+
</table>
156+
</div>
157+
</div>
158+
159+
</div>
160+
<div>
161+
<h4>Created with <a href="https://www.mrdocs.com">MrDocs</a></h4>
162+
</div>
163+
</body>
164+
</html>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<mrdocs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdocs/raw/develop/mrdocs.rnc">
4+
<namespace id="//////////////////////////8=">
5+
<namespace name="std" id="eIvg7iueGIPcE8p1NVfngsp2ojw=">
6+
<template>
7+
<tparam name="T" class="type"/>
8+
<class name="hash" id="PJd7qch01fTpaC83fxeMwg+clc0=">
9+
<file short-path="extract-friends.cpp" source-path="extract-friends.cpp" line="2"/>
10+
</class>
11+
</template>
12+
<template class="explicit" id="PJd7qch01fTpaC83fxeMwg+clc0=">
13+
<targ class="type" type="A"/>
14+
<class name="hash" id="jTCZUvygQOxo6L+VfFZcAI6KU0Y=">
15+
<file short-path="extract-friends.cpp" source-path="extract-friends.cpp" line="12" class="def"/>
16+
<function name="operator()" exception-spec="noexcept" id="oizNQDy8La+BwcGOBpMPC63TA5U=">
17+
<file short-path="extract-friends.cpp" source-path="extract-friends.cpp" line="14" class="def"/>
18+
<attr id="operator" name="call" value="42"/>
19+
<attr id="is-const"/>
20+
<return>
21+
<type name="unsigned long long"/>
22+
</return>
23+
<param name="rhs">
24+
<type class="lvalue-reference">
25+
<pointee-type id="YrPSaKAbmXgzCAX5WByx4eVoqBM=" name="A" cv-qualifiers="const"/>
26+
</type>
27+
</param>
28+
</function>
29+
</class>
30+
</template>
31+
</namespace>
32+
<class name="A" id="YrPSaKAbmXgzCAX5WByx4eVoqBM=">
33+
<file short-path="extract-friends.cpp" source-path="extract-friends.cpp" line="6" class="def"/>
34+
<friend id="jTCZUvygQOxo6L+VfFZcAI6KU0Y=">
35+
<befriended id="jTCZUvygQOxo6L+VfFZcAI6KU0Y="/>
36+
</friend>
37+
</class>
38+
</namespace>
39+
</mrdocs>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
extract-friends: true
2+
warn-if-undocumented: false

0 commit comments

Comments
 (0)