Logo ROOT  
Reference Guide
TClingDataMemberInfo.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-2000, 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_TClingDataMemberInfo
13 #define ROOT_TClingDataMemberInfo
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TClingDataMemberInfo //
18 // //
19 // Emulation of the CINT DataMemberInfo class. //
20 // //
21 // The CINT C++ interpreter provides an interface to metadata about //
22 // the data members of a class through the DataMemberInfo class. This //
23 // class provides the same functionality, using an interface as close //
24 // as possible to DataMemberInfo but the data member metadata comes //
25 // from the Clang C++ compiler, not CINT. //
26 // //
27 //////////////////////////////////////////////////////////////////////////
28 
29 #include "TClingClassInfo.h"
30 
31 #include "TClingDeclInfo.h"
32 
33 #include "cling/Interpreter/Interpreter.h"
34 
35 #include "clang/AST/ASTContext.h"
36 #include "clang/AST/Decl.h"
37 #include "clang/Frontend/CompilerInstance.h"
38 
39 #include <vector>
40 #include <string>
41 
42 namespace clang {
43  class Decl;
44  class ValueDecl;
45 }
46 
47 namespace ROOT {
48  namespace TMetaUtils {
49  class TNormalizedCtxt;
50  }
51 }
52 
53 class TClingClassInfo;
54 
55 class TClingDataMemberInfo final : public TClingDeclInfo {
56 
57 private:
58 
59  cling::Interpreter *fInterp; // Cling interpreter, we do *not* own.
60  TClingClassInfo *fClassInfo; // Class we are iterating over, we own.
61  bool fFirstTime; // We need to skip the first increment to support the cint Next() semantics.
62  clang::DeclContext::decl_iterator fIter; // Current decl.
63  std::vector<clang::DeclContext::decl_iterator> fIterStack; // Recursion stack for traversing nested transparent scopes.
64  std::string fTitle; // The meta info for the member.
65 
66  llvm::SmallVector<clang::DeclContext *, 2> fContexts; // Set of DeclContext that we will iterate over.
67 
68  unsigned int fContextIdx; // Index in fContexts of DeclContext we are iterating over.
69  mutable std::string fIoType;
70  mutable std::string fIoName;
71  union {
72  float fFloat;
73  double fDouble;
74  long fLong;
75  } fConstInitVal; // Result of VarDecl::evaluateValue()
76  inline void CheckForIoTypeAndName () const;
77 
78 public:
79 
81 
82  explicit TClingDataMemberInfo(cling::Interpreter *interp)
83  : TClingDeclInfo(nullptr), fInterp(interp), fClassInfo(0), fFirstTime(true), fContextIdx(0U)
84  {
86  fIter = fInterp->getCI()->getASTContext().getTranslationUnitDecl()->decls_begin();
87  // Move to first global variable.
88  InternalNext();
89  }
90 
91  TClingDataMemberInfo(cling::Interpreter *, TClingClassInfo *);
92 
93  // Takes concrete decl and disables the iterator.
94  // ValueDecl is the common base between enum constant, var decl and field decl
95  TClingDataMemberInfo(cling::Interpreter *, const clang::ValueDecl *, TClingClassInfo *);
96 
99  {
100  fInterp = rhs.fInterp;
102  fFirstTime = rhs.fFirstTime;
103  fIter = rhs.fIter;
104  fIterStack = rhs.fIterStack;
105  fContexts = rhs.fContexts;
106  fContextIdx = rhs.fContextIdx;
107  }
108 
110  {
111  if (this != &rhs) {
112  fInterp = rhs.fInterp;
113  delete fClassInfo;
115  fFirstTime = rhs.fFirstTime;
116  fIter = rhs.fIter;
117  fIterStack = rhs.fIterStack;
118  fContexts = rhs.fContexts;
119  fContextIdx = rhs.fContextIdx;
120  }
121  return *this;
122  }
123 
125 
126  int ArrayDim() const;
128  const clang::Decl *GetDecl() const override {
129  if (const clang::Decl* SingleDecl = TClingDeclInfo::GetDecl())
130  return SingleDecl;
131  return *fIter;
132  }
133  DeclId_t GetDeclId() const;
134  int MaxIndex(int dim) const;
135  int InternalNext();
136  bool Next() { return InternalNext(); }
137  long Offset();
138  long Property() const;
139  long TypeProperty() const;
140  int TypeSize() const;
141  const char *TypeName() const;
142  const char *TypeTrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
143  const char *Name() const override;
144  const char *Title();
145  llvm::StringRef ValidArrayIndex() const;
146 
147 };
148 
149 #endif // ROOT_TClingDataMemberInfo
TClingDataMemberInfo::fConstInitVal
union TClingDataMemberInfo::@26 fConstInitVal
TClingDataMemberInfo::TypeProperty
long TypeProperty() const
Definition: TClingDataMemberInfo.cxx:466
TClingDataMemberInfo::GetDeclId
DeclId_t GetDeclId() const
Definition: TClingDataMemberInfo.cxx:116
TClingDataMemberInfo::ValidArrayIndex
llvm::StringRef ValidArrayIndex() const
Definition: TClingDataMemberInfo.cxx:610
TClingDataMemberInfo::TypeTrueName
const char * TypeTrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Definition: TClingDataMemberInfo.cxx:530
TClingDataMemberInfo::TClingDataMemberInfo
TClingDataMemberInfo(const TClingDataMemberInfo &rhs)
Definition: TClingDataMemberInfo.h:97
TClingDataMemberInfo::fClassInfo
TClingClassInfo * fClassInfo
Definition: TClingDataMemberInfo.h:60
TClingDataMemberInfo::Offset
long Offset()
Definition: TClingDataMemberInfo.cxx:309
TClingDataMemberInfo::fFirstTime
bool fFirstTime
Definition: TClingDataMemberInfo.h:61
TClingDataMemberInfo::DeclId_t
TDictionary::DeclId_t DeclId_t
Definition: TClingDataMemberInfo.h:124
TClingDataMemberInfo::InternalNext
int InternalNext()
Definition: TClingDataMemberInfo.cxx:238
TClingDataMemberInfo::TypeName
const char * TypeName() const
Definition: TClingDataMemberInfo.cxx:500
TClingDataMemberInfo::MaxIndex
int MaxIndex(int dim) const
Definition: TClingDataMemberInfo.cxx:171
TClingDataMemberInfo::fIterStack
std::vector< clang::DeclContext::decl_iterator > fIterStack
Definition: TClingDataMemberInfo.h:63
TClingDeclInfo
Definition: TClingDeclInfo.h:28
TClingDataMemberInfo::TClingDataMemberInfo
TClingDataMemberInfo(cling::Interpreter *interp)
Definition: TClingDataMemberInfo.h:82
TClingDataMemberInfo::fContextIdx
unsigned int fContextIdx
Definition: TClingDataMemberInfo.h:68
TClingDataMemberInfo::Name
const char * Name() const override
Definition: TClingDataMemberInfo.cxx:562
TDictionary::DeclId_t
const typedef void * DeclId_t
Definition: TDictionary.h:209
TClingDataMemberInfo::fIter
clang::DeclContext::decl_iterator fIter
Definition: TClingDataMemberInfo.h:62
TClingClassInfo.h
TClingDataMemberInfo::Title
const char * Title()
Definition: TClingDataMemberInfo.cxx:574
TClingDataMemberInfo::TypeSize
int TypeSize() const
Definition: TClingDataMemberInfo.cxx:476
TClingDataMemberInfo::Property
long Property() const
Definition: TClingDataMemberInfo.cxx:388
TClingDataMemberInfo::fFloat
float fFloat
Definition: TClingDataMemberInfo.h:72
TClingClassInfo
Definition: TClingClassInfo.h:58
TClingDataMemberInfo
Definition: TClingDataMemberInfo.h:55
TClingDataMemberInfo::CheckForIoTypeAndName
void CheckForIoTypeAndName() const
Definition: TClingDataMemberInfo.cxx:98
TClingDataMemberInfo::operator=
TClingDataMemberInfo & operator=(const TClingDataMemberInfo &rhs)
Definition: TClingDataMemberInfo.h:109
TClingDataMemberInfo::fLong
long fLong
Definition: TClingDataMemberInfo.h:74
ROOT::TMetaUtils::TNormalizedCtxt
Definition: TClingUtils.h:138
TClingDataMemberInfo::fTitle
std::string fTitle
Definition: TClingDataMemberInfo.h:64
TClingDataMemberInfo::fContexts
llvm::SmallVector< clang::DeclContext *, 2 > fContexts
Definition: TClingDataMemberInfo.h:66
TClingDeclInfo.h
The file contains a base class of TCling*Info classes.
TClingDataMemberInfo::GetClassInfo
TClingClassInfo * GetClassInfo() const
Definition: TClingDataMemberInfo.h:127
clang
Definition: BaseSelectionRule.h:29
TClingDataMemberInfo::fInterp
cling::Interpreter * fInterp
Definition: TClingDataMemberInfo.h:59
TClingDeclInfo::GetDecl
virtual const clang::Decl * GetDecl() const
Definition: TClingDeclInfo.h:37
TClingDataMemberInfo::GetDecl
const clang::Decl * GetDecl() const override
Definition: TClingDataMemberInfo.h:128
TClingDataMemberInfo::ArrayDim
int ArrayDim() const
Definition: TClingDataMemberInfo.cxx:124
TClingDataMemberInfo::fIoName
std::string fIoName
Definition: TClingDataMemberInfo.h:70
ROOT
VSD Structures.
Definition: StringConv.hxx:21
TClingDataMemberInfo::~TClingDataMemberInfo
~TClingDataMemberInfo()
Definition: TClingDataMemberInfo.h:80
TClingDataMemberInfo::fIoType
std::string fIoType
Definition: TClingDataMemberInfo.h:69
TClingDataMemberInfo::Next
bool Next()
Definition: TClingDataMemberInfo.h:136
TClingDataMemberInfo::fDouble
double fDouble
Definition: TClingDataMemberInfo.h:73