Skip to content

Commit 753823e

Browse files
authored
feat: support using directives, using declarations and namespace aliases
1 parent 0655c84 commit 753823e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+939
-4
lines changed

include/mrdocs/Metadata.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// All headers related to
1818
// metadata extracted from AST
1919

20+
#include <mrdocs/Metadata/Alias.hpp>
2021
#include <mrdocs/Metadata/Enum.hpp>
2122
#include <mrdocs/Metadata/Enumerator.hpp>
2223
#include <mrdocs/Metadata/Expression.hpp>
@@ -37,6 +38,7 @@
3738
#include <mrdocs/Metadata/Template.hpp>
3839
#include <mrdocs/Metadata/Type.hpp>
3940
#include <mrdocs/Metadata/Typedef.hpp>
41+
#include <mrdocs/Metadata/Using.hpp>
4042
#include <mrdocs/Metadata/Variable.hpp>
4143

4244
#endif

include/mrdocs/Metadata/Alias.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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) 2024 Fernando Pelliccioni ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdocs
9+
//
10+
11+
#ifndef MRDOCS_API_METADATA_ALIAS_HPP
12+
#define MRDOCS_API_METADATA_ALIAS_HPP
13+
14+
#include <mrdocs/Platform.hpp>
15+
#include <mrdocs/Metadata/Info.hpp>
16+
#include <mrdocs/Metadata/Source.hpp>
17+
#include <mrdocs/Metadata/Type.hpp>
18+
#include <utility>
19+
20+
namespace clang {
21+
namespace mrdocs {
22+
23+
/** Info for namespace aliases.
24+
*/
25+
struct AliasInfo
26+
: IsInfo<InfoKind::Alias>
27+
, SourceInfo
28+
{
29+
/** The aliased symbol. */
30+
std::unique_ptr<NameInfo> AliasedSymbol;
31+
32+
//--------------------------------------------
33+
34+
explicit AliasInfo(SymbolID ID) noexcept
35+
: IsInfo(ID)
36+
{
37+
}
38+
};
39+
40+
} // mrdocs
41+
} // clang
42+
43+
#endif

include/mrdocs/Metadata/Info.hpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
namespace clang {
2828
namespace mrdocs {
2929

30+
struct AliasInfo;
3031
struct NamespaceInfo;
3132
struct RecordInfo;
3233
struct FunctionInfo;
@@ -38,6 +39,7 @@ struct SpecializationInfo;
3839
struct FriendInfo;
3940
struct EnumeratorInfo;
4041
struct GuideInfo;
42+
struct UsingInfo;
4143

4244
/** Info variant discriminator
4345
*/
@@ -64,7 +66,11 @@ enum class InfoKind
6466
/// The symbol is an enumerator
6567
Enumerator,
6668
/// The symbol is a deduction guide
67-
Guide
69+
Guide,
70+
/// The symbol is a namespace alias
71+
Alias,
72+
/// The symbol is a using declaration and using directive
73+
Using,
6874
};
6975

7076
/** Return the name of the InfoKind as a string.
@@ -177,6 +183,12 @@ struct MRDOCS_VISIBLE
177183

178184
/// Determine if this symbol is a deduction guide.
179185
constexpr bool isGuide() const noexcept { return Kind == InfoKind::Guide; }
186+
187+
/// Determine if this symbol is a namespace alias.
188+
constexpr bool isAlias() const noexcept { return Kind == InfoKind::Alias; }
189+
190+
/// Determine if this symbol is a using declaration or using directive.
191+
constexpr bool isUsing() const noexcept { return Kind == InfoKind::Using; }
180192
};
181193

182194
//------------------------------------------------
@@ -230,6 +242,12 @@ struct IsInfo : Info
230242
/// Determine if this symbol is a deduction guide.
231243
static constexpr bool isGuide() noexcept { return K == InfoKind::Guide; }
232244

245+
/// Determine if this symbol is a namespace alias.
246+
static constexpr bool isAlias() noexcept { return K == InfoKind::Alias; }
247+
248+
/// Determine if this symbol is a using declaration or using directive.
249+
static constexpr bool isUsing() noexcept { return K == InfoKind::Using; }
250+
233251
protected:
234252
constexpr explicit IsInfo(SymbolID ID)
235253
: Info(K, ID)
@@ -282,6 +300,10 @@ visit(
282300
return visitor.template visit<EnumeratorInfo>();
283301
case InfoKind::Guide:
284302
return visitor.template visit<GuideInfo>();
303+
case InfoKind::Alias:
304+
return visitor.template visit<AliasInfo>();
305+
case InfoKind::Using:
306+
return visitor.template visit<UsingInfo>();
285307
default:
286308
MRDOCS_UNREACHABLE();
287309
}

include/mrdocs/Metadata/Interface.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ struct Tranche
3737
std::vector<SymbolID> Variables;
3838
std::vector<SymbolID> Friends;
3939
std::vector<SymbolID> Guides;
40+
std::vector<SymbolID> Aliases;
41+
std::vector<SymbolID> Usings;
4042

4143
ScopeInfo Overloads;
4244
ScopeInfo StaticOverloads;

include/mrdocs/Metadata/Using.hpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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) 2024 Fernando Pelliccioni ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdocs
9+
//
10+
11+
#ifndef MRDOCS_API_METADATA_USING_HPP
12+
#define MRDOCS_API_METADATA_USING_HPP
13+
14+
#include <mrdocs/Platform.hpp>
15+
#include <mrdocs/Metadata/Info.hpp>
16+
#include <mrdocs/Metadata/Source.hpp>
17+
#include <mrdocs/Metadata/Type.hpp>
18+
#include <vector>
19+
#include <utility>
20+
21+
namespace clang {
22+
namespace mrdocs {
23+
24+
enum class UsingClass
25+
{
26+
Normal = 0, // using
27+
Typename, // using typename
28+
Enum, // using enum
29+
Namespace // using namespace (using directive)
30+
};
31+
32+
static constexpr
33+
std::string_view
34+
toString(UsingClass const& value)
35+
{
36+
switch (value)
37+
{
38+
case UsingClass::Normal: return "normal";
39+
case UsingClass::Typename: return "typename";
40+
case UsingClass::Enum: return "enum";
41+
case UsingClass::Namespace: return "namespace";
42+
}
43+
return "unknown";
44+
}
45+
46+
/** Info for using declarations and directives.
47+
*/
48+
struct UsingInfo
49+
: IsInfo<InfoKind::Using>,
50+
SourceInfo
51+
{
52+
/** The kind of using declaration/directive. */
53+
UsingClass Class = UsingClass::Normal;
54+
55+
/** The symbols being "used". */
56+
std::vector<SymbolID> UsingSymbols;
57+
58+
/** The qualifier for a using declaration/directive. */
59+
std::unique_ptr<NameInfo> Qualifier;
60+
61+
//--------------------------------------------
62+
63+
explicit UsingInfo(SymbolID ID) noexcept
64+
: IsInfo(ID)
65+
{
66+
}
67+
};
68+
69+
} // mrdocs
70+
} // clang
71+
72+
#endif

