Skip to content

Commit a7e4d08

Browse files
committed
[metacling] Refactor TClingMethodInfo to use the base class. NFC.
This patch removes the redundant norm context method arguments.
1 parent 20438e5 commit a7e4d08

File tree

4 files changed

+37
-40
lines changed

4 files changed

+37
-40
lines changed

core/metacling/src/TCling.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8424,15 +8424,15 @@ const char* TCling::MethodInfo_GetMangledName(MethodInfo_t* minfo) const
84248424
const char* TCling::MethodInfo_GetPrototype(MethodInfo_t* minfo) const
84258425
{
84268426
TClingMethodInfo* info = (TClingMethodInfo*) minfo;
8427-
return info->GetPrototype(*fNormalizedCtxt);
8427+
return info->GetPrototype();
84288428
}
84298429

84308430
////////////////////////////////////////////////////////////////////////////////
84318431

84328432
const char* TCling::MethodInfo_Name(MethodInfo_t* minfo) const
84338433
{
84348434
TClingMethodInfo* info = (TClingMethodInfo*) minfo;
8435-
return info->Name(*fNormalizedCtxt);
8435+
return info->Name();
84368436
}
84378437

84388438
////////////////////////////////////////////////////////////////////////////////

core/metacling/src/TClingCallFunc.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ void TClingCallFunc::exec(void *address, void *ret)
14831483
if (num_args < GetMinRequiredArguments()) {
14841484
::Error("TClingCallFunc::exec",
14851485
"Not enough arguments provided for %s (%d instead of the minimum %d)",
1486-
fMethod->Name(ROOT::TMetaUtils::TNormalizedCtxt(fInterp->getLookupHelper())),
1486+
fMethod->Name(),
14871487
num_args, (int)GetMinRequiredArguments());
14881488
return;
14891489
}
@@ -1492,7 +1492,7 @@ void TClingCallFunc::exec(void *address, void *ret)
14921492
&& !dyn_cast<CXXConstructorDecl>(FD)) {
14931493
::Error("TClingCallFunc::exec",
14941494
"The method %s is called without an object.",
1495-
fMethod->Name(ROOT::TMetaUtils::TNormalizedCtxt(fInterp->getLookupHelper())));
1495+
fMethod->Name());
14961496
return;
14971497
}
14981498
vh_ary.reserve(num_args);

core/metacling/src/TClingMethodInfo.cxx

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ class TClingMethodInfo::SpecIterator
8383
};
8484

