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"
65 llvm::raw_string_ostream stream(buf);
66 ND->getNameForDiagnostic(stream, Policy,
true);
73 fIsIter(
true), fOffsetCache(0)
76 interp->getCI()->getASTContext().getTranslationUnitDecl();
85 const cling::LookupHelper&
lh =
fInterp->getLookupHelper();
86 const Type *
type =
nullptr;
88 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
89 : cling::LookupHelper::NoDiagnostics,
95 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
96 : cling::LookupHelper::NoDiagnostics,
108 if (
decl &&
decl->isInvalidDecl()) {
109 Error(
"TClingClassInfo",
"Found an invalid decl for %s.",
name);
118 fIsIter(
false), fOffsetCache(0)
126 fIsIter(
false), fOffsetCache(0)
150 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
163 llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
167 if (
CRD->isAbstract()) {
170 if (
CRD->hasUserDeclaredConstructor()) {
174 !
CRD->hasUserDeclaredConstructor() &&
175 !
CRD->hasTrivialDefaultConstructor()
180 CRD->hasUserProvidedDefaultConstructor() ||
181 !
CRD->hasTrivialDefaultConstructor()
185 if (
CRD->hasUserDeclaredDestructor()) {
188 else if (!
CRD->hasTrivialDestructor()) {
191 if (
CRD->hasUserDeclaredCopyAssignment()) {
194 if (
CRD->isPolymorphic()) {
197 if (
CRD->isAggregate() ||
CRD->isPOD()) {
209 Error(
"TClingClassInfo::Delete()",
"Called while invalid!");
213 Error(
"TClingClassInfo::Delete()",
"Class is not loaded: %s",
218 cf.ExecDestructor(
this,
arena, 0,
true);
234 Error(
"DeleteArray",
"Placement delete of an array is unsupported!\n");
238 cf.ExecDestructor(
this,
arena, 1,
true);
249 cf.ExecDestructor(
this,
arena, 0,
false);
263 llvm::StringRef
tname(TT->getDecl()->getName());
273 const cling::LookupHelper &
lh =
fInterp->getLookupHelper();
276 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
277 : cling::LookupHelper::NoDiagnostics,
false);
278 if (fd)
return fd->getCanonicalDecl();
287 const cling::LookupHelper &
lh =
fInterp->getLookupHelper();
290 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
291 : cling::LookupHelper::NoDiagnostics);
292 if (
vd)
return llvm::dyn_cast<ValueDecl>(
vd->getCanonicalDecl());
310 llvm::StringRef
tname(TT->getDecl()->getName());
320 const cling::LookupHelper &
lh =
fInterp->getLookupHelper();
323 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
324 : cling::LookupHelper::NoDiagnostics,
361 llvm::StringRef
tname(TT->getDecl()->getName());
374 const cling::LookupHelper&
lh =
fInterp->getLookupHelper();
378 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
379 : cling::LookupHelper::NoDiagnostics,
383 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
384 : cling::LookupHelper::NoDiagnostics,
387 Error(
"TClingClassInfo::GetMethod",
388 "The MatchMode %d is not supported.",
mode);
406 const clang::DeclContext*
ourDC = llvm::dyn_cast<clang::DeclContext>(
GetDecl());
407 if (!fd->getDeclContext()->Equals(
ourDC)
408 && !(fd->getDeclContext()->isTransparentContext()
409 && fd->getDeclContext()->getParent()->Equals(
ourDC)))
418 llvm::dyn_cast<CXXMethodDecl>(fd)) {
430 const llvm::SmallVectorImpl<clang::QualType> &
proto,
455 llvm::StringRef
tname(TT->getDecl()->getName());
467 const cling::LookupHelper&
lh =
fInterp->getLookupHelper();
471 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
472 : cling::LookupHelper::NoDiagnostics,
476 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
477 : cling::LookupHelper::NoDiagnostics,
480 Error(
"TClingClassInfo::GetMethod",
481 "The MatchMode %d is not supported.",
mode);
493 llvm::dyn_cast<CXXMethodDecl>(fd)) {
521 llvm::StringRef
tname(TT->getDecl()->getName());
545 const cling::LookupHelper &
lh =
fInterp->getLookupHelper();
548 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
549 : cling::LookupHelper::NoDiagnostics,
559 llvm::dyn_cast<CXXMethodDecl>(fd)) {
583 unsigned num_params =
mi.GetTargetFunctionDecl()->getNumParams();
597 llvm::cast<CXXRecordDecl>(
GetDecl());
625 std::pair<ptrdiff_t, OffsetPtrFunc_t>
offsetCache = (*iter).second;
631 Error(
"TClingBaseClassInfo::Offset",
"The address of the object for virtual base offset calculation is not valid.");
650 std::vector<std::string> res;
654 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
659 clang::PrintingPolicy
policy(
fDecl->getASTContext().getPrintingPolicy());
660 for (
auto UD :
DC->using_directives()) {
664 llvm::raw_string_ostream stream(
nsName);
666 NS->getNameForDiagnostic(stream,
policy,
true);
690 return EIOCtorCategory::kAbsent;
692 auto CRD = llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
695 return EIOCtorCategory::kAbsent;
698 auto kind = CheckIOConstructor(
CRD,
"TRootIOCtor",
nullptr, *
fInterp);
699 if ((kind == EIOCtorCategory::kIORefType) || (kind == EIOCtorCategory::kIOPtrType)) {
704 kind = CheckIOConstructor(
CRD,
"__void__",
nullptr, *
fInterp);
705 if (kind == EIOCtorCategory::kIORefType) {
711 return CheckDefaultConstructor(
CRD, *
fInterp) ? EIOCtorCategory::kDefault : EIOCtorCategory::kAbsent;
718 return fInterp->getLookupHelper()
720 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
721 : cling::LookupHelper::NoDiagnostics);
731 fIter = DeclContext::decl_iterator();
735 const cling::LookupHelper&
lh =
fInterp->getLookupHelper();
737 : cling::LookupHelper::NoDiagnostics,
742 SetDecl(
lh.findScope(buf,
gDebug > 5 ? cling::LookupHelper::WithDiagnostics
743 : cling::LookupHelper::NoDiagnostics,
760 fIter = DeclContext::decl_iterator();
768 Fatal(
"TClingClassInfo::Init(tagnum)",
"Should no longer be called");
789 Error(
"TClingClassInfo::Init(const Type&)",
790 "The given type %s does not point to a Decl",
808 llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
815 llvm::dyn_cast<CXXRecordDecl>(base.
GetDecl());
832 if (
auto *
ED = llvm::dyn_cast<clang::EnumDecl>(
GetDecl()))
833 return ED->isScoped();
844 if (
auto ED = llvm::dyn_cast<EnumDecl>(
GetDecl())) {
846 auto Ty =
ED->getIntegerType().getTypePtrOrNull();
848 Ty =
Ty->getUnqualifiedDesugaredType();
849 if (
auto BTy = llvm::dyn_cast_or_null<BuiltinType>(
Ty)) {
850 switch (
BTy->getKind()) {
851 case BuiltinType::Bool:
854 case BuiltinType::Char_U:
855 case BuiltinType::UChar:
858 case BuiltinType::Char_S:
859 case BuiltinType::SChar:
862 case BuiltinType::UShort:
864 case BuiltinType::Short:
866 case BuiltinType::UInt:
868 case BuiltinType::Int:
870 case BuiltinType::ULong:
872 case BuiltinType::Long:
874 case BuiltinType::ULongLong:
876 case BuiltinType::LongLong:
904 if (!
CRD->hasDefinition()) {
909 if (
TD &&
TD->getDefinition() ==
nullptr) {
940 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
947 fIter =
DC->noload_decls_begin();
955 llvm::dyn_cast<NamedDecl>(
GetDecl())) {
958 llvm::raw_string_ostream stream(buf);
959 ND->getNameForDiagnostic(stream, Policy,
false);
961 Error(
"TClingClassInfo::InternalNext",
962 "Next called but iteration not prepared for %s!", buf.c_str());
964 Error(
"TClingClassInfo::InternalNext",
965 "Next called but iteration not prepared!");
997 fIter =
DC->noload_decls_begin();
1017 Decl::Kind
DK =
fIter->getKind();
1018 if ((
DK == Decl::Namespace) || (
DK == Decl::Enum) ||
1019 (
DK == Decl::CXXRecord) ||
1020 (
DK == Decl::ClassTemplateSpecialization)) {
1022 if (
TD && !
TD->isCompleteDefinition()) {
1026 if (
DK == Decl::Namespace) {
1028 if (!
fIter->isCanonicalDecl()) {
1034 if (
DK != Decl::Enum) {
1038 || (!
fIterAll && *
DC->noload_decls_begin())) {
1049 Warning(
"TClingClassInfo::Next()",
"Reached an invalid decl.");
1052 llvm::dyn_cast<RecordDecl>(
GetDecl())) {
1053 fType =
RD->getASTContext().getRecordType(
RD).getTypePtr();
1071 Error(
"TClingClassInfo::New()",
"Called while invalid!");
1075 Error(
"TClingClassInfo::New()",
"Class is not loaded: %s",
1087 Error(
"TClingClassInfo::New()",
"This is a namespace!: %s",
1101 void* obj =
nullptr;
1103 obj =
cf.ExecDefaultConstructor(
this, kind,
type_name,
1106 Error(
"TClingClassInfo::New()",
"Call of default constructor "
1107 "failed to return an object for class: %s",
1120 Error(
"TClingClassInfo::New(n)",
"Called while invalid!");
1124 Error(
"TClingClassInfo::New(n)",
"Class is not loaded: %s",
1137 Error(
"TClingClassInfo::New(n)",
"This is a namespace!: %s",
1151 void* obj =
nullptr;
1153 obj =
cf.ExecDefaultConstructor(
this, kind,
type_name,
1154 nullptr, (
unsigned long)
n);
1156 Error(
"TClingClassInfo::New(n)",
"Call of default constructor "
1157 "failed to return an array of class: %s",
1171 Error(
"TClingClassInfo::New(n, arena)",
"Called while invalid!");
1175 Error(
"TClingClassInfo::New(n, arena)",
"Class is not loaded: %s",
1188 Error(
"TClingClassInfo::New(n, arena)",
"This is a namespace!: %s",
1202 void* obj =
nullptr;
1205 obj =
cf.ExecDefaultConstructor(
this, kind,
type_name,
1206 arena, (
unsigned long)
n);
1216 Error(
"TClingClassInfo::New(arena)",
"Called while invalid!");
1220 Error(
"TClingClassInfo::New(arena)",
"Class is not loaded: %s",
1233 Error(
"TClingClassInfo::New(arena)",
"This is a namespace!: %s",
1247 void* obj =
nullptr;
1250 obj =
cf.ExecDefaultConstructor(
this, kind,
type_name,
1267 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
1269 const clang::DeclContext *
ctxt =
GetDecl()->getDeclContext();
1270 clang::NamespaceDecl *
std_ns =
fInterp->getSema().getStdNamespace();
1271 while (
ctxt && !
ctxt->isTranslationUnit()) {
1279 if ((
DK == Decl::Namespace) || (
DK == Decl::TranslationUnit)) {
1294 llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
1298 if (
CRD->isClass()) {
1300 }
else if (
CRD->isStruct()) {
1302 }
else if (
CRD->isUnion()) {
1305 if (
CRD->hasDefinition() &&
CRD->isAbstract()) {
1333 if (
DK == Decl::Namespace) {
1337 else if (
DK == Decl::Enum) {
1346 if (!
RD->getDefinition()) {
1351 cling::Interpreter::PushTransactionRAII
RAII(
fInterp);
1353 int64_t
size = Layout.getSize().getQuantity();
1389 llvm::dyn_cast<NamedDecl>(
GetDecl())) {
1392 llvm::raw_string_ostream stream(
output);
1393 ND->getNameForDiagnostic(stream, Policy,
true);
1414 std::string
attr = A->getAnnotation().str();
1431 llvm::dyn_cast<CXXRecordDecl>(
GetDecl());
1432 if (
CRD && !
CRD->isFromASTFile()) {
1451 buf =
ND->getNameAsString();
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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
#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
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
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.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
R__EXTERN TVirtualRWMutex * gCoreMutex
std::string InsertStd(const char *tname)