ROOT  6.06/09
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 "cling/Interpreter/Interpreter.h"
32 
33 #include "clang/AST/ASTContext.h"
34 #include "clang/AST/Decl.h"
35 #include "clang/Frontend/CompilerInstance.h"
36 
37 #include <vector>
38 #include <string>
39 
40 namespace clang {
41  class Decl;
42  class ValueDecl;
43 }
44 
45 namespace ROOT {
46  namespace TMetaUtils {
47  class TNormalizedCtxt;
48  }
49 }
50 
51 class TClingClassInfo;
52 
54 
55 private:
56 
57  cling::Interpreter *fInterp; // Cling interpreter, we do *not* own.
58  TClingClassInfo *fClassInfo; // Class we are iterating over, we own.
59  bool fFirstTime; // We need to skip the first increment to support the cint Next() semantics.
60  clang::DeclContext::decl_iterator fIter; // Current decl.
61  std::vector<clang::DeclContext::decl_iterator> fIterStack; // Recursion stack for traversing nested transparent scopes.
62  std::string fTitle; // The meta info for the member.
63  const clang::ValueDecl *fSingleDecl; // The single member
64 
65  llvm::SmallVector<clang::DeclContext *, 2> fContexts; // Set of DeclContext that we will iterate over.
66 
67  unsigned int fContextIdx; // Index in fContexts of DeclContext we are iterating over.
68  mutable std::string fIoType;
69  mutable std::string fIoName;
70  union {
71  float fFloat;
72  double fDouble;
73  long fLong;
74  } fConstInitVal; // Result of VarDecl::evaluateValue()
75  inline void CheckForIoTypeAndName () const;
76 
77 public:
78 
80 
81  explicit TClingDataMemberInfo(cling::Interpreter *interp)
82  : fInterp(interp), fClassInfo(0), fFirstTime(true), fSingleDecl(0), fContextIdx(0U)
83  {
84  fClassInfo = new TClingClassInfo(fInterp);
85  fIter = fInterp->getCI()->getASTContext().getTranslationUnitDecl()->decls_begin();
86  // Move to first global variable.
87  InternalNext();
88  }
89 
90  TClingDataMemberInfo(cling::Interpreter *, TClingClassInfo *);
91 
92  // Takes concrete decl and disables the iterator.
93  // ValueDecl is the common base between enum constant, var decl and field decl
94  TClingDataMemberInfo(cling::Interpreter *, const clang::ValueDecl *, TClingClassInfo *);
95 
97  {
98  fInterp = rhs.fInterp;
99  fClassInfo = new TClingClassInfo(*rhs.fClassInfo);
100  fFirstTime = rhs.fFirstTime;
101  fIter = rhs.fIter;
102  fIterStack = rhs.fIterStack;
103  fSingleDecl = rhs.fSingleDecl;
104  }
105 
107  {
108  if (this != &rhs) {
109  fInterp = rhs.fInterp;
110  delete fClassInfo;
111  fClassInfo = new TClingClassInfo(*rhs.fClassInfo);
112  fFirstTime = rhs.fFirstTime;
113  fIter = rhs.fIter;
114  fIterStack = rhs.fIterStack;
115  }
116  return *this;
117  }
118 
120 
121  int ArrayDim() const;
123  const clang::Decl *GetDecl() const { return fSingleDecl ? fSingleDecl : *fIter; }
124  DeclId_t GetDeclId() const;
125  bool IsValid() const { return GetDecl(); }
126  int MaxIndex(int dim) const;
127  int InternalNext();
128  bool Next() { return InternalNext(); }
129  long Offset();
130  long Property() const;
131  long TypeProperty() const;
132  int TypeSize() const;
133  const char *TypeName() const;
134  const char *TypeTrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
135  const char *Name() const;
136  const char *Title();
137  llvm::StringRef ValidArrayIndex() const;
138 
139 };
140 
141 #endif // ROOT_TClingDataMemberInfo
const char * Name() const
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
union TClingDataMemberInfo::@38 fConstInitVal
Emulation of the CINT DataMemberInfo class.
TClingDataMemberInfo(cling::Interpreter *interp)
llvm::StringRef ValidArrayIndex() const
clang::DeclContext::decl_iterator fIter
const void * DeclId_t
Definition: TDictionary.h:209
TClingClassInfo * GetClassInfo() const
std::vector< clang::DeclContext::decl_iterator > fIterStack
const char * TypeTrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
int MaxIndex(int dim) const
llvm::SmallVector< clang::DeclContext *, 2 > fContexts
void CheckForIoTypeAndName() const
TClingDataMemberInfo & operator=(const TClingDataMemberInfo &rhs)
const clang::Decl * GetDecl() const
cling::Interpreter * fInterp
const char * TypeName() const
TDictionary::DeclId_t DeclId_t
Definition: TCling.h:48
TClingDataMemberInfo(const TClingDataMemberInfo &rhs)
const clang::ValueDecl * fSingleDecl
Emulation of the CINT ClassInfo class.
TClingClassInfo * fClassInfo