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
41namespace cling {
42 class Interpreter;
43}
44
45namespace clang {
46 class CXXMethodDecl;
47 class FunctionTemplateDecl;
48 class ValueDecl;
49}
50
51namespace ROOT {
52 namespace TMetaUtils {
53 class TNormalizedCtxt;
54 }
55}
56
57extern "C" typedef ptrdiff_t (*OffsetPtrFunc_t)(void*, bool);
58
59class TClingClassInfo final : public TClingDeclInfo {
60
61private:
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
75 llvm::DenseMap<const clang::Decl*, std::pair<ptrdiff_t, OffsetPtrFunc_t> > fOffsetCache; // Functions already generated for offsets.
76
77 explicit TClingClassInfo() = delete;
79public: // Types
80
84 };
85
86public:
87
88 TClingClassInfo(const TClingClassInfo &rhs) : // Copy all but the mutex
89 TClingDeclInfo(rhs),
91 fIterAll(rhs.fIterAll), fIsIter(rhs.fIsIter), fIter(rhs.fIter),
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,
123 EInheritanceMode imode = kWithInheritance) const;
124 TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist,
126 EInheritanceMode imode = kWithInheritance) const;
127 TClingMethodInfo GetMethod(const char *fname, const char *proto, bool objectIsConst,
129 EInheritanceMode imode = kWithInheritance) const;
130 TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, bool objectIsConst,
132 EInheritanceMode imode = kWithInheritance) const;
133 TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto,
135 EInheritanceMode imode = kWithInheritance) const;
136 TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto, bool objectIsConst,
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
bool Bool_t
Definition: RtypesCore.h:61
const Bool_t kTRUE
Definition: RtypesCore.h:89
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.
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
std::mutex fOffsetCacheMutex
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
ROOT::TMetaUtils::EIOCtorCategory HasDefaultConstructor(bool checkio=false, std::string *type_name=nullptr) 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
TClingClassInfo(const TClingClassInfo &rhs)
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:222
Type
enumeration specifying the integration types.
const Int_t n
Definition: legend1.C:16
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21
EFunctionMatchMode
Definition: TDictionary.h:159
@ kConversionMatch
Definition: TDictionary.h:161
static constexpr double L
static void output(int code)
Definition: gifencode.c:226