Skip to content
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
4 changes: 4 additions & 0 deletions include/mrdocs/Metadata/Info/Function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ struct Param final
operator<=>(Param const&) const = default;
};

MRDOCS_DECL
void
merge(Param& I, Param&& Other);

/** Return the Param as a @ref dom::Value object.
*/
MRDOCS_DECL
Expand Down
4 changes: 4 additions & 0 deletions include/mrdocs/Metadata/Template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ struct TemplateInfo
operator<=>(TemplateInfo const& other) const;
};

MRDOCS_DECL
void
merge(TemplateInfo& I, TemplateInfo&& Other);

inline
auto
operator<=>(std::optional<TemplateInfo> const& lhs, std::optional<TemplateInfo> const& rhs)
Expand Down
5 changes: 2 additions & 3 deletions src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ populate(
MRDOCS_SYMBOL_TRACE(P, context_);
Param& param = I.Params[i];

if (!param.Name)
if (!param.Name && !P->getName().empty())
{
param.Name = P->getName();
}
Expand All @@ -804,8 +804,7 @@ populate(

Expr const* default_arg = P->hasUninstantiatedDefaultArg() ?
P->getUninstantiatedDefaultArg() : P->getInit();
if (!param.Default &&
default_arg)
if (!param.Default && default_arg)
{
param.Default = getSourceCode(default_arg->getSourceRange());
param.Default = trim(*param.Default);
Expand Down
8 changes: 6 additions & 2 deletions src/lib/Metadata/Info/Concept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ merge(ConceptInfo& I, ConceptInfo&& Other)
{
MRDOCS_ASSERT(canMerge(I, Other));
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
if(I.Constraint.Written.empty())
if (I.Constraint.Written.empty())
{
I.Constraint = std::move(Other.Constraint);
if (! I.Template)
}
if (!I.Template)
{
I.Template = std::move(Other.Template);
}
}

} // clang::mrdocs
Expand Down
8 changes: 6 additions & 2 deletions src/lib/Metadata/Info/Enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ merge(EnumInfo& I, EnumInfo&& Other)
{
MRDOCS_ASSERT(canMerge(I, Other));
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
if(! I.Scoped)
if (!I.Scoped)
{
I.Scoped = Other.Scoped;
if (! I.UnderlyingType)
}
if (!I.UnderlyingType)
{
I.UnderlyingType = std::move(Other.UnderlyingType);
}
reduceSymbolIDs(I.Constants, std::move(Other.Constants));
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib/Metadata/Info/EnumConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ merge(EnumConstantInfo& I, EnumConstantInfo&& Other)
{
MRDOCS_ASSERT(canMerge(I, Other));
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
if(I.Initializer.Written.empty())
if (I.Initializer.Written.empty())
{
I.Initializer = std::move(Other.Initializer);
}
}

} // clang::mrdocs
Expand Down
8 changes: 6 additions & 2 deletions src/lib/Metadata/Info/Field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ merge(FieldInfo& I, FieldInfo&& Other)
{
MRDOCS_ASSERT(canMerge(I, Other));
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
if(! I.Type)
if (!I.Type)
{
I.Type = std::move(Other.Type);
if(I.Default.Written.empty())
}
if (I.Default.Written.empty())
{
I.Default = std::move(Other.Default);
}
I.IsBitfield |= Other.IsBitfield;
merge(I.BitfieldWidth, std::move(Other.BitfieldWidth));
I.IsVariant |= Other.IsVariant;
Expand Down
8 changes: 6 additions & 2 deletions src/lib/Metadata/Info/Friend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ merge(FriendInfo& I, FriendInfo&& Other)
{
MRDOCS_ASSERT(canMerge(I, Other));
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
if(! I.FriendSymbol)
if (!I.FriendSymbol)
{
I.FriendSymbol = Other.FriendSymbol;
if(! I.FriendType)
}
if (!I.FriendType)
{
I.FriendType = std::move(Other.FriendType);
}
}

} // clang::mrdocs
Expand Down
33 changes: 31 additions & 2 deletions src/lib/Metadata/Info/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,23 @@ toString(
}
}

void
merge(Param& I, Param&& Other)
{
if (!I.Type)
{
I.Type = std::move(Other.Type);
}
if (!I.Name)
{
I.Name = std::move(Other.Name);
}
if (!I.Default)
{
I.Default = std::move(Other.Default);
}
}

template <class IO>
void
tag_invoke(
Expand Down Expand Up @@ -276,14 +293,26 @@ merge(FunctionInfo& I, FunctionInfo&& Other)
{
I.ReturnType = std::move(Other.ReturnType);
}
if (I.Params.empty())
std::size_t const n = std::min(I.Params.size(), Other.Params.size());
for (std::size_t i = 0; i < n; ++i)
{
I.Params = std::move(Other.Params);
merge(I.Params[i], std::move(Other.Params[i]));
}
if (Other.Params.size() > n)
{
I.Params.insert(
I.Params.end(),
std::make_move_iterator(Other.Params.begin() + n),
std::make_move_iterator(Other.Params.end()));
}
if (!I.Template)
{
I.Template = std::move(Other.Template);
}
else if (Other.Template)
{
merge(*I.Template, std::move(*Other.Template));
}
if (I.Noexcept.Implicit)
{
I.Noexcept = std::move(Other.Noexcept);
Expand Down
4 changes: 3 additions & 1 deletion src/lib/Metadata/Info/NamespaceAlias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ merge(NamespaceAliasInfo& I, NamespaceAliasInfo&& Other)
{
MRDOCS_ASSERT(canMerge(I, Other));
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
if (! I.AliasedSymbol)
if (!I.AliasedSymbol)
{
I.AliasedSymbol = std::move(Other.AliasedSymbol);
}
}

} // clang::mrdocs
Expand Down
4 changes: 3 additions & 1 deletion src/lib/Metadata/Info/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ merge(RecordInfo& I, RecordInfo&& Other)
I.Bases = std::move(Other.Bases);
}
merge(I.Interface, std::move(Other.Interface));
if (! I.Template)
if (!I.Template)
{
I.Template = std::move(Other.Template);
}
}

