34#include "cling/Interpreter/Interpreter.h"
35#include "cling/Interpreter/LookupHelper.h"
36#include "cling/Utils/AST.h"
38#include "clang/AST/ASTContext.h"
39#include "clang/AST/Decl.h"
40#include "clang/AST/DeclCXX.h"
41#include "clang/AST/DeclTemplate.h"
42#include "clang/AST/GlobalDecl.h"
43#include "clang/AST/PrettyPrinter.h"
44#include "clang/AST/RecordLayout.h"
45#include "clang/AST/Type.h"
46#include "clang/Basic/Specifiers.h"
47#include "clang/Frontend/CompilerInstance.h"
48#include "clang/Sema/Sema.h"
50#include "llvm/ExecutionEngine/GenericValue.h"
51#include "llvm/Support/Casting.h"
52#include "llvm/Support/raw_ostream.h"
67 llvm::raw_string_ostream stream(
buf);
68 ND->getNameForDiagnostic(stream, Policy,
true);
75 fIsIter(
true), fOffsetCache(0)
78 interp->getCI()->getASTContext().getTranslationUnitDecl();
87 const cling::LookupHelper&
lh =
fInterp->getLookupHelper();
88 const Type *
type =
nullptr;
90 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
91 : cling::LookupHelper::NoDiagnostics,
97 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
98 : cling::LookupHelper::NoDiagnostics,
103 if (
const auto *
TD =
type->getAsTagDecl()) {
109 if (
decl &&
decl->isInvalidDecl()) {
110 Error(
"TClingClassInfo",
"Found an invalid decl for %s.",
name);
119 fIsIter(
false), fOffsetCache(0)
158 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
171 llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
175 if (
CRD->isAbstract()) {
178 if (
CRD->hasUserDeclaredConstructor()) {
182 !
CRD->hasUserDeclaredConstructor() &&
183 !
CRD->hasTrivialDefaultConstructor()
188 CRD->hasUserProvidedDefaultConstructor() ||
189 !
CRD->hasTrivialDefaultConstructor()
193 if (
CRD->hasUserDeclaredDestructor()) {
196 else if (!
CRD->hasTrivialDestructor()) {
199 if (
CRD->hasUserDeclaredCopyAssignment()) {
202 if (
CRD->isPolymorphic()) {
205 if (
CRD->isAggregate() ||
CRD->isPOD()) {
209 if (
CRD->hasDefinition() &&
fInterp->getSema().IsCXXTriviallyRelocatableType(*
CRD)) {
224 Error(
"TClingClassInfo::Delete()",
"Called while invalid!");
228 Error(
"TClingClassInfo::Delete()",
"Class is not loaded: %s",
233 cf.ExecDestructor(
this,
arena, 0,
true);
249 Error(
"DeleteArray",
"Placement delete of an array is unsupported!\n");
253 cf.ExecDestructor(
this,
arena, 1,
true);
264 cf.ExecDestructor(
this,
arena, 0,
false);
278 llvm::StringRef
tname(TT->getDecl()->getName());
288 const cling::LookupHelper &
lh =
fInterp->getLookupHelper();
291 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
292 : cling::LookupHelper::NoDiagnostics,
false);
293 if (fd)
return fd->getCanonicalDecl();
302 const cling::LookupHelper &
lh =
fInterp->getLookupHelper();
305 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
306 : cling::LookupHelper::NoDiagnostics);
307 if (
vd)
return llvm::dyn_cast<ValueDecl>(
vd->getCanonicalDecl());
325 llvm::StringRef
tname(TT->getDecl()->getName());
335 const cling::LookupHelper &
lh =
fInterp->getLookupHelper();
338 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
339 : cling::LookupHelper::NoDiagnostics,
376 llvm::StringRef
tname(TT->getDecl()->getName());
389 const cling::LookupHelper&
lh =
fInterp->getLookupHelper();
393 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
394 : cling::LookupHelper::NoDiagnostics,
398 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
399 : cling::LookupHelper::NoDiagnostics,
402 Error(
"TClingClassInfo::GetMethod",
403 "The MatchMode %d is not supported.",
mode);
421 const clang::DeclContext*
ourDC = llvm::dyn_cast<clang::DeclContext>(
GetDecl());
422 if (!fd->getDeclContext()->Equals(
ourDC)
423 && !(fd->getDeclContext()->isTransparentContext()
424 && fd->getDeclContext()->getParent()->Equals(
ourDC)))
433 llvm::dyn_cast<CXXMethodDecl>(fd)) {
445 const llvm::SmallVectorImpl<clang::QualType> &
proto,
470 llvm::StringRef
tname(TT->getDecl()->getName());
482 const cling::LookupHelper&
lh =
fInterp->getLookupHelper();
486 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
487 : cling::LookupHelper::NoDiagnostics,
491 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
492 : cling::LookupHelper::NoDiagnostics,
495 Error(
"TClingClassInfo::GetMethod",
496 "The MatchMode %d is not supported.",
mode);
508 llvm::dyn_cast<CXXMethodDecl>(fd)) {
536 llvm::StringRef
tname(TT->getDecl()->getName());
560 const cling::LookupHelper &
lh =
fInterp->getLookupHelper();
563 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
564 : cling::LookupHelper::NoDiagnostics,
574 llvm::dyn_cast<CXXMethodDecl>(fd)) {
598 unsigned num_params =
mi.GetTargetFunctionDecl()->getNumParams();
612 llvm::cast<CXXRecordDecl>(
GetDecl());
640 std::pair<ptrdiff_t, OffsetPtrFunc_t>
offsetCache = (*iter).second;
646 Error(
"TClingBaseClassInfo::Offset",
"The address of the object for virtual base offset calculation is not valid.");
665 std::vector<std::string> res;
669 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
674 clang::PrintingPolicy
policy(
fDecl->getASTContext().getPrintingPolicy());
675 for (
auto UD :
DC->using_directives()) {
679 llvm::raw_string_ostream stream(
nsName);
681 NS->getNameForDiagnostic(stream,
policy,
true);
705 return EIOCtorCategory::kAbsent;
707 auto CRD = llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
710 return EIOCtorCategory::kAbsent;
713 auto kind = CheckIOConstructor(
CRD,
"TRootIOCtor",
nullptr, *
fInterp);
714 if ((
kind == EIOCtorCategory::kIORefType) || (
kind == EIOCtorCategory::kIOPtrType)) {
720 if (
kind == EIOCtorCategory::kIORefType) {
726 return CheckDefaultConstructor(
CRD, *
fInterp) ? EIOCtorCategory::kDefault : EIOCtorCategory::kAbsent;
733 return fInterp->getLookupHelper()
735 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
736 : cling::LookupHelper::NoDiagnostics);
746 fIter = DeclContext::decl_iterator();
750 const cling::LookupHelper&
lh =
fInterp->getLookupHelper();
752 : cling::LookupHelper::NoDiagnostics,
758 : cling::LookupHelper::NoDiagnostics,
763 if (
const auto *
TD =
fType->getAsTagDecl()) {
774 fIter = DeclContext::decl_iterator();
782 Fatal(
"TClingClassInfo::Init(tagnum)",
"Should no longer be called");
792 if (
const auto *
TD =
fType->getAsTagDecl()) {
801 Error(
"TClingClassInfo::Init(const Type&)",
802 "The given type %s does not point to a Decl",
820 llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
827 llvm::dyn_cast<CXXRecordDecl>(base.
GetDecl());
844 if (
auto *
ED = llvm::dyn_cast<clang::EnumDecl>(
GetDecl()))
845 return ED->isScoped();
856 if (
auto ED = llvm::dyn_cast<EnumDecl>(
GetDecl())) {
858 auto Ty =
ED->getIntegerType().getTypePtrOrNull();
860 Ty =
Ty->getUnqualifiedDesugaredType();
861 if (
auto BTy = llvm::dyn_cast_or_null<BuiltinType>(
Ty)) {
862 switch (
BTy->getKind()) {
863 case BuiltinType::Bool:
866 case BuiltinType::Char_U:
867 case BuiltinType::UChar:
870 case BuiltinType::Char_S:
871 case BuiltinType::SChar:
874 case BuiltinType::UShort:
876 case BuiltinType::Short:
878 case BuiltinType::UInt:
880 case BuiltinType::Int:
882 case BuiltinType::ULong:
884 case BuiltinType::Long:
886 case BuiltinType::ULongLong:
888 case BuiltinType::LongLong:
916 if (!
CRD->hasDefinition()) {
921 if (
TD &&
TD->getDefinition() ==
nullptr) {
952 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
959 fIter =
DC->noload_decls_begin();
967 llvm::dyn_cast<NamedDecl>(
GetDecl())) {
970 llvm::raw_string_ostream stream(
buf);
971 ND->getNameForDiagnostic(stream, Policy,
false);
973 Error(
"TClingClassInfo::InternalNext",
974 "Next called but iteration not prepared for %s!",
buf.c_str());
976 Error(
"TClingClassInfo::InternalNext",
977 "Next called but iteration not prepared!");
1009 fIter =
DC->noload_decls_begin();
1029 Decl::Kind
DK =
fIter->getKind();
1030 if ((
DK == Decl::Namespace) || (
DK == Decl::Enum) ||
1031 (
DK == Decl::CXXRecord) ||
1032 (
DK == Decl::ClassTemplateSpecialization)) {
1034 if (
TD && !
TD->isCompleteDefinition()) {
1038 if (
DK == Decl::Namespace) {
1040 if (!
fIter->isCanonicalDecl()) {
1046 if (
DK != Decl::Enum) {
1050 || (!
fIterAll && *
DC->noload_decls_begin())) {
1061 Warning(
"TClingClassInfo::Next()",
"Reached an invalid decl.");
1064 llvm::dyn_cast<RecordDecl>(
GetDecl())) {
1065 fType =
RD->getASTContext().getCanonicalTagType(
RD).getTypePtr();
1083 Error(
"TClingClassInfo::New()",
"Called while invalid!");
1087 Error(
"TClingClassInfo::New()",
"Class is not loaded: %s",
1099 Error(
"TClingClassInfo::New()",
"This is a namespace!: %s",
1113 void* obj =
nullptr;
1118 Error(
"TClingClassInfo::New()",
"Call of default constructor "
1119 "failed to return an object for class: %s",
1132 Error(
"TClingClassInfo::New(n)",
"Called while invalid!");
1136 Error(
"TClingClassInfo::New(n)",
"Class is not loaded: %s",
1149 Error(
"TClingClassInfo::New(n)",
"This is a namespace!: %s",
1163 void* obj =
nullptr;
1166 nullptr, (
unsigned long)
n);
1168 Error(
"TClingClassInfo::New(n)",
"Call of default constructor "
1169 "failed to return an array of class: %s",
1183 Error(
"TClingClassInfo::New(n, arena)",
"Called while invalid!");
1187 Error(
"TClingClassInfo::New(n, arena)",
"Class is not loaded: %s",
1200 Error(
"TClingClassInfo::New(n, arena)",
"This is a namespace!: %s",
1214 void* obj =
nullptr;
1218 arena, (
unsigned long)
n);
1228 Error(
"TClingClassInfo::New(arena)",
"Called while invalid!");
1232 Error(
"TClingClassInfo::New(arena)",
"Class is not loaded: %s",
1245 Error(
"TClingClassInfo::New(arena)",
"This is a namespace!: %s",
1259 void* obj =
nullptr;
1279 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
1281 const clang::DeclContext *
ctxt =
GetDecl()->getDeclContext();
1282 clang::NamespaceDecl *
std_ns =
fInterp->getSema().getStdNamespace();
1283 while (
ctxt && !
ctxt->isTranslationUnit()) {
1291 if ((
DK == Decl::Namespace) || (
DK == Decl::TranslationUnit)) {
1306 llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
1310 if (
CRD->isClass()) {
1312 }
else if (
CRD->isStruct()) {
1314 }
else if (
CRD->isUnion()) {
1317 if (
CRD->hasDefinition() &&
CRD->isAbstract()) {
1351 if (
DK == Decl::Namespace) {
1355 else if (
DK == Decl::Enum) {
1364 if (!
RD->getDefinition()) {
1369 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
1371 int64_t
size = Layout.getSize().getQuantity();
1395 if (
DK == Decl::Namespace) {
1397 }
else if (
DK == Decl::Enum) {
1404 if (!
RD->getDefinition()) {
1409 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
1411 auto align = Layout.getAlignment().getQuantity();
1447 llvm::dyn_cast<NamedDecl>(
GetDecl())) {
1450 llvm::raw_string_ostream stream(output);
1451 ND->getNameForDiagnostic(stream, Policy,
true);
1472 std::string
attr = A->getAnnotation().str();
1489 llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
1490 if (
CRD && !
CRD->isFromASTFile()) {
1509 buf =
ND->getNameAsString();
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
static std::string FullyQualifiedName(const Decl *decl)
ptrdiff_t(* OffsetPtrFunc_t)(void *, bool)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ kClassIsTriviallyRelocatable
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t property
R__EXTERN TVirtualMutex * gInterpreterMutex
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
#define R__LOCKGUARD(mutex)
#define R__WRITE_LOCKGUARD(mutex)
Emulation of the CINT BaseClassInfo class.
Emulation of the CINT CallFunc class.
Emulation of the CINT ClassInfo class.
clang::DeclContext::decl_iterator fIter
static bool IsEnum(cling::Interpreter *interp, const char *name)
long ClassProperty() const
void Init(const char *name)
void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
llvm::DenseMap< const clang::Decl *, std::pair< ptrdiff_t, OffsetPtrFunc_t > > fOffsetCache
EDataType GetUnderlyingType() const
size_t GetAlignOf() const
Return the alignment of the class in bytes as reported by clang.
std::mutex fOffsetCacheMutex
const char * TmpltName() const
void AddBaseOffsetValue(const clang::Decl *decl, ptrdiff_t offset)
Longptr_t GetOffset(const clang::CXXMethodDecl *md) const
ptrdiff_t GetBaseOffset(TClingClassInfo *toBase, void *address, bool isDerivedObject)
void SetDecl(const clang::Decl *D)
bool IsScopedEnum() const
ROOT::TMetaUtils::EIOCtorCategory HasDefaultConstructor(bool checkio=false, std::string *type_name=nullptr) const
TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, Longptr_t *poffset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch, EInheritanceMode imode=kWithInheritance) const
const clang::FunctionTemplateDecl * GetFunctionTemplate(const char *fname) const
int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, Longptr_t *offset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
bool HasMethod(const char *name) const
std::string fDeclFileName
void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
void * New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
TClingMethodInfo GetMethod(const char *fname) const
const clang::ValueDecl * GetDataMember(const char *name) const
int Size() const
Return the size of the class in bytes as reported by clang.
void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
std::vector< std::string > GetUsingNamespaces()
cling::Interpreter * fInterp
std::vector< clang::DeclContext::decl_iterator > fIterStack
bool IsBase(const char *name) const
const clang::Type * fType
void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
const clang::Decl * fDecl
virtual bool IsValid() const
virtual const clang::Decl * GetDecl() const
Emulation of the CINT MethodInfo class.
constexpr bool IsValidAlignment(std::size_t align) noexcept
Return true if align is a valid C++ alignment value: strictly positive and a power of two.
R__EXTERN TVirtualRWMutex * gCoreMutex
std::string InsertStd(const char *tname)