38 struct ShuttingDownSignaler :
public T {
41 ShuttingDownSignaler() =
default;
42 ShuttingDownSignaler(T &&in) :
T(std::move(in)) {}
44 ~ShuttingDownSignaler()
46 if (gInterpreterHelper)
59 if (
name.compare(0,5,
"std::")==0) {
64 if (gInterpreterHelper) {
65 for(
size_t i = 5; i <
name.length(); ++i) {
66 if (
name[i] ==
'<')
break;
68 std::string scope(
name.data(),i);
72 static ShuttingDownSignaler<std::set<std::string>> gInlined;
73 static std::atomic_flag spinFlag = ATOMIC_FLAG_INIT;
78 isInlined = (gInlined.find(scope) != gInlined.end());
83 if (i+1<
name.length() &&
name[i+1]==
':') {
87 std::string scoperesult;
94 gInlined.insert(scope);
97 if (i+1<
name.length() &&
name[i+1]==
':') {
131 name.remove_prefix(len);
139 if (0 == strncmp(clName,
"complex<", 8)) {
140 const char *clNamePlus8 = clName + 8;
141 if (0 == strcmp(
"float>", clNamePlus8)) {
142 return EComplexType::kFloat;
144 if (0 == strcmp(
"double>", clNamePlus8)) {
145 return EComplexType::kDouble;
147 if (0 == strcmp(
"int>", clNamePlus8)) {
148 return EComplexType::kInt;
150 if (0 == strcmp(
"long>", clNamePlus8)) {
151 return EComplexType::kLong;
154 return EComplexType::kNone;
165 if (
this == gInterpreterHelper)
166 gInterpreterHelper =
nullptr;
173 gInterpreterHelper = helper;
209 if (fElements[0].empty())
return 0;
210 int numb = fElements.size();
211 if (!fElements[numb-1].empty() && fElements[numb-1][0]==
'*') --numb;
213 if ( fNestedLocation ) {
219 int kind =
STLKind(fElements[0]);
224 if (testAlloc && (numb-1 > nargs) && !
IsDefAlloc(fElements[numb-1].c_str(),fElements[1].c_str())) {
236 if (k<0) kind = -kind;
242 if(kind>2) kind = - kind;
262 int narg = fElements.size();
273 if (fElements[narg-1].empty() ==
false &&
274 (fElements[narg-1][0]==
'*'
275 || fElements[narg-1][0]==
'&'
276 || fElements[narg-1][0]==
'['
277 || 0 == fElements[narg-1].compare(0,6,
"const*")
278 || 0 == fElements[narg-1].compare(0,6,
"const&")
279 || 0 == fElements[narg-1].compare(0,6,
"const[")
280 || 0 == fElements[narg-1].compare(
"const")
283 if ((mode&1)==0) tailLoc = narg-1;
285 else { assert(fElements[narg-1].empty()); };
289 if (fNestedLocation) narg--;
294 const int kind =
STLKind(fElements[0]);
295 const int iall =
STLArgs(kind);
299 while(narg-1>iall) { fElements.pop_back(); narg--;}
300 if (!fElements[0].empty() && tailLoc) {
303 fElements[0].clear();
311 bool allocRemoved =
false;
317 if (narg-1 == iall+1) {
319 bool dropAlloc =
false;
334 dropAlloc =
IsDefAlloc(fElements[iall+1].c_str(),fElements[1].c_str());
340 dropAlloc =
IsDefAlloc(fElements[iall+1].c_str(),fElements[1].c_str(),fElements[2].c_str());
358 if (
IsDefComp( fElements[iall].c_str(), fElements[1].c_str() ) ) {
373 if (!allocRemoved && narg-1 == iall+1) {
377 if (narg-1 == iall) narg--;
400 bool predRemoved =
false;
403 if (
IsDefPred( fElements[iall].c_str(), fElements[1].c_str() ) ) {
410 if (
IsDefHash( fElements[iall-1].c_str(), fElements[1].c_str() ) ) {
418 unsigned int offset = (0==strncmp(
"const ",fElements[0].c_str(),6)) ? 6 : 0;
419 offset += (0==strncmp(
"std::",fElements[0].c_str()+offset,5)) ? 5 : 0;
420 if (0 == strcmp(fElements[0].c_str()+offset,
"__shared_ptr"))
423 static const std::string sharedPtrDef = std::to_string(__gnu_cxx::__default_lock_policy);
425 static const std::string sharedPtrDef = std::to_string(2);
427 if (fElements[2] == sharedPtrDef) {
435 for (
int i=1;i<narg; i++) {
436 if (strchr(fElements[i].c_str(),
'<')==0) {
438 unsigned int offset = (0==strncmp(
"const ",fElements[i].c_str(),6)) ? 6 : 0;
452 if (gInterpreterHelper &&
455 if (!typeresult.empty()) fElements[i] = typeresult;
460 unsigned int tailOffset = 0;
461 if (tailLoc && fElements[tailLoc].compare(0,5,
"const") == 0) {
465 if (!fElements[0].empty()) {answ += fElements[0]; answ +=
"<";}
474 int nargNonDefault = 0;
475 std::string nonDefName = answ;
477 std::string nameSuperLong = fName;
478 if (gInterpreterHelper)
480 while (++nargNonDefault < narg) {
483 const char* closeTemplate =
" >";
484 if (nonDefName[nonDefName.length() - 1] !=
'>')
486 string nondef = nonDefName + closeTemplate;
487 if (gInterpreterHelper &&
490 if (nargNonDefault>1) nonDefName +=
",";
491 nonDefName += fElements[nargNonDefault];
493 if (nargNonDefault < narg)
494 narg = nargNonDefault;
498 {
for (
int i=1;i<narg-1; i++) { answ += fElements[i]; answ+=
",";} }
499 if (narg>1) { answ += fElements[narg-1]; }
501 if (!fElements[0].empty()) {
502 if ( answ.at(answ.size()-1) ==
'>') {
508 if (fNestedLocation) {
511 answ += fElements[fNestedLocation];
514 if (tailLoc) answ += fElements[tailLoc].c_str()+tailOffset;
521 return !fElements[0].empty();
530 if (
type.length() == 0)
533 if (
type.compare(0,6,
"const ")==0) { offset += 6; }
535 const auto len =
type.length() - offset;
540 static const char *stls[] =
541 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
542 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap", 0};
543 static const size_t stllen[] =
544 { 3, 6, 4, 5, 3, 8, 3, 8, 6,
545 12, 13, 18, 13, 18, 0};
561 for (
int k = 1; stls[k]; ++k) {
562 if (len == stllen[k]) {
563 if (
type.compare(offset, len, stls[k]) == 0)
575 static const char stln[] =
577 { 1, 1, 1, 1, 3, 3, 2, 2, 1,
580 assert(std::size_t(kind) <
sizeof(stln) &&
"index is out of bounds");
590 for(
size_t i = 0; i < full.length(); ++i) {
592 case '<': { ++level;
break; }
594 if (level == 0)
return i;
599 if (level == 0)
return i;
605 return full.length();
612 return pos +
findNameEnd( {full.data()+pos,full.length()-pos} );
624 if (
a==
"alloc")
return true;
625 if (
a==
"__default_alloc_template<true,0>")
return true;
626 if (
a==
"__malloc_alloc_template<0>")
return true;
628 const static int alloclen = strlen(
"allocator<");
629 if (
a.compare(0,alloclen,
"allocator<") != 0) {
632 a.remove_prefix(alloclen);
639 if (
a.compare(0,k.length(),k) != 0) {
643 std::string valuepart;
646 std::string norm_value;
649 if (valuepart != norm_value) {
652 a.remove_prefix(end);
654 a.remove_prefix(k.length());
657 if (
a.compare(0,1,
">")!=0 &&
a.compare(0,2,
" >")!=0) {
669 const char *keyclassname,
670 const char *valueclassname)
672 if (
IsDefAlloc(allocname,keyclassname))
return true;
677 const static int alloclen = strlen(
"allocator<");
678 if (
a.compare(0,alloclen,
"allocator<") != 0) {
681 a.remove_prefix(alloclen);
685 const static int pairlen = strlen(
"pair<");
686 if (
a.compare(0,pairlen,
"pair<") != 0) {
689 a.remove_prefix(pairlen);
691 const static int constlen = strlen(
"const");
692 if (
a.compare(0,constlen+1,
"const ") == 0) {
693 a.remove_prefix(constlen+1);
700 if (k.compare(0,constlen+1,
"const ") == 0) {
701 k.remove_prefix(constlen+1);
704 if (
a.compare(0,k.length(),k) != 0) {
708 std::string alloc_keypart;
711 std::string norm_key;
714 if (alloc_keypart != norm_key) {
715 if ( norm_key[norm_key.length()-1] ==
'*' ) {
719 norm_key +=
" const";
721 if (alloc_keypart != norm_key) {
725 a.remove_prefix(end);
727 size_t end = k.length();
728 if ( (
a[end-1] ==
'*') ||
a[end]==
' ' ) {
729 size_t skipSpace = (
a[end] ==
' ');
730 if (
a.compare(end+skipSpace,constlen,
"const") == 0) {
731 end += constlen+skipSpace;
734 a.remove_prefix(end);
746 if (
a.compare(0,
v.length(),
v) != 0) {
750 std::string valuepart;
753 std::string norm_value;
756 if (valuepart != norm_value) {
759 a.remove_prefix(end);
761 a.remove_prefix(
v.length());
764 if (
a.compare(0,1,
">")!=0 &&
a.compare(0,2,
" >")!=0) {
775static bool IsDefElement(
const char *elementName,
const char* defaultElementName,
const char *classname)
777 string c = elementName;
781 const int elementlen = strlen(defaultElementName);
782 if (
c.compare(pos,elementlen,defaultElementName) != 0) {
787 string k = classname;
788 if (
c.compare(pos,k.length(),k) != 0) {
797 std::string norm_key;
800 if (keypart != norm_key) {
808 if (
c.compare(pos,1,
">")!=0 &&
c.compare(pos,2,
" >")!=0) {
859 norm_name = std::string(
name);
874 std::string
first, second;
878 if (!second.empty() && second.back() ==
'>')
888 if (norm_name.length()>2 && norm_name[0]==
':' && norm_name[1]==
':') {
889 norm_name.erase(0,2);
892 if (gInterpreterHelper) {
894 std::string typeresult;
898 if (!typeresult.empty()) norm_name = typeresult;
919 static const char* longlong_s =
"long long";
920 static const char* ulonglong_s =
"unsigned long long";
921 static const unsigned int longlong_len = strlen(longlong_s);
922 static const unsigned int ulonglong_len = strlen(ulonglong_s);
924 string result = original;
927 while( (pos = result.find(ulonglong_s,pos) ) >=0 ) {
928 result.replace(pos, ulonglong_len,
"ULong64_t");
931 while( (pos = result.find(longlong_s,pos) ) >=0 ) {
932 result.replace(pos, longlong_len,
"Long64_t");
942 const char *lastPos = original;
945 for(
auto cursor = original; *cursor !=
'\0'; ++cursor) {
946 if ( *cursor ==
'<' || *cursor ==
'(') ++depth;
947 else if ( *cursor ==
'>' || *cursor ==
')' ) --depth;
948 else if ( *cursor ==
':' ) {
949 if (depth==0 && *(cursor+1) ==
':' && *(cursor+2) !=
'\0') {
964 const char *t = full.c_str();
965 const unsigned int tlen( full.size() );
967 const char *starloc = t + tlen - 1;
968 bool hasconst =
false;
970 && (starloc-t) > 4 && 0 == strncmp((starloc-4),
"const",5)
971 && ( (*(starloc-5)) ==
' ' || (*(starloc-5)) ==
'*' || (*(starloc-5)) ==
'&'
972 || (*(starloc-5)) ==
'>' || (*(starloc-5)) ==
']') ) {
975 if ((*starloc-1)==
' ') {
981 if ( hasconst || (*starloc)==
'*' || (*starloc)==
'&' || (*starloc)==
']' ) {
982 bool isArray = ( (*starloc)==
']' );
983 while( t<=(starloc-1) && ((*(starloc-1))==
'*' || (*(starloc-1))==
'&' || (*(starloc-1))==
't' || isArray)) {
986 isArray = ! ( (*starloc)==
'[' );
987 }
else if ( (*(starloc-1))==
't' ) {
988 if ( (starloc-1-t) > 5 && 0 == strncmp((starloc-5),
"const",5)
989 && ( (*(starloc-6)) ==
' ' || (*(starloc-6)) ==
'*' || (*(starloc-6)) ==
'&'
990 || (*(starloc-6)) ==
'>' || (*(starloc-6)) ==
']')) {
1001 if ((*(starloc-1))==
' ') {
1006 const unsigned int starlen = strlen(starloc);
1007 full.erase(tlen-starlen,starlen);
1008 }
else if (hasconst) {
1010 const unsigned int starlen = strlen(starloc);
1011 full.erase(tlen-starlen,starlen);
1031 if (strlen(
type)==0)
return 0;
1033 int cleantypeMode = 1 ;
1042 unsigned int const_offset = (0==strncmp(
"const ",full.c_str(),6)) ? 6 : 0;
1043 bool isString =
false;
1044 bool isStdString =
false;
1045 size_t std_offset = const_offset;
1046 static const char* basic_string_std =
"std::basic_string<char";
1047 static const unsigned int basic_string_std_len = strlen(basic_string_std);
1049 if (full.compare(const_offset,basic_string_std_len,basic_string_std) == 0
1050 && full.size() > basic_string_std_len) {
1054 }
else if (full.compare(const_offset,basic_string_std_len-5,basic_string_std+5) == 0
1055 && full.size() > (basic_string_std_len-5)) {
1058 }
else if (full.find(
"basic_string") != std::string::npos) {
1059 size_t len =
StdLen(full.c_str() + const_offset);
1060 if (len && len != 5 && full.compare(const_offset + len, basic_string_std_len-5, basic_string_std+5) == 0) {
1067 size_t offset = basic_string_std_len - 5;
1068 offset += std_offset;
1069 if ( full[offset] ==
'>' ) {
1071 }
else if (full[offset] ==
',') {
1073 if (full.compare(offset, 5,
"std::") == 0) {
1076 static const char* char_traits_s =
"char_traits<char>";
1077 static const unsigned int char_traits_len = strlen(char_traits_s);
1078 if (full.compare(offset, char_traits_len, char_traits_s) == 0) {
1079 offset += char_traits_len;
1080 if ( full[offset] ==
'>') {
1082 }
else if (full[offset] ==
' ' && full[offset+1] ==
'>') {
1085 }
else if (full[offset] ==
',') {
1087 if (full.compare(offset, 5,
"std::") == 0) {
1090 static const char* allocator_s =
"allocator<char>";
1091 static const unsigned int allocator_len = strlen(allocator_s);
1092 if (full.compare(offset, allocator_len, allocator_s) == 0) {
1093 offset += allocator_len;
1094 if ( full[offset] ==
'>') {
1096 }
else if (full[offset] ==
' ' && full[offset+1] ==
'>') {
1117 output.push_back(
string());
1119 if (isStdString && !(mode &
kDropStd)) {
1120 output.push_back(
"const std::string");
1122 output.push_back(
"const string");
1125 if (isStdString && !(mode &
kDropStd)) {
1126 output.push_back(
"std::string");
1128 output.push_back(
"string");
1131 if (offset < full.length()) {
1134 string right( full.substr(offset) );
1137 output.back().append(right.c_str()+1);
1148 unsigned int offset = (0==strncmp(
"const ",full.c_str(),6)) ? 6 : 0;
1153 if ( !full.empty() ) {
1157 const char *
c = strchr(full.c_str(),
'<');
1160 output.push_back(
string(full,0,
c - full.c_str()));
1164 int parenthesis = 0;
1165 for(cursor =
c + 1; *cursor !=
'\0' && !(level==0 && *cursor ==
'>'); ++cursor) {
1166 if (*cursor ==
'(') {
1169 }
else if (*cursor ==
')') {
1176 case '<': ++level;
break;
1177 case '>': --level;
break;
1180 output.push_back(std::string(
c+1,cursor));
1187 if (*(cursor-1) ==
' ') {
1188 output.push_back(std::string(
c+1,cursor-1));
1190 output.push_back(std::string(
c+1,cursor));
1193 if (*(cursor+1)==
':') {
1196 nestedLoc =
output.size();
1197 output.push_back((cursor+1));
1199 }
else if (level >= 0) {
1201 output.push_back(std::string(
c+1,cursor));
1205 output.push_back(
string());
1232 static const char* remove[] = {
"class",
"const",
"volatile",0};
1233 auto initLengthsVector = []() {
1234 std::vector<size_t> create_lengths;
1235 for (
int k=0; remove[k]; ++k) {
1236 create_lengths.push_back(strlen(remove[k]));
1238 return create_lengths;
1240 static std::vector<size_t> lengths{ initLengthsVector() };
1243 result.reserve(strlen(typeDesc)*2);
1247 for(
c=typeDesc;*
c;
c++) {
1250 if (!isalnum(
c[ 1]) &&
c[ 1] !=
'_')
continue;
1252 if (kbl && (mode>=2 || lev==0)) {
1254 int n = (mode) ? 999 : 1;
1257 for (
int k=0; k<
n && remove[k]; k++) {
1258 int rlen = lengths[k];
1261 if (strncmp(remove[k],
c,rlen))
continue;
1264 if (isalnum(
c[rlen]) ||
c[rlen]==
'_' ||
c[rlen]==
'$')
continue;
1266 c+=rlen-1; done = 1;
break;
1271 kbl = (!isalnum(
c[ 0]) &&
c[ 0]!=
'_' &&
c[ 0]!=
'$' &&
c[0]!=
'[' &&
c[0]!=
']' &&
c[0]!=
'-' &&
c[0]!=
'@');
1275 if (*
c ==
'<' || *
c ==
'(') lev++;
1276 if (lev==0 && !isalnum(*
c)) {
1277 if (!strchr(
"*&:._$ []-@",*
c))
break;
1281 if (
c[0]==
'>' && result.size() && result[result.size()-1]==
'>') result+=
" ";
1285 if (*
c ==
'>' || *
c ==
')') lev--;
1322 size_t len = strlen(
type);
1323 if (len < 2 || strncmp(
type+len-2,
"_t",2) != 0)
return false;
1325 unsigned char offset = 0;
1326 if (strncmp(
type,
"const ",6)==0) { offset += 6; }
1327 static const char *names[] = {
"CallFunc_t",
"ClassInfo_t",
"BaseClassInfo_t",
1328 "DataMemberInfo_t",
"FuncTempInfo_t",
"MethodInfo_t",
"MethodArgInfo_t",
1329 "TypeInfo_t",
"TypedefInfo_t",0};
1331 for(
int k=1;names[k];k++) {
if (strcmp(
type+offset,names[k])==0)
return true;}
1340 size_t offset =
StdLen(classname);
1341 if ( strncmp(classname+offset,
"bitset<",strlen(
"bitset<"))==0)
return true;
1359 if (
type.compare(0,6,
"const ",6) == 0)
1360 type.remove_prefix(6);
1362 while(
type[
type.length()-1]==
'*' ||
1365 type.remove_suffix(1);
1378 auto pos =
type.find(
'<');
1382 for (
decltype(
type.length()) level = 1;
c <
type.length(); ++
c) {
1383 if (
type[
c] ==
'<') ++level;
1384 if (
type[
c] ==
'>') --level;
1385 if (level == 0)
break;
1387 if (
c != (
type.length()-1) ) {
1407 if (strchr(
type,
'<')==0)
return 0;
1418 classname +=
StdLen( classname );
1419 if ( strcmp(classname,
"string")==0 )
return true;
1420 if ( strncmp(classname,
"bitset<",strlen(
"bitset<"))==0)
return true;
1421 if (
IsStdPair(classname) )
return true;
1422 if ( strcmp(classname,
"allocator")==0)
return true;
1423 if ( strncmp(classname,
"allocator<",strlen(
"allocator<"))==0)
return true;
1424 if ( strncmp(classname,
"greater<",strlen(
"greater<"))==0)
return true;
1425 if ( strncmp(classname,
"less<",strlen(
"less<"))==0)
return true;
1426 if ( strncmp(classname,
"equal_to<",strlen(
"equal_to<"))==0)
return true;
1427 if ( strncmp(classname,
"hash<",strlen(
"hash<"))==0)
return true;
1428 if ( strncmp(classname,
"auto_ptr<",strlen(
"auto_ptr<"))==0)
return true;
1430 if ( strncmp(classname,
"vector<",strlen(
"vector<"))==0)
return true;
1431 if ( strncmp(classname,
"list<",strlen(
"list<"))==0)
return true;
1432 if ( strncmp(classname,
"forward_list<",strlen(
"forward_list<"))==0)
return true;
1433 if ( strncmp(classname,
"deque<",strlen(
"deque<"))==0)
return true;
1434 if ( strncmp(classname,
"map<",strlen(
"map<"))==0)
return true;
1435 if ( strncmp(classname,
"multimap<",strlen(
"multimap<"))==0)
return true;
1436 if ( strncmp(classname,
"set<",strlen(
"set<"))==0)
return true;
1437 if ( strncmp(classname,
"multiset<",strlen(
"multiset<"))==0)
return true;
1438 if ( strncmp(classname,
"unordered_set<",strlen(
"unordered_set<"))==0)
return true;
1439 if ( strncmp(classname,
"unordered_multiset<",strlen(
"unordered_multiset<"))==0)
return true;
1440 if ( strncmp(classname,
"unordered_map<",strlen(
"unordered_map<"))==0)
return true;
1441 if ( strncmp(classname,
"unordered_multimap<",strlen(
"unordered_multimap<"))==0)
return true;
1442 if ( strncmp(classname,
"bitset<",strlen(
"bitset<"))==0)
return true;
1461 unsigned int cursor,
1463 unsigned int start_of_type,
1464 unsigned int end_of_type,
1465 unsigned int mod_start_of_type,
1467 std::string &result)
1469 std::string
type(modified && (mod_start_of_type < result.length()) ?
1470 result.substr(mod_start_of_type, string::npos)
1471 : string(tname, start_of_type, end_of_type == 0 ? cursor - start_of_type : end_of_type - start_of_type));
1476 if (!typeresult.empty()) {
1479 result.replace(mod_start_of_type, string::npos,
1484 mod_start_of_type = start_of_type;
1485 result += string(tname,0,start_of_type);
1486 if (constprefix && typeresult.compare(0,6,
"const ",6) == 0) {
1487 result += typeresult.substr(6,string::npos);
1489 result += typeresult;
1492 }
else if (modified) {
1493 result.replace(mod_start_of_type, string::npos,
1497 if (end_of_type != 0 && end_of_type!=cursor) {
1498 result += std::string(tname,end_of_type,cursor-end_of_type);
1505 if (end_of_type != 0 && end_of_type!=cursor) {
1506 result += std::string(tname,end_of_type,cursor-end_of_type);
1516 unsigned int &cursor,
1518 std::string &result)
1525 bool constprefix =
false;
1527 if (tname[cursor]==
' ') {
1530 result += string(tname,0,cursor);
1532 while (tname[cursor]==
' ') ++cursor;
1535 if (tname[cursor]==
'c' && (cursor+6<len)) {
1536 if (strncmp(tname+cursor,
"const ",6) == 0) {
1538 if (modified) result +=
"const ";
1544 if (len > 2 && strncmp(tname+cursor,
"::",2) == 0) {
1548 unsigned int start_of_type = cursor;
1549 unsigned int end_of_type = 0;
1550 unsigned int mod_start_of_type = result.length();
1551 unsigned int prevScope = cursor;
1552 for ( ; cursor<len; ++cursor) {
1553 switch (tname[cursor]) {
1555 if ((cursor+1)>=len || tname[cursor+1]!=
':') {
1557 if (modified) result += (tname+prevScope);
1562 scope = result.substr(mod_start_of_type, string::npos);
1563 scope += std::string(tname+prevScope,cursor-prevScope);
1565 scope = std::string(tname, start_of_type, cursor - start_of_type);
1567 std::string scoperesult;
1568 bool isInlined =
false;
1572 if (!scoperesult.empty()) {
1575 if (constprefix && scoperesult.compare(0,6,
"const ",6) != 0) mod_start_of_type -= 6;
1576 result.replace(mod_start_of_type, string::npos,
1581 mod_start_of_type = start_of_type;
1582 result += string(tname,0,start_of_type);
1584 result += scoperesult;
1587 }
else if (modified) {
1588 result += std::string(tname+prevScope,cursor+2-prevScope);
1592 if (modified) result += std::string(tname+prevScope,cursor+2-prevScope);
1593 }
else if (isInlined) {
1597 mod_start_of_type = start_of_type;
1598 result += string(tname,0,start_of_type);
1600 result += string(tname,start_of_type,prevScope - start_of_type);
1602 }
else if (modified) {
1603 result += std::string(tname+prevScope,cursor+2-prevScope);
1607 prevScope = cursor+1;
1613 result += std::string(tname+prevScope,cursor+1-prevScope);
1619 }
while( cursor<len && tname[cursor] ==
',' );
1621 while (cursor<len && tname[cursor+1]==
' ') ++cursor;
1626 if (cursor+2<len && tname[cursor+1]==
':' && tname[cursor+2]==
':') {
1627 if (modified) result +=
"::";
1629 prevScope = cursor+1;
1631 if ( (cursor+1)<len && tname[cursor+1] ==
',') {
1633 if (modified) result +=
',';
1636 if ( (cursor+1)<len && tname[cursor+1] ==
'>') {
1638 if (modified) result +=
" >";
1641 if ( (cursor+1) >= len) {
1644 if (tname[cursor] !=
' ')
break;
1645 if (modified) prevScope = cursor+1;
1652 end_of_type = cursor;
1654 while ((cursor+1)<len && tname[cursor+1] ==
' ') ++cursor;
1656 auto next = cursor+1;
1657 if (strncmp(tname+next,
"const",5) == 0 && ((next+5)==len || tname[next+5] ==
' ' || tname[next+5] ==
'*' || tname[next+5] ==
'&' || tname[next+5] ==
',' || tname[next+5] ==
'>' || tname[next+5] ==
']'))
1662 result += string(tname,0,start_of_type);
1664 mod_start_of_type = start_of_type + 6;
1665 result += string(tname,start_of_type,end_of_type-start_of_type);
1666 }
else if (mod_start_of_type < result.length()) {
1667 result.insert(mod_start_of_type,
"const ");
1668 mod_start_of_type += 6;
1671 mod_start_of_type += 6;
1672 result += string(tname,start_of_type,end_of_type-start_of_type);
1675 end_of_type = cursor+1;
1676 prevScope = end_of_type;
1677 if ((next+5)==len || tname[next+5] ==
',' || tname[next+5] ==
'>' || tname[next+5] ==
'[') {
1680 }
else if (next!=len && tname[next] !=
'*' && tname[next] !=
'&') {
1690 if (tname[cursor] !=
' ') end_of_type = cursor;
1692 auto next = cursor+1;
1693 if (strncmp(tname+next,
"const",5) == 0) {
1694 if ((next+5)==len || tname[next+5] ==
' ' || tname[next+5] ==
'*' || tname[next+5] ==
'&' || tname[next+5] ==
',' || tname[next+5] ==
'>' || tname[next+5] ==
'[') {
1699 (tname[next] ==
' ' || tname[next] ==
'*' || tname[next] ==
'&')) {
1702 if (strncmp(tname+next,
"const",5) == 0) {
1703 if ((next+5)==len || tname[next+5] ==
' ' || tname[next+5] ==
'*' || tname[next+5] ==
'&' || tname[next+5] ==
',' || tname[next+5] ==
'>' || tname[next+5] ==
'[') {
1715 if (modified && prevScope) {
1716 result += std::string(tname+prevScope,(end_of_type == 0 ? cursor : end_of_type)-prevScope);
1720 if (modified) result +=
',';
1724 if (modified && prevScope) {
1725 result += std::string(tname+prevScope,(end_of_type == 0 ? cursor : end_of_type)-prevScope);
1729 if (modified) result +=
'>';
1737 if (prevScope && modified) result += std::string(tname+prevScope,(end_of_type == 0 ? cursor : end_of_type)-prevScope);
1754 if (tname == 0 || tname[0] == 0)
1756 if (!gInterpreterHelper)
1765 if (result.empty())
return tname;
1769 unsigned int len = strlen(tname);
1771 unsigned int cursor = 0;
1772 bool modified =
false;
1775 if (!modified)
return tname;
1789 static const char* sSTLtypes[] = {
1802 "basic_istringstream",
1805 "basic_ostringstream",
1809 "basic_stringstream",
1838 "istreambuf_iterator",
1847 "localedef utility",
1864 "moneypunct_byname",
1876 "ostreambuf_iterator",
1882 "pointer_to_binary_function",
1883 "pointer_to_unary_function",
1887 "raw_storage_iterator",
1906 "unordered_multimap",
1907 "unordered_multiset",
1914 if (tname==0 || tname[0]==0)
return "";
1916 auto initSetSTLtypes = []() {
1917 std::set<std::string> iSetSTLtypes;
1919 const size_t nSTLtypes =
sizeof(sSTLtypes) /
sizeof(
const char*);
1920 for (
size_t i = 0; i < nSTLtypes; ++i)
1921 iSetSTLtypes.insert(sSTLtypes[i]);
1922 return iSetSTLtypes;
1924 static ShuttingDownSignaler<std::set<std::string>> sSetSTLtypes{ initSetSTLtypes() };
1927 size_t len = strlen(tname);
1929 ret.reserve(len + 20);
1933 bool precScope =
false;
1934 while (!(isalnum(tname[
b]) || tname[
b] ==
'_') &&
b < len) {
1935 precScope = (
b < len - 2) && (tname[
b] ==
':') && (tname[
b + 1] ==
':');
1947 while (
e < len && (isalnum(tname[
e]) || tname[
e] ==
'_'))
1951 set<string>::const_iterator iSTLtype = sSetSTLtypes.find(
id);
1952 if (iSTLtype != sSetSTLtypes.end())
1967class NameCleanerForIO {
1969 std::vector<std::unique_ptr<NameCleanerForIO>> fArgumentNodes = {};
1970 NameCleanerForIO* fMother;
1971 bool fHasChanged =
false;
1972 bool AreAncestorsSTLContOrArray()
1974 NameCleanerForIO* mother = fMother;
1975 if (!mother)
return false;
1976 bool isSTLContOrArray =
true;
1977 while (
nullptr != mother){
1980 mother = mother->fMother;
1983 return isSTLContOrArray;
1987 NameCleanerForIO(
const std::string& clName =
"",
1989 NameCleanerForIO* mother =
nullptr):fMother(mother)
1991 if (clName.back() !=
'>') {
1996 std::vector<std::string>
v;
2001 auto argsEnd =
v.end();
2002 auto argsBeginPlusOne = ++
v.begin();
2003 auto argPos = std::find_if(argsBeginPlusOne, argsEnd,
2004 [](std::string& arg){
return (!arg.empty() && arg.front() ==
':');});
2005 if (argPos != argsEnd) {
2006 const int lenght = clName.size();
2007 int wedgeBalance = 0;
2008 int lastOpenWedge = 0;
2009 for (
int i=lenght-1;i>-1;i--) {
2010 auto&
c = clName.at(i);
2014 }
else if (
c ==
'>') {
2016 }
else if (
c ==
':' && 0 == wedgeBalance) {
2018 auto nameToClean = clName.substr(0,i-1);
2019 NameCleanerForIO node(nameToClean, mode);
2020 auto cleanName = node.ToString();
2021 fHasChanged = node.HasChanged();
2027 cleanName += clName.substr(i+1,lastOpenWedge-i-1);
2030 auto lastTemplate = &clName.data()[i+1];
2042 unsigned int nargs =
v.size() - 2;
2043 for (
unsigned int i=0;i<nargs;++i) {
2044 fArgumentNodes.emplace_back(
new NameCleanerForIO(
v[i+1],mode,
this));
2048 bool HasChanged()
const {
return fHasChanged;}
2052 std::string
name(fName);
2054 if (fArgumentNodes.empty())
return name;
2059 name = fArgumentNodes.front()->ToString();
2062 tst.ShortType(
name, 1);
2068 auto stlContType = AreAncestorsSTLContOrArray();
2070 name = fArgumentNodes.front()->ToString();
2077 for (
auto& node : fArgumentNodes) {
2078 name += node->ToString() +
",";
2079 fHasChanged |= node->HasChanged();
2082 name +=
name.back() ==
'>' ?
" >" :
">";
2086 const std::string& GetName() {
return fName;}
2087 const std::vector<std::unique_ptr<NameCleanerForIO>>* GetChildNodes()
const {
return &fArgumentNodes;}
2103 NameCleanerForIO node(templateInstanceName, mode);
2104 auto nameForIO = node.ToString();
2106 *hasChanged = node.HasChanged();
2115 std::string& typeNameBuf,
2116 std::array<int, 5>& maxIndices,
2122 NameCleanerForIO node(typeName);
2125 auto childNodes = node.GetChildNodes();
2126 for (ndim = 1;ndim <=5 ; ndim++) {
2127 maxIndices[ndim-1] = std::atoi(childNodes->back()->GetName().c_str());
2128 auto& frontNode = childNodes->front();
2129 typeNameBuf = frontNode->GetName();
2131 typeNameBuf = frontNode->ToString();
2134 childNodes = frontNode->GetChildNodes();
2147 const char* mangled_name = ti.name();
2153struct FunctionSplitInfo {
2155 std::string fReturnType;
2158 std::string fScopeName;
2161 std::string fFunctionName;
2165 std::vector<std::string> fFunctionTemplateArguments;
2168 std::vector<std::string> fFunctionParameters;
2175 std::size_t FindNonNestedNeedles(std::string_view haystack, string_view needles)
2177 std::stack<char> expected;
2178 for (std::size_t pos = 0, end = haystack.length(); pos < end; ++pos) {
2179 char c = haystack[pos];
2180 if (expected.empty()) {
2181 if (needles.find(
c) != std::string_view::npos)
2184 if (
c == expected.top()) {
2190 case '<': expected.emplace(
'>');
break;
2191 case '(': expected.emplace(
')');
break;
2192 case '[': expected.emplace(
']');
break;
2195 return std::string_view::npos;
2199 std::size_t FindNonNestedDoubleColons(std::string_view haystack)
2201 std::size_t lenHaystack = haystack.length();
2202 std::size_t prevAfterColumn = 0;
2204 std::size_t posColumn = FindNonNestedNeedles(haystack.substr(prevAfterColumn),
":");
2205 if (posColumn == std::string_view::npos)
2206 return std::string_view::npos;
2207 prevAfterColumn += posColumn;
2209 if (prevAfterColumn + 1 >= lenHaystack)
2210 return std::string_view::npos;
2213 if (haystack[prevAfterColumn] ==
':')
2214 return prevAfterColumn - 1;
2218 return std::string_view::npos;
2221 std::string_view StripSurroundingSpace(std::string_view str)
2223 while (!str.empty() && std::isspace(str[0]))
2224 str.remove_prefix(1);
2225 while (!str.empty() && std::isspace(str.back()))
2226 str.remove_suffix(1);
2230 std::string
ToString(std::string_view sv)
2234 return std::string(sv.data(), sv.length());
2247 std::size_t posArgs = FindNonNestedNeedles(decl,
"(");
2248 std::string_view declNoArgs = decl.substr(0, posArgs);
2250 std::size_t prevAfterWhiteSpace = 0;
2251 static const char whitespace[] =
" \t\n";
2252 while (declNoArgs.length() > prevAfterWhiteSpace) {
2253 std::size_t posWS = FindNonNestedNeedles(declNoArgs.substr(prevAfterWhiteSpace), whitespace);
2254 if (posWS == std::string_view::npos)
2256 prevAfterWhiteSpace += posWS + 1;
2257 while (declNoArgs.length() > prevAfterWhiteSpace
2258 && strchr(whitespace, declNoArgs[prevAfterWhiteSpace]))
2259 ++prevAfterWhiteSpace;
2263 std::size_t endReturn = prevAfterWhiteSpace;
2264 while (declNoArgs.length() > endReturn
2265 && strchr(
"&* \t \n", declNoArgs[endReturn]))
2268 result.
fReturnType = ToString(StripSurroundingSpace(declNoArgs.substr(0, endReturn)));
2271 std::string_view scopeFunctionTmplt = declNoArgs.substr(endReturn);
2272 std::size_t prevAtScope = FindNonNestedDoubleColons(scopeFunctionTmplt);
2273 while (prevAtScope != std::string_view::npos
2274 && scopeFunctionTmplt.length() > prevAtScope + 2) {
2275 std::size_t posScope = FindNonNestedDoubleColons(scopeFunctionTmplt.substr(prevAtScope + 2));
2276 if (posScope == std::string_view::npos)
2278 prevAtScope += posScope + 2;
2281 std::size_t afterScope = prevAtScope + 2;
2282 if (prevAtScope == std::string_view::npos) {
2287 result.
fScopeName = ToString(StripSurroundingSpace(scopeFunctionTmplt.substr(0, prevAtScope)));
2288 std::string_view funcNameTmplArgs = scopeFunctionTmplt.substr(afterScope);
2291 std::size_t posTmpltOpen = FindNonNestedNeedles(funcNameTmplArgs,
"<");
2292 if (posTmpltOpen != std::string_view::npos) {
2293 result.
fFunctionName = ToString(StripSurroundingSpace(funcNameTmplArgs.substr(0, posTmpltOpen)));
2296 std::string_view tmpltArgs = funcNameTmplArgs.substr(posTmpltOpen + 1);
2297 std::size_t posTmpltClose = FindNonNestedNeedles(tmpltArgs,
">");
2298 if (posTmpltClose != std::string_view::npos) {
2299 tmpltArgs = tmpltArgs.substr(0, posTmpltClose);
2300 std::size_t prevAfterArg = 0;
2301 while (tmpltArgs.length() > prevAfterArg) {
2302 std::size_t posComma = FindNonNestedNeedles(tmpltArgs.substr(prevAfterArg),
",");
2303 if (posComma == std::string_view::npos) {
2307 prevAfterArg += posComma + 1;
2313 result.
fFunctionName = ToString(StripSurroundingSpace(funcNameTmplArgs));
2317 if (posArgs != std::string_view::npos) {
2319 std::string_view params = decl.substr(posArgs + 1);
2320 std::size_t posEndArgs = FindNonNestedNeedles(params,
")");
2321 if (posEndArgs != std::string_view::npos) {
2322 params = params.substr(0, posEndArgs);
2323 std::size_t prevAfterArg = 0;
2324 while (params.length() > prevAfterArg) {
2325 std::size_t posComma = FindNonNestedNeedles(params.substr(prevAfterArg),
",");
2326 if (posComma == std::string_view::npos) {
2327 result.
fFunctionParameters.emplace_back(ToString(StripSurroundingSpace(params.substr(prevAfterArg))));
2330 result.
fFunctionParameters.emplace_back(ToString(StripSurroundingSpace(params.substr(prevAfterArg, posComma))));
2331 prevAfterArg += posComma + 1;
static void R__FindTrailing(std::string &full, std::string &stars)
static void ResolveTypedefImpl(const char *tname, unsigned int len, unsigned int &cursor, bool &modified, std::string &result)
static size_t findNameEnd(const std::string_view full)
static bool IsDefElement(const char *elementName, const char *defaultElementName, const char *classname)
return whether or not 'elementName' is the STL default Element for type 'classname'
static void ResolveTypedefProcessType(const char *tname, unsigned int, unsigned int cursor, bool constprefix, unsigned int start_of_type, unsigned int end_of_type, unsigned int mod_start_of_type, bool &modified, std::string &result)
static void RemoveStd(std::string &name, size_t pos=0)
Remove std:: and any potential inline namespace (well compiler detail namespace.
static size_t StdLen(const std::string_view name)
Return the length, if any, taken by std:: and any potential inline namespace (well compiler detail na...
A spin mutex-as-code-guard class.
virtual bool GetPartiallyDesugaredNameWithScopeHandling(const std::string &, std::string &, bool=true)=0
virtual ~TInterpreterLookupHelper()
virtual bool IsAlreadyPartiallyDesugaredName(const std::string &, const std::string &)=0
virtual bool IsDeclaredScope(const std::string &, bool &)=0
virtual void ShuttingDownSignal()=0
virtual void GetPartiallyDesugaredName(std::string &)=0
virtual bool ExistingTypeCheck(const std::string &, std::string &)=0
basic_string_view< char > string_view
std::string ToString(const T &val)
Utility function for conversion to strings.
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
bool IsDefComp(const char *comp, const char *classname)
return whether or not 'compare' is the STL default comparator for type 'classname'
std::string ResolveTypedef(const char *tname, bool resolveAll=false)
std::string CleanType(const char *typeDesc, int mode=0, const char **tail=0)
Cleanup type description, redundant blanks removed and redundant tail ignored return *tail = pointer ...
bool IsStdArray(std::string_view name)
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
bool IsDefHash(const char *hashname, const char *classname)
return whether or not 'hashname' is the STL default hash for type 'classname'
bool IsStdPair(std::string_view name)
bool IsInterpreterDetail(const char *type)
Return true if the type is one the interpreter details which are only forward declared (ClassInfo_t e...
std::string InsertStd(const char *tname)
bool SplitFunction(std::string_view decl, FunctionSplitInfo &result)
Split a function declaration into its different parts.
std::string GetLong64_Name(const char *original)
Replace 'long long' and 'unsigned long long' by 'Long64_t' and 'ULong64_t'.
bool IsDefPred(const char *predname, const char *classname)
return whether or not 'predname' is the STL default predicate for type 'classname'
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.
const char * GetUnqualifiedName(const char *name)
Return the start of the unqualified name include in 'original'.
bool IsVectorBool(const char *name)
void Init(TClassEdit::TInterpreterLookupHelper *helper)
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.
char * DemangleName(const char *mangled_name, int &errorCode)
bool IsArtificial(std::string_view name)
bool GetStdArrayProperties(const char *typeName, std::string &typeNameBuf, std::array< int, 5 > &maxIndices, int &ndim)
std::string GetNameForIO(const std::string &templateInstanceName, TClassEdit::EModType mode=TClassEdit::kNone, bool *hasChanged=nullptr)
int STLArgs(int kind)
Return number of arguments for STL container before allocator.
int GetSplit(const char *type, std::vector< std::string > &output, int &nestedLoc, EModType mode=TClassEdit::kNone)
Stores in output (after emptying it) the split type.
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
bool IsDefAlloc(const char *alloc, const char *classname)
return whether or not 'allocname' is the STL default allocator for type 'classname'
bool IsUniquePtr(std::string_view name)
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset<number> or bitset<number>
ROOT::ESTLType UnderlyingIsSTLCont(std::string_view type)
Return the type of STL collection, if any, that is the underlying type of the given type.
EComplexType GetComplexType(const char *)
Result of splitting a function declaration into fReturnType fScopeName::fFunctionName<fFunctionTempla...
std::string fFunctionName
Name of the function.
std::vector< std::string > fFunctionTemplateArguments
Template arguments of the function template specialization, if any; will contain one element "" for f...
std::string fScopeName
Name of the scope qualification of the function, possibly empty.
std::vector< std::string > fFunctionParameters
Function parameters.
std::string fReturnType
Return type of the function, might be empty if the function declaration string did not provide it.
bool IsTemplate()
Check if the type is a template.
int IsSTLCont(int testAlloc=0) const
type : type name: vector<list<classA,allocator>,allocator> testAlloc: if true, we test allocator,...
TSplitType(const char *type2split, EModType mode=TClassEdit::kNone)
default constructor
std::vector< std::string > fElements
ROOT::ESTLType IsInSTL() const
type : type name: vector<list<classA,allocator>,allocator>[::iterator] result: 0 : not stl container ...
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.
static void output(int code)