Logo ROOT  
Reference Guide
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
17namespace clang {
18 class Decl;
19 class DeclarationName;
20 class LookupResult;
21 class NamespaceDecl;
22 class Scope;
23 class TagDecl;
24 class Token;
25 class FileEntry;
26 class Module;
27}
28
29namespace cling {
30 class Interpreter;
31 class Transaction;
32}
33
34namespace llvm {
35 class StringRef;
36}
37
38// The callbacks are used to update the list of globals in ROOT.
39//
40class TClingCallbacks : public cling::InterpreterCallbacks {
41private:
42 void *fLastLookupCtx = nullptr;
43 clang::NamespaceDecl *fROOTSpecialNamespace = nullptr;
44 bool fFirstRun = true;
45 bool fIsAutoLoading = false;
48 bool fPPOldFlag = false;
49 bool fPPChanged = 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; }
63
64 void SetAutoParsingSuspended(bool val = true) { fIsAutoParsingSuspended = val; }
66
67 bool LibraryLoadingFailed(const std::string &, const std::string &, bool, bool) override;
68
69 void InclusionDirective(clang::SourceLocation /*HashLoc*/, const clang::Token & /*IncludeTok*/,
70 llvm::StringRef FileName, bool /*IsAngled*/, clang::CharSourceRange /*FilenameRange*/,
71 const clang::FileEntry * /*File*/, llvm::StringRef /*SearchPath*/,
72 llvm::StringRef /*RelativePath*/, const clang::Module * /*Imported*/,
73 clang::SrcMgr::CharacteristicKind /*FileType*/) override;
74
75 // Preprocessor callbacks used to handle special cases like for example:
76 // #include "myMacro.C+"
77 //
78 bool FileNotFound(llvm::StringRef FileName, llvm::SmallVectorImpl<char> &RecoveryPath) override;
79
80 bool LookupObject(clang::LookupResult &R, clang::Scope *S) override;
81 bool LookupObject(const clang::DeclContext *DC, clang::DeclarationName Name) override;
82 bool LookupObject(clang::TagDecl *Tag) override;
83
84 // The callback is used to update the list of globals in ROOT.
85 //
86 void TransactionCommitted(const cling::Transaction &T) override;
87
88 // The callback is used to inform ROOT when cling started code generation.
89 //
90 void TransactionCodeGenStarted(const cling::Transaction &T) override
91 {
92 assert(!fIsCodeGening);
93 fIsCodeGening = true;
94 }
95
96 // The callback is used to inform ROOT when cling finished code generation.
97 //
98 void TransactionCodeGenFinished(const cling::Transaction &T) override
99 {
100 assert(fIsCodeGening);
101 fIsCodeGening = false;
102 }
103
104 // The callback is used to update the list of globals in ROOT.
105 //
106 void TransactionUnloaded(const cling::Transaction &T) override;
107
108 // The callback is used to clear the autoparsing caches.
109 //
110 void TransactionRollback(const cling::Transaction &T) override;
111
112 ///\brief A previous definition has been shadowed; invalidate TCling' stored
113 /// data about the old (global) decl.
114 void DefinitionShadowed(const clang::NamedDecl *D) override;
115
116 // Used to inform client about a new decl read by the ASTReader.
117 //
118 void DeclDeserialized(const clang::Decl *D) override;
119
120 void LibraryLoaded(const void *dyLibHandle, llvm::StringRef canonicalName) override;
121 void LibraryUnloaded(const void *dyLibHandle, llvm::StringRef canonicalName) override;
122
123 void PrintStackTrace() override;
124
125 void *EnteringUserCode() override;
126 void ReturnedFromUserCode(void *stateInfo) override;
128 void UnlockCompilationDuringUserCodeExecution(void *StateInfo) override;
129
130private:
131 bool tryAutoParseInternal(llvm::StringRef Name, clang::LookupResult &R,
132 clang::Scope *S, const clang::FileEntry* FE = 0);
133 bool tryFindROOTSpecialInternal(clang::LookupResult &R, clang::Scope *S);
134 bool tryResolveAtRuntimeInternal(clang::LookupResult &R, clang::Scope *S);
135 bool shouldResolveAtRuntime(clang::LookupResult &R, clang::Scope *S);
136 bool tryInjectImplicitAutoKeyword(clang::LookupResult &R, clang::Scope *S);
137 bool findInGlobalModuleIndex(clang::DeclarationName Name, bool loadFirstMatchOnly = true);
138};
void TransactionCodeGenFinished(const cling::Transaction &T) override
void LibraryUnloaded(const void *dyLibHandle, llvm::StringRef canonicalName) override
bool tryAutoParseInternal(llvm::StringRef Name, clang::LookupResult &R, clang::Scope *S, const clang::FileEntry *FE=0)
bool tryFindROOTSpecialInternal(clang::LookupResult &R, clang::Scope *S)
void ReturnedFromUserCode(void *stateInfo) override
bool fIsAutoParsingSuspended
bool IsAutoParsingSuspended()
bool tryResolveAtRuntimeInternal(clang::LookupResult &R, clang::Scope *S)
bool findInGlobalModuleIndex(clang::DeclarationName Name, bool loadFirstMatchOnly=true)
void PrintStackTrace() override
bool tryInjectImplicitAutoKeyword(clang::LookupResult &R, clang::Scope *S)
bool IsAutoLoadingEnabled()
clang::NamespaceDecl * fROOTSpecialNamespace
void TransactionRollback(const cling::Transaction &T) override
void TransactionCommitted(const cling::Transaction &T) override
TClingCallbacks(cling::Interpreter *interp, bool hasCodeGen)
llvm::DenseMap< llvm::StringRef, clang::DeclarationName > m_LoadedModuleFiles
void DeclDeserialized(const clang::Decl *D) override
void InclusionDirective(clang::SourceLocation, const clang::Token &, llvm::StringRef FileName, bool, clang::CharSourceRange, const clang::FileEntry *, llvm::StringRef, llvm::StringRef, const clang::Module *, clang::SrcMgr::CharacteristicKind) override
void DefinitionShadowed(const clang::NamedDecl *D) override
A previous definition has been shadowed; invalidate TCling' stored data about the old (global) decl.
bool FileNotFound(llvm::StringRef FileName, llvm::SmallVectorImpl< char > &RecoveryPath) override
void * EnteringUserCode() override
bool fIsAutoLoadingRecursively
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 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
double T(double x)
Definition: ChebyshevPol.h:34
RooArgSet S(Args_t &&... args)
Definition: RooArgSet.h:241
Definition: TString.h:850
const char * Name
Definition: TXMLSetup.cxx:67