Skip to content

Commit

Permalink
fix: render using-directives correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed May 30, 2024
1 parent ed4d49b commit 9b1ffc5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{#if (eq symbol.class "namespace")}}
using namespace {{#if symbol.qualifier}}{{>name-info symbol.qualifier}}::{{/if}}{{symbol.name}}
{{else}}
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}}
{{#if (eq symbol.class "namespace")~}}
using namespace {{>name-info symbol.nominatedSymbol~}}
{{else~}}
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~}}
{{/if}}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{!-- alias --}}
= {{>nested-name-specifier symbol=symbol.parent}}{{symbol.name}}
= Namespace Alias {{>nested-name-specifier symbol=symbol.parent}}{{symbol.name}}

{{symbol.doc.brief}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{!-- symbols/using.adoc.hbs --}}
= Using {{#if (eq symbol.class "namespace")}}Directive: {{symbol.qualifier.name}}{{else}}Declaration: {{symbol.name}}{{/if}}
= Using {{#if (eq symbol.class "namespace")}}Directive{{else}}Declaration {{symbol.name}}{{/if}}

{{symbol.doc.brief}}

Expand Down
16 changes: 4 additions & 12 deletions src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2210,19 +2210,11 @@ class ASTVisitor
return;

I.Class = UsingClass::Namespace;
// KRYSTIAN FIXME: we treat using-directives as having no name,
// and we store the full name of the nominated namespace in
// Qualifier. we should probably rename the member accordingly
I.Qualifier = buildNameInfo(D->getNominatedNamespaceAsWritten());

if (D->getQualifier())
{
I.Qualifier = buildNameInfo(D->getQualifier());
}

if (NamedDecl* ND = D->getNominatedNamespace())
{
I.Name = extractName(ND);
SymbolID id;
getDependencyID(ND, id);
I.UsingSymbols.emplace_back(id);
}
getParentNamespaces(I, D);
}

Expand Down
8 changes: 6 additions & 2 deletions src/lib/Metadata/DomMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,13 @@ DomInfo<T>::construct() const
if constexpr(T::isUsing())
{
entries.emplace_back("class", toString(I_.Class));
entries.emplace_back("symbols", dom::newArray<DomSymbolArray>(I_.UsingSymbols, domCorpus_));
if (I_.Qualifier)
if (I_.Class == UsingClass::Namespace)
{
entries.emplace_back("nominatedSymbol", domCreate(I_.Qualifier, domCorpus_));
}
else
{
entries.emplace_back("symbols", dom::newArray<DomSymbolArray>(I_.UsingSymbols, domCorpus_));
entries.emplace_back("qualifier", domCreate(I_.Qualifier, domCorpus_));
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/lib/Support/SafeNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,9 @@ class SafeNames::Impl
}

if constexpr(T::isUsing()) {
MRDOCS_ASSERT(! t.Name.empty());
if (t.Class == UsingClass::Namespace) {
if (t.Class == UsingClass::Namespace)
return getReserved(t);
}
MRDOCS_ASSERT(! t.Name.empty());
return t.Name;
}

Expand Down

0 comments on commit 9b1ffc5

Please sign in to comment.