From 2b5c5c869360c1d3404efd5ed2566777034e95ae Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Fri, 10 Nov 2023 14:54:45 -0500 Subject: [PATCH] fix: qualified lookup for transparent contexts --- src/lib/Lib/Lookup.cpp | 29 ++++++++++++++++++++++++----- src/lib/Lib/Lookup.hpp | 4 ++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/lib/Lib/Lookup.cpp b/src/lib/Lib/Lookup.cpp index 594f9a241..fffc208d8 100644 --- a/src/lib/Lib/Lookup.cpp +++ b/src/lib/Lib/Lookup.cpp @@ -25,6 +25,20 @@ bool supportsLookup(const Info* info) info->isSpecialization()); } +bool isTransparent(const Info* info) +{ + MRDOCS_ASSERT(info); + return visit(*info, []( + const InfoTy& I) -> bool + { + if constexpr(InfoTy::isNamespace()) + return I.specs.isInline; + if constexpr(InfoTy::isEnum()) + return ! I.Scoped; + return false; + }); +} + void buildLookups( const Corpus& corpus, @@ -41,6 +55,11 @@ buildLookups( for(const SymbolID& M : I.Members) { const Info* child = corpus.find(M); + // if the member is an inline namespace or + // an unscoped enumeration, add its members as well + if(isTransparent(child)) + buildLookups(corpus, *child, lookups); + // KRYSTIAN TODO: handle inline/anonymous namespaces // KRYSTIAN TODO: injected class names? if(child->Name.empty()) @@ -125,11 +144,11 @@ lookupInContext( std::string_view name, bool for_nns) { - context = lookThroughTypedefs(context); - // KRYSTIAN FIXME: enumerators need to have their own - // info type for lookup to work - if(! context) + // if the lookup context is a typedef, we want to + // lookup the name in the type it denotes + if(! (context = lookThroughTypedefs(context))) return nullptr; + MRDOCS_ASSERT(supportsLookup(context)); LookupTable& table = lookup_tables_.at(context); // KRYSTIAN FIXME: disambiguation based on signature for(auto& result : table.lookup(name)) @@ -216,7 +235,7 @@ lookupQualified( while(! qualifier.empty()) { if(! (context = lookupInContext( - context, qualifier.front())), true) + context, qualifier.front(), true))) return nullptr; qualifier = qualifier.subspan(1); } diff --git a/src/lib/Lib/Lookup.hpp b/src/lib/Lib/Lookup.hpp index 06e27fa31..527fdf364 100644 --- a/src/lib/Lib/Lookup.hpp +++ b/src/lib/Lib/Lookup.hpp @@ -26,6 +26,10 @@ namespace mrdocs { class LookupTable { + // maps unquaified names to symbols with that name. + // names from member symbols which are "transparent" + // (e.g. unscoped enums and inline namespaces) will + // have their members added to the table as well std::unordered_multimap< std::string_view, const Info*> lookups_;