Skip to content

Commit

Permalink
feat: overload sets
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Nov 21, 2023
1 parent a0c9d1d commit bbc08f1
Show file tree
Hide file tree
Showing 39 changed files with 991 additions and 601 deletions.
180 changes: 172 additions & 8 deletions include/mrdocs/Corpus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2023 Vinnie Falco ([email protected])
// Copyright (c) 2023 Krystian Stasiowski ([email protected])
//
// Official repository: https://github.com/cppalliance/mrdocs
//
Expand Down Expand Up @@ -101,6 +102,8 @@ class MRDOCS_VISIBLE

//--------------------------------------------

// KRYSTIAN FIXME: this could just be a single
// overload constrained with std::derived_from<ScopeInfo>
template<class F, class... Args>
void traverse(
NamespaceInfo const& I,
Expand All @@ -121,6 +124,36 @@ class MRDOCS_VISIBLE
SpecializationInfo const& I,
F&& f, Args&&... args) const;

template<class F, class... Args>
void traverse(
OverloadSet const& OS,
F&& f, Args&&... args) const;

template<class F, class... Args>
void traverseOverloads(
ScopeInfo const& S,
F&& f, Args&&... args) const;

template<class F, class... Args>
void traverseOverloads(
RecordInfo const& I,
F&& f, Args&&... args) const;

template<class F, class... Args>
void traverseOverloads(
NamespaceInfo const& I,
F&& f, Args&&... args) const;

template<class F, class... Args>
void traverseOverloads(
EnumInfo const& I,
F&& f, Args&&... args) const;

template<class F, class... Args>
void traverseOverloads(
SpecializationInfo const& I,
F&& f, Args&&... args) const;

//--------------------------------------------

// KRYSTIAN NOTE: temporary
Expand Down Expand Up @@ -163,9 +196,6 @@ traverse(
for(auto const& id : I.Members)
visit(get(id), std::forward<F>(f),
std::forward<Args>(args)...);
for(auto const& id : I.Specializations)
visit(get(id), std::forward<F>(f),
std::forward<Args>(args)...);
}

template<class F, class... Args>
Expand All @@ -178,7 +208,16 @@ traverse(
for(auto const& id : I.Members)
visit(get(id), std::forward<F>(f),
std::forward<Args>(args)...);
for(auto const& id : I.Specializations)
}

