Skip to content

Commit c9285ec

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

File tree

113 files changed

+14115
-2259
lines changed

Some content is hidden

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

113 files changed

+14115
-2259
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: 82 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-
607-
static constexpr auto static_kind = NodeKind::copied;
606+
static constexpr auto static_kind = NodeKind::copy_details;
608607

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,10 @@ 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 Paragraph&
826+
operator=(std::string_view str);
832827

833828
auto operator<=>(Paragraph const&) const = default;
834829

@@ -881,11 +876,30 @@ struct Brief final : Paragraph
881876
{
882877
static constexpr NodeKind static_kind = NodeKind::brief;
883878

879+
std::vector<std::string> copiedFrom;
880+
884881
Brief() noexcept
885882
: Paragraph(NodeKind::brief)
886883
{
887884
}
888885

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

891905
bool equals(Node const& other) const noexcept override
@@ -1228,6 +1242,30 @@ struct Param final : Paragraph
12281242
{
12291243
}
12301244

1245+
explicit
1246+
Param(
1247+
std::string_view const name,
1248+
std::string_view const text)
1249+
: Param()
1250+
{
1251+
this->name = name;
1252+
this->operator=(text);
1253+
}
1254+
1255+
explicit
1256+
Param(Paragraph const& other)
1257+
: Param()
1258+
{
1259+
children = other.children;
1260+
}
1261+
1262+
Param&
1263+
operator=(std::string_view const text) override
1264+
{
1265+
Paragraph::operator=(text);
1266+
return *this;
1267+
}
1268+
12311269
auto operator<=>(Param const&) const = default;
12321270

12331271
bool operator==(Param const&)
@@ -1279,6 +1317,27 @@ struct Returns final : Paragraph
12791317
{
12801318
}
12811319

1320+
explicit
1321+
Returns(std::string_view const text)
1322+
: Returns()
1323+
{
1324+
operator=(text);
1325+
}
1326+
1327+
explicit
1328+
Returns(Paragraph const& other)
1329+
: Returns()
1330+
{
1331+
children = other.children;
1332+
}
1333+
1334+
Returns&
1335+
operator=(std::string_view const text) override
1336+
{
1337+
Paragraph::operator=(text);
1338+
return *this;
1339+
}
1340+
12821341
auto operator<=>(Returns const&) const = default;
12831342

12841343
bool operator==(Returns const&)
@@ -1561,8 +1620,8 @@ visit(
15611620
return visitor.template visit<Link>();
15621621
case NodeKind::reference:
15631622
return visitor.template visit<Reference>();
1564-
case NodeKind::copied:
1565-
return visitor.template visit<Copied>();
1623+
case NodeKind::copy_details:
1624+
return visitor.template visit<CopyDetails>();
15661625
case NodeKind::list_item:
15671626
return visitor.template visit<ListItem>();
15681627
case NodeKind::unordered_list:
@@ -1698,14 +1757,6 @@ struct MRDOCS_DECL
16981757
postconditions.empty();
16991758
}
17001759

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-
17091760
/** Return the list of top level blocks.
17101761
*/
17111762
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/Gen/xml/XMLWriter.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,8 @@ writeNode(doc::Node const& node)
797797
case doc::NodeKind::reference:
798798
writeReference(dynamic_cast<doc::Reference const&>(node));
799799
break;
800-
case doc::NodeKind::copied:
801-
writeCopied(dynamic_cast<doc::Copied const&>(node));
800+
case doc::NodeKind::copy_details:
801+
writeCopied(dynamic_cast<doc::CopyDetails const&>(node));
802802
break;
803803
case doc::NodeKind::throws:
804804
writeThrows(dynamic_cast<doc::Throws const&>(node));
@@ -831,23 +831,9 @@ writeReference(
831831
void
832832
XMLWriter::
833833
writeCopied(
834-
doc::Copied const& node)
834+
doc::CopyDetails const& node)
835835
{
836-
std::string_view tag_name;
837-
switch(node.parts)
838-
{
839-
case doc::Parts::all:
840-
tag_name = "copydoc";
841-
break;
842-
case doc::Parts::brief:
843-
tag_name = "copybrief";
844-
break;
845-
case doc::Parts::description:
846-
tag_name = "copydetails";
847-
break;
848-
default:
849-
MRDOCS_UNREACHABLE();
850-
}
836+
std::string_view const tag_name = "copydetails";
851837
tags_.write(tag_name, node.string, {
852838
{ node.id }
853839
});

src/lib/Gen/xml/XMLWriter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class XMLWriter
8888
void writeText(doc::Text const& node);
8989
void writeTParam(doc::TParam const& node);
9090
void writeReference(doc::Reference const& node);
91-
void writeCopied(doc::Copied const& node);
91+
void writeCopied(doc::CopyDetails const& node);
9292
void writeThrows(doc::Throws const& node);
9393
void writeSee(doc::See const& node, llvm::StringRef tag = "");
9494
void writePrecondition(doc::Precondition const& node);

src/lib/Lib/ConfigOptions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@
177177
"details": "When set to `true`, MrDocs automatically finds non-member functions that are related to the current class.",
178178
"type": "bool",
179179
"default": true
180+
},
181+
{
182+
"name": "auto-function-metadata",
183+
"brief": "Automatically provide missing documentation for special functions and trivial metadata",
184+
"details": "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.",
185+
"type": "bool",
186+
"default": true
180187
}
181188
]
182189
},

0 commit comments

Comments
 (0)