Logo ROOT  
Reference Guide
TClingClassInfo.h
Go to the documentation of this file.
1 // @(#)root/core/meta:$Id$
2 // Author: Paul Russo 30/07/2012
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2019, 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 #ifndef ROOT_TClingClassInfo
13 #define ROOT_TClingClassInfo
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TClingClassInfo //
18 // //
19 // Emulation of the CINT ClassInfo class. //
20 // //
21 // The CINT C++ interpreter provides an interface to metadata about //
22 // a class through the ClassInfo class. This class provides the same //
23 // functionality, using an interface as close as possible to ClassInfo //
24 // but the class metadata comes from the Clang C++ compiler, not CINT. //
25 // //
26 //////////////////////////////////////////////////////////////////////////
27 
28 #include "TClingDeclInfo.h"
29 #include "TClingMethodInfo.h"
30 #include "TClingUtils.h"
31 #include "TDataType.h"
32 #include "TDictionary.h"
33 
34 #include <vector>
35 #include <string>
36 #include <utility>
37 #include <mutex>
38 
39 #include "llvm/ADT/DenseMap.h"
40 
41 namespace cling {
42  class Interpreter;
43 }
44 
45 namespace clang {
46  class CXXMethodDecl;
47  class FunctionTemplateDecl;
48  class ValueDecl;
49 }
50 
51 namespace ROOT {
52  namespace TMetaUtils {
53  class TNormalizedCtxt;
54  }
55 }
56 
57 extern "C" typedef ptrdiff_t (*OffsetPtrFunc_t)(void*, bool);
58 
59 class TClingClassInfo final : public TClingDeclInfo {
60 
61 private:
62 
63  cling::Interpreter *fInterp; // Cling interpreter, we do *not* own.
64  bool fFirstTime: 1; // We need to skip the first increment to support the cint Next() semantics.
65  bool fDescend : 1; // Flag for signaling the need to descend on this advancement.
66  bool fIterAll : 1; // Flag whether iteration should be as complete as possible.
67  bool fIsIter : 1; // Flag whether this object was setup for iteration.
68  clang::DeclContext::decl_iterator fIter; // Current decl in scope.
69  const clang::Type *fType; // Type representing the decl (conserves typedefs like Double32_t). (we do *not* own)
70  std::vector<clang::DeclContext::decl_iterator> fIterStack; // Recursion stack for traversing nested scopes.
71  std::string fTitle; // The meta info for the class.
72  std::string fDeclFileName; // Name of the file where the underlying entity is declared.
73 
74  std::mutex fOffsetCacheMutex;
75  llvm::DenseMap<const clang::Decl*, std::pair<ptrdiff_t, OffsetPtrFunc_t> > fOffsetCache; // Functions already generated for offsets.
76 
77  explicit TClingClassInfo() = delete;
79 public: // Types
80 
84  };
85 
86 public:
87 
88  TClingClassInfo(const TClingClassInfo &rhs) : // Copy all but the mutex
89  TClingDeclInfo(rhs),
91  fIterAll(rhs.fIterAll), fIsIter(rhs.fIsIter), fIter(rhs.fIter),
92  fType(rhs.fType), fIterStack(rhs.fIterStack), fTitle(rhs.fTitle),
94  {}
95  explicit TClingClassInfo(cling::Interpreter *, Bool_t all = kTRUE);
96  explicit TClingClassInfo(cling::Interpreter *, const char *classname, bool intantiateTemplate = kTRUE);
97  explicit TClingClassInfo(cling::Interpreter *, const clang::Type &);
98  explicit TClingClassInfo(cling::Interpreter *, const clang::Decl *);
99  void AddBaseOffsetFunction(const clang::Decl* decl, OffsetPtrFunc_t func) {
100  std::unique_lock<std::mutex> lock(fOffsetCacheMutex);
101  fOffsetCache[decl] = std::make_pair(0L, func);
102  }
103  void AddBaseOffsetValue(const clang::Decl* decl, ptrdiff_t offset);
104  long ClassProperty() const;
105  void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
106  void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
107  void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
108  const clang::ValueDecl *GetDataMember(const char *name) const;
109  void SetDecl(const clang::Decl* D) {
110  // FIXME: We should track down all sets and potentially avoid them.
111  fDecl = D;
112  fNameCache.clear(); // invalidate the cache.
113  }
115  if (!fDecl)
116  return nullptr;
117  return (const clang::Decl*)(fDecl->getCanonicalDecl());
118  }
119  const clang::FunctionTemplateDecl *GetFunctionTemplate(const char *fname) const;
120  TClingMethodInfo GetMethod(const char *fname) const;
121  TClingMethodInfo GetMethod(const char *fname, const char *proto,
122  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
123  EInheritanceMode imode = kWithInheritance) const;
124  TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist,
125  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
126  EInheritanceMode imode = kWithInheritance) const;
127  TClingMethodInfo GetMethod(const char *fname, const char *proto, bool objectIsConst,
128  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
129  EInheritanceMode imode = kWithInheritance) const;
130  TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, bool objectIsConst,
131  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
132  EInheritanceMode imode = kWithInheritance) const;
133  TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto,
134  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
135  EInheritanceMode imode = kWithInheritance) const;
136  TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto, bool objectIsConst,
137  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
138  EInheritanceMode imode = kWithInheritance) const;
139  int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch) const;
140  long GetOffset(const clang::CXXMethodDecl* md) const;
141  ptrdiff_t GetBaseOffset(TClingClassInfo* toBase, void* address, bool isDerivedObject);
142  const clang::Type *GetType() const { return fType; } // Underlying representation with Double32_t
143  std::vector<std::string> GetUsingNamespaces();
144  ROOT::TMetaUtils::EIOCtorCategory HasDefaultConstructor(bool checkio = false, std::string *type_name = nullptr) const;
145  bool HasMethod(const char *name) const;
146  void Init(const char *name);
147  void Init(const clang::Decl*);
148  void Init(int tagnum);
149  void Init(const clang::Type &);
150  bool IsBase(const char *name) const;
151  static bool IsEnum(cling::Interpreter *interp, const char *name);
152  bool IsScopedEnum() const;
154  bool IsLoaded() const;
155  bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, long *offset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch) const;
156  int InternalNext();
157  int Next();
158  void *New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
159  void *New(int n, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
160  void *New(int n, void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
161  void *New(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
162  long Property() const;
163  int RootFlag() const;
164  int Size() const;
165  long Tagnum() const;
166  const char *FileName();
167  void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
168  const char *Title();
169  const char *TmpltName() const;
170 
171 };
172 
173 #endif // ROOT_TClingClassInfo
TClingClassInfo::GetDataMember
const clang::ValueDecl * GetDataMember(const char *name) const
Definition: TClingClassInfo.cxx:277
TClingClassInfo::fFirstTime
bool fFirstTime
Definition: TClingClassInfo.h:64
TClingClassInfo::fTitle
std::string fTitle
Definition: TClingClassInfo.h:71
TClingClassInfo::GetMethodNArg
int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
Definition: TClingClassInfo.cxx:564
n
const Int_t n
Definition: legend1.C:16
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:89
TClingClassInfo::fType
const clang::Type * fType
Definition: TClingClassInfo.h:69
TClingClassInfo::AddBaseOffsetValue
void AddBaseOffsetValue(const clang::Decl *decl, ptrdiff_t offset)
Definition: TClingClassInfo.cxx:132
TClingClassInfo::fDescend
bool fDescend
Definition: TClingClassInfo.h:65
TClingClassInfo::FileName
const char * FileName()
Definition: TClingClassInfo.cxx:1357
ROOT::kConversionMatch
@ kConversionMatch
Definition: TDictionary.h:161
TClingClassInfo::ClassProperty
long ClassProperty() const
Definition: TClingClassInfo.cxx:142
TClingMethodInfo.h
output
static void output(int code)
Definition: gifencode.c:226
TClingClassInfo::fInterp
cling::Interpreter * fInterp
Definition: TClingClassInfo.h:63
TClingClassInfo::GetDeclId
TDictionary::DeclId_t GetDeclId() const
Definition: TClingClassInfo.h:114
TClingClassInfo::operator=
TClingClassInfo & operator=(const TClingClassInfo &)=delete
TClingClassInfo::Delete
void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Definition: TClingClassInfo.cxx:199
TClingDeclInfo
Definition: TClingDeclInfo.h:28
TClingClassInfo::Init
void Init(const char *name)
Definition: TClingClassInfo.cxx:721
TClingClassInfo::fIterStack
std::vector< clang::DeclContext::decl_iterator > fIterStack
Definition: TClingClassInfo.h:70
TClingClassInfo::GetOffset
long GetOffset(const clang::CXXMethodDecl *md) const
Definition: TClingClassInfo.cxx:584
TClingClassInfo::FullName
void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Definition: TClingClassInfo.cxx:1367
TClingClassInfo::Property
long Property() const
Definition: TClingClassInfo.cxx:1247
TClingClassInfo::fIter
clang::DeclContext::decl_iterator fIter
Definition: TClingClassInfo.h:68
TClingClassInfo::New
void * New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Definition: TClingClassInfo.cxx:1058
TClingClassInfo::IsBase
bool IsBase(const char *name) const
Definition: TClingClassInfo.cxx:790
TClingClassInfo::Title
const char * Title()
Definition: TClingClassInfo.cxx:1389
Bool_t
bool Bool_t
Definition: RtypesCore.h:61
ROOT::Math::IntegrationOneDim::Type
Type
enumeration specifying the integration types.
Definition: AllIntegrationTypes.h:45
TClingClassInfo::IsScopedEnum
bool IsScopedEnum() const
Definition: TClingClassInfo.cxx:824
TClingClassInfo::TmpltName
const char * TmpltName() const
Definition: TClingClassInfo.cxx:1429
TClingDeclInfo::fDecl
const clang::Decl * fDecl
Definition: TClingDeclInfo.h:30
bool
TClingClassInfo::GetMethodWithArgs
TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, long *poffset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch, EInheritanceMode imode=kWithInheritance) const
Definition: TClingClassInfo.cxx:498
TClingClassInfo::TClingClassInfo
TClingClassInfo()=delete
TClingClassInfo::Size
int Size() const
Definition: TClingClassInfo.cxx:1311
TGeant4Unit::L
static constexpr double L
Definition: TGeant4SystemOfUnits.h:117
TDictionary.h
TClingClassInfo::AddBaseOffsetFunction
void AddBaseOffsetFunction(const clang::Decl *decl, OffsetPtrFunc_t func)
Definition: TClingClassInfo.h:99
TClingClassInfo::HasDefaultConstructor
ROOT::TMetaUtils::EIOCtorCategory HasDefaultConstructor(bool checkio=false, std::string *type_name=nullptr) const
Definition: TClingClassInfo.cxx:671
TClingClassInfo::fDeclFileName
std::string fDeclFileName
Definition: TClingClassInfo.h:72
TClingClassInfo::IsEnum
static bool IsEnum(cling::Interpreter *interp, const char *name)
Definition: TClingClassInfo.cxx:814
TDataType.h
TClingClassInfo::GetBaseOffset
ptrdiff_t GetBaseOffset(TClingClassInfo *toBase, void *address, bool isDerivedObject)
Definition: TClingClassInfo.cxx:611
TClingMethodInfo
Emulation of the CINT MethodInfo class.
Definition: TClingMethodInfo.h:124
TClingClassInfo::fIterAll
bool fIterAll
Definition: TClingClassInfo.h:66
TClingClassInfo::TClingClassInfo
TClingClassInfo(cling::Interpreter *, const clang::Type &)
TClingClassInfo::TClingClassInfo
TClingClassInfo(const TClingClassInfo &rhs)
Definition: TClingClassInfo.h:88
TClingClassInfo::fIsIter
bool fIsIter
Definition: TClingClassInfo.h:67
TDictionary::DeclId_t
const void * DeclId_t
Definition: TDictionary.h:222
TClingClassInfo::Next
int Next()
Definition: TClingClassInfo.cxx:1053
TClingClassInfo::kInThisScope
@ kInThisScope
Definition: TClingClassInfo.h:82
TClingClassInfo
Emulation of the CINT ClassInfo class.
Definition: TClingClassInfo.h:59
OffsetPtrFunc_t
ptrdiff_t(* OffsetPtrFunc_t)(void *, bool)
Definition: TClingClassInfo.h:57
TClingClassInfo::RootFlag
int RootFlag() const
Definition: TClingClassInfo.cxx:1302
TClingClassInfo::fOffsetCache
llvm::DenseMap< const clang::Decl *, std::pair< ptrdiff_t, OffsetPtrFunc_t > > fOffsetCache
Definition: TClingClassInfo.h:75
TClingClassInfo::GetMethod
TClingMethodInfo GetMethod(const char *fname) const
Definition: TClingClassInfo.cxx:291
TClingClassInfo::Tagnum
long Tagnum() const
Definition: TClingClassInfo.cxx:1349
TClingClassInfo::GetFunctionTemplate
const clang::FunctionTemplateDecl * GetFunctionTemplate(const char *fname) const
Definition: TClingClassInfo.cxx:247
TClingClassInfo::SetDecl
void SetDecl(const clang::Decl *D)
Definition: TClingClassInfo.h:109
TClingClassInfo::GetUsingNamespaces
std::vector< std::string > GetUsingNamespaces()
Definition: TClingClassInfo.cxx:642
TClingClassInfo::IsValidMethod
bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, long *offset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
Definition: TClingClassInfo.cxx:909
TClingClassInfo::IsLoaded
bool IsLoaded() const
Definition: TClingClassInfo.cxx:879
ROOT::TMetaUtils::TNormalizedCtxt
Definition: TClingUtils.h:135
ROOT::EFunctionMatchMode
EFunctionMatchMode
Definition: TDictionary.h:159
ROOT::TMetaUtils::EIOCtorCategory
EIOCtorCategory
Definition: TClingUtils.h:356
proto
const char * proto
Definition: civetweb.c:16604
TClingClassInfo::HasMethod
bool HasMethod(const char *name) const
Definition: TClingClassInfo.cxx:709
TClingClassInfo::GetType
const clang::Type * GetType() const
Definition: TClingClassInfo.h:142
TClingClassInfo::kWithInheritance
@ kWithInheritance
Definition: TClingClassInfo.h:83
TClingDeclInfo.h
The file contains a base class of TCling*Info classes.
TClingClassInfo::EInheritanceMode
EInheritanceMode
Definition: TClingClassInfo.h:81
TClingClassInfo::Init
void Init(const clang::Type &)
EDataType
EDataType
Definition: TDataType.h:28
clang
Definition: BaseSelectionRule.h:29
TClingClassInfo::InternalNext
int InternalNext()
Definition: TClingClassInfo.cxx:925
TClingClassInfo::Init
void Init(const clang::Decl *)
TClingClassInfo::GetUnderlyingType
EDataType GetUnderlyingType() const
Definition: TClingClassInfo.cxx:831
TClingClassInfo::Destruct
void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Definition: TClingClassInfo.cxx:236
name
char name[80]
Definition: TGX11.cxx:109
TClingUtils.h
TClingDeclInfo::fNameCache
std::string fNameCache
Definition: TClingDeclInfo.h:31
TClingClassInfo::DeleteArray
void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Definition: TClingClassInfo.cxx:216
TClingClassInfo::TClingClassInfo
TClingClassInfo(cling::Interpreter *, const clang::Decl *)
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21
TClingClassInfo::fOffsetCacheMutex
std::mutex fOffsetCacheMutex
Definition: TClingClassInfo.h:74