Skip to content

Commit aa4e6ff

Browse files
committed
feat: represent possibly-qualified names with NameInfo
1 parent 0faf7a9 commit aa4e6ff

File tree

15 files changed

+1123
-505
lines changed

15 files changed

+1123
-505
lines changed

include/mrdocs/Metadata.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <mrdocs/Metadata/Info.hpp>
2828
#include <mrdocs/Metadata/Interface.hpp>
2929
#include <mrdocs/Metadata/Javadoc.hpp>
30+
#include <mrdocs/Metadata/Name.hpp>
3031
#include <mrdocs/Metadata/Namespace.hpp>
3132
#include <mrdocs/Metadata/Overloads.hpp>
3233
#include <mrdocs/Metadata/Record.hpp>

include/mrdocs/Metadata/Name.hpp

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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/mrdocs
9+
//
10+
11+
#ifndef MRDOCS_API_METADATA_NAME_HPP
12+
#define MRDOCS_API_METADATA_NAME_HPP
13+
14+
#include <mrdocs/Platform.hpp>
15+
#include <mrdocs/Metadata/Info.hpp>
16+
#include <mrdocs/Metadata/Type.hpp>
17+
#include <mrdocs/Metadata/Template.hpp>
18+
#include <memory>
19+
20+
namespace clang {
21+
namespace mrdocs {
22+
23+
enum class NameKind
24+
{
25+
Identifier = 1, // for bitstream
26+
Specialization
27+
};
28+
29+
MRDOCS_DECL
30+
dom::String
31+
toString(NameKind kind) noexcept;
32+
33+
/** Represents a (possibly qualified) symbol name.
34+
*/
35+
struct NameInfo
36+
{
37+
/** The kind of name this is.
38+
*/
39+
NameKind Kind;
40+
41+
/** The SymbolID of the named symbol, if it exists.
42+
*/
43+
SymbolID id = SymbolID::invalid;
44+
45+
/** The unqualified name.
46+
*/
47+
std::string Name;
48+
49+
/** The parent name info, if any.
50+
*/
51+
std::unique_ptr<NameInfo> Prefix;
52+
53+
constexpr
54+
NameInfo() noexcept
55+
: NameInfo(NameKind::Identifier)
56+
{
57+
}
58+
59+
constexpr
60+
NameInfo(NameKind kind) noexcept
61+
: Kind(kind)
62+
{
63+
}
64+
65+
virtual ~NameInfo() = default;
66+
};
67+
68+
/** Represents a (possibly qualified) symbol name with template arguments.
69+
*/
70+
struct SpecializationNameInfo
71+
: NameInfo
72+
{
73+
/** The template arguments.
74+
*/
75+
std::vector<std::unique_ptr<TArg>> TemplateArgs;
76+
77+
constexpr
78+
SpecializationNameInfo() noexcept
79+
: NameInfo(NameKind::Specialization)
80+
{
81+
}
82+
};
83+
84+
template<
85+
class NameInfoTy,
86+
class Fn,
87+
class... Args>
88+
requires std::derived_from<NameInfoTy, NameInfo>
89+
decltype(auto)
90+
visit(
91+
NameInfoTy& info,
92+
Fn&& fn,
93+
Args&&... args)
94+
{
95+
auto visitor = makeVisitor<NameInfo>(
96+
info, std::forward<Fn>(fn),
97+
std::forward<Args>(args)...);
98+
switch(info.Kind)
99+
{
100+
case NameKind::Identifier:
101+
return visitor.template visit<NameInfo>();
102+
case NameKind::Specialization:
103+
return visitor.template visit<SpecializationNameInfo>();
104+
default:
105+
MRDOCS_UNREACHABLE();
106+
}
107+
}
108+
109+
} // mrdocs
110+
} // clang
111+
112+
#endif

include/mrdocs/Metadata/Type.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ struct BuiltinTypeInfo
122122
{
123123
QualifierKind CVQualifiers = QualifierKind::None;
124124
std::string Name;
125+
126+
std::unique_ptr<NameInfo> Name_;
125127
};
126128

127129
struct TagTypeInfo
@@ -131,6 +133,8 @@ struct TagTypeInfo
131133
std::unique_ptr<TypeInfo> ParentType;
132134
std::string Name;
133135
SymbolID id = SymbolID::invalid;
136+
137+
std::unique_ptr<NameInfo> Name_;
134138
};
135139

136140
struct SpecializationTypeInfo
@@ -141,6 +145,8 @@ struct SpecializationTypeInfo
141145
std::string Name;
142146
SymbolID id = SymbolID::invalid;
143147
std::vector<std::unique_ptr<TArg>> TemplateArgs;
148+
149+
std::unique_ptr<NameInfo> Name_;
144150
};
145151

146152
struct DecltypeTypeInfo

include/mrdocs/MetadataFwd.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct Info;
4646
class Javadoc;
4747
struct Location;
4848
struct NamespaceInfo;
49+
struct NameInfo;
4950
struct RecordInfo;
5051
struct Param;
5152
struct SpecializationInfo;

share/mrdocs/addons/generator/asciidoc/partials/declarator-before.adoc.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
{{#if cv-qualifiers~}}
1313
{{#if pointee-type}} {{cv-qualifiers}}{{else}}{{cv-qualifiers}} {{/if~}}
1414
{{/if~}}
15-
{{#if (and symbol (not parent-type))}}{{>qualified-path symbol=symbol.parent nolink=nolink}}{{/if~}}
15+
{{#if prefix~}}{{>name-info prefix nolink=nolink}}{{/if~}}
16+
{{!-- {{#if (and symbol (not parent-type))}}{{>qualified-path symbol=symbol.parent nolink=nolink}}{{/if~}} --~}}
1617
{{#if (and symbol (not nolink))~}}
1718
xref:{{symbol.ref}}[{{name}}]
1819
{{~else if name}}{{name~}}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{#unless (or (contains @root.symbol.namespace symbol) (eq @root.symbol symbol))~}}
2+
{{#if prefix~}}
3+
{{>name-info prefix nolink=nolink~}}
4+
{{else~}}
5+
{{/if~}}
6+
{{#if (and symbol.ref (not nolink))}}xref:{{symbol.ref}}[{{name}}]{{else~}}
7+
{{name}}{{/if}}{{#if args}}{{>template-args args=args nolink=nolink}}{{/if}}::
8+
{{~/unless}}

0 commit comments

Comments
 (0)