Skip to content

Commit

Permalink
[cxxmodules] Implement mapping between identifier and a library.
Browse files Browse the repository at this point in the history
This patch allows given a name to deduce the library it is defined in.
It uses the fact that we have a module per library. The lookup returns
a declaration whose owning module gives a hint about the corresponding
library.

This is useful to implement the TCling::AutoLoad interface for modules.
  • Loading branch information
vgvassilev committed Mar 27, 2019
1 parent 304743e commit 6ead6cb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions core/metacling/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6679,6 +6679,25 @@ const char* TCling::GetSharedLibs()
return fSharedLibs;
}

static const char* GetClassSharedLibsForModule(const char* cls,
cling::LookupHelper &LH)
{
if (!cls || !*cls)
return 0;

if (const clang::Decl* D = LH.findScope(cls, cling::LookupHelper::NoDiagnostics)) {
if (!D->isFromASTFile()) {
if (gDebug > 5)
Warning("GetClassSharedLibsForModule",
"Decl found for %s is not part of a module", cls);
return 0;
}
clang::Module *M = D->getOwningModule()->getTopLevelModule();
return M->Name.c_str();
}
return 0;
}

////////////////////////////////////////////////////////////////////////////////
/// Get the list of shared libraries containing the code for class cls.
/// The first library in the list is the one containing the class, the
Expand All @@ -6687,6 +6706,10 @@ const char* TCling::GetSharedLibs()

const char* TCling::GetClassSharedLibs(const char* cls)
{
if (fCxxModulesEnabled)
if (const char* lib = GetClassSharedLibsForModule(cls, fInterpreter->getLookupHelper()))
return lib;

if (!cls || !*cls) {
return 0;
}
Expand Down

0 comments on commit 6ead6cb

Please sign in to comment.