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,
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();
238 assert(!
fSingleDecl &&
"This is not an iterator!");
247 else if (increment) {
270 cling::Interpreter::PushTransactionRAII RAII(
fInterp);
271 fIter = dc->decls_begin();
280 clang::Decl::Kind DK =
fIter->getKind();
281 if (DK == clang::Decl::Enum) {
285 cling::Interpreter::PushTransactionRAII RAII(
fInterp);
286 fIter = llvm::dyn_cast<clang::DeclContext>(*fIter)->decls_begin();
290 if ((DK == clang::Decl::Field) || (DK == clang::Decl::EnumConstant) ||
291 (DK == clang::Decl::Var)) {
302 using namespace clang;
309 ASTContext&
C = D->getASTContext();
310 if (
const FieldDecl *FldD = dyn_cast<FieldDecl>(D)) {
312 const clang::RecordDecl *RD = FldD->getParent();
313 const clang::ASTRecordLayout &
Layout = C.getASTRecordLayout(RD);
314 uint64_t bits = Layout.getFieldOffset(FldD->getFieldIndex());
315 int64_t offset = C.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 (
long addr = reinterpret_cast<long>(
fInterp->getAddressOfGlobal(GlobalDecl(VD))))
326 auto evalStmt = VD->ensureEvaluatedStmt();
327 if (evalStmt && evalStmt->Value) {
328 if (
const APValue* val = VD->evaluateValue()) {
329 if (VD->getType()->isIntegralType(C)) {
330 return reinterpret_cast<long>(val->getInt().getRawData());
334 switch (val->getKind()) {
336 if (val->getInt().isSigned())
343 if (&val->getFloat().getSemantics()
344 == &llvm::APFloat::IEEEsingle) {
347 }
else if (&val->getFloat().getSemantics()
348 == &llvm::APFloat::IEEEdouble) {
366 else if (
const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D))
371 return reinterpret_cast<long>(ECD->getInitVal().getRawData());
374 return reinterpret_cast<long>(((
char*)ECD->getInitVal().getRawData())+
sizeof(
long) );
385 const clang::Decl *declaccess =
GetDecl();
386 if (declaccess->getDeclContext()->isTransparentContext()) {
387 declaccess = llvm::dyn_cast<clang::Decl>(declaccess->getDeclContext());
388 if (!declaccess) declaccess =
GetDecl();
390 switch (declaccess->getAccess()) {
391 case clang::AS_public:
394 case clang::AS_protected:
397 case clang::AS_private:
401 if (declaccess->getDeclContext()->isNamespace()) {
411 if (
const clang::VarDecl *vard = llvm::dyn_cast<clang::VarDecl>(
GetDecl())) {
412 if (vard->getStorageClass() == clang::SC_Static) {
414 }
else if (declaccess->getDeclContext()->isNamespace()) {
420 if (llvm::isa<clang::EnumConstantDecl>(
GetDecl())) {
425 const clang::ValueDecl *vd = llvm::dyn_cast<clang::ValueDecl>(
GetDecl());
426 clang::QualType qt = vd->getType();
427 if (llvm::isa<clang::TypedefType>(qt)) {
430 qt = qt.getCanonicalType();
431 if (qt.isConstQualified()) {
435 if (qt->isArrayType()) {
437 qt = llvm::cast<clang::ArrayType>(qt)->getElementType();
440 else if (qt->isReferenceType()) {
442 qt = llvm::cast<clang::ReferenceType>(qt)->getPointeeType();
445 else if (qt->isPointerType()) {
447 if (qt.isConstQualified()) {
450 qt = llvm::cast<clang::PointerType>(qt)->getPointeeType();
453 else if (qt->isMemberPointerType()) {
454 qt = llvm::cast<clang::MemberPointerType>(qt)->getPointeeType();
459 if (qt->isBuiltinType()) {
462 if (qt.isConstQualified()) {
465 const clang::TagType *
tt = qt->getAs<clang::TagType>();
467 const clang::TagDecl *td = tt->getDecl();
471 else if (td->isStruct()) {
474 else if (td->isUnion()) {
477 else if (td->isEnum()) {
493 const clang::ValueDecl *vd = llvm::dyn_cast<clang::ValueDecl>(
GetDecl());
494 clang::QualType qt = vd->getType();
505 clang::Decl::Kind dk =
GetDecl()->getKind();
506 if ((dk != clang::Decl::Field) && (dk != clang::Decl::Var) &&
507 (dk != clang::Decl::EnumConstant)) {
511 const clang::ValueDecl *vd = llvm::dyn_cast<clang::ValueDecl>(
GetDecl());
512 clang::QualType qt = vd->getType();
513 if (qt->isIncompleteType()) {
517 clang::ASTContext &context =
GetDecl()->getASTContext();
519 return static_cast<int>(context.getTypeSizeInChars(qt).getQuantity());
532 static std::string buf;
534 if (
const clang::ValueDecl *vd = llvm::dyn_cast<clang::ValueDecl>(
GetDecl())) {
535 clang::QualType vdType = vd->getType();
538 while (vdType->isArrayType()) {
539 vdType =
GetDecl()->getASTContext().getQualifiedType(vdType->getBaseElementTypeUnsafe(),vdType.getQualifiers());
562 static std::string buf;
564 if (
const clang::ValueDecl *vd = llvm::dyn_cast<clang::ValueDecl>(
GetDecl())) {
573 while (buf.length() && buf[buf.length()-1] ==
']') {
574 size_t last = buf.rfind(
'[');
575 if (last != std::string::npos) {
594 static std::string buf;
597 if (
const clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(
GetDecl())) {
598 clang::PrintingPolicy policy(
GetDecl()->getASTContext().getPrintingPolicy());
599 llvm::raw_string_ostream stream(buf);
600 nd->getNameForDiagnostic(stream, policy,
false);
617 bool titleFound=
false;
619 std::string attribute_s;
621 for (Decl::attr_iterator attrIt = decl->attr_begin();
622 attrIt!=decl->attr_end() && !titleFound ;++attrIt){
630 if (!titleFound && !
GetDecl()->isFromASTFile()) {
646 return llvm::StringRef();
648 const clang::DeclaratorDecl *FD = llvm::dyn_cast<clang::DeclaratorDecl>(
GetDecl());
650 else return llvm::StringRef();
RooArgList L(const RooAbsArg &v1)
const clang::Decl * GetDecl() const
const char * TypeName() const
llvm::StringRef ValidArrayIndex() const
TClingDataMemberInfo(cling::Interpreter *interp)
clang::DeclContext::decl_iterator fIter
const char * TypeTrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
int MaxIndex(int dim) const
std::vector< clang::DeclContext::decl_iterator > fIterStack
Emulation of the CINT TypeInfo class.
union TClingDataMemberInfo::@42 fConstInitVal
llvm::SmallVector< clang::DeclContext *, 2 > fContexts
cling::Interpreter * fInterp
const clang::ValueDecl * fSingleDecl
Emulation of the CINT ClassInfo class.
TClingClassInfo * fClassInfo
const clang::Decl * GetDecl() const
RooCmdArg Layout(Double_t xmin, Double_t xmax=0.99, Double_t ymin=0.95)
void CheckForIoTypeAndName() const
const char * Name() const
const clang::Type * GetType() const
DeclId_t GetDeclId() const
long TypeProperty() const