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
5 changes: 5 additions & 0 deletions include/mrdocs/Metadata/Name.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ tag_invoke(
tag_invoke(dom::ValueFromTag{}, v, *I, domCorpus);
}

/** Merge two Name metadata objects.
*/
void
merge(Name& I, Name&& Other);

} // mrdocs

#endif
11 changes: 11 additions & 0 deletions include/mrdocs/Metadata/Symbol/ExtractionMode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ mostSpecific(ExtractionMode const a, ExtractionMode const b) noexcept
std::max(static_cast<IT>(a), static_cast<IT>(b)));
}

/** Merge two ExtractionMode values.

Takes the least specific (most conservative) of the two,
so that a symbol demoted in any TU stays demoted.
*/
inline void
merge(ExtractionMode& dst, ExtractionMode&& src) noexcept
{
dst = leastSpecific(dst, src);
}

} // mrdocs

#endif // MRDOCS_API_METADATA_SYMBOL_EXTRACTIONMODE_HPP
12 changes: 11 additions & 1 deletion include/mrdocs/Metadata/Symbol/Friend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <mrdocs/Metadata/Symbol.hpp>
#include <mrdocs/Metadata/Symbol/Source.hpp>
#include <mrdocs/Metadata/Type.hpp>
#include <vector>

namespace mrdocs {

Expand Down Expand Up @@ -42,12 +43,21 @@ struct FriendInfo final
Optional<Polymorphic<struct Type>> Type = std::nullopt;
};

MRDOCS_DECL
/** Merge another FriendInfo into this one.
*/
MRDOCS_DECL
void
merge(FriendInfo& I, FriendInfo&& Other);

/** Merge friend declarations, deduplicating by symbol ID.

@param dst The destination.
@param src The source (moved from).
*/
MRDOCS_DECL
void
merge(std::vector<FriendInfo>& dst, std::vector<FriendInfo>&& src);

/** Map a FriendInfo to a dom::Object.

@param t The tag type.
Expand Down
10 changes: 10 additions & 0 deletions include/mrdocs/Metadata/Symbol/Param.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <mrdocs/ADT/Optional.hpp>
#include <mrdocs/ADT/Polymorphic.hpp>
#include <mrdocs/Metadata/Type.hpp>
#include <vector>
#include <string>

namespace mrdocs {
Expand Down Expand Up @@ -68,6 +69,15 @@ MRDOCS_DECL
void
merge(Param& I, Param&& Other);

/** Merge parameters element-wise, appending extras from `src`.

@param dst The destination.
@param src The source (moved from).
*/
MRDOCS_DECL
void
merge(std::vector<Param>& dst, std::vector<Param>&& src);

/** Return the Param as a @ref dom::Value object.
*/
MRDOCS_DECL
Expand Down
27 changes: 3 additions & 24 deletions src/lib/Metadata/Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
//

#include <lib/Support/Radix.hpp>
#include <lib/Support/Reflection/MergeReflectedType.hpp>
#include <lib/Support/Reflection/Reflection.hpp>
#include <mrdocs/Dom/LazyArray.hpp>
#include <mrdocs/Dom/LazyObject.hpp>
#include <mrdocs/Metadata.hpp>
Expand Down Expand Up @@ -41,30 +43,7 @@ void
merge(Symbol& I, Symbol&& Other)
{
MRDOCS_ASSERT(I.id);
merge(I.Loc, std::move(Other.Loc));
if (I.Name == "")
{
I.Name = Other.Name;
}
if (I.Parent)
{
I.Parent = Other.Parent;
}
if (I.Access == AccessKind::None)
{
I.Access = Other.Access;
}
I.Extraction = leastSpecific(I.Extraction, Other.Extraction);

// Append docs
if (!I.doc)
{
I.doc = std::move(Other.doc);
}
else if (Other.doc)
{
merge(*I.doc, std::move(*Other.doc));
}
mergeReflected(I, Other);
}

} // mrdocs
8 changes: 8 additions & 0 deletions src/lib/Metadata/Name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
//

#include <lib/Support/Reflection/MapReflectedType.hpp>
#include <lib/Support/Reflection/MergeReflectedType.hpp>
#include <lib/Support/Reflection/Reflection.hpp>
#include <mrdocs/Dom/LazyArray.hpp>
#include <mrdocs/Dom/LazyObject.hpp>
#include <mrdocs/Metadata/DomCorpus.hpp>
Expand Down Expand Up @@ -176,4 +178,10 @@ tag_invoke(
v = dom::LazyObject(I, domCorpus);
}

