Skip to content
Closed
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
1 change: 1 addition & 0 deletions core/base/src/TROOT.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,7 @@ void TROOT::InitInterpreter()

// Enable autoloading
fInterpreter->EnableAutoLoading();
fInterpreter->SetupModules();
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions core/meta/inc/TInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class TInterpreter : public TNamed {
void (*histaddFunc)(const char* line)) = 0;
virtual void Reset() = 0;
virtual void ResetAll() = 0;
virtual bool SetupModules() = 0;
virtual void ResetGlobals() = 0;
virtual void ResetGlobalVar(void *obj) = 0;
virtual void RewindDictionary() = 0;
Expand Down
6 changes: 6 additions & 0 deletions core/metacling/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3768,6 +3768,12 @@ void TCling::UpdateListOfDataMembers(TClass* cl) const
{
}

bool TCling::SetupModules() {
if (!fInterpreter->getCI()->getLangOpts().Modules)
return false;
return fInterpreter->setupModules();
}

////////////////////////////////////////////////////////////////////////////////
/// Create list of pointers to method arguments for TMethod m.

Expand Down
1 change: 1 addition & 0 deletions core/metacling/src/TCling.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class TCling : public TInterpreter {
void CreateListOfMethodArgs(TFunction* m) const;
void UpdateListOfMethods(TClass* cl) const;
void UpdateListOfDataMembers(TClass* cl) const;
virtual bool SetupModules();

virtual DeclId_t GetDataMember(ClassInfo_t *cl, const char *name) const;
virtual DeclId_t GetDataMemberAtAddr(const void *addr) const;
Expand Down
2 changes: 2 additions & 0 deletions interpreter/cling/include/cling/Interpreter/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ namespace cling {
int getDefaultOptLevel() const { return m_OptLevel; }
void setDefaultOptLevel(int optLevel) { m_OptLevel = optLevel; }

bool setupModules();

clang::CompilerInstance* getCI() const;
clang::CompilerInstance* getCIOrNull() const;
clang::Sema& getSema() const;
Expand Down
75 changes: 75 additions & 0 deletions interpreter/cling/lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@

#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <sstream>

using namespace clang;

Expand Down Expand Up @@ -1473,6 +1476,78 @@ namespace cling {
m_DynamicLookupEnabled = value;
}

bool Interpreter::setupModules() {
clang::CompilerInstance* CI = getCI();
std::stringstream declarations;
if (CI->getLangOpts().Modules && CI->getLangOpts().CurrentModule.empty()) {

clang::HeaderSearch &headerSearch = CI->getPreprocessor().getHeaderSearchInfo();
clang::ModuleMap &moduleMap = headerSearch.getModuleMap();

llvm::SetVector<clang::Module *> modules;
auto& PP = getParser().getPreprocessor();

for (auto MI = moduleMap.module_begin(), end = moduleMap.module_end(); MI != end; MI++) {
clang::Module* Module = MI->second;
HeaderSearchOptions &HSOpts =
PP.getHeaderSearchInfo().getHeaderSearchOpts();

std::string ModuleFileName;
bool LoadFromPrebuiltModulePath = false;
// We try to load the module from the prebuilt module paths. If not
// successful, we then try to find it in the module cache.
if (!HSOpts.PrebuiltModulePaths.empty()) {
// Load the module from the prebuilt module path.
ModuleFileName = PP.getHeaderSearchInfo().getModuleFileName(
Module->Name, "", /*UsePrebuiltPath*/ true);
if (!ModuleFileName.empty())
LoadFromPrebuiltModulePath = true;
}
if (!LoadFromPrebuiltModulePath && Module) {
// Load the module from the module cache.
ModuleFileName = PP.getHeaderSearchInfo().getModuleFileName(Module);
}
bool Exists = false;
{
std::ifstream f(ModuleFileName);
Exists = f.good();
}
if (Exists)
modules.insert(Module);
}

for (size_t i = 0; i < modules.size(); ++i) {
clang::Module *M = modules[i];
for (clang::Module *subModule : M->submodules()) modules.insert(subModule);
}

// Now we collect all header files from the previously collected modules.
std::set<StringRef> moduleHeaders;
for (clang::Module *module : modules) {
for (int i = 0; i < 4; i++) {
auto &headerList = module->Headers[i];
for (const clang::Module::Header &moduleHeader : headerList) {
moduleHeaders.insert(moduleHeader.NameAsWritten);
}
}
}

for (StringRef H : moduleHeaders) {
if (H == "GL/glew.h")
continue;
if (H == "GL/glxew.h")
continue;
if (H.endswith(".inc"))
continue;
if (H == "TException.h")
continue;
declarations << "#include \"" << H.str() << "\"\n";
}
}

return declare(declarations.str()) == CompilationResult::kSuccess;
}

Interpreter::ExecutionResult
Interpreter::executeTransaction(Transaction& T) {
assert(!isInSyntaxOnlyMode() && "Running on what?");
Expand Down