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;
49 bool fIsCodeGening = false;
50 bool fIsLoadingModule = false;
51 llvm::DenseMap<llvm::StringRef, clang::DeclarationName> m_LoadedModuleFiles;
52
53public:
54 TClingCallbacks(cling::Interpreter* interp, bool hasCodeGen);
55
57
58 void Initialize();
59
60 void SetAutoLoadingEnabled(bool val = true) { fIsAutoLoading = val; }
61 bool IsAutoLoadingEnabled() const { return fIsAutoLoading; }
62
63 void SetAutoParsingSuspended(bool val = true) { fIsAutoParsingSuspended = val; }
65
66 bool LibraryLoadingFailed(const std::string &, const std::string &, bool, bool) override;
67
68 void InclusionDirective(clang::SourceLocation /*HashLoc*/, const clang::Token & /*IncludeTok*/,
69 llvm::StringRef FileName, bool /*IsAngled*/, clang::CharSourceRange /*FilenameRange*/,
70 clang::OptionalFileEntryRef /*File*/, llvm::StringRef /*SearchPath*/,
71 llvm::StringRef /*RelativePath*/, const clang::Module * /*Imported*/,
72 clang::SrcMgr::CharacteristicKind /*FileType*/) override;
73
74 // Preprocessor callbacks used to handle special cases like for example:
75 // #include "myMacro.C+"
76 //
77 bool FileNotFound(llvm::StringRef FileName) override;
78
79 bool LookupObject(clang::LookupResult &R, clang::Scope *S) override;
80 bool LookupObject(const clang::DeclContext *DC, clang::DeclarationName Name) override;
81 bool LookupObject(clang::TagDecl *Tag) override;
82
83 // The callback is used to update the list of globals in ROOT.
84 //
85 void TransactionCommitted(const cling::Transaction &T) override;
86
87 // The callback is used to inform ROOT when cling started code generation.
88 //
89 void TransactionCodeGenStarted(const cling::Transaction &T) override
90 {
91 assert(!fIsCodeGening);
92 fIsCodeGening = true;
93 }
94
95 // The callback is used to inform ROOT when cling finished code generation.
96 //
97 void TransactionCodeGenFinished(const cling::Transaction &T) override
98 {
99 assert(fIsCodeGening);
100 fIsCodeGening = false;
101 }
102
103 // The callback is used to update the list of globals in ROOT.
104 //
105 void TransactionUnloaded(const cling::Transaction &T) override;
106
107 // The callback is used to clear the autoparsing caches.
108 //
109 void TransactionRollback(const cling::Transaction &T) override;
110
111 ///\brief A previous definition has been shadowed; invalidate TCling' stored
112 /// data about the old (global) decl.
113 void DefinitionShadowed(const clang::NamedDecl *D) override;
114
115 // Used to inform client about a new decl read by the ASTReader.
116 //
117 void DeclDeserialized(const clang::Decl *D) override;
118
119 void LibraryLoaded(const void *dyLibHandle, llvm::StringRef canonicalName) override;
120 void LibraryUnloaded(const void *dyLibHandle, llvm::StringRef canonicalName) override;
121
122 void PrintStackTrace() override;
123
124 void *EnteringUserCode() override;
125 void ReturnedFromUserCode(void *stateInfo) override;
127 void UnlockCompilationDuringUserCodeExecution(void *StateInfo) override;
128
129private:
130 bool tryAutoParseInternal(llvm::StringRef Name, clang::LookupResult &R, clang::Scope *S,
131 clang::OptionalFileEntryRef FE = std::nullopt);
132 bool tryFindROOTSpecialInternal(clang::LookupResult &R, clang::Scope *S);
133 bool tryResolveAtRuntimeInternal(clang::LookupResult &R, clang::Scope *S);
134 bool shouldResolveAtRuntime(clang::LookupResult &R, clang::Scope *S);
135 bool tryInjectImplicitAutoKeyword(clang::LookupResult &R, clang::Scope *S);
136 bool findInGlobalModuleIndex(clang::DeclarationName Name, bool loadFirstMatchOnly = true);
137};
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)
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
llvm::DenseMap< llvm::StringRef, clang::DeclarationName > m_LoadedModuleFiles
void DeclDeserialized(const clang::Decl *D) override
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 InclusionDirective(clang::SourceLocation, const clang::Token &, llvm::StringRef FileName, bool, clang::CharSourceRange, clang::OptionalFileEntryRef, llvm::StringRef, llvm::StringRef, const clang::Module *, clang::SrcMgr::CharacteristicKind) override
void * LockCompilationDuringUserCodeExecution() override
bool LookupObject(clang::LookupResult &R, clang::Scope *S) override
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