Logo ROOT   6.08/07
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 
79  ~TClingDataMemberInfo() { delete fClassInfo; }
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  fContextIdx(0)
98  {
99  fInterp = rhs.fInterp;
100  fClassInfo = new TClingClassInfo(*rhs.fClassInfo);
101  fFirstTime = rhs.fFirstTime;
102  fIter = rhs.fIter;
103  fIterStack = rhs.fIterStack;
104  fSingleDecl = rhs.fSingleDecl;
105  fContexts = rhs.fContexts;
106  fContextIdx = rhs.fContextIdx;
107  }
108 
110  {
111  if (this != &rhs) {
112  fInterp = rhs.fInterp;
113  delete fClassInfo;
114  fClassInfo = new TClingClassInfo(*rhs.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;
127  TClingClassInfo *GetClassInfo() const { return fClassInfo; }
128  const clang::Decl *GetDecl() const { return fSingleDecl ? fSingleDecl : *fIter; }
129  DeclId_t GetDeclId() const;
130  bool IsValid() const { return GetDecl(); }
131  int MaxIndex(int dim) const;
132  int InternalNext();
133  bool Next() { return InternalNext(); }
134  long Offset();
135  long Property() const;
136  long TypeProperty() const;
137  int TypeSize() const;
138  const char *TypeName() const;
139  const char *TypeTrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
140  const char *Name() const;
141  const char *Title();
142  llvm::StringRef ValidArrayIndex() const;
143 
144 };
145 
146 #endif // ROOT_TClingDataMemberInfo
RooCmdArg Offset(Bool_t flag=kTRUE)
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
const char * Title
Definition: TXMLSetup.cxx:68
Emulation of the CINT DataMemberInfo class.
TClingDataMemberInfo(cling::Interpreter *interp)
clang::DeclContext::decl_iterator fIter
const void * DeclId_t
Definition: TDictionary.h:209
const char * Name
Definition: TXMLSetup.cxx:67
std::vector< clang::DeclContext::decl_iterator > fIterStack
llvm::SmallVector< clang::DeclContext *, 2 > fContexts
TClingClassInfo * GetClassInfo() const
TClingDataMemberInfo & operator=(const TClingDataMemberInfo &rhs)
cling::Interpreter * fInterp
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
const clang::Decl * GetDecl() const