Skip to content

auto-function-metadata option #889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/mrdocs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
"title": "Use the first line of the comment as the brief",
"type": "boolean"
},
"auto-function-metadata": {
"default": true,
"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.",
"enum": [
true,
false
],
"title": "Automatically provide missing documentation for special functions and trivial metadata",
"type": "boolean"
},
"auto-relates": {
"default": true,
"description": "When set to `true`, MrDocs automatically finds non-member functions that are related to the current class.",
Expand Down
7 changes: 7 additions & 0 deletions include/mrdocs/Metadata/Info/Function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ getSafeOperatorName(
OperatorKind kind,
bool include_keyword = false) noexcept;

/** Return the human-readable name of the operator
*/
std::optional<std::string_view>
getOperatorReadableName(
OperatorKind kind,
int nParams);

/** Function classifications */
enum class FunctionClass
{
Expand Down
133 changes: 102 additions & 31 deletions include/mrdocs/Metadata/Javadoc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
styled,
tparam,
reference,
copied,
copy_details,
throws,
details,
see,
Expand Down Expand Up @@ -373,7 +373,8 @@
{
}

bool isBlock() const noexcept final
bool
isBlock() const noexcept final
{
return false;
}
Expand Down Expand Up @@ -600,26 +601,21 @@

/** Documentation copied from another symbol.
*/
struct Copied final : Reference
struct CopyDetails final : Reference
{
Parts parts;
static constexpr auto static_kind = NodeKind::copy_details;

static constexpr auto static_kind = NodeKind::copied;

Copied(
std::string string_ = std::string(),
Parts parts_ = Parts::all) noexcept
: Reference(std::move(string_), NodeKind::copied)
, parts(parts_)
CopyDetails(std::string string_ = std::string()) noexcept
: Reference(std::move(string_), NodeKind::copy_details)
{
}

auto operator<=>(Copied const&) const = default;
bool operator==(Copied const&) const noexcept = default;
auto operator<=>(CopyDetails const&) const = default;
bool operator==(CopyDetails const&) const noexcept = default;
bool equals(Node const& other) const noexcept override
{
return Kind == other.Kind &&
*this == dynamic_cast<Copied const&>(other);
*this == dynamic_cast<CopyDetails const&>(other);
}
};

Expand All @@ -630,11 +626,10 @@
tag_invoke(
dom::LazyObjectMapTag t,
IO& io,
Copied const& I,
CopyDetails const& I,
DomCorpus const* domCorpus)
{
tag_invoke(t, io, dynamic_cast<Reference const&>(I), domCorpus);
io.map("parts", I.parts);
}

/** Return the @ref Copied as a @ref dom::Value object.
Expand All @@ -644,7 +639,7 @@
tag_invoke(
dom::ValueFromTag,
dom::Value& v,
Copied const& I,
CopyDetails const& I,
DomCorpus const* domCorpus)
{
v = dom::LazyObject(I, domCorpus);
Expand Down Expand Up @@ -825,10 +820,11 @@
{
static constexpr auto static_kind = NodeKind::paragraph;

Paragraph() noexcept
: Block(NodeKind::paragraph)
{
}
Paragraph() noexcept : Block(NodeKind::paragraph) {}

virtual
Paragraph&
operator=(std::string_view str);

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

Expand Down Expand Up @@ -881,11 +877,30 @@
{
static constexpr NodeKind static_kind = NodeKind::brief;

std::vector<std::string> copiedFrom;

Brief() noexcept
: Paragraph(NodeKind::brief)
{
}

explicit
Brief(std::string_view const text)
: Brief()
{
operator=(text);
}

Brief&
operator=(Brief const& other) = default;

Check warning on line 895 in include/mrdocs/Metadata/Javadoc.hpp

View workflow job for this annotation

GitHub Actions / Apple-Clang

Build Warning - clang++ - [-Wdeprecated-copy]

clang++ - definition of implicit copy constructor for 'Brief' is deprecated because it has a user-declared copy assignment operator ([-Wdeprecated-copy])

Check warning on line 895 in include/mrdocs/Metadata/Javadoc.hpp

View workflow job for this annotation

GitHub Actions / Apple-Clang

Build Warning - clang++ - [-Wdeprecated-copy]

clang++ - definition of implicit copy constructor for 'Brief' is deprecated because it has a user-declared copy assignment operator ([-Wdeprecated-copy])

Check warning on line 895 in include/mrdocs/Metadata/Javadoc.hpp

View workflow job for this annotation

GitHub Actions / Apple-Clang

Build Warning - clang++ - [-Wdeprecated-copy]

clang++ - definition of implicit copy constructor for 'Brief' is deprecated because it has a user-declared copy assignment operator ([-Wdeprecated-copy])

Check warning on line 895 in include/mrdocs/Metadata/Javadoc.hpp

View workflow job for this annotation

GitHub Actions / Apple-Clang

Build Warning - clang++ - [-Wdeprecated-copy]

clang++ - definition of implicit copy constructor for 'Brief' is deprecated because it has a user-declared copy assignment operator ([-Wdeprecated-copy])

Check warning on line 895 in include/mrdocs/Metadata/Javadoc.hpp

View workflow job for this annotation

GitHub Actions / Apple-Clang

Build Warning - clang++ - [-Wdeprecated-copy]

clang++ - definition of implicit copy constructor for 'Brief' is deprecated because it has a user-declared copy assignment operator ([-Wdeprecated-copy])

Check warning on line 895 in include/mrdocs/Metadata/Javadoc.hpp

View workflow job for this annotation

GitHub Actions / Clang 18: C++20

Build Warning - clang++-18 - [-Wdeprecated-copy]

clang++-18 - definition of implicit copy constructor for 'Brief' is deprecated because it has a user-declared copy assignment operator ([-Wdeprecated-copy])

Check warning on line 895 in include/mrdocs/Metadata/Javadoc.hpp

View workflow job for this annotation

GitHub Actions / Clang 18: C++20

Build Warning - clang++-18 - [-Wdeprecated-copy]

clang++-18 - definition of implicit copy constructor for 'Brief' is deprecated because it has a user-declared copy assignment operator ([-Wdeprecated-copy])

Check warning on line 895 in include/mrdocs/Metadata/Javadoc.hpp

View workflow job for this annotation

GitHub Actions / Clang 18: C++20

Build Warning - clang++-18 - [-Wdeprecated-copy]

clang++-18 - definition of implicit copy constructor for 'Brief' is deprecated because it has a user-declared copy assignment operator ([-Wdeprecated-copy])

Check warning on line 895 in include/mrdocs/Metadata/Javadoc.hpp

View workflow job for this annotation

GitHub Actions / Clang 18: C++20

Build Warning - clang++-18 - [-Wdeprecated-copy]

clang++-18 - definition of implicit copy constructor for 'Brief' is deprecated because it has a user-declared copy assignment operator ([-Wdeprecated-copy])

Check warning on line 895 in include/mrdocs/Metadata/Javadoc.hpp

View workflow job for this annotation

GitHub Actions / Clang 18: C++20

Build Warning - clang++-18 - [-Wdeprecated-copy]

clang++-18 - definition of implicit copy constructor for 'Brief' is deprecated because it has a user-declared copy assignment operator ([-Wdeprecated-copy])

Brief&
operator=(std::string_view const text) override
{
Paragraph::operator=(text);
return *this;
}

auto operator<=>(Brief const&) const = default;

bool equals(Node const& other) const noexcept override
Expand Down Expand Up @@ -939,8 +954,12 @@
{
}

using Paragraph::operator=;

auto operator<=>(Admonition const&) const = default;

bool operator==(Admonition const&) const noexcept = default;

bool equals(Node const& other) const noexcept override
{
return Kind == other.Kind &&
Expand Down Expand Up @@ -989,6 +1008,7 @@
{
}

using Paragraph::operator=;
auto operator<=>(Code const&) const = default;
bool operator==(Code const&) const noexcept = default;
bool equals(Node const& other) const noexcept override
Expand Down Expand Up @@ -1034,6 +1054,8 @@
: Paragraph(static_kind)
{}

using Paragraph::operator=;

auto operator<=>(ListItem const&) const = default;
bool
operator==(ListItem const&) const noexcept = default;
Expand Down Expand Up @@ -1093,6 +1115,8 @@
{
}

using Paragraph::operator=;

auto operator<=>(UnorderedList const& other) const {
if (auto const cmp = items.size() <=> other.items.size();
!std::is_eq(cmp))
Expand Down Expand Up @@ -1169,6 +1193,8 @@
{
}

using Paragraph::operator=;

auto operator<=>(See const&) const = default;

bool operator==(See const&)
Expand Down Expand Up @@ -1228,6 +1254,30 @@
{
}

explicit
Param(
std::string_view const name,
std::string_view const text)
: Param()
{
this->name = name;
this->operator=(text);
}

explicit
Param(Paragraph const& other)
: Param()
{
children = other.children;
}

Param&
operator=(std::string_view const text) override
{
Paragraph::operator=(text);
return *this;
}

auto operator<=>(Param const&) const = default;

bool operator==(Param const&)
Expand Down Expand Up @@ -1279,6 +1329,27 @@
{
}

explicit
Returns(std::string_view const text)
: Returns()
{
operator=(text);
}

explicit
Returns(Paragraph const& other)
: Returns()
{
children = other.children;
}

Returns&
operator=(std::string_view const text) override
{
Paragraph::operator=(text);
return *this;
}

auto operator<=>(Returns const&) const = default;

bool operator==(Returns const&)
Expand Down Expand Up @@ -1330,6 +1401,8 @@
{
}

using Paragraph::operator=;

auto operator<=>(TParam const&) const = default;
bool operator==(TParam const&) const noexcept = default;
bool equals(Node const& other) const noexcept override
Expand Down Expand Up @@ -1384,6 +1457,8 @@
{
}

using Paragraph::operator=;

auto operator<=>(Throws const&) const = default;

bool operator==(Throws const&)
Expand Down Expand Up @@ -1435,6 +1510,8 @@
{
}

using Paragraph::operator=;

auto operator<=>(Precondition const&) const = default;

bool operator==(Precondition const&)
Expand Down Expand Up @@ -1485,6 +1562,8 @@
{
}

using Paragraph::operator=;

auto operator<=>(Postcondition const&) const = default;

bool operator==(Postcondition const&)
Expand Down Expand Up @@ -1561,8 +1640,8 @@
return visitor.template visit<Link>();
case NodeKind::reference:
return visitor.template visit<Reference>();
case NodeKind::copied:
return visitor.template visit<Copied>();
case NodeKind::copy_details:
return visitor.template visit<CopyDetails>();
case NodeKind::list_item:
return visitor.template visit<ListItem>();
case NodeKind::unordered_list:
Expand Down Expand Up @@ -1698,14 +1777,6 @@
postconditions.empty();
}

/** Return the brief, or nullptr if there is none.
*/
doc::Paragraph const*
getBrief(Corpus const& corpus) const noexcept;

std::vector<Polymorphic<doc::Block>> const&
getDescription(Corpus const& corpus) const noexcept;

/** Return the list of top level blocks.
*/
std::vector<Polymorphic<doc::Block>> const&
Expand Down
12 changes: 12 additions & 0 deletions include/mrdocs/Metadata/Specifiers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ tag_invoke(
v = static_cast<std::underlying_type_t<OperatorKind>>(kind);
}

/** Determines whether the operator is potentially unary.
*/
MRDOCS_DECL
bool
isUnaryOperator(OperatorKind kind) noexcept;

/** Determines whether the operator is potentially binary.
*/
MRDOCS_DECL
bool
isBinaryOperator(OperatorKind kind) noexcept;

/** Reference type kinds
*/
enum class ReferenceKind
Expand Down
2 changes: 1 addition & 1 deletion include/mrdocs/Support/Algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace clang::mrdocs {
template <std::ranges::range Range, class El>
requires std::equality_comparable_with<El, std::ranges::range_value_t<Range>>
bool
contains(Range const& range, El const& el)
contains(Range&& range, El const& el)
{
return std::find(
std::ranges::begin(range),
Expand Down
28 changes: 24 additions & 4 deletions src/lib/AST/ParseJavadoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,10 +992,30 @@ visitInlineCommandComment(
std::string ref = C->getArgText(0).str();
std::string leftOver = fixReference(ref);
bool const hasExtra = !leftOver.empty();
emplaceText<doc::Copied>(
C->hasTrailingNewline() && !hasExtra,
ref,
convertCopydoc(ID));
doc::Parts const parts = convertCopydoc(ID);
bool const copyBrief = parts == doc::Parts::brief || parts == doc::Parts::all;
bool const copyDetails = parts == doc::Parts::description || parts == doc::Parts::all;
MRDOCS_ASSERT(copyBrief || copyDetails);
if (copyBrief)
{
// The brief is metadata associated with the javadoc
if (!jd_.brief)
{
jd_.brief.emplace();
}
if (!contains(jd_.brief->copiedFrom, ref))
{
jd_.brief->copiedFrom.emplace_back(ref);
}
}
if (copyDetails)
{
// The details are in the main body of the javadoc
// and are replaced at the same position as the command
emplaceText<doc::CopyDetails>(
C->hasTrailingNewline() && !hasExtra,
ref);
}
if (hasExtra)
{
emplaceText<doc::Text>(
Expand Down
6 changes: 3 additions & 3 deletions src/lib/AST/ParseRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,9 @@ class RefParser
bool
parseDeclarationSpecifiers(Polymorphic<TypeInfo>& dest)
{
static constexpr std::string_view typeQualifiers[] = {
"const", "volatile"
};
//static constexpr std::string_view typeQualifiers[] = {
// "const", "volatile"
//};
static constexpr std::string_view typeModifiers[] = {
"long", "short", "signed", "unsigned"
};
Expand Down
Loading