Logo ROOT   master
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 "llvm/ADT/DenseMap.h"
37 
38 namespace cling {
39  class Interpreter;
40 }
41 
42 namespace clang {
43  class CXXMethodDecl;
44  class FunctionTemplateDecl;
45  class ValueDecl;
46 }
47 
48 namespace ROOT {
49  namespace TMetaUtils {
50  class TNormalizedCtxt;
51  }
52 }
53 
54 extern "C" typedef ptrdiff_t (*OffsetPtrFunc_t)(void*, bool);
55 
56 class TClingClassInfo final : public TClingDeclInfo {
57 
58 private:
59 
60  cling::Interpreter *fInterp; // Cling interpreter, we do *not* own.
61  bool fFirstTime: 1; // We need to skip the first increment to support the cint Next() semantics.
62  bool fDescend : 1; // Flag for signaling the need to descend on this advancement.
63  bool fIterAll : 1; // Flag whether iteration should be as complete as possible.
64  bool fIsIter : 1; // Flag whether this object was setup for iteration.
65  clang::DeclContext::decl_iterator fIter; // Current decl in scope.
66  const clang::Type *fType; // Type representing the decl (conserves typedefs like Double32_t). (we do *not* own)
67  std::vector<clang::DeclContext::decl_iterator> fIterStack; // Recursion stack for traversing nested scopes.
68  std::string fTitle; // The meta info for the class.
69  std::string fDeclFileName; // Name of the file where the underlying entity is declared.
70  llvm::DenseMap<const clang::Decl*, std::pair<ptrdiff_t, OffsetPtrFunc_t> > fOffsetCache; // Functions already generated for offsets.
71 
72  explicit TClingClassInfo() = delete;
73  TClingClassInfo &operator=(const TClingClassInfo &) = delete;
74 public: // Types
75 
79  };
80 
81 public:
82 
83  explicit TClingClassInfo(cling::Interpreter *, Bool_t all = kTRUE);
84  explicit TClingClassInfo(cling::Interpreter *, const char *classname, bool intantiateTemplate = kTRUE);
85  explicit TClingClassInfo(cling::Interpreter *, const clang::Type &);
86  explicit TClingClassInfo(cling::Interpreter *, const clang::Decl *);
87  void AddBaseOffsetFunction(const clang::Decl* decl, OffsetPtrFunc_t func) { fOffsetCache[decl] = std::make_pair(0L, func); }
88  void AddBaseOffsetValue(const clang::Decl* decl, ptrdiff_t offset);
89  long ClassProperty() const;
90  void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
91  void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
92  void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
93  const clang::ValueDecl *GetDataMember(const char *name) const;
94  void SetDecl(const clang::Decl* D) {
95  // FIXME: We should track down all sets and potentially avoid them.
96  fDecl = D;
97  fNameCache.clear(); // invalidate the cache.
98  }
100  if (!fDecl)
101  return nullptr;
102  return (const clang::Decl*)(fDecl->getCanonicalDecl());
103  }
104  const clang::FunctionTemplateDecl *GetFunctionTemplate(const char *fname) const;
105  TClingMethodInfo GetMethod(const char *fname) const;
106  TClingMethodInfo GetMethod(const char *fname, const char *proto,
107  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
108  EInheritanceMode imode = kWithInheritance) const;
109  TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist,
110  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
111  EInheritanceMode imode = kWithInheritance) const;
112  TClingMethodInfo GetMethod(const char *fname, const char *proto, bool objectIsConst,
113  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
114  EInheritanceMode imode = kWithInheritance) const;
115  TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, bool objectIsConst,
116  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
117  EInheritanceMode imode = kWithInheritance) const;
118  TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto,
119  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
120  EInheritanceMode imode = kWithInheritance) const;
121  TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto, bool objectIsConst,
122  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
123  EInheritanceMode imode = kWithInheritance) const;
124  int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch) const;
125  long GetOffset(const clang::CXXMethodDecl* md) const;
126  ptrdiff_t GetBaseOffset(TClingClassInfo* toBase, void* address, bool isDerivedObject);
127  const clang::Type *GetType() const { return fType; } // Underlying representation with Double32_t
128  std::vector<std::string> GetUsingNamespaces();
129  ROOT::TMetaUtils::EIOCtorCategory HasDefaultConstructor(bool checkio = false, std::string *type_name = nullptr) const;
130  bool HasMethod(const char *name) const;
131  void Init(const char *name);
132  void Init(const clang::Decl*);
133  void Init(int tagnum);
134  void Init(const clang::Type &);
135  bool IsBase(const char *name) const;
136  static bool IsEnum(cling::Interpreter *interp, const char *name);
137  bool IsScopedEnum() const;
139  bool IsLoaded() const;
140  bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, long *offset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch) const;
141  int InternalNext();
142  int Next();
143  void *New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
144  void *New(int n, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
145  void *New(int n, void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
146  void *New(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
147  long Property() const;
148  int RootFlag() const;
149  int Size() const;
150  long Tagnum() const;
151  const char *FileName();
152  void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
153  const char *Title();
154  const char *TmpltName() const;
155 
156 };
157 
158 #endif // ROOT_TClingClassInfo
const clang::FunctionTemplateDecl * GetFunctionTemplate(const char *fname) const
void AddBaseOffsetValue(const clang::Decl *decl, ptrdiff_t offset)
ROOT::TMetaUtils::EIOCtorCategory HasDefaultConstructor(bool checkio=false, std::string *type_name=nullptr) const
llvm::DenseMap< const clang::Decl *, std::pair< ptrdiff_t, OffsetPtrFunc_t > > fOffsetCache
Returns the available number of logical cores.
Definition: RNumpyDS.hxx:30
bool IsScopedEnum() const
const clang::Type * fType
TClingMethodInfo GetMethod(const char *fname) const
TClingClassInfo & operator=(const TClingClassInfo &)=delete
Emulation of the CINT MethodInfo class.
std::string fTitle
ptrdiff_t GetBaseOffset(TClingClassInfo *toBase, void *address, bool isDerivedObject)
long ClassProperty() const
bool Bool_t
Definition: RtypesCore.h:61
long Property() const
const char * FileName()
void SetDecl(const clang::Decl *D)
void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
const void * DeclId_t
Definition: TDictionary.h:209
ptrdiff_t(* OffsetPtrFunc_t)(void *, bool)
bool IsBase(const char *name) const
const char * Title()
EFunctionMatchMode
Definition: TDictionary.h:155
static bool IsEnum(cling::Interpreter *interp, const char *name)
long GetOffset(const clang::CXXMethodDecl *md) const
bool HasMethod(const char *name) const
const clang::ValueDecl * GetDataMember(const char *name) const
std::string fDeclFileName
const char * TmpltName() const
void Init(const char *name)
void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
TClingClassInfo()=delete
TDictionary::DeclId_t GetDeclId() const
Type
enumeration specifying the integration types.
void * New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
std::vector< std::string > GetUsingNamespaces()
bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, long *offset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
static constexpr double L
Print a TSeq at the prompt:
Definition: TDatime.h:115
EDataType
Definition: TDataType.h:28
Emulation of the CINT ClassInfo class.
const clang::Decl * fDecl
The file contains a base class of TCling*Info classes.
clang::DeclContext::decl_iterator fIter
EDataType GetUnderlyingType() const
void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
const char * proto
Definition: civetweb.c:16604
std::string fNameCache
std::vector< clang::DeclContext::decl_iterator > fIterStack
void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
bool IsLoaded() const
cling::Interpreter * fInterp
static void output(int code)
Definition: gifencode.c:226
const Bool_t kTRUE
Definition: RtypesCore.h:89
void AddBaseOffsetFunction(const clang::Decl *decl, OffsetPtrFunc_t func)
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109
const clang::Type * GetType() const
TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, long *poffset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch, EInheritanceMode imode=kWithInheritance) const