include/mrdocs/MetadataFwd.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ enum class OperatorKind;
3535
enum class ReferenceKind;
3636
enum class StorageClassKind;
3737

38+
struct AliasInfo;
3839
struct BaseInfo;
3940
struct EnumInfo;
4041
struct EnumeratorInfo;
@@ -56,6 +57,7 @@ struct TypeInfo;
5657
struct TypedefInfo;
5758
struct VariableInfo;
5859
struct VerbatimBlock;
60+
struct UsingInfo;
5961

6062
struct ExprInfo;
6163
template<typename T>

include/mrdocs/mrdocs.natvis

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<AlternativeType Name="clang::mrdocs::FriendInfo"/>
3434
<AlternativeType Name="clang::mrdocs::EnumeratorInfo"/>
3535
<AlternativeType Name="clang::mrdocs::GuideInfo"/>
36+
<AlternativeType Name="clang::mrdocs::AliasInfo"/>
37+
<AlternativeType Name="clang::mrdocs::UsingInfo"/>
3638

3739
<DisplayString>{Kind,en} {Name} (ID = {id})</DisplayString>
3840

@@ -49,6 +51,8 @@
4951
<ExpandedItem Condition="Kind == InfoKind::Friend">(FriendInfo*)this,view(noinherit)</ExpandedItem>
5052
<ExpandedItem Condition="Kind == InfoKind::Enumerator">(EnumeratorInfo*)this,view(noinherit)</ExpandedItem>
5153
<ExpandedItem Condition="Kind == InfoKind::Guide">(GuideInfo*)this,view(noinherit)</ExpandedItem>
54+
<ExpandedItem Condition="Kind == InfoKind::Alias">(AliasInfo*)this,view(noinherit)</ExpandedItem>
55+
<ExpandedItem Condition="Kind == InfoKind::Using">(UsingInfo*)this,view(noinherit)</ExpandedItem>
5256
</Expand>
5357
</Type>
5458

mrdocs.rnc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66
# Copyright (c) 2023 Klemens Morgenstern ([email protected])
77
# Copyright (c) 2023 Krystian Stasiowski ([email protected])
8+
# Copyright (c) 2024 Fernando Pelliccioni ([email protected])
89
#
910
# Official repository: https://github.com/cppalliance/mrdocs
1011
#
@@ -212,6 +213,37 @@ grammar
212213

213214
#---------------------------------------------
214215

216+
Alias =
217+
element alias
218+
{
219+
Name,
220+
Access ?,
221+
ID,
222+
Location *,
223+
Javadoc ?,
224+
element aliased
225+
{
226+
attribute name { text },
227+
attribute id { text }
228+
}
229+
}
230+
231+
#---------------------------------------------
232+
233+
Using =
234+
element using
235+
{
236+
Access ?,
237+
ID,
238+
Location *,
239+
Javadoc ?,
240+
attribute class { "using" | "using typename" | "using enum" | "using namespace" },
241+
attribute qualifier { text } ?,
242+
element named { ID } *
243+
}
244+
245+
#---------------------------------------------
246+
215247
Symbol =
216248
(
217249
attribute Tag { text },
@@ -301,6 +333,8 @@ grammar
301333
Var |
302334
Guide |
303335
Template |
336+
Alias |
337+
Using |
304338
Specialization
305339
)*
306340

@@ -315,6 +349,8 @@ grammar
315349
Guide |
316350
Template |
317351
Friend |
352+
Alias |
353+
Using |
318354
Specialization
319355
)*
320356

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
namespace {{symbol.name}} = {{>name-info symbol.aliasedSymbol}}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{{#if (eq symbol.class "namespace")}}
2+
using namespace {{#if symbol.qualifier}}{{>name-info symbol.qualifier}}::{{/if}}{{symbol.name}}
3+
{{else}}
4+
using {{#if (eq symbol.class "typename")}}typename {{/if}}{{#if (eq symbol.class "enum")}}enum {{/if}}{{#if symbol.qualifier}}{{>name-info symbol.qualifier}}::{{/if}}{{symbol.name}}
5+
{{/if}}

0 commit comments

Comments
 (0)