717 const std::vector<std::string> &
headers,
718 const std::vector<std::string> &
fwdDecls,
719 const std::vector<std::string> &
unknown)
725 if (classes.empty()) {
729 const std::string& className = classes[0];
731 TString fileName =
"AutoDict_";
732 std::string::const_iterator
sIt;
733 for (
sIt = className.begin();
sIt != className.end(); ++
sIt) {
734 if (*
sIt ==
'<' || *
sIt ==
'>' ||
735 *
sIt ==
' ' || *
sIt ==
'*' ||
736 *
sIt ==
',' || *
sIt ==
'&' ||
744 if (classes.size() > 1) {
746 std::vector<std::string>::const_iterator it = classes.begin();
747 while ((++it) != classes.end()) {
762 static const std::set<std::string>
sSTLTypes {
763 "vector",
"list",
"forward_list",
"deque",
"map",
"unordered_map",
"multimap",
764 "unordered_multimap",
"set",
"unordered_set",
"multiset",
"unordered_multiset",
765 "queue",
"priority_queue",
"stack",
"iterator"};
766 std::vector<std::string>::const_iterator it;
790 fileContent +=
"#pragma link C++ nestedclasses;\n";
791 fileContent +=
"#pragma link C++ nestedtypedefs;\n";
792 for (it = classes.begin(); it != classes.end(); ++it) {
798 if (
n.compare(0, 5,
"std::") == 0) {
808 fileContent +=
"#pragma link C++ class " + *it +
"::*+;\n" ;
1137 for (ModuleMap::module_iterator I =
MMap.module_begin(), E =
MMap.module_end(); I != E; ++I) {
1147 clang::GlobalModuleIndex::UserDefinedInterestingIDs
IDs;
1155 if (!
ND->isFromASTFile())
1157 if (!
ND->getIdentifier())
1164 if (
TD->isCompleteDefinition())
1167 Register(
NSD,
false);
1175 clang::GlobalModuleIndex::UserDefinedInterestingIDs &
DefinitionIDs;
1180 if (!
ND->hasOwningModule()) {
1186 assert(
FE->getName().contains(
"input_line_"));
1193 assert(!
ND->getName().empty() &&
"Empty name");
1205 llvm::cantFail(GlobalModuleIndex::writeIndex(
CI.getFileManager(),
1206 CI.getPCHContainerReader(),
1246 std::vector<std::string>
CoreModules = {
"ROOT_Foundation_C",
1249 "ROOT_Foundation_Stage1_NoRTTI",
1266 clang::Preprocessor &
PP =
CI.getPreprocessor();
1268 if (
MMap.findModule(
"RInterface"))
1276 std::optional<std::string>
envUseGMI = llvm::sys::Process::GetEnv(
"ROOT_USE_GMI");
1294 for (
auto I =
MMap.module_begin(), E =
MMap.module_end(); I != E; ++I) {
1295 clang::Module *M = I->second;
1306 if (M->IsUnimportable)
1392#ifdef R__USE_CXXMODULES
1402 for (
const char*
const* arg =
argv; *arg; ++arg)
1451#ifdef CLING_WITH_ADAPTIVECPP
1462 std::optional<std::string>
EnvOpt = llvm::sys::Process::GetEnv(
"EXTRA_CLING_ARGS");
1463 if (
EnvOpt.has_value()) {
1465 while (!
Env.empty()) {
1467 std::tie(Arg,
Env) =
Env.split(
' ');
1473 std::optional<std::string>
EnvOpt = llvm::sys::Process::GetEnv(
EnvVar);
1474 if (
EnvOpt.has_value()) {
1476 while (!
Env.empty()) {
1480 Paths.push_back(Arg.str());
1486 std::vector<std::string>
Paths;
1493 for (
const std::string& P :
Paths)
1500 EnvOpt = llvm::sys::Process::GetEnv(
"ROOT_CLING_TIMING");
1523 EnvOpt = llvm::sys::Process::GetEnv(
"CLING_MODULES_CACHE_PATH");
1526 assert(llvm::sys::fs::exists(
Env) &&
"Path does not exist!");
1548 interpArgs.push_back(
"-fno-implicit-module-maps");
1578 std::vector<std::string>
_empty;
1580 for (
const auto &arg: args)
1584 cling::Interpreter::ModuleFileExtensions
extensions;
1585 EnvOpt = llvm::sys::Process::GetEnv(
"ROOTDEBUG_RDICT");
1587 extensions.push_back(std::make_shared<TClingRdictModuleFileExtension>());
1604 fInterpreter->getCI()->getPreprocessorOpts().DisablePCHOrModuleValidation =
1605 DisableValidationForModuleKind::All;
1609 fInterpreter->getCI()->getLangOpts().SpellChecking =
false;
1643 fInterpreter->getRuntimeOptions().AllowRedefinition = 1;
1644 auto &Policy =
const_cast<clang::PrintingPolicy &
>(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
1648 Policy.SplitTemplateClosers =
true;
1650 Policy.SuppressDefaultTemplateArgs =
false;
1656 std::unique_ptr<TClingCallbacks>
1663 cling::DynamicLibraryManager&
DLM = *
fInterpreter->getDynamicLibraryManager();
1669 llvm::StringRef
stem = llvm::sys::path::stem(FileName);
1670 return stem.starts_with(
"libNew") ||
stem.starts_with(
"libcppyy_backend");
2105 Info(
"TCling::RegisterModule",
2106 "Header parsing on demand is active but this is an Aclic library. Disabling it for this library.");
2124 cling::Transaction* T =
nullptr;
2131 "A fwd declaration could not be compiled");
2132 if (
compRes!=cling::Interpreter::kSuccess){
2133 Warning(
"TCling::RegisterModule",
2134 "Problems in declaring string '%s' were encountered.",
2157 ::Error(
"TCling::RegisterModule",
"Dictionary trigger function for %s not found",
modulename);
2195 std::vector<std::string>
scopes;
2199 if (
enumPos != std::string::npos) {
2217 clang::DeclContext*
DC =
nullptr;
2244 = cling::utils::Lookup::Named(&
fInterpreter->getSema(),
2262 "The forward declarations could not be compiled");
2263 if (
compRes!=cling::Interpreter::kSuccess){
2264 Warning(
"TCling::RegisterModule",
2265 "Problems in compiling forward declarations for module %s: '%s'",
2274 ExtLexicalStorageAdder
elsa;
2276 cling::Transaction::DelayCallInfo&
dci = *
dciIt;
2314 Info(
"TCling::RegisterModule",
2315 "Adding a header for %s", temp.c_str());
2338 clang::Preprocessor &
PP =
TheSema.getPreprocessor();
2356 Info(
"TCling::RegisterModule",
"Module %s in modulemap failed to load.",
ModuleName.c_str());
2392#if defined(R__MUST_REVISIT)
2393#if R__MUST_REVISIT(6,2)
2394 Warning(
"TCling::RegisterModule",
"Diagnostics suppression should be gone by now.");
2409 "Payload code of a dictionary could not be parsed correctly.");
2410 if (
compRes!=cling::Interpreter::kSuccess) {
2411 Warning(
"TCling::RegisterModule",
2412 "Problems declaring payload for module %s.",
modulename) ;
2428 "#undef __ROOTCLING__\n"
2553 gROOT->SetLineIsProcessing();
2557 gROOT->SetLineHasBeenProcessed();
2570 gROOT->SetLineIsProcessing();
2573 cling::Interpreter* fInterpreter;
2580 fInterpreter->enableDynamicLookup(
true);
2584 gROOT->SetLineHasBeenProcessed();
2593 cling::Interpreter::CompilationResult
compRes = cling::Interpreter::kSuccess;
2614 compRes = cling::Interpreter::kFailure;
2619 if (arguments.
Length() == 0) {
2632 }
else if (cling::DynamicLibraryManager::isSharedLibrary(
fname.Data()) &&
2636 compRes = cling::Interpreter::kFailure;
2638 if (arguments.
Length() == 0) {
2669 std::ifstream in(
fname, std::ifstream::binary);
2675 = cling::utils::isUnnamedMacro(code,
fInterpreter->getCI()->getLangOpts());
2714 case cling::Interpreter::kSuccess: *error =
kNoError;
break;
2715 case cling::Interpreter::kFailure: *error =
kRecoverable;
break;
2716 case cling::Interpreter::kMoreInputExpected: *error =
kProcessing;
break;
2719 if (
compRes == cling::Interpreter::kSuccess
2821 const char*
cobj = (
const char*) obj;
2861 static clang::PrintingPolicy
2866 printPol.SuppressInitializers =
true;
2887 Error(
"InspectMembers",
"Cannot find Decl for class %s",
clname);
2891 = llvm::dyn_cast<const clang::CXXRecordDecl>(
scopeDecl);
2893 Error(
"InspectMembers",
"Cannot find Decl for class %s is not a CXXRecordDecl.",
clname);
2917 Error(
"InspectMembers",
"TClass and cling disagree on the size of the class %s, respectively %d %lld\n",
2939 printPol.AnonymousTagLocations =
false;
2942 Error(
"InspectMembers",
2943 "Cannot retrieve QualType for member %s while inspecting class %s",
2952 printPol.AnonymousTagLocations =
false;
2955 Error(
"InspectMembers",
2956 "Cannot retrieve Type for member %s while inspecting class %s",
2965 clang::QualType
ptrQT
2972 if (
ptrQT.isNull()) {
2976 printPol.AnonymousTagLocations =
false;
2979 Error(
"InspectMembers",
2980 "Cannot retrieve pointee Type for member %s while inspecting class %s",
2988 llvm::SmallString<8> arraySize;
2996 clang::dyn_cast<clang::ConstantArrayType>(
arrType);
3006 printPol.AnonymousTagLocations =
false;
3009 Error(
"InspectMembers",
3010 "Cannot retrieve QualType for array level %d (i.e. element type of %s) for member %s while inspecting class %s",
3024 if (
memType->isPointerType()) {
3029 std::string ioname(
iField->getName());
3047 if (!
insp.IsTreatingNonAccessibleTypes()){
3076 if (!
mbr || !
mbr->IsPersistent())
3077 insp.IncrementNestedTransient();
3080 if (!
mbr || !
mbr->IsPersistent())
3081 insp.DecrementNestedTransient();
3090 for (clang::CXXRecordDecl::base_class_const_iterator
iBase
3095 Error(
"InspectMembers",
3096 "Cannot find QualType for base number %d while inspecting class %s",
3100 const clang::CXXRecordDecl*
baseDecl
3101 =
baseQT->getAsCXXRecordDecl();
3103 Error(
"InspectMembers",
3104 "Cannot find CXXRecordDecl for base number %d while inspecting class %s",
3129 Error(
"InspectMembers",
3135 if (
iBase->isVirtual()) {
3138 Error(
"InspectMembers",
3139 "Base %s of class %s is virtual but no object provided",
3151 Error(
"InspectMembers",
3152 "Error calculating offset of virtual base %s of class %s",
3156 Error(
"InspectMembers",
3157 "Cannot calculate offset of virtual base %s of class %s",
3166 if (
baseCl->IsLoaded()) {
3323 size_t at = std::string::npos;
3324 while ((at =
file_name.find(
"/./")) != std::string::npos)
3329 clang::SourceManager &
SM =
fInterpreter->getCI()->getSourceManager();
3330 cling::ClangInternalState::printIncludedFiles(
filesOS,
SM);
3333 llvm::SmallVector<llvm::StringRef, 100>
files;
3336 std::set<std::string>
fileMap;
3356 incPath.Append(
":").Prepend(
" ");
3357 incPath.ReplaceAll(
" -I",
":");
3358 while (
incPath.Index(
" :") != -1) {
3359 incPath.ReplaceAll(
" :",
":");
3373 clang::ConstSearchDirIterator *
CurDir =
nullptr;
3374 clang::Preprocessor &
PP =
fInterpreter->getCI()->getPreprocessor();
3375 clang::HeaderSearch &
HS =
PP.getHeaderSearchInfo();
3377 clang::SourceLocation(),
3380 clang::ArrayRef<std::pair<clang::OptionalFileEntryRef,
3381 clang::DirectoryEntryRef>>(),
3394 clang::SourceManager &
SM =
fInterpreter->getCI()->getSourceManager();
3396 clang::FileID
FID =
SM.translateFile(*
FE);
3397 if (!
FID.isInvalid() &&
FID.getHashValue() == 0)
3400 clang::SrcMgr::SLocEntry
SLocE =
SM.getSLocEntry(
FID);
3401 if (
SLocE.isFile() && !
SLocE.getFile().getContentCache().getBufferIfLoaded())
3403 if (!
FID.isInvalid())
3672 cling::DynamicLibraryManager*
DLM =
fInterpreter->getDynamicLibraryManager();
3674 cling::DynamicLibraryManager::LoadLibResult res
3675 = cling::DynamicLibraryManager::kLoadLibNotFound;
3682 cling::Interpreter::CompilationResult
compRes;
3684 if (
compRes == cling::Interpreter::kSuccess)
3685 res = cling::DynamicLibraryManager::kLoadLibSuccess;
3689 if (res == cling::DynamicLibraryManager::kLoadLibSuccess) {
3693 case cling::DynamicLibraryManager::kLoadLibSuccess:
return 0;
3694 case cling::DynamicLibraryManager::kLoadLibAlreadyLoaded:
return 1;
3951#if defined(R__MUST_REVISIT)
3952#if R__MUST_REVISIT(6,2)
3953 Warning(
"DeleteVariable",
"should do more that just reseting the value to zero");
3961 const clang::DeclContext*
declCtx =
nullptr;
3962 if (
posScope != llvm::StringRef::npos) {
3966 cling::LookupHelper::WithDiagnostics);
3968 Error(
"DeleteVariable",
"Cannot find enclosing scope for variable %s",
3974 Error(
"DeleteVariable",
3975 "Enclosing scope for variable %s is not a declaration context",
3986 Error(
"DeleteVariable",
"Unknown variable %s",
name);
3991 Error(
"DeleteVariable",
"Entity %s is not a variable",
name);
3996 const clang::Type*
type =
qType->getUnqualifiedDesugaredType();
3999 if (
type->isPointerType()) {
4348 static const char *
anonEnum =
"anonymous enum ";
4376 const char *classname =
name;
4412 const clang::Type *
type =
nullptr;
4413 const clang::Decl *
decl
4414 =
lh.findScope(classname,
4415 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
4416 : cling::LookupHelper::NoDiagnostics,
4421 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
4422 : cling::LookupHelper::NoDiagnostics,
4439 clang::ClassTemplateSpecializationDecl *
tmpltDecl =
4440 llvm::dyn_cast_or_null<clang::ClassTemplateSpecializationDecl>
4441 (
type->getAsCXXRecordDecl());
4453 if (!
tci.IsValid()) {
4578 D =
fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
4589 for (clang::DeclContext::decl_iterator
DI = (*declIter)->decls_begin(),
4590 DE = (*declIter)->decls_end();
DI !=
DE; ++
DI) {
4595 llvm::raw_string_ostream stream(
buf);
4597 Policy.AnonymousTagLocations =
false;
4598 ED->getNameForDiagnostic(stream, Policy,
false);
4602 const char*
name =
buf.c_str();
4898 if (classes ==
nullptr || classes[0] == 0) {
4899 Error(
"TCling::GenerateDictionary",
"Cannot generate dictionary without passing classes.");
4905 const char* current = classes, *prev = classes;
4909 if (*current ==
';') {
4910 listClasses.push_back(std::string(prev, current - prev));
4913 else if (*(current + 1) == 0) {
4914 listClasses.push_back(std::string(prev, current + 1 - prev));
4922 const char* current = includes, *prev = includes;
4926 if (*current ==
';') {
4927 listIncludes.push_back(std::string(prev, current - prev));
4930 else if (*(current + 1) == 0) {
4931 listIncludes.push_back(std::string(prev, current + 1 - prev));
4937 std::vector<std::string>(), std::vector<std::string>());
5222 std::vector<DeclId_t>& res)
const
5225 clang::ASTContext&
Ctx = S.Context;
5228 Ctx.getTranslationUnitDecl();
5236 clang::DeclarationName
DName;
5242 clang::CanQualType
QT =
Ctx.getCanonicalTagType(
RecDecl);
5243 DName =
Ctx.DeclarationNames.getCXXConstructorName(
QT);
5245 clang::CanQualType
QT =
Ctx.getCanonicalTagType(
RecDecl);
5246 DName =
Ctx.DeclarationNames.getCXXDestructorName(
QT);
5255 clang::LookupResult
R(S,
DName, clang::SourceLocation(), Sema::LookupOrdinaryName,
5256 RedeclarationKind::NotForRedeclaration);
5257 R.suppressDiagnostics();
5259 if (
R.empty())
return;
5261 res.reserve(res.size() + (
R.end() -
R.begin()));
5264 if (
const clang::FunctionDecl*
FD
5265 = llvm::dyn_cast<const clang::FunctionDecl>(*
IR)) {
5266 if (!
FD->getDescribedFunctionTemplate()) {
5269 }
else if (
const auto *
USD = llvm::dyn_cast<const clang::UsingShadowDecl>(*
IR)) {
5271 if (llvm::isa<clang::FunctionDecl>(
USD->getTargetDecl())) {
6560 unsigned long offset = 0;
6619 Info(
"TCling::AutoParse",
6620 "Starting autoparse for %s\n",
apKey);
6625 const cling::Transaction *T =
fInterpreter->getCurrentTransaction();
6629 Info(
"TCling::AutoParse",
6630 "We can proceed for %s. We have %s headers.",
apKey, std::to_string(
hNamesPtrs.size()).c_str());
6640 "Parsing full payload for %s",
apKey);
6647 if (
cRes != cling::Interpreter::kSuccess) {
6648 if (
hName[0] ==
'\n')
6649 Error(
"AutoParse",
"Error parsing payload code for class %s with content:\n%s",
apKey,
hName);
6665 "Parsing single header %s",
hName);
6668 if (
cRes != cling::Interpreter::kSuccess) {
6669 Error(
"AutoParse",
"Error parsing headerfile %s for class %s.",
hName,
apKey);
6963 if (!T.empty() && T.decls_begin() + 1 == T.decls_end() && !T.hasNestedTransactions()) {
6964 clang::Decl*
FirstDecl = *(T.decls_begin()->m_DGR.begin());
6965 if (llvm::isa<clang::TranslationUnitDecl>(
FirstDecl)) {
6974 const clang::Decl*
WrapperFD = T.getWrapperFD();
6977 if (I->m_Call != cling::Transaction::kCCIHandleTopLevelDecl
6978 && I->m_Call != cling::Transaction::kCCIHandleTagDeclDefinition)
6994 E = T.deserialized_decls_end(); I != E; ++I) {
7014 std::vector<TClass*>::iterator it;
7027 if (!
gROOT->GetListOfClasses()->FindObject(*I)) {
7191 using namespace clang;
7192 if (
const Decl *D =
LH.findScope(
cls, cling::LookupHelper::NoDiagnostics,
7194 if (!D->isFromASTFile()) {
7196 Warning(
"GetClassSharedLibsForModule",
"Decl found for %s is not part of a module",
cls);
7204 void Collect(
const Decl *D) { Visit(D); }
7216 if (!D->hasOwningModule())
7218 if (
Module *M = D->getOwningModule()->getTopLevelModule())
7224 switch (
TA.getKind()) {
7225 case TemplateArgument::Null:
7226 case TemplateArgument::Integral:
7227 case TemplateArgument::Pack:
7228 case TemplateArgument::NullPtr:
7229 case TemplateArgument::StructuralValue:
7230 case TemplateArgument::Expression:
7231 case TemplateArgument::Template:
7232 case TemplateArgument::TemplateExpansion:
return;
7233 case TemplateArgument::Type:
7235 return Visit(
TagTy->getDecl());
7237 case TemplateArgument::Declaration:
return Visit(
TA.getAsDecl());
7244 if (
CTSD->getOwningModule())
7262 if (!M->LinkLibraries.size())
7267 assert(M->LinkLibraries.size() == 1);
7270 result += M->LinkLibraries[0].Library;
7352 cling::Interpreter *
interp,
7356 if (!llvm::sys::path::is_absolute(lib)) {
7358 Error(
"TCling__GetSharedLibImmediateDepsSlow",
"Cannot find library '%s'", lib.c_str());
7362 assert(llvm::sys::fs::exists(lib) &&
"Must exist!");
7363 lib = llvm::sys::path::filename(lib).str();
7366 auto ObjF = llvm::object::ObjectFile::createObjectFile(
LibFullPath.Data());
7368 Warning(
"TCling__GetSharedLibImmediateDepsSlow",
"Failed to read object file %s", lib.c_str());
7375 std::string Result = lib +
' ';
7376 for (
const auto &S :
BinObjFile->symbols()) {
7377 uint32_t
Flags = llvm::cantFail(S.getFlags());
7379 if (!(
Flags & llvm::object::SymbolRef::SF_Undefined))
7383 if (
Flags & llvm::object::SymbolRef::SF_Weak)
7385 llvm::Expected<StringRef>
SymNameErr = S.getName();
7387 Warning(
"GetSharedLibDepsForModule",
"Failed to read symbol");
7398 if (
SymName.contains(
"@GLIBCXX") ||
SymName.contains(
"@CXXABI") ||
7407 static constexpr llvm::StringRef
RegisterClasses(
"_Jv_RegisterClasses");
7419 if (llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(
SymNameForDlsym))
7424 std::string found =
interp->getDynamicLibraryManager()->searchLibrariesForSymbol(
SymName,
false);
7430 if (!found.empty()) {
7431 std::string
cand = llvm::sys::path::filename(found).str();
7435 Result +=
cand +
' ';
7809 &
fInterpreter->getDiagnostics().getDiagnosticOptions(),
7811 [] (clang::DiagnosticsEngine::Level Level,
const std::string &
Info) {
7812 if (Level == clang::DiagnosticsEngine::Warning) {
7813 ::Warning(
"cling",
"%s", Info.c_str());
7814 }
else if (Level == clang::DiagnosticsEngine::Error
7815 || Level == clang::DiagnosticsEngine::Fatal) {
7823 fInterpreter->replaceDiagnosticConsumer(
nullptr);
8336 const clang::DeclContext *
ctxt =
nullptr;
8345 const clang::Decl *
decl =
reinterpret_cast<const clang::Decl*
>(
declid);
8349 const clang::DeclContext *
declDC =
decl->getDeclContext();
8352 if (
declDC->isTransparentContext()) {
8356 if (
const auto *
declRD = llvm::dyn_cast<clang::RecordDecl>(
declDC)) {
8357 if (
declRD->isAnonymousStructOrUnion()) {
8362 if (
const auto *
declNS = llvm::dyn_cast<clang::NamespaceDecl>(
declDC)) {
8363 if (
declNS->isAnonymousNamespace() ||
declNS->isInlineNamespace()) {
8965 const auto *
FD = llvm::dyn_cast<clang::FunctionDecl>(
decl);
8966 if (
const auto *
USD = llvm::dyn_cast<clang::UsingShadowDecl>(
decl)) {
8967 FD = llvm::dyn_cast<clang::FunctionDecl>(
USD->getTargetDecl());
8970 Error(
"GetFunctionName",
"NULL Decl!");
8977 if (llvm::isa<clang::CXXConstructorDecl>(
FD))
8981 }
else if (llvm::isa<clang::CXXDestructorDecl>(
decl))
8984 output.insert(output.begin(),
'~');
8986 llvm::raw_string_ostream stream(output);