ROOT  6.06/09
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-2000, 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 "TClingMethodInfo.h"
29 #include "TDictionary.h"
30 
31 #include <vector>
32 #include <string>
33 #include "llvm/ADT/DenseMap.h"
34 
35 namespace cling {
36  class Interpreter;
37 }
38 
39 namespace clang {
40  class CXXMethodDecl;
41  class FunctionTemplateDecl;
42  class ValueDecl;
43 }
44 
45 namespace ROOT {
46  namespace TMetaUtils {
47  class TNormalizedCtxt;
48  }
49 }
50 
51 extern "C" typedef ptrdiff_t (*OffsetPtrFunc_t)(void*, bool);
52 
54 
55 private:
56 
57  cling::Interpreter *fInterp; // Cling interpreter, we do *not* own.
58  bool fFirstTime; // We need to skip the first increment to support the cint Next() semantics.
59  bool fDescend; // Flag for signaling the need to descend on this advancement.
60  bool fIterAll; // Flag whether iteration should be as complete as possible.
61  clang::DeclContext::decl_iterator fIter; // Current decl in scope.
62  const clang::Decl *fDecl; // Current decl, we do *not* own.
63  const clang::Type *fType; // Type representing the decl (conserves typedefs like Double32_t). (we do *not* own)
64  std::vector<clang::DeclContext::decl_iterator> fIterStack; // Recursion stack for traversing nested scopes.
65  std::string fTitle; // The meta info for the class.
66  std::string fDeclFileName; // Name of the file where the underlying entity is declared.
67  llvm::DenseMap<const clang::Decl*, std::pair<ptrdiff_t, OffsetPtrFunc_t> > fOffsetCache; // Functions already generated for offsets.
68 
69  explicit TClingClassInfo() /* = delete */; // NOT IMPLEMENTED
70  TClingClassInfo &operator=(const TClingClassInfo &) /* = delete */; // NOT IMPLEMENTED
71 public: // Types
72 
76  };
77 
78 public:
79 
80  explicit TClingClassInfo(cling::Interpreter *, Bool_t all = kTRUE);
81  explicit TClingClassInfo(cling::Interpreter *, const char *);
82  explicit TClingClassInfo(cling::Interpreter *, const clang::Type &);
83  void AddBaseOffsetFunction(const clang::Decl* decl, OffsetPtrFunc_t func) { fOffsetCache[decl] = std::make_pair(0L, func); }
84  void AddBaseOffsetValue(const clang::Decl* decl, ptrdiff_t offset);
85  long ClassProperty() const;
86  void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
87  void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
88  void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
89  const clang::ValueDecl *GetDataMember(const char *name) const;
90  const clang::Decl *GetDecl() const { return fDecl; } // Underlying representation without Double32_t
91  TDictionary::DeclId_t GetDeclId() const { return (const clang::Decl*)(fDecl->getCanonicalDecl()); }
92  const clang::FunctionTemplateDecl *GetFunctionTemplate(const char *fname) const;
93  TClingMethodInfo GetMethod(const char *fname) const;
94  TClingMethodInfo GetMethod(const char *fname, const char *proto,
96  EInheritanceMode imode = kWithInheritance) const;
97  TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist,
99  EInheritanceMode imode = kWithInheritance) const;
100  TClingMethodInfo GetMethod(const char *fname, const char *proto, bool objectIsConst,
101  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
102  EInheritanceMode imode = kWithInheritance) const;
103  TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, bool objectIsConst,
104  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
105  EInheritanceMode imode = kWithInheritance) const;
106  TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto,
107  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
108  EInheritanceMode imode = kWithInheritance) const;
109  TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto, bool objectIsConst,
110  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
111  EInheritanceMode imode = kWithInheritance) const;
112  int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch) const;
113  long GetOffset(const clang::CXXMethodDecl* md) const;
114  ptrdiff_t GetBaseOffset(TClingClassInfo* toBase, void* address, bool isDerivedObject);
115  const clang::Type *GetType() const { return fType; } // Underlying representation with Double32_t
116  bool HasDefaultConstructor() const;
117  bool HasMethod(const char *name) const;
118  void Init(const char *name);
119  void Init(const clang::Decl*);
120  void Init(int tagnum);
121  void Init(const clang::Type &);
122  bool IsBase(const char *name) const;
123  static bool IsEnum(cling::Interpreter *interp, const char *name);
124  bool IsLoaded() const;
125  bool IsValid() const;
126  bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, long *offset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch) const;
127  int InternalNext();
128  int Next();
129  void *New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
130  void *New(int n, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
131  void *New(int n, void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
132  void *New(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
133  long Property() const;
134  int RootFlag() const;
135  int Size() const;
136  long Tagnum() const;
137  const char *FileName();
138  void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
139  const char *Name() const;
140  const char *Title();
141  const char *TmpltName() const;
142 
143 };
144 
145 #endif // ROOT_TClingClassInfo
const clang::FunctionTemplateDecl * GetFunctionTemplate(const char *fname) const
void AddBaseOffsetValue(const clang::Decl *decl, ptrdiff_t offset)
llvm::DenseMap< const clang::Decl *, std::pair< ptrdiff_t, OffsetPtrFunc_t > > fOffsetCache
bool IsLoaded() const
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
bool IsValid() const
const char * Name() const
RooArgList L(const RooAbsArg &v1)
const clang::Type * fType
int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
bool HasMethod(const char *name) const
void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Emulation of the CINT MethodInfo class.
TClingClassInfo & operator=(const TClingClassInfo &)
std::string fTitle
ptrdiff_t GetBaseOffset(TClingClassInfo *toBase, void *address, bool isDerivedObject)
bool HasDefaultConstructor() const
TClingMethodInfo GetMethod(const char *fname) const
bool Bool_t
Definition: RtypesCore.h:59
long Tagnum() const
const char * FileName()
const clang::Type * GetType() const
const void * DeclId_t
Definition: TDictionary.h:209
ptrdiff_t(* OffsetPtrFunc_t)(void *, bool)
const clang::Decl * fDecl
const char * Title()
long ClassProperty() const
EFunctionMatchMode
Definition: TDictionary.h:155
static bool IsEnum(cling::Interpreter *interp, const char *name)
long GetOffset(const clang::CXXMethodDecl *md) const
std::string fDeclFileName
const char * TmpltName() const
void Init(const char *name)
Type
enumeration specifying the integration types.
const clang::Decl * GetDecl() const
Definition: TCling.h:48
void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Definition: TDatime.h:114
double func(double *x, double *p)
Definition: stressTF1.cxx:213
void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Emulation of the CINT ClassInfo class.
long Property() const
const clang::ValueDecl * GetDataMember(const char *name) const
void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
void * New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
#define name(a, b)
Definition: linkTestLib0.cpp:5
clang::DeclContext::decl_iterator fIter
TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, long *poffset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch, EInheritanceMode imode=kWithInheritance) const
std::vector< clang::DeclContext::decl_iterator > fIterStack
bool IsBase(const char *name) const
bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, long *offset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
cling::Interpreter * fInterp
static void output(int code)
Definition: gifencode.c:226
const Bool_t kTRUE
Definition: Rtypes.h:91
void AddBaseOffsetFunction(const clang::Decl *decl, OffsetPtrFunc_t func)
const Int_t n
Definition: legend1.C:16
TDictionary::DeclId_t GetDeclId() const
int RootFlag() const