31 #include "clang/AST/Attr.h"
32 #include "clang/AST/ASTContext.h"
33 #include "clang/AST/Decl.h"
34 #include "clang/AST/GlobalDecl.h"
35 #include "clang/AST/Expr.h"
36 #include "clang/AST/ExprCXX.h"
37 #include "clang/AST/PrettyPrinter.h"
38 #include "clang/AST/RecordLayout.h"
39 #include "clang/AST/Type.h"
41 #include "llvm/Support/Casting.h"
42 #include "llvm/Support/raw_ostream.h"
43 #include "llvm/ADT/APSInt.h"
44 #include "llvm/ADT/APFloat.h"
46 using namespace clang;
50 : fInterp(interp), fClassInfo(0), fFirstTime(true), fTitle(
""), fSingleDecl(0), fContextIdx(0U), fIoType(
""), fIoName(
"")
61 clang::DeclContext *dc = llvm::cast<clang::DeclContext>(D);
65 cling::Interpreter::PushTransactionRAII RAII(interp);
66 fIter = llvm::cast<clang::DeclContext>(D)->decls_begin();
69 fIter = TD->decls_begin();
79 const clang::ValueDecl *ValD,
82 fTitle(
""), fSingleDecl(ValD), fContextIdx(0U), fIoType(
""), fIoName(
""){
85 assert((ci || isa<TranslationUnitDecl>(ValD->getDeclContext()) ||
86 (ValD->getDeclContext()->isTransparentContext() && isa<TranslationUnitDecl>(ValD->getDeclContext()->getParent()) ) ||
87 isa<EnumConstantDecl>(ValD)) &&
"Not TU?");
88 assert((isa<VarDecl>(ValD) ||
89 isa<FieldDecl>(ValD) ||
90 isa<EnumConstantDecl>(ValD) ||
91 isa<IndirectFieldDecl>(ValD)) &&
92 "The decl should be either VarDecl or FieldDecl or EnumConstDecl");
103 unsigned int code =
fIoType.empty() + (int(
fIoName.empty()) << 1);
105 if (code == 0)
return;
119 return (
const clang::Decl*)(
GetDecl()->getCanonicalDecl());
128 clang::Decl::Kind DK =
GetDecl()->getKind();
130 (DK != clang::Decl::Field) &&
131 (DK != clang::Decl::Var) &&
132 (DK != clang::Decl::EnumConstant)
137 if (DK == clang::Decl::EnumConstant) {
143 const clang::ValueDecl *VD = llvm::dyn_cast<clang::ValueDecl>(
GetDecl());
144 clang::QualType QT = VD->getType().getCanonicalType();
147 if (QT->isArrayType()) {
149 QT = llvm::cast<clang::ArrayType>(QT)->getElementType();
152 else if (QT->isReferenceType()) {
153 QT = llvm::cast<clang::ReferenceType>(QT)->getPointeeType();
156 else if (QT->isPointerType()) {
157 QT = llvm::cast<clang::PointerType>(QT)->getPointeeType();
160 else if (QT->isMemberPointerType()) {
161 QT = llvm::cast<clang::MemberPointerType>(QT)->getPointeeType();
175 clang::Decl::Kind DK =
GetDecl()->getKind();
177 (DK != clang::Decl::Field) &&
178 (DK != clang::Decl::Var) &&
179 (DK != clang::Decl::EnumConstant)
184 if (DK == clang::Decl::EnumConstant) {
190 const clang::ValueDecl *VD = llvm::dyn_cast<clang::ValueDecl>(
GetDecl());
191 clang::QualType QT = VD->getType().getCanonicalType();
193 if ((dim < 0) || (dim >= paran)) {
200 if (QT->isArrayType()) {
202 if (
const clang::ConstantArrayType *
CAT =
203 llvm::dyn_cast<clang::ConstantArrayType>(QT)
205 max =
static_cast<int>(
CAT->getSize().getZExtValue());
207 else if (llvm::dyn_cast<clang::IncompleteArrayType>(QT)) {
216 QT = llvm::cast<clang::ArrayType>(QT)->getElementType();
219 else if (QT->isReferenceType()) {
220 QT = llvm::cast<clang::ReferenceType>(QT)->getPointeeType();
223 else if (QT->isPointerType()) {
224 QT = llvm::cast<clang::PointerType>(QT)->getPointeeType();
227 else if (QT->isMemberPointerType()) {
228 QT = llvm::cast<clang::MemberPointerType>(QT)->getPointeeType();
247 else if (increment) {
270 cling::Interpreter::PushTransactionRAII RAII(
fInterp);
271 fIter = dc->decls_begin();
280 clang::Decl::Kind DK =
fIter->getKind();
285 fIter = llvm::dyn_cast<clang::DeclContext>(*fIter)->decls_begin();
289 if ((DK == clang::Decl::Field) || (DK == clang::Decl::EnumConstant) ||
290 (DK == clang::Decl::Var)) {
301 using namespace clang;
308 ASTContext&
C = D->getASTContext();
309 if (
const FieldDecl *FldD = dyn_cast<FieldDecl>(D)) {
311 clang::ASTContext &
Context = FldD->getASTContext();
312 const clang::RecordDecl *RD = FldD->getParent();
313 const clang::ASTRecordLayout &
Layout = Context.getASTRecordLayout(RD);
314 uint64_t bits = Layout.getFieldOffset(FldD->getFieldIndex());
315 int64_t offset = Context.toCharUnitsFromBits(bits).getQuantity();
316 return static_cast<long>(offset);
318 else if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
322 cling::Interpreter::PushTransactionRAII RAII(
fInterp);
324 if (VD->hasInit() && VD->checkInitIsICE()) {
327 const APValue* val = VD->evaluateValue();
328 if (VD->getType()->isIntegralType(C)) {
329 return reinterpret_cast<long>(val->getInt().getRawData());
333 switch (val->getKind()) {
335 if (val->getInt().isSigned())
342 if (&val->getFloat().getSemantics()
343 == &llvm::APFloat::IEEEsingle) {
346 }
else if (&val->getFloat().getSemantics()
347 == &llvm::APFloat::IEEEdouble) {
358 return reinterpret_cast<long>(
fInterp->getAddressOfGlobal(GlobalDecl(VD)));
365 else if (
const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D))
370 return reinterpret_cast<long>(ECD->getInitVal().getRawData());
373 return reinterpret_cast<long>(((
char*)ECD->getInitVal().getRawData())+
sizeof(
long) );
384 const clang::Decl *declaccess =
GetDecl();
385 if (declaccess->getDeclContext()->isTransparentContext()) {
386 declaccess = llvm::dyn_cast<clang::Decl>(declaccess->getDeclContext());
387 if (!declaccess) declaccess =
GetDecl();
389 switch (declaccess->getAccess()) {
390 case clang::AS_public:
393 case clang::AS_protected:
396 case clang::AS_private:
400 if (declaccess->getDeclContext()->isNamespace()) {
410 if (
const clang::VarDecl *vard = llvm::dyn_cast<clang::VarDecl>(
GetDecl())) {
411 if (vard->getStorageClass() == clang::SC_Static) {
413 }
else if (declaccess->getDeclContext()->isNamespace()) {
419 if (llvm::isa<clang::EnumConstantDecl>(
GetDecl())) {
424 const clang::ValueDecl *vd = llvm::dyn_cast<clang::ValueDecl>(
GetDecl());
425 clang::QualType qt = vd->getType();
426 if (llvm::isa<clang::TypedefType>(qt)) {
429 qt = qt.getCanonicalType();
430 if (qt.isConstQualified()) {
434 if (qt->isArrayType()) {
436 qt = llvm::cast<clang::ArrayType>(qt)->getElementType();
439 else if (qt->isReferenceType()) {
441 qt = llvm::cast<clang::ReferenceType>(qt)->getPointeeType();
444 else if (qt->isPointerType()) {
446 if (qt.isConstQualified()) {
449 qt = llvm::cast<clang::PointerType>(qt)->getPointeeType();
452 else if (qt->isMemberPointerType()) {
453 qt = llvm::cast<clang::MemberPointerType>(qt)->getPointeeType();
458 if (qt->isBuiltinType()) {
461 if (qt.isConstQualified()) {
464 const clang::TagType *
tt = qt->getAs<clang::TagType>();
466 const clang::TagDecl *td = tt->getDecl();
470 else if (td->isStruct()) {
473 else if (td->isUnion()) {
476 else if (td->isEnum()) {
492 const clang::ValueDecl *vd = llvm::dyn_cast<clang::ValueDecl>(
GetDecl());
493 clang::QualType qt = vd->getType();
504 clang::Decl::Kind dk =
GetDecl()->getKind();
505 if ((dk != clang::Decl::Field) && (dk != clang::Decl::Var) &&
506 (dk != clang::Decl::EnumConstant)) {
510 const clang::ValueDecl *vd = llvm::dyn_cast<clang::ValueDecl>(
GetDecl());
511 clang::QualType qt = vd->getType();
512 if (qt->isIncompleteType()) {
516 clang::ASTContext &context =
GetDecl()->getASTContext();
518 return static_cast<int>(context.getTypeSizeInChars(qt).getQuantity());
531 static std::string buf;
533 if (
const clang::ValueDecl *vd = llvm::dyn_cast<clang::ValueDecl>(
GetDecl())) {
534 clang::QualType vdType = vd->getType();
537 while (vdType->isArrayType()) {
538 vdType =
GetDecl()->getASTContext().getQualifiedType(vdType->getBaseElementTypeUnsafe(),vdType.getQualifiers());
561 static std::string buf;
563 if (
const clang::ValueDecl *vd = llvm::dyn_cast<clang::ValueDecl>(
GetDecl())) {
572 while (buf.length() && buf[buf.length()-1] ==
']') {
573 size_t last = buf.rfind(
'[');
574 if (last != std::string::npos) {
593 static std::string buf;
596 if (
const clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(
GetDecl())) {
597 clang::PrintingPolicy policy(
GetDecl()->getASTContext().getPrintingPolicy());
598 llvm::raw_string_ostream stream(buf);
599 nd->getNameForDiagnostic(stream, policy,
false);
616 bool titleFound=
false;
618 std::string attribute_s;
620 for (Decl::attr_iterator attrIt = decl->attr_begin();
621 attrIt!=decl->attr_end() && !titleFound ;++attrIt){
629 if (!titleFound && !
GetDecl()->isFromASTFile()) {
645 return llvm::StringRef();
647 const clang::DeclaratorDecl *FD = llvm::dyn_cast<clang::DeclaratorDecl>(
GetDecl());
649 else return llvm::StringRef();
long TypeProperty() const
const char * Name() const
RooArgList L(const RooAbsArg &v1)
union TClingDataMemberInfo::@38 fConstInitVal
Small helper to keep current directory context.
TClingDataMemberInfo(cling::Interpreter *interp)
llvm::StringRef ValidArrayIndex() const
const clang::Type * GetType() const
clang::DeclContext::decl_iterator fIter
std::vector< clang::DeclContext::decl_iterator > fIterStack
Emulation of the CINT TypeInfo class.
const char * TypeTrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
DeclId_t GetDeclId() const
int MaxIndex(int dim) const
llvm::SmallVector< clang::DeclContext *, 2 > fContexts
void CheckForIoTypeAndName() const
const clang::Decl * GetDecl() const
cling::Interpreter * fInterp
const clang::Decl * GetDecl() const
const char * TypeName() const
const clang::ValueDecl * fSingleDecl
Emulation of the CINT ClassInfo class.
TClingClassInfo * fClassInfo
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
RooCmdArg Layout(Double_t xmin, Double_t xmax=0.99, Double_t ymin=0.95)