Skip to content

Commit 3497b03

Browse files
committed
merge function parameter names from multiple declarations
#feat
1 parent 8fe596e commit 3497b03

24 files changed

+514
-24
lines changed

include/mrdocs/Metadata/Info/Function.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ struct Param final
127127
operator<=>(Param const&) const = default;
128128
};
129129

130+
MRDOCS_DECL
131+
void
132+
merge(Param& I, Param&& Other);
133+
130134
/** Return the Param as a @ref dom::Value object.
131135
*/
132136
MRDOCS_DECL

include/mrdocs/Metadata/Template.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ struct TemplateInfo
412412
operator<=>(TemplateInfo const& other) const;
413413
};
414414

415+
MRDOCS_DECL
416+
void
417+
merge(TemplateInfo& I, TemplateInfo&& Other);
418+
415419
inline
416420
auto
417421
operator<=>(std::optional<TemplateInfo> const& lhs, std::optional<TemplateInfo> const& rhs)

src/lib/AST/ASTVisitor.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ populate(
792792
MRDOCS_SYMBOL_TRACE(P, context_);
793793
Param& param = I.Params[i];
794794

795-
if (!param.Name)
795+
if (!param.Name && !P->getName().empty())
796796
{
797797
param.Name = P->getName();
798798
}
@@ -804,8 +804,7 @@ populate(
804804

805805
Expr const* default_arg = P->hasUninstantiatedDefaultArg() ?
806806
P->getUninstantiatedDefaultArg() : P->getInit();
807-
if (!param.Default &&
808-
default_arg)
807+
if (!param.Default && default_arg)
809808
{
810809
param.Default = getSourceCode(default_arg->getSourceRange());
811810
param.Default = trim(*param.Default);

src/lib/Metadata/Info/Concept.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ merge(ConceptInfo& I, ConceptInfo&& Other)
6363
{
6464
MRDOCS_ASSERT(canMerge(I, Other));
6565
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
66-
if(I.Constraint.Written.empty())
66+
if (I.Constraint.Written.empty())
67+
{
6768
I.Constraint = std::move(Other.Constraint);
68-
if (! I.Template)
69+
}
70+
if (!I.Template)
71+
{
6972
I.Template = std::move(Other.Template);
73+
}
7074
}
7175

7276
} // clang::mrdocs

src/lib/Metadata/Info/Enum.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ merge(EnumInfo& I, EnumInfo&& Other)
3939
{
4040
MRDOCS_ASSERT(canMerge(I, Other));
4141
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
42-
if(! I.Scoped)
42+
if (!I.Scoped)
43+
{
4344
I.Scoped = Other.Scoped;
44-
if (! I.UnderlyingType)
45+
}
46+
if (!I.UnderlyingType)
47+
{
4548
I.UnderlyingType = std::move(Other.UnderlyingType);
49+
}
4650
reduceSymbolIDs(I.Constants, std::move(Other.Constants));
4751
}
4852

src/lib/Metadata/Info/EnumConstant.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ merge(EnumConstantInfo& I, EnumConstantInfo&& Other)
2020
{
2121
MRDOCS_ASSERT(canMerge(I, Other));
2222
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
23-
if(I.Initializer.Written.empty())
23+
if (I.Initializer.Written.empty())
24+
{
2425
I.Initializer = std::move(Other.Initializer);
26+
}
2527
}
2628

2729
} // clang::mrdocs

src/lib/Metadata/Info/Field.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ merge(FieldInfo& I, FieldInfo&& Other)
2020
{
2121
MRDOCS_ASSERT(canMerge(I, Other));
2222
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
23-
if(! I.Type)
23+
if (!I.Type)
24+
{
2425
I.Type = std::move(Other.Type);
25-
if(I.Default.Written.empty())
26+
}
27+
if (I.Default.Written.empty())
28+
{
2629
I.Default = std::move(Other.Default);
30+
}
2731
I.IsBitfield |= Other.IsBitfield;
2832
merge(I.BitfieldWidth, std::move(Other.BitfieldWidth));
2933
I.IsVariant |= Other.IsVariant;

src/lib/Metadata/Info/Friend.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ merge(FriendInfo& I, FriendInfo&& Other)
2020
{
2121
MRDOCS_ASSERT(canMerge(I, Other));
2222
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
23-
if(! I.FriendSymbol)
23+
if (!I.FriendSymbol)
24+
{
2425
I.FriendSymbol = Other.FriendSymbol;
25-
if(! I.FriendType)
26+
}
27+
if (!I.FriendType)
28+
{
2629
I.FriendType = std::move(Other.FriendType);
30+
}
2731
}
2832

2933
} // clang::mrdocs

src/lib/Metadata/Info/Function.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,23 @@ toString(
187187
}
188188
}
189189

190+
void
191+
merge(Param& I, Param&& Other)
192+
{
193+
if (!I.Type)
194+
{
195+
I.Type = std::move(Other.Type);
196+
}
197+
if (!I.Name)
198+
{
199+
I.Name = std::move(Other.Name);
200+
}
201+
if (!I.Default)
202+
{
203+
I.Default = std::move(Other.Default);
204+
}
205+
}
206+
190207
template <class IO>
191208
void
192209
tag_invoke(
@@ -276,14 +293,26 @@ merge(FunctionInfo& I, FunctionInfo&& Other)
276293
{
277294
I.ReturnType = std::move(Other.ReturnType);
278295
}
279-
if (I.Params.empty())
296+
std::size_t const n = std::min(I.Params.size(), Other.Params.size());
297+
for (std::size_t i = 0; i < n; ++i)
280298
{
281-
I.Params = std::move(Other.Params);
299+
merge(I.Params[i], std::move(Other.Params[i]));
300+
}
301+
if (Other.Params.size() > n)
302+
{
303+
I.Params.insert(
304+
I.Params.end(),
305+
std::make_move_iterator(Other.Params.begin() + n),
306+
std::make_move_iterator(Other.Params.end()));
282307
}
283308
if (!I.Template)
284309
{
285310
I.Template = std::move(Other.Template);
286311
}
312+
else if (Other.Template)
313+
{
314+
merge(*I.Template, std::move(*Other.Template));
315+
}
287316
if (I.Noexcept.Implicit)
288317
{
289318
I.Noexcept = std::move(Other.Noexcept);

src/lib/Metadata/Info/NamespaceAlias.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ merge(NamespaceAliasInfo& I, NamespaceAliasInfo&& Other)
2020
{
2121
MRDOCS_ASSERT(canMerge(I, Other));
2222
merge(dynamic_cast<Info&>(I), std::move(dynamic_cast<Info&>(Other)));
23-
if (! I.AliasedSymbol)
23+
if (!I.AliasedSymbol)
24+
{
2425
I.AliasedSymbol = std::move(Other.AliasedSymbol);
26+
}
2527
}
2628

2729
} // clang::mrdocs

0 commit comments

Comments
 (0)