Skip to content

Commit 01c5e15

Browse files
committed
auto-function-metadata option
#feat
1 parent 1cbeee6 commit 01c5e15

File tree

114 files changed

+14146
-2266
lines changed

Some content is hidden

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

114 files changed

+14146
-2266
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-function-metadata": {
21+
"default": true,
22+
"description": "When set to `true`, MrDocs automatically provides documentation for special functions, such as constructors, destructors, and operators. It also provides documentation for missing documentation metadata, such as known types.",
23+
"enum": [
24+
true,
25+
false
26+
],
27+
"title": "Automatically provide missing documentation for special functions and trivial metadata",
28+
"type": "boolean"
29+
},
2030
"auto-relates": {
2131
"default": true,
2232
"description": "When set to `true`, MrDocs automatically finds non-member functions that are related to the current class.",

include/mrdocs/Metadata/Info/Function.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ getSafeOperatorName(
7070
OperatorKind kind,
7171
bool include_keyword = false) noexcept;
7272

73+
/** Return the human-readable name of the operator
74+
*/
75+
std::optional<std::string_view>
76+
getOperatorReadableName(
77+
OperatorKind kind,
78+
int nParams);
79+
7380
/** Function classifications */
7481
enum class FunctionClass
7582
{

include/mrdocs/Metadata/Javadoc.hpp

Lines changed: 102 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ enum class NodeKind
119119
styled,
120120
tparam,
121121
reference,
122-
copied,
122+
copy_details,
123123
throws,
124124
details,
125125
see,
@@ -373,7 +373,8 @@ struct Text : Node
373373
{
374374
}
375375

376-
bool isBlock() const noexcept final
376+
bool
377+
isBlock() const noexcept final
377378
{
378379
return false;
379380
}
@@ -600,26 +601,21 @@ tag_invoke(
600601

601602
/** Documentation copied from another symbol.
602603
*/
603-
struct Copied final : Reference
604+
struct CopyDetails final : Reference
604605
{
605-
Parts parts;
606+
static constexpr auto static_kind = NodeKind::copy_details;
606607

607-
static constexpr auto static_kind = NodeKind::copied;
608-
609-
Copied(
610-
std::string string_ = std::string(),
611-
Parts parts_ = Parts::all) noexcept
612-
: Reference(std::move(string_), NodeKind::copied)
613-
, parts(parts_)
608+
CopyDetails(std::string string_ = std::string()) noexcept
609+
: Reference(std::move(string_), NodeKind::copy_details)
614610
{
615611
}
616612

617-
auto operator<=>(Copied const&) const = default;
618-
bool operator==(Copied const&) const noexcept = default;
613+
auto operator<=>(CopyDetails const&) const = default;
614+
bool operator==(CopyDetails const&) const noexcept = default;
619615
bool equals(Node const& other) const noexcept override
620616
{
621617
return Kind == other.Kind &&
622-
*this == dynamic_cast<Copied const&>(other);
618+
*this == dynamic_cast<CopyDetails const&>(other);
623619
}
624620
};
625621

@@ -630,11 +626,10 @@ void
630626
tag_invoke(
631627
dom::LazyObjectMapTag t,
632628
IO& io,
633-
Copied const& I,
629+
CopyDetails const& I,
634630
DomCorpus const* domCorpus)
635631
{
636632
tag_invoke(t, io, dynamic_cast<Reference const&>(I), domCorpus);
637-
io.map("parts", I.parts);
638633
}
639634

640635
/** Return the @ref Copied as a @ref dom::Value object.
@@ -644,7 +639,7 @@ void
644639
tag_invoke(
645640
dom::ValueFromTag,
646641
dom::Value& v,
647-
Copied const& I,
642+
CopyDetails const& I,
648643
DomCorpus const* domCorpus)
649644
{
650645
v = dom::LazyObject(I, domCorpus);
@@ -825,10 +820,11 @@ struct Paragraph : Block
825820
{
826821
static constexpr auto static_kind = NodeKind::paragraph;
827822

828-
Paragraph() noexcept
829-
: Block(NodeKind::paragraph)
830-
{
831-
}
823+
Paragraph() noexcept : Block(NodeKind::paragraph) {}
824+
825+
virtual
826+
Paragraph&
827+
operator=(std::string_view str);
832828

833829
auto operator<=>(Paragraph const&) const = default;
834830

@@ -881,11 +877,30 @@ struct Brief final : Paragraph
881877
{
882878
static constexpr NodeKind static_kind = NodeKind::brief;
883879

880+
std::vector<std::string> copiedFrom;
881+
884882
Brief() noexcept
885883
: Paragraph(NodeKind::brief)
886884
{
887885
}
888886

887+
explicit
888+
Brief(std::string_view const text)
889+
: Brief()
890+
{
891+
operator=(text);
892+
}
893+
894+
Brief&
895+
operator=(Brief const& other) = default;
896+
897+
Brief&
898+
operator=(std::string_view const text) override
899+
{
900+
Paragraph::operator=(text);
901+
return *this;
902+
}
903+
889904
auto operator<=>(Brief const&) const = default;
890905

891906
bool equals(Node const& other) const noexcept override
@@ -939,8 +954,12 @@ struct Admonition final : Paragraph
939954
{
940955
}
941956

957+
using Paragraph::operator=;
958+
942959
auto operator<=>(Admonition const&) const = default;
960+
943961
bool operator==(Admonition const&) const noexcept = default;
962+
944963
bool equals(Node const& other) const noexcept override
945964
{
946965
return Kind == other.Kind &&
@@ -989,6 +1008,7 @@ struct Code final : Paragraph
9891008
{
9901009
}
9911010

1011+
using Paragraph::operator=;
9921012
auto operator<=>(Code const&) const = default;
9931013
bool operator==(Code const&) const noexcept = default;
9941014
bool equals(Node const& other) const noexcept override
@@ -1034,6 +1054,8 @@ struct ListItem final : Paragraph
10341054
: Paragraph(static_kind)
10351055
{}
10361056

1057+
using Paragraph::operator=;
1058+
10371059
auto operator<=>(ListItem const&) const = default;
10381060
bool
10391061
operator==(ListItem const&) const noexcept = default;
@@ -1093,6 +1115,8 @@ struct UnorderedList final : Paragraph
10931115
{
10941116
}
10951117

1118+
using Paragraph::operator=;
1119+
10961120
auto operator<=>(UnorderedList const& other) const {
10971121
if (auto const cmp = items.size() <=> other.items.size();
10981122
!std::is_eq(cmp))
@@ -1169,6 +1193,8 @@ struct See final : Paragraph
11691193
{
11701194
}
11711195

1196+
using Paragraph::operator=;
1197+
11721198
auto operator<=>(See const&) const = default;
11731199

11741200
bool operator==(See const&)
@@ -1228,6 +1254,30 @@ struct Param final : Paragraph
12281254
{
12291255
}
12301256

1257+
explicit
1258+
Param(
1259+
std::string_view const name,
1260+
std::string_view const text)
1261+
: Param()
1262+
{
1263+
this->name = name;
1264+
this->operator=(text);
1265+
}
1266+
1267+
explicit
1268+
Param(Paragraph const& other)
1269+
: Param()
1270+
{
1271+
children = other.children;
1272+
}
1273+
1274+
Param&
1275+
operator=(std::string_view const text) override
1276+
{
1277+
Paragraph::operator=(text);
1278+
return *this;
1279+
}
1280+
12311281
auto operator<=>(Param const&) const = default;
12321282

12331283
bool operator==(Param const&)
@@ -1279,6 +1329,27 @@ struct Returns final : Paragraph
12791329
{
12801330
}
12811331

1332+
explicit
1333+
Returns(std::string_view const text)
1334+
: Returns()
1335+
{
1336+
operator=(text);
1337+
}
1338+
1339+
explicit
1340+
Returns(Paragraph const& other)
1341+
: Returns()
1342+
{
1343+
children = other.children;
1344+
}
1345+
1346+
Returns&
1347+
operator=(std::string_view const text) override
1348+
{
1349+
Paragraph::operator=(text);
1350+
return *this;
1351+
}
1352+
12821353
auto operator<=>(Returns const&) const = default;
12831354

12841355
bool operator==(Returns const&)
@@ -1330,6 +1401,8 @@ struct TParam final : Paragraph
13301401
{
13311402
}
13321403

1404+
using Paragraph::operator=;
1405+
13331406
auto operator<=>(TParam const&) const = default;
13341407
bool operator==(TParam const&) const noexcept = default;
13351408
bool equals(Node const& other) const noexcept override
@@ -1384,6 +1457,8 @@ struct Throws final : Paragraph
13841457
{
13851458
}
13861459

1460+
using Paragraph::operator=;
1461+
13871462
auto operator<=>(Throws const&) const = default;
13881463

13891464
bool operator==(Throws const&)
@@ -1435,6 +1510,8 @@ struct Precondition final : Paragraph
14351510
{
14361511
}
14371512

1513+
using Paragraph::operator=;
1514+
14381515
auto operator<=>(Precondition const&) const = default;
14391516

14401517
bool operator==(Precondition const&)
@@ -1485,6 +1562,8 @@ struct Postcondition : Paragraph
14851562
{
14861563
}
14871564

1565+
using Paragraph::operator=;
1566+
14881567
auto operator<=>(Postcondition const&) const = default;
14891568

14901569
bool operator==(Postcondition const&)
@@ -1561,8 +1640,8 @@ visit(
15611640
return visitor.template visit<Link>();
15621641
case NodeKind::reference:
15631642
return visitor.template visit<Reference>();
1564-
case NodeKind::copied:
1565-
return visitor.template visit<Copied>();
1643+
case NodeKind::copy_details:
1644+
return visitor.template visit<CopyDetails>();
15661645
case NodeKind::list_item:
15671646
return visitor.template visit<ListItem>();
15681647
case NodeKind::unordered_list:
@@ -1698,14 +1777,6 @@ struct MRDOCS_DECL
16981777
postconditions.empty();
16991778
}
17001779

1701-
/** Return the brief, or nullptr if there is none.
1702-
*/
1703-
doc::Paragraph const*
1704-
getBrief(Corpus const& corpus) const noexcept;
1705-
1706-
std::vector<Polymorphic<doc::Block>> const&
1707-
getDescription(Corpus const& corpus) const noexcept;
1708-
17091780
/** Return the list of top level blocks.
17101781
*/
17111782
std::vector<Polymorphic<doc::Block>> const&

include/mrdocs/Metadata/Specifiers.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@ tag_invoke(
180180
v = static_cast<std::underlying_type_t<OperatorKind>>(kind);
181181
}
182182

183+
/** Determines whether the operator is potentially unary.
184+
*/
185+
MRDOCS_DECL
186+
bool
187+
isUnaryOperator(OperatorKind kind) noexcept;
188+
189+
/** Determines whether the operator is potentially binary.
190+
*/
191+
MRDOCS_DECL
192+
bool
193+
isBinaryOperator(OperatorKind kind) noexcept;
194+
183195
/** Reference type kinds
184196
*/
185197
enum class ReferenceKind

include/mrdocs/Support/Algorithm.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace clang::mrdocs {
2525
template <std::ranges::range Range, class El>
2626
requires std::equality_comparable_with<El, std::ranges::range_value_t<Range>>
2727
bool
28-
contains(Range const& range, El const& el)
28+
contains(Range&& range, El const& el)
2929
{
3030
return std::find(
3131
std::ranges::begin(range),

src/lib/AST/ParseJavadoc.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,10 +992,30 @@ visitInlineCommandComment(
992992
std::string ref = C->getArgText(0).str();
993993
std::string leftOver = fixReference(ref);
994994
bool const hasExtra = !leftOver.empty();
995-
emplaceText<doc::Copied>(
996-
C->hasTrailingNewline() && !hasExtra,
997-
ref,
998-
convertCopydoc(ID));
995+
doc::Parts const parts = convertCopydoc(ID);
996+
bool const copyBrief = parts == doc::Parts::brief || parts == doc::Parts::all;
997+
bool const copyDetails = parts == doc::Parts::description || parts == doc::Parts::all;
998+
MRDOCS_ASSERT(copyBrief || copyDetails);
999+
if (copyBrief)
1000+
{
1001+
// The brief is metadata associated with the javadoc
1002+
if (!jd_.brief)
1003+
{
1004+
jd_.brief.emplace();
1005+
}
1006+
if (!contains(jd_.brief->copiedFrom, ref))
1007+
{
1008+
jd_.brief->copiedFrom.emplace_back(ref);
1009+
}
1010+
}
1011+
if (copyDetails)
1012+
{
1013+
// The details are in the main body of the javadoc
1014+
// and are replaced at the same position as the command
1015+
emplaceText<doc::CopyDetails>(
1016+
C->hasTrailingNewline() && !hasExtra,
1017+
ref);
1018+
}
9991019
if (hasExtra)
10001020
{
10011021
emplaceText<doc::Text>(

src/lib/AST/ParseRef.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,9 @@ class RefParser
854854
bool
855855
parseDeclarationSpecifiers(Polymorphic<TypeInfo>& dest)
856856
{
857-
static constexpr std::string_view typeQualifiers[] = {
858-
"const", "volatile"
859-
};
857+
//static constexpr std::string_view typeQualifiers[] = {
858+
// "const", "volatile"
859+
//};
860860
static constexpr std::string_view typeModifiers[] = {
861861
"long", "short", "signed", "unsigned"
862862
};

0 commit comments

Comments
 (0)