Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 = nullptr; // 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 = nullptr; // 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
77public: // Types
78
82 };
83
84public:
85 explicit TClingClassInfo():
86 fFirstTime(true), fDescend(false),
87 fIterAll(false), fIsIter(false)
88 {}
89 TClingClassInfo(const TClingClassInfo &rhs) : // Copy all but the mutex
90 TClingDeclInfo(rhs),
92 fIterAll(rhs.fIterAll), fIsIter(rhs.fIsIter), fIter(rhs.fIter),
95 {}
96 explicit TClingClassInfo(cling::Interpreter *, Bool_t all = kTRUE);
97 explicit TClingClassInfo(cling::Interpreter *, const char *classname, bool intantiateTemplate = kTRUE);
98 explicit TClingClassInfo(cling::Interpreter *interp, const clang::Type &tag);
99 explicit TClingClassInfo(cling::Interpreter *interp, const clang::Decl *D);
101 {
102 // Copy all but the mutex
103 *((TClingDeclInfo*)this) = rhs;
104 fInterp = rhs.fInterp;
106 fDescend = rhs.fDescend;
107 fIterAll = rhs.fIterAll;
108 fIsIter = rhs.fIsIter;
109 fIter = rhs.fIter;
110 fType = rhs.fType;
112 fTitle = rhs.fTitle;
115 return *this;
116 }
117
118 void AddBaseOffsetFunction(const clang::Decl* decl, OffsetPtrFunc_t func) {
119 std::unique_lock<std::mutex> lock(fOffsetCacheMutex);
120 fOffsetCache[decl] = std::make_pair(0L, func);
121 }
122 void AddBaseOffsetValue(const clang::Decl* decl, ptrdiff_t offset);
123 long ClassProperty() const;
124 void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
125 void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
126 void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
127 const clang::ValueDecl *GetDataMember(const char *name) const;
128 void SetDecl(const clang::Decl* D) {
129 // FIXME: We should track down all sets and potentially avoid them.
130 fDecl = D;
131 fNameCache.clear(); // invalidate the cache.
132 }
134 if (!fDecl)
135 return nullptr;
136 return (const clang::Decl*)(fDecl->getCanonicalDecl());
137 }
138 const clang::FunctionTemplateDecl *GetFunctionTemplate(const char *fname) const;
139 TClingMethodInfo GetMethod(const char *fname) const;
140 TClingMethodInfo GetMethod(const char *fname, const char *proto,
142 EInheritanceMode imode = kWithInheritance) const;
143 TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist,
145 EInheritanceMode imode = kWithInheritance) const;
146 TClingMethodInfo GetMethod(const char *fname, const char *proto, bool objectIsConst,
148 EInheritanceMode imode = kWithInheritance) const;
149 TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, bool objectIsConst,
151 EInheritanceMode imode = kWithInheritance) const;
152 TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto,
154 EInheritanceMode imode = kWithInheritance) const;
155 TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto, bool objectIsConst,
157 EInheritanceMode imode = kWithInheritance) const;
158 int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch) const;
159 Longptr_t GetOffset(const clang::CXXMethodDecl* md) const;
160 ptrdiff_t GetBaseOffset(TClingClassInfo* toBase, void* address, bool isDerivedObject);
161 const clang::Type *GetType() const { return fType; } // Underlying representation with Double32_t
162 std::vector<std::string> GetUsingNamespaces();
163 ROOT::TMetaUtils::EIOCtorCategory HasDefaultConstructor(bool checkio = false, std::string *type_name = nullptr) const;
164 bool HasMethod(const char *name) const;
165 void Init(const char *name);
166 void Init(const clang::Decl* decl);
167 void Init(int tagnum);
168 void Init(const clang::Type &tag);
169 bool IsBase(const char *name) const;
170 static bool IsEnum(cling::Interpreter *interp, const char *name);
171 bool IsScopedEnum() const;
173 bool IsLoaded() const;
174 bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, Longptr_t *offset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch) const;
175 int InternalNext();
176 int Next();
177 void *New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
178 void *New(int n, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
179 void *New(int n, void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
180 void *New(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
181 long Property() const;
182 int RootFlag() const;
183 int Size() const;
184 Longptr_t Tagnum() const;
185 const char *FileName();
186 void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
187 const char *Title();
188 const char *TmpltName() const;
189
190};
191
192#endif // ROOT_TClingClassInfo
bool Bool_t
Definition RtypesCore.h:63
long Longptr_t
Definition RtypesCore.h:82
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
ptrdiff_t(* OffsetPtrFunc_t)(void *, bool)
The file contains a base class of TCling*Info classes.
EDataType
Definition TDataType.h:28
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char mode
char name[80]
Definition TGX11.cxx:110
const char * proto
Definition civetweb.c:17502
Emulation of the CINT ClassInfo class.
clang::DeclContext::decl_iterator fIter
const char * Title()
static bool IsEnum(cling::Interpreter *interp, const char *name)
TClingClassInfo(cling::Interpreter *interp, const clang::Type &tag)
long ClassProperty() const
void Init(const char *name)
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
EDataType GetUnderlyingType() const
std::mutex fOffsetCacheMutex
const char * TmpltName() const
void AddBaseOffsetValue(const clang::Decl *decl, ptrdiff_t offset)
const clang::Type * GetType() const
Longptr_t GetOffset(const clang::CXXMethodDecl *md) const
ptrdiff_t GetBaseOffset(TClingClassInfo *toBase, void *address, bool isDerivedObject)
Longptr_t Tagnum() const
void SetDecl(const clang::Decl *D)
bool IsScopedEnum() const
ROOT::TMetaUtils::EIOCtorCategory HasDefaultConstructor(bool checkio=false, std::string *type_name=nullptr) const
TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, Longptr_t *poffset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch, EInheritanceMode imode=kWithInheritance) const
const clang::FunctionTemplateDecl * GetFunctionTemplate(const char *fname) const
int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, Longptr_t *offset, 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
void Init(const clang::Decl *decl)
TClingMethodInfo GetMethod(const char *fname) const
bool IsLoaded() const
TClingClassInfo(const TClingClassInfo &rhs)
void Init(const clang::Type &tag)
const clang::ValueDecl * GetDataMember(const char *name) const
TClingClassInfo(cling::Interpreter *interp, const clang::Decl *D)
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()
std::vector< clang::DeclContext::decl_iterator > fIterStack
bool IsBase(const char *name) const
const clang::Type * fType
TClingClassInfo & operator=(const TClingClassInfo &rhs)
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
const Int_t n
Definition legend1.C:16
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
EFunctionMatchMode
@ kConversionMatch
static void output()