Skip to content

Commit 1138867

Browse files
committed
feat: interface for records
1 parent 2e4b285 commit 1138867

22 files changed

+466
-236
lines changed

addons/generator/asciidoc/partials/function-sig.adoc.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ static
1717
{{name}}()
1818
{{~/if~}}
1919
{{#if (eq specs.exceptionSpec "noexcept")}} noexcept{{/if~}}
20+
{{#if specs.isDeleted}} = delete{{/if~}}
2021
;
2122
----
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[,cols=2]
2+
|===
3+
|Name |Description
4+
{{#each .}}
5+
|xref:{{id}}[`{{name}}`] |{{doc.brief}}
6+
{{/each}}
7+
|===

addons/generator/asciidoc/partials/record.adoc.hbs

+19-7
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,32 @@
1010
----
1111
{{#if symbol.template}}
1212
{{>template-head symbol.template}}
13-
{{symbol.tag}} {{symbol.name}}{{>template-args symbol.template}}
13+
{{symbol.tag}} {{symbol.name~}}
14+
{{>template-args symbol.template}}
1415
{{else}}
15-
{{symbol.tag}} {{symbol.name}}
16+
{{symbol.tag}} {{symbol.name~}}
1617
{{/if}}
17-
{
18-
{{#each symbol.members}}
19-
{{>record-member}}
20-
18+
{{#unless symbol.bases}}
19+
;
20+
{{else}}{{"\n"}}
21+
{{#each symbol.bases}}
22+
{{#if @first}}: {{else}}, {{/if}}
23+
{{~access}}
24+
{{~#if isVirtual}} virtual{{/if}}
25+
{{~null}} {{type.name}}
26+
{{~#if @last}};{{/if}}
2127
{{/each}}
22-
};
28+
{{/unless}}
2329
----
2430
2531
{{>source symbol.loc}}
2632
33+
{{#with symbol.interface}}
34+
{{> tranche tranche=public label=""}}
35+
{{> tranche tranche=protected label=" Protected"}}
36+
{{> tranche tranche=private label=" Private"}}
37+
{{/with}}
38+
2739
{{#if symbol.doc.description}}
2840
=== Description
2941
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{{#if def}}
2-
Declared in file <{{def.file}}>
2+
Declared in file <{{def.file}}> at line {{line}}
33
{{else if decl}}
44
{{#each decl}}
5-
Declared in file <{{file}}>
5+
Declared in file <{{file}}> at line {{line}}
66
{{/each}}
77
{{else}}
88
{{/if}}

addons/generator/asciidoc/partials/template-args.adoc.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{~#if (neq kind "primary")~}}<
1+
{{#if (neq kind "primary")~}}<
22
{{~#each args~}}
33
{{value}}
44
{{~#if (not @last)}}, {{/if}}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
template<
2-
{{~#each params~}}
3-
{{~#if (eq kind "type")}}
4-
{{~>type-tparam~}}
5-
{{~else if (eq kind "non-type")}}
6-
{{~>nontype-tparam~}}
7-
{{~else if (eq kind "template")}}
8-
{{~>template-tparam~}}
9-
{{~/if~}}
10-
{{~#if (not @last)~}}, {{/if}}
11-
{{~/each~}}>
2+
{{#each params}}
3+
{{#if (eq kind "type")}}
4+
{{>type-tparam~}}
5+
{{else if (eq kind "non-type")}}
6+
{{>nontype-tparam~}}
7+
{{else if (eq kind "template")}}
8+
{{>template-tparam~}}
9+
{{/if}}
10+
{{~#unless @last}},
11+
{{else}}
12+
{{/unless}}
13+
{{/each}}>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{#if tranche.records}}
2+
==={{label}} Types
3+
{{>info-list tranche.records}}
4+
{{/if}}
5+
{{#if tranche.types}}
6+
{{#if label}}
7+
==={{label}} Types
8+
{{else}}
9+
=== Types
10+
{{/if}}
11+
{{>info-list tranche.types}}
12+
{{/if}}
13+
{{#if tranche.functions}}
14+
==={{label}} Functions
15+
{{>info-list tranche.functions}}
16+
{{/if}}
17+
{{#if tranche.enums}}
18+
==={{label}} Enums
19+
{{>info-list tranche.enums}}
20+
{{/if}}
21+
{{#if tranche.data}}
22+
==={{label}} Data
23+
{{>info-list tranche.data}}
24+
{{/if}}
25+
{{#if tranche.staticfunctions}}
26+
==={{label}} Static Functions
27+
{{>info-list tranche.staticfunctions}}
28+
{{/if}}
29+
{{#if tranche.staticdata}}
30+
==={{label}} Static Data
31+
{{>info-list tranche.staticdata}}
32+
{{/if}}

include/mrdox/Dom/DomBase.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ namespace mrdox {
2121
/** A base class record
2222
*/
2323
class MRDOX_DECL
24-
DomBase : public DomSymbol<RecordInfo>
24+
DomBase : public dom::Object
2525
{
26-
BaseInfo const* B_;
26+
BaseInfo const& B_;
27+
Corpus const& corpus_;
2728

2829
public:
2930
DomBase(
30-
RecordInfo const& I,
3131
BaseInfo const& B,
3232
Corpus const& corpus) noexcept;
3333

include/mrdox/Dom/DomInterface.hpp

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdox
9+
//
10+
11+
#ifndef MRDOX_API_DOM_DOMINTERFACE_HPP
12+
#define MRDOX_API_DOM_DOMINTERFACE_HPP
13+
14+
#include <mrdox/Platform.hpp>
15+
#include <mrdox/Corpus.hpp>
16+
#include <mrdox/Metadata/Interface.hpp>
17+
#include <mrdox/Support/Dom.hpp>
18+
#include <memory>
19+
20+
namespace clang {
21+
namespace mrdox {
22+
23+
/** The aggregate interface to a record.
24+
*/
25+
class MRDOX_DECL
26+
DomInterface : public dom::Object
27+
{
28+
std::shared_ptr<Interface> I_;
29+
Corpus const& corpus_;
30+
31+
public:
32+
DomInterface(
33+
std::shared_ptr<Interface> I,
34+
Corpus const& corpus) noexcept;
35+
dom::Value get(std::string_view key) const override;
36+
std::vector<std::string_view> props() const override;
37+
};
38+
39+
} // mrdox
40+
} // clang
41+
42+
#endif

include/mrdox/Dom/DomSymbol.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class MRDOX_DECL
2929
static_assert(std::derived_from<T, Info>);
3030

3131
protected:
32-
T const* I_;
32+
T const& I_;
3333
Corpus const& corpus_;
3434

3535
public:

include/mrdox/Metadata/Interface.hpp

+17-63
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,14 @@
1515
#include <mrdox/Platform.hpp>
1616
#include <mrdox/MetadataFwd.hpp>
1717
#include <mrdox/Metadata/Record.hpp>
18+
#include <memory>
1819
#include <span>
1920
#include <utility>
2021
#include <vector>
2122

2223
namespace clang {
2324
namespace mrdox {
2425

25-
struct DataMember
26-
{
27-
FieldInfo const* I;
28-
RecordInfo const* From;
29-
};
30-
31-
struct MemberEnum
32-
{
33-
EnumInfo const* I;
34-
RecordInfo const* From;
35-
};
36-
37-
struct MemberFunction
38-
{
39-
FunctionInfo const* I;
40-
RecordInfo const* From;
41-
};
42-
43-
struct MemberRecord
44-
{
45-
RecordInfo const* I;
46-
RecordInfo const* From;
47-
};
48-
49-
struct MemberType
50-
{
51-
TypedefInfo const* I;
52-
RecordInfo const* From;
53-
};
54-
55-
struct StaticDataMember
56-
{
57-
VariableInfo const* I;
58-
RecordInfo const* From;
59-
};
60-
6126
/** The aggregated interface for a given struct, class, or union.
6227
*/
6328
class Interface
@@ -67,12 +32,13 @@ class Interface
6732
*/
6833
struct Tranche
6934
{
70-
std::span<MemberRecord const> Records;
71-
std::span<MemberFunction const> Functions;
72-
std::span<MemberEnum const> Enums;
73-
std::span<MemberType const> Types;
74-
std::span<DataMember const> Data;
75-
std::span<StaticDataMember const> Vars;
35+
std::span<RecordInfo const*> Records;
36+
std::span<FunctionInfo const*> Functions;
37+
std::span<EnumInfo const*> Enums;
38+
std::span<TypedefInfo const*> Types;
39+
std::span<FieldInfo const*> Data;
40+
std::span<FunctionInfo const*> StaticFunctions;
41+
std::span<VariableInfo const*> StaticData;
7642
};
7743

7844
/** The aggregated public interfaces.
@@ -89,21 +55,21 @@ class Interface
8955

9056
MRDOX_DECL
9157
friend
92-
Interface&
58+
std::shared_ptr<Interface>
9359
makeInterface(
94-
Interface& I,
9560
RecordInfo const& Derived,
9661
Corpus const& corpus);
9762

9863
private:
9964
class Build;
10065

101-
std::vector<DataMember> data_;
102-
std::vector<MemberEnum> enums_;
103-
std::vector<MemberFunction> functions_;
104-
std::vector<MemberRecord> records_;
105-
std::vector<MemberType> types_;
106-
std::vector<StaticDataMember> vars_;
66+
std::vector<RecordInfo const*> records_;
67+
std::vector<FunctionInfo const*> functions_;
68+
std::vector<EnumInfo const*> enums_;
69+
std::vector<TypedefInfo const*> types_;
70+
std::vector<FieldInfo const*> data_;
71+
std::vector<FunctionInfo const*> staticfuncs_;
72+
std::vector<VariableInfo const*> staticdata_;
10773
};
10874

10975
//------------------------------------------------
@@ -119,23 +85,11 @@ class Interface
11985
@param corpus The complete metadata.
12086
*/
12187
MRDOX_DECL
122-
Interface&
88+
std::shared_ptr<Interface>
12389
makeInterface(
124-
Interface& I,
12590
RecordInfo const& Derived,
12691
Corpus const& corpus);
12792

128-
inline
129-
Interface
130-
makeInterface(
131-
RecordInfo const& Derived,
132-
Corpus const& corpus)
133-
{
134-
Interface I;
135-
makeInterface(I, Derived, corpus);
136-
return I;
137-
}
138-
13993
} // mrdox
14094
} // clang
14195

source/-adoc/SinglePageVisitor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ SinglePageVisitor::
4747
operator()(RecordInfo const& I)
4848
{
4949
renderPage(I, numPages_++);
50-
//corpus_.traverse(I, *this);
50+
corpus_.traverse(I, *this);
5151
}
5252

5353
void

source/Dom/DomBase.cpp

+12-17
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ namespace mrdox {
1717

1818
DomBase::
1919
DomBase(
20-
RecordInfo const& I,
2120
BaseInfo const& B,
2221
Corpus const& corpus) noexcept
23-
: DomSymbol<RecordInfo>(I, corpus)
24-
, B_(&B)
22+
: B_(B)
23+
, corpus_(corpus)
2524
{
2625
}
2726

@@ -30,28 +29,24 @@ DomBase::
3029
get(std::string_view key) const
3130
{
3231
if(key == "type")
33-
return dom::makePointer<DomType>(B_->Type, corpus_);
34-
if(key == "base-access")
35-
return toString(B_->Access);
36-
if(key == "is-virtual")
37-
return B_->IsVirtual;
38-
39-
return DomSymbol<RecordInfo>::get(key);
32+
return dom::create<DomType>(B_.Type, corpus_);
33+
if(key == "access")
34+
return toString(B_.Access);
35+
if(key == "isVirtual")
36+
return B_.IsVirtual;
37+
return nullptr;
4038
}
4139

4240
auto
4341
DomBase::
4442
props() const ->
4543
std::vector<std::string_view>
4644
{
47-
std::vector<std::string_view> v =
48-
DomSymbol<RecordInfo>::props();
49-
v.insert(v.end(), {
45+
return {
5046
"type",
51-
"base-access",
52-
"is-virtual"
53-
});
54-
return v;
47+
"access",
48+
"isVirtual"
49+
};
5550
}
5651

5752
} // mrdox

source/Dom/DomBaseArray.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ get(
3737
{
3838
if(index < list_.size())
3939
return dom::create<DomBase>(
40-
corpus_.get<RecordInfo>(
41-
list_[index].Type.id),
42-
list_[index],
43-
corpus_);
40+
list_[index], corpus_);
4441
return nullptr;
4542
}
4643

0 commit comments

Comments
 (0)