Skip to content

Commit 1810e93

Browse files
committed
explicit specializations of implicit instantiations
1 parent c5bd179 commit 1810e93

22 files changed

+459
-108
lines changed

include/mrdox/Corpus.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class MRDOX_VISIBLE
106106
// KRYSTIAN FIXME: is this correct? does it make sense to
107107
// visit a field as a non-member (a field *must* be class member)?
108108
MRDOX_DECL virtual bool visit(FieldInfo const&);
109+
MRDOX_DECL virtual bool visit(SpecializationInfo const&);
109110

110111
MRDOX_DECL virtual bool visit(MemberEnum const&, Access);
111112
MRDOX_DECL virtual bool visit(MemberFunction const&, Access);
@@ -121,6 +122,7 @@ class MRDOX_VISIBLE
121122
MRDOX_DECL bool traverse(Visitor&, Info const& I) const;
122123
MRDOX_DECL bool traverse(Visitor&, NamespaceInfo const& I) const;
123124
MRDOX_DECL bool traverse(Visitor&, RecordInfo const& I) const;
125+
MRDOX_DECL bool traverse(Visitor&, SpecializationInfo const& I) const;
124126
MRDOX_DECL bool traverse(Visitor&, SymbolID id) const;
125127
MRDOX_DECL bool traverse(Visitor&, std::vector<Reference> const& R) const;
126128
MRDOX_DECL bool traverse(Visitor&, std::vector<SymbolID> const& R) const;
@@ -161,6 +163,8 @@ get(
161163
assert(t->Kind == InfoKind::Variable);
162164
else if constexpr(std::is_same_v<T, FieldInfo>)
163165
assert(t->Kind == InfoKind::Field);
166+
else if constexpr(std::is_same_v<T, SpecializationInfo>)
167+
assert(t->Kind == InfoKind::Specialization);
164168
return *t;
165169
}
166170

include/mrdox/Metadata.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <mrdox/Metadata/Record.hpp>
3030
#include <mrdox/Metadata/Reference.hpp>
3131
#include <mrdox/Metadata/Scope.hpp>
32+
#include <mrdox/Metadata/Specialization.hpp>
3233
#include <mrdox/Metadata/Symbol.hpp>
3334
#include <mrdox/Metadata/Symbols.hpp>
3435
#include <mrdox/Metadata/Template.hpp>

include/mrdox/Metadata/Scope.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct Scope
4040
std::vector<Reference> Typedefs;
4141
std::vector<Reference> Enums;
4242
std::vector<Reference> Vars;
43+
std::vector<Reference> Specializations;
4344

