Skip to content

Commit

Permalink
feat: tranches & overload sets for namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Nov 28, 2023
1 parent 335e9b3 commit 5a202a5
Show file tree
Hide file tree
Showing 20 changed files with 425 additions and 335 deletions.
55 changes: 48 additions & 7 deletions include/mrdocs/Corpus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class MRDOCS_VISIBLE
ScopeInfo const& S,
F&& f, Args&&... args) const;

#if 0
template<class F, class... Args>
void traverseOverloads(
RecordInfo const& I,
Expand All @@ -153,6 +154,7 @@ class MRDOCS_VISIBLE
void traverseOverloads(
SpecializationInfo const& I,
F&& f, Args&&... args) const;
#endif

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

Expand Down Expand Up @@ -253,6 +255,7 @@ traverseOverloads(
ScopeInfo const& S,
F&& f, Args&&... args) const
{
#if 0
for(const SymbolID& id : S.Members)
{
const Info& member = get(id);
Expand All @@ -265,13 +268,40 @@ traverseOverloads(
else if(lookup.front() == id)
{
OverloadSet overloads(member.Name,
member.Namespace.front(), lookup);
member.Namespace.front(),
member.Namespace, lookup);
visit(overloads, std::forward<F>(f),
std::forward<Args>(args)...);
}
}
#endif
for(const SymbolID& id : S.Members)
{
const Info& member = get(id);
const auto& lookup = S.Lookups.at(member.Name);
auto first_func = std::ranges::find_if(
lookup, [this](const SymbolID& elem)
{
return get(elem).isFunction();
});
if(lookup.size() == 1 ||
first_func == lookup.end())
{
visit(member, std::forward<F>(f),
std::forward<Args>(args)...);
}
else if(*first_func == id)
{
OverloadSet overloads(member.Name,
member.Namespace.front(),
member.Namespace, lookup);
visit(overloads, std::forward<F>(f),
std::forward<Args>(args)...);
}
}
}

#if 0
template<class F, class... Args>
void
Corpus::
Expand All @@ -283,14 +313,21 @@ traverseOverloads(
{
const Info& member = get(id);
const auto& lookup = I.Lookups.at(member.Name);
if(lookup.size() == 1 || member.Name.empty())
auto first_func = std::ranges::find_if(
lookup, [&](const SymbolID& elem)
{
return get(elem).isFunction();
});
if(lookup.size() == 1 ||
first_func == lookup.end())
{
visit(member, std::forward<F>(f),
std::forward<Args>(args)...);
}
else if(lookup.front() == id)
else if(*first_func == id)
{
OverloadSet overloads(member.Name, I.id, lookup);
OverloadSet overloads(member.Name,
I.id, member.Namespace, lookup);
visit(overloads, std::forward<F>(f),
std::forward<Args>(args)...);
}
Expand All @@ -315,7 +352,8 @@ traverseOverloads(
}
else if(lookup.front() == id)
{
OverloadSet overloads(member.Name, I.id, lookup);
OverloadSet overloads(member.Name,
I.id, member.Namespace, lookup);
visit(overloads, std::forward<F>(f),
std::forward<Args>(args)...);
}
Expand All @@ -340,7 +378,8 @@ traverseOverloads(
}
else if(lookup.front() == id)
{
OverloadSet overloads(member.Name, I.id, lookup);
OverloadSet overloads(member.Name,
I.id, member.Namespace, lookup);
visit(overloads, std::forward<F>(f),
std::forward<Args>(args)...);
}
Expand All @@ -365,12 +404,14 @@ traverseOverloads(
}
else if(lookup.front() == id)
{
OverloadSet overloads(member.Name, I.id, lookup);
OverloadSet overloads(member.Name,
I.id, member.Namespace, lookup);
visit(overloads, std::forward<F>(f),
std::forward<Args>(args)...);
}
}
}
#endif

class Corpus::iterator
{
Expand Down
68 changes: 36 additions & 32 deletions include/mrdocs/Metadata/Interface.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//
// This is a derivative work. originally part of the LLVM Project.
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
// Copyright (c) 2023 Krystian Stasiowski (sdkrystian@gmail.com)
//
// Official repository: https://github.com/cppalliance/mrdocs
//
Expand All @@ -23,41 +23,42 @@
namespace clang {
namespace mrdocs {

/** A group of children that have the same access specifier.
*/
struct Tranche
{
std::vector<SymbolID> Namespaces;
std::vector<SymbolID> Records;
std::vector<SymbolID> Functions;
std::vector<SymbolID> Enums;
std::vector<SymbolID> Types;
std::vector<SymbolID> Fields;
std::vector<SymbolID> StaticFunctions;
std::vector<SymbolID> Variables;
std::vector<SymbolID> Friends;

ScopeInfo Overloads;
ScopeInfo StaticOverloads;
};

/** The aggregated interface for a given struct, class, or union.
*/
class Interface
{
public:
/** A group of children that have the same access specifier.
*/
struct Tranche
{
std::span<RecordInfo const*> Records;
std::span<FunctionInfo const*> Functions;
std::span<EnumInfo const*> Enums;
std::span<TypedefInfo const*> Types;
std::span<FieldInfo const*> Data;
std::span<FunctionInfo const*> StaticFunctions;
std::span<VariableInfo const*> StaticData;
std::span<FriendInfo const*> Friends;
};

Corpus const& corpus;

/** The aggregated public interfaces.
*/
Tranche Public;
std::shared_ptr<Tranche> Public;

/** The aggregated protected interfaces.
*/
Tranche Protected;
std::shared_ptr<Tranche> Protected;

/** The aggregated private interfaces.
*/
Tranche Private;

ScopeInfo Overloads;
ScopeInfo StaticOverloads;
std::shared_ptr<Tranche> Private;

MRDOCS_DECL
friend
Expand All @@ -67,18 +68,7 @@ class Interface
Corpus const& corpus);

private:
class Build;

explicit Interface(Corpus const&) noexcept;

std::vector<RecordInfo const*> records_;
std::vector<FunctionInfo const*> functions_;
std::vector<EnumInfo const*> enums_;
std::vector<TypedefInfo const*> types_;
std::vector<FieldInfo const*> data_;
std::vector<FunctionInfo const*> staticfuncs_;
std::vector<VariableInfo const*> staticdata_;
std::vector<FriendInfo const*> friends_;
};

//------------------------------------------------
Expand All @@ -99,6 +89,20 @@ makeInterface(
RecordInfo const& Derived,
Corpus const& corpus);

/** Return a tranche representing the members of a namespace.
@return The tranche.
@param Derived The namespace to build the tranche for.
@param corpus The complete metadata.
*/
MRDOCS_DECL
Tranche
makeTranche(
NamespaceInfo const& Namespace,
Corpus const& corpus);

} // mrdocs
} // clang

Expand Down
7 changes: 5 additions & 2 deletions include/mrdocs/Metadata/Overloads.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//
// This is a derivative work. originally part of the LLVM Project.
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
// Copyright (c) 2023 Krystian Stasiowski (sdkrystian@gmail.com)
//
// Official repository: https://github.com/cppalliance/mrdocs
//
Expand All @@ -27,14 +26,18 @@ struct OverloadSet

SymbolID Parent;

std::span<const SymbolID> Namespace;

std::span<const SymbolID> Members;

OverloadSet(
std::string_view name,
const SymbolID& parent,
std::span<const SymbolID> ns,
std::span<const SymbolID> members)
: Name(name)
, Parent(parent)
, Namespace(ns)
, Members(members)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{{#if relfileprefix}}:relfileprefix: {{relfileprefix}}{{/if}}
[#{{#if (is_multipage)}}{{symbol.id}}{{else}}{{symbol.ref}}{{/if}}]

== {{#if symbol.name}}Overload set {{>nested-name-specifier symbol=symbol.parent}}{{symbol.name}}{{else}}Unnamed overload set{{/if}}
= {{#if symbol.name}}Overload set {{>nested-name-specifier symbol=symbol.parent}}{{symbol.name}}{{else}}Unnamed overload set{{/if}}

== Members

{{#each symbol.members as | member |}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{{#if pointee-type~}}
{{#if (or (eq pointee-type.kind "array") (eq pointee-type.kind "function"))}}){{/if~}}
{{~>declarator-after pointee-type~}}
{{~>declarator-after pointee-type nolink=nolink~}}
{{else if (eq kind "array")~}}
[{{bounds-value}}]
{{~>declarator-after element-type~}}
{{~>declarator-after element-type nolink=nolink~}}
{{else if (eq kind "function")~}}
({{#each param-types~}}
{{~>declarator~}}{{~#unless @last}}, {{/unless~}}
{{~>declarator nolink=../nolink~}}{{~#unless @last}}, {{/unless~}}
{{/each~}})
{{~#if cv-qualifiers}} {{cv-qualifiers}}{{/if~}}
{{#if (eq ref-qualifier "lvalue")}} &{{else if (eq ref-qualifier "rvalue")}} &&{{/if~}}
{{#if exception-spec}} {{exception-spec}}{{/if~}}
{{~>declarator-after return-type~}}
{{~>declarator-after return-type nolink=nolink~}}
{{/if}}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{{#if pointee-type~}}
{{~>declarator-before pointee-type~}}
{{~>declarator-before pointee-type nolink=nolink~}}
{{#if (or (eq pointee-type.kind "array") (eq pointee-type.kind "function"))}}({{/if~}}
{{~/if~}}
{{#if element-type~}}{{~>declarator-before element-type~}}{{/if~}}
{{#if return-type~}}{{~>declarator-before return-type~}}{{/if~}}
{{#if parent-type~}}{{>declarator parent-type}}::{{/if~}}
{{#if element-type~}}{{~>declarator-before element-type nolink=nolink~}}{{/if~}}
{{#if return-type~}}{{~>declarator-before return-type nolink=nolink~}}{{/if~}}
{{#if parent-type~}}{{>declarator parent-type nolink=nolink}}::{{/if~}}
{{#if (eq kind "lvalue-reference")}}&{{/if~}}
{{#if (eq kind "rvalue-reference")}}&&{{/if~}}
{{#if (eq kind "pointer")}}*{{/if~}}
{{#if (eq kind "member-pointer")}}*{{/if~}}
{{#if cv-qualifiers~}}
{{#if pointee-type}} {{cv-qualifiers}}{{else}}{{cv-qualifiers}} {{/if~}}
{{/if~}}
{{#if symbol~}}
{{#if (not parent-type)}}{{>qualified-path symbol=symbol.parent}}{{/if~}}
{{#if (and symbol (not parent-type))}}{{>qualified-path symbol=symbol.parent nolink=nolink}}{{/if~}}
{{#if (and symbol (not nolink))~}}
xref:{{symbol.ref}}[{{name}}]
{{~else if name}}{{name~}}
{{/if~}}
{{#if (eq kind "decltype")}}decltype({{operand}}){{/if~}}
{{#if (eq kind "specialization")}}{{>template-args args=args}}{{/if~}}
{{#if (eq kind "specialization")}}{{>template-args args=args nolink=nolink}}{{/if~}}
{{#if is-pack~}}...{{/if}}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{#if (and (eq kind "function") (eq class "conversion"))~}}
operator {{>declarator return~}}
operator {{>declarator return nolink=nolink~}}
{{else~}}
{{#if link.ref}}xref:{{link.ref}}[{{name}}]{{else}}{{name}}{{/if~}}
{{#if (and link.ref (not nolink))}}xref:{{link.ref}}[{{name}}]{{else}}{{name}}{{/if~}}
{{#if (or (eq template.kind "explicit") (eq template.kind "partial"))~}}
{{>template-args args=template.args~}}
{{>template-args args=template.args nolink=nolink~}}
{{/if~}}
{{/if}}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{>declarator-before~}}
{{>declarator-before nolink=nolink~}}
{{~#if decl-name}} {{decl-name~}}
{{~#if decl-name-targs~}}{{>template-args args=decl-name-targs}}{{~/if~}}
{{~#if decl-name-targs~}}{{>template-args args=decl-name-targs nolink=nolink}}{{~/if~}}
{{~/if~}}
{{~>declarator-after}}
{{~>declarator-after nolink=nolink}}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{{#if members}}
== {{title}}
[,cols=2]
|===
|Name |Description
{{#each .}}
|xref:{{ref}}[`pass:v[{{name}}]`] | {{#if (ne kind "overload")}}{{doc.brief}}{{else}}{{#each (unique (pluck (pluck members "doc") "brief"))}}{{.}}
{{/each}}{{/if}}
{{#each members}}
{{>info-member .}}
{{/each}}
|===
{{/if}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{!-- |xref:{{ref}}[`pass:v[{{name}}]`] | --}}
|xref:{{ref}}[`pass:v[{{>declarator-id . nolink=true}}]`] |
{{#if (ne kind "overload")~}}
{{~doc.brief}}
{{else~}}
{{#each (unique (pluck (pluck members "doc") "brief"))~}}
{{.}}
{{/each~}}
{{/if}}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{#unless (contains @root.symbol.namespace symbol)~}}
{{#if symbol.parent~}}
{{>qualified-path symbol=symbol.parent~}}
{{>qualified-path symbol=symbol.parent nolink=nolink~}}
{{else~}}
{{/if~}}
{{#if symbol.name}}xref:{{symbol.ref}}[{{symbol.name}}]::{{/if~}}
{{#if symbol.name}}{{#if (not nolink)}}xref:{{symbol.ref}}[{{symbol.name}}]{{else}}{{symbol.name}}{{/if}}::{{/if~}}
{{/unless}}
Loading

0 comments on commit 5a202a5

Please sign in to comment.