32using std::string, std::string_view, std::vector, std::set;
38struct ShuttingDownSignaler :
public T {
41 ShuttingDownSignaler() =
default;
42 ShuttingDownSignaler(T &&in) : T(std::move(in)) {}
44 ~ShuttingDownSignaler()
46 if (gInterpreterHelper)
47 gInterpreterHelper->ShuttingDownSignal();
53void RemoveSpace(std::string_view &s)
55 while (!s.empty() && s[0] ==
' ')
63size_t StdLen(
const std::string_view
name)
66 if (
name.compare(0, 5,
"std::") == 0) {
71 if (gInterpreterHelper) {
72 for (
size_t i = 5; i <
name.length(); ++i) {
76 std::string scope(
name.data(), i);
80 static ShuttingDownSignaler<std::set<std::string>> gInlined;
81 static std::atomic_flag spinFlag = ATOMIC_FLAG_INIT;
86 isInlined = (gInlined.find(scope) != gInlined.end());
91 if (i + 1 <
name.length() &&
name[i + 1] ==
':') {
95 std::string scoperesult;
96 if (!gInterpreterHelper->ExistingTypeCheck(scope, scoperesult) &&
97 gInterpreterHelper->IsDeclaredScope(scope, isInlined)) {
101 gInlined.insert(scope);
104 if (i + 1 <
name.length() &&
name[i + 1] ==
':') {
122void RemoveStd(std::string &
name,
size_t pos = 0)
124 size_t len = StdLen({
name.data() + pos,
name.length() - pos});
134void RemoveStd(std::string_view &
name)
145void RemoveScopeResolution(std::string &
name)
147 if (
name.length() > 2 &&
name[0] ==
':' &&
name[1] ==
':') {
158 if (0 == strncmp(clName,
"complex<", 8)) {
159 const char *clNamePlus8 = clName + 8;
160 if (0 == strcmp(
"float>", clNamePlus8)) {
161 return EComplexType::kFloat;
163 if (0 == strcmp(
"double>", clNamePlus8)) {
164 return EComplexType::kDouble;
166 if (0 == strcmp(
"int>", clNamePlus8)) {
167 return EComplexType::kInt;
169 if (0 == strcmp(
"long>", clNamePlus8)) {
170 return EComplexType::kLong;
173 return EComplexType::kNone;
184 if (
this == gInterpreterHelper)
185 gInterpreterHelper =
nullptr;
192 gInterpreterHelper = helper;
228 if (fElements[0].empty())
return 0;
229 int numb = fElements.size();
230 if (!fElements[numb-1].empty() && fElements[numb-1][0]==
'*') --numb;
232 if ( fNestedLocation ) {
238 int kind =
STLKind(fElements[0]);
243 if (testAlloc && (numb-1 > nargs) && !
IsDefAlloc(fElements[numb-1].c_str(),fElements[1].c_str())) {
255 if (k<0) kind = -kind;
261 if(kind>2) kind = - kind;
281 int narg = fElements.size();
292 if (fElements[narg-1].empty() ==
false &&
293 (fElements[narg-1][0]==
'*'
294 || fElements[narg-1][0]==
'&'
295 || fElements[narg-1][0]==
'['
296 || 0 == fElements[narg-1].compare(0,6,
"const*")
297 || 0 == fElements[narg-1].compare(0,6,
"const&")
298 || 0 == fElements[narg-1].compare(0,6,
"const[")
299 || 0 == fElements[narg-1].compare(
"const")
302 if ((
mode&1)==0) tailLoc = narg-1;
304 else { assert(fElements[narg-1].empty()); };
308 if (fNestedLocation) narg--;
313 const int kind =
STLKind(fElements[0]);
314 const int iall =
STLArgs(kind);
318 while(narg-1>iall) { fElements.pop_back(); narg--;}
319 if (!fElements[0].empty() && tailLoc) {
322 fElements[0].clear();
330 bool allocRemoved =
false;
336 if (narg-1 == iall+1) {
338 bool dropAlloc =
false;
353 dropAlloc =
IsDefAlloc(fElements[iall+1].c_str(),fElements[1].c_str());
359 dropAlloc =
IsDefAlloc(fElements[iall+1].c_str(),fElements[1].c_str(),fElements[2].c_str());
377 if (
IsDefComp( fElements[iall].c_str(), fElements[1].c_str() ) ) {
392 if (!allocRemoved && narg-1 == iall+1) {
396 if (narg-1 == iall) narg--;
419 bool predRemoved =
false;
422 if (
IsDefPred( fElements[iall].c_str(), fElements[1].c_str() ) ) {
429 if (
IsDefHash( fElements[iall-1].c_str(), fElements[1].c_str() ) ) {
437 unsigned int offset = (0==strncmp(
"const ",fElements[0].c_str(),6)) ? 6 : 0;
438 offset += (0==strncmp(
"std::",fElements[0].c_str()+
offset,5)) ? 5 : 0;
439 if (0 == strcmp(fElements[0].c_str()+
offset,
"__shared_ptr"))
442 static const std::string sharedPtrDef = std::to_string(__gnu_cxx::__default_lock_policy);
444 static const std::string sharedPtrDef = std::to_string(2);
446 if (fElements[2] == sharedPtrDef) {
454 for (
int i=1;i<narg; i++) {
455 if (!strchr(fElements[i].c_str(),
'<')) {
460 unsigned int offset = (0==strncmp(
"const ",fElements[i].c_str(),6)) ? 6 : 0;
461 RemoveStd( fElements[i],
offset );
471 if (gInterpreterHelper &&
472 (gInterpreterHelper->ExistingTypeCheck(fElements[i], typeresult)
473 || gInterpreterHelper->GetPartiallyDesugaredNameWithScopeHandling(fElements[i], typeresult))) {
474 if (!typeresult.empty() && typeresult != fElements[i]) {
482 unsigned int tailOffset = 0;
483 if (tailLoc && fElements[tailLoc].compare(0,5,
"const") == 0) {
487 if (!fElements[0].empty()) {answ += fElements[0]; answ +=
"<";}
496 int nargNonDefault = 0;
497 std::string nonDefName = answ;
499 std::string nameSuperLong = fName;
500 if (gInterpreterHelper)
501 gInterpreterHelper->GetPartiallyDesugaredName(nameSuperLong);
502 while (++nargNonDefault < narg) {
505 const char* closeTemplate =
" >";
506 if (nonDefName[nonDefName.length() - 1] !=
'>')
508 string nondef = nonDefName + closeTemplate;
509 if (gInterpreterHelper &&
510 gInterpreterHelper->IsAlreadyPartiallyDesugaredName(nondef, nameSuperLong))
512 if (nargNonDefault>1) nonDefName +=
",";
513 nonDefName += fElements[nargNonDefault];
515 if (nargNonDefault < narg)
516 narg = nargNonDefault;
520 {
for (
int i=1;i<narg-1; i++) { answ += fElements[i]; answ+=
",";} }
521 if (narg>1) { answ += fElements[narg-1]; }
523 if (!fElements[0].empty()) {
524 if ( answ.at(answ.size()-1) ==
'>') {
530 if (fNestedLocation) {
533 answ += fElements[fNestedLocation];
536 if (tailLoc) answ += fElements[tailLoc].c_str()+tailOffset;
543 return !fElements[0].empty();
552 if (
type.length() == 0)
555 if (
type.compare(0,6,
"const ")==0) {
offset += 6; }
562 static const char *stls[] =
563 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
564 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",
nullptr};
565 static const size_t stllen[] =
566 { 3, 6, 4, 5, 3, 8, 3, 8, 6,
567 12, 13, 18, 13, 18, 0};
583 for (
int k = 1; stls[k]; ++k) {
584 if (
len == stllen[k]) {
599 static const char stln[] =
601 { 1, 1, 1, 1, 3, 3, 2, 2, 1,
604 assert(std::size_t(kind) <
sizeof(stln) &&
"index is out of bounds");
614 for(
size_t i = 0; i < full.length(); ++i) {
616 case '<': { ++level;
break; }
618 if (level == 0)
return i;
623 if (level == 0)
return i;
629 return full.length();
636 return pos +
findNameEnd( {full.data()+pos,full.length()-pos} );
645 string_view
a( allocname );
648 constexpr auto length = std::char_traits<char>::length;
649 constexpr static int clalloclen =
length(
"class ");
650 if (
a.compare(0,clalloclen,
"class ") == 0) {
651 a.remove_prefix(clalloclen);
655 if (
a==
"alloc")
return true;
656 if (
a==
"__default_alloc_template<true,0>")
return true;
657 if (
a==
"__malloc_alloc_template<0>")
return true;
659 constexpr static int alloclen =
length(
"allocator<");
660 if (
a.compare(0,alloclen,
"allocator<") != 0) {
663 a.remove_prefix(alloclen);
668 string_view k = classname;
671 if (
a.compare(0,k.length(),k) != 0) {
675 std::string valuepart;
678 std::string norm_value;
681 if (valuepart != norm_value) {
684 a.remove_prefix(end);
686 a.remove_prefix(k.length());
691 if (
a.compare(0, 1,
">") != 0) {
703 const char *keyclassname,
704 const char *valueclassname)
706 if (
IsDefAlloc(allocname,keyclassname))
return true;
708 string_view
a( allocname );
712 constexpr auto length = std::char_traits<char>::length;
713 constexpr static int alloclen =
length(
"allocator<");
714 if (
a.compare(0,alloclen,
"allocator<") != 0) {
717 a.remove_prefix(alloclen);
722 constexpr static int pairlen =
length(
"pair<");
723 if (
a.compare(0,pairlen,
"pair<") != 0) {
726 a.remove_prefix(pairlen);
728 const static int constlen = strlen(
"const");
729 if (
a.compare(0,constlen+1,
"const ") == 0) {
730 a.remove_prefix(constlen+1);
736 string_view k = keyclassname;
738 if (k.compare(0,constlen+1,
"const ") == 0) {
739 k.remove_prefix(constlen+1);
742 if (
a.compare(0,k.length(),k) != 0) {
746 std::string alloc_keypart;
749 std::string norm_key;
752 if (alloc_keypart != norm_key) {
753 if ( norm_key[norm_key.length()-1] ==
'*' ) {
757 norm_key +=
" const";
759 if (alloc_keypart != norm_key) {
763 a.remove_prefix(end);
766 a.remove_prefix(k.length());
768 if (
a.compare(0, constlen,
"const") == 0) {
769 a.remove_prefix(constlen);
779 string_view
v = valueclassname;
782 if (
a.compare(0,
v.length(),
v) != 0) {
786 std::string valuepart;
789 std::string norm_value;
792 if (valuepart != norm_value) {
795 a.remove_prefix(end);
797 a.remove_prefix(
v.length());
802 if (
a.compare(0, 1,
">") != 0) {
813static bool IsDefElement(
const char *elementName,
const char* defaultElementName,
const char *classname)
815 string c = elementName;
817 size_t pos = StdLen(
c);
819 const int elementlen = strlen(defaultElementName);
820 if (
c.compare(pos,elementlen,defaultElementName) != 0) {
825 string k = classname;
826 if (
c.compare(pos,k.length(),k) != 0) {
835 std::string norm_key;
838 if (keypart != norm_key) {
846 if (
c.compare(pos,1,
">")!=0 &&
c.compare(pos,2,
" >")!=0) {
897 norm_name = std::string(
name);
906 if (gInterpreterHelper) {
914 std::string typeresult;
915 if (gInterpreterHelper->CheckInClassTable(norm_name, typeresult)) {
916 if (!typeresult.empty()) {
917 norm_name = typeresult;
927 if (splitname.fElements.size() == 4 && (splitname.fElements[0] ==
"std::pair" || splitname.fElements[0] ==
"pair" || splitname.fElements[0] ==
"__pair_base")) {
929 std::string first, second;
932 norm_name = splitname.fElements[0] +
"<" + first +
"," + second;
933 if (!second.empty() && second.back() ==
'>')
943 RemoveScopeResolution(norm_name);
945 if (gInterpreterHelper) {
947 std::string typeresult;
948 if (gInterpreterHelper->ExistingTypeCheck(norm_name, typeresult)
949 || gInterpreterHelper->GetPartiallyDesugaredNameWithScopeHandling(norm_name, typeresult)) {
951 if (!typeresult.empty()) {
959 RemoveScopeResolution(norm_name);
981 static const char* longlong_s =
"long long";
982 static const char* ulonglong_s =
"unsigned long long";
983 static const unsigned int longlong_len = strlen(longlong_s);
984 static const unsigned int ulonglong_len = strlen(ulonglong_s);
989 while( (pos =
result.find(ulonglong_s,pos) ) >=0 ) {
990 result.replace(pos, ulonglong_len,
"ULong64_t");
993 while( (pos =
result.find(longlong_s,pos) ) >=0 ) {
994 result.replace(pos, longlong_len,
"Long64_t");
1004 const char *lastPos = original;
1010 else if ( *
cursor ==
':' ) {
1011 if (depth==0 && *(
cursor+1) ==
':' && *(
cursor+2) !=
'\0') {
1026 const char *t = full.c_str();
1027 const unsigned int tlen( full.size() );
1029 const char *starloc = t + tlen - 1;
1030 bool hasconst =
false;
1031 if ( (*starloc)==
't'
1032 && (starloc-t) > 4 && 0 == strncmp((starloc-4),
"const",5)
1033 && ( (*(starloc-5)) ==
' ' || (*(starloc-5)) ==
'*' || (*(starloc-5)) ==
'&'
1034 || (*(starloc-5)) ==
'>' || (*(starloc-5)) ==
']') ) {
1037 if ((*starloc-1)==
' ') {
1043 if ( hasconst || (*starloc)==
'*' || (*starloc)==
'&' || (*starloc)==
']' ) {
1044 bool isArray = ( (*starloc)==
']' );
1045 while( t<=(starloc-1) && ((*(starloc-1))==
'*' || (*(starloc-1))==
'&' || (*(starloc-1))==
't' || isArray)) {
1048 isArray = ! ( (*starloc)==
'[' );
1049 }
else if ( (*(starloc-1))==
't' ) {
1050 if ( (starloc-1-t) > 5 && 0 == strncmp((starloc-5),
"const",5)
1051 && ( (*(starloc-6)) ==
' ' || (*(starloc-6)) ==
'*' || (*(starloc-6)) ==
'&'
1052 || (*(starloc-6)) ==
'>' || (*(starloc-6)) ==
']')) {
1063 if ((*(starloc-1))==
' ') {
1068 const unsigned int starlen = strlen(starloc);
1069 full.erase(tlen-starlen,starlen);
1070 }
else if (hasconst) {
1072 const unsigned int starlen = strlen(starloc);
1073 full.erase(tlen-starlen,starlen);
1093 if (strlen(
type)==0)
return 0;
1095 int cleantypeMode = 1 ;
1104 bool isString =
false;
1105 bool isStdString =
false;
1106 bool isConst =
false;
1107 size_t prefix_offset = 0;
1109 if (full.compare(prefix_offset, 6,
"const ") == 0) {
1113 if (full.compare(prefix_offset, 5,
"std::") == 0) {
1117 if (full.compare(prefix_offset, 9,
"__cxx11::") == 0) {
1120 if (full.compare(prefix_offset, 17,
"basic_string<char") == 0) {
1122 prefix_offset += 17;
1126 size_t offset = prefix_offset;
1127 if ( full[
offset] ==
'>' ) {
1129 }
else if (full[
offset] ==
',') {
1131 if (full.compare(
offset, 5,
"std::") == 0) {
1134 constexpr auto char_traits_s =
"char_traits<char>";
1137 static constexpr unsigned int char_traits_len = std::char_traits<char>::length(char_traits_s);
1138 if (full.compare(
offset, char_traits_len, char_traits_s) == 0) {
1139 offset += char_traits_len;
1140 if ( full[
offset] ==
'>') {
1142 }
else if (full[
offset] ==
' ' && full[
offset+1] ==
'>') {
1145 }
else if (full[
offset] ==
',') {
1147 if (full.compare(
offset, 5,
"std::") == 0) {
1150 static const char* allocator_s =
"allocator<char>";
1151 static const unsigned int allocator_len = strlen(allocator_s);
1152 if (full.compare(
offset, allocator_len, allocator_s) == 0) {
1154 if ( full[
offset] ==
'>') {
1156 }
else if (full[
offset] ==
' ' && full[
offset+1] ==
'>') {
1177 output.push_back(
string());
1180 output.push_back(
"const std::string");
1182 output.push_back(
"const string");
1186 output.push_back(
"std::string");
1188 output.push_back(
"string");
1191 if (
offset < full.length()) {
1194 string right( full.substr(
offset) );
1197 output.back().append(right.c_str()+1);
1198 output.push_back(stars);
1200 output.push_back(
"");
1202 return output.size();
1208 unsigned int offset = (0==strncmp(
"const ",full.c_str(),6)) ? 6 : 0;
1209 RemoveStd( full,
offset );
1213 if ( !full.empty() ) {
1217 const char *
c = strchr(full.c_str(),
'<');
1220 output.push_back(
string(full,0,
c - full.c_str()));
1224 int parenthesis = 0;
1225 for ( ; *
cursor !=
'\0' && !(level == 0 && parenthesis == 0 && *
cursor ==
'>'); ++
cursor) {
1229 }
else if (*
cursor ==
')') {
1236 case '<': ++level;
break;
1237 case '>': --level;
break;
1240 output.push_back(std::string(
c+1,
cursor));
1247 if (*(
cursor-1) ==
' ') {
1248 output.push_back(std::string(
c+1,
cursor-1));
1250 output.push_back(std::string(
c+1,
cursor));
1256 nestedLoc = output.size();
1257 output.push_back((
cursor+1));
1259 }
else if (level >= 0) {
1261 output.push_back(std::string(
c+1,
cursor));
1265 output.push_back(
string());
1266 output.push_back(full);
1269 if (!output.empty()) output.push_back(stars);
1270 return output.size();
1292 constexpr static std::array<const char *, 3> remove{
"class",
"const",
"volatile"};
1293 constexpr static auto lengths = []()
constexpr {
1294 std::array<std::size_t, std::size(remove)> ret{};
1295 for (std::size_t i = 0; i < remove.size(); i++)
1296 ret[i] = std::char_traits<char>::length(remove[i]);
1301 result.reserve(strlen(typeDesc)*2);
1303 std::vector<char> parensStack;
1306 for(
c=typeDesc;*
c;
c++) {
1307 if (std::isspace(
c[0])) {
1309 if (!isalnum(
c[ 1]) &&
c[ 1] !=
'_')
continue;
1318 if (kbl && (
mode>=2 || parensStack.empty())) {
1320 size_t n = (
mode) ? std::size(remove) : 1;
1323 for (
size_t k = 0; k <
n; k++) {
1324 auto rlen = lengths[k];
1327 if (strncmp(remove[k],
c,rlen))
continue;
1330 if (isalnum(
c[rlen]) ||
c[rlen]==
'_' ||
c[rlen]==
'$')
continue;
1332 c+=rlen-1; done = 1;
break;
1337 kbl = (!isalnum(
c[ 0]) &&
c[ 0]!=
'_' &&
c[ 0]!=
'$' &&
c[0]!=
'[' &&
c[0]!=
']' &&
c[0]!=
'-' &&
c[0]!=
'@');
1341 if (*
c ==
'<' || *
c ==
'(')
1342 parensStack.push_back(*
c);
1344 if (parensStack.empty() && !isalnum(*
c)) {
1345 if (!strchr(
"*&:._$ []-@",*
c))
break;
1353 if (*
c ==
'>' && !parensStack.empty() && parensStack.back() ==
'<')
1354 parensStack.pop_back();
1355 else if (*
c ==
')' && !parensStack.empty() && parensStack.back() ==
'(')
1356 parensStack.pop_back();
1381 arglist.ShortType(answer,
mode);
1394 if (
len < 2 || strncmp(
type+
len-2,
"_t",2) != 0)
return false;
1396 unsigned char offset = 0;
1397 if (strncmp(
type,
"const ",6)==0) {
offset += 6; }
1398 static const char *names[] = {
"CallFunc_t",
"ClassInfo_t",
"BaseClassInfo_t",
1399 "DataMemberInfo_t",
"FuncTempInfo_t",
"MethodInfo_t",
"MethodArgInfo_t",
1400 "TypeInfo_t",
"TypedefInfo_t",
nullptr};
1402 for(
int k=1;names[k];k++) {
if (strcmp(
type+
offset,names[k])==0)
return true;}
1411 size_t offset = StdLen(classname);
1412 if ( strncmp(classname+
offset,
"bitset<",std::char_traits<char>::length(
"bitset<"))==0)
return true;
1430 if (
type.compare(0,6,
"const ",6) == 0)
1431 type.remove_prefix(6);
1433 while(
type[
type.length()-1]==
'*' ||
1436 type.remove_suffix(1);
1449 auto pos =
type.find(
'<');
1453 for (
decltype(
type.length()) level = 1;
c <
type.length(); ++
c) {
1454 if (
type[
c] ==
'<') ++level;
1455 if (
type[
c] ==
'>') --level;
1456 if (level == 0)
break;
1458 if (
c != (
type.length()-1) ) {
1478 if (!strchr(
type,
'<'))
return 0;
1481 return arglist.IsSTLCont(testAlloc);
1489 constexpr auto length = std::char_traits<char>::length;
1490 classname += StdLen( classname );
1491 if ( strcmp(classname,
"string")==0 )
return true;
1492 if ( strncmp(classname,
"bitset<",
length(
"bitset<"))==0)
return true;
1493 if (
IsStdPair(classname) )
return true;
1494 if ( strcmp(classname,
"allocator")==0)
return true;
1495 if ( strncmp(classname,
"allocator<",
length(
"allocator<"))==0)
return true;
1496 if ( strncmp(classname,
"greater<",
length(
"greater<"))==0)
return true;
1497 if ( strncmp(classname,
"less<",
length(
"less<"))==0)
return true;
1498 if ( strncmp(classname,
"equal_to<",
length(
"equal_to<"))==0)
return true;
1499 if ( strncmp(classname,
"hash<",
length(
"hash<"))==0)
return true;
1500 if ( strncmp(classname,
"auto_ptr<",
length(
"auto_ptr<"))==0)
return true;
1502 if ( strncmp(classname,
"vector<",
length(
"vector<"))==0)
return true;
1503 if ( strncmp(classname,
"list<",
length(
"list<"))==0)
return true;
1504 if ( strncmp(classname,
"forward_list<",
length(
"forward_list<"))==0)
return true;
1505 if ( strncmp(classname,
"deque<",
length(
"deque<"))==0)
return true;
1506 if ( strncmp(classname,
"map<",
length(
"map<"))==0)
return true;
1507 if ( strncmp(classname,
"multimap<",
length(
"multimap<"))==0)
return true;
1508 if ( strncmp(classname,
"set<",
length(
"set<"))==0)
return true;
1509 if ( strncmp(classname,
"multiset<",
length(
"multiset<"))==0)
return true;
1510 if ( strncmp(classname,
"unordered_set<",
length(
"unordered_set<"))==0)
return true;
1511 if ( strncmp(classname,
"unordered_multiset<",
length(
"unordered_multiset<"))==0)
return true;
1512 if ( strncmp(classname,
"unordered_map<",
length(
"unordered_map<"))==0)
return true;
1513 if ( strncmp(classname,
"unordered_multimap<",
length(
"unordered_multimap<"))==0)
return true;
1514 if ( strncmp(classname,
"bitset<",
length(
"bitset<"))==0)
return true;
1515 if ( strncmp(classname,
"ROOT::VecOps::RVec<",
length(
"ROOT::VecOps::RVec<"))==0)
return true;
1527 && ( splitname.fElements[1] ==
"bool" || splitname.fElements[1]==
"Bool_t");
1536 unsigned int start_of_type,
1537 unsigned int end_of_type,
1538 unsigned int mod_start_of_type,
1542 std::string
type(modified && (mod_start_of_type <
result.length()) ?
1543 result.substr(mod_start_of_type, string::npos)
1544 : string(tname, start_of_type, end_of_type == 0 ?
cursor - start_of_type : end_of_type - start_of_type));
1546 if (gInterpreterHelper->ExistingTypeCheck(
type, typeresult)
1547 || gInterpreterHelper->GetPartiallyDesugaredNameWithScopeHandling(
type, typeresult,
false)) {
1549 if (!typeresult.empty()) {
1552 result.replace(mod_start_of_type, string::npos,
1557 result += string(tname,0,start_of_type);
1558 if (constprefix && typeresult.compare(0,6,
"const ",6) == 0) {
1559 result += typeresult.substr(6,string::npos);
1564 }
else if (modified) {
1565 result.replace(mod_start_of_type, string::npos,
1569 if (end_of_type != 0 && end_of_type!=
cursor) {
1570 result += std::string(tname,end_of_type,
cursor-end_of_type);
1577 if (end_of_type != 0 && end_of_type!=
cursor) {
1578 result += std::string(tname,end_of_type,
cursor-end_of_type);
1597 bool constprefix =
false;
1599 if (tname[
cursor]==
' ') {
1613 if (modified)
result +=
"const ";
1621 unsigned int start_of_type =
cursor;
1622 unsigned int end_of_type = 0;
1623 unsigned int mod_start_of_type =
result.length();
1624 unsigned int prevScope =
cursor;
1630 if (modified)
result += (tname+prevScope);
1635 scope =
result.substr(mod_start_of_type, string::npos);
1636 scope += std::string(tname+prevScope,
cursor-prevScope);
1638 scope = std::string(tname, start_of_type,
cursor - start_of_type);
1640 std::string scoperesult;
1641 bool isInlined =
false;
1642 if (gInterpreterHelper->ExistingTypeCheck(scope, scoperesult)
1643 ||gInterpreterHelper->GetPartiallyDesugaredNameWithScopeHandling(scope, scoperesult)) {
1645 if (!scoperesult.empty()) {
1648 if (constprefix && scoperesult.compare(0,6,
"const ",6) != 0) mod_start_of_type -= 6;
1649 result.replace(mod_start_of_type, string::npos,
1654 mod_start_of_type = start_of_type;
1655 result += string(tname,0,start_of_type);
1660 }
else if (modified) {
1661 result += std::string(tname+prevScope,
cursor+2-prevScope);
1663 }
else if (!gInterpreterHelper->IsDeclaredScope(scope,isInlined)) {
1665 if (modified)
result += std::string(tname+prevScope,
cursor+2-prevScope);
1666 }
else if (isInlined) {
1670 mod_start_of_type = start_of_type;
1671 result += string(tname,0,start_of_type);
1673 result += string(tname,start_of_type,prevScope - start_of_type);
1675 }
else if (modified) {
1676 result += std::string(tname+prevScope,
cursor+2-prevScope);
1691 for (; next !=
cursor && nStars < 2 && next <
len; next++) {
1692 if (
' ' == tname[next]) {
1695 }
else if (
'*' == tname[next]) {
1697 }
else if (
')' == tname[next]) {
1715 result += std::string(tname+prevScope,
cursor+1-prevScope);
1729 if (modified)
result +=
"::";
1735 if (modified)
result +=
',';
1740 if (modified)
result +=
" >";
1745 if (modified)
result +=
")";
1751 if (tname[
cursor] !=
' ')
break;
1752 if (modified) prevScope =
cursor+1;
1764 if (next <
len && 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] ==
')' || tname[next+5] ==
']'))
1769 result += string(tname,0,start_of_type);
1771 mod_start_of_type = start_of_type + 6;
1772 result += string(tname,start_of_type,end_of_type-start_of_type);
1773 }
else if (mod_start_of_type <
result.length()) {
1774 result.insert(mod_start_of_type,
"const ");
1775 mod_start_of_type += 6;
1778 mod_start_of_type += 6;
1779 result += string(tname,start_of_type,end_of_type-start_of_type);
1783 prevScope = end_of_type;
1784 if ((next+5)==
len || tname[next+5] ==
',' || tname[next+5] ==
'>' || tname[next+5] ==
')' || tname[next+5] ==
'[') {
1787 }
else if (next!=
len && tname[next] !=
'*' && tname[next] !=
'&') {
1800 if (next <
len && strncmp(tname+next,
"const",5) == 0) {
1801 if ((next+5)==
len || tname[next+5] ==
' ' || tname[next+5] ==
'*' || tname[next+5] ==
'&' || tname[next+5] ==
',' || tname[next+5] ==
'>' || tname[next+5] ==
')' || tname[next+5] ==
'[') {
1806 (tname[next] ==
' ' || tname[next] ==
'*' || tname[next] ==
'&')) {
1809 if (next <
len && strncmp(tname+next,
"const",5) == 0) {
1810 if ((next+5)==
len || tname[next+5] ==
' ' || tname[next+5] ==
'*' || tname[next+5] ==
'&' || tname[next+5] ==
',' || tname[next+5] ==
'>'|| tname[next+5] ==
')' || tname[next+5] ==
'[') {
1822 if (modified && prevScope) {
1823 result += std::string(tname+prevScope,(end_of_type == 0 ?
cursor : end_of_type)-prevScope);
1827 if (modified)
result +=
',';
1833 if (modified && prevScope) {
1834 result += std::string(tname+prevScope,(end_of_type == 0 ?
cursor : end_of_type)-prevScope);
1846 if (prevScope && modified)
result += std::string(tname+prevScope,(end_of_type == 0 ?
cursor : end_of_type)-prevScope);
1863 if (!tname || *tname == 0)
1865 if (!gInterpreterHelper)
1872 if (gInterpreterHelper->ExistingTypeCheck(tname,
result))
1874 if (
result.empty())
return tname;
1878 unsigned int len = strlen(tname);
1881 bool modified =
false;
1884 if (!modified)
return tname;
1898 static const char* sSTLtypes[] = {
1911 "basic_istringstream",
1914 "basic_ostringstream",
1918 "basic_stringstream",
1947 "istreambuf_iterator",
1956 "localedef utility",
1973 "moneypunct_byname",
1985 "ostreambuf_iterator",
1991 "pointer_to_binary_function",
1992 "pointer_to_unary_function",
1996 "raw_storage_iterator",
2015 "unordered_multimap",
2016 "unordered_multiset",
2023 if (!tname || *tname == 0)
return "";
2025 auto initSetSTLtypes = []() {
2026 std::set<std::string> iSetSTLtypes;
2028 const size_t nSTLtypes =
sizeof(sSTLtypes) /
sizeof(
const char*);
2029 for (
size_t i = 0; i < nSTLtypes; ++i)
2030 iSetSTLtypes.insert(sSTLtypes[i]);
2031 return iSetSTLtypes;
2033 static ShuttingDownSignaler<std::set<std::string>> sSetSTLtypes{ initSetSTLtypes() };
2036 size_t len = strlen(tname);
2038 ret.reserve(
len + 20);
2042 bool precScope =
false;
2043 while (!(isalnum(tname[
b]) || tname[
b] ==
'_') &&
b <
len) {
2044 precScope = (
b <
len - 2) && (tname[
b] ==
':') && (tname[
b + 1] ==
':');
2056 while (
e <
len && (isalnum(tname[
e]) || tname[
e] ==
'_'))
2060 set<string>::const_iterator iSTLtype = sSetSTLtypes.find(
id);
2061 if (iSTLtype != sSetSTLtypes.end())
2078 std::vector<std::unique_ptr<NameCleanerForIO>> fArgumentNodes = {};
2080 bool fHasChanged =
false;
2084 if (!mother)
return false;
2085 bool isSTLContOrArray =
true;
2086 while (
nullptr != mother){
2089 mother = mother->fMother;
2092 return isSTLContOrArray;
2100 if (clName.back() !=
'>') {
2105 std::vector<std::string>
v;
2110 auto argsEnd =
v.end();
2111 auto argsBeginPlusOne = ++
v.begin();
2112 auto argPos = std::find_if(argsBeginPlusOne, argsEnd,
2113 [](std::string& arg){
return (!arg.empty() && arg.front() ==
':');});
2114 if (argPos != argsEnd) {
2115 const int length = clName.size();
2116 int wedgeBalance = 0;
2117 int lastOpenWedge = 0;
2118 for (
int i=
length-1;i>-1;i--) {
2119 auto&
c = clName.at(i);
2123 }
else if (
c ==
'>') {
2125 }
else if (
c ==
':' && 0 == wedgeBalance) {
2127 auto nameToClean = clName.substr(0,i-1);
2136 cleanName += clName.substr(i+1,lastOpenWedge-i-1);
2139 auto lastTemplate = &clName.data()[i+1];
2151 unsigned int nargs =
v.size() - 2;
2152 for (
unsigned int i=0;i<nargs;++i) {
2161 std::string
name(fName);
2163 if (fArgumentNodes.empty())
return name;
2168 name = fArgumentNodes.front()->ToString();
2171 tst.ShortType(
name, 1);
2178 auto stlContType = AreAncestorsSTLContOrArray();
2180 name = fArgumentNodes.front()->ToString();
2187 for (
auto& node : fArgumentNodes) {
2188 name += node->ToString() +
",";
2189 fHasChanged |= node->HasChanged();
2192 name +=
name.back() ==
'>' ?
" >" :
">";
2197 const std::vector<std::unique_ptr<NameCleanerForIO>>*
GetChildNodes()
const {
return &fArgumentNodes;}
2225 std::string& typeNameBuf,
2226 std::array<int, 5>& maxIndices,
2236 for (ndim = 1;ndim <=5 ; ndim++) {
2237 maxIndices[ndim-1] = std::atoi(childNodes->back()->GetName().c_str());
2238 auto& frontNode = childNodes->front();
2239 typeNameBuf = frontNode->GetName();
2241 typeNameBuf = frontNode->ToString();
2244 childNodes = frontNode->GetChildNodes();
2257 const char* mangled_name = ti.name();
2263struct FunctionSplitInfo {
2265 std::string fReturnType;
2268 std::string fScopeName;
2271 std::string fFunctionName;
2275 std::vector<std::string> fFunctionTemplateArguments;
2278 std::vector<std::string> fFunctionParameters;
2285 std::size_t FindNonNestedNeedles(std::string_view haystack, string_view needles)
2287 std::stack<char> expected;
2288 for (std::size_t pos = 0, end = haystack.length(); pos < end; ++pos) {
2289 char c = haystack[pos];
2290 if (expected.empty()) {
2291 if (needles.find(
c) != std::string_view::npos)
2294 if (
c == expected.top()) {
2300 case '<': expected.emplace(
'>');
break;
2301 case '(': expected.emplace(
')');
break;
2302 case '[': expected.emplace(
']');
break;
2305 return std::string_view::npos;
2309 std::size_t FindNonNestedDoubleColons(std::string_view haystack)
2311 std::size_t lenHaystack = haystack.length();
2312 std::size_t prevAfterColumn = 0;
2314 std::size_t posColumn = FindNonNestedNeedles(haystack.substr(prevAfterColumn),
":");
2315 if (posColumn == std::string_view::npos)
2316 return std::string_view::npos;
2317 prevAfterColumn += posColumn;
2319 if (prevAfterColumn + 1 >= lenHaystack)
2320 return std::string_view::npos;
2323 if (haystack[prevAfterColumn] ==
':')
2324 return prevAfterColumn - 1;
2328 return std::string_view::npos;
2331 std::string_view StripSurroundingSpace(std::string_view str)
2333 while (!str.empty() && std::isspace(str[0]))
2334 str.remove_prefix(1);
2335 while (!str.empty() && std::isspace(str.back()))
2336 str.remove_suffix(1);
2340 std::string
ToString(std::string_view sv)
2344 return std::string(sv.data(), sv.length());
2357 std::size_t posArgs = FindNonNestedNeedles(decl,
"(");
2358 std::string_view declNoArgs = decl.substr(0, posArgs);
2360 std::size_t prevAfterWhiteSpace = 0;
2361 static const char whitespace[] =
" \t\n";
2362 while (declNoArgs.length() > prevAfterWhiteSpace) {
2363 std::size_t posWS = FindNonNestedNeedles(declNoArgs.substr(prevAfterWhiteSpace), whitespace);
2364 if (posWS == std::string_view::npos)
2366 prevAfterWhiteSpace += posWS + 1;
2367 while (declNoArgs.length() > prevAfterWhiteSpace
2368 && strchr(whitespace, declNoArgs[prevAfterWhiteSpace]))
2369 ++prevAfterWhiteSpace;
2373 std::size_t endReturn = prevAfterWhiteSpace;
2374 while (declNoArgs.length() > endReturn
2375 && strchr(
"&* \t \n", declNoArgs[endReturn]))
2378 result.fReturnType =
ToString(StripSurroundingSpace(declNoArgs.substr(0, endReturn)));
2381 std::string_view scopeFunctionTmplt = declNoArgs.substr(endReturn);
2382 std::size_t prevAtScope = FindNonNestedDoubleColons(scopeFunctionTmplt);
2383 while (prevAtScope != std::string_view::npos
2384 && scopeFunctionTmplt.length() > prevAtScope + 2) {
2385 std::size_t posScope = FindNonNestedDoubleColons(scopeFunctionTmplt.substr(prevAtScope + 2));
2386 if (posScope == std::string_view::npos)
2388 prevAtScope += posScope + 2;
2391 std::size_t afterScope = prevAtScope + 2;
2392 if (prevAtScope == std::string_view::npos) {
2397 result.fScopeName =
ToString(StripSurroundingSpace(scopeFunctionTmplt.substr(0, prevAtScope)));
2398 std::string_view funcNameTmplArgs = scopeFunctionTmplt.substr(afterScope);
2400 result.fFunctionTemplateArguments.clear();
2401 std::size_t posTmpltOpen = FindNonNestedNeedles(funcNameTmplArgs,
"<");
2402 if (posTmpltOpen != std::string_view::npos) {
2403 result.fFunctionName =
ToString(StripSurroundingSpace(funcNameTmplArgs.substr(0, posTmpltOpen)));
2406 std::string_view tmpltArgs = funcNameTmplArgs.substr(posTmpltOpen + 1);
2407 std::size_t posTmpltClose = FindNonNestedNeedles(tmpltArgs,
">");
2408 if (posTmpltClose != std::string_view::npos) {
2409 tmpltArgs = tmpltArgs.substr(0, posTmpltClose);
2410 std::size_t prevAfterArg = 0;
2411 while (tmpltArgs.length() > prevAfterArg) {
2412 std::size_t posComma = FindNonNestedNeedles(tmpltArgs.substr(prevAfterArg),
",");
2413 if (posComma == std::string_view::npos) {
2416 result.fFunctionTemplateArguments.emplace_back(
ToString(StripSurroundingSpace(tmpltArgs.substr(prevAfterArg, posComma))));
2417 prevAfterArg += posComma + 1;
2420 result.fFunctionTemplateArguments.emplace_back(
ToString(StripSurroundingSpace(tmpltArgs.substr(prevAfterArg))));
2423 result.fFunctionName =
ToString(StripSurroundingSpace(funcNameTmplArgs));
2426 result.fFunctionParameters.clear();
2427 if (posArgs != std::string_view::npos) {
2429 std::string_view params = decl.substr(posArgs + 1);
2430 std::size_t posEndArgs = FindNonNestedNeedles(params,
")");
2431 if (posEndArgs != std::string_view::npos) {
2432 params = params.substr(0, posEndArgs);
2433 std::size_t prevAfterArg = 0;
2434 while (params.length() > prevAfterArg) {
2435 std::size_t posComma = FindNonNestedNeedles(params.substr(prevAfterArg),
",");
2436 if (posComma == std::string_view::npos) {
2437 result.fFunctionParameters.emplace_back(
ToString(StripSurroundingSpace(params.substr(prevAfterArg))));
2440 result.fFunctionParameters.emplace_back(
ToString(StripSurroundingSpace(params.substr(prevAfterArg, posComma))));
2441 prevAfterArg += posComma + 1;
static const char * ToString(ENameCycleError err)
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)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t cursor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
An helper class to dismount the name and remount it changed whenever necessary.
NameCleanerForIO(const std::string &clName="", TClassEdit::EModType mode=TClassEdit::kNone, NameCleanerForIO *mother=nullptr)
NameCleanerForIO * fMother
const std::string & GetName()
const std::vector< std::unique_ptr< NameCleanerForIO > > * GetChildNodes() const
bool AreAncestorsSTLContOrArray()
A spin mutex-as-code-guard class.
A RAII helper to remove and readd enclosing _Atomic() It expects no spaces at the beginning or end of...
virtual ~TInterpreterLookupHelper()
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)
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 CleanType(const char *typeDesc, int mode=0, const char **tail=nullptr)
Cleanup type description, redundant blanks removed and redundant tail ignored return *tail = pointer ...
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...
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.