Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
36a7534
[TCling] Use string,vector instead of std.
Axel-Naumann Jul 22, 2022
9670fe8
[test] Remove legacy using namespace std/stdext.
Axel-Naumann May 9, 2023
38a0341
[proof] Remove unnecessary `using namespace std` in header.
Axel-Naumann May 9, 2023
1395866
[foundation] Add doc to some TClassEdit functions (NFC).
Axel-Naumann May 9, 2023
7c7a1d5
[dictgen] Make gOptNoGlobalUsingStd the default and only way.
Axel-Naumann May 9, 2023
6a2a6a7
[dictgen] Remove unused var; add using decls for std types.
Axel-Naumann May 10, 2023
d9edba9
[core] In generated dict code, always prefix std classes with "std":
Axel-Naumann May 10, 2023
859bfeb
[mathcore] Do not generate a dict for vector<double> iters:
Axel-Naumann May 10, 2023
f1065cb
[foundation] TClassEdit::InsertStd: add PRNG types to std type list.
Axel-Naumann May 11, 2023
c6ec900
Do not generate dicts for iterators:
Axel-Naumann May 11, 2023
542e382
[foundation] Fix spelling of std types; add missing ones, rm auto_ptr.
Axel-Naumann May 11, 2023
cdc2a31
[io] Diagnose missing stdlib I/O support:
Axel-Naumann May 15, 2023
4503bd0
[geo] Do not generate dictionaries for thread::id:
Axel-Naumann May 15, 2023
52e9f32
[fumili] no dict for TFumiliMinimizer: not persistent and not a TObje…
Axel-Naumann May 15, 2023
430660e
[clingutils] Fwd decls must use "std::" where needed:
Axel-Naumann May 15, 2023
a316141
[dictgen] Inject using decls for common stdlib names in ACLiC dicts:
Axel-Naumann May 16, 2023
32f08fa
[core] Do not InspectMembers() for stdlib types:
Axel-Naumann May 16, 2023
353faaa
[core] Centralize using decls injected into cling, add more.
Axel-Naumann May 17, 2023
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
8 changes: 0 additions & 8 deletions core/base/inc/LinkDef2.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

#ifdef __CLING__
#include <string>
#pragma link C++ class string::iterator;
#pragma link C++ class string::const_iterator;
#else
#include "dll_stl/str.h"
#endif
Expand All @@ -24,15 +22,9 @@
#pragma create TClass string;
#pragma link C++ class std::vector<string>;
#pragma link C++ operator std::vector<string>;
#pragma link C++ class std::vector<string>::iterator;
#pragma link C++ class std::vector<string>::const_iterator;
#pragma link C++ class std::vector<string>::reverse_iterator;

#pragma link C++ class std::vector<TString>;
#pragma link C++ operators std::vector<TString>;
#pragma link C++ class std::vector<TString>::iterator;
#pragma link C++ class std::vector<TString>::const_iterator;
#pragma link C++ class std::vector<TString>::reverse_iterator;

#include <vector>

Expand Down
3 changes: 3 additions & 0 deletions core/clingutils/res/TClingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ void SetPathsForRelocatability(std::vector<std::string>& clingArgs);
//______________________________________________________________________________
void ReplaceAll(std::string& str, const std::string& from, const std::string& to, bool recurse=false);

//______________________________________________________________________________
std::string GetInjectedUsingDecls();

// Functions for the printouts -------------------------------------------------

//______________________________________________________________________________
Expand Down
72 changes: 56 additions & 16 deletions core/clingutils/src/TClingUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1715,13 +1715,11 @@ void ROOT::TMetaUtils::WriteClassInit(std::ostream& finalString,
std::string csymbol = classname;
std::string args;

if ( ! TClassEdit::IsStdClass( classname.c_str() ) ) {
csymbol = TClassEdit::InsertStd(csymbol.c_str());

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

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

needCollectionProxy = true;
}
Expand Down Expand Up @@ -2378,15 +2377,12 @@ void ROOT::TMetaUtils::WriteAuxFunctions(std::ostream& finalString,
// operator delete
// operator delete[]

ROOT::TMetaUtils::GetCppName(mappedname,classname.c_str());
classname = TClassEdit::InsertStd(classname.c_str());

if ( ! TClassEdit::IsStdClass( classname.c_str() ) ) {

// Prefix the full class name with '::' except for the STL
// containers and std::string. This is to request the
// real class instead of the class in the namespace ROOT::Shadow
classname.insert(0,"::");
}
// Prefix the full class name with '::' except for the STL
// containers and std::string. This is to request the
// real class instead of the class in the namespace ROOT::Shadow
classname.insert(0,"::");

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

Expand Down Expand Up @@ -5102,6 +5098,49 @@ bool ROOT::TMetaUtils::IsHeaderName(const std::string &filename)
llvm::sys::path::extension(filename) == "HXX";
}

////////////////////////////////////////////////////////////////////////////////
/// Get the using decls (and corresponding `#includes`) injected into cling for
/// backward compatibility with the earlier `using namespace std`.
std::string ROOT::TMetaUtils::GetInjectedUsingDecls() {
return R"CODE(#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::abs;
using std::fabs;
using std::array;
using std::bitset;
using std::cerr;
using std::cos;
using std::cout;
using std::endl;
using std::list;
using std::map;
using std::multimap;
using std::multiset;
using std::pair;
using std::round;
using std::set;
using std::sin;
using std::shared_ptr;
using std::string;
using std::tan;
using std::unique_ptr;
using std::unordered_map;
using std::unordered_set;
using std::vector;
)CODE";
}