template <class IO>
Expand Down
8 changes: 6 additions & 2 deletions src/lib/Metadata/Info/Specialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ merge(SpecializationInfo& I, SpecializationInfo&& Other)
{
MRDOCS_ASSERT(canMerge(I, Other));
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
if(! I.Primary)
if (!I.Primary)
{
I.Primary = Other.Primary;
if(I.Args.empty())
}
if (I.Args.empty())
{
I.Args = std::move(Other.Args);
}
}

} // clang::mrdocs
Expand Down
10 changes: 8 additions & 2 deletions src/lib/Metadata/Info/Typedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ void merge(TypedefInfo& I, TypedefInfo&& Other)
MRDOCS_ASSERT(canMerge(I, Other));
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
if (!I.IsUsing)
{
I.IsUsing = Other.IsUsing;
if (! I.Type)
}
if (!I.Type)
{
I.Type = std::move(Other.Type);
if(! I.Template)
}
if (!I.Template)
{
I.Template = std::move(Other.Template);
}
}

} // clang::mrdocs
Expand Down
6 changes: 5 additions & 1 deletion src/lib/Metadata/Info/Using.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ merge(UsingInfo& I, UsingInfo&& Other)
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
reduceSymbolIDs(I.UsingSymbols, std::move(Other.UsingSymbols));
if (I.Class == UsingClass::Normal)
{
I.Class = Other.Class;
if (! I.Qualifier)
}
if (!I.Qualifier)
{
I.Qualifier = std::move(Other.Qualifier);
}
}

} // clang::mrdocs
Expand Down
12 changes: 9 additions & 3 deletions src/lib/Metadata/Info/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,18 @@ merge(VariableInfo& I, VariableInfo&& Other)
{
MRDOCS_ASSERT(canMerge(I, Other));
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
if(! I.Type)
if (!I.Type)
{
I.Type = std::move(Other.Type);
if(! I.Template)
}
if (!I.Template)
{
I.Template = std::move(Other.Template);
if(I.Initializer.Written.empty())
}
if (I.Initializer.Written.empty())
{
I.Initializer = std::move(Other.Initializer);
}
I.IsConstinit |= Other.IsConstinit;
I.IsThreadLocal |= Other.IsThreadLocal;
I.IsConstexpr |= Other.IsConstexpr;
Expand Down
57 changes: 57 additions & 0 deletions src/lib/Metadata/Template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,63 @@ operator<=>(TemplateInfo const& other) const {
std::tie(Args, Params, other.Requires, other.Primary);
}

void
merge(TemplateInfo& I, TemplateInfo&& Other)
{
std::size_t const pn = std::min(I.Params.size(), Other.Params.size());
for (std::size_t i = 0; i < pn; ++i)
{
if (!I.Params[i] || I.Params[i]->Kind != Other.Params[i]->Kind)
{
I.Params[i] = std::move(Other.Params[i]);
}
else
{
if (I.Params[i]->Name.empty())
{
I.Params[i]->Name = std::move(Other.Params[i]->Name);
}
if (!I.Params[i]->Default)
{
I.Params[i]->Default = std::move(Other.Params[i]->Default);
}
}
}
if (Other.Params.size() > pn)
{
I.Params.insert(
I.Params.end(),
std::make_move_iterator(Other.Params.begin() + pn),
std::make_move_iterator(Other.Params.end()));
}

std::size_t const an = std::min(I.Args.size(), Other.Args.size());
for (std::size_t i = 0; i < an; ++i)
{
if (!I.Args[i] || I.Args[i]->Kind != Other.Args[i]->Kind)
{
I.Args[i] = std::move(Other.Args[i]);
}
}
if (Other.Args.size() > an)
{
I.Args.insert(
I.Args.end(),
std::make_move_iterator(Other.Args.begin() + an),
std::make_move_iterator(Other.Args.end()));
}

if (I.Requires.Written.empty())
{
I.Requires = std::move(Other.Requires);
}

if (I.Primary == SymbolID::invalid)
{
I.Primary = Other.Primary;
}
}

template <class IO>
void
tag_invoke(
Expand Down
55 changes: 55 additions & 0 deletions test-files/golden-tests/symbols/function/merge-params.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
= Reference
:mrdocs:

[#index]
== Global namespace


=== Functions

[cols=2]
|===
| Name
| Description

| <<f,`f`>>
| Function

|===

[#f]
== f


Function

=== Synopsis


Declared in `&lt;merge&hyphen;params&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
f(
int a,
int b);
----

=== Parameters


|===
| Name | Description

| *a*
| The first parameter&period;

| *b*
| The second parameter&period;

|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
Loading
Loading