void
merge(Name& I, Name&& Other)
{
mergeReflected(I, Other);
}

} // mrdocs
13 changes: 3 additions & 10 deletions src/lib/Metadata/Symbol/Concept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
// Official repository: https://github.com/cppalliance/mrdocs
//

#include <lib/Support/Reflection/MergeReflectedType.hpp>
#include <lib/Support/Reflection/Reflection.hpp>
#include <mrdocs/Platform.hpp>
#include <mrdocs/Metadata/Symbol/Concept.hpp>
#include <llvm/ADT/STLExtras.h>

namespace mrdocs {

Expand Down Expand Up @@ -62,15 +63,7 @@ void
merge(ConceptSymbol& I, ConceptSymbol&& Other)
{
MRDOCS_ASSERT(canMerge(I, Other));
merge(I.asInfo(), std::move(Other.asInfo()));
if (I.Constraint.Written.empty())
{
I.Constraint = std::move(Other.Constraint);
}
if (!I.Template)
{
I.Template = std::move(Other.Template);
}
mergeReflected(I, Other);
}

} // mrdocs
Expand Down
33 changes: 3 additions & 30 deletions src/lib/Metadata/Symbol/Enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,18 @@
// Official repository: https://github.com/cppalliance/mrdocs
//

#include <lib/Support/Reflection/MergeReflectedType.hpp>
#include <lib/Support/Reflection/Reflection.hpp>
#include <mrdocs/Platform.hpp>
#include <mrdocs/Metadata/Symbol/Enum.hpp>
#include <llvm/ADT/STLExtras.h>

namespace mrdocs {

namespace {

void
reduceSymbolIDs(
std::vector<SymbolID>& list,
std::vector<SymbolID>&& otherList)
{
for(auto const& id : otherList)
{
if (auto it = llvm::find(list, id); it != list.end())
{
continue;
}
list.push_back(id);
}
}

} // (anon)

void
merge(EnumSymbol& I, EnumSymbol&& Other)
{
MRDOCS_ASSERT(canMerge(I, Other));
merge(I.asInfo(), std::move(Other.asInfo()));
if (!I.Scoped)
{
I.Scoped = Other.Scoped;
}
if (!I.UnderlyingType)
{
I.UnderlyingType = std::move(Other.UnderlyingType);
}
reduceSymbolIDs(I.Constants, std::move(Other.Constants));
mergeReflected(I, Other);
}

} // mrdocs
Expand Down
9 changes: 3 additions & 6 deletions src/lib/Metadata/Symbol/EnumConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@
// Official repository: https://github.com/cppalliance/mrdocs
//

#include <lib/Support/Reflection/MergeReflectedType.hpp>
#include <lib/Support/Reflection/Reflection.hpp>
#include <mrdocs/Platform.hpp>
#include <mrdocs/Metadata/Symbol/EnumConstant.hpp>
#include <llvm/ADT/STLExtras.h>

namespace mrdocs {

void
merge(EnumConstantSymbol& I, EnumConstantSymbol&& Other)
{
MRDOCS_ASSERT(canMerge(I, Other));
merge(I.asInfo(), std::move(Other.asInfo()));
if (I.Initializer.Written.empty())
{
I.Initializer = std::move(Other.Initializer);
}
mergeReflected(I, Other);
}

} // mrdocs
Expand Down
28 changes: 21 additions & 7 deletions src/lib/Metadata/Symbol/Friend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,40 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2025 Alan de Freitas (alandefreitas@gmail.com)
// Copyright (c) 2026 Gennaro Prota (gennaro.prota@gmail.com)
//
// Official repository: https://github.com/cppalliance/mrdocs
//

#include <lib/Support/Reflection/MergeReflectedType.hpp>
#include <lib/Support/Reflection/Reflection.hpp>
#include <mrdocs/Platform.hpp>
#include <mrdocs/Metadata/Symbol/Friend.hpp>
#include <llvm/ADT/STLExtras.h>
#include <algorithm>
#include <vector>

namespace mrdocs {

void
merge(FriendInfo& I, FriendInfo&& Other)
{
if (!I.id)
{
I.id = Other.id;
}
if (!I.Type)
mergeReflected(I, Other);
}

void
merge(
std::vector<FriendInfo>& dst,
std::vector<FriendInfo>&& src)
{
for (FriendInfo const& F : src)
{
I.Type = std::move(Other.Type);
auto it = std::ranges::find_if(dst, [&F](auto const& other) {
return F.id == other.id;
});
if (it == dst.end())
{
dst.push_back(F);
}
}
}

Expand Down
Loading
Loading