////////////////////////////////////////////////////////////////////////////////

const std::string ROOT::TMetaUtils::AST2SourceTools::Decls2FwdDecls(const std::vector<const clang::Decl *> &decls,
Expand Down Expand Up @@ -5369,7 +5408,8 @@ int ROOT::TMetaUtils::AST2SourceTools::FwdDeclIfTmplSpec(const clang::RecordDecl
}
defString += argFwdDecl + '\n';
}
defString += "template <> class " + normalizedName + ';';
std::string normalizedNameWithStd = TClassEdit::InsertStd(normalizedName.c_str());
defString += "template <> class " + normalizedNameWithStd + ';';
return 0;
}
}
Expand Down
3 changes: 0 additions & 3 deletions core/cont/inc/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
#pragma link C++ class TVirtualCollectionProxy-;

#pragma link C++ class std::vector<Int_t>;
#pragma link C++ class std::vector<Int_t>::iterator;
#pragma link C++ class std::vector<Int_t>::const_iterator;
#pragma link C++ class std::vector<Int_t>::reverse_iterator;

#pragma link C++ nestedclass;
#pragma link C++ nestedtypedef;
Expand Down
111 changes: 59 additions & 52 deletions core/dictgen/src/rootcling_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ int STLContainerStreamer(const clang::FieldDecl &m,
if (!tmplt_specialization) return 0;

string stlType(ROOT::TMetaUtils::ShortTypeName(mTypename.c_str()));
stlType = TClassEdit::InsertStd(stlType.c_str());
string stlName;
stlName = ROOT::TMetaUtils::ShortTypeName(m.getName().str().c_str());

Expand Down Expand Up @@ -1171,6 +1172,9 @@ void WriteClassFunctions(const clang::CXXRecordDecl *cl, std::ostream &dictStrea
enclSpaceNesting = ROOT::TMetaUtils::WriteNamespaceHeader(dictStream, cl);
}

fullname = TClassEdit::InsertStd(fullname.c_str());
clsname = TClassEdit::InsertStd(clsname.c_str());

if (autoLoad)
dictStream << "#include \"TInterpreter.h\"\n";

Expand All @@ -1183,22 +1187,31 @@ void WriteClassFunctions(const clang::CXXRecordDecl *cl, std::ostream &dictStrea
<< "//_______________________________________"
<< "_______________________________________" << std::endl;
if (add_template_keyword) dictStream << "template <> ";
dictStream << "const char *" << clsname << "::Class_Name()" << std::endl << "{" << std::endl
<< " return \"" << fullname << "\";" << std::endl << "}" << std::endl << std::endl;
dictStream << "const char *" << clsname << "::Class_Name()" << std::endl
<< "{" << std::endl
<< " return \"" << fullname << "\";" << std::endl
<< "}" << std::endl
<< std::endl;

dictStream << "//_______________________________________"
<< "_______________________________________" << std::endl;
if (add_template_keyword) dictStream << "template <> ";
dictStream << "const char *" << clsname << "::ImplFileName()" << std::endl << "{" << std::endl
<< " return ::ROOT::GenerateInitInstanceLocal((const ::" << fullname
<< "*)nullptr)->GetImplFileName();" << std::endl << "}" << std::endl << std::endl
dictStream << "const char *" << clsname << "::ImplFileName()" << std::endl
<< "{" << std::endl
<< " return ::ROOT::GenerateInitInstanceLocal((const ::" << fullname << "*)nullptr)->GetImplFileName();"
<< std::endl
<< "}" << std::endl
<< std::endl

<< "//_______________________________________"
<< "_______________________________________" << std::endl;
if (add_template_keyword) dictStream << "template <> ";
dictStream << "int " << clsname << "::ImplFileLine()" << std::endl << "{" << std::endl
<< " return ::ROOT::GenerateInitInstanceLocal((const ::" << fullname
<< "*)nullptr)->GetImplFileLine();" << std::endl << "}" << std::endl << std::endl
dictStream << "int " << clsname << "::ImplFileLine()" << std::endl
<< "{" << std::endl
<< " return ::ROOT::GenerateInitInstanceLocal((const ::" << fullname << "*)nullptr)->GetImplFileLine();"
<< std::endl
<< "}" << std::endl
<< std::endl

<< "//_______________________________________"
<< "_______________________________________" << std::endl;
Expand All @@ -1208,13 +1221,14 @@ void WriteClassFunctions(const clang::CXXRecordDecl *cl, std::ostream &dictStrea
// Trigger autoloading if dictionary is split
if (autoLoad)
dictStream << " gInterpreter->AutoLoad(\"" << fullname << "\");\n";
dictStream << " fgIsA = ::ROOT::GenerateInitInstanceLocal((const ::" << fullname
<< "*)nullptr)->GetClass();" << std::endl
<< " return fgIsA;\n"
<< "}" << std::endl << std::endl
dictStream << " fgIsA = ::ROOT::GenerateInitInstanceLocal((const ::" << fullname << "*)nullptr)->GetClass();"
<< std::endl
<< " return fgIsA;\n"
<< "}" << std::endl
<< std::endl

<< "//_______________________________________"
<< "_______________________________________" << std::endl;
<< "//_______________________________________"
<< "_______________________________________" << std::endl;
if (add_template_keyword) dictStream << "template <> ";
dictStream << "TClass *" << clsname << "::Class()" << std::endl << "{" << std::endl;
if (autoLoad) {
Expand Down Expand Up @@ -1386,6 +1400,7 @@ void WriteStreamer(const ROOT::TMetaUtils::AnnotatedRecordDecl &cl,
if (ROOT::TMetaUtils::GetNameWithinNamespace(fullname, clsname, nsname, clxx)) {
enclSpaceNesting = ROOT::TMetaUtils::WriteNamespaceHeader(dictStream, cl);
}
clsname = TClassEdit::InsertStd(clsname.c_str());

dictStream << "//_______________________________________"
<< "_______________________________________" << std::endl;
Expand Down Expand Up @@ -1788,19 +1803,22 @@ void WriteAutoStreamer(const ROOT::TMetaUtils::AnnotatedRecordDecl &cl,
if (ROOT::TMetaUtils::GetNameWithinNamespace(fullname, clsname, nsname, clxx)) {
enclSpaceNesting = ROOT::TMetaUtils::WriteNamespaceHeader(dictStream, cl);
}
clsname = TClassEdit::InsertStd(clsname.c_str());

dictStream << "//_______________________________________"
<< "_______________________________________" << std::endl;
if (add_template_keyword) dictStream << "template <> ";
dictStream << "void " << clsname << "::Streamer(TBuffer &R__b)" << std::endl
<< "{" << std::endl
<< " // Stream an object of class " << fullname << "." << std::endl << std::endl
<< " // Stream an object of class " << fullname << "." << std::endl
<< std::endl
<< " if (R__b.IsReading()) {" << std::endl
<< " R__b.ReadClassBuffer(" << fullname << "::Class(),this);" << std::endl
<< " R__b.ReadClassBuffer(" << clsname << "::Class(),this);" << std::endl
<< " } else {" << std::endl
<< " R__b.WriteClassBuffer(" << fullname << "::Class(),this);" << std::endl
<< " R__b.WriteClassBuffer(" << clsname << "::Class(),this);" << std::endl
<< " }" << std::endl
<< "}" << std::endl << std::endl;
<< "}" << std::endl
<< std::endl;

while (enclSpaceNesting) {
dictStream << "} // namespace " << nsname << std::endl;
Expand Down Expand Up @@ -2821,14 +2839,15 @@ void CreateDictHeader(std::ostream &dictStream, const std::string &main_dictname
<< "#include \"TCollectionProxyInfo.h\"\n"
<< "/*******************************************************************/\n\n"
<< "#include \"TDataMember.h\"\n\n"; // To set their transiency

if (main_dictname.length() > 11 && main_dictname.substr(main_dictname.length() - 11) == "_ACLiC_dict")
dictStream << ROOT::TMetaUtils::GetInjectedUsingDecls();
}

////////////////////////////////////////////////////////////////////////////////

void AddNamespaceSTDdeclaration(std::ostream &dictStream)
void AddNamespaceSTDdeclaration(std::ostream & dictStream)
{
dictStream << "// The generated code does not explicitly qualify STL entities\n"
<< "namespace std {} using namespace std;\n\n";
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -4436,8 +4455,24 @@ int RootClingMain(int argc,
// ROOTCINT uses to define a few header implicitly, we need to do it explicitly.
if (interp.declare("#include <assert.h>\n"
"#include \"Rtypes.h\"\n"
"#include \"TObject.h\"") != cling::Interpreter::kSuccess
) {
"#include \"TObject.h\"\n"
"#include <bitset>\n"
"#include <forward_list>\n"
"#include <list>\n"
"#include <map>\n"
"#include <memory>\n"
"#include <set>\n"
"#include <string>\n"
"#include <unordered_map>\n"
"#include <unordered_set>\n"
"#include <utility>\n"
"#include <vector>\n"
"using std::allocator; using std::bitset; using std::default_delete; using "
"std::forward_list; using std::list; using std::map; using std::multimap; using "
"std::multiset; using std::pair; using std::set; using std::shared_ptr; using std::string; "
"using std::unique_ptr; using std::unordered_multimap; using std::unordered_map; using "
"std::unordered_multiset; using std::unordered_set; using std::vector;") !=
cling::Interpreter::kSuccess) {
// There was an error.
ROOT::TMetaUtils::Error(nullptr, "Error loading the default rootcling header files.\n");
return 1;
Expand All @@ -4446,7 +4481,7 @@ int RootClingMain(int argc,

if (interp.declare("#include <string>\n" // For the list of 'opaque' typedef to also include string.
"#include <RtypesCore.h>\n" // For initializing TNormalizedCtxt.
"namespace std {} using namespace std;") != cling::Interpreter::kSuccess) {
) != cling::Interpreter::kSuccess) {
ROOT::TMetaUtils::Error(nullptr, "Error loading the default header files.\n");
return 1;
}
Expand Down Expand Up @@ -4635,8 +4670,6 @@ int RootClingMain(int argc,
}

std::ostream &dictStream = (!gOptIgnoreExistingDict && !gOptDictionaryFileName.empty()) ? fileout : std::cout;
bool isACLiC = gOptDictionaryFileName.getValue().find("_ACLiC_dict") != std::string::npos;

if (!gOptIgnoreExistingDict) {
// Now generate a second stream for the split dictionary if it is necessary
if (gOptSplit) {
Expand All @@ -4657,16 +4690,6 @@ int RootClingMain(int argc,
CreateDictHeader(dictStream, main_dictname);
if (gOptSplit)
CreateDictHeader(*splitDictStream, main_dictname);

if (!gOptNoGlobalUsingStd) {
// ACLiC'ed macros might rely on `using namespace std` in front of user headers
if (isACLiC) {
AddNamespaceSTDdeclaration(dictStream);
if (gOptSplit) {
AddNamespaceSTDdeclaration(*splitDictStream);
}
}
}
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -4884,15 +4907,6 @@ int RootClingMain(int argc,
GenerateNecessaryIncludes(*splitDictStream, includeForSource, extraIncludes);
}
}
if (!gOptNoGlobalUsingStd) {
// ACLiC'ed macros might have relied on `using namespace std` in front of user headers
if (!isACLiC) {
AddNamespaceSTDdeclaration(dictStream);
if (gOptSplit) {
AddNamespaceSTDdeclaration(*splitDictStream);
}
}
}
if (gDriverConfig->fInitializeStreamerInfoROOTFile) {
gDriverConfig->fInitializeStreamerInfoROOTFile(modGen.GetModuleFileName().c_str());
}
Expand All @@ -4906,13 +4920,6 @@ int RootClingMain(int argc,
constructorTypes.emplace_back("", interp);
}
}
if (!gOptIgnoreExistingDict && gOptNoGlobalUsingStd) {
AddNamespaceSTDdeclaration(dictStream);

if (gOptSplit && splitDictStream) {
AddNamespaceSTDdeclaration(*splitDictStream);
}
}

if (gOptGeneratePCH) {
AnnotateAllDeclsForPCH(interp, scan);
Expand Down
Loading