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,
110 if (
decl &&
decl->isInvalidDecl()) {
111 Error(
"TClingClassInfo",
"Found an invalid decl for %s.",
name);
120 fIsIter(
false), fOffsetCache(0)
128 fIsIter(
false), fOffsetCache(0)
152 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
165 llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
169 if (
CRD->isAbstract()) {
172 if (
CRD->hasUserDeclaredConstructor()) {
176 !
CRD->hasUserDeclaredConstructor() &&
177 !
CRD->hasTrivialDefaultConstructor()
182 CRD->hasUserProvidedDefaultConstructor() ||
183 !
CRD->hasTrivialDefaultConstructor()
187 if (
CRD->hasUserDeclaredDestructor()) {
190 else if (!
CRD->hasTrivialDestructor()) {
193 if (
CRD->hasUserDeclaredCopyAssignment()) {
196 if (
CRD->isPolymorphic()) {
199 if (
CRD->isAggregate() ||
CRD->isPOD()) {
211 Error(
"TClingClassInfo::Delete()",
"Called while invalid!");
215 Error(
"TClingClassInfo::Delete()",
"Class is not loaded: %s",
220 cf.ExecDestructor(
this,
arena, 0,
true);
236 Error(
"DeleteArray",
"Placement delete of an array is unsupported!\n");
240 cf.ExecDestructor(
this,
arena, 1,
true);
251 cf.ExecDestructor(
this,
arena, 0,
false);
265 llvm::StringRef
tname(TT->getDecl()->getName());
275 const cling::LookupHelper &
lh =
fInterp->getLookupHelper();
278 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
279 : cling::LookupHelper::NoDiagnostics,
false);
280 if (fd)
return fd->getCanonicalDecl();
289 const cling::LookupHelper &
lh =
fInterp->getLookupHelper();
292 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
293 : cling::LookupHelper::NoDiagnostics);
294 if (
vd)
return llvm::dyn_cast<ValueDecl>(
vd->getCanonicalDecl());
312 llvm::StringRef
tname(TT->getDecl()->getName());
322 const cling::LookupHelper &
lh =
fInterp->getLookupHelper();
325 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
326 : cling::LookupHelper::NoDiagnostics,
363 llvm::StringRef
tname(TT->getDecl()->getName());
376 const cling::LookupHelper&
lh =
fInterp->getLookupHelper();
380 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
381 : cling::LookupHelper::NoDiagnostics,
385 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
386 : cling::LookupHelper::NoDiagnostics,
389 Error(
"TClingClassInfo::GetMethod",
390 "The MatchMode %d is not supported.",
mode);
408 const clang::DeclContext*
ourDC = llvm::dyn_cast<clang::DeclContext>(
GetDecl());
409 if (!fd->getDeclContext()->Equals(
ourDC)
410 && !(fd->getDeclContext()->isTransparentContext()
411 && fd->getDeclContext()->getParent()->Equals(
ourDC)))
420 llvm::dyn_cast<CXXMethodDecl>(fd)) {
432 const llvm::SmallVectorImpl<clang::QualType> &
proto,
457 llvm::StringRef
tname(TT->getDecl()->getName());
469 const cling::LookupHelper&
lh =
fInterp->getLookupHelper();
473 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
474 : cling::LookupHelper::NoDiagnostics,
478 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
479 : cling::LookupHelper::NoDiagnostics,
482 Error(
"TClingClassInfo::GetMethod",
483 "The MatchMode %d is not supported.",
mode);
495 llvm::dyn_cast<CXXMethodDecl>(fd)) {
523 llvm::StringRef
tname(TT->getDecl()->getName());
547 const cling::LookupHelper &
lh =
fInterp->getLookupHelper();
550 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
551 : cling::LookupHelper::NoDiagnostics,
561 llvm::dyn_cast<CXXMethodDecl>(fd)) {
585 unsigned num_params =
mi.GetTargetFunctionDecl()->getNumParams();
599 llvm::cast<CXXRecordDecl>(
GetDecl());
627 std::pair<ptrdiff_t, OffsetPtrFunc_t>
offsetCache = (*iter).second;
633 Error(
"TClingBaseClassInfo::Offset",
"The address of the object for virtual base offset calculation is not valid.");
652 std::vector<std::string> res;
656 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
661 clang::PrintingPolicy
policy(
fDecl->getASTContext().getPrintingPolicy());
662 for (
auto UD :
DC->using_directives()) {
666 llvm::raw_string_ostream stream(
nsName);
668 NS->getNameForDiagnostic(stream,
policy,
true);
692 return EIOCtorCategory::kAbsent;
694 auto CRD = llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
697 return EIOCtorCategory::kAbsent;
700 auto kind = CheckIOConstructor(
CRD,
"TRootIOCtor",
nullptr, *
fInterp);
701 if ((kind == EIOCtorCategory::kIORefType) || (kind == EIOCtorCategory::kIOPtrType)) {
706 kind = CheckIOConstructor(
CRD,
"__void__",
nullptr, *
fInterp);
707 if (kind == EIOCtorCategory::kIORefType) {
713 return CheckDefaultConstructor(
CRD, *
fInterp) ? EIOCtorCategory::kDefault : EIOCtorCategory::kAbsent;
720 return fInterp->getLookupHelper()
722 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
723 : cling::LookupHelper::NoDiagnostics);
733 fIter = DeclContext::decl_iterator();
737 const cling::LookupHelper&
lh =
fInterp->getLookupHelper();
739 : cling::LookupHelper::NoDiagnostics,
744 SetDecl(
lh.findScope(buf,
gDebug > 5 ? cling::LookupHelper::WithDiagnostics
745 : cling::LookupHelper::NoDiagnostics,
762 fIter = DeclContext::decl_iterator();
770 Fatal(
"TClingClassInfo::Init(tagnum)",
"Should no longer be called");
791 Error(
"TClingClassInfo::Init(const Type&)",
792 "The given type %s does not point to a Decl",
810 llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
817 llvm::dyn_cast<CXXRecordDecl>(base.
GetDecl());
834 if (
auto *
ED = llvm::dyn_cast<clang::EnumDecl>(
GetDecl()))
835 return ED->isScoped();
846 if (
auto ED = llvm::dyn_cast<EnumDecl>(
GetDecl())) {
848 auto Ty =
ED->getIntegerType().getTypePtrOrNull();
850 Ty =
Ty->getUnqualifiedDesugaredType();
851 if (
auto BTy = llvm::dyn_cast_or_null<BuiltinType>(
Ty)) {
852 switch (
BTy->getKind()) {
853 case BuiltinType::Bool:
856 case BuiltinType::Char_U:
857 case BuiltinType::UChar:
860 case BuiltinType::Char_S:
861 case BuiltinType::SChar:
864 case BuiltinType::UShort:
866 case BuiltinType::Short:
868 case BuiltinType::UInt:
870 case BuiltinType::Int:
872 case BuiltinType::ULong:
874 case BuiltinType::Long:
876 case BuiltinType::ULongLong:
878 case BuiltinType::LongLong:
906 if (!
CRD->hasDefinition()) {
911 if (
TD &&
TD->getDefinition() ==
nullptr) {
942 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
949 fIter =
DC->noload_decls_begin();
957 llvm::dyn_cast<NamedDecl>(
GetDecl())) {
960 llvm::raw_string_ostream stream(buf);
961 ND->getNameForDiagnostic(stream, Policy,
false);
963 Error(
"TClingClassInfo::InternalNext",
964 "Next called but iteration not prepared for %s!", buf.c_str());
966 Error(
"TClingClassInfo::InternalNext",
967 "Next called but iteration not prepared!");
999 fIter =
DC->noload_decls_begin();
1019 Decl::Kind
DK =
fIter->getKind();
1020 if ((
DK == Decl::Namespace) || (
DK == Decl::Enum) ||
1021 (
DK == Decl::CXXRecord) ||
1022 (
DK == Decl::ClassTemplateSpecialization)) {
1024 if (
TD && !
TD->isCompleteDefinition()) {
1028 if (
DK == Decl::Namespace) {
1030 if (!
fIter->isCanonicalDecl()) {
1036 if (
DK != Decl::Enum) {
1040 || (!
fIterAll && *
DC->noload_decls_begin())) {
1051 Warning(
"TClingClassInfo::Next()",
"Reached an invalid decl.");
1054 llvm::dyn_cast<RecordDecl>(
GetDecl())) {
1055 fType =
RD->getASTContext().getRecordType(
RD).getTypePtr();
1073 Error(
"TClingClassInfo::New()",
"Called while invalid!");
1077 Error(
"TClingClassInfo::New()",
"Class is not loaded: %s",
1089 Error(
"TClingClassInfo::New()",
"This is a namespace!: %s",
1103 void* obj =
nullptr;
1105 obj =
cf.ExecDefaultConstructor(
this, kind,
type_name,
1108 Error(
"TClingClassInfo::New()",
"Call of default constructor "
1109 "failed to return an object for class: %s",
1122 Error(
"TClingClassInfo::New(n)",
"Called while invalid!");
1126 Error(
"TClingClassInfo::New(n)",
"Class is not loaded: %s",
1139 Error(
"TClingClassInfo::New(n)",
"This is a namespace!: %s",
1153 void* obj =
nullptr;
1155 obj =
cf.ExecDefaultConstructor(
this, kind,
type_name,
1156 nullptr, (
unsigned long)
n);
1158 Error(
"TClingClassInfo::New(n)",
"Call of default constructor "
1159 "failed to return an array of class: %s",
1173 Error(
"TClingClassInfo::New(n, arena)",
"Called while invalid!");
1177 Error(
"TClingClassInfo::New(n, arena)",
"Class is not loaded: %s",
1190 Error(
"TClingClassInfo::New(n, arena)",
"This is a namespace!: %s",
1204 void* obj =
nullptr;
1207 obj =
cf.ExecDefaultConstructor(
this, kind,
type_name,
1208 arena, (
unsigned long)
n);
1218 Error(
"TClingClassInfo::New(arena)",
"Called while invalid!");
1222 Error(
"TClingClassInfo::New(arena)",
"Class is not loaded: %s",
1235 Error(
"TClingClassInfo::New(arena)",
"This is a namespace!: %s",
1249 void* obj =
nullptr;
1252 obj =
cf.ExecDefaultConstructor(
this, kind,
type_name,
1269 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
1271 const clang::DeclContext *
ctxt =
GetDecl()->getDeclContext();
1272 clang::NamespaceDecl *
std_ns =
fInterp->getSema().getStdNamespace();
1273 while (
ctxt && !
ctxt->isTranslationUnit()) {
1281 if ((
DK == Decl::Namespace) || (
DK == Decl::TranslationUnit)) {
1296 llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
1300 if (
CRD->isClass()) {
1302 }
else if (
CRD->isStruct()) {
1304 }
else if (
CRD->isUnion()) {
1307 if (
CRD->hasDefinition() &&
CRD->isAbstract()) {
1341 if (
DK == Decl::Namespace) {
1345 else if (
DK == Decl::Enum) {
1354 if (!
RD->getDefinition()) {
1359 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
1361 int64_t
size = Layout.getSize().getQuantity();
1385 if (
DK == Decl::Namespace) {
1387 }
else if (
DK == Decl::Enum) {
1394 if (!
RD->getDefinition()) {
1399 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
1401 auto align = Layout.getAlignment().getQuantity();
1437 llvm::dyn_cast<NamedDecl>(
GetDecl())) {
1440 llvm::raw_string_ostream stream(output);
1441 ND->getNameForDiagnostic(stream, Policy,
true);
1462 std::string
attr = A->getAnnotation().str();
1479 llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
1480 if (
CRD && !
CRD->isFromASTFile()) {
1499 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.
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)