Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
37 namespace cling {
38  class Interpreter;
39 }
40 
41 namespace clang {
42  class CXXMethodDecl;
43  class FunctionTemplateDecl;
44  class ValueDecl;
45 }
46 
47 namespace ROOT {
48  namespace TMetaUtils {
49  class TNormalizedCtxt;
50  }
51 }
52 
53 extern "C" typedef ptrdiff_t (*OffsetPtrFunc_t)(void*, bool);
54 
55 class TClingClassInfo final : public TClingDeclInfo {
56 
57 private:
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;
72  TClingClassInfo &operator=(const TClingClassInfo &) = delete;
73 public: // Types
74 
75  enum EInheritanceMode {
76  kInThisScope = 0,
77  kWithInheritance = 1
78  };
79 
80 public:
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 {
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,
106  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
107  EInheritanceMode imode = kWithInheritance) const;
108  TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist,
109  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
110  EInheritanceMode imode = kWithInheritance) const;
111  TClingMethodInfo GetMethod(const char *fname, const char *proto, bool objectIsConst,
112  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
113  EInheritanceMode imode = kWithInheritance) const;
114  TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, bool objectIsConst,
115  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
116  EInheritanceMode imode = kWithInheritance) const;
117  TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto,
118  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
119  EInheritanceMode imode = kWithInheritance) const;
120  TClingMethodInfo GetMethod(const char *fname, const llvm::SmallVectorImpl<clang::QualType> &proto, bool objectIsConst,
121  long *poffset, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch,
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;
137  EDataType GetUnderlyingType() 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