12#include "rootclingCommandLineOptionsHelp.h"
14#include "RConfigure.h"
33#include <unordered_map>
34#include <unordered_set>
46#define PATH_MAX _MAX_PATH
54#include <mach-o/dyld.h>
63#include "cling/Interpreter/Interpreter.h"
64#include "cling/Interpreter/InterpreterCallbacks.h"
65#include "cling/Interpreter/LookupHelper.h"
66#include "cling/Interpreter/Value.h"
67#include "clang/AST/CXXInheritance.h"
68#include "clang/Basic/Diagnostic.h"
69#include "clang/Frontend/CompilerInstance.h"
70#include "clang/Frontend/FrontendActions.h"
71#include "clang/Frontend/FrontendDiagnostic.h"
72#include "clang/Lex/HeaderSearch.h"
73#include "clang/Lex/Preprocessor.h"
74#include "clang/Lex/ModuleMap.h"
75#include "clang/Lex/Pragma.h"
76#include "clang/Sema/Sema.h"
77#include "clang/Serialization/ASTWriter.h"
78#include "cling/Utils/AST.h"
80#include "llvm/ADT/StringRef.h"
82#include "llvm/Support/CommandLine.h"
83#include "llvm/Support/Path.h"
84#include "llvm/Support/PrettyStackTrace.h"
85#include "llvm/Support/Signals.h"
109#include <mach-o/dyld.h>
114#define strcasecmp _stricmp
115#define strncasecmp _strnicmp
123#define rootclingStringify(s) rootclingStringifyx(s)
124#define rootclingStringifyx(s) #s
143static llvm::cl::opt<bool>
145 llvm::cl::desc(
"Deprecated. Similar to -f but it ignores the dictionary generation. \
146When -r is present rootcling becomes a tool to generate rootmaps (and capability files)."),
166static void EmitTypedefs(
const std::vector<const clang::TypedefNameDecl *> &tdvec)
170 for (
const auto td : tdvec)
173static void EmitEnums(
const std::vector<const clang::EnumDecl *> &enumvec)
177 for (
const auto en : enumvec) {
179 if (clang::isa<clang::TranslationUnitDecl>(en->getDeclContext())
180 || clang::isa<clang::LinkageSpecDecl>(en->getDeclContext())
181 || clang::isa<clang::NamespaceDecl>(en->getDeclContext()))
191 static std::string exepath;
194 exepath = _dyld_get_image_name(0);
196#if defined(__linux) || defined(__linux__)
197 char linkname[PATH_MAX];
203 snprintf(linkname, PATH_MAX,
"/proc/%i/exe", pid);
204 int ret = readlink(linkname, buf, 1024);
205 if (ret > 0 && ret < 1024) {
211 char *buf =
new char[MAX_MODULE_NAME32 + 1];
214 while ((
p = strchr(
p,
'\\')))
220 return exepath.c_str();
226 const cling::Interpreter &interp)
234 const std::list<VariableSelectionRule> &fieldSelRules)
242 if (fieldSelRules.empty())
return;
244 clang::ASTContext &
C = decl.getASTContext();
246 const std::string declName(decl.getNameAsString());
248 for (std::list<VariableSelectionRule>::const_iterator it = fieldSelRules.begin();
249 it != fieldSelRules.end(); ++it) {
251 if (declName == varName) {
254 BaseSelectionRule::AttributesMap_t::iterator iter;
255 std::string userDefinedProperty;
256 for (iter = attrMap.begin(); iter != attrMap.end(); ++iter) {
257 const std::string &
name = iter->first;
258 const std::string &
value = iter->second;
266 (decl.getType()->isArrayType() || decl.getType()->isPointerType())) {
267 const char *msg =
"Data member \"%s\" is an array or a pointer. "
268 "It is not possible to assign to it the iotype \"%s\". "
269 "This transformation is possible only with data members "
270 "which are not pointers or arrays.\n";
272 msg, varName.c_str(),
value.c_str());
281 decl.addAttr(clang::AnnotateAttr::CreateImplicit(
C,
value));
291 decl.addAttr(clang::AnnotateAttr::CreateImplicit(
C,
"!"));
299 decl.addAttr(clang::AnnotateAttr::CreateImplicit(
C, userDefinedProperty));
310 cling::Interpreter &interpreter,
318 using namespace clang;
319 SourceLocation commentSLoc;
322 ASTContext &
C = CXXRD.getASTContext();
325 clang::Decl *declBaseClassPtr =
static_cast<clang::Decl *
>(&CXXRD);
326 auto declSelRulePair = declSelRulesMap.find(declBaseClassPtr->getCanonicalDecl());
327 if (declSelRulePair == declSelRulesMap.end()){
328 const std::string thisClassName(CXXRD.getName());
329 ROOT::TMetaUtils::Error(
"AnnotateDecl",
"Cannot find class %s in the list of selected classes.\n",thisClassName.c_str());
334 if (thisClassBaseSelectionRule) {
337 BaseSelectionRule::AttributesMap_t::iterator iter;
338 std::string userDefinedProperty;
340 const std::string &
name =
attr.first;
345 CXXRD.addAttr(AnnotateAttr::CreateImplicit(
C, userDefinedProperty));
352 for (CXXRecordDecl::decl_iterator
I = CXXRD.decls_begin(),
353 E = CXXRD.decls_end();
I !=
E; ++
I) {
357 if (!(*I)->isImplicit()
358 && (isa<CXXMethodDecl>(*
I) || isa<FieldDecl>(*
I) || isa<VarDecl>(*
I))) {
362 if (isClassDefMacro) {
363 while (isa<NamedDecl>(*
I) && cast<NamedDecl>(*I)->getName() !=
"DeclFileLine") {
371 if (isClassDefMacro) {
372 CXXRD.addAttr(AnnotateAttr::CreateImplicit(
C,
comment.str()));
373 }
else if (!isGenreflex) {
379 (*I)->addAttr(AnnotateAttr::CreateImplicit(
C,
comment.str()));
384 if (isGenreflex && thisClassSelectionRule !=
nullptr) {
388 if (FieldDecl *fieldDecl = dyn_cast<FieldDecl>(*
I)) {
402 llvm::APInt
len = arrayType->getSize();
403 while (
const clang::ConstantArrayType *subArrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual())) {
404 len *= subArrayType->getSize();
405 arrayType = subArrayType;
407 return len.getLimitedValue();
413 const cling::Interpreter &interp)
415 static const clang::CXXRecordDecl *TObject_decl
418 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
425 const cling::Interpreter &interp)
427 static const clang::CXXRecordDecl *TObject_decl
440 return (0 == strcasecmp(
filename + (
len - xmllen),
".xml"));
466 if (exepath && *exepath) {
468 char *ep =
new char[PATH_MAX];
469 if (!realpath(exepath, ep)) {
470 fprintf(stderr,
"rootcling: error getting realpath of rootcling!");
471 strlcpy(ep, exepath, PATH_MAX);
474 int nche = strlen(exepath) + 1;
475 char *ep =
new char[nche];
476 strlcpy(ep, exepath, nche);
480 if ((
s = strrchr(ep,
'/'))) {
482 int removesubdirs = 2;
483 if (!strncmp(
s + 1,
"rootcling_stage1.exe", 20)) {
487 }
else if (!strncmp(
s + 1,
"rootcling_stage1", 16)) {
492 for (
int i = 1;
s && i < removesubdirs; ++i) {
494 s = strrchr(ep,
'/');
508 int ncha = strlen(ep) + 10;
509 char *env =
new char[ncha];
510 snprintf(env, ncha,
"ROOTSYS=%s", ep);
531 const char *expectedTokens[],
532 size_t *end =
nullptr)
535 if (
line[0] !=
'#')
return false;
537 for (
const char **iToken = expectedTokens; *iToken; ++iToken) {
538 while (isspace(
line[pos])) ++pos;
539 size_t lenToken = strlen(*iToken);
540 if (
line.compare(pos, lenToken, *iToken)) {
559 if (recordDecl->hasOwningModule()) {
560 clang::Module *M = recordDecl->getOwningModule()->getTopLevelModule();
563 std::string qual_name;
569 if (need.length() &&
gLibsNeeded.find(need) == string::npos) {
578 if (classname.find(
':') == std::string::npos)
return;
581 int slen = classname.size();
582 for (
int k = 0; k < slen; ++k) {
583 if (classname[k] ==
':') {
584 if (k + 1 >= slen || classname[k + 1] !=
':') {
589 string base = classname.substr(0, k);
594 autoloads[base] =
"";
598 }
else if (classname[k] ==
'<') {
610 std::string classname;
614 if (
line.find(
"Library.") != 0)
continue;
616 int pos =
line.find(
":", 8);
617 classname =
line.substr(8, pos - 8);
623 while (
line[0] ==
' ')
line.replace(0, 1,
"");
627 if (classname ==
"ROOT::TImpProxy") {
631 autoloads[classname] =
line;
646 const std::unordered_map<char, unsigned int> keyLenMap = {{
'c', 6}, {
'n', 10}, {
't', 8}};
649 if (
line ==
"{ decls }") {
651 if (
line[0] ==
'[')
break;
654 const char firstChar =
line[0];
655 if (firstChar ==
'[') {
657 libs =
line.substr(1,
line.find(
']') - 1);
658 while (libs[0] ==
' ') libs.replace(0, 1,
"");
659 }
else if (0 != keyLenMap.count(firstChar)) {
660 unsigned int keyLen = keyLenMap.at(firstChar);
661 keyname =
line.substr(keyLen,
line.length() - keyLen);
663 autoloads[keyname] = libs;
673void LoadLibraryMap(
const std::string &fileListName, map<string, string> &autoloads)
675 std::ifstream filelist(fileListName.c_str());
682 if (llvm::sys::fs::is_directory(
filename))
continue;
688 bool new_format = (
line[0] ==
'[' ||
line[0] ==
'{') ;
690 file.seekg(0, std::ios::beg);
711 const string &fullname,
712 const clang::RecordDecl *cl,
713 cling::Interpreter &interp)
716 const clang::FunctionDecl *method
721 clang::TranslationUnitDecl *TU =
722 cl->getASTContext().getTranslationUnitDecl();
726 bool has_input_error =
false;
727 if (method !=
nullptr && (method->getAccess() == clang::AS_public || method->getAccess() == clang::AS_none)) {
729 if (strstr(
filename.c_str(),
"TBuffer.h") !=
nullptr ||
730 strstr(
filename.c_str(),
"Rtypes.h") !=
nullptr) {
732 has_input_error =
true;
735 has_input_error =
true;
737 if (has_input_error) {
739 const char *maybeconst =
"";
740 const char *mayberef =
"&";
741 if (
what[strlen(
what) - 1] ==
'<') {
742 maybeconst =
"const ";
746 "in this version of ROOT, the option '!' used in a linkdef file\n"
747 " implies the actual existence of customized operators.\n"
748 " The following declaration is now required:\n"
749 " TBuffer &%s(TBuffer &,%s%s *%s);\n",
what, maybeconst, fullname.c_str(), mayberef);
751 return has_input_error;
763 int ncha = fullname.length() + 13;
764 char *
proto =
new char[ncha];
776 return has_input_error;
782bool CheckClassDef(
const clang::RecordDecl &cl,
const cling::Interpreter &interp)
788 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(&cl);
792 bool isAbstract = clxx->isAbstract();
795 std::string qualName;
797 const char *qualName_c = qualName.c_str();
799 "because it inherits from TObject but does not "
800 "have its own ClassDef.\n",
813 if (
m.getType().isConstQualified()) {
814 string ret =
"const_cast< ";
817 if (type_name.substr(0,6)==
"const ") {
818 ret += type_name.c_str()+6;
824 ret +=
m.getName().str();
828 return prefix +
m.getName().str();
838 const cling::Interpreter &interp,
840 std::ostream &dictStream)
843 std::string mTypename;
856 if (!clxx || clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return 0;
858 const clang::ClassTemplateSpecializationDecl *tmplt_specialization = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl> (clxx);
859 if (!tmplt_specialization)
return 0;
865 string fulName1, fulName2;
866 const char *tcl1 =
nullptr, *tcl2 =
nullptr;
867 const clang::TemplateArgument &arg0(tmplt_specialization->getTemplateArgs().get(0));
868 clang::QualType ti = arg0.getAsType();
872 fulName1 = ti.getAsString();
875 const clang::TemplateArgument &arg1(tmplt_specialization->getTemplateArgs().get(1));
876 clang::QualType tmplti = arg1.getAsType();
879 fulName2 = tmplti.getAsString();
886 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
m.getType().getTypePtr());
892 if (arrayType->getArrayElementTypeNoTypeQual()->isPointerType()) {
896 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual());
898 }
else if (
m.getType()->isPointerType()) {
903 dictStream <<
" {" << std::endl;
905 dictStream <<
" for (Int_t R__l = 0; R__l < " <<
len <<
"; R__l++) {" << std::endl;
910 dictStream <<
" " << stlType.c_str() <<
" &R__stl = " << stlName.c_str() <<
";" << std::endl;
913 dictStream <<
" " << stlType.c_str() <<
" &R__stl = " << stlName.c_str() <<
"[R__l];" << std::endl;
916 dictStream <<
" delete *" << stlName.c_str() <<
";" << std::endl
917 <<
" *" << stlName.c_str() <<
" = new " << stlType.c_str() <<
";" << std::endl
918 <<
" " << stlType.c_str() <<
" &R__stl = **" << stlName.c_str() <<
";" << std::endl;
921 dictStream <<
" delete " << stlName.c_str() <<
"[R__l];" << std::endl
922 <<
" " << stlName.c_str() <<
"[R__l] = new " << stlType.c_str() <<
";" << std::endl
923 <<
" " << stlType.c_str() <<
" &R__stl = *" << stlName.c_str() <<
"[R__l];" << std::endl;
927 dictStream <<
" R__stl.clear();" << std::endl;
930 dictStream <<
" TClass *R__tcl1 = TBuffer::GetClass(typeid(" << fulName1.c_str() <<
"));" << std::endl
931 <<
" if (R__tcl1==0) {" << std::endl
932 <<
" Error(\"" << stlName.c_str() <<
" streamer\",\"Missing the TClass object for "
933 << fulName1.c_str() <<
"!\");" << std::endl
934 <<
" return;" << std::endl
935 <<
" }" << std::endl;
938 dictStream <<
" TClass *R__tcl2 = TBuffer::GetClass(typeid(" << fulName2.c_str() <<
"));" << std::endl
939 <<
" if (R__tcl2==0) {" << std::endl
940 <<
" Error(\"" << stlName.c_str() <<
" streamer\",\"Missing the TClass object for "
941 << fulName2.c_str() <<
"!\");" << std::endl
942 <<
" return;" << std::endl
943 <<
" }" << std::endl;
946 dictStream <<
" int R__i, R__n;" << std::endl
947 <<
" R__b >> R__n;" << std::endl;
950 dictStream <<
" R__stl.reserve(R__n);" << std::endl;
952 dictStream <<
" for (R__i = 0; R__i < R__n; R__i++) {" << std::endl;
956 const clang::TemplateArgument &arg1(tmplt_specialization->getTemplateArgs().get(1));
976 std::string keyName(ti.getAsString());
977 dictStream <<
" typedef " << keyName <<
" Value_t;" << std::endl
978 <<
" std::pair<Value_t const, " << tmplt_specialization->getTemplateArgs().get(1).getAsType().getAsString() <<
" > R__t3(R__t,R__t2);" << std::endl
979 <<
" R__stl.insert(R__t3);" << std::endl;
987 dictStream <<
" R__stl.insert(R__t);" << std::endl;
992 dictStream <<
" R__stl.push_back(R__t);" << std::endl;
995 dictStream <<
" R__stl.push_front(R__t);" << std::endl;
1000 dictStream <<
" }" << std::endl
1001 <<
" }" << std::endl;
1002 if (isArr) dictStream <<
" }" << std::endl;
1008 dictStream <<
" for (Int_t R__l = 0; R__l < " <<
len <<
"; R__l++) {" << std::endl;
1010 dictStream <<
" {" << std::endl;
1013 dictStream <<
" " << stlType.c_str() <<
" &R__stl = " << stlName.c_str() <<
";" << std::endl;
1016 dictStream <<
" " << stlType.c_str() <<
" &R__stl = " << stlName.c_str() <<
"[R__l];" << std::endl;
1019 dictStream <<
" " << stlType.c_str() <<
" &R__stl = **" << stlName.c_str() <<
";" << std::endl;
1022 dictStream <<
" " << stlType.c_str() <<
" &R__stl = *" << stlName.c_str() <<
"[R__l];" << std::endl;
1026 dictStream <<
" int R__n=int(R__stl.size());" << std::endl
1027 <<
" R__b << R__n;" << std::endl
1028 <<
" if(R__n) {" << std::endl;
1031 dictStream <<
" TClass *R__tcl1 = TBuffer::GetClass(typeid(" << fulName1.c_str() <<
"));" << std::endl
1032 <<
" if (R__tcl1==0) {" << std::endl
1033 <<
" Error(\"" << stlName.c_str() <<
" streamer\",\"Missing the TClass object for "
1034 << fulName1.c_str() <<
"!\");" << std::endl
1035 <<
" return;" << std::endl
1036 <<
" }" << std::endl;
1039 dictStream <<
" TClass *R__tcl2 = TBuffer::GetClass(typeid(" << fulName2.c_str() <<
"));" << std::endl
1040 <<
" if (R__tcl2==0) {" << std::endl
1041 <<
" Error(\"" << stlName.c_str() <<
"streamer\",\"Missing the TClass object for " << fulName2.c_str() <<
"!\");" << std::endl
1042 <<
" return;" << std::endl
1043 <<
" }" << std::endl;
1046 dictStream <<
" " << stlType.c_str() <<
"::iterator R__k;" << std::endl
1047 <<
" for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {" << std::endl;
1049 const clang::TemplateArgument &arg1(tmplt_specialization->getTemplateArgs().get(1));
1050 clang::QualType tmplti = arg1.getAsType();
1057 dictStream <<
" }" << std::endl
1058 <<
" }" << std::endl
1059 <<
" }" << std::endl;
1060 if (isArr) dictStream <<
" }" << std::endl;
1072 std::string mTypenameStr;
1076 if (!strcmp(mTypeName,
"string")) {
1078 std::string fieldname =
m.getName().str();
1081 if (
m.getType()->isConstantArrayType()) {
1082 if (
m.getType().getTypePtr()->getArrayElementTypeNoTypeQual()->isPointerType()) {
1083 dictStream <<
"// Array of pointer to std::string are not supported (" << fieldname <<
"\n";
1085 std::stringstream fullIdx;
1086 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
m.getType().getTypePtr());
1089 dictStream <<
" for (int R__i" << dim <<
"=0; R__i" << dim <<
"<"
1090 << arrayType->getSize().getLimitedValue() <<
"; ++R__i" << dim <<
" )" << std::endl;
1091 fullIdx <<
"[R__i" << dim <<
"]";
1092 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual());
1095 dictStream <<
" { TString R__str; R__str.Streamer(R__b); "
1096 << fieldname << fullIdx.str() <<
" = R__str.Data();}" << std::endl;
1099 dictStream <<
" { TString R__str; R__str.Streamer(R__b); ";
1100 if (
m.getType()->isPointerType())
1101 dictStream <<
"if (*" << fieldname <<
") delete *" << fieldname <<
"; (*"
1102 << fieldname <<
" = new string(R__str.Data())); }" << std::endl;
1104 dictStream << fieldname <<
" = R__str.Data(); }" << std::endl;
1108 if (
m.getType()->isPointerType())
1109 dictStream <<
" { TString R__str; if (*" << fieldname <<
") R__str = (*"
1110 << fieldname <<
")->c_str(); R__str.Streamer(R__b);}" << std::endl;
1111 else if (
m.getType()->isConstantArrayType()) {
1112 std::stringstream fullIdx;
1113 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
m.getType().getTypePtr());
1116 dictStream <<
" for (int R__i" << dim <<
"=0; R__i" << dim <<
"<"
1117 << arrayType->getSize().getLimitedValue() <<
"; ++R__i" << dim <<
" )" << std::endl;
1118 fullIdx <<
"[R__i" << dim <<
"]";
1119 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual());
1122 dictStream <<
" { TString R__str(" << fieldname << fullIdx.str() <<
".c_str()); R__str.Streamer(R__b);}" << std::endl;
1124 dictStream <<
" { TString R__str = " << fieldname <<
".c_str(); R__str.Streamer(R__b);}" << std::endl;
1135 if (
m.getType()->isPointerType()) {
1136 if (
m.getType()->getPointeeType()->isPointerType()) {
1148 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
type.getTypePtr());
1150 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual());
1152 dictStream <<
"[0]";
1153 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual());
1168 int enclSpaceNesting = 0;
1175 dictStream <<
"#include \"TInterpreter.h\"\n";
1177 dictStream <<
"//_______________________________________"
1178 <<
"_______________________________________" << std::endl;
1179 if (add_template_keyword) dictStream <<
"template <> ";
1180 dictStream <<
"atomic_TClass_ptr " << clsname <<
"::fgIsA(nullptr); // static to hold class pointer" << std::endl
1183 <<
"//_______________________________________"
1184 <<
"_______________________________________" << std::endl;
1185 if (add_template_keyword) dictStream <<
"template <> ";
1186 dictStream <<
"const char *" << clsname <<
"::Class_Name()" << std::endl <<
"{" << std::endl
1187 <<
" return \"" << fullname <<
"\";" << std::endl <<
"}" << std::endl << std::endl;
1189 dictStream <<
"//_______________________________________"
1190 <<
"_______________________________________" << std::endl;
1191 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
1196 <<
"//_______________________________________"
1197 <<
"_______________________________________" << std::endl;
1198 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
1203 <<
"//_______________________________________"
1204 <<
"_______________________________________" << std::endl;
1205 if (add_template_keyword) dictStream <<
"template <> ";
1206 dictStream <<
"TClass *" << clsname <<
"::Dictionary()" << std::endl <<
"{" << std::endl;
1210 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
1216 <<
"//_______________________________________"
1217 <<
"_______________________________________" << std::endl;
1218 if (add_template_keyword) dictStream <<
"template <> ";
1219 dictStream <<
"TClass *" << clsname <<
"::Class()" << std::endl <<
"{" << std::endl;
1221 dictStream <<
" Dictionary();\n";
1223 dictStream <<
" if (!fgIsA.load()) { R__LOCKGUARD(gInterpreterMutex); fgIsA = ::ROOT::GenerateInitInstanceLocal((const ::";
1224 dictStream << fullname <<
"*)nullptr)->GetClass(); }" << std::endl;
1226 dictStream <<
" return fgIsA;" << std::endl
1227 <<
"}" << std::endl << std::endl;
1229 while (enclSpaceNesting) {
1230 dictStream <<
"} // namespace " << nsname << std::endl;
1239 cling::Interpreter &interp,
1240 std::ostream &dictStream)
1242 if (cl->isAnonymousNamespace()) {
1254 if (classname !=
"ROOT") {
1258 dictStream <<
" namespace ROOTDict {" << std::endl;
1261 dictStream <<
" inline ::ROOT::TGenericClassInfo *GenerateInitInstance();" << std::endl;
1265 dictStream <<
" static TClass *" << mappedname.c_str() <<
"_Dictionary();" << std::endl;
1266 dictStream << std::endl
1268 <<
" // Function generating the singleton type initializer" << std::endl
1271 <<
" inline ::ROOT::TGenericClassInfo *GenerateInitInstance()" << std::endl
1272 <<
" {" << std::endl
1274 <<
" ::ROOT::TGenericClassInfo *GenerateInitInstance()" << std::endl
1275 <<
" {" << std::endl
1278 <<
" static ::ROOT::TGenericClassInfo " << std::endl
1280 <<
" instance(\"" << classname.c_str() <<
"\", ";
1283 dictStream <<
"::" << classname.c_str() <<
"::Class_Version(), ";
1285 dictStream <<
"0 /*version*/, ";
1289 for (
unsigned int i = 0; i <
filename.length(); i++) {
1293 <<
" ::ROOT::Internal::DefineBehavior((void*)nullptr,(void*)nullptr)," << std::endl
1297 dictStream <<
"&::" << classname.c_str() <<
"::Dictionary, ";
1299 dictStream <<
"&" << mappedname.c_str() <<
"_Dictionary, ";
1302 dictStream << 0 <<
");" << std::endl
1304 <<
" return &instance;" << std::endl
1305 <<
" }" << std::endl
1306 <<
" // Insure that the inline function is _not_ optimized away by the compiler\n"
1307 <<
" ::ROOT::TGenericClassInfo *(*_R__UNIQUE_DICT_(InitFunctionKeeper))() = &GenerateInitInstance; " << std::endl
1308 <<
" // Static variable to force the class initialization" << std::endl
1310 <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstance();"
1311 <<
" R__UseDummy(_R__UNIQUE_DICT_(Init));" << std::endl;
1314 dictStream << std::endl <<
" // Dictionary for non-ClassDef classes" << std::endl
1315 <<
" static TClass *" << mappedname.c_str() <<
"_Dictionary() {" << std::endl
1316 <<
" return GenerateInitInstance()->GetClass();" << std::endl
1317 <<
" }" << std::endl << std::endl;
1320 dictStream <<
" }" << std::endl;
1322 dictStream <<
"}" << std::endl;
1324 dictStream << std::endl;
1333llvm::StringRef
GrabIndex(
const cling::Interpreter& interp,
const clang::FieldDecl &member,
int printError)
1336 llvm::StringRef where;
1339 if (
index.size() == 0 && printError) {
1340 const char *errorstring;
1343 errorstring =
"is not an integer";
1346 errorstring =
"has not been defined before the array";
1349 errorstring =
"is a private member of a parent class";
1352 errorstring =
"is not known";
1355 errorstring =
"UNKNOWN ERROR!!!!";
1358 if (where.size() == 0) {
1360 member.getParent()->getName().str().c_str(), member.getName().str().c_str());
1363 member.getParent()->getName().str().c_str(), member.getName().str().c_str(), where.str().c_str(), errorstring);
1372 const cling::Interpreter &interp,
1374 std::ostream &dictStream)
1376 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1377 if (clxx ==
nullptr)
return;
1384 int enclSpaceNesting = 0;
1390 dictStream <<
"//_______________________________________"
1391 <<
"_______________________________________" << std::endl;
1392 if (add_template_keyword) dictStream <<
"template <> ";
1393 dictStream <<
"void " << clsname <<
"::Streamer(TBuffer &R__b)" << std::endl <<
"{" << std::endl
1394 <<
" // Stream an object of class " << fullname <<
"." << std::endl << std::endl;
1402 int basestreamer = 0;
1403 for (clang::CXXRecordDecl::base_class_const_iterator iter = clxx->bases_begin(), end = clxx->bases_end();
1407 string base_fullname;
1410 if (strstr(base_fullname.c_str(),
"::")) {
1412 dictStream <<
" //This works around a msvc bug and should be harmless on other platforms" << std::endl
1413 <<
" typedef " << base_fullname <<
" baseClass" << basestreamer <<
";" << std::endl
1414 <<
" baseClass" << basestreamer <<
"::Streamer(R__b);" << std::endl;
1416 dictStream <<
" " << base_fullname <<
"::Streamer(R__b);" << std::endl;
1421 if (!basestreamer) {
1422 dictStream <<
" ::Error(\"" << fullname <<
"::Streamer\", \"version id <=0 in ClassDef,"
1423 " dummy Streamer() called\"); if (R__b.IsReading()) { }" << std::endl;
1425 dictStream <<
"}" << std::endl << std::endl;
1426 while (enclSpaceNesting) {
1427 dictStream <<
"} // namespace " << nsname.c_str() << std::endl;
1434 string classname = fullname;
1435 if (strstr(fullname.c_str(),
"::")) {
1437 dictStream <<
" //This works around a msvc bug and should be harmless on other platforms" << std::endl
1438 <<
" typedef ::" << fullname <<
" thisClass;" << std::endl;
1439 classname =
"thisClass";
1441 for (
int i = 0; i < 2; i++) {
1446 dictStream <<
" UInt_t R__s, R__c;" << std::endl;
1447 dictStream <<
" if (R__b.IsReading()) {" << std::endl;
1448 dictStream <<
" Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }" << std::endl;
1450 dictStream <<
" R__b.CheckByteCount(R__s, R__c, " << classname.c_str() <<
"::IsA());" << std::endl;
1451 dictStream <<
" } else {" << std::endl;
1452 dictStream <<
" R__c = R__b.WriteVersion(" << classname.c_str() <<
"::IsA(), kTRUE);" << std::endl;
1457 for (clang::CXXRecordDecl::base_class_const_iterator iter = clxx->bases_begin(), end = clxx->bases_end();
1461 string base_fullname;
1464 if (strstr(base_fullname.c_str(),
"::")) {
1466 dictStream <<
" //This works around a msvc bug and should be harmless on other platforms" << std::endl
1467 <<
" typedef " << base_fullname <<
" baseClass" << base <<
";" << std::endl
1468 <<
" baseClass" << base <<
"::Streamer(R__b);" << std::endl;
1471 dictStream <<
" " << base_fullname <<
"::Streamer(R__b);" << std::endl;
1477 for (clang::RecordDecl::field_iterator field_iter = clxx->field_begin(), end = clxx->field_end();
1482 clang::QualType
type = field_iter->getType();
1483 std::string type_name =
type.getAsString(clxx->getASTContext().getPrintingPolicy());
1493 if (strstr(type_name.c_str(),
"Float16_t")) isFloat16 = 1;
1497 if (strstr(type_name.c_str(),
"Double32_t")) isDouble32 = 1;
1500 if (strncmp(
comment,
"!", 1)) {
1503 if (underling_type->isFundamentalType() || underling_type->isEnumeralType()) {
1504 if (
type.getTypePtr()->isConstantArrayType() &&
1505 type.getTypePtr()->getArrayElementTypeNoTypeQual()->isPointerType()) {
1506 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
type.getTypePtr());
1510 dictStream <<
" int R__i;" << std::endl;
1513 dictStream <<
" for (R__i = 0; R__i < " <<
s <<
"; R__i++)" << std::endl;
1515 ROOT::TMetaUtils::Error(
nullptr,
"*** Datamember %s::%s: array of pointers to fundamental type (need manual intervention)\n", fullname.c_str(), field_iter->getName().str().c_str());
1516 dictStream <<
" ;//R__b.ReadArray(" << field_iter->getName().str() <<
");" << std::endl;
1518 dictStream <<
" ;//R__b.WriteArray(" << field_iter->getName().str() <<
", __COUNTER__);" << std::endl;
1520 }
else if (
type.getTypePtr()->isPointerType()) {
1521 llvm::StringRef indexvar =
GrabIndex(interp, **field_iter, i == 0);
1522 if (indexvar.size() == 0) {
1524 ROOT::TMetaUtils::Error(
nullptr,
"*** Datamember %s::%s: pointer to fundamental type (need manual intervention)\n", fullname.c_str(), field_iter->getName().str().c_str());
1525 dictStream <<
" //R__b.ReadArray(" << field_iter->getName().str() <<
");" << std::endl;
1527 dictStream <<
" //R__b.WriteArray(" << field_iter->getName().str() <<
", __COUNTER__);" << std::endl;
1531 dictStream <<
" delete [] " << field_iter->getName().str() <<
";" << std::endl
1536 <<
"," << indexvar.str() <<
");" << std::endl;
1537 }
else if (isDouble32) {
1539 <<
"," << indexvar.str() <<
");" << std::endl;
1542 <<
"," << indexvar.str() <<
");" << std::endl;
1546 dictStream <<
" R__b.WriteFastArrayFloat16("
1547 << field_iter->getName().str() <<
"," << indexvar.str() <<
");" << std::endl;
1548 }
else if (isDouble32) {
1549 dictStream <<
" R__b.WriteFastArrayDouble32("
1550 << field_iter->getName().str() <<
"," << indexvar.str() <<
");" << std::endl;
1552 dictStream <<
" R__b.WriteFastArray("
1553 << field_iter->getName().str() <<
"," << indexvar.str() <<
");" << std::endl;
1557 }
else if (
type.getTypePtr()->isArrayType()) {
1559 if (
type.getTypePtr()->getArrayElementTypeNoTypeQual()->isArrayType()) {
1560 if (underling_type->isEnumeralType())
1561 dictStream <<
" R__b.ReadStaticArray((Int_t*)" << field_iter->getName().str() <<
");" << std::endl;
1565 <<
"*)" << field_iter->getName().str() <<
");" << std::endl;
1566 }
else if (isDouble32) {
1568 <<
"*)" << field_iter->getName().str() <<
");" << std::endl;
1571 <<
"*)" << field_iter->getName().str() <<
");" << std::endl;
1575 if (underling_type->isEnumeralType()) {
1576 dictStream <<
" R__b.ReadStaticArray((Int_t*)" << field_iter->getName().str() <<
");" << std::endl;
1579 dictStream <<
" R__b.ReadStaticArrayFloat16(" << field_iter->getName().str() <<
");" << std::endl;
1580 }
else if (isDouble32) {
1581 dictStream <<
" R__b.ReadStaticArrayDouble32(" << field_iter->getName().str() <<
");" << std::endl;
1584 <<
"*)" << field_iter->getName().str() <<
");" << std::endl;
1589 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
type.getTypePtr());
1592 if (
type.getTypePtr()->getArrayElementTypeNoTypeQual()->isArrayType()) {
1593 if (underling_type->isEnumeralType())
1594 dictStream <<
" R__b.WriteArray((Int_t*)" << field_iter->getName().str() <<
", "
1595 <<
s <<
");" << std::endl;
1596 else if (isFloat16) {
1598 <<
"*)" << field_iter->getName().str() <<
", " <<
s <<
");" << std::endl;
1599 }
else if (isDouble32) {
1601 <<
"*)" << field_iter->getName().str() <<
", " <<
s <<
");" << std::endl;
1604 <<
"*)" << field_iter->getName().str() <<
", " <<
s <<
");" << std::endl;
1607 if (underling_type->isEnumeralType())
1608 dictStream <<
" R__b.WriteArray((Int_t*)" << field_iter->getName().str() <<
", " <<
s <<
");" << std::endl;
1609 else if (isFloat16) {
1610 dictStream <<
" R__b.WriteArrayFloat16(" << field_iter->getName().str() <<
", " <<
s <<
");" << std::endl;
1611 }
else if (isDouble32) {
1612 dictStream <<
" R__b.WriteArrayDouble32(" << field_iter->getName().str() <<
", " <<
s <<
");" << std::endl;
1614 dictStream <<
" R__b.WriteArray(" << field_iter->getName().str() <<
", " <<
s <<
");" << std::endl;
1618 }
else if (underling_type->isEnumeralType()) {
1620 dictStream <<
" void *ptr_" << field_iter->getName().str() <<
" = (void*)&" << field_iter->getName().str() <<
";\n";
1621 dictStream <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_" << field_iter->getName().str() <<
");" << std::endl;
1623 dictStream <<
" R__b << (Int_t)" << field_iter->getName().str() <<
";" << std::endl;
1628 <<
"=Float16_t(R_Dummy);}" << std::endl;
1631 }
else if (isDouble32) {
1634 <<
"=Double32_t(R_Dummy);}" << std::endl;
1656 if (
type.getTypePtr()->isConstantArrayType() &&
1657 type.getTypePtr()->getArrayElementTypeNoTypeQual()->isPointerType()) {
1658 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
type.getTypePtr());
1662 dictStream <<
" int R__i;" << std::endl;
1665 dictStream <<
" for (R__i = 0; R__i < " <<
s <<
"; R__i++)" << std::endl;
1670 dictStream <<
" R__b << (TObject*)" << field_iter->getName().str();
1675 dictStream <<
"[R__i];" << std::endl;
1676 }
else if (
type.getTypePtr()->isPointerType()) {
1684 ROOT::TMetaUtils::Error(
nullptr,
"*** Datamember %s::%s: pointer to pointer (need manual intervention)\n", fullname.c_str(), field_iter->getName().str().c_str());
1685 dictStream <<
" //R__b.ReadArray(" << field_iter->getName().str() <<
");" << std::endl;
1687 dictStream <<
" //R__b.WriteArray(" << field_iter->getName().str() <<
", __COUNTER__);";
1691 dictStream <<
" " << field_iter->getName().str() <<
"->Streamer(R__b);" << std::endl;
1705 dictStream <<
" R__b << (TObject*)" << field_iter->getName().str() <<
";" << std::endl;
1711 }
else if (
const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
type.getTypePtr())) {
1715 dictStream <<
" int R__i;" << std::endl;
1718 dictStream <<
" for (R__i = 0; R__i < " <<
s <<
"; R__i++)" << std::endl;
1719 std::string mTypeNameStr;
1721 const char *mTypeName = mTypeNameStr.c_str();
1722 const char *constwd =
"const ";
1723 if (strncmp(constwd, mTypeName, strlen(constwd)) == 0) {
1724 mTypeName += strlen(constwd);
1725 dictStream <<
" const_cast< " << mTypeName <<
" &>(" << field_iter->getName().str();
1727 dictStream <<
"[R__i]).Streamer(R__b);" << std::endl;
1731 dictStream <<
"[R__i].Streamer(R__b);" << std::endl;
1737 dictStream <<
" R__b.StreamObject(&(" << field_iter->getName().str() <<
"),typeid("
1738 << field_iter->getName().str() <<
"));" << std::endl;
1749 dictStream <<
" R__b.SetByteCount(R__c, kTRUE);" << std::endl
1750 <<
" }" << std::endl
1751 <<
"}" << std::endl << std::endl;
1753 while (enclSpaceNesting) {
1754 dictStream <<
"} // namespace " << nsname.c_str() << std::endl;
1762 const cling::Interpreter &interp,
1764 std::ostream &dictStream)
1768 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1769 if (clxx ==
nullptr)
return;
1774 for (clang::CXXRecordDecl::base_class_const_iterator iter = clxx->bases_begin(), end = clxx->bases_end();
1786 int enclSpaceNesting = 0;
1792 dictStream <<
"//_______________________________________"
1793 <<
"_______________________________________" << std::endl;
1794 if (add_template_keyword) dictStream <<
"template <> ";
1795 dictStream <<
"void " << clsname <<
"::Streamer(TBuffer &R__b)" << std::endl
1797 <<
" // Stream an object of class " << fullname <<
"." << std::endl << std::endl
1798 <<
" if (R__b.IsReading()) {" << std::endl
1799 <<
" R__b.ReadClassBuffer(" << fullname <<
"::Class(),this);" << std::endl
1800 <<
" } else {" << std::endl
1801 <<
" R__b.WriteClassBuffer(" << fullname <<
"::Class(),this);" << std::endl
1802 <<
" }" << std::endl
1803 <<
"}" << std::endl << std::endl;
1805 while (enclSpaceNesting) {
1806 dictStream <<
"} // namespace " << nsname << std::endl;
1814 const cling::Interpreter &interp,
1816 std::ostream &dictStream,
1817 bool isAutoStreamer)
1819 if (isAutoStreamer) {
1829 std::string &code_for_parser)
1831 code_for_parser +=
"#ifdef __CINT__\n\n";
1832 code_for_parser +=
"#pragma link off all globals;\n";
1833 code_for_parser +=
"#pragma link off all classes;\n";
1834 code_for_parser +=
"#pragma link off all functions;\n\n";
1836 for (std::string& arg : InputFiles) {
1838 int nostr = 0, noinp = 0, bcnt = 0,
l = arg.length() - 1;
1839 for (
int j = 0; j < 3; j++) {
1840 if (arg[
l] ==
'-') {
1845 if (arg[
l] ==
'!') {
1850 if (arg[
l] ==
'+') {
1856 if (nostr || noinp) {
1858 if (nostr) strlcat(trail,
"-", 3);
1859 if (noinp) strlcat(trail,
"!", 3);
1862 strlcpy(trail,
"+", 3);
1867 llvm::sys::path::replace_extension(filestem,
"");
1869 code_for_parser +=
"#pragma link C++ class ";
1870 code_for_parser += filestem.str().str();
1871 if (nostr || noinp || bcnt)
1872 code_for_parser += trail;
1873 code_for_parser +=
";\n";
1876 code_for_parser +=
"\n#endif\n";
1884bool Which(cling::Interpreter &interp,
const char *fname,
string &pname)
1889 static const char *fopenopts =
"rb";
1891 static const char *fopenopts =
"r";
1895 fp = fopen(pname.c_str(), fopenopts);
1901 llvm::SmallVector<std::string, 10> includePaths;
1903 interp.GetIncludePaths(includePaths,
false,
false);
1905 const size_t nPaths = includePaths.size();
1906 for (
size_t i = 0; i < nPaths; i += 1 ) {
1910 fp = fopen(pname.c_str(), fopenopts);
1932 const char *inc = strstr(original,
"\\inc\\");
1934 inc = strstr(original,
"/inc/");
1935 if (inc && strlen(inc) > 5)
1955 cling::Interpreter &interp,
1958 std::ostringstream out;
1963 if (interp.declare(out.str()) != cling::Interpreter::kSuccess) {
1964 const std::string &hdrName
1982static bool WriteAST(llvm::StringRef fileName, clang::CompilerInstance *compilerInstance,
1983 llvm::StringRef iSysRoot,
1984 clang::Module *module =
nullptr)
1987 llvm::SmallVector<char, 128> buffer;
1988 llvm::BitstreamWriter stream(buffer);
1989 clang::ASTWriter
writer(stream, buffer, compilerInstance->getModuleCache(), {});
1990 std::unique_ptr<llvm::raw_ostream> out =
1991 compilerInstance->createOutputFile(fileName,
true,
2000 compilerInstance->getFrontendOpts().RelocatablePCH =
true;
2002 writer.WriteAST(compilerInstance->getSema(), fileName.str(), module, iSysRoot);
2005 out->write(&buffer.front(), buffer.size());
2017 const std::string ¤tDirectory)
2019 assert(modGen.
IsPCH() &&
"modGen must be in PCH mode");
2021 std::string iSysRoot(
"/DUMMY_SYSROOT/include/");
2029static bool IncludeHeaders(
const std::vector<std::string> &headers, cling::Interpreter &interpreter)
2032 if (headers.empty())
2036 std::stringstream includes;
2037 for (
const std::string &header : headers) {
2038 includes <<
"#include \"" << header <<
"\"\n";
2040 std::string includeListStr = includes.str();
2041 auto result = interpreter.declare(includeListStr);
2042 return result == cling::Interpreter::CompilationResult::kSuccess;
2050 char platformDefines[64] = {0};
2051#ifdef __INTEL_COMPILER
2052 snprintf(platformDefines, 64,
"-DG__INTEL_COMPILER=%ld", (
long)__INTEL_COMPILER);
2053 clingArgs.push_back(platformDefines);
2056 snprintf(platformDefines, 64,
"-DG__xlC=%ld", (
long)__xlC__);
2057 clingArgs.push_back(platformDefines);
2060 snprintf(platformDefines, 64,
"-DG__GNUC=%ld", (
long)__GNUC__);
2061 snprintf(platformDefines, 64,
"-DG__GNUC_VER=%ld", (
long)__GNUC__ * 1000 + __GNUC_MINOR__);
2062 clingArgs.push_back(platformDefines);
2064#ifdef __GNUC_MINOR__
2065 snprintf(platformDefines, 64,
"-DG__GNUC_MINOR=%ld", (
long)__GNUC_MINOR__);
2066 clingArgs.push_back(platformDefines);
2069 snprintf(platformDefines, 64,
"-DG__HP_aCC=%ld", (
long)__HP_aCC);
2070 clingArgs.push_back(platformDefines);
2073 snprintf(platformDefines, 64,
"-DG__sun=%ld", (
long)__sun);
2074 clingArgs.push_back(platformDefines);
2077 snprintf(platformDefines, 64,
"-DG__SUNPRO_CC=%ld", (
long)__SUNPRO_CC);
2078 clingArgs.push_back(platformDefines);
2080#ifdef _STLPORT_VERSION
2082 snprintf(platformDefines, 64,
"-DG__STLPORT_VERSION=%ld", (
long)_STLPORT_VERSION);
2083 clingArgs.push_back(platformDefines);
2086 snprintf(platformDefines, 64,
"-DG__ia64=%ld", (
long)__ia64__);
2087 clingArgs.push_back(platformDefines);
2090 snprintf(platformDefines, 64,
"-DG__x86_64=%ld", (
long)__x86_64__);
2091 clingArgs.push_back(platformDefines);
2094 snprintf(platformDefines, 64,
"-DG__i386=%ld", (
long)__i386__);
2095 clingArgs.push_back(platformDefines);
2098 snprintf(platformDefines, 64,
"-DG__arm=%ld", (
long)__arm__);
2099 clingArgs.push_back(platformDefines);
2102 snprintf(platformDefines, 64,
"-DG__WIN32=%ld", (
long)_WIN32);
2103 clingArgs.push_back(platformDefines);
2106 snprintf(platformDefines, 64,
"-DG__WIN32=%ld", (
long)WIN32);
2107 clingArgs.push_back(platformDefines);
2111 snprintf(platformDefines, 64,
"-DG__WIN64=%ld", (
long)_WIN64);
2112 clingArgs.push_back(platformDefines);
2115 snprintf(platformDefines, 64,
"-DG__MSC_VER=%ld", (
long)_MSC_VER);
2116 clingArgs.push_back(platformDefines);
2117 snprintf(platformDefines, 64,
"-DG__VISUAL=%ld", (
long)_MSC_VER);
2118 clingArgs.push_back(platformDefines);
2137 if (std::string::npos != pos) {
2138 dirname.assign(path.begin(), path.begin() + pos + 1);
2149 std::string dictLocation;
2151 return !dictLocation.empty();
2157 std::string &rootmapLibName)
2161 if (rootmapFileName.empty()) {
2163 rootmapFileName = rootmapLibName.substr(0, libExtensionPos) +
".rootmap";
2164 size_t libCleanNamePos = rootmapLibName.find_last_of(
gPathSeparator) + 1;
2165 rootmapLibName = rootmapLibName.substr(libCleanNamePos, std::string::npos);
2167 rootmapLibName.c_str(),
2168 rootmapFileName.c_str());
2177 std::string &ctxtName,
2178 const cling::Interpreter &interpreter,
2179 bool treatParent =
true)
2181 const clang::DeclContext *outerCtxt = treatParent ? theContext.getParent() : &theContext;
2183 if (!outerCtxt)
return;
2185 if (
const clang::RecordDecl *thisRcdDecl = llvm::dyn_cast<clang::RecordDecl>(outerCtxt)) {
2195 std::string &ctxtName,
2196 const cling::Interpreter &interpreter)
2198 const clang::DeclContext *theContext = theDecl.getDeclContext();
2206 const cling::Interpreter &interp)
2208 if (!decls.empty()) {
2209 std::string autoLoadKey;
2210 for (
auto &
d : decls) {
2214 if (autoLoadKey.empty()) {
2215 names.push_back(
d->getQualifiedNameAsString());
2233 const std::string &rootmapLibName,
2234 const std::list<std::string> &classesDefsList,
2235 const std::list<std::string> &classesNames,
2236 const std::list<std::string> &nsNames,
2237 const std::list<std::string> &tdNames,
2238 const std::list<std::string> &enNames,
2239 const std::list<std::string> &varNames,
2241 const std::unordered_set<std::string> headersToIgnore)
2244 std::ofstream rootmapFile(rootmapFileName.c_str());
2252 std::unordered_set<std::string> classesKeys;
2256 if (!classesNames.empty() || !nsNames.empty() || !tdNames.empty() ||
2257 !enNames.empty() || !varNames.empty()) {
2260 if (!classesDefsList.empty()) {
2261 rootmapFile <<
"{ decls }\n";
2262 for (
auto & classDef : classesDefsList) {
2263 rootmapFile << classDef << std::endl;
2265 rootmapFile <<
"\n";
2267 rootmapFile <<
"[ " << rootmapLibName <<
" ]\n";
2270 if (!classesNames.empty()) {
2271 rootmapFile <<
"# List of selected classes\n";
2272 for (
auto & className : classesNames) {
2273 rootmapFile <<
"class " << className << std::endl;
2274 classesKeys.insert(className);
2277 std::unordered_set<std::string> treatedHeaders;
2278 for (
auto & className : classesNames) {
2280 if (className.find(
"<") != std::string::npos)
continue;
2281 if (headersClassesMap.count(className)) {
2282 auto &headers = headersClassesMap.at(className);
2283 if (!headers.empty()){
2284 auto &header = headers.front();
2285 if (treatedHeaders.insert(header).second &&
2286 headersToIgnore.find(header) == headersToIgnore.end() &&
2288 rootmapFile <<
"header " << header << std::endl;
2296 if (!nsNames.empty()) {
2297 rootmapFile <<
"# List of selected namespaces\n";
2298 for (
auto & nsName : nsNames) {
2299 rootmapFile <<
"namespace " << nsName << std::endl;
2304 if (!tdNames.empty()) {
2305 rootmapFile <<
"# List of selected typedefs and outer classes\n";
2306 for (
const auto & autoloadKey : tdNames)
2307 if (classesKeys.insert(autoloadKey).second)
2308 rootmapFile <<
"typedef " << autoloadKey << std::endl;
2313 if (!enNames.empty()){
2314 rootmapFile <<
"# List of selected enums and outer classes\n";
2315 for (
const auto & autoloadKey : enNames)
2316 if (classesKeys.insert(autoloadKey).second)
2317 rootmapFile <<
"enum " << autoloadKey << std::endl;
2321 if (!varNames.empty()){
2322 rootmapFile <<
"# List of selected vars\n";
2323 for (
const auto & autoloadKey : varNames)
2324 if (classesKeys.insert(autoloadKey).second)
2325 rootmapFile <<
"var " << autoloadKey << std::endl;
2339 auto nsPattern =
'{';
auto nsPatternLength = 1;
2340 auto foundNsPos =
line.find_last_of(nsPattern);
2341 if (foundNsPos == std::string::npos)
return {
"",
""};
2342 foundNsPos+=nsPatternLength;
2343 auto extNs =
line.substr(0,foundNsPos);
2345 auto nsEndPattern =
'}';
2346 auto foundEndNsPos =
line.find(nsEndPattern);
2347 auto contained =
line.substr(foundNsPos, foundEndNsPos-foundNsPos);
2349 return {extNs, contained};
2365 std::map<std::string, std::string> nsEntitiesMap;
2366 std::list<std::string> optFwdDeclList;
2367 for (
auto const & fwdDecl : fwdDeclarationsList){
2370 if (extNsAndEntities.first.empty()) {
2372 optFwdDeclList.push_front(fwdDecl);
2374 auto currentVal = nsEntitiesMap[extNsAndEntities.first];
2375 nsEntitiesMap[extNsAndEntities.first] = currentVal +=extNsAndEntities.second;
2379 std::string optFwdDecl;
2380 for (
auto const & extNsAndEntities : nsEntitiesMap) {
2381 optFwdDecl = extNsAndEntities.first;
2382 optFwdDecl += extNsAndEntities.second;
2383 for (
int i = 0; i < std::count(optFwdDecl.begin(), optFwdDecl.end(),
'{'); ++i ){
2386 optFwdDeclList.push_front(optFwdDecl);
2389 return optFwdDeclList;
2397 std::list<std::string> &el_list,
2398 std::unordered_set<std::string> &el_set)
2400 std::stringstream elStream(el);
2403 while (getline(elStream, tmp,
'\n')) {
2405 if (el_set.insert(tmp).second && !tmp.empty()) {
2406 el_list.push_back(tmp);
2417 std::list<std::string> &classesList,
2418 std::list<std::string> &classesListForRootmap,
2419 std::list<std::string> &fwdDeclarationsList,
2420 const cling::Interpreter &interpreter)
2428 std::unordered_set<std::string> classesSet;
2429 std::unordered_set<std::string> outerMostClassesSet;
2431 std::string attrName, attrValue;
2432 bool isClassSelected;
2433 std::unordered_set<std::string> availableFwdDecls;
2434 std::string fwdDeclaration;
2436 fwdDeclaration =
"";
2442 fwdDeclaration =
"";
2449 isClassSelected =
true;
2450 const clang::RecordDecl *rDecl = selClass.GetRecordDecl();
2451 std::string normalizedName;
2452 normalizedName = selClass.GetNormalizedName();
2453 if (!normalizedName.empty() &&
2454 !classesSet.insert(normalizedName).second &&
2455 outerMostClassesSet.count(normalizedName) == 0) {
2456 std::cerr <<
"FATAL: A class with normalized name " << normalizedName
2457 <<
" was already selected. This means that two different instances of"
2458 <<
" clang::RecordDecl had the same name, which is not possible."
2459 <<
" This can be a hint of a serious problem in the class selection."
2460 <<
" In addition, the generated dictionary would not even compile.\n";
2463 classesList.push_back(normalizedName);
2466 const char *reqName(selClass.GetRequestedName());
2469 fwdDeclaration =
"";
2474 if (llvm::isa<clang::ClassTemplateSpecializationDecl>(rDecl)) {
2475 fwdDeclaration =
"";
2478 std::string fwdDeclarationTemplateSpec;
2480 fwdDeclaration +=
'\n' + fwdDeclarationTemplateSpec;
2488 for (
auto ait = rDecl->attr_begin(); ait != rDecl->attr_end(); ++ait) {
2490 attrName ==
"rootmap" &&
2491 attrValue ==
"false") {
2492 attrName = attrValue =
"";
2493 isClassSelected =
false;
2497 if (isClassSelected) {
2513 std::string outerMostClassName;
2515 if (!outerMostClassName.empty() &&
2516 !llvm::isa<clang::ClassTemplateSpecializationDecl>(rDecl) &&
2517 classesSet.insert(outerMostClassName).second &&
2518 outerMostClassesSet.insert(outerMostClassName).second) {
2519 classesListForRootmap.push_back(outerMostClassName);
2521 classesListForRootmap.push_back(normalizedName);
2522 if (reqName && reqName[0] && reqName != normalizedName) {
2523 classesListForRootmap.push_back(reqName);
2528 std::string demangledName = selClass.GetDemangledTypeInfo();
2529 if (!demangledName.empty()) {
2534 if (demangledName != normalizedName && (!reqName || demangledName != reqName)) {
2536 classesListForRootmap.push_back(demangledName);
2542 classesListForRootmap.sort();
2555 for (RScanner::NamespaceColl_t::const_iterator selNsIter = scan.
fSelectedNamespaces.begin();
2570 if (clang::CXXRecordDecl *CXXRD =
2571 llvm::dyn_cast<clang::CXXRecordDecl>(
const_cast<clang::RecordDecl *
>(selClass.GetRecordDecl()))) {
2583 if (!selClass.GetRecordDecl()->isCompleteDefinition() || selClass.RequestOnlyTClass()) {
2586 const clang::CXXRecordDecl *cxxdecl = llvm::dyn_cast<clang::CXXRecordDecl>(selClass.GetRecordDecl());
2589 "Interactivity only dictionaries are not supported for classes with ClassDef\n");
2605 if (interp.parseForModule(
"#include \"TStreamerInfo.h\"\n"
2606 "#include \"TFile.h\"\n"
2607 "#include \"TObjArray.h\"\n"
2608 "#include \"TVirtualArray.h\"\n"
2609 "#include \"TStreamerElement.h\"\n"
2610 "#include \"TProtoClass.h\"\n"
2611 "#include \"TBaseClass.h\"\n"
2612 "#include \"TListOfDataMembers.h\"\n"
2613 "#include \"TListOfEnums.h\"\n"
2614 "#include \"TListOfEnumsWithLock.h\"\n"
2615 "#include \"TDataMember.h\"\n"
2616 "#include \"TEnum.h\"\n"
2617 "#include \"TEnumConstant.h\"\n"
2618 "#include \"TDictAttributeMap.h\"\n"
2619 "#include \"TMessageHandler.h\"\n"
2620 "#include \"TArray.h\"\n"
2621 "#include \"TRefArray.h\"\n"
2622 "#include \"root_std_complex.h\"\n")
2623 != cling::Interpreter::kSuccess)
2634 cling::Interpreter &interp,
2639 bool writeEmptyRootPCM)
2643 bool needsCollectionProxy =
false;
2665 auto nsName =
ns.GetNamespaceDecl()->getQualifiedNameAsString();
2666 if (nsName.find(
"(anonymous)") == std::string::npos)
2671 if (!selClass.GetRecordDecl()->isCompleteDefinition()) {
2675 if (selClass.RequestOnlyTClass()) {
2683 if (clang::CXXRecordDecl *CXXRD =
2684 llvm::dyn_cast<clang::CXXRecordDecl>(
const_cast<clang::RecordDecl *
>(selClass.GetRecordDecl()))) {
2688 const clang::CXXRecordDecl *CRD = llvm::dyn_cast<clang::CXXRecordDecl>(selClass.GetRecordDecl());
2696 }
else if (CRD->getName() ==
"RVec") {
2697 static const clang::DeclContext *vecOpsDC =
nullptr;
2699 vecOpsDC = llvm::dyn_cast<clang::DeclContext>(
2700 interp.getLookupHelper().findScope(
"ROOT::VecOps", cling::LookupHelper::NoDiagnostics));
2701 if (vecOpsDC && vecOpsDC->Equals(CRD->getDeclContext())) {
2709 needsCollectionProxy);
2724 if (!selClass.GetRecordDecl()->isCompleteDefinition() || selClass.RequestOnlyTClass()) {
2728 const clang::CXXRecordDecl *cxxdecl = llvm::dyn_cast<clang::CXXRecordDecl>(selClass.GetRecordDecl());
2740 if (!selClass.GetRecordDecl()->isCompleteDefinition() || !selClass.RequestOnlyTClass()) {
2744 const clang::CXXRecordDecl *CRD = llvm::dyn_cast<clang::CXXRecordDecl>(selClass.GetRecordDecl());
2749 needsCollectionProxy);
2778 if (finRetCode != 0)
return finRetCode;
2788 dictStream <<
"// Do NOT change. Changes will be lost next time file is generated\n\n"
2789 <<
"#define R__DICTIONARY_FILENAME " << main_dictname << std::endl
2792 <<
"#define R__NO_DEPRECATION" << std::endl
2797 <<
"\n/*******************************************************************/\n"
2798 <<
"#include <stddef.h>\n"
2799 <<
"#include <stdio.h>\n"
2800 <<
"#include <stdlib.h>\n"
2801 <<
"#include <string.h>\n"
2802 <<
"#include <assert.h>\n"
2803 <<
"#define G__DICTIONARY\n"
2804 <<
"#include \"ROOT/RConfig.hxx\"\n"
2805 <<
"#include \"TClass.h\"\n"
2806 <<
"#include \"TDictAttributeMap.h\"\n"
2807 <<
"#include \"TInterpreter.h\"\n"
2808 <<
"#include \"TROOT.h\"\n"
2809 <<
"#include \"TBuffer.h\"\n"
2810 <<
"#include \"TMemberInspector.h\"\n"
2811 <<
"#include \"TInterpreter.h\"\n"
2812 <<
"#include \"TVirtualMutex.h\"\n"
2813 <<
"#include \"TError.h\"\n\n"
2814 <<
"#ifndef G__ROOT\n"
2815 <<
"#define G__ROOT\n"
2817 <<
"#include \"RtypesImp.h\"\n"
2818 <<
"#include \"TIsAProxy.h\"\n"
2819 <<
"#include \"TFileMergeInfo.h\"\n"
2820 <<
"#include <algorithm>\n"
2821 <<
"#include \"TCollectionProxyInfo.h\"\n"
2822 <<
"/*******************************************************************/\n\n"
2823 <<
"#include \"TDataMember.h\"\n\n";
2830 dictStream <<
"// The generated code does not explicitly qualify STL entities\n"
2831 <<
"namespace std {} using namespace std;\n\n";
2837 const std::string &includeForSource,
2838 const std::string &extraIncludes)
2840 dictStream <<
"// Header files passed as explicit arguments\n"
2841 << includeForSource << std::endl
2842 <<
"// Header files passed via #pragma extra_include\n"
2843 << extraIncludes << std::endl;
2849#if defined(R__IOSSIM) || defined(R__IOS)
2874 return filename +
"_tmp_" + std::to_string(getpid());
2881 if (nameStr.empty())
return;
2883 std::string tmpNameStr(getTmpFileName(nameStr));
2886 const char *
name(nameStr.c_str());
2887 const char *tmpName(tmpNameStr.c_str());
2889 m_names.push_back(nameStr);
2890 m_tempNames.push_back(tmpNameStr);
2894 if (0 == std::rename(
name , tmpName)) {
2899 nameStr = tmpNameStr;
2910 for (
unsigned int i = 0; i < m_size; ++i) {
2911 const char *tmpName = m_tempNames[i].c_str();
2913 std::ifstream ifile(tmpName);
2918 if (ifile.is_open())
2920 if (0 != std::remove(tmpName)) {
2933 for (
unsigned int i = 0; i < m_size; ++i) {
2934 const char *tmpName = m_tempNames[i].c_str();
2935 const char *
name = m_names[i].c_str();
2937 std::ifstream ifile(tmpName);
2942 if (ifile.is_open())
2948 if (0 != std::rename(tmpName ,
name)) {
2949 if (llvm::sys::fs::copy_file(tmpName ,
name)) {
2950 llvm::sys::fs::remove(tmpName);
2954 if (0 != std::rename(tmpName ,
name)) {
2966 size_t i = std::distance(m_tempNames.begin(),
2967 find(m_tempNames.begin(), m_tempNames.end(), tmpFileName));
2968 if (i == m_tempNames.size())
return m_emptyString;
2975 std::cout <<
"Restoring files in temporary file catalog:\n";
2976 for (
unsigned int i = 0; i < m_size; ++i) {
2977 std::cout << m_tempNames[i] <<
" --> " << m_names[i] << std::endl;
2994 std::string splitDictName(tmpCatalog.
getFileName(dictpathname));
2995 const size_t dotPos = splitDictName.find_last_of(
".");
2996 splitDictName.insert(dotPos,
"_classdef");
2998 return new std::ofstream(splitDictName.c_str());
3007 std::list<std::string> &diagnosticPragmas)
3009 static const std::string
pattern(
"-Wno-");
3013 if (arg ==
"-Wno-noexcept-type") {
3020 diagnosticPragmas.push_back(arg);
3026 cling::Interpreter &interp)
3029 std::string fwdDecl;
3030 std::string initStr(
"{");
3032 for (
auto & strigNargsToKeepPair : fwdDeclnArgsToSkipColl) {
3033 auto &clTemplDecl = *strigNargsToKeepPair.first;
3037 + std::to_string(strigNargsToKeepPair.second)
3040 if (!fwdDeclnArgsToSkipColl.empty())
3051 if (qt.isNull())
return qt;
3052 clang::QualType thisQt(qt);
3053 while (thisQt->isPointerType() ||
3054 thisQt->isReferenceType()) {
3055 thisQt = thisQt->getPointeeType();
3065 const cling::Interpreter &interp,
3066 std::set<const clang::CXXRecordDecl *> &visitedDecls)
3068 std::list<std::string> headers;
3071 cling::Interpreter::PushTransactionRAII RAII(&interp);
3074 if (!visitedDecls.insert(rcd.getCanonicalDecl()).second)
3078 if (
const clang::ClassTemplateSpecializationDecl *tsd = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&rcd)) {
3081 for (
auto & tArg : tsd->getTemplateArgs().asArray()) {
3084 if (tArgQualType.isNull())
continue;
3085 if (
const clang::CXXRecordDecl *tArgCxxRcd = tArgQualType->getAsCXXRecordDecl()) {
3086 headers.splice(headers.end(),
RecordDecl2Headers(*tArgCxxRcd, interp, visitedDecls));
3093 for (
auto baseIt = tsd->bases_begin(); baseIt != tsd->bases_end(); baseIt++) {
3095 if (baseQualType.isNull())
continue;
3096 if (
const clang::CXXRecordDecl *baseRcdPtr = baseQualType->getAsCXXRecordDecl()) {
3097 headers.splice(headers.end(),
RecordDecl2Headers(*baseRcdPtr, interp, visitedDecls));
3102 for (
auto declIt = tsd->decls_begin(); declIt != tsd->decls_end(); ++declIt) {
3103 if (
const clang::FieldDecl *fieldDecl = llvm::dyn_cast<clang::FieldDecl>(*declIt)) {
3105 if (fieldQualType.isNull()) continue ;
3106 if (
const clang::CXXRecordDecl *fieldCxxRcd = fieldQualType->getAsCXXRecordDecl()) {
3107 if (fieldCxxRcd->hasDefinition())
3108 headers.splice(headers.end(),
RecordDecl2Headers(*fieldCxxRcd, interp, visitedDecls));
3114 for (
auto methodIt = tsd->method_begin(); methodIt != tsd->method_end(); ++methodIt) {
3116 for (
auto & fPar : methodIt->parameters()) {
3118 if (fParQualType.isNull())
continue;
3119 if (
const clang::CXXRecordDecl *fParCxxRcd = fParQualType->getAsCXXRecordDecl()) {
3120 if (fParCxxRcd->hasDefinition())
3121 headers.splice(headers.end(),
RecordDecl2Headers(*fParCxxRcd, interp, visitedDecls));
3126 if (retQualType.isNull())
continue;
3127 if (
const clang::CXXRecordDecl *retCxxRcd = retQualType->getAsCXXRecordDecl()) {
3128 if (retCxxRcd->hasDefinition())
3137 headers.emplace_back(header);
3150 if (
auto dclCtxt= rcd.getDeclContext()){
3151 if (! dclCtxt->isStdNamespace()){
3160 auto clAsTmplSpecDecl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&rcd);
3161 if (!clAsTmplSpecDecl)
return false;
3166 auto& astCtxt = rcd.getASTContext();
3167 auto& templInstArgs = clAsTmplSpecDecl->getTemplateInstantiationArgs();
3168 for (
auto&& arg : templInstArgs.asArray()){
3170 auto argKind = arg.getKind();
3172 if (argKind == clang::TemplateArgument::Integral)
continue;
3176 auto argQualType = arg.getAsType();
3177 auto isPOD = argQualType.isPODType(astCtxt);
3179 if (isPOD)
continue;
3181 auto argType = argQualType.getTypePtr();
3182 if (
auto recType = llvm::dyn_cast<clang::RecordType>(argType)){
3185 if (isArgGoodForAutoParseMap)
continue;
3204 const cling::Interpreter &interp)
3206 std::set<const clang::CXXRecordDecl *> visitedDecls;
3207 std::unordered_set<std::string> buffer;
3208 std::string autoParseKey;
3211 for (
auto & annotatedRcd : annotatedRcds) {
3212 if (
const clang::CXXRecordDecl *cxxRcd =
3213 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(annotatedRcd.GetRecordDecl())) {
3215 visitedDecls.clear();
3219 headers.remove_if([&buffer](
const std::string &
s) {
3220 return !buffer.insert(
s).
second;
3223 if (autoParseKey.empty()) autoParseKey = annotatedRcd.GetNormalizedName();
3225 headersDeclsMap[autoParseKey] = headers;
3226 headersDeclsMap[annotatedRcd.GetRequestedName()] = headers;
3228 ROOT::TMetaUtils::Info(
nullptr,
"Class %s is not included in the set of autoparse keys.\n", autoParseKey.c_str());
3233 if (!llvm::isa<clang::ClassTemplateSpecializationDecl>(cxxRcd)){
3234 headersClassesMap[autoParseKey] = headersDeclsMap[autoParseKey];
3235 headersClassesMap[annotatedRcd.GetRequestedName()] = headersDeclsMap[annotatedRcd.GetRequestedName()];
3241 for (
auto & tDef : tDefDecls) {
3242 if (clang::CXXRecordDecl *cxxRcd = tDef->getUnderlyingType()->getAsCXXRecordDecl()) {
3244 visitedDecls.clear();
3249 headers.remove_if([&buffer](
const std::string &
s) {
3250 return !buffer.insert(
s).
second;
3253 if (autoParseKey.empty()) autoParseKey = tDef->getQualifiedNameAsString();
3254 headersDeclsMap[autoParseKey] = headers;
3259 for (
auto & func : funcDecls) {
3265 for (
auto & var : varDecls) {
3271 for (
auto & en : enumDecls) {
3281 const cling::Interpreter &interp)
3283 std::string newFwdDeclString;
3287 std::string fwdDeclString;
3289 std::unordered_set<std::string> fwdDecls;
3310 std::vector<const clang::Decl *> selectedDecls(scan.
fSelectedClasses.size());
3315 selectedDecls.begin(),
3319 selectedDecls.push_back(TD);
3324 std::string fwdDeclLogs;
3332 std::cout <<
"Logs from forward decl printer: \n"
3349 if (fwdDeclString.empty()) fwdDeclString =
"";
3350 return fwdDeclString;
3357 const std::string &detectedUmbrella,
3358 bool payLoadOnly =
false)
3360 std::string headerName;
3363 std::cout <<
"Class-headers Mapping:\n";
3364 std::string headersClassesMapString =
"";
3365 for (
auto const & classHeaders : headersClassesMap) {
3367 std::cout <<
" o " << classHeaders.first <<
" --> ";
3368 headersClassesMapString +=
"\"";
3369 headersClassesMapString += classHeaders.first +
"\"";
3370 for (
auto const & header : classHeaders.second) {
3371 headerName = (detectedUmbrella == header || payLoadOnly) ?
"payloadCode" :
"\"" + header +
"\"";
3372 headersClassesMapString +=
", " + headerName;
3374 std::cout <<
", " << headerName;
3379 std::cout << std::endl;
3380 headersClassesMapString +=
", \"@\",\n";
3382 headersClassesMapString +=
"nullptr";
3383 return headersClassesMapString;
3406 static const std::vector<std::string> namePrfxes {
3409 auto pos = find_if(namePrfxes.begin(),
3411 [&](
const std::string& str){return ROOT::TMetaUtils::BeginsWith(name,str);});
3412 return namePrfxes.end() == pos;
3419 static const std::vector<std::string> uclNamePrfxes {
3423 static const std::set<std::string> unsupportedClassesNormNames{
3426 if ( unsupportedClassesNormNames.count(
name) == 1)
return false;
3427 auto pos = find_if(uclNamePrfxes.begin(),
3428 uclNamePrfxes.end(),
3429 [&](
const std::string& str){return ROOT::TMetaUtils::BeginsWith(name,str);});
3430 return uclNamePrfxes.end() == pos;
3440 for (
auto&& aRcd : annotatedRcds){
3441 auto clName = aRcd.GetNormalizedName();
3443 std::cerr <<
"Error: Class " << clName <<
" has been selected but "
3444 <<
"currently the support for its I/O is not yet available. Note that "
3445 << clName <<
", even if not selected, will be available for "
3446 <<
"interpreted code.\n";
3450 std::cerr <<
"Error: It is not necessary to explicitly select class "
3451 << clName <<
". I/O is supported for it transparently.\n";
3463 bool isLocked =
false;
3466 InterpreterCallbacks(interp),
3467 fFilesIncludedByLinkdef(filesIncludedByLinkdef){};
3472 llvm::StringRef FileName,
bool IsAngled, clang::CharSourceRange ,
3473 const clang::FileEntry * , llvm::StringRef ,
3474 llvm::StringRef ,
const clang::Module * ,
3475 clang::SrcMgr::CharacteristicKind )
override
3477 if (isLocked)
return;
3478 if (IsAngled)
return;
3479 auto& PP = m_Interpreter->getCI()->getPreprocessor();
3480 auto curLexer = PP.getCurrentFileLexer();
3481 if (!curLexer)
return;
3482 auto fileEntry = curLexer->getFileEntry();
3483 if (!fileEntry)
return;
3484 auto thisFileName = fileEntry->getName();
3485 auto fileNameAsString = FileName.str();
3487 if (isThisLinkdef) {
3489 if (isTheIncludedLinkdef) {
3490 fFilesIncludedByLinkdef.clear();
3493 fFilesIncludedByLinkdef.emplace_back(fileNameAsString.c_str());
3507 clang::SourceLocation ImportLoc,
3508 bool ForPragma)
override {
3510 using namespace clang;
3511 if (llvm::StringRef(M->Name).endswith(
"ACLiC_dict")) {
3512 Preprocessor& PP = m_Interpreter->getCI()->getPreprocessor();
3513 HeaderSearch& HS = PP.getHeaderSearchInfo();
3515 Module* CoreModule = HS.lookupModule(
"Core",
false);
3516 assert(M &&
"Must have module Core");
3517 PP.makeModuleVisible(CoreModule, ImportLoc);
3522static llvm::cl::list<std::string>
3525 llvm::cl::desc(
"The list of the expected implicit modules build as part of building the current module."),
3528static llvm::cl::opt<std::string>
3530 llvm::cl::desc(
"<output dictionary file>"),
3550 : fChild(Child), fOwnsChild(OwnsChild), fMap(
Map)
3562 using namespace clang::diag;
3568 std::string moduleName;
3569 const clang::Module *module =
nullptr;
3572 const auto &ID =
Info.getID();
3573 if (ID == remark_module_build || ID == remark_module_build_done) {
3574 moduleName =
Info.getArgStdStr(0);
3575 module = fMap.findModule(moduleName);
3581 "Couldn't find module %s in the available modulemaps. This"
3582 "prevents us from correctly diagnosing wrongly built modules.\n",
3583 moduleName.c_str());
3596 bool isByproductModule
3598 if (!isByproductModule)
3599 fChild->HandleDiagnostic(DiagLevel,
Info);
3601 if (ID == remark_module_build && !isByproductModule) {
3603 "Building module '%s' implicitly. If '%s' requires a \n"
3604 "dictionary please specify build dependency: '%s' depends on '%s'.\n"
3605 "Otherwise, specify '-mByproduct %s' to disable this diagnostic.\n",
3607 moduleName.c_str(), moduleName.c_str());
3615 DiagnosticConsumer::clear();
3618 virtual void BeginSourceFile(
const clang::LangOptions &LangOpts,
const clang::Preprocessor *PP)
override
3620 fChild->BeginSourceFile(LangOpts, PP);
3621 DiagnosticConsumer::BeginSourceFile(LangOpts, PP);
3626 fChild->EndSourceFile();
3627 DiagnosticConsumer::EndSourceFile();
3633 DiagnosticConsumer::finish();
3640#if defined(_WIN32) && defined(_MSC_VER)
3644 const char *EnablePopups = getenv(
"Cling_GuiOnAssert");
3645 if (EnablePopups ==
nullptr || EnablePopups[0] ==
'0') {
3646 ::_set_error_mode(_OUT_TO_STDERR);
3647 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
3648 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
3649 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
3650 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
3651 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
3652 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
3657static llvm::cl::opt<bool>
gOptForce(
"f", llvm::cl::desc(
"Overwrite <file>s."),
3659static llvm::cl::opt<bool>
gOptRootBuild(
"rootbuild", llvm::cl::desc(
"If we are building ROOT."),
3670static llvm::cl::opt<VerboseLevel>
3672 llvm::cl::values(clEnumVal(
v,
"Show errors."),
3673 clEnumVal(
v0,
"Show only fatal errors."),
3674 clEnumVal(
v1,
"Show errors (the same as -v)."),
3675 clEnumVal(
v2,
"Show warnings (default)."),
3676 clEnumVal(
v3,
"Show notes."),
3677 clEnumVal(
v4,
"Show information.")),
3681static llvm::cl::opt<bool>
3682gOptCint(
"cint", llvm::cl::desc(
"Deprecated, legacy flag which is ignored."),
3685static llvm::cl::opt<bool>
3686gOptReflex(
"reflex", llvm::cl::desc(
"Deprecated, legacy flag which is ignored."),
3689static llvm::cl::opt<bool>
3690gOptGccXml(
"gccxml", llvm::cl::desc(
"Deprecated, legacy flag which is ignored."),
3693static llvm::cl::opt<std::string>
3695 llvm::cl::desc(
"An ACLiC feature which exports the list of dependent libraries."),
3698static llvm::cl::opt<bool>
3700 llvm::cl::desc(
"Generates a pch file from a predefined set of headers. See makepch.py."),
3703static llvm::cl::opt<bool>
3704gOptC(
"c", llvm::cl::desc(
"Deprecated, legacy flag which is ignored."),
3706static llvm::cl::opt<bool>
3707gOptP(
"p", llvm::cl::desc(
"Deprecated, legacy flag which is ignored."),
3709static llvm::cl::list<std::string>
3711 llvm::cl::desc(
"Generate rootmap file."),
3713static llvm::cl::opt<std::string>
3715 llvm::cl::desc(
"Generate a rootmap file with the specified name."),
3717static llvm::cl::opt<bool>
3719 llvm::cl::desc(
"Generate a C++ module."),
3721static llvm::cl::list<std::string>
3723 llvm::cl::desc(
"Specify a C++ modulemap file."),
3726static llvm::cl::opt<bool>
3728 llvm::cl::desc(
"A single header including all headers instead of specifying them on the command line."),
3730static llvm::cl::opt<bool>
3732 llvm::cl::desc(
"If this library has multiple separate LinkDef files."),
3734static llvm::cl::opt<bool>
3736 llvm::cl::desc(
"Do not declare {using namespace std} in dictionary global scope."),
3738static llvm::cl::opt<bool>
3740 llvm::cl::desc(
"Generate minimal dictionary for interactivity (without IO information)."),
3742static llvm::cl::opt<bool>
3744 llvm::cl::desc(
"Split the dictionary into two parts: one containing the IO (ClassDef)\
3745information and another the interactivity support."),
3747static llvm::cl::opt<bool>
3750 llvm::cl::desc(
"Do not run the selection rules. Useful when in -onepcm mode."),
3752static llvm::cl::opt<std::string>
3754 llvm::cl::desc(
"The path to the library of the built dictionary."),
3756static llvm::cl::list<std::string>
3758 llvm::cl::desc(
"The list of dependent modules of the dictionary."),
3760static llvm::cl::list<std::string>
3762 llvm::cl::desc(
"Do not store the <path> in the dictionary."),
3766static llvm::cl::opt<bool>
3768 llvm::cl::desc(
"Does not generate #include <header> but expands the header content."),
3776static llvm::cl::opt<bool>
3779 llvm::cl::desc(
"Does not include the header files as it assumes they exist in the pch."),
3781static llvm::cl::opt<bool>
3783 llvm::cl::desc(
"Check the selection syntax only."),
3785static llvm::cl::opt<bool>
3787 llvm::cl::desc(
"Fail if there are warnings."),
3789static llvm::cl::opt<bool>
3791 llvm::cl::desc(
"Do not store include paths but rely on the env variable ROOT_INCLUDE_PATH."),
3793static llvm::cl::opt<std::string>
3795 llvm::cl::desc(
"Specify an isysroot."),
3798static llvm::cl::list<std::string>
3800 llvm::cl::desc(
"Specify an include path."),
3802static llvm::cl::list<std::string>
3804 llvm::cl::desc(
"Specify a compiler default include path, to suppress unneeded `-isystem` arguments."),
3806static llvm::cl::list<std::string>
3808 llvm::cl::desc(
"Specify a system include path."),
3810static llvm::cl::list<std::string>
3812 llvm::cl::desc(
"Specify defined macros."),
3814static llvm::cl::list<std::string>
3816 llvm::cl::desc(
"Specify undefined macros."),
3818static llvm::cl::list<std::string>
3820 llvm::cl::desc(
"Specify compiler diagnostics options."),
3823static llvm::cl::list<std::string>
3825 llvm::cl::desc(
"<list of dictionary header files> <LinkDef file>"),
3827static llvm::cl::list<std::string>
3829 llvm::cl::desc(
"Consumes all unrecognized options."),
3832static llvm::cl::SubCommand
3835static llvm::cl::list<std::string>
3837 llvm::cl::desc(
"Consumes options and sends them to cling."),
3847 clang::Module *module, std::vector<std::array<std::string, 2>> &missingHeaders)
3850 std::vector<clang::Module::Header> moduleHeaders;
3852 [&moduleHeaders](
const clang::Module::Header &
h) { moduleHeaders.push_back(
h); });
3854 bool foundAllHeaders =
true;
3856 auto isHeaderInModule = [&moduleHeaders](
const std::string &header) {
3857 for (
const clang::Module::Header &moduleHeader : moduleHeaders)
3858 if (header == moduleHeader.NameAsWritten)
3866 for (
const std::string &header : modGen.
GetHeaders()) {
3867 if (isHeaderInModule(header))
3870 clang::ModuleMap::KnownHeader SuggestedModule;
3871 const clang::DirectoryLookup *CurDir =
nullptr;
3872 if (
auto FE = headerSearch.LookupFile(
3873 header, clang::SourceLocation(),
3876 clang::ArrayRef<std::pair<const clang::FileEntry *, const clang::DirectoryEntry *>>(),
3879 0, &SuggestedModule,
3886 if (
auto OtherModule = SuggestedModule.getModule()) {
3887 std::string OtherModuleName;
3888 auto TLM = OtherModule->getTopLevelModuleName();
3890 OtherModuleName = TLM.str();
3892 OtherModuleName = OtherModule->Name;
3899 missingHeaders.push_back({header, OtherModuleName});
3902 missingHeaders.push_back({header, {}});
3904 foundAllHeaders =
false;
3906 return foundAllHeaders;
3912 llvm::StringRef LinkdefPath,
const std::string &moduleName)
3914 clang::CompilerInstance *CI = interpreter.getCI();
3915 clang::HeaderSearch &headerSearch = CI->getPreprocessor().getHeaderSearchInfo();
3916 headerSearch.loadTopLevelSystemModules();
3919 clang::Module *module = headerSearch.lookupModule(llvm::StringRef(moduleName));
3924 moduleName.c_str());
3931 std::vector<std::array<std::string, 2>> missingHdrMod;
3934 std::stringstream msgStream;
3935 msgStream <<
"after creating module \"" << module->Name <<
"\" ";
3936 if (!module->PresumedModuleMapFile.empty())
3937 msgStream <<
"using modulemap \"" << module->PresumedModuleMapFile <<
"\" ";
3938 msgStream <<
"the following headers are not part of that module:\n";
3939 for (
auto &
H : missingHdrMod) {
3940 msgStream <<
" " <<
H[0];
3942 msgStream <<
" (already part of module \"" <<
H[1] <<
"\")";
3945 std::string warningMessage = msgStream.str();
3947 bool maybeUmbrella = modGen.
GetHeaders().size() == 1;
3958 ROOT::TMetaUtils::Info(
"CheckModuleValid, %s. You can silence this message by adding %s to the invocation.",
3959 warningMessage.c_str(),
3966 std::vector<std::string> missingHeaders;
3967 std::transform(missingHdrMod.begin(), missingHdrMod.end(), missingHeaders.begin(),
3968 [](
const std::array<std::string, 2>& HdrMod) { return HdrMod[0];});
3971 module->Name.c_str());
3982 moduleName.consume_front(
"lib");
3983 moduleName.consume_back(
".pcm");
3984 moduleName.consume_back(
"_rdict");
3992 bool isGenreflex =
false)
4003 const char *executableFileName = argv[0];
4005 llvm::sys::PrintStackTraceOnErrorSignal(executableFileName);
4006 llvm::PrettyStackTraceProgram X(argc, argv);
4009#if defined(R__WIN32) && !defined(R__WINGCC)
4014 for (
int iic = 1 ; iic < argc; ++iic) {
4015 std::string iiarg(argv[iic]);
4017 size_t len = iiarg.length();
4019 char *argviic =
new char[
len + 1];
4020 strlcpy(argviic, iiarg.c_str(),
len + 1);
4021 argv[iic] = argviic;
4030 auto &opts = llvm::cl::getRegisteredOptions();
4031 llvm::cl::Option* optHelp = opts[
"help"];
4032 llvm::cl::alias optHelpAlias1(
"h",
4033 llvm::cl::desc(
"Alias for -help"),
4034 llvm::cl::aliasopt(*optHelp));
4035 llvm::cl::alias optHelpAlias2(
"?",
4036 llvm::cl::desc(
"Alias for -help"),
4037 llvm::cl::aliasopt(*optHelp));
4039 llvm::cl::ParseCommandLineOptions(argc, argv,
"rootcling");
4043 std::vector<const char *> clingArgsC;
4044 clingArgsC.push_back(executableFileName);
4046 clingArgsC.push_back(
"-I");
4053 clingArgsC.push_back(Opt.c_str());
4055 auto interp = std::make_unique<cling::Interpreter>(clingArgsC.size(),
4057 llvmResourceDir.c_str());
4060 return interp->getDiagnostics().hasFatalErrorOccurred();
4063 std::string dictname;
4077 llvm::cl::PrintHelpMessage();
4092 if ((fp = fopen(filein.c_str(),
"r")) ==
nullptr) {
4093 ROOT::TMetaUtils::Error(
nullptr,
"%s: The input list file %s does not exist\n", executableFileName, filein.c_str());
4120 ROOT::TMetaUtils::Error(
nullptr,
"Inconsistent set of arguments detected: overwrite of dictionary file forced but no filename specified.\n");
4121 llvm::cl::PrintHelpMessage();
4125 std::vector<std::string> clingArgs;
4126 clingArgs.push_back(executableFileName);
4127 clingArgs.push_back(
"-iquote.");
4133 std::list<std::string> diagnosticPragmas = {
"#pragma clang diagnostic ignored \"-Wdeprecated-declarations\""};
4155 ROOT::TMetaUtils::Error(
"",
"Multidict requested but no target library. Please specify one with the -s argument.\n");
4160 clingArgs.push_back(std::string(
"-D") + PPDefine);
4163 clingArgs.push_back(std::string(
"-U") + PPUndefine);
4166 clingArgs.push_back(std::string(
"-I") + llvm::sys::path::convert_to_slash(IncludePath));
4173 clingArgs.push_back(
"-isystem");
4174 clingArgs.push_back(llvm::sys::path::convert_to_slash(IncludePath));
4178 for (
const std::string &WDiag :
gOptWDiags) {
4179 const std::string FullWDiag = std::string(
"-W") + WDiag;
4183 clingArgs.push_back(FullWDiag);
4187 clingArgs.push_back(std::string(
"-I") + includeDir);
4189 std::vector<std::string> pcmArgs;
4190 for (
size_t parg = 0,
n = clingArgs.size(); parg <
n; ++parg) {
4191 auto thisArg = clingArgs[parg];
4193 if (thisArg ==
"-c" ||
4199 while (
c ==
' ')
c = thisArg[++
offset];
4203 [&](
const std::string& path){
4204 return ROOT::TMetaUtils::BeginsWith(&thisArg[offset], path);});
4205 if (excludePathsEnd != excludePathPos)
continue;
4207 pcmArgs.push_back(thisArg);
4214 clingArgs.push_back(
"-D__ROOTCLING__");
4217 clingArgs.push_back(
"-DSYSTEM_TYPE_macosx");
4218#elif defined(R__WIN32)
4219 clingArgs.push_back(
"-DSYSTEM_TYPE_winnt");
4222 clingArgs.push_back(
"-D_XKEYCHECK_H");
4224 clingArgs.push_back(
"-DNOMINMAX");
4226 clingArgs.push_back(
"-DSYSTEM_TYPE_unix");
4229 clingArgs.push_back(
"-fsyntax-only");
4231 clingArgs.push_back(
"-fPIC");
4233 clingArgs.push_back(
"-Xclang");
4234 clingArgs.push_back(
"-fmodules-embed-all-files");
4235 clingArgs.push_back(
"-Xclang");
4236 clingArgs.push_back(
"-main-file-name");
4237 clingArgs.push_back(
"-Xclang");
4238 clingArgs.push_back((dictname +
".h").c_str());
4246 std::string outputFile;
4248 llvm::StringRef moduleName;
4253 auto clingArgsInterpreter = clingArgs;
4262 clingArgsInterpreter.push_back(
"-fmodules");
4263 clingArgsInterpreter.push_back(
"-fno-implicit-module-maps");
4266 clingArgsInterpreter.push_back(
"-fmodule-map-file=" + modulemap);
4268 clingArgsInterpreter.push_back(
"-fmodule-map-file=" +
4270 "/module.modulemap");
4272 if (llvm::sys::fs::exists(ModuleMapCWD))
4273 clingArgsInterpreter.push_back(
"-fmodule-map-file=" + ModuleMapCWD);
4281 clingArgsInterpreter.push_back(
"-Xclang");
4282 clingArgsInterpreter.push_back(
"-fmodule-feature");
4283 clingArgsInterpreter.push_back(
"-Xclang");
4286 clingArgsInterpreter.push_back(
"-fmodule-name=" + moduleName.str());
4296 if (moduleName ==
"Core") {
4298 remove((moduleCachePath + llvm::sys::path::get_separator() +
"_Builtin_intrinsics.pcm").str().c_str());
4299 remove((moduleCachePath + llvm::sys::path::get_separator() +
"_Builtin_stddef_max_align_t.pcm").str().c_str());
4300 remove((moduleCachePath + llvm::sys::path::get_separator() +
"Cling_Runtime.pcm").str().c_str());
4301 remove((moduleCachePath + llvm::sys::path::get_separator() +
"Cling_Runtime_Extra.pcm").str().c_str());
4303 remove((moduleCachePath + llvm::sys::path::get_separator() +
"vcruntime.pcm").str().c_str());
4304 remove((moduleCachePath + llvm::sys::path::get_separator() +
"services.pcm").str().c_str());
4308 remove((moduleCachePath + llvm::sys::path::get_separator() +
"Darwin.pcm").str().c_str());
4310 remove((moduleCachePath + llvm::sys::path::get_separator() +
"libc.pcm").str().c_str());
4312 remove((moduleCachePath + llvm::sys::path::get_separator() +
"std.pcm").str().c_str());
4313 remove((moduleCachePath + llvm::sys::path::get_separator() +
"boost.pcm").str().c_str());
4314 remove((moduleCachePath + llvm::sys::path::get_separator() +
"tinyxml2.pcm").str().c_str());
4315 remove((moduleCachePath + llvm::sys::path::get_separator() +
"ROOT_Config.pcm").str().c_str());
4316 remove((moduleCachePath + llvm::sys::path::get_separator() +
"ROOT_Rtypes.pcm").str().c_str());
4317 remove((moduleCachePath + llvm::sys::path::get_separator() +
"ROOT_Foundation_C.pcm").str().c_str());
4318 remove((moduleCachePath + llvm::sys::path::get_separator() +
"ROOT_Foundation_Stage1_NoRTTI.pcm").str().c_str());
4319 }
else if (moduleName ==
"MathCore") {
4320 remove((moduleCachePath + llvm::sys::path::get_separator() +
"Vc.pcm").str().c_str());
4325 clingArgsInterpreter.push_back(
"-fmodules-cache-path=" + moduleCachePath);
4329 clingArgsInterpreter.push_back(
"-v");
4332 std::vector<const char *> clingArgsC;
4333 for (
auto const &clingArg : clingArgsInterpreter) {
4335 std::cerr <<
"Argument \""<< clingArg <<
"\" is not a supported cling argument. "
4336 <<
"This could be mistyped rootcling argument. Please check the commandline.\n";
4339 clingArgsC.push_back(clingArg.c_str());
4343 std::unique_ptr<cling::Interpreter> owningInterpPtr;
4344 cling::Interpreter* interpPtr =
nullptr;
4346 std::list<std::string> filesIncludedByLinkdef;
4350 clingArgsC.push_back(
"-ffast-math");
4353 owningInterpPtr.reset(
new cling::Interpreter(clingArgsC.size(), &clingArgsC[0],
4354 llvmResourceDir.c_str()));
4355 interpPtr = owningInterpPtr.get();
4358 clingArgsC.push_back(
"-resource-dir");
4359 clingArgsC.push_back(llvmResourceDir.c_str());
4360 clingArgsC.push_back(
nullptr);
4362 extraArgs = &clingArgsC[1];
4365 std::unique_ptr<TRootClingCallbacks> callBacks (
new TRootClingCallbacks(interpPtr, filesIncludedByLinkdef));
4366 interpPtr->setCallbacks(std::move(callBacks));
4369 cling::Interpreter &interp = *interpPtr;
4370 clang::CompilerInstance *CI = interp.getCI();
4372 CI->getFrontendOpts().ModulesEmbedAllFiles =
true;
4373 CI->getSourceManager().setAllFilesAreTransient(
true);
4375 clang::Preprocessor &PP = CI->getPreprocessor();
4376 clang::HeaderSearch &headerSearch = PP.getHeaderSearchInfo();
4377 clang::ModuleMap &moduleMap = headerSearch.getModuleMap();
4378 auto &diags = interp.getDiagnostics();
4385 diags.setSeverity(clang::diag::remark_module_build, clang::diag::Severity::Remark, clang::SourceLocation());
4390 diags.setClient(recordingClient,
true);
4396 interp.DumpIncludePath();
4401 interp.printIncludedFiles(llvm::outs());
4402 llvm::outs() <<
"\n\n";
4403 llvm::outs().flush();
4406 const clang::LangOptions& LangOpts
4407 = interp.getCI()->getASTContext().getLangOpts();
4408#define LANGOPT(Name, Bits, Default, Description) \
4409 ROOT::TMetaUtils::Info(nullptr, "%s = %d // %s\n", #Name, (int)LangOpts.Name, Description);
4410#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
4411#include "clang/Basic/LangOptions.def"
4415 interp.getOptions().ErrorOut =
true;
4416 interp.enableRawInput(
true);
4420 if (DepMod.endswith(
"_rdict.pcm")) {
4427 cling::Interpreter::PushTransactionRAII RAII(&interp);
4428 if (!interp.loadModule(DepMod.str(),
false)) {
4437 if (interp.declare(
"#include <assert.h>\n"
4438 "#include \"Rtypes.h\"\n"
4439 "#include \"TObject.h\"") != cling::Interpreter::kSuccess
4447 if (interp.declare(
"#include <string>\n"
4448 "#include <RtypesCore.h>\n"
4449 "namespace std {} using namespace std;") != cling::Interpreter::kSuccess) {
4460 clingArgs.push_back(
"-D__CINT__");
4461 clingArgs.push_back(
"-D__MAKECINT__");
4467 std::string interpPragmaSource;
4468 std::string includeForSource;
4469 std::string interpreterDeclarations;
4470 std::string linkdef;
4476 if (isSelectionFile) {
4478 linkdef = optHeaderFileName;
4481 executableFileName, optHeaderFileName.c_str());
4487 std::string fullheader(optHeaderFileName);
4490 if (fullheader[fullheader.length() - 1] ==
'+') {
4491 fullheader.erase(fullheader.length() - 1);
4496 interpPragmaSource += std::string(
"#include \"") + header +
"\"\n";
4497 if (!isSelectionFile) {
4505 includeForSource += std::string(
"#include \"") + fullheader +
"\"\n";
4506 pcmArgs.push_back(header);
4508 interpreterDeclarations += std::string(
"#include \"") + header +
"\"\n";
4513 bool hasSelectionFile = !linkdef.empty();
4514 unsigned expectedHeaderFilesSize = 1 + hasSelectionFile;
4525 if (!newName.empty())
4538 string incCurDir =
"-I";
4539 incCurDir += currentDirectory;
4540 pcmArgs.push_back(incCurDir);
4545 std::stringstream res;
4546 const char* delim=
"\n";
4547 std::copy(diagnosticPragmas.begin(),
4548 diagnosticPragmas.end(),
4549 std::ostream_iterator<std::string>(res, delim));
4550 if (interp.declare(res.str()) != cling::Interpreter::kSuccess) {
4556 class IgnoringPragmaHandler:
public clang::PragmaNamespace {
4558 IgnoringPragmaHandler(
const char* pragma):
4559 clang::PragmaNamespace(pragma) {}
4560 void HandlePragma(clang::Preprocessor &PP,
4561 clang::PragmaIntroducer Introducer,
4562 clang::Token &tok)
override {
4563 PP.DiscardUntilEndOfDirective();
4569 PP.AddPragmaHandler(
new IgnoringPragmaHandler(
"link"));
4570 PP.AddPragmaHandler(
new IgnoringPragmaHandler(
"extra_include"));
4571 PP.AddPragmaHandler(
new IgnoringPragmaHandler(
"read"));
4572 PP.AddPragmaHandler(
new IgnoringPragmaHandler(
"create"));
4574 if (!interpreterDeclarations.empty() &&
4575 interp.declare(interpreterDeclarations) != cling::Interpreter::kSuccess) {
4587 pcmArgs.push_back(linkdef);
4595 interp.AddIncludePath(inclPath);
4597 std::stringstream definesUndefinesStr;
4600 if (!definesUndefinesStr.str().empty()) {
4601 if (interp.declare(definesUndefinesStr.str()) != cling::Interpreter::kSuccess) {
4602 ROOT::TMetaUtils::Error(
nullptr,
"Failed to parse -D, -U flags as preprocessor directives:\n%s", definesUndefinesStr.str().c_str());
4613 if (linkdef.empty()) {
4619 std::ofstream fileout;
4621 std::ostream *splitDictStream =
nullptr;
4622 std::unique_ptr<std::ostream> splitDeleter(
nullptr);
4644 splitDeleter.reset(splitDictStream);
4646 splitDictStream = &dictStream;
4649 size_t dh = main_dictname.rfind(
'.');
4650 if (dh != std::string::npos) {
4651 main_dictname.erase(dh);
4654 std::string main_dictname_copy(main_dictname);
4676 string linkdefFilename;
4677 if (linkdef.empty()) {
4678 linkdefFilename =
"in memory";
4680 bool found =
Which(interp, linkdef.c_str(), linkdefFilename);
4688 std::vector<std::pair<std::string, std::string>> namesForExclusion;
4694 SelectionRules selectionRules(interp, normCtxt, namesForExclusion);
4696 std::string extraIncludes;
4701 const unsigned int selRulesInitialSize = selectionRules.
Size();
4705 bool dictSelRulesPresent = selectionRules.
Size() > selRulesInitialSize;
4709 int rootclingRetCode(0);
4713 std::ifstream
file(linkdefFilename.c_str());
4714 if (
file.is_open()) {
4727 clingArgs.push_back(
"-Ietc/cling/cint");
4729 if (!ldefr.
Parse(selectionRules, interpPragmaSource, clingArgs,
4730 llvmResourceDir.c_str())) {
4732 rootclingRetCode += 1;
4742 }
else if (isSelXML) {
4746 std::ifstream
file(linkdefFilename.c_str());
4747 if (
file.is_open()) {
4751 if (!xmlr.
Parse(linkdefFilename.c_str(), selectionRules)) {
4787 dictStream <<
"#include \"TBuffer.h\"\n"
4788 <<
"#include \"TVirtualObject.h\"\n"
4789 <<
"#include <vector>\n"
4790 <<
"#include \"TSchemaHelper.h\"\n\n";
4792 std::list<std::string> includes;
4794 for (
auto & incFile : includes) {
4795 dictStream <<
"#include <" << incFile <<
">" << std::endl;
4797 dictStream << std::endl;
4802 int scannerVerbLevel = 0;
4830 scan.
Scan(CI->getASTContext());
4832 bool has_input_error =
false;
4839 !dictSelRulesPresent &&
4846 if (rootclingRetCode)
return rootclingRetCode;
4853 if (annRcd.RequestNoInputOperator()) {
4865 if (has_input_error) {
4875 for (
auto &&includedFromLinkdef : filesIncludedByLinkdef) {
4876 includeForSource +=
"#include \"" + includedFromLinkdef +
"\"\n";
4904 constructorTypes.emplace_back(
"TRootIOCtor", interp);
4905 constructorTypes.emplace_back(
"__void__", interp);
4906 constructorTypes.emplace_back(
"", interp);
4936 if (rootclingRetCode != 0) {
4937 return rootclingRetCode;
4956 std::string detectedUmbrella;
4957 for (
auto & arg : pcmArgs) {
4959 detectedUmbrella = arg;
4965 headersDeclsMap.clear();
4969 std::string headersClassesMapString =
"\"\"";
4970 std::string fwdDeclsString =
"\"\"";
4986 if (modGen.
IsPCH()) {
4989 if (!
CheckModuleValid(modGen, llvmResourceDir, interp, linkdefFilename, moduleName.str()))
4999 ofstream outputfile(liblist_filename.c_str(), ios::out);
5002 executableFileName, liblist_filename.c_str());
5004 const size_t endStr =
gLibsNeeded.find_last_not_of(
" \t");
5005 outputfile <<
gLibsNeeded.substr(0, endStr + 1) << endl;
5007 outputfile <<
"# Now the list of classes\n";
5012 outputfile << annRcd.GetNormalizedName() << endl;
5019 if (0 != rootclingRetCode)
return rootclingRetCode;
5025 [](
const std::string &
a,
const std::string &
b) -> std::string {
5026 if (a.empty()) return b;
5027 else return a +
" " + b;
5032 std::list<std::string> classesNames;
5033 std::list<std::string> classesNamesForRootmap;
5034 std::list<std::string> classesDefsList;
5038 classesNamesForRootmap,
5042 std::list<std::string> enumNames;
5047 std::list<std::string> varNames;
5052 if (0 != rootclingRetCode)
return rootclingRetCode;
5055 if (rootMapNeeded) {
5057 std::list<std::string> nsNames;
5066 rootmapLibName.c_str());
5069 std::unordered_set<std::string> headersToIgnore;
5072 headersToIgnore.insert(optHeaderFileName.c_str());
5074 std::list<std::string> typedefsRootmapLines;
5082 classesNamesForRootmap,
5084 typedefsRootmapLines,
5090 if (0 != rootclingRetCode)
return 1;
5100 cling::Interpreter::PushTransactionRAII RAII(&interp);
5101 CI->getSema().getASTConsumer().HandleTranslationUnit(CI->getSema().getASTContext());
5112 if(rootclingRetCode == 0) {
5113 rootclingRetCode += tmpCatalog.
commit();
5118 return rootclingRetCode;
5129 unsigned int numberOfHeaders = 0;
5130 for (std::vector<std::string>::iterator it = headersNames.begin();
5131 it != headersNames.end(); ++it) {
5132 const std::string headername(*it);
5137 "*** genreflex: %s is not a valid header name (.h and .hpp extensions expected)!\n",
5138 headername.c_str());
5141 return numberOfHeaders;
5147 unsigned int extractArgs(
int argc,
char **argv, std::vector<std::string> &args)
5150 unsigned int argvCounter = 0;
5151 for (
int i = 1; i < argc; ++i) {
5154 args.push_back(argv[i]);
5156 }
else if (argvCounter) {
5157 argv[i - argvCounter] = argv[i];
5164 std::cout <<
"Args: \n";
5165 for (std::vector<std::string>::iterator it = args.begin();
5166 it < args.end(); ++it) {
5167 std::cout << i <<
") " << *it << std::endl;
5181 if (std::string::npos !=
result) {
5193 const unsigned int size(str.size());
5194 char *
a =
new char[
size + 1];
5196 memcpy(
a, str.c_str(),
size);
5212 std::vector<std::string> &ofilesnames)
5214 ofilesnames.reserve(headersNames.size());
5216 for (std::vector<std::string>::const_iterator it = headersNames.begin();
5217 it != headersNames.end(); ++it) {
5218 std::string ofilename(*it);
5220 ofilesnames.push_back(ofilename);
5227 const std::vector<std::string> &argsToBeAdded,
5228 const std::string &optName =
"")
5230 for (std::vector<std::string>::const_iterator it = argsToBeAdded.begin();
5231 it != argsToBeAdded.end(); ++it) {
5239 const std::vector<std::string> &argsToBeAdded,
5240 const std::string &optName =
"")
5242 for (std::vector<std::string>::const_iterator it = argsToBeAdded.begin();
5243 it != argsToBeAdded.end(); ++it) {
5244 if (optName.length()) {
5254 const std::string &selectionFileName,
5255 const std::string &targetLibName,
5257 const std::vector<std::string> &pcmsNames,
5258 const std::vector<std::string> &includes,
5259 const std::vector<std::string> &preprocDefines,
5260 const std::vector<std::string> &preprocUndefines,
5261 const std::vector<std::string> &warnings,
5262 const std::string &rootmapFileName,
5263 const std::string &rootmapLibName,
5264 bool interpreteronly,
5267 bool writeEmptyRootPCM,
5269 bool noIncludePaths,
5270 bool noGlobalUsingStd,
5271 const std::vector<std::string> &headersNames,
5272 bool failOnWarnings,
5273 const std::string &ofilename)
5277 std::vector<char *> argvVector;
5288 std::string dictLocation;
5294 std::string newRootmapLibName(rootmapLibName);
5295 if (!rootmapFileName.empty() && newRootmapLibName.empty()) {
5296 if (headersNames.size() != 1) {
5298 "*** genreflex: No rootmap lib and several header specified!\n");
5301 newRootmapLibName =
"lib";
5302 newRootmapLibName += cleanHeaderName;
5308 std::string newRootmapFileName(rootmapFileName);
5309 if (!newRootmapFileName.empty() && !
HasPath(newRootmapFileName)) {
5310 newRootmapFileName = dictLocation + newRootmapFileName;
5315 if (!newRootmapFileName.empty()) {
5321 if (!newRootmapLibName.empty()) {
5327 if (interpreteronly)
5335 if (!targetLibName.empty()) {
5345 if (noGlobalUsingStd)
5355 if (writeEmptyRootPCM)
5378 if (!selectionFileName.empty()) {
5382 const int argc = argvVector.size();
5386 std::cout <<
"Rootcling commandline:\n";
5387 for (
int i = 0; i < argc; i++)
5388 std::cout << i <<
") " << argvVector[i] << std::endl;
5391 char **argv = & (argvVector[0]);
5396 for (
int i = 0; i < argc; i++)
5397 delete [] argvVector[i];
5399 return rootclingReturnCode;
5408 const std::string &selectionFileName,
5409 const std::string &targetLibName,
5411 const std::vector<std::string> &pcmsNames,
5412 const std::vector<std::string> &includes,
5413 const std::vector<std::string> &preprocDefines,
5414 const std::vector<std::string> &preprocUndefines,
5415 const std::vector<std::string> &warnings,
5416 const std::string &rootmapFileName,
5417 const std::string &rootmapLibName,
5418 bool interpreteronly,
5421 bool writeEmptyRootPCM,
5423 bool noIncludePaths,
5424 bool noGlobalUsingStd,
5425 const std::vector<std::string> &headersNames,
5426 bool failOnWarnings,
5427 const std::string &outputDirName_const =
"")
5429 std::string outputDirName(outputDirName_const);
5431 std::vector<std::string> ofilesNames;
5438 std::vector<std::string> namesSingleton(1);
5439 for (
unsigned int i = 0; i < headersNames.size(); ++i) {
5440 namesSingleton[0] = headersNames[i];
5441 std::string ofilenameFullPath(ofilesNames[i]);
5442 if (llvm::sys::path::parent_path(ofilenameFullPath) ==
"")
5443 ofilenameFullPath = outputDirName + ofilenameFullPath;