Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TClingCallbacks.h
Go to the documentation of this file.
1// @(#)root/core/meta:$Id$
2// Author: Vassil Vassilev 7/10/2012
3
4/*************************************************************************
5 * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "cling/Interpreter/InterpreterCallbacks.h"
13
14#include <stack>
15#include <string>
16#include <optional>
17
18namespace clang {
19 class Decl;
20 class DeclarationName;
21 class LookupResult;
22 class NamespaceDecl;
23 class Scope;
24 class TagDecl;
25 class Token;
26 class FileEntry;
27 class Module;
28}
29
30namespace cling {
31 class Interpreter;
32 class Transaction;
33}
34
35namespace llvm {
36 class StringRef;
37}
38
39// The callbacks are used to update the list of globals in ROOT.
40//
41class TClingCallbacks : public cling::InterpreterCallbacks {
42private:
43 void *fLastLookupCtx = nullptr;
44 clang::NamespaceDecl *fROOTSpecialNamespace = nullptr;
45 bool fFirstRun = true;
46 bool fIsAutoLoading = false;
50 bool fIsCodeGening = false;
51 bool fIsLoadingModule = false;
52 llvm::DenseMap<llvm::StringRef, clang::DeclarationName> m_LoadedModuleFiles;
53
54public:
55 TClingCallbacks(cling::Interpreter* interp, bool hasCodeGen);
56
58
59 void Initialize();
60
61 void SetAutoLoadingEnabled(bool val = true) { fIsAutoLoading = val; }
62 bool IsAutoLoadingEnabled() const { return fIsAutoLoading; }
63
64 void SetAutoParsingSuspended(bool val = true) { fIsAutoParsingSuspended = val; }
66
67 // Whether the JIT is allowed to autoload a library to resolve a symbol it
68 // genuinely needs to link and run emitted code, even while class/dictionary
69 // autoloading is suspended (as TCling::Declare does while parsing). See #16601.
72
73 bool LibraryLoadingFailed(const std::string &, const std::string &, bool, bool) override;
74
75 void InclusionDirective(clang::SourceLocation /*HashLoc*/, const clang::Token & /*IncludeTok*/,
76 llvm::StringRef FileName, bool /*IsAngled*/, clang::CharSourceRange /*FilenameRange*/,
77 clang::OptionalFileEntryRef /*File*/, llvm::StringRef /*SearchPath*/,
78 llvm::StringRef /*RelativePath*/, const clang::Module * /*Imported*/,
79 bool /*ModuleImported*/, clang::SrcMgr::CharacteristicKind /*FileType*/) override;
80
81 // Preprocessor callbacks used to handle special cases like for example:
82 // #include "myMacro.C+"
83 //
84 bool FileNotFound(llvm::StringRef FileName) override;
85
86 bool LookupObject(clang::LookupResult &R, clang::Scope *S) override;
87 bool LookupObject(const clang::DeclContext *DC, clang::DeclarationName Name) override;
88 bool LookupObject(clang::TagDecl *Tag) override;
89
90 // The callback is used to update the list of globals in ROOT.
91 //
92 void TransactionCommitted(const cling::Transaction &T) override;
93
94 // The callback is used to inform ROOT when cling started code generation.
95 //
96 void TransactionCodeGenStarted(const cling::Transaction &T) override
97 {
99 fIsCodeGening = true;
100 }
101
102 // The callback is used to inform ROOT when cling finished code generation.
103 //
104 void TransactionCodeGenFinished(const cling::Transaction &T) override
105 {
107 fIsCodeGening = false;
108 }
109
110 // The callback is used to update the list of globals in ROOT.
111 //
112 void TransactionUnloaded(const cling::Transaction &T) override;
113
114 // The callback is used to clear the autoparsing caches.
115 //
116 void TransactionRollback(const cling::Transaction &T) override;
117
118 ///\brief A previous definition has been shadowed; invalidate TCling' stored
119 /// data about the old (global) decl.
120 void DefinitionShadowed(const clang::NamedDecl *D) override;
121
122 void LibraryLoaded(const void *dyLibHandle, llvm::StringRef canonicalName) override;
123 void LibraryUnloaded(const void *dyLibHandle, llvm::StringRef canonicalName) override;
124
125 void PrintStackTrace() override;
126
127 void *EnteringUserCode() override;
128 void ReturnedFromUserCode(void *stateInfo) override;
131
132private:
133 bool tryAutoParseInternal(llvm::StringRef Name, clang::LookupResult &R, clang::Scope *S,
134 clang::OptionalFileEntryRef FE = std::nullopt);
135 bool tryFindROOTSpecialInternal(clang::LookupResult &R, clang::Scope *S);
136 bool tryResolveAtRuntimeInternal(clang::LookupResult &R, clang::Scope *S);
137 bool shouldResolveAtRuntime(clang::LookupResult &R, clang::Scope *S);
138 bool tryInjectImplicitAutoKeyword(clang::LookupResult &R, clang::Scope *S);
139 bool findInGlobalModuleIndex(clang::DeclarationName Name, bool loadFirstMatchOnly = true);
140};
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void TransactionCodeGenFinished(const cling::Transaction &T) override
void LibraryUnloaded(const void *dyLibHandle, llvm::StringRef canonicalName) override
bool tryFindROOTSpecialInternal(clang::LookupResult &R, clang::Scope *S)
void ReturnedFromUserCode(void *stateInfo) override
bool IsAutoParsingSuspended()
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)
bool fIsAutoLoadingForJITSymbols
void PrintStackTrace() override
bool tryInjectImplicitAutoKeyword(clang::LookupResult &R, clang::Scope *S)
bool IsAutoLoadingForJITSymbols() const
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
void UnlockCompilationDuringUserCodeExecution(void *StateInfo) override
void SetAutoParsingSuspended(bool val=true)
bool LibraryLoadingFailed(const std::string &, const std::string &, bool, bool) override
void * LockCompilationDuringUserCodeExecution() override
bool LookupObject(clang::LookupResult &R, clang::Scope *S) override
void SetAutoLoadingForJITSymbols(bool val=true)
void LibraryLoaded(const void *dyLibHandle, llvm::StringRef canonicalName) override
void SetAutoLoadingEnabled(bool val=true)
bool shouldResolveAtRuntime(clang::LookupResult &R, clang::Scope *S)
bool LookupObject(const clang::DeclContext *DC, clang::DeclarationName Name) override
void TransactionUnloaded(const cling::Transaction &T) override
void TransactionCodeGenStarted(const cling::Transaction &T) override