Skip to content

Commit

Permalink
fix: qualified lookup for transparent contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Nov 10, 2023
1 parent 1b486b7 commit 2b5c5c8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/lib/Lib/Lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ bool supportsLookup(const Info* info)
info->isSpecialization());
}

bool isTransparent(const Info* info)
{
MRDOCS_ASSERT(info);
return visit(*info, []<typename InfoTy>(
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,
Expand All @@ -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())
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Lib/Lookup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand Down

0 comments on commit 2b5c5c8

Please sign in to comment.