Skip to content

Commit 67fe17e

Browse files
committed
refactor: UsingInfo uses introduced NameInfo
1 parent 02d81dc commit 67fe17e

File tree

5 files changed

+69
-19
lines changed

5 files changed

+69
-19
lines changed

include/mrdocs/Metadata/Info/NamespaceAlias.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ namespace clang::mrdocs {
2323
struct NamespaceAliasInfo final
2424
: InfoCommonBase<InfoKind::NamespaceAlias>
2525
{
26-
/** The aliased symbol. */
26+
/** The aliased symbol.
27+
28+
This is another namespace that might or might
29+
not be in the same project.
30+
*/
2731
Polymorphic<NameInfo> AliasedSymbol;
2832

2933
//--------------------------------------------

include/mrdocs/Metadata/Info/Using.hpp

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,67 @@ tag_invoke(
5555

5656

5757
/** Info for using declarations.
58+
59+
For instance, the following code:
60+
61+
@code
62+
using A::f; // where f is a function in namespace A
63+
@endcode
64+
65+
would be represented by a `UsingInfo` object.
66+
67+
Using-declarations can be used to introduce namespace
68+
members into other namespaces and block scopes, or to
69+
introduce base class members into derived class definitions,
70+
or to introduce enumerators into namespaces, block,
71+
and class scopes.
72+
5873
*/
5974
struct UsingInfo final
6075
: InfoCommonBase<InfoKind::Using>
6176
{
62-
/** The kind of using declaration.
77+
/** The using declaration.
6378
*/
6479
UsingClass Class = UsingClass::Normal;
6580

66-
/** The symbols being "used".
67-
*/
68-
std::vector<SymbolID> UsingSymbols;
81+
/** The symbol being introduced.
82+
83+
This is the symbol that is being "used" or
84+
introduced into the current scope.
85+
86+
Note that this can be a qualified name, such as
87+
`A::f` in the example above.
88+
*/
89+
Polymorphic<NameInfo> IntroducedName;
90+
91+
/** The shadow declarations.
92+
93+
A using declaration can refer to and introduce
94+
multiple symbols into the current context.
95+
96+
These multiple symbols are considered a special
97+
case of declarations: "shadow declarations".
98+
99+
This typically happens when there are
100+
conflicting symbol names in the scope
101+
being introduced, such as:
102+
103+
* Overloaded functions: the base namespace contains
104+
overloaded functions.
105+
* Name conflicts: the base scope contains a function
106+
and a type.
107+
* Enums: a using enum declaration can refer to
108+
multiple enumerators.
109+
110+
Also note that more shadow declarations can be
111+
introduced later in the same scope, after
112+
the using declaration.
69113
70-
/** The qualifier for a using declaration.
114+
The shadow declarations here are only those
115+
that are shadowed at the point where the
116+
using declaration is located.
71117
*/
72-
Polymorphic<NameInfo> Qualifier;
118+
std::vector<SymbolID> ShadowDeclarations;
73119

74120
//--------------------------------------------
75121

@@ -94,8 +140,8 @@ tag_invoke(
94140
{
95141
tag_invoke(t, io, dynamic_cast<Info const&>(I), domCorpus);
96142
io.map("usingClass", I.Class);
97-
io.map("shadows", dom::LazyArray(I.UsingSymbols, domCorpus));
98-
io.map("qualifier", I.Qualifier);
143+
io.map("shadows", dom::LazyArray(I.ShadowDeclarations, domCorpus));
144+
io.map("qualifier", I.IntroducedName);
99145
}
100146

101147
/** Map the UsingInfo to a @ref dom::Value object.

src/lib/Gen/xml/XMLWriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,9 @@ XMLWriter::
471471
}
472472

473473
std::string qualifierStr;
474-
if (I.Qualifier)
474+
if (I.IntroducedName)
475475
{
476-
qualifierStr = toString(*I.Qualifier);
476+
qualifierStr = toString(*I.IntroducedName);
477477
}
478478

479479
constexpr std::string_view usingTagName = "using";
@@ -488,7 +488,7 @@ XMLWriter::
488488

489489
writeJavadoc(I.javadoc);
490490

491-
for (auto const& id : I.UsingSymbols)
491+
for (auto const& id : I.ShadowDeclarations)
492492
tags_.write("named", {}, { id });
493493

494494
tags_.close(usingTagName);

src/lib/Metadata/Finalizers/JavadocFinalizer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,13 @@ finalizeInfoData(InfoTy& I)
744744
{
745745
finalize(I.AliasedSymbol);
746746
}
747-
if constexpr (requires { I.Qualifier; })
747+
if constexpr (requires { I.IntroducedName; })
748748
{
749-
finalize(I.Qualifier);
749+
finalize(I.IntroducedName);
750750
}
751-
if constexpr (requires { I.UsingSymbols; })
751+
if constexpr (requires { I.ShadowDeclarations; })
752752
{
753-
finalize(I.UsingSymbols);
753+
finalize(I.ShadowDeclarations);
754754
}
755755
if constexpr (requires { I.Deduced; })
756756
{

src/lib/Metadata/Info/Using.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ merge(UsingInfo& I, UsingInfo&& Other)
3939
{
4040
MRDOCS_ASSERT(canMerge(I, Other));
4141
merge(I.asInfo(), std::move(Other.asInfo()));
42-
reduceSymbolIDs(I.UsingSymbols, std::move(Other.UsingSymbols));
42+
reduceSymbolIDs(I.ShadowDeclarations, std::move(Other.ShadowDeclarations));
4343
if (I.Class == UsingClass::Normal)
4444
{
4545
I.Class = Other.Class;
4646
}
47-
if (!I.Qualifier)
47+
if (!I.IntroducedName)
4848
{
49-
I.Qualifier = std::move(Other.Qualifier);
49+
I.IntroducedName = std::move(Other.IntroducedName);
5050
}
5151
}
5252

0 commit comments

Comments
 (0)