Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: qualified lookup for transparent contexts #482

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading