Logo ROOT   6.18/05
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 *);
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 }
98 TDictionary::DeclId_t GetDeclId() const { return (const clang::Decl*)(fDecl->getCanonicalDecl()); }
99 const clang::FunctionTemplateDecl *GetFunctionTemplate(const char *fname) const;
100 TClingMethodInfo GetMethod(const char *fname) const;
101 TClingMethodInfo GetMethod(const char *fname, const char *proto,
103 EInheritanceMode imode = kWithInheritance) const;
104 TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist,
106 EInheritanceMode imode = kWithInheritance) const;
107 TClingMethodInfo GetMethod(const char *fname, const char *proto, bool objectIsConst,
109 EInheritanceMode imode = kWithInheritance) const;
110 TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, bool objectIsConst,
112 EInheritanceMode imode = kWithInheritance) const;
113 TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto,
115 EInheritanceMode imode = kWithInheritance) const;
116 TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto, bool objectIsConst,
118 EInheritanceMode imode = kWithInheritance) const;
119 int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch) const;
120 long GetOffset(const clang::CXXMethodDecl* md) const;
121 ptrdiff_t GetBaseOffset(TClingClassInfo* toBase, void* address, bool isDerivedObject);
122 const clang::Type *GetType() const { return fType; } // Underlying representation with Double32_t
123 std::vector<std::string> GetUsingNamespaces();
124 bool HasDefaultConstructor() const;
125 bool HasMethod(const char *name) const;
126 void Init(const char *name);
127 void Init(const clang::Decl*);
128 void Init(int tagnum);
129 void Init(const clang::Type &);
130 bool IsBase(const char *name) const;
131 static bool IsEnum(cling::Interpreter *interp, const char *name);
132 bool IsScopedEnum() const;
134 bool IsLoaded() const;
135 bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, long *offset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch) const;
136 int InternalNext();
137 int Next();
138 void *New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
139 void *New(int n, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
140 void *New(int n, void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
141 void *New(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
142 long Property() const;
143 int RootFlag() const;
144 int Size() const;
145 long Tagnum() const;
146 const char *FileName();
147 void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
148 const char *Title();
149 const char *TmpltName() const;
150
151};
152
153#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:206
Type
enumeration specifying the integration types.
const Int_t n
Definition: legend1.C:16
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
EFunctionMatchMode
Definition: TDictionary.h:152
@ kConversionMatch
Definition: TDictionary.h:154
static constexpr double L
static void output(int code)
Definition: gifencode.c:226