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