Skip to content
Snippets Groups Projects
Commit 8452c6a6 authored by Sergey Linev's avatar Sergey Linev
Browse files

[metacling] provide method to check default constructor

parent 5ae3632b
No related branches found
No related tags found
No related merge requests found
...@@ -354,6 +354,10 @@ enum class EIOCtorCategory : short {kAbsent, kDefault, kIOPtrType, kIORefType, k ...@@ -354,6 +354,10 @@ enum class EIOCtorCategory : short {kAbsent, kDefault, kIOPtrType, kIORefType, k
//______________________________________________________________________________ //______________________________________________________________________________
EIOCtorCategory CheckConstructor(const clang::CXXRecordDecl*, const RConstructorType&, const cling::Interpreter& interp); EIOCtorCategory CheckConstructor(const clang::CXXRecordDecl*, const RConstructorType&, const cling::Interpreter& interp);
//______________________________________________________________________________
bool CheckDefaultConstructor(const clang::CXXRecordDecl*, const cling::Interpreter& interp);
//______________________________________________________________________________ //______________________________________________________________________________
const clang::FunctionDecl* ClassInfo__HasMethod(const clang::DeclContext *cl, char const*, const cling::Interpreter& interp); const clang::FunctionDecl* ClassInfo__HasMethod(const clang::DeclContext *cl, char const*, const cling::Interpreter& interp);
......
...@@ -987,6 +987,25 @@ int ROOT::TMetaUtils::ElementStreamer(std::ostream& finalString, ...@@ -987,6 +987,25 @@ int ROOT::TMetaUtils::ElementStreamer(std::ostream& finalString,
return 0; return 0;
} }
////////////////////////////////////////////////////////////////////////////////
/// Checks if default constructor exists and accessible
bool ROOT::TMetaUtils::CheckDefaultConstructor(const clang::CXXRecordDecl* cl, const cling::Interpreter& interpreter)
{
clang::CXXRecordDecl* ncCl = const_cast<clang::CXXRecordDecl*>(cl);
// We may induce template instantiation
cling::Interpreter::PushTransactionRAII clingRAII(const_cast<cling::Interpreter*>(&interpreter));
if (auto* Ctor = interpreter.getCI()->getSema().LookupDefaultConstructor(ncCl)) {
if (Ctor->getAccess() == clang::AS_public && !Ctor->isDeleted()) {
return true;
}
}
return false;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ROOT::TMetaUtils::EIOCtorCategory ROOT::TMetaUtils::CheckConstructor(const clang::CXXRecordDecl *cl, ROOT::TMetaUtils::EIOCtorCategory ROOT::TMetaUtils::CheckConstructor(const clang::CXXRecordDecl *cl,
...@@ -995,19 +1014,10 @@ ROOT::TMetaUtils::EIOCtorCategory ROOT::TMetaUtils::CheckConstructor(const clang ...@@ -995,19 +1014,10 @@ ROOT::TMetaUtils::EIOCtorCategory ROOT::TMetaUtils::CheckConstructor(const clang
{ {
const char *arg = ioctortype.GetName(); const char *arg = ioctortype.GetName();
if (ioctortype.GetType() ==0 && (arg == 0 || arg[0] == '\0')) { if (ioctortype.GetType() == nullptr && (arg == 0 || arg[0] == '\0')) {
// We are looking for a constructor with zero non-default arguments. // We are looking for a constructor with zero non-default arguments.
clang::CXXRecordDecl* ncCl = const_cast<clang::CXXRecordDecl*>(cl);
// We may induce template instantiation
cling::Interpreter::PushTransactionRAII clingRAII(const_cast<cling::Interpreter*>(&interpreter));
if (auto* Ctor = interpreter.getCI()->getSema().LookupDefaultConstructor(ncCl)) { return CheckDefaultConstructor(cl, interpreter) ? EIOCtorCategory::kDefault : EIOCtorCategory::kAbsent;
if (Ctor->getAccess() == clang::AS_public && !Ctor->isDeleted()) {
return EIOCtorCategory::kDefault;
}
}
return EIOCtorCategory::kAbsent;
} }
for (auto iter = cl->ctor_begin(), end = cl->ctor_end(); for (auto iter = cl->ctor_begin(), end = cl->ctor_end();
...@@ -1075,7 +1085,7 @@ const clang::CXXMethodDecl *GetMethodWithProto(const clang::Decl* cinfo, ...@@ -1075,7 +1085,7 @@ const clang::CXXMethodDecl *GetMethodWithProto(const clang::Decl* cinfo,
namespace ROOT { namespace ROOT {
namespace TMetaUtils { namespace TMetaUtils {
RConstructorType::RConstructorType(const char *type_of_arg, const cling::Interpreter &interp) : fArgTypeName(type_of_arg),fArgType(0) RConstructorType::RConstructorType(const char *type_of_arg, const cling::Interpreter &interp) : fArgTypeName(type_of_arg),fArgType(nullptr)
{ {
const cling::LookupHelper& lh = interp.getLookupHelper(); const cling::LookupHelper& lh = interp.getLookupHelper();
// We can not use findScope since the type we are given are usually, // We can not use findScope since the type we are given are usually,
......
...@@ -684,21 +684,17 @@ ROOT::TMetaUtils::EIOCtorCategory TClingClassInfo::HasDefaultConstructor(bool ch ...@@ -684,21 +684,17 @@ ROOT::TMetaUtils::EIOCtorCategory TClingClassInfo::HasDefaultConstructor(bool ch
if (!CRD) if (!CRD)
return EIOCtorCategory::kAbsent; return EIOCtorCategory::kAbsent;
const RConstructorType ioctortype_dflt("", *fInterp); if (checkio) {
auto kind = CheckConstructor(CRD, ioctortype_dflt, *fInterp);
if (checkio && (kind == EIOCtorCategory::kAbsent)) {
const RConstructorType ioctortype_io("TRootIOCtor", *fInterp); const RConstructorType ioctortype_io("TRootIOCtor", *fInterp);
kind = CheckConstructor(CRD, ioctortype_io, *fInterp); auto kind = CheckConstructor(CRD, ioctortype_io, *fInterp);
if (kind != EIOCtorCategory::kAbsent) return kind;
if (kind == EIOCtorCategory::kAbsent) { const RConstructorType ioctortype_io2("__void__", *fInterp);
const RConstructorType ioctortype_io2("__void__", *fInterp); if (CheckConstructor(CRD, ioctortype_io2, *fInterp) == EIOCtorCategory::kIORefType)
if (CheckConstructor(CRD, ioctortype_io2, *fInterp) == EIOCtorCategory::kIORefType) return EIOCtorCategory::kIOVoidType;
kind = EIOCtorCategory::kIOVoidType;
}
} }
return kind; return CheckDefaultConstructor(CRD, *fInterp) ? EIOCtorCategory::kDefault: EIOCtorCategory::kAbsent;
} }
bool TClingClassInfo::HasMethod(const char *name) const bool TClingClassInfo::HasMethod(const char *name) const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment