Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
16 namespace clang {
17  class Decl;
18  class LookupResult;
19  class NamespaceDecl;
20  class Scope;
21  class TagDecl;
22  class Token;
23  class FileEntry;
24  class Module;
25 }
26 
27 namespace cling {
28  class Interpreter;
29  class Transaction;
30 }
31 
32 namespace llvm {
33  class StringRef;
34 }
35 
36 // The callbacks are used to update the list of globals in ROOT.
37 //
38 class TClingCallbacks : public cling::InterpreterCallbacks {
39 private:
40  void *fLastLookupCtx;
41  clang::NamespaceDecl *fROOTSpecialNamespace;
42  bool fFirstRun;
43  bool fIsAutoloading;
44  bool fIsAutoloadingRecursively;
45  bool fIsAutoParsingSuspended;
46  bool fPPOldFlag;
47  bool fPPChanged;
48 public:
49  TClingCallbacks(cling::Interpreter* interp, bool hasCodeGen);
50 
51  ~TClingCallbacks();
52 
53  void Initialize();
54 
55  void SetAutoloadingEnabled(bool val = true) { fIsAutoloading = val; }
56  bool IsAutoloadingEnabled() { return fIsAutoloading; }
57 
58  void SetAutoParsingSuspended(bool val = true) { fIsAutoParsingSuspended = val; }
59  bool IsAutoParsingSuspended() { return fIsAutoParsingSuspended; }
60 
61  virtual bool LibraryLoadingFailed(const std::string&, const std::string&, bool, bool);
62 
63  virtual void InclusionDirective(clang::SourceLocation /*HashLoc*/,
64  const clang::Token &/*IncludeTok*/,
65  llvm::StringRef FileName,
66  bool /*IsAngled*/,
67  clang::CharSourceRange /*FilenameRange*/,
68  const clang::FileEntry * /*File*/,
69  llvm::StringRef /*SearchPath*/,
70  llvm::StringRef /*RelativePath*/,
71  const clang::Module * /*Imported*/);
72 
73  // Preprocessor callbacks used to handle special cases like for example:
74  // #include "myMacro.C+"
75  //
76  virtual bool FileNotFound(llvm::StringRef FileName,
77  llvm::SmallVectorImpl<char>& RecoveryPath);
78 
79  virtual bool LookupObject(clang::LookupResult &R, clang::Scope *S);
80  virtual bool LookupObject(const clang::DeclContext* DC,
81  clang::DeclarationName Name);
82  virtual bool LookupObject(clang::TagDecl* Tag);
83 
84  // The callback is used to update the list of globals in ROOT.
85  //
86  virtual void TransactionCommitted(const cling::Transaction &T);
87 
88  // The callback is used to update the list of globals in ROOT.
89  //
90  virtual void TransactionUnloaded(const cling::Transaction &T);
91 
92  // The callback is used to clear the autoparsing caches.
93  //
94  virtual void TransactionRollback(const cling::Transaction &T);
95 
96  ///\brief A previous definition has been shadowed; invalidate TCling' stored
97  /// data about the old (global) decl.
98  virtual void DefinitionShadowed(const clang::NamedDecl *D);
99 
100  // Used to inform client about a new decl read by the ASTReader.
101  //
102  virtual void DeclDeserialized(const clang::Decl* D);
103 
104  virtual void LibraryLoaded(const void* dyLibHandle,
105  llvm::StringRef canonicalName);
106  virtual void LibraryUnloaded(const void* dyLibHandle,
107  llvm::StringRef canonicalName);
108 
109  virtual void PrintStackTrace();
110 
111  virtual void *EnteringUserCode();
112  virtual void ReturnedFromUserCode(void *stateInfo);
113  virtual void *LockCompilationDuringUserCodeExecution();
114  virtual void UnlockCompilationDuringUserCodeExecution(void *StateInfo);
115 
116 private:
117  bool tryAutoParseInternal(llvm::StringRef Name, clang::LookupResult &R,
118  clang::Scope *S, const clang::FileEntry* FE = 0);
119  bool tryFindROOTSpecialInternal(clang::LookupResult &R, clang::Scope *S);
120  bool tryResolveAtRuntimeInternal(clang::LookupResult &R, clang::Scope *S);
121  bool shouldResolveAtRuntime(clang::LookupResult &R, clang::Scope *S);
122  bool tryInjectImplicitAutoKeyword(clang::LookupResult &R, clang::Scope *S);
123 };