template<class F, class... Args>
void
Corpus::
traverse(
EnumInfo const& I,
F&& f, Args&&... args) const
{
for(auto const& id : I.Members)
visit(get(id), std::forward<F>(f),
std::forward<Args>(args)...);
}
Expand All @@ -187,7 +226,7 @@ template<class F, class... Args>
void
Corpus::
traverse(
EnumInfo const& I,
SpecializationInfo const& I,
F&& f, Args&&... args) const
{
for(auto const& id : I.Members)
Expand All @@ -199,13 +238,138 @@ template<class F, class... Args>
void
Corpus::
traverse(
OverloadSet const& OS,
F&& f, Args&&... args) const
{
for(auto const& id : OS.Members)
visit(get(id), std::forward<F>(f),
std::forward<Args>(args)...);
}

template<class F, class... Args>
void
Corpus::
traverseOverloads(
ScopeInfo const& S,
F&& f, Args&&... args) const
{
for(const SymbolID& id : S.Members)
{
const Info& member = get(id);
const auto& lookup = S.Lookups.at(member.Name);
if(lookup.size() == 1 || member.Name.empty())
{
visit(member, std::forward<F>(f),
std::forward<Args>(args)...);
}
else if(lookup.front() == id)
{
OverloadSet overloads(member.Name,
member.Namespace.front(), lookup);
visit(overloads, std::forward<F>(f),
std::forward<Args>(args)...);
}
}
}

template<class F, class... Args>
void
Corpus::
traverseOverloads(
RecordInfo const& I,
F&& f, Args&&... args) const
{
for(const SymbolID& id : I.Members)
{
const Info& member = get(id);
const auto& lookup = I.Lookups.at(member.Name);
if(lookup.size() == 1 || member.Name.empty())
{
visit(member, std::forward<F>(f),
std::forward<Args>(args)...);
}
else if(lookup.front() == id)
{
OverloadSet overloads(member.Name, I.id, lookup);
visit(overloads, std::forward<F>(f),
std::forward<Args>(args)...);
}
}
}

template<class F, class... Args>
void
Corpus::
traverseOverloads(
NamespaceInfo const& I,
F&& f, Args&&... args) const
{
for(const SymbolID& id : I.Members)
{
const Info& member = get(id);
const auto& lookup = I.Lookups.at(member.Name);
if(lookup.size() == 1 || member.Name.empty())
{
visit(member, std::forward<F>(f),
std::forward<Args>(args)...);
}
else if(lookup.front() == id)
{
OverloadSet overloads(member.Name, I.id, lookup);
visit(overloads, std::forward<F>(f),
std::forward<Args>(args)...);
}
}
}

template<class F, class... Args>
void
Corpus::
traverseOverloads(
EnumInfo const& I,
F&& f, Args&&... args) const
{
for(const SymbolID& id : I.Members)
{
const Info& member = get(id);
const auto& lookup = I.Lookups.at(member.Name);
if(lookup.size() == 1 || member.Name.empty())
{
visit(member, std::forward<F>(f),
std::forward<Args>(args)...);
}
else if(lookup.front() == id)
{
OverloadSet overloads(member.Name, I.id, lookup);
visit(overloads, std::forward<F>(f),
std::forward<Args>(args)...);
}
}
}

template<class F, class... Args>
void
Corpus::
traverseOverloads(
SpecializationInfo const& I,
F&& f, Args&&... args) const
{
for(auto const& J : I.Members)
visit(get(J.Specialized),
std::forward<F>(f),
for(const SymbolID& id : I.Members)
{
const Info& member = get(id);
const auto& lookup = I.Lookups.at(member.Name);
if(lookup.size() == 1 || member.Name.empty())
{
visit(member, std::forward<F>(f),
std::forward<Args>(args)...);
}
else if(lookup.front() == id)
{
OverloadSet overloads(member.Name, I.id, lookup);
visit(overloads, std::forward<F>(f),
std::forward<Args>(args)...);
}
}
}

class Corpus::iterator
Expand Down
20 changes: 20 additions & 0 deletions include/mrdocs/Metadata/DomMetadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2023 Vinnie Falco ([email protected])
// Copyright (c) 2023 Krystian Stasiowski ([email protected])
//
// Official repository: https://github.com/cppalliance/mrdocs
//
Expand Down Expand Up @@ -53,6 +54,14 @@ class MRDOCS_DECL
*/
Corpus const& getCorpus() const;

/** Returns the Corpus associated with the Dom.
*/
Corpus const& operator*() const;

/** Returns the Corpus associated with the Dom.
*/
Corpus const* operator->() const;

/** Construct a Dom object representing the given symbol.
This function is called internally when a `dom::Object`
Expand Down Expand Up @@ -84,6 +93,17 @@ class MRDOCS_DECL
dom::Value
getJavadoc(
Javadoc const& jd) const;

/** Return a Dom value representing an overload set.
A @ref Generator should override this member
and return suitable @ref dom::Value representing
the overload set.
*/
virtual
dom::Object
getOverloads(
OverloadSet const& os) const;
};

} // mrdocs
Expand Down
5 changes: 2 additions & 3 deletions include/mrdocs/Metadata/Enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <mrdocs/Platform.hpp>
#include <mrdocs/Metadata/Expression.hpp>
#include <mrdocs/Metadata/Javadoc.hpp>
#include <mrdocs/Metadata/Scope.hpp>
#include <mrdocs/Metadata/Source.hpp>
#include <mrdocs/Metadata/Type.hpp>
#include <optional>
Expand All @@ -30,6 +31,7 @@ namespace mrdocs {
struct EnumInfo
: IsInfo<InfoKind::Enum>
, SourceInfo
, ScopeInfo
{
// Indicates whether this enum is scoped (e.g. enum class).
bool Scoped = false;
Expand All @@ -39,9 +41,6 @@ struct EnumInfo
// this will be "short".
std::unique_ptr<TypeInfo> UnderlyingType;

// Enumeration members.
std::vector<SymbolID> Members;

//--------------------------------------------

explicit EnumInfo(SymbolID ID) noexcept
Expand Down
3 changes: 3 additions & 0 deletions include/mrdocs/Metadata/Interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class Interface
*/
Tranche Private;

ScopeInfo Overloads;
ScopeInfo StaticOverloads;

MRDOCS_DECL
friend
Interface
Expand Down
7 changes: 3 additions & 4 deletions include/mrdocs/Metadata/Namespace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#define MRDOCS_API_METADATA_NAMESPACE_HPP

#include <mrdocs/Platform.hpp>
#include <mrdocs/Metadata/Info.hpp>
#include <mrdocs/ADT/BitField.hpp>
#include <mrdocs/Metadata/Info.hpp>
#include <mrdocs/Metadata/Scope.hpp>
#include <vector>

namespace clang {
Expand All @@ -32,10 +33,8 @@ union NamespaceFlags
*/
struct NamespaceInfo
: IsInfo<InfoKind::Namespace>
, ScopeInfo
{
std::vector<SymbolID> Members;
std::vector<SymbolID> Specializations;

NamespaceFlags specs;

//--------------------------------------------
Expand Down
Loading

0 comments on commit bbc08f1

Please sign in to comment.