Skip to content

TClass: inline initialize most members #19114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/base/inc/Rtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
//---- forward declared class types --------------------------------------------

class TClass;
class TBrowser;
class TBuffer;
class TDirectory;
class TMemberInspector;
Expand Down Expand Up @@ -119,6 +120,7 @@ namespace ROOT {
typedef void (*DirAutoAdd_t)(void *, TDirectory *);
typedef Long64_t (*MergeFunc_t)(void *, TCollection *, TFileMergeInfo *);
typedef void (*ResetAfterMergeFunc_t)(void *, TFileMergeInfo *);
typedef void (*BrowseFunc_t)(const void *, TBrowser *);

template <class RootClass> Short_t SetClassVersion(RootClass *);

Expand Down
6 changes: 5 additions & 1 deletion core/clingutils/res/TClingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ bool HasDirectoryAutoAdd(clang::CXXRecordDecl const*, const cling::Interpreter&)
//______________________________________________________________________________
bool HasIOConstructor(clang::CXXRecordDecl const*, std::string&, const RConstructorTypes&, const cling::Interpreter&);

//______________________________________________________________________________
bool HasBrowse(clang::CXXRecordDecl const*, const cling::Interpreter&);

//______________________________________________________________________________
bool HasNewMerge(clang::CXXRecordDecl const*, const cling::Interpreter&);

Expand All @@ -446,7 +449,8 @@ bool NeedTemplateKeyword(clang::CXXRecordDecl const*);

//______________________________________________________________________________
bool CheckPublicFuncWithProto(clang::CXXRecordDecl const*, char const*, char const*,
const cling::Interpreter&, bool diagnose);
const cling::Interpreter&, bool diagnose,
bool objectIsConst = false);

//______________________________________________________________________________
long GetLineNumber(clang::Decl const*);
Expand Down
34 changes: 30 additions & 4 deletions core/clingutils/src/TClingUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1148,12 +1148,14 @@ ROOT::TMetaUtils::EIOCtorCategory ROOT::TMetaUtils::CheckConstructor(const clang
const clang::CXXMethodDecl *GetMethodWithProto(const clang::Decl* cinfo,
const char *method, const char *proto,
const cling::Interpreter &interp,
bool diagnose)
bool diagnose,
bool objectIsConst = false)
{
const clang::FunctionDecl* funcD
= interp.getLookupHelper().findFunctionProto(cinfo, method, proto,
diagnose ? cling::LookupHelper::WithDiagnostics
: cling::LookupHelper::NoDiagnostics);
: cling::LookupHelper::NoDiagnostics,
objectIsConst);
if (funcD)
return llvm::dyn_cast<const clang::CXXMethodDecl>(funcD);

Expand Down Expand Up @@ -1254,12 +1256,14 @@ bool ROOT::TMetaUtils::CheckPublicFuncWithProto(const clang::CXXRecordDecl *cl,
const char *methodname,
const char *proto,
const cling::Interpreter &interp,
bool diagnose)
bool diagnose,
bool objectIsConst)
{
const clang::CXXMethodDecl *method
= GetMethodWithProto(cl,methodname,proto, interp,
diagnose ? cling::LookupHelper::WithDiagnostics
: cling::LookupHelper::NoDiagnostics);
: cling::LookupHelper::NoDiagnostics,
objectIsConst);
return (method && method->getAccess() == clang::AS_public);
}

Expand All @@ -1277,6 +1281,16 @@ bool ROOT::TMetaUtils::HasDirectoryAutoAdd(const clang::CXXRecordDecl *cl, const
return CheckPublicFuncWithProto(cl,name,proto,interp, false /*diags*/);
}

////////////////////////////////////////////////////////////////////////////////
/// Return true if the class has a method Browse(TBrowser*) const

bool ROOT::TMetaUtils::HasBrowse(const clang::CXXRecordDecl *cl, const cling::Interpreter &interp)
{
const char *proto = "TBrowser*";
const char *name = "Browse";

return CheckPublicFuncWithProto(cl,name,proto,interp, false /*diags*/, true /* objectIsConst */);
}

////////////////////////////////////////////////////////////////////////////////
/// Return true if the class has a method Merge(TCollection*,TFileMergeInfo*)
Expand Down Expand Up @@ -1808,6 +1822,9 @@ void ROOT::TMetaUtils::WriteClassInit(std::ostream& finalString,
if (HasCustomConvStreamerMemberFunction(cl, decl, interp, normCtxt)) {
finalString << " static void conv_streamer_" << mappedname.c_str() << "(TBuffer &buf, void *obj, const TClass*);" << "\n";
}
if (HasBrowse(decl, interp)) {
finalString << " static void browse_" << mappedname.c_str() << "(const void *obj, TBrowser *b);" << "\n";
}
if (HasNewMerge(decl, interp) || HasOldMerge(decl, interp)) {
finalString << " static Long64_t merge_" << mappedname.c_str() << "(void *obj, TCollection *coll,TFileMergeInfo *info);" << "\n";
}
Expand Down Expand Up @@ -1988,6 +2005,9 @@ void ROOT::TMetaUtils::WriteClassInit(std::ostream& finalString,
// We have a custom member function streamer or an older (not StreamerInfo based) automatic streamer.
finalString << " instance.SetConvStreamerFunc(&conv_streamer_" << mappedname.c_str() << ");" << "\n";
}
if (HasBrowse(decl, interp)) {
finalString << " instance.SetBrowse(&browse_" << mappedname.c_str() << ");" << "\n";
}
if (HasNewMerge(decl, interp) || HasOldMerge(decl, interp)) {
finalString << " instance.SetMerge(&merge_" << mappedname.c_str() << ");" << "\n";
}
Expand Down Expand Up @@ -2606,6 +2626,12 @@ void ROOT::TMetaUtils::WriteAuxFunctions(std::ostream& finalString,
finalString << " // Wrapper around a custom streamer member function." << "\n" << " static void conv_streamer_" << mappedname.c_str() << "(TBuffer &buf, void *obj, const TClass *onfile_class) {" << "\n" << " ((" << classname.c_str() << "*)obj)->" << classname.c_str() << "::Streamer(buf,onfile_class);" << "\n" << " }" << "\n";
}

if (HasBrowse(decl, interp)) {
finalString << " // Wrapper around the browse function." << "\n"
<< " static void browse_" << mappedname.c_str() << "(const void *obj, TBrowser *b) {" << "\n"
<< " return ((const " << classname.c_str() << "*)obj)->Browse(b);" << "\n" << " }" << "\n";
}

if (HasNewMerge(decl, interp)) {
finalString << " // Wrapper around the merge function." << "\n" << " static Long64_t merge_" << mappedname.c_str() << "(void *obj,TCollection *coll,TFileMergeInfo *info) {" << "\n" << " return ((" << classname.c_str() << "*)obj)->Merge(coll,info);" << "\n" << " }" << "\n";
} else if (HasOldMerge(decl, interp)) {
Expand Down
Loading
Loading