17#include "cling/Interpreter/DynamicLibraryManager.h"
18#include "cling/Interpreter/Interpreter.h"
19#include "cling/Interpreter/InterpreterCallbacks.h"
20#include "cling/Interpreter/Transaction.h"
21#include "cling/Utils/AST.h"
23#include "clang/AST/ASTConsumer.h"
24#include "clang/AST/ASTContext.h"
25#include "clang/AST/DeclBase.h"
26#include "clang/AST/DeclTemplate.h"
27#include "clang/AST/GlobalDecl.h"
28#include "clang/Frontend/CompilerInstance.h"
29#include "clang/Lex/HeaderSearch.h"
30#include "clang/Lex/PPCallbacks.h"
31#include "clang/Lex/Preprocessor.h"
32#include "clang/Parse/Parser.h"
33#include "clang/Sema/Lookup.h"
34#include "clang/Sema/Scope.h"
35#include "clang/Serialization/ASTReader.h"
36#include "clang/Serialization/GlobalModuleIndex.h"
37#include "clang/Basic/DiagnosticSema.h"
39#include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h"
40#include "llvm/ExecutionEngine/Orc/Core.h"
42#include "llvm/Support/Error.h"
43#include "llvm/Support/FileSystem.h"
44#include "llvm/Support/Path.h"
45#include "llvm/Support/Process.h"
75 std::string &args, std::string &
io, std::string &
fname);
96 llvm::Error
tryToGenerate(llvm::orc::LookupState &
LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &
JD,
98 const llvm::orc::SymbolLookupSet &
Symbols)
override
101 return llvm::Error::success();
107 std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
113 llvm::orc::SymbolStringPtr
name =
KV.first;
115 const cling::DynamicLibraryManager &
DLM = *
fInterpreter->getDynamicLibraryManager();
117 std::string
libName =
DLM.searchLibrariesForSymbol((*name).str(),
121 assert(
libName.find(
"/libNew.") == std::string::npos &&
"We must not autoload libNew!");
127 assert(
libName.find(
"/libCling.") == std::string::npos &&
"Must not autoload libCling!");
134 for (
const auto &
KV : found) {
141 for (
const auto &
symbol :
KV.second) {
145 void *
addr = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(
nameForDlsym);
156 return llvm::Error::success();
164 m_Interpreter->declare(
"namespace __ROOT_SpecialObjects{}", &T);
167 interp->addGenerator(std::make_unique<AutoloadLibraryGenerator>(
interp, *
this));
175 const clang::Token &,
176 llvm::StringRef FileName,
178 clang::CharSourceRange ,
179 clang::OptionalFileEntryRef
FE,
184 clang::SrcMgr::CharacteristicKind
FileType) {
191 "Module %s resolved but not visible!",
Imported->Name.c_str());
207 bool isHeaderFile = FileName.ends_with(
".h") || FileName.ends_with(
".hxx") || FileName.ends_with(
".hpp");
239 std::string
filename(FileName.str().substr(0,FileName.str().find_last_of(
'"')));
243 if (
mode.length() > 0) {
244 if (llvm::sys::fs::exists(
fname)) {
246 std::string options =
"k";
247 if (
mode.find(
"++") != std::string::npos) options +=
"f";
248 if (
mode.find(
"g") != std::string::npos) options +=
"g";
249 if (
mode.find(
"O") != std::string::npos) options +=
"O";
255 clang::Parser::ParserCurTokRestoreRAII fSavedCurToken(P);
260 Tok.setKind(tok::semi);
324 if (
m_Interpreter->getSema().getDiagnostics().hasErrorOccurred())
362 std::optional<std::string>
envUseGMI = llvm::sys::Process::GetEnv(
"ROOT_USE_GMI");
385 if (
SemaR.InstantiatingSpecializations.size() > 0)
398 if (Index->lookupIdentifier(Name.getAsString(),
FoundModules)) {
405 llvm::errs() <<
"Module '" <<
ModuleName <<
"' already loaded"
406 <<
" for '" << Name.getAsString() <<
"'\n";
412 llvm::errs() <<
"Loading '" <<
ModuleName <<
"' on demand"
413 <<
" for '" << Name.getAsString() <<
"'\n";
438 if (
Name.getNameKind() != DeclarationName::Identifier)
444 if (
Loc.isValid() &&
SemaR.getSourceManager().isInSystemHeader(
Loc)) {
469 R.suppressDiagnostics();
472 =
NSD->getQualifiedNameAsString() +
"::" +
Name.getAsString();
478 clang::Scope
S(
SemaR.TUScope, clang::Scope::DeclScope,
SemaR.getDiagnostics());
510 if (
SemaR.getSourceManager().isInSystemHeader(
Loc)) {
516 for (
auto ReRD:
Tag->redecls()) {
518 if (
ReRD->isBeingDefined())
534 C.getTypeDeclType(
RD),
540 Tag->setHasExternalLexicalStorage(
false);
556 Scope *S, clang::OptionalFileEntryRef
FE) {
571 Sema::LookupNameKind kind =
R.getLookupKind();
572 if (!(kind == Sema::LookupTagName || kind == Sema::LookupOrdinaryName
573 || kind == Sema::LookupNestedNameSpecifierName
574 || kind == Sema::LookupNamespaceName))
581 Parser &P =
const_cast<Parser &
>(
m_Interpreter->getParser());
590 if (
R.isSingleResult()) {
605 raii.fPushedDCAndS.pop();
606 raii.fCleanupRAII.pop();
613 std::string
incl =
"#include \"";
652 if (
R.isForRedeclaration())
657 const Sema::LookupNameKind
LookupKind =
R.getLookupKind();
681#if defined(R__MUST_REVISIT)
682#if R__MUST_REVISIT(6,2)
687 if (!fgSetOfSpecials) {
688 fgSetOfSpecials =
new std::set<TObject*>;
690 ((std::set<TObject*>*)fgSetOfSpecials)->insert((
TObject*)*obj);
704 Expr*
newInit = utils::Synthesize::IntegerLiteralExpr(C, (uint64_t)obj);
723 = utils::Synthesize::CStyleCastPtrExpr(&
SemaR,
QT, (uint64_t)obj);
728 cling::CompilationOptions
CO;
729 CO.DeclarationExtraction = 0;
730 CO.ValuePrinting = CompilationOptions::VPDisabled;
731 CO.ResultEvaluation = 0;
732 CO.DynamicScoping = 0;
734 CO.CodeGeneration = 1;
736 cling::Transaction* T =
new cling::Transaction(
CO,
SemaR);
738 T->setState(cling::Transaction::kCompleted);
768 clang::FunctionDecl*
Wrapper =
nullptr;
776 if (utils::Analyze::IsWrapper(
Wrapper)) {
793 if (
annot->getAnnotation() ==
"__ResolveAtRuntime" && S->isControlScope())
808 Wrapper->addAttr(AnnotateAttr::CreateImplicit(C,
"__ResolveAtRuntime",
nullptr, 0));
823 if (
R.getLookupKind() != Sema::LookupOrdinaryName)
826 if (
R.isForRedeclaration())
835 const cling::CompilationOptions&
COpts = T->getCompilationOpts();
836 if (!
COpts.DynamicScoping)
839 auto &
PP =
R.getSema().PP;
867 if (!
Ctx->isDependentContext())
887 if (
R.isForRedeclaration())
890 if (
R.getLookupKind() != Sema::LookupOrdinaryName)
908 if (!
FD || !utils::Analyze::IsWrapper(
FD))
921 if (
PP.LookAhead(0).isNot(tok::equal)) {
931 C.getAutoType(QualType(),
932 clang::AutoTypeKeyword::Auto,
938 "Cannot create VarDecl");
945 Result->addAttr(AnnotateAttr::CreateImplicit(C,
"__Auto",
nullptr, 0));
950 SemaRef.getDiagnostics().setSeverity(diag::warn_deprecated_message, diag::Severity::Warning,
SourceLocation());
951 SemaRef.Diag(
Loc, diag::warn_deprecated_message)
952 <<
"declaration without the 'auto' keyword" <<
DC <<
Loc << FixItHint::CreateInsertion(
Loc,
"auto ");
963 cling::Transaction
TPrev((cling::CompilationOptions(),
SemaR));
964 TPrev.append(
SemaR.getASTContext().getTranslationUnitDecl());
The file contains utilities which are foundational and could be used across the core component of ROO...
#define R(a, b, c, d, e, f, g, h, i)
bool TCling__LibraryLoadingFailed(const std::string &, const std::string &, bool, bool)
Lookup libraries in LD_LIBRARY_PATH and DYLD_LIBRARY_PATH with mangled_name, which is extracted by er...
void * TCling__LockCompilationDuringUserCodeExecution()
Lock the interpreter.
int TCling__LoadLibrary(const char *library)
Load a library.
void TCling__UpdateListsOnCommitted(const cling::Transaction &, Interpreter *)
void TCling__SplitAclicMode(const char *fileName, std::string &mode, std::string &args, std::string &io, std::string &fname)
void TCling__TransactionRollback(const cling::Transaction &)
const char * TCling__GetClassSharedLibs(const char *className)
int TCling__AutoParseCallback(const char *className)
Decl * TCling__GetObjectDecl(TObject *obj)
R__EXTERN int gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
void TCling__GetNormalizedContext(const ROOT::TMetaUtils::TNormalizedCtxt *&)
void TCling__RestoreInterpreterMutex(void *state)
Re-apply the lock count delta that TCling__ResetInterpreterMutex() caused.
int TCling__CompileMacro(const char *fileName, const char *options)
void * TCling__ResetInterpreterMutex()
Reset the interpreter lock to the state it had before interpreter-related calls happened.
int TCling__AutoLoadCallback(const char *className)
void TCling__LibraryUnloadedRTTI(const void *dyLibHandle, llvm::StringRef canonicalName)
void TCling__PrintStackTrace()
Print a StackTrace!
int TCling__IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl *name)
void TCling__UpdateListsOnUnloaded(const cling::Transaction &)
void TCling__UnlockCompilationDuringUserCodeExecution(void *state)
Unlock the interpreter.
static bool topmostDCIsFunction(Scope *S)
void TCling__InvalidateGlobal(const clang::Decl *)
void TCling__LibraryLoadedRTTI(const void *dyLibHandle, llvm::StringRef canonicalName)
TObject * TCling__GetObjectAddress(const char *Name, void *&LookupCtx)
void TCling__RestoreInterpreterMutex(void *delta)
Re-apply the lock count delta that TCling__ResetInterpreterMutex() caused.
void TCling__TransactionRollback(const cling::Transaction &T)
void TCling__InvalidateGlobal(const clang::Decl *D)
void * TCling__LockCompilationDuringUserCodeExecution()
Lock the interpreter.
void TCling__UpdateListsOnUnloaded(const cling::Transaction &T)
void TCling__GetNormalizedContext(const ROOT::TMetaUtils::TNormalizedCtxt *&normCtxt)
bool TCling__LibraryLoadingFailed(const std::string &errmessage, const std::string &libStem, bool permanent, bool resolved)
Lookup libraries in LD_LIBRARY_PATH and DYLD_LIBRARY_PATH with mangled_name, which is extracted by er...
const char * TCling__GetClassSharedLibs(const char *className, bool skipCore)
void TCling__UnlockCompilationDuringUserCodeExecution(void *)
Unlock the interpreter.
int TCling__AutoParseCallback(const char *className)
void TCling__LibraryUnloadedRTTI(const void *dyLibHandle, const char *canonicalName)
void TCling__UpdateListsOnCommitted(const cling::Transaction &T, cling::Interpreter *)
const Decl * TCling__GetObjectDecl(TObject *obj)
int TCling__CompileMacro(const char *fileName, const char *options)
void * TCling__ResetInterpreterMutex()
Reset the interpreter lock to the state it had before interpreter-related calls happened.
int TCling__AutoLoadCallback(const char *className)
void TCling__PrintStackTrace()
Print a StackTrace!
void TCling__LibraryLoadedRTTI(const void *dyLibHandle, const char *canonicalName)
TObject * TCling__GetObjectAddress(const char *Name, void *&LookupCtx)
int TCling__IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl *nsDecl)
void TCling__SplitAclicMode(const char *fileName, string &mode, string &args, string &io, string &fname)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char mode
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
AutoloadLibraryGenerator(cling::Interpreter *interp, const TClingCallbacks &cb)
const TClingCallbacks & fCallbacks
cling::Interpreter * fInterpreter
llvm::Error tryToGenerate(llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD, llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override
void LibraryUnloaded(const void *dyLibHandle, llvm::StringRef canonicalName) override
bool tryFindROOTSpecialInternal(clang::LookupResult &R, clang::Scope *S)
void ReturnedFromUserCode(void *stateInfo) override
bool fIsAutoParsingSuspended
bool tryResolveAtRuntimeInternal(clang::LookupResult &R, clang::Scope *S)
bool findInGlobalModuleIndex(clang::DeclarationName Name, bool loadFirstMatchOnly=true)
bool tryAutoParseInternal(llvm::StringRef Name, clang::LookupResult &R, clang::Scope *S, clang::OptionalFileEntryRef FE=std::nullopt)
void PrintStackTrace() override
bool tryInjectImplicitAutoKeyword(clang::LookupResult &R, clang::Scope *S)
clang::NamespaceDecl * fROOTSpecialNamespace
void TransactionRollback(const cling::Transaction &T) override
void TransactionCommitted(const cling::Transaction &T) override
bool FileNotFound(llvm::StringRef FileName) override
TClingCallbacks(cling::Interpreter *interp, bool hasCodeGen)
void InclusionDirective(clang::SourceLocation, const clang::Token &, llvm::StringRef FileName, bool, clang::CharSourceRange, clang::OptionalFileEntryRef, llvm::StringRef, llvm::StringRef, const clang::Module *, bool, clang::SrcMgr::CharacteristicKind) override
llvm::DenseMap< llvm::StringRef, clang::DeclarationName > m_LoadedModuleFiles
bool IsAutoLoadingEnabled() const
void DefinitionShadowed(const clang::NamedDecl *D) override
A previous definition has been shadowed; invalidate TCling' stored data about the old (global) decl.
void * EnteringUserCode() override
bool fIsAutoLoadingRecursively
void UnlockCompilationDuringUserCodeExecution(void *StateInfo) override
bool LibraryLoadingFailed(const std::string &, const std::string &, bool, bool) override
void * LockCompilationDuringUserCodeExecution() override
bool LookupObject(clang::LookupResult &R, clang::Scope *S) override
void LibraryLoaded(const void *dyLibHandle, llvm::StringRef canonicalName) override
bool shouldResolveAtRuntime(clang::LookupResult &R, clang::Scope *S)
void TransactionUnloaded(const cling::Transaction &T) override
Mother of all ROOT objects.
bool ConvertEnvValueToBool(const std::string &value)
RooArgSet S(Args_t &&... args)
constexpr Double_t E()
Base of natural log: .
RAII used to store Parser, Sema, Preprocessor state for recursive parsing.