From d68d13341bbe6d4b122a01e8c038ed0773a58a68 Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Thu, 30 May 2024 09:40:40 -0400 Subject: [PATCH] chore: build NameInfo using explicitly provided nested-name-specifier --- .../asciidoc/partials/name-info.adoc.hbs | 4 +- src/lib/AST/ASTVisitor.cpp | 42 +++++------- .../class-template-specializations-1.xml | 68 +++++++++---------- .../class-template-specializations-3.xml | 20 +++--- .../old-tests/dependency-propagation.xml | 4 +- .../implicit-instantiation-member-ref.xml | 12 ++-- test-files/old-tests/record-data.xml | 2 +- test-files/old-tests/ref.xml | 2 +- 8 files changed, 73 insertions(+), 81 deletions(-) diff --git a/share/mrdocs/addons/generator/asciidoc/partials/name-info.adoc.hbs b/share/mrdocs/addons/generator/asciidoc/partials/name-info.adoc.hbs index 51d6ad9cf..2bcc287da 100644 --- a/share/mrdocs/addons/generator/asciidoc/partials/name-info.adoc.hbs +++ b/share/mrdocs/addons/generator/asciidoc/partials/name-info.adoc.hbs @@ -1,7 +1,5 @@ {{#if prefix~}} -{{#unless (or (contains @root.symbol.namespace prefix.symbol) (eq @root.symbol prefix.symbol))~}} {{>name-info prefix nolink=nolink~}}:: -{{~/unless~}} -{{/if~}} +{{~/if~}} {{#if (and symbol.ref (not nolink))}}xref:{{symbol.ref}}[{{name}}]{{else~}} {{name}}{{/if}}{{#if args}}{{>template-args args=args nolink=nolink}}{{/if~}} \ No newline at end of file diff --git a/src/lib/AST/ASTVisitor.cpp b/src/lib/AST/ASTVisitor.cpp index 93aca8449..ab268c08c 100644 --- a/src/lib/AST/ASTVisitor.cpp +++ b/src/lib/AST/ASTVisitor.cpp @@ -2180,7 +2180,14 @@ class ASTVisitor return; I.Name = extractName(D); - I.AliasedSymbol = buildNameInfo(D->getAliasedNamespace()); + auto& Underlying = I.AliasedSymbol = + std::make_unique(); + + NamedDecl* Aliased = D->getAliasedNamespace(); + Underlying->Name = Aliased->getIdentifier()->getName(); + getDependencyID(Aliased, Underlying->id); + if(NestedNameSpecifier* NNS = D->getQualifier()) + Underlying->Prefix = buildNameInfo(NNS); getParentNamespaces(I, D); } @@ -3074,7 +3081,7 @@ class TerminalTypeVisitor unsigned Quals_ = 0; bool IsPack_ = false; - const NestedNameSpecifier* NNS_ = nullptr; + const NestedNameSpecifier* NNS_; Derived& getDerived() { @@ -3361,8 +3368,10 @@ class TerminalTypeVisitor public: TerminalTypeVisitor( - ASTVisitor& Visitor) + ASTVisitor& Visitor, + const NestedNameSpecifier* NNS = nullptr) : Visitor_(Visitor) + , NNS_(NNS) { } @@ -3462,10 +3471,7 @@ class TypeInfoBuilder std::unique_ptr* Inner = &Result; public: - TypeInfoBuilder(ASTVisitor& Visitor) - : TerminalTypeVisitor(Visitor) - { - } + using TerminalTypeVisitor::TerminalTypeVisitor; std::unique_ptr result() { @@ -3615,8 +3621,6 @@ class TypeInfoBuilder V.getDependencyID(V.getInstantiatedFrom(D), Name->id); if(NNS) Name->Prefix = V.buildNameInfo(NNS); - else - Name->Prefix = V.buildNameInfo(V.getParentDecl(D)); V.buildTemplateArgs(Name->TemplateArgs, *TArgs); I->Name = std::move(Name); @@ -3629,8 +3633,6 @@ class TypeInfoBuilder V.getDependencyID(V.getInstantiatedFrom(D), Name->id); if(NNS) Name->Prefix = V.buildNameInfo(NNS); - else - Name->Prefix = V.buildNameInfo(V.getParentDecl(D)); I->Name = std::move(Name); } *Inner = std::move(I); @@ -3661,10 +3663,7 @@ class NameInfoBuilder std::unique_ptr Result; public: - NameInfoBuilder(ASTVisitor& Visitor) - : TerminalTypeVisitor(Visitor) - { - } + using TerminalTypeVisitor::TerminalTypeVisitor; std::unique_ptr result() { @@ -3752,8 +3751,6 @@ class NameInfoBuilder } if(NNS) Result->Prefix = V.buildNameInfo(NNS); - else - Result->Prefix = V.buildNameInfo(V.getParentDecl(D)); } }; @@ -3770,7 +3767,7 @@ buildNameInfo( return I; if(const Type* T = NNS->getAsType()) { - NameInfoBuilder Builder(*this); + NameInfoBuilder Builder(*this, NNS->getPrefix()); Builder.Visit(T); I = Builder.result(); } @@ -3785,17 +3782,14 @@ buildNameInfo( I = std::make_unique(); I->Name = ND->getIdentifier()->getName(); getDependencyID(ND, I->id); - I->Prefix = buildNameInfo(getParentDecl(ND), extract_mode); + I->Prefix = buildNameInfo(NNS->getPrefix(), extract_mode); } else if(const NamespaceAliasDecl* NAD = NNS->getAsNamespaceAlias()) { I = std::make_unique(); I->Name = NAD->getIdentifier()->getName(); - const NamespaceDecl* ND = NAD->getNamespace(); - // KRYSTIAN FIXME: this should use the SymbolID of the namespace alias - // once we add an Info kind to represent them - getDependencyID(ND, I->id); - I->Prefix = buildNameInfo(getParentDecl(ND), extract_mode); + getDependencyID(NAD, I->id); + I->Prefix = buildNameInfo(NNS->getPrefix(), extract_mode); } return I; } diff --git a/test-files/old-tests/class-template-specializations-1.xml b/test-files/old-tests/class-template-specializations-1.xml index 2b824a5f8..6bf84eab4 100644 --- a/test-files/old-tests/class-template-specializations-1.xml +++ b/test-files/old-tests/class-template-specializations-1.xml @@ -474,55 +474,55 @@ - + - + - + - + - + - + - + - + - + @@ -552,61 +552,61 @@ - + - + - + - + - + - + - + - + - + - + @@ -633,26 +633,26 @@ - + - + - + - + - + - +