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
42namespace clang {
43 class Decl;
44 class ValueDecl;
45}
46
47namespace ROOT {
48 namespace TMetaUtils {
49 class TNormalizedCtxt;
50 }
51}
52
53class TClingClassInfo;
54
56
57private:
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
78public:
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.
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;
103 fIter = rhs.fIter;
105 fContexts = rhs.fContexts;
107 }
108
110 {
111 if (this != &rhs) {
112 fInterp = rhs.fInterp;
113 delete fClassInfo;
116 fIter = rhs.fIter;
118 fContexts = rhs.fContexts;
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() override;
144 const char *Title();
145 llvm::StringRef ValidArrayIndex() const;
146
147};
148
149#endif // ROOT_TClingDataMemberInfo
The file contains a base class of TCling*Info classes.
Emulation of the CINT ClassInfo class.
Emulation of the CINT DataMemberInfo class.
const char * TypeName() const
clang::DeclContext::decl_iterator fIter
const clang::Decl * GetDecl() const override
union TClingDataMemberInfo::@26 fConstInitVal
TClingDataMemberInfo(const TClingDataMemberInfo &rhs)
const char * TypeTrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
const char * Name() override
int MaxIndex(int dim) const
TClingClassInfo * fClassInfo
std::vector< clang::DeclContext::decl_iterator > fIterStack
TClingDataMemberInfo(cling::Interpreter *interp)
cling::Interpreter * fInterp
llvm::SmallVector< clang::DeclContext *, 2 > fContexts
llvm::StringRef ValidArrayIndex() const
TClingDataMemberInfo & operator=(const TClingDataMemberInfo &rhs)
TDictionary::DeclId_t DeclId_t
TClingClassInfo * GetClassInfo() const
virtual const clang::Decl * GetDecl() const
const void * DeclId_t
Definition: TDictionary.h:209
VSD Structures.
Definition: StringConv.hxx:21