8585
TClingMethodInfo::TClingMethodInfo(const TClingMethodInfo &rhs) :
86+
TClingDeclInfo(rhs),
8687
fInterp(rhs.fInterp),
8788
fContexts(rhs.fContexts),
8889
fFirstTime(rhs.fFirstTime),
8990
fContextIdx(rhs.fContextIdx),
9091
fIter(rhs.fIter),
9192
fTitle(rhs.fTitle),
92-
fTemplateSpecIter(nullptr),
93-
fSingleDecl(rhs.fSingleDecl)
93+
fTemplateSpecIter(nullptr)
9494
{
9595
if (rhs.fTemplateSpecIter) {
9696
// The SpecIterator query the decl.
@@ -102,8 +102,8 @@ TClingMethodInfo::TClingMethodInfo(const TClingMethodInfo &rhs) :
102102

103103
TClingMethodInfo::TClingMethodInfo(cling::Interpreter *interp,
104104
TClingClassInfo *ci)
105-
: fInterp(interp), fFirstTime(true), fContextIdx(0U), fTitle(""),
106-
fTemplateSpecIter(0), fSingleDecl(0)
105+
: TClingDeclInfo(nullptr), fInterp(interp), fFirstTime(true), fContextIdx(0U), fTitle(""),
106+
fTemplateSpecIter(0)
107107
{
108108
R__LOCKGUARD(gInterpreterMutex);
109109

@@ -131,8 +131,8 @@ TClingMethodInfo::TClingMethodInfo(cling::Interpreter *interp,
131131

132132
TClingMethodInfo::TClingMethodInfo(cling::Interpreter *interp,
133133
const clang::FunctionDecl *FD)
134-
: fInterp(interp), fFirstTime(true), fContextIdx(0U), fTitle(""),
135-
fTemplateSpecIter(0), fSingleDecl(FD)
134+
: TClingDeclInfo(FD), fInterp(interp), fFirstTime(true), fContextIdx(0U), fTitle(""),
135+
fTemplateSpecIter(0)
136136
{
137137

138138
}
@@ -152,17 +152,7 @@ TDictionary::DeclId_t TClingMethodInfo::GetDeclId() const
152152

153153
const clang::FunctionDecl *TClingMethodInfo::GetMethodDecl() const
154154
{
155-
if (!IsValid()) {
156-
return 0;
157-
}
158-
159-
if (fSingleDecl)
160-
return fSingleDecl;
161-
162-
if (fTemplateSpecIter)
163-
return *(*fTemplateSpecIter);
164-
165-
return llvm::dyn_cast<clang::FunctionDecl>(*fIter);
155+
return cast_or_null<FunctionDecl>(GetDecl());
166156
}
167157

168158
void TClingMethodInfo::CreateSignature(TString &signature) const
@@ -203,7 +193,7 @@ void TClingMethodInfo::Init(const clang::FunctionDecl *decl)
203193
fIter = clang::DeclContext::decl_iterator();
204194
delete fTemplateSpecIter;
205195
fTemplateSpecIter = 0;
206-
fSingleDecl = decl;
196+
fDecl = decl;
207197
}
208198

209199
void *TClingMethodInfo::InterfaceMethod(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
@@ -217,7 +207,7 @@ void *TClingMethodInfo::InterfaceMethod(const ROOT::TMetaUtils::TNormalizedCtxt
217207
return cf.InterfaceMethod();
218208
}
219209

220-
bool TClingMethodInfo::IsValidSlow() const
210+
const clang::Decl* TClingMethodInfo::GetDeclSlow() const
221211
{
222212
if (fTemplateSpecIter) {
223213
// Could trigger deserialization of decls.
@@ -374,7 +364,9 @@ static void InstantiateFuncTemplateWithDefaults(clang::FunctionTemplateDecl* FTD
374364
int TClingMethodInfo::InternalNext()
375365
{
376366

377-
assert(!fSingleDecl && "This is not an iterator!");
367+
assert(!fDecl && "This is not an iterator!");
368+
369+
fNameCache.clear(); // invalidate the cache.
378370

379371
if (!fFirstTime && !*fIter) {
380372
// Iterator is already invalid.
@@ -619,7 +611,7 @@ std::string TClingMethodInfo::GetMangledName() const
619611
return mangled_name;
620612
}
621613

622-
const char *TClingMethodInfo::GetPrototype(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
614+
const char *TClingMethodInfo::GetPrototype()
623615
{
624616
if (!IsValid()) {
625617
return 0;
@@ -643,7 +635,7 @@ const char *TClingMethodInfo::GetPrototype(const ROOT::TMetaUtils::TNormalizedCt
643635
buf += name;
644636
buf += "::";
645637
}
646-
buf += Name(normCtxt);
638+
buf += Name();
647639
buf += '(';
648640
TClingMethodArgInfo arg(fInterp, this);
649641
int idx = 0;
@@ -672,14 +664,16 @@ const char *TClingMethodInfo::GetPrototype(const ROOT::TMetaUtils::TNormalizedCt
672664
return buf.c_str();
673665
}
674666

675-
const char *TClingMethodInfo::Name(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
667+
const char *TClingMethodInfo::Name()
676668
{
677669
if (!IsValid()) {
678670
return 0;
679671
}
680-
TTHREAD_TLS_DECL( std::string, buf );
681-
((TCling*)gCling)->GetFunctionName(GetMethodDecl(),buf);
682-
return buf.c_str();
672+
if (!fNameCache.empty())
673+
return fNameCache.c_str();
674+
675+
((TCling*)gCling)->GetFunctionName(GetMethodDecl(), fNameCache);
676+
return fNameCache.c_str();
683677
}
684678

685679
const char *TClingMethodInfo::TypeName() const

core/metacling/src/TClingMethodInfo.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
// //
2727
//////////////////////////////////////////////////////////////////////////
2828

29+
#include "TClingDeclInfo.h"
30+
2931
#include "TString.h"
3032
#include "TDictionary.h"
3133

@@ -49,7 +51,7 @@ namespace ROOT {
4951
class TClingClassInfo;
5052
class TClingTypeInfo;
5153

52-
class TClingMethodInfo {
54+
class TClingMethodInfo final : public TClingDeclInfo {
5355
private:
5456
class SpecIterator;
5557

@@ -60,14 +62,13 @@ class TClingMethodInfo {
6062
clang::DeclContext::decl_iterator fIter; // Our iterator.
6163
std::string fTitle; // The meta info for the method.
6264
SpecIterator *fTemplateSpecIter; // Iter over template specialization. [We own]
63-
const clang::FunctionDecl *fSingleDecl; // The single member
6465

65-
bool IsValidSlow() const;
66+
const clang::Decl* GetDeclSlow() const;
6667

6768
public:
6869
explicit TClingMethodInfo(cling::Interpreter *interp)
69-
: fInterp(interp), fFirstTime(true), fContextIdx(0U), fTitle(""),
70-
fTemplateSpecIter(0), fSingleDecl(0) {}
70+
: TClingDeclInfo(nullptr), fInterp(interp), fFirstTime(true), fContextIdx(0U), fTitle(""),
71+
fTemplateSpecIter(0) {}
7172

7273
TClingMethodInfo(const TClingMethodInfo&);
7374

@@ -83,9 +84,11 @@ class TClingMethodInfo {
8384
void CreateSignature(TString &signature) const;
8485
void Init(const clang::FunctionDecl *);
8586
void *InterfaceMethod(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
86-
bool IsValid() const {
87-
if (fSingleDecl) return fSingleDecl;
88-
return IsValidSlow();
87+
88+
const clang::Decl *GetDecl() const override {
89+
if (const clang::Decl* SingleDecl = TClingDeclInfo::GetDecl())
90+
return SingleDecl;
91+
return GetDeclSlow();
8992
}
9093
int NArg() const;
9194
int NDefaultArg() const;
@@ -95,8 +98,8 @@ class TClingMethodInfo {
9598
long ExtraProperty() const;
9699
TClingTypeInfo *Type() const;
97100
std::string GetMangledName() const;
98-
const char *GetPrototype(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
99-
const char *Name(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
101+
const char *GetPrototype();
102+
const char *Name() override;
100103
const char *TypeName() const;
101104
const char *Title();
102105
};

0 commit comments

Comments
 (0)