4445
explicit
4546
Scope(
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 Krystian Stasiowski ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdox
9+
//
10+
11+
#ifndef MRDOX_API_METADATA_SPECIALIZATION_HPP
12+
#define MRDOX_API_METADATA_SPECIALIZATION_HPP
13+
14+
#include <mrdox/Platform.hpp>
15+
#include <mrdox/MetadataFwd.hpp>
16+
#include <mrdox/Metadata/Info.hpp>
17+
#include <mrdox/Metadata/Symbols.hpp>
18+
#include <utility>
19+
#include <vector>
20+
21+
namespace clang {
22+
namespace mrdox {
23+
24+
/** Primary and specialized IDs of specialized members
25+
*/
26+
struct SpecializedMember
27+
{
28+
/** ID of the member in the primary template */
29+
SymbolID Primary;
30+
31+
/** ID of the member specialization */
32+
SymbolID Specialized;
33+
34+
SpecializedMember() = default;
35+
36+
SpecializedMember(
37+
SymbolID primary,
38+
SymbolID specialized)
39+
: Primary(primary)
40+
, Specialized(specialized)
41+
{
42+
}
43+
};
44+
45+
/** Specialization info for members of implicit instantiations
46+
*/
47+
struct SpecializationInfo
48+
: Info
49+
{
50+
/** The template arguments the parent template is specialized for */
51+
std::vector<TArg> Args;
52+
53+
/** ID of the template to which the arguments pertain */
54+
SymbolID Primary = SymbolID::zero;
55+
56+
/** The specialized members.
57+
58+
A specialized member `C` may itself be a `SpecializationInfo`
59+
if any of its members `M` are explicitly specialized for an implicit
60+
instantiation of `C`.
61+
*/
62+
std::vector<SpecializedMember> Members;
63+
64+
static constexpr InfoKind kind_id = InfoKind::Specialization;
65+
66+
SpecializationInfo(
67+
SymbolID ID = SymbolID::zero)
68+
: Info(InfoKind::Specialization, ID)
69+
{
70+
}
71+
};
72+
73+
} // mrdox
74+
} // clang
75+
76+
#endif

include/mrdox/Metadata/Template.hpp

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -195,54 +195,6 @@ struct TArg
195195

196196
// ----------------------------------------------------------------
197197

198-
/** Information pertaining to member specializations.
199-
200-
This structure is stored in the `TemplateInfo` corresponding to the
201-
outermost specialized template. If the explicitly specialized
202-
member is itself a member of a nested template, the `SpecializationInfo`
203-
which stores the arguments for the parent template will additionally
204-
store a pointer to the SpecializationInfo for the nested template,
205-
recursively. Each `SpecializationInfo` node contains a vector of
206-
`SymbolID` pairs `(specialized, primary)`, where `specialized` is the
207-
replacement definition of `primary` for the given set of template
208-
arguments of its parent template(s).
209-
*/
210-
#if 0
211-
struct SpecializationInfo
212-
{
213-
/** The template arguments the parent template is specialized for */
214-
std::vector<TArg> Args;
215-
216-
/** ID of the template to which the arguments pertain */
217-
SymbolID Template;
218-
219-
/** SpecializationInfo for nested templates which are also specialized */
220-
std::vector<SpecializationInfo> Nested;
221-
222-
/** SymbolID pairs of any specialized members.
223-
the first element is the ID of the original member (i.e. member that is replaced)
224-
the second element is the ID of the specialized member (i.e. the replacement)
225-
*/
226-
std::vector<std::pair<SymbolID, SymbolID>> Members;
227-
};
228-
#endif
229-
struct SpecializationInfo
230-
{
231-
/** The template arguments the parent template is specialized for */
232-
std::vector<TArg> Args;
233-
234-
/** ID of the template to which the arguments pertain */
235-
SymbolID Primary;
236-
237-
/** SpecializationInfo for nested templates which are also specialized */
238-
std::vector<SpecializationInfo> Nested;
239-
240-
/** SymbolID pairs of any specialized members.
241-
the first element is the ID of the original member (i.e. member that is replaced)
242-
the second element is the ID of the specialized member (i.e. the replacement)
243-
*/
244-
std::vector<std::pair<SymbolID, SymbolID>> Members;
245-
};
246198

247199
// ----------------------------------------------------------------
248200

include/mrdox/MetadataFwd.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ struct RecordScope;
4343
struct Param;
4444
struct Reference;
4545
struct Scope;
46+
struct SpecializationInfo;
47+
struct SpecializedMember;
4648
struct SymbolInfo;
4749
struct TypeInfo;
4850
struct TypedefInfo;

source/-XML/CXXTags.hpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,28 @@ namespace clang {
3131
namespace mrdox {
3232
namespace xml {
3333

34-
constexpr llvm::StringRef accessTagName = "access";
35-
constexpr llvm::StringRef aliasTagName = "alias";
36-
constexpr llvm::StringRef attributeTagName = "attr";
37-
constexpr llvm::StringRef baseTagName = "base";
38-
constexpr llvm::StringRef classTagName = "class";
39-
constexpr llvm::StringRef dataMemberTagName = "data";
40-
constexpr llvm::StringRef javadocTagName = "doc";
41-
constexpr llvm::StringRef enumTagName = "enum";
42-
constexpr llvm::StringRef friendTagName = "friend";
43-
constexpr llvm::StringRef functionTagName = "function";
44-
constexpr llvm::StringRef interfaceTagName = "interface";
45-
constexpr llvm::StringRef namespaceTagName = "namespace";
46-
constexpr llvm::StringRef paramTagName = "param";
47-
constexpr llvm::StringRef returnTagName = "return";
48-
constexpr llvm::StringRef structTagName = "struct";
49-
constexpr llvm::StringRef targTagName = "targ";
50-
constexpr llvm::StringRef templateTagName = "template";
51-
constexpr llvm::StringRef tparamTagName = "tparam";
52-
constexpr llvm::StringRef typedefTagName = "typedef";
53-
constexpr llvm::StringRef unionTagName = "union";
54-
constexpr llvm::StringRef varTagName = "variable";
34+
constexpr llvm::StringRef accessTagName = "access";
35+
constexpr llvm::StringRef aliasTagName = "alias";
36+
constexpr llvm::StringRef attributeTagName = "attr";
37+
constexpr llvm::StringRef baseTagName = "base";
38+
constexpr llvm::StringRef classTagName = "class";
39+
constexpr llvm::StringRef dataMemberTagName = "data";
40+
constexpr llvm::StringRef javadocTagName = "doc";
41+
constexpr llvm::StringRef enumTagName = "enum";
42+
constexpr llvm::StringRef friendTagName = "friend";
43+
constexpr llvm::StringRef functionTagName = "function";
44+
constexpr llvm::StringRef interfaceTagName = "interface";
45+
constexpr llvm::StringRef namespaceTagName = "namespace";
46+
constexpr llvm::StringRef paramTagName = "param";
47+
constexpr llvm::StringRef returnTagName = "return";
48+
constexpr llvm::StringRef structTagName = "struct";
49+
constexpr llvm::StringRef specializationTagName = "specialization";
50+
constexpr llvm::StringRef targTagName = "targ";
51+
constexpr llvm::StringRef templateTagName = "template";
52+
constexpr llvm::StringRef tparamTagName = "tparam";
53+
constexpr llvm::StringRef typedefTagName = "typedef";
54+
constexpr llvm::StringRef unionTagName = "union";
55+
constexpr llvm::StringRef varTagName = "variable";
5556

5657
constexpr llvm::StringRef getNameForValue(...)
5758
{

source/-XML/XMLWriter.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ visit(
253253
return writeVar(I);
254254
}
255255

256+
bool
257+
XMLWriter::
258+
visit(
259+
SpecializationInfo const& I)
260+
{
261+
return writeSpecialization(I);
262+
}
263+
256264
//------------------------------------------------
257265

258266
bool
@@ -586,6 +594,26 @@ closeTemplate(
586594
tags_.close(templateTagName);
587595
}
588596

597+
bool
598+
XMLWriter::
599+
writeSpecialization(
600+
const SpecializationInfo& I)
601+
{
602+
tags_.open(specializationTagName, {
603+
{I.id},
604+
{"primary", toString(I.Primary) }
605+
});
606+
607+
for(const TArg& targ : I.Args)
608+
writeTemplateArg(targ, tags_);
609+
610+
if(! corpus_.traverse(*this, I))
611+
return false;
612+
613+
tags_.close(specializationTagName);
614+
615+
return true;
616+
}
589617

590618
//------------------------------------------------
591619

source/-XML/XMLWriter.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class XMLWriter
6464
bool visit(TypedefInfo const&) override;
6565
bool visit(EnumInfo const&) override;
6666
bool visit(VarInfo const&) override;
67+
bool visit(SpecializationInfo const&) override;
6768

6869
bool visit(MemberEnum const&, Access) override;
6970
bool visit(MemberFunction const&, Access) override;
@@ -78,6 +79,7 @@ class XMLWriter
7879
bool writeTypedef(TypedefInfo const&, Access const* access = nullptr);
7980
bool writeField(FieldInfo const&, Access const* access = nullptr);
8081
bool writeVar(VarInfo const&, Access const* access = nullptr);
82+
bool writeSpecialization(const SpecializationInfo& I);
8183

8284
void writeInfo(Info const&);
8385
void writeSymbol(SymbolInfo const& I);

0 commit comments

Comments
 (0)