Skip to content

Commit d9edba9

Browse files
committed
[core] In generated dict code, always prefix std classes with "std":
This is backward compatible and avoids having to inject a "using namespace std".
1 parent 6a2a6a7 commit d9edba9

File tree

3 files changed

+51
-38
lines changed

3 files changed

+51
-38
lines changed

core/clingutils/src/TClingUtils.cxx

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,13 +1715,11 @@ void ROOT::TMetaUtils::WriteClassInit(std::ostream& finalString,
17151715
std::string csymbol = classname;
17161716
std::string args;
17171717

1718-
if ( ! TClassEdit::IsStdClass( classname.c_str() ) ) {
1718+
csymbol = TClassEdit::InsertStd(csymbol.c_str());
17191719

1720-
// Prefix the full class name with '::' except for the STL
1721-
// containers and std::string. This is to request the
1722-
// real class instead of the class in the namespace ROOT::Shadow
1723-
csymbol.insert(0,"::");
1724-
}
1720+
// Prefix the full class name with '::', to refert to the
1721+
// real class instead of the class in the namespace ROOT::Shadow
1722+
csymbol.insert(0,"::");
17251723

17261724
int stl = TClassEdit::IsSTLCont(classname);
17271725
bool bset = TClassEdit::IsSTLBitset(classname.c_str());
@@ -1988,7 +1986,8 @@ void ROOT::TMetaUtils::WriteClassInit(std::ostream& finalString,
19881986
// FIXME Workaround: for the moment we do not generate coll proxies with unique ptrs since
19891987
// they imply copies and therefore do not compile.
19901988
auto classNameForIO = TClassEdit::GetNameForIO(classname);
1991-
finalString << " instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" << methodTCP << "< " << classNameForIO.c_str() << " >()));" << "\n";
1989+
classNameForIO = TClassEdit::InsertStd(classNameForIO.c_str());
1990+
finalString << " instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" << methodTCP << "< " << classNameForIO << " >()));" << "\n";
19921991

19931992
needCollectionProxy = true;
19941993
}
@@ -2378,15 +2377,12 @@ void ROOT::TMetaUtils::WriteAuxFunctions(std::ostream& finalString,
23782377
// operator delete
23792378
// operator delete[]
23802379

2381-
ROOT::TMetaUtils::GetCppName(mappedname,classname.c_str());
2382-
2383-
if ( ! TClassEdit::IsStdClass( classname.c_str() ) ) {
2380+
classname = TClassEdit::InsertStd(classname.c_str());
23842381

2385-
// Prefix the full class name with '::' except for the STL
2386-
// containers and std::string. This is to request the
2387-
// real class instead of the class in the namespace ROOT::Shadow
2388-
classname.insert(0,"::");
2389-
}
2382+
// Prefix the full class name with '::' except for the STL
2383+
// containers and std::string. This is to request the
2384+
// real class instead of the class in the namespace ROOT::Shadow
2385+
classname.insert(0,"::");
23902386

23912387
finalString << "namespace ROOT {" << "\n";
23922388

core/dictgen/src/rootcling_impl.cxx

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ int STLContainerStreamer(const clang::FieldDecl &m,
859859
if (!tmplt_specialization) return 0;
860860

861861
string stlType(ROOT::TMetaUtils::ShortTypeName(mTypename.c_str()));
862+
stlType = TClassEdit::InsertStd(stlType.c_str());
862863
string stlName;
863864
stlName = ROOT::TMetaUtils::ShortTypeName(m.getName().str().c_str());
864865

@@ -1171,6 +1172,8 @@ void WriteClassFunctions(const clang::CXXRecordDecl *cl, std::ostream &dictStrea
11711172
enclSpaceNesting = ROOT::TMetaUtils::WriteNamespaceHeader(dictStream, cl);
11721173
}
11731174

1175+
clsname = TClassEdit::InsertStd(clsname.c_str());
1176+
11741177
if (autoLoad)
11751178
dictStream << "#include \"TInterpreter.h\"\n";
11761179

@@ -1189,16 +1192,22 @@ void WriteClassFunctions(const clang::CXXRecordDecl *cl, std::ostream &dictStrea
11891192
dictStream << "//_______________________________________"
11901193
<< "_______________________________________" << std::endl;
11911194
if (add_template_keyword) dictStream << "template <> ";
1192-
dictStream << "const char *" << clsname << "::ImplFileName()" << std::endl << "{" << std::endl
1193-
<< " return ::ROOT::GenerateInitInstanceLocal((const ::" << fullname
1194-
<< "*)nullptr)->GetImplFileName();" << std::endl << "}" << std::endl << std::endl
1195+
dictStream << "const char *" << clsname << "::ImplFileName()" << std::endl
1196+
<< "{" << std::endl
1197+
<< " return ::ROOT::GenerateInitInstanceLocal((const ::" << clsname << "*)nullptr)->GetImplFileName();"
1198+
<< std::endl
1199+
<< "}" << std::endl
1200+
<< std::endl
11951201

11961202
<< "//_______________________________________"
11971203
<< "_______________________________________" << std::endl;
11981204
if (add_template_keyword) dictStream << "template <> ";
1199-
dictStream << "int " << clsname << "::ImplFileLine()" << std::endl << "{" << std::endl
1200-
<< " return ::ROOT::GenerateInitInstanceLocal((const ::" << fullname
1201-
<< "*)nullptr)->GetImplFileLine();" << std::endl << "}" << std::endl << std::endl
1205+
dictStream << "int " << clsname << "::ImplFileLine()" << std::endl
1206+
<< "{" << std::endl
1207+
<< " return ::ROOT::GenerateInitInstanceLocal((const ::" << clsname << "*)nullptr)->GetImplFileLine();"
1208+
<< std::endl
1209+
<< "}" << std::endl
1210+
<< std::endl
12021211

12031212
<< "//_______________________________________"
12041213
<< "_______________________________________" << std::endl;
@@ -1208,20 +1217,21 @@ void WriteClassFunctions(const clang::CXXRecordDecl *cl, std::ostream &dictStrea
12081217
// Trigger autoloading if dictionary is split
12091218
if (autoLoad)
12101219
dictStream << " gInterpreter->AutoLoad(\"" << fullname << "\");\n";
1211-
dictStream << " fgIsA = ::ROOT::GenerateInitInstanceLocal((const ::" << fullname
1212-
<< "*)nullptr)->GetClass();" << std::endl
1213-
<< " return fgIsA;\n"
1214-
<< "}" << std::endl << std::endl
1220+
dictStream << " fgIsA = ::ROOT::GenerateInitInstanceLocal((const ::" << clsname << "*)nullptr)->GetClass();"
1221+
<< std::endl
1222+
<< " return fgIsA;\n"
1223+
<< "}" << std::endl
1224+
<< std::endl
12151225

1216-
<< "//_______________________________________"
1217-
<< "_______________________________________" << std::endl;
1226+
<< "//_______________________________________"
1227+
<< "_______________________________________" << std::endl;
12181228
if (add_template_keyword) dictStream << "template <> ";
12191229
dictStream << "TClass *" << clsname << "::Class()" << std::endl << "{" << std::endl;
12201230
if (autoLoad) {
12211231
dictStream << " Dictionary();\n";
12221232
} else {
12231233
dictStream << " if (!fgIsA.load()) { R__LOCKGUARD(gInterpreterMutex); fgIsA = ::ROOT::GenerateInitInstanceLocal((const ::";
1224-
dictStream << fullname << "*)nullptr)->GetClass(); }" << std::endl;
1234+
dictStream << clsname << "*)nullptr)->GetClass(); }" << std::endl;
12251235
}
12261236
dictStream << " return fgIsA;" << std::endl
12271237
<< "}" << std::endl << std::endl;
@@ -1386,6 +1396,7 @@ void WriteStreamer(const ROOT::TMetaUtils::AnnotatedRecordDecl &cl,
13861396
if (ROOT::TMetaUtils::GetNameWithinNamespace(fullname, clsname, nsname, clxx)) {
13871397
enclSpaceNesting = ROOT::TMetaUtils::WriteNamespaceHeader(dictStream, cl);
13881398
}
1399+
clsname = TClassEdit::InsertStd(clsname.c_str());
13891400

13901401
dictStream << "//_______________________________________"
13911402
<< "_______________________________________" << std::endl;
@@ -1788,19 +1799,22 @@ void WriteAutoStreamer(const ROOT::TMetaUtils::AnnotatedRecordDecl &cl,
17881799
if (ROOT::TMetaUtils::GetNameWithinNamespace(fullname, clsname, nsname, clxx)) {
17891800
enclSpaceNesting = ROOT::TMetaUtils::WriteNamespaceHeader(dictStream, cl);
17901801
}
1802+
clsname = TClassEdit::InsertStd(clsname.c_str());
17911803

17921804
dictStream << "//_______________________________________"
17931805
<< "_______________________________________" << std::endl;
17941806
if (add_template_keyword) dictStream << "template <> ";
17951807
dictStream << "void " << clsname << "::Streamer(TBuffer &R__b)" << std::endl
17961808
<< "{" << std::endl
1797-
<< " // Stream an object of class " << fullname << "." << std::endl << std::endl
1809+
<< " // Stream an object of class " << fullname << "." << std::endl
1810+
<< std::endl
17981811
<< " if (R__b.IsReading()) {" << std::endl
1799-
<< " R__b.ReadClassBuffer(" << fullname << "::Class(),this);" << std::endl
1812+
<< " R__b.ReadClassBuffer(" << clsname << "::Class(),this);" << std::endl
18001813
<< " } else {" << std::endl
1801-
<< " R__b.WriteClassBuffer(" << fullname << "::Class(),this);" << std::endl
1814+
<< " R__b.WriteClassBuffer(" << clsname << "::Class(),this);" << std::endl
18021815
<< " }" << std::endl
1803-
<< "}" << std::endl << std::endl;
1816+
<< "}" << std::endl
1817+
<< std::endl;
18041818

18051819
while (enclSpaceNesting) {
18061820
dictStream << "} // namespace " << nsname << std::endl;

core/foundation/src/RConversionRuleParser.cxx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,11 @@ namespace ROOT
475475

476476
static void WriteAutoVariables( const std::list<std::string>& target,
477477
const SourceTypeList_t& source,
478-
MembersTypeMap_t& members,
479-
std::string& className, std::string& mappedName,
478+
const MembersTypeMap_t& members,
479+
std::string className, const std::string& mappedName,
480480
std::ostream& output )
481481
{
482+
className = TClassEdit::InsertStd(className.c_str());
482483
if (!source.empty()) {
483484
Bool_t start = true;
484485
SourceTypeList_t::const_iterator it;
@@ -616,18 +617,20 @@ namespace ROOT
616617

617618
std::list<std::string>::const_iterator it;
618619
for( it = target.begin(); it != target.end(); ++it ) {
619-
Internal::TSchemaType memData = members[*it];
620+
const Internal::TSchemaType &memData = members.find(*it)->second;
620621
output << " static Long_t offset_" << *it << " = ";
621622
output << "cls->GetDataMemberOffset(\"" << *it << "\");";
622623
output << std::endl;
624+
std::string memDataType = TClassEdit::InsertStd(memData.fType.c_str());
623625
if (memData.fDimensions.size()) {
624-
output << " typedef " << memData.fType << " " << *it << "_t" << memData.fDimensions << ";" << std::endl;
626+
output << " typedef " << memDataType << " " << *it << "_t" << memData.fDimensions << ";"
627+
<< std::endl;
625628
output << " " << *it << "_t& " << *it << " = ";
626629
output << "*(" << *it << "_t *)(target+offset_" << *it;
627630
output << ");" << std::endl;
628631
} else {
629-
output << " " << memData.fType << "& " << *it << " = ";
630-
output << "*(" << memData.fType << "*)(target+offset_" << *it;
632+
output << " " << memDataType << "& " << *it << " = ";
633+
output << "*(" << memDataType << "*)(target+offset_" << *it;
631634
output << ");" << std::endl;
632635
}
633636
}

0 commit comments

Comments
 (0)