Skip to content

Commit a489091

Browse files
committed
[core] Only check via TClassTable for alternative names
1 parent 22ad2f2 commit a489091

File tree

6 files changed

+65
-21
lines changed

6 files changed

+65
-21
lines changed

core/clingutils/res/TClingUtils.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,25 +160,26 @@ class TNormalizedCtxt {
160160
class TClingLookupHelper : public TClassEdit::TInterpreterLookupHelper {
161161
public:
162162
typedef bool (*ExistingTypeCheck_t)(const std::string &tname, std::string &result);
163+
typedef bool (*TClassTableCheck_t)(const std::string &tname, std::string &result);
163164
typedef bool (*AutoParse_t)(const char *name);
164165

165166
private:
166167
cling::Interpreter *fInterpreter;
167168
TNormalizedCtxt *fNormalizedCtxt;
168169
ExistingTypeCheck_t fExistingTypeCheck;
170+
TClassTableCheck_t fTClassTableCheck;
169171
AutoParse_t fAutoParse;
170172
bool *fInterpreterIsShuttingDownPtr;
171173
const int *fPDebug; // debug flag, might change at runtime thus *
172174
bool WantDiags() const { return fPDebug && *fPDebug > 5; }
173175

174176
public:
175-
TClingLookupHelper(cling::Interpreter &interpreter, TNormalizedCtxt &normCtxt,
176-
ExistingTypeCheck_t existingTypeCheck,
177-
AutoParse_t autoParse,
178-
bool *shuttingDownPtr,
177+
TClingLookupHelper(cling::Interpreter &interpreter, TNormalizedCtxt &normCtxt, ExistingTypeCheck_t existingTypeCheck,
178+
TClassTableCheck_t TClassTableCheck, AutoParse_t autoParse, bool *shuttingDownPtr,
179179
const int *pgDebug = nullptr);
180180
virtual ~TClingLookupHelper() { /* we're not owner */ }
181181

182+
bool TClassTableCheck(const std::string &tname, std::string &result) override;
182183
bool ExistingTypeCheck(const std::string &tname, std::string &result) override;
183184
void GetPartiallyDesugaredName(std::string &nameLong) override;
184185
bool IsAlreadyPartiallyDesugaredName(const std::string &nondef, const std::string &nameLong) override;

core/clingutils/src/TClingUtils.cxx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -522,17 +522,16 @@ AnnotatedRecordDecl::AnnotatedRecordDecl(long index,
522522

523523
////////////////////////////////////////////////////////////////////////////////
524524

525-
TClingLookupHelper::TClingLookupHelper(cling::Interpreter &interpreter,
526-
TNormalizedCtxt &normCtxt,
527-
ExistingTypeCheck_t existingTypeCheck,
528-
AutoParse_t autoParse,
529-
bool *shuttingDownPtr,
530-
const int* pgDebug /*= 0*/):
531-
fInterpreter(&interpreter),fNormalizedCtxt(&normCtxt),
532-
fExistingTypeCheck(existingTypeCheck),
533-
fAutoParse(autoParse),
534-
fInterpreterIsShuttingDownPtr(shuttingDownPtr),
535-
fPDebug(pgDebug)
525+
TClingLookupHelper::TClingLookupHelper(cling::Interpreter &interpreter, TNormalizedCtxt &normCtxt,
526+
ExistingTypeCheck_t existingTypeCheck, TClassTableCheck_t TClassTableCheck,
527+
AutoParse_t autoParse, bool *shuttingDownPtr, const int *pgDebug /*= 0*/)
528+
: fInterpreter(&interpreter),
529+
fNormalizedCtxt(&normCtxt),
530+
fExistingTypeCheck(existingTypeCheck),
531+
fTClassTableCheck(TClassTableCheck),
532+
fAutoParse(autoParse),
533+
fInterpreterIsShuttingDownPtr(shuttingDownPtr),
534+
fPDebug(pgDebug)
536535
{
537536
}
538537

@@ -549,6 +548,17 @@ bool TClingLookupHelper::ExistingTypeCheck(const std::string &tname,
549548
else return false;
550549
}
551550

551+
bool TClingLookupHelper::TClassTableCheck(const std::string &tname, std::string &result)
552+
{
553+
if (tname.empty())
554+
return false;
555+
556+
if (fTClassTableCheck)
557+
return fTClassTableCheck(tname, result);
558+
else
559+
return false;
560+
}
561+
552562
////////////////////////////////////////////////////////////////////////////////
553563

554564
void TClingLookupHelper::GetPartiallyDesugaredName(std::string &nameLong)

core/dictgen/src/rootcling_impl.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4498,7 +4498,7 @@ int RootClingMain(int argc,
44984498

44994499
// We are now ready (enough is loaded) to init the list of opaque typedefs.
45004500
ROOT::TMetaUtils::TNormalizedCtxt normCtxt(interp.getLookupHelper());
4501-
ROOT::TMetaUtils::TClingLookupHelper helper(interp, normCtxt, nullptr, nullptr, nullptr);
4501+
ROOT::TMetaUtils::TClingLookupHelper helper(interp, normCtxt, nullptr, nullptr, nullptr, nullptr);
45024502
TClassEdit::Init(&helper);
45034503

45044504
// flags used only for the pragma parser:

core/foundation/inc/TClassEdit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ namespace TClassEdit {
124124
TInterpreterLookupHelper() { }
125125
virtual ~TInterpreterLookupHelper();
126126

127+
virtual bool TClassTableCheck(const std::string &, std::string &) = 0;
127128
virtual bool ExistingTypeCheck(const std::string & /*tname*/,
128129
std::string & /*result*/) = 0;
129130
virtual void GetPartiallyDesugaredName(std::string & /*nameLong*/) = 0;

core/foundation/src/TClassEdit.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ void TClassEdit::GetNormalizedName(std::string &norm_name, std::string_view name
913913
// is when looking for registered alternate names of a custom user class
914914
// present in the class dictionary.
915915
std::string typeresult;
916-
if (gInterpreterHelper->ExistingTypeCheck(norm_name, typeresult)) {
916+
if (gInterpreterHelper->TClassTableCheck(norm_name, typeresult)) {
917917
if (!typeresult.empty()) {
918918
norm_name = typeresult;
919919
}

core/metacling/src/TCling.cxx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,39 @@ bool TClingLookupHelper__ExistingTypeCheck(const std::string &tname,
10101010
return false;
10111011
}
10121012

1013+
bool TClingLookupHelper__TClassTableCheck(const std::string &tname, std::string &result)
1014+
{
1015+
result.clear();
1016+
1017+
unsigned long offset = 0;
1018+
if (strncmp(tname.c_str(), "const ", 6) == 0) {
1019+
offset = 6;
1020+
}
1021+
unsigned long end = tname.length();
1022+
while (end && (tname[end - 1] == '&' || tname[end - 1] == '*' || tname[end - 1] == ']')) {
1023+
if (tname[end - 1] == ']') {
1024+
--end;
1025+
while (end && tname[end - 1] != '[')
1026+
--end;
1027+
}
1028+
--end;
1029+
}
1030+
std::string innerbuf;
1031+
const char *inner;
1032+
if (end != tname.length()) {
1033+
innerbuf = tname.substr(offset, end - offset);
1034+
inner = innerbuf.c_str();
1035+
} else {
1036+
inner = tname.c_str() + offset;
1037+
}
1038+
1039+
if (gROOT->GetListOfClasses()->FindObject(inner) || TClassTable::Check(inner, result)) {
1040+
// This is a known class.
1041+
return true;
1042+
}
1043+
1044+
return false;
1045+
}
10131046
////////////////////////////////////////////////////////////////////////////////
10141047

10151048
TCling::TUniqueString::TUniqueString(Long64_t size)
@@ -1586,10 +1619,9 @@ TCling::TCling(const char *name, const char *title, const char* const argv[], vo
15861619

15871620
// We are now ready (enough is loaded) to init the list of opaque typedefs.
15881621
fNormalizedCtxt = new ROOT::TMetaUtils::TNormalizedCtxt(fInterpreter->getLookupHelper());
1589-
fLookupHelper = new ROOT::TMetaUtils::TClingLookupHelper(*fInterpreter, *fNormalizedCtxt,
1590-
TClingLookupHelper__ExistingTypeCheck,
1591-
TClingLookupHelper__AutoParse,
1592-
&fIsShuttingDown);
1622+
fLookupHelper = new ROOT::TMetaUtils::TClingLookupHelper(
1623+
*fInterpreter, *fNormalizedCtxt, TClingLookupHelper__ExistingTypeCheck, TClingLookupHelper__TClassTableCheck,
1624+
TClingLookupHelper__AutoParse, &fIsShuttingDown);
15931625
TClassEdit::Init(fLookupHelper);
15941626

15951627
// Disallow auto-parsing in rootcling

0 commit comments

Comments
 (0)