From 2ff3579d5dae85e79b501ca58df011b71a510bcf Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Wed, 13 Dec 2023 15:47:08 -0500 Subject: [PATCH] feat: replace (Builtin/Tag/Specialization)TypeInfo with NamedTypeInfo --- include/mrdocs/Metadata/Name.hpp | 15 +++- include/mrdocs/Metadata/Type.hpp | 59 +++----------- include/mrdocs/MetadataFwd.hpp | 1 + .../partials/declarator-before.adoc.hbs | 11 +-- .../asciidoc/partials/name-info.adoc.hbs | 9 +-- src/lib/AST/ASTVisitor.cpp | 80 +++++++++++-------- src/lib/AST/AnyBlock.hpp | 40 ++-------- src/lib/AST/BitcodeIDs.hpp | 2 - src/lib/AST/BitcodeWriter.cpp | 28 ++----- src/lib/Gen/xml/CXXTags.hpp | 24 +++--- src/lib/Lib/Lookup.cpp | 23 +----- src/lib/Metadata/DomMetadata.cpp | 16 +--- src/lib/Metadata/Finalize.cpp | 10 +-- src/lib/Metadata/Interface.cpp | 25 +----- src/lib/Metadata/Name.cpp | 68 ++++++++++++++++ src/lib/Metadata/Type.cpp | 64 +++++---------- 16 files changed, 199 insertions(+), 276 deletions(-) diff --git a/include/mrdocs/Metadata/Name.hpp b/include/mrdocs/Metadata/Name.hpp index 4b79a5d1d..15d100ef3 100644 --- a/include/mrdocs/Metadata/Name.hpp +++ b/include/mrdocs/Metadata/Name.hpp @@ -26,8 +26,8 @@ enum class NameKind Specialization }; -MRDOCS_DECL -dom::String +MRDOCS_DECL +dom::String toString(NameKind kind) noexcept; /** Represents a (possibly qualified) symbol name. @@ -41,7 +41,7 @@ struct NameInfo /** The SymbolID of the named symbol, if it exists. */ SymbolID id = SymbolID::invalid; - + /** The unqualified name. */ std::string Name; @@ -50,6 +50,9 @@ struct NameInfo */ std::unique_ptr Prefix; + constexpr bool isIdentifier() const noexcept { return Kind == NameKind::Identifier; } + constexpr bool isSpecialization() const noexcept { return Kind == NameKind::Specialization; } + constexpr NameInfo() noexcept : NameInfo(NameKind::Identifier) @@ -67,7 +70,7 @@ struct NameInfo /** Represents a (possibly qualified) symbol name with template arguments. */ -struct SpecializationNameInfo +struct SpecializationNameInfo : NameInfo { /** The template arguments. @@ -106,6 +109,10 @@ visit( } } +MRDOCS_DECL +std::string +toString(const NameInfo& N); + } // mrdocs } // clang diff --git a/include/mrdocs/Metadata/Type.hpp b/include/mrdocs/Metadata/Type.hpp index 75da21c28..bd6035f8d 100644 --- a/include/mrdocs/Metadata/Type.hpp +++ b/include/mrdocs/Metadata/Type.hpp @@ -37,9 +37,7 @@ MRDOCS_DECL dom::String toString(QualifierKind kind) noexcept; enum class TypeKind { - Builtin = 1, // for bitstream - Tag, - Specialization, + Named = 1, // for bitstream Decltype, LValueReference, RValueReference, @@ -63,9 +61,7 @@ struct TypeInfo constexpr virtual ~TypeInfo() = default; - constexpr bool isBuiltin() const noexcept { return Kind == TypeKind::Builtin ; } - constexpr bool isTag() const noexcept { return Kind == TypeKind::Tag; } - constexpr bool isSpecialization() const noexcept { return Kind == TypeKind::Specialization; } + constexpr bool isNamed() const noexcept { return Kind == TypeKind::Named; } constexpr bool isDecltype() const noexcept { return Kind == TypeKind::Decltype; } constexpr bool isLValueReference() const noexcept { return Kind == TypeKind::LValueReference; } constexpr bool isRValueReference() const noexcept { return Kind == TypeKind::RValueReference; } @@ -84,6 +80,10 @@ struct TypeInfo return nullptr; } + /** Return the symbol named by this type. + */ + SymbolID namedSymbol() const noexcept; + protected: constexpr TypeInfo( @@ -98,9 +98,7 @@ struct IsType : TypeInfo { static constexpr TypeKind kind_id = K; - static constexpr bool isBuiltin() noexcept { return K == TypeKind::Builtin; } - static constexpr bool isTag() noexcept { return K == TypeKind::Tag; } - static constexpr bool isSpecialization() noexcept { return K == TypeKind::Specialization; } + static constexpr bool isNamed() noexcept { return K == TypeKind::Named; } static constexpr bool isDecltype() noexcept { return K == TypeKind::Decltype; } static constexpr bool isLValueReference() noexcept { return K == TypeKind::LValueReference; } static constexpr bool isRValueReference() noexcept { return K == TypeKind::RValueReference; } @@ -117,36 +115,11 @@ struct IsType : TypeInfo } }; -struct BuiltinTypeInfo - : IsType -{ - QualifierKind CVQualifiers = QualifierKind::None; - std::string Name; - - std::unique_ptr Name_; -}; - -struct TagTypeInfo - : IsType +struct NamedTypeInfo + : IsType { QualifierKind CVQualifiers = QualifierKind::None; - std::unique_ptr ParentType; - std::string Name; - SymbolID id = SymbolID::invalid; - - std::unique_ptr Name_; -}; - -struct SpecializationTypeInfo - : IsType -{ - QualifierKind CVQualifiers = QualifierKind::None; - std::unique_ptr ParentType; - std::string Name; - SymbolID id = SymbolID::invalid; - std::vector> TemplateArgs; - - std::unique_ptr Name_; + std::unique_ptr Name; }; struct DecltypeTypeInfo @@ -244,17 +217,9 @@ visit( add_cv_from_t& II = I; switch(I.Kind) { - case TypeKind::Builtin: - return f(static_cast&>(II), - std::forward(args)...); - case TypeKind::Tag: - return f(static_cast&>(II), - std::forward(args)...); - case TypeKind::Specialization: + case TypeKind::Named: return f(static_cast&>(II), + TypeTy, NamedTypeInfo>&>(II), std::forward(args)...); case TypeKind::Decltype: return f(static_castdeclarator-before element-type nolink=nolink~}}{{/if~}} {{#if return-type~}}{{~>declarator-before return-type nolink=nolink~}}{{/if~}} -{{#if parent-type~}}{{>declarator parent-type nolink=nolink}}::{{/if~}} {{#if (eq kind "lvalue-reference")}}&{{/if~}} {{#if (eq kind "rvalue-reference")}}&&{{/if~}} {{#if (eq kind "pointer")}}*{{/if~}} -{{#if (eq kind "member-pointer")}}*{{/if~}} +{{#if (eq kind "member-pointer")}}{{>declarator parent-type nolink=nolink}}::*{{/if~}} {{#if cv-qualifiers~}} {{#if pointee-type}} {{cv-qualifiers}}{{else}}{{cv-qualifiers}} {{/if~}} {{/if~}} -{{#if prefix~}}{{>name-info prefix nolink=nolink}}{{/if~}} -{{!-- {{#if (and symbol (not parent-type))}}{{>qualified-path symbol=symbol.parent nolink=nolink}}{{/if~}} --~}} -{{#if (and symbol (not nolink))~}} - xref:{{symbol.ref}}[{{name}}] -{{~else if name}}{{name~}} -{{/if~}} {{#if (eq kind "decltype")}}decltype({{operand}}){{/if~}} -{{#if (eq kind "specialization")}}{{>template-args args=args nolink=nolink}}{{/if~}} +{{#if (eq kind "named")}}{{>name-info name nolink=nolink}}{{/if~}} {{#if is-pack~}}...{{/if}} \ No newline at end of file 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 7d9bca427..51d6ad9cf 100644 --- a/share/mrdocs/addons/generator/asciidoc/partials/name-info.adoc.hbs +++ b/share/mrdocs/addons/generator/asciidoc/partials/name-info.adoc.hbs @@ -1,8 +1,7 @@ -{{#unless (or (contains @root.symbol.namespace symbol) (eq @root.symbol symbol))~}} {{#if prefix~}} -{{>name-info prefix nolink=nolink~}} -{{else~}} +{{#unless (or (contains @root.symbol.namespace prefix.symbol) (eq @root.symbol prefix.symbol))~}} +{{>name-info prefix nolink=nolink~}}:: +{{~/unless~}} {{/if~}} {{#if (and symbol.ref (not nolink))}}xref:{{symbol.ref}}[{{name}}]{{else~}} -{{name}}{{/if}}{{#if args}}{{>template-args args=args nolink=nolink}}{{/if}}:: -{{~/unless}} \ No newline at end of file +{{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 93bd6699e..f0b84bbcd 100644 --- a/src/lib/AST/ASTVisitor.cpp +++ b/src/lib/AST/ASTVisitor.cpp @@ -2725,6 +2725,12 @@ class TerminalTypeVisitor bool VisitAutoType( const AutoType* T) { + // KRYSTIAN TODO: we should probably add a TypeInfo + // to represent deduced types that also stores what + // it was deduced as. + // KRYSTIAN NOTE: we don't use isDeduced because it will + // return true if the type is dependent + // if the type has been deduced, use the deduced type if(QualType DT = T->getDeducedType(); ! DT.isNull()) return Visit(DT); getDerived().buildTerminal(NNS_, T, Quals_, IsPack_); @@ -2734,6 +2740,9 @@ class TerminalTypeVisitor bool VisitDeducedTemplateSpecializationType( const DeducedTemplateSpecializationType* T) { + // KRYSTIAN TODO: we should probably add a TypeInfo + // to represent deduced types that also stores what + // it was deduced as. if(QualType DT = T->getDeducedType(); ! DT.isNull()) return Visit(DT); TemplateName TN = T->getTemplateName(); @@ -3047,10 +3056,13 @@ class TypeInfoBuilder unsigned quals, bool pack) { - auto I = std::make_unique(); + auto I = std::make_unique(); I->CVQualifiers = convertToQualifierKind(quals); - I->Name = getASTVisitor().getTypeAsString(T); - I->Name_ = getASTVisitor().buildNameInfo(NNS); + + auto Name = std::make_unique(); + Name->Name = getASTVisitor().getTypeAsString(T); + Name->Prefix = getASTVisitor().buildNameInfo(NNS); + I->Name = std::move(Name); *Inner = std::move(I); Result->IsPackExpansion = pack; } @@ -3064,25 +3076,27 @@ class TypeInfoBuilder bool pack) { ASTVisitor& V = getASTVisitor(); + auto I = std::make_unique(); + I->CVQualifiers = convertToQualifierKind(quals); + if(TArgs) { - auto I = std::make_unique(); - I->CVQualifiers = convertToQualifierKind(quals); + auto Name = std::make_unique(); if(II) - I->Name = II->getName(); - I->Name_ = V.buildNameInfo(NNS); - V.buildTemplateArgs(I->TemplateArgs, *TArgs); - *Inner = std::move(I); + Name->Name = II->getName(); + Name->Prefix = getASTVisitor().buildNameInfo(NNS); + V.buildTemplateArgs(Name->TemplateArgs, *TArgs); + I->Name = std::move(Name); } else { - auto I = std::make_unique(); - I->CVQualifiers = convertToQualifierKind(quals); + auto Name = std::make_unique(); if(II) - I->Name = II->getName(); - I->Name_ = V.buildNameInfo(NNS); - *Inner = std::move(I); + Name->Name = II->getName(); + Name->Prefix = getASTVisitor().buildNameInfo(NNS); + I->Name = std::move(Name); } + *Inner = std::move(I); Result->IsPackExpansion = pack; } @@ -3095,34 +3109,36 @@ class TypeInfoBuilder bool pack) { ASTVisitor& V = getASTVisitor(); - const IdentifierInfo* II = D->getIdentifier(); + auto I = std::make_unique(); + I->CVQualifiers = convertToQualifierKind(quals); + if(TArgs) { - auto I = std::make_unique(); - I->CVQualifiers = convertToQualifierKind(quals); - if(II) - I->Name = II->getName(); - V.getDependencyID(V.getInstantiatedFrom(D), I->id); + auto Name = std::make_unique(); + if(const IdentifierInfo* II = D->getIdentifier()) + Name->Name = II->getName(); + V.getDependencyID(V.getInstantiatedFrom(D), Name->id); if(NNS) - I->Name_ = V.buildNameInfo(NNS); + Name->Prefix = V.buildNameInfo(NNS); else - I->Name_ = V.buildNameInfo(D); - V.buildTemplateArgs(I->TemplateArgs, *TArgs); - *Inner = std::move(I); + Name->Prefix = V.buildNameInfo(D); + + V.buildTemplateArgs(Name->TemplateArgs, *TArgs); + I->Name = std::move(Name); } else { - auto I = std::make_unique(); - I->CVQualifiers = convertToQualifierKind(quals); - if(II) - I->Name = II->getName(); - V.getDependencyID(V.getInstantiatedFrom(D), I->id); + auto Name = std::make_unique(); + if(const IdentifierInfo* II = D->getIdentifier()) + Name->Name = II->getName(); + V.getDependencyID(V.getInstantiatedFrom(D), Name->id); if(NNS) - I->Name_ = V.buildNameInfo(NNS); + Name->Prefix = V.buildNameInfo(NNS); else - I->Name_ = V.buildNameInfo(D); - *Inner = std::move(I); + Name->Prefix = V.buildNameInfo(D); + I->Name = std::move(Name); } + *Inner = std::move(I); Result->IsPackExpansion = pack; } }; diff --git a/src/lib/AST/AnyBlock.hpp b/src/lib/AST/AnyBlock.hpp index e923acbd9..8ecae833d 100644 --- a/src/lib/AST/AnyBlock.hpp +++ b/src/lib/AST/AnyBlock.hpp @@ -806,14 +806,8 @@ class TypeInfoBlock return err; switch(k) { - case TypeKind::Builtin: - I_ = std::make_unique(); - break; - case TypeKind::Tag: - I_ = std::make_unique(); - break; - case TypeKind::Specialization: - I_ = std::make_unique(); + case TypeKind::Named: + I_ = std::make_unique(); break; case TypeKind::Decltype: I_ = std::make_unique(); @@ -845,22 +839,6 @@ class TypeInfoBlock if(auto err = decodeRecord(R, I_->IsPackExpansion, Blob)) return err; return Error::success(); - case TYPEINFO_ID: - return visit(*I_, [&](T& t) - { - if constexpr(requires { t.id; }) - return decodeRecord(R, t.id, Blob); - else - return Error("wrong TypeInfo kind"); - }); - case TYPEINFO_NAME: - return visit(*I_, [&](T& t) - { - if constexpr(requires { t.Name; }) - return decodeRecord(R, t.Name, Blob); - else - return Error("wrong TypeInfo kind"); - }); case TYPEINFO_CVQUAL: return visit(*I_, [&](T& t) { @@ -1195,7 +1173,7 @@ class NameInfoBlock } case BI_TEMPLATE_ARG_BLOCK_ID: { - SpecializationNameInfo* S = + SpecializationNameInfo* S = static_cast(I.get()); TemplateArgBlock B(S->TemplateArgs.emplace_back(), br_); return br_.readBlock(B, ID); @@ -1311,14 +1289,6 @@ readSubBlock(unsigned ID) TypeInfoBlock B(I.ParamTypes.emplace_back(), br_); return br_.readBlock(B, ID); } - case BI_TEMPLATE_ARG_BLOCK_ID: - { - if(! I_->isSpecialization()) - return Error("wrong TypeInfo kind"); - auto& I = static_cast(*I_); - TemplateArgBlock B(I.TemplateArgs.emplace_back(), br_); - return br_.readBlock(B, ID); - } case BI_EXPR_BLOCK_ID: { if(I_->isArray()) @@ -1340,8 +1310,8 @@ readSubBlock(unsigned ID) std::unique_ptr* NI = nullptr; visit(*I_, [&](T& t) { - if constexpr(requires { t.Name_; }) - NI = &t.Name_; + if constexpr(requires { t.Name; }) + NI = &t.Name; }); if(! NI) return Error("wrong TypeInfo kind"); diff --git a/src/lib/AST/BitcodeIDs.hpp b/src/lib/AST/BitcodeIDs.hpp index 330215cf3..302d36fd1 100644 --- a/src/lib/AST/BitcodeIDs.hpp +++ b/src/lib/AST/BitcodeIDs.hpp @@ -108,8 +108,6 @@ enum RecordID NAMESPACE_BITS, TYPEINFO_KIND, TYPEINFO_IS_PACK, - TYPEINFO_ID, - TYPEINFO_NAME, TYPEINFO_CVQUAL, TYPEINFO_NOEXCEPT, TYPEINFO_REFQUAL, diff --git a/src/lib/AST/BitcodeWriter.cpp b/src/lib/AST/BitcodeWriter.cpp index 85ad3d5d9..9a91c421f 100644 --- a/src/lib/AST/BitcodeWriter.cpp +++ b/src/lib/AST/BitcodeWriter.cpp @@ -329,8 +329,6 @@ RecordIDNameMap = []() {TEMPLATE_PARAM_KEY_KIND,{"TParamKeyKind", &Integer32Abbrev}}, {TYPEINFO_KIND, {"TypeinfoKind", &Integer32Abbrev}}, {TYPEINFO_IS_PACK, {"TypeinfoIsPack", &BoolAbbrev}}, - {TYPEINFO_ID, {"TypeinfoID", &SymbolIDAbbrev}}, - {TYPEINFO_NAME, {"TypeinfoName", &StringAbbrev}}, {TYPEINFO_CVQUAL, {"TypeinfoCV", &Integer32Abbrev}}, {TYPEINFO_NOEXCEPT, {"TypeinfoNoexcept", &NoexceptAbbrev}}, {TYPEINFO_REFQUAL, {"TypeinfoRefqual", &Integer32Abbrev}}, @@ -425,8 +423,8 @@ RecordsByBlock{ {}}, // TypeInfo {BI_TYPEINFO_BLOCK_ID, - {TYPEINFO_KIND, TYPEINFO_IS_PACK, TYPEINFO_ID, TYPEINFO_NAME, - TYPEINFO_CVQUAL, TYPEINFO_NOEXCEPT, TYPEINFO_REFQUAL}}, + {TYPEINFO_KIND, TYPEINFO_IS_PACK, TYPEINFO_CVQUAL, + TYPEINFO_NOEXCEPT, TYPEINFO_REFQUAL}}, {BI_TYPEINFO_PARENT_BLOCK_ID, {}}, {BI_TYPEINFO_CHILD_BLOCK_ID, @@ -440,7 +438,7 @@ RecordsByBlock{ {BI_VARIABLE_BLOCK_ID, {VARIABLE_BITS}}, // GuideInfo {BI_GUIDE_BLOCK_ID, {GUIDE_EXPLICIT}}, - {BI_NAME_INFO_ID, + {BI_NAME_INFO_ID, {NAME_INFO_KIND, NAME_INFO_ID, NAME_INFO_NAME}}, }; //------------------------------------------------ @@ -995,19 +993,9 @@ emitBlock( emitRecord(TI->IsPackExpansion, TYPEINFO_IS_PACK); visit(*TI, [&](const T& t) { - if constexpr(requires { t.id; }) - emitRecord(t.id, TYPEINFO_ID); - if constexpr(requires { t.Name; }) - emitRecord(t.Name, TYPEINFO_NAME); if constexpr(requires { t.CVQualifiers; }) emitRecord(t.CVQualifiers, TYPEINFO_CVQUAL); - if constexpr(T::isSpecialization()) - { - for(const auto& targ : t.TemplateArgs) - emitBlock(targ); - } - if constexpr(requires { t.ParentType; }) emitBlock(t.ParentType, BI_TYPEINFO_PARENT_BLOCK_ID); @@ -1034,11 +1022,11 @@ emitBlock( emitRecord(t.RefQualifier, TYPEINFO_REFQUAL); emitRecord(t.ExceptionSpec, TYPEINFO_NOEXCEPT); } - - if constexpr(requires { t.Name_; }) + + if constexpr(T::isNamed()) { - if(t.Name_) - emitBlock(*t.Name_); + if(t.Name) + emitBlock(*t.Name); } }); } @@ -1135,7 +1123,7 @@ emitBlock( emitBlock(tparam); } -void +void BitcodeWriter:: emitBlock(NameInfo const& I) { diff --git a/src/lib/Gen/xml/CXXTags.hpp b/src/lib/Gen/xml/CXXTags.hpp index 7b58cbc8c..db3af0a20 100644 --- a/src/lib/Gen/xml/CXXTags.hpp +++ b/src/lib/Gen/xml/CXXTags.hpp @@ -15,6 +15,7 @@ #include "XMLTags.hpp" #include +#include #include #include #include @@ -207,15 +208,10 @@ writeType( { Attributes attrs = { { "class", toString(T::kind_id), - T::kind_id != TypeKind::Builtin }, + T::kind_id != TypeKind::Named }, { "is-pack", "1", t.IsPackExpansion } }; - if constexpr(requires { t.id; }) - { - attrs.push({t.id}); - } - // KRYSTIAN FIXME: parent should is a type itself if constexpr(requires { t.ParentType; }) { @@ -223,9 +219,13 @@ writeType( attrs.push({"parent", toString(*t.ParentType)}); } - if constexpr(requires { t.Name; }) + if constexpr(T::isNamed()) { - attrs.push({"name", t.Name}); + if(t.Name) + { + attrs.push({t.Name->id}); + attrs.push({"name", toString(*t.Name)}); + } } if constexpr(requires { t.CVQualifiers; }) @@ -261,7 +261,7 @@ writeType( // ---------------------------------------------------------------- // no nested types; write as self closing tag - if constexpr(T::isBuiltin() || T::isTag()) + if constexpr(T::isNamed()) { tags.write(type_tag, {}, std::move(attrs)); return; @@ -269,12 +269,6 @@ writeType( tags.open(type_tag, std::move(attrs)); - if constexpr(T::isSpecialization()) - { - for(const auto& targ : t.TemplateArgs) - writeTemplateArg(*targ, tags); - } - if constexpr(requires { t.PointeeType; }) { writeType(*t.PointeeType, tags, "pointee-type"); diff --git a/src/lib/Lib/Lookup.cpp b/src/lib/Lib/Lookup.cpp index fffc208d8..c8a9ab434 100644 --- a/src/lib/Lib/Lookup.cpp +++ b/src/lib/Lib/Lookup.cpp @@ -109,24 +109,6 @@ adjustLookupContext( return context; } -const Info* -SymbolLookup:: -getTypeAsTag( - const std::unique_ptr& T) -{ - if(! T) - return nullptr; - SymbolID id = visit(*T, [](const T& t) - { - if constexpr(T::isTag() || T::isSpecialization()) - return t.id; - return SymbolID::invalid; - }); - if(! id) - return nullptr; - return corpus_.find(id); -} - const Info* SymbolLookup:: lookThroughTypedefs(const Info* I) @@ -134,7 +116,8 @@ lookThroughTypedefs(const Info* I) if(! I || ! I->isTypedef()) return I; auto* TI = static_cast(I); - return lookThroughTypedefs(getTypeAsTag(TI->Type)); + return lookThroughTypedefs( + corpus_.find(TI->Type->namedSymbol())); } const Info* @@ -176,7 +159,7 @@ lookupInContext( for(const auto& B : RI->Bases) { if(const Info* result = lookupInContext( - getTypeAsTag(B.Type), name, for_nns)) + corpus_.find(B.Type->namedSymbol()), name, for_nns)) return result; } } diff --git a/src/lib/Metadata/DomMetadata.cpp b/src/lib/Metadata/DomMetadata.cpp index 798db115b..9b7a55491 100644 --- a/src/lib/Metadata/DomMetadata.cpp +++ b/src/lib/Metadata/DomMetadata.cpp @@ -460,19 +460,9 @@ domCreate( }; visit(*I, [&](const T& t) { - if constexpr(requires { t.Name; }) - entries.emplace_back("name", t.Name); - - if constexpr(requires { t.Name_; }) - entries.emplace_back("prefix", - domCreate(t.Name_, domCorpus)); - - if constexpr(requires { t.id; }) - entries.emplace_back("symbol", domCorpus.get(t.id)); - - if constexpr(T::isSpecialization()) - entries.emplace_back("args", - dom::newArray(t.TemplateArgs, domCorpus)); + if constexpr(T::isNamed()) + entries.emplace_back("name", + domCreate(t.Name, domCorpus)); if constexpr(T::isDecltype()) entries.emplace_back("operand", t.Operand.Written); diff --git a/src/lib/Metadata/Finalize.cpp b/src/lib/Metadata/Finalize.cpp index 405df8f84..5376d0fc0 100644 --- a/src/lib/Metadata/Finalize.cpp +++ b/src/lib/Metadata/Finalize.cpp @@ -141,14 +141,8 @@ class Finalizer if constexpr(requires { T.ParentType; }) finalize(T.ParentType); - if constexpr(requires { T.id; }) - finalize(T.id); - - if constexpr(requires { T.Name_; }) - finalize(T.Name_); - - if constexpr(Ty::isSpecialization()) - finalize(T.TemplateArgs); + if constexpr(Ty::isNamed()) + finalize(T.Name); }); } diff --git a/src/lib/Metadata/Interface.cpp b/src/lib/Metadata/Interface.cpp index 7ccdf5aec..9b7e0a1eb 100644 --- a/src/lib/Metadata/Interface.cpp +++ b/src/lib/Metadata/Interface.cpp @@ -114,31 +114,14 @@ class TrancheBuilder I.Namespace.front() == parent_.id; } - const Info* - getTypeAsTag( - const std::unique_ptr& T) - { - if(! T) - return nullptr; - SymbolID id = visit(*T, [](const T& t) - { - if constexpr(T::isTag() || T::isSpecialization()) - return t.id; - return SymbolID::invalid; - }); - if(! id) - return nullptr; - return corpus_.find(id); - } - - const Info* lookThroughTypedefs(const Info* I) { if(! I || ! I->isTypedef()) return I; auto* TI = static_cast(I); - return lookThroughTypedefs(getTypeAsTag(TI->Type)); + return lookThroughTypedefs( + corpus_.find(TI->Type->namedSymbol())); } public: @@ -185,8 +168,8 @@ class TrancheBuilder actualAccess == AccessKind::Private) continue; const Info* Base = lookThroughTypedefs( - getTypeAsTag(B.Type)); - if(! Base || Base->id == I.id || + corpus_.find(B.Type->namedSymbol())); + if(! Base || Base->id == I.id || ! Base->isRecord()) continue; addFrom(*static_cast< diff --git a/src/lib/Metadata/Name.cpp b/src/lib/Metadata/Name.cpp index d848a2bfa..bc85a73b0 100644 --- a/src/lib/Metadata/Name.cpp +++ b/src/lib/Metadata/Name.cpp @@ -9,6 +9,7 @@ // #include +#include namespace clang { namespace mrdocs { @@ -26,5 +27,72 @@ dom::String toString(NameKind kind) noexcept } } +static +void +writeTo( + std::string& result, + auto&&... args) +{ + (result += ... += args); +} + +static +void +toStringImpl( + std::string& result, + const NameInfo& N) +{ + if(N.Prefix) + { + toStringImpl(result, *N.Prefix); + writeTo(result, "::"); + } + + writeTo(result, N.Name); + + if(! N.isSpecialization()) + return; + std::span> targs = + static_cast(N).TemplateArgs; + writeTo(result, '<'); + if(! targs.empty()) + { + auto targ_writer = + [&](const U& u) + { + if constexpr(U::isType()) + { + if(u.Type) + writeTo(result, toString(*u.Type)); + } + if constexpr(U::isNonType()) + { + writeTo(result, u.Value.Written); + } + if constexpr(U::isTemplate()) + { + writeTo(result, u.Name); + } + if(u.IsPackExpansion) + writeTo(result, "..."); + }; + visit(*targs.front(), targ_writer); + for(const auto& arg : targs.subspan(1)) + { + writeTo(result, ", "); + visit(*arg, targ_writer); + } + } + writeTo(result, '>'); +} + +std::string +toString(const NameInfo& N) +{ + std::string result; + toStringImpl(result, N); + return result; +} + } // mrdocs } // clang diff --git a/src/lib/Metadata/Type.cpp b/src/lib/Metadata/Type.cpp index dde5a7ce0..f5b4b8c65 100644 --- a/src/lib/Metadata/Type.cpp +++ b/src/lib/Metadata/Type.cpp @@ -8,8 +8,8 @@ // Official repository: https://github.com/cppalliance/mrdocs // +#include #include -#include namespace clang { namespace mrdocs { @@ -39,12 +39,8 @@ toString( { switch(kind) { - case TypeKind::Builtin: - return "builtin"; - case TypeKind::Tag: - return "tag"; - case TypeKind::Specialization: - return "specialization"; + case TypeKind::Named: + return "named"; case TypeKind::Decltype: return "decltype"; case TypeKind::LValueReference: @@ -64,6 +60,19 @@ toString( } } +SymbolID +TypeInfo:: +namedSymbol() const noexcept +{ + if(! isNamed()) + return SymbolID::invalid; + const auto* NT = static_cast< + const NamedTypeInfo*>(this); + if(! NT->Name) + return SymbolID::invalid; + return NT->Name->id; +} + namespace { constexpr @@ -124,7 +133,7 @@ operator()( if(t.IsPackExpansion) write("..."); - if constexpr(requires { t.Name; }) + if constexpr(T::isNamed()) { if(t.CVQualifiers != QualifierKind::None) write(toString(t.CVQualifiers), ' '); @@ -139,46 +148,11 @@ operator()( } } - if constexpr(requires { t.Name; }) - write(t.Name); - if constexpr(T::isDecltype()) write("decltype(", t.Operand.Written, ')'); - if constexpr(T::isSpecialization()) - { - write('<'); - if(! t.TemplateArgs.empty()) - { - auto targ_writer = - [&](const U& u) - { - if constexpr(U::isType()) - { - if(u.Type) - writeFullType(*u.Type, write); - } - if constexpr(U::isNonType()) - { - write(u.Value.Written); - } - if constexpr(U::isTemplate()) - { - write(u.Name); - } - if(u.IsPackExpansion) - write("..."); - }; - visit(*t.TemplateArgs.front(), targ_writer); - for(auto first = t.TemplateArgs.begin(); - ++first != t.TemplateArgs.end();) - { - write(", "); - visit(**first, targ_writer); - } - } - write('>'); - } + if constexpr(T::isNamed()) + write(toString(*t.Name)); if constexpr(requires { t.PointeeType; }) {