21#include "../../kernel.hpp"
24#define MAX_PROCEDURE_STACK_SIZE 2000000
65 for (
unsigned int i = 0; i < 6; i++)
134 int nCurrentByteCode = nByteCode;
153 if (!sLine.length() || sLine[0] ==
'@')
155 thisReturnVal.
vNumVal.push_back(NAN);
156 return thisReturnVal;
164 if (
findCommand(sLine,
"assert").sString ==
"assert")
181 if (sLine.find(
"to_cmd(") != string::npos)
183 unsigned int nPos = 0;
186 while (sLine.find(
"to_cmd(", nPos) != string::npos)
188 nPos = sLine.find(
"to_cmd(", nPos) + 6;
195 if (nParPos == string::npos)
198 string sCmdString = sLine.substr(nPos + 1, nParPos - 1);
204 sCmdString +=
" -nq";
210 sLine = sLine.substr(0, nPos - 6) + sCmdString + sLine.substr(nPos + nParPos + 1);
227 if (sCurrentCommand ==
"throw")
254 if (sLine.find(
"??") != string::npos && sCurrentCommand !=
"help")
272 || sCurrentCommand ==
"help"
273 || sCurrentCommand ==
"man"
274 || sCurrentCommand ==
"quit"
275 || sCurrentCommand ==
"list"
276 || sCurrentCommand ==
"find"
277 || sCurrentCommand ==
"search"
278 || sCurrentCommand ==
"mode"
279 || sCurrentCommand ==
"menue")
282 string sCommandBack = sLine;
290 string sCurrentLine = sLine;
292 if (sCommandBack != sCurrentLine)
300 thisReturnVal.
vNumVal.push_back(NAN);
301 return thisReturnVal;
306 thisReturnVal.
vNumVal.push_back(NAN);
307 return thisReturnVal;
313 if (sLine.find(
"??") != string::npos)
318 if (sLine.find(
'$') != std::string::npos)
319 procedureInterface(sLine, _parser, _functions, _data, _out, _pData, _script, _option, 0);
328 if (sCurrentCommand !=
"for" && sCurrentCommand !=
"if" && sCurrentCommand !=
"while" && sCurrentCommand !=
"switch")
330 if (!_functions.
call(sLine))
346 bool bBreakPoint = (sLine.substr(0, 2) ==
"|>");
381 thisReturnVal.
vNumVal.push_back(NAN);
382 return thisReturnVal;
389 bool bWriteToCache =
false;
390 bool bWriteToCluster =
false;
405 if (sCache.length() && sCache.find(
'#') == string::npos)
406 bWriteToCache =
true;
409#warning NOTE (numere#1#08/21/21): Might need some adaption, if bytecode issues are experienced
415 bWriteToCache =
true;
442 return thisReturnVal;
445#warning NOTE (erik.haenel#3#): This is changed due to double writes in combination with c{nlen+1} = VAL
452 bWriteToCache =
false;
474 getIndices(sCache, _idx, _parser, _data, _option);
476 if (sCache[sCache.find_first_of(
"({")] ==
'{')
477 bWriteToCluster =
true;
485 sCache.erase(sCache.find_first_of(
"({"));
494 v = _parser.
Eval(nNum);
500 for (
int i = 0; i < nNum; ++i)
501 thisReturnVal.
vNumVal.push_back(v[i]);
505 thisReturnVal.
vNumVal.push_back(v[0]);
532 return thisReturnVal;
551 string _sProc = sProc;
555 if (
sProcNames.length() && !bInstallFileName && _sProc.substr(0, 9) ==
"thisfile~")
566 else if (_sProc.substr(0, 9) ==
"thisfile~")
572 for (
size_t i = 0; i < _sProc.length(); i++)
574 if (_sProc[i] ==
'~')
576 if (_sProc.length() > 5 && i >= 4 && _sProc.substr(i - 4, 5) ==
"main~")
577 _sProc = _sProc.substr(0, i - 4) + _sProc.substr(i + 1);
651 sVarList =
" " + sVarList +
" ";
654 if (sProc.length() > 5 && sProc.substr(sProc.length() - 5) ==
".nprc")
655 sProc = sProc.substr(0, sProc.rfind(
'.'));
661 if (sProc.find(
'~') != string::npos)
662 sProc = sProc.substr(sProc.rfind(
'~') + 1);
664 if (sProc.find(
'/') != string::npos)
665 sProc = sProc.substr(sProc.rfind(
'/') + 1);
667 if (sProc.find(
'\\') != string::npos)
668 sProc = sProc.substr(sProc.rfind(
'\\') + 1);
672 pair<int, ProcedureCommandLine> currentLine;
678 if (currentLine.first == -1)
706 nFlags = currentLine.second.getFlags();
777 _debugger.
showError(current_exception());
791 std::queue<std::string> commandQueue;
792 std::string sCurrentCommand =
"";
794 int nCurrentByteCode = 0;
800 while (!ProcElement->
isLastLine(currentLine.first))
803 ProcElement->
setByteCode(nCurrentByteCode | nByteCode, currentLine.first);
810 if (!commandQueue.size())
812 currentLine = ProcElement->
getNextLine(currentLine.first);
815 nCurrentByteCode = currentLine.second.getByteCode();
816 nByteCode = nCurrentByteCode;
854 if (commandQueue.size())
880 for (
const auto& expr : expressions)
882 commandQueue.push(expr +
";");
886 commandQueue.back().pop_back();
902 if (sCurrentCommand ==
"lclfunc")
968 _debugger.
showError(current_exception());
1001 if (sCurrentCommand ==
"for"
1002 || sCurrentCommand ==
"if"
1003 || sCurrentCommand ==
"switch"
1004 || sCurrentCommand ==
"try"
1005 || sCurrentCommand ==
"while")
1059 _debugger.
showError(current_exception());
1061 nCurrentByteCode = 0;
1076 if (sCurrentCommand ==
"explicit")
1090 if (sCurrentCommand ==
"throw")
1126 if (sCurrentCommand ==
"return")
1137 if (sReturnValue.back() ==
';')
1138 sReturnValue.pop_back();
1142 if (sReturnValue ==
"void")
1144 else if (sReturnValue.find(
'(') != std::string::npos
1145 && sReturnValue.substr(sReturnValue.find(
'(')) ==
"()"
1146 && _data.
isTable(sReturnValue.substr(0, sReturnValue.find(
'('))))
1148 _ReturnVal.
sReturnedTable = sReturnValue.substr(0, sReturnValue.find(
'('));
1151 else if (sReturnValue.length())
1152 _ReturnVal =
ProcCalc(sReturnValue, sCurrentCommand, nCurrentByteCode, _parser, _functions, _data, _option, _out, _pData, _script);
1159 _debugger.
showError(current_exception());
1161 nCurrentByteCode = 0;
1171 ProcCalc(
sProcCommandLine, sCurrentCommand, nCurrentByteCode, _parser, _functions, _data, _option, _out, _pData, _script);
1188 _debugger.
showError(current_exception());
1190 nCurrentByteCode = 0;
1226 _ReturnVal.
vNumVal.push_back(1.0);
1253 std::unique_ptr<Procedure> _procedure(
new Procedure(*
this));
1257 if (sLine.find(
'$') != string::npos && sLine.find(
'(', sLine.find(
'$')) != string::npos)
1264 unsigned int nPos = 0;
1268 while (sLine.find(
'$', nPos) != string::npos && sLine.find(
'(', sLine.find(
'$', nPos)) != string::npos)
1270 nPos = sLine.find(
'$', nPos) + 1;
1271 string __sName = sLine.substr(nPos, sLine.find(
'(', nPos) - nPos);
1272 string __sVarList =
"";
1276 unsigned int nParPos = 0;
1279 if (__sName.find(
'~') == string::npos)
1282 if (__sName.substr(0, 5) ==
"this~")
1287 if (sLine[nPos] ==
'\'')
1289 __sName = sLine.substr(nPos + 1, sLine.find(
'\'', nPos + 1) - nPos - 1);
1290 nParPos = sLine.find(
'(', nPos + 1 + __sName.length());
1293 nParPos = sLine.find(
'(', nPos);
1296 __sVarList = sLine.substr(nParPos);
1304 unsigned int nVarPos = 0;
1308 while (__sVarList.find(
'$', nVarPos) != string::npos)
1312 nVarPos = __sVarList.find(
'$', nVarPos) + 1;
1316 if (!
isInQuotes(__sVarList, nVarPos-1) && __sVarList.substr(nVarPos, __sVarList.find(
'(', nVarPos) - nVarPos).find(
'~') == string::npos)
1317 __sVarList = __sVarList.substr(0, nVarPos) +
sNameSpace + __sVarList.substr(nVarPos);
1321 Returnvalue tempreturnval = _procedure->execute(__sName, __sVarList, _parser, _functions, _data, _option, _out, _pData, _script,
nthRecursion + 1);
1324 if (!_procedure->nReturnType)
1325 sLine = sLine.substr(0, nPos - 1) + sLine.substr(nParPos + 1);
1328 nPos +=
replaceReturnVal(sLine, _parser, tempreturnval, nPos - 1, nParPos + 1,
1338 nPos += __sName.length() + 1;
1349 if (!sLine.length())
1352 else if (sLine.find(
'$') != string::npos)
1357 for (
size_t i = 0; i < sLine.length(); i++)
1359 if (sLine[i] ==
'"' && (!i || sLine[i - 1] !=
'\\'))
1362 if (sLine[i] ==
'$' && !(nQuotes % 2))
1375 if (_procedure->evalPluginCmd(sLine))
1382 _return = _procedure->execute(_procedure->getPluginProcName(), _procedure->getPluginVarList(), _parser, _functions, _data, _option, _out, _pData, _script,
nthRecursion + 1);
1390 _return = _procedure->execute(_procedure->getPluginProcName(), _procedure->getPluginVarList(), _parser, _functions, _data, _option, _out, _pData, _script,
nthRecursion + 1);
1400 if (sLine.find(
"<<RETURNVAL>>") != string::npos)
1406 && sLine.find_first_not_of(
' ', _cmd.
nPos+_cmd.
sString.length()) == sLine.find(
"<<RETURNVAL>>"))
1415 string sReturn =
"{";
1417 for (
unsigned int v = 0; v < _return.
vStringVal.size(); v++)
1420 sReturn.back() =
'}';
1421 sLine.replace(sLine.find(
"<<RETURNVAL>>"), 13, sReturn);
1425 std::string sTargetTable = sLine.substr(0, sLine.find(
"<<RETURNVAL>>"));
1427 if (sTargetTable.find(
'=') != std::string::npos)
1428 sTargetTable.erase(sTargetTable.find_last_not_of(
" ="));
1432 if (sTargetTable.find(
'(') != std::string::npos
1433 && sTargetTable.substr(sTargetTable.find(
'(')) ==
"()"
1434 && sLine.substr(sLine.find(
"<<RETURNVAL>>")+13).find_first_not_of(
" ;") == std::string::npos)
1436 sTargetTable.erase(sTargetTable.find(
'('));
1441 if (!_data.
isTable(sTargetTable))
1453 _data.
getCols(sTargetTable)}))
1454 + sLine.substr(sLine.find(
"<<RETURNVAL>>")+13);
1458 sLine.replace(sLine.find(
"<<RETURNVAL>>"), 13, _data.
isEmpty(_return.
sReturnedTable) ?
"false" :
"true");
1467 sLine.replace(sLine.find(
"<<RETURNVAL>>"), 13,
"_~PLUGIN[" + _procedure->getPluginProcName() +
"~" +
toString((
int)(nth_command +
nthRecursion)) +
"]");
1500 if (sCommand ==
"var" || sCommand ==
"str" || sCommand ==
"tab" || sCommand ==
"cst")
1505 else if (sCommand ==
"namespace")
1507 sLine = sLine.substr(sLine.find(
"namespace") + 9);
1513 if (sLine.find(
' ') != string::npos)
1514 sLine = sLine.substr(0, sLine.find(
' '));
1516 if (sLine.substr(0, 5) ==
"this~" || sLine ==
"this")
1519 if (sLine !=
"main")
1549 string sAppendedLine =
"";
1553 if (sProcedureLine.substr(0, 9) ==
"procedure"
1554 && sProcedureLine.find(
'$') != string::npos
1555 && sProcedureLine.find(
'(', sProcedureLine.find(
'$')) != string::npos)
1560 bool bAppend =
false;
1565 string sFileName = sProcedureLine.substr(sProcedureLine.find(
'$') + 1, sProcedureLine.find(
'(', sProcedureLine.find(
'$')) - sProcedureLine.find(
'$') - 1);
1576 if (sFileName.substr(0, 9) ==
"thisfile~")
1602 vector<string> vProcedureFile;
1608 vProcedureFile.push_back(sLineTemp);
1615 for (
int i = vProcedureFile.size()-1; i >= 0; i--)
1617 if (vProcedureFile[i] ==
"endprocedure")
1619 vProcedureFile.erase(vProcedureFile.begin()+i+1, vProcedureFile.end());
1628 for (
size_t i = 0; i < vProcedureFile.size(); i++)
1647 string sProcName =
"";
1649 if (sFileName.find(
'~') != string::npos)
1650 sProcName = sFileName.substr(sFileName.rfind(
'~') + 1);
1652 sProcName = sFileName;
1655 unsigned int nLength =
_lang.
get(
"PROC_FOOTER").length();
1656 fProcedure <<
"#**" << std::setfill(
'*') << std::setw(nLength) <<
'*' << endl;
1658 fProcedure <<
" * " << std::setfill(
'=') << std::setw(nLength) <<
'=' << endl;
1668 if (sProcedureLine.find(
"##!") != string::npos)
1671 fProcedure << sProcedureLine.substr(sProcedureLine.find(
"##!"));
1672 sProcedureLine.erase(sProcedureLine.find(
"##!"));
1674 else if (sProcedureLine.find(
"#*!") != string::npos)
1677 fProcedure << sProcedureLine.substr(sProcedureLine.find(
"#*!"));
1678 sProcedureLine.erase(sProcedureLine.find(
"#*!"));
1684 if (sFileName.find(
'~') != string::npos)
1685 fProcedure << sFileName.substr(sFileName.rfind(
'~') + 1);
1690 fProcedure << sProcedureLine.substr(sProcedureLine.find(
'(')) << endl;
1693 else if (sProcedureLine.substr(0, 12) ==
"endprocedure")
1702 if (sProcedureLine.find(
'(') != string::npos
1703 && (sProcedureLine.substr(0, 3) ==
"for"
1704 || sProcedureLine.substr(0, 3) ==
"if "
1705 || sProcedureLine.substr(0, 3) ==
"if("
1706 || sProcedureLine.substr(0, 6) ==
"elseif"
1707 || sProcedureLine.substr(0, 6) ==
"switch"
1708 || sProcedureLine.substr(0, 5) ==
"while"))
1713 else if (sProcedureLine.find(
':', 5) != string::npos
1714 && (sProcedureLine.substr(0, 5) ==
"case "
1715 || sProcedureLine.substr(0, 6) ==
"catch "
1716 || sProcedureLine.substr(0, 6) ==
"catch:"
1717 || sProcedureLine.substr(0, 8) ==
"default "
1718 || sProcedureLine.substr(0, 8) ==
"default:")
1719 && sProcedureLine.find_first_not_of(
' ', sProcedureLine.find(
':', 5)) != string::npos)
1721 sAppendedLine = sProcedureLine.substr(sProcedureLine.find(
':', 5)+1);
1722 sProcedureLine.erase(sProcedureLine.find(
':', 5)+1);
1724 else if (sProcedureLine.find(
' ', 4) != string::npos
1725 && (sProcedureLine.substr(0, 5) ==
"else "
1726 || sProcedureLine.substr(0, 6) ==
"endif "
1727 || sProcedureLine.substr(0, 7) ==
"endtry "
1728 || sProcedureLine.substr(0, 10) ==
"endswitch "
1729 || sProcedureLine.substr(0, 7) ==
"endfor "
1730 || sProcedureLine.substr(0, 9) ==
"endwhile ")
1731 && sProcedureLine.find_first_not_of(
' ', sProcedureLine.find(
' ', 4)) != string::npos
1732 && sProcedureLine[sProcedureLine.find_first_not_of(
' ', sProcedureLine.find(
' ', 4))] !=
'-')
1734 sAppendedLine = sProcedureLine.substr(sProcedureLine.find(
' ', 4));
1735 sProcedureLine.erase(sProcedureLine.find(
' ', 4));
1737 else if (sProcedureLine.find(
" for ") != string::npos
1738 || sProcedureLine.find(
" for(") != string::npos
1739 || sProcedureLine.find(
" endfor") != string::npos
1740 || sProcedureLine.find(
" if ") != string::npos
1741 || sProcedureLine.find(
" if(") != string::npos
1742 || sProcedureLine.find(
" else") != string::npos
1743 || sProcedureLine.find(
" elseif ") != string::npos
1744 || sProcedureLine.find(
" elseif(") != string::npos
1745 || sProcedureLine.find(
" endif") != string::npos
1746 || sProcedureLine.find(
" switch ") != string::npos
1747 || sProcedureLine.find(
" switch(") != string::npos
1748 || sProcedureLine.find(
" case") != string::npos
1749 || sProcedureLine.find(
" default") != string::npos
1750 || sProcedureLine.find(
" endswitch") != string::npos
1751 || sProcedureLine.find(
" try") != string::npos
1752 || sProcedureLine.find(
" catch") != string::npos
1753 || sProcedureLine.find(
" endtry") != string::npos
1754 || sProcedureLine.find(
" while ") != string::npos
1755 || sProcedureLine.find(
" while(") != string::npos
1756 || sProcedureLine.find(
" endwhile") != string::npos)
1758 for (
unsigned int n = 0; n < sProcedureLine.length(); n++)
1760 if (sProcedureLine[n] ==
' ' && !
isInQuotes(sProcedureLine, n))
1762 if (sProcedureLine.substr(n, 5) ==
" for "
1763 || sProcedureLine.substr(n, 5) ==
" for("
1764 || sProcedureLine.substr(n, 7) ==
" endfor"
1765 || sProcedureLine.substr(n, 4) ==
" if "
1766 || sProcedureLine.substr(n, 4) ==
" if("
1767 || sProcedureLine.substr(n, 5) ==
" else"
1768 || sProcedureLine.substr(n, 8) ==
" elseif "
1769 || sProcedureLine.substr(n, 8) ==
" elseif("
1770 || sProcedureLine.substr(n, 6) ==
" endif"
1771 || sProcedureLine.substr(n, 8) ==
" switch "
1772 || sProcedureLine.substr(n, 8) ==
" switch("
1773 || sProcedureLine.substr(n, 6) ==
" case "
1774 || sProcedureLine.substr(n, 9) ==
" default "
1775 || sProcedureLine.substr(n, 9) ==
" default:"
1776 || sProcedureLine.substr(n, 10) ==
" endswitch"
1777 || sProcedureLine.substr(n, 5) ==
" try "
1778 || sProcedureLine.substr(n, 7) ==
" catch "
1779 || sProcedureLine.substr(n, 7) ==
" catch:"
1780 || sProcedureLine.substr(n, 7) ==
" endtry"
1781 || sProcedureLine.substr(n, 7) ==
" while "
1782 || sProcedureLine.substr(n, 7) ==
" while("
1783 || sProcedureLine.substr(n, 9) ==
" endwhile")
1785 sAppendedLine = sProcedureLine.substr(n + 1);
1786 sProcedureLine.erase(n);
1795 if (
findCommand(sProcedureLine).sString ==
"endif"
1796 ||
findCommand(sProcedureLine).sString ==
"endwhile"
1797 ||
findCommand(sProcedureLine).sString ==
"endfor"
1798 ||
findCommand(sProcedureLine).sString ==
"endtry"
1800 ||
findCommand(sProcedureLine).sString ==
"endcompose"
1801 ||
findCommand(sProcedureLine).sString ==
"endswitch"
1803 ||
findCommand(sProcedureLine).sString ==
"default"
1804 ||
findCommand(sProcedureLine).sString ==
"elseif"
1808 string sTabs =
"\t";
1814 sProcedureLine = sTabs + sProcedureLine;
1823 ||
findCommand(sProcedureLine).sString ==
"compose"
1824 ||
findCommand(sProcedureLine).sString ==
"switch"
1826 ||
findCommand(sProcedureLine).sString ==
"default"
1827 ||
findCommand(sProcedureLine).sString ==
"elseif"
1843 fProcedure <<
" * https://www.numere.org/" << endl;
1844 fProcedure <<
" **" << std::setfill(
'*') << std::setw(
_lang.
get(
"PROC_FOOTER").length() + 1) <<
"#" << endl;
1859 if (sAppendedLine.length())
1882 string __sName = sCmdLine.substr(nPos, sCmdLine.find(
'(', nPos) - nPos);
1885 sArgList = sCmdLine.substr(sCmdLine.find(
'(', nPos));
1887 sArgList.erase(0, 1);
1889 if (__sName.find(
'~') == string::npos)
1892 if (__sName.substr(0, 5) ==
"this~")
1896 if (sCmdLine[nPos] ==
'\'')
1898 __sName = sCmdLine.substr(nPos + 1, sCmdLine.find(
'\'', nPos + 1) - nPos - 1);
1902 sFileName = __sName;
1905 if (__sName.find(
'~') != string::npos)
1906 sProcName = __sName.substr(__sName.rfind(
'~')+1);
1908 sProcName = __sName;
1911 if (sFileName.find(
'~') != string::npos)
1913 if (sFileName.substr(0, 9) ==
"thisfile~")
1924 for (
unsigned int i = 0; i < sFileName.length(); i++)
1926 if (sFileName[i] ==
'~')
1928 if (sFileName.length() > 5 && i >= 4 && sFileName.substr(i - 4, 5) ==
"main~")
1929 sFileName = sFileName.substr(0, i - 4) + sFileName.substr(i + 1);
1940 if (sFileName[1] !=
':')
1942 sFileName =
"<procpath>/" + sFileName;
1961 if (sProc.find(
'$') == string::npos)
1964 size_t nProcedures = 0;
1967 if (sProc.find(
'$') != string::npos && sProc.find(
'(', sProc.find(
'$')) != string::npos)
1973 while (sProc.find(
'$', nPos) != string::npos && sProc.find(
'(', sProc.find(
'$', nPos)) != string::npos)
1976 nPos = sProc.find(
'$', nPos) + 1;
1989 int nInlineFlag = 0;
1995 nInlineable =
max(
isInlineable(__sProcName, __sFileName, &nInlineFlag), nInlineable);
2028 vector<string> vExpandedProcedures;
2031 if (sProc.find(
'$') == string::npos)
2032 return vExpandedProcedures;
2036 if (sProc.find(
'$') != string::npos && sProc.find(
'(', sProc.find(
'$')) != string::npos)
2042 while (sProc.find(
'$', nPos) != string::npos && sProc.find(
'(', sProc.find(
'$', nPos)) != string::npos && nProcedures)
2045 nPos = sProc.find(
'$', nPos) + 1;
2060 if (__sArgList.find(
'$') != string::npos)
2066 if (vExpandedArgList.size())
2068 vExpandedProcedures.insert(vExpandedProcedures.end(), vExpandedArgList.begin(), vExpandedArgList.end());
2078 vector<string> vInlinedRepresentation =
getInlined(__sProcName, __sArgList, __sFileName, nProcedures);
2084 vExpandedProcedures.insert(vExpandedProcedures.end(), vInlinedRepresentation.begin(), vInlinedRepresentation.end()-1);
2093 return vExpandedProcedures;
2115 string sArgumentList;
2117 const int nMAX_INLINING_LINES = 7;
2119 if (nProcedureLine < 0)
2123 pair<int, ProcedureCommandLine> currentline = element->
getCurrentLine(nProcedureLine);
2133 nInlineable = currentline.second.isInlineable();
2134 sArgumentList = currentline.second.getArgumentList();
2141 while (!element->
isLastLine(currentline.first))
2143 currentline = element->
getNextLine(currentline.first);
2159 if (nLines > nMAX_INLINING_LINES)
2165 currentline.second.setInlineable(nInlineable);
2187 static const string sINVALID_INLINING_COMMANDS =
" cst tab namespace for if while switch ifndef ifndefined def define lclfunc redef redefine undef undefine ";
2191 if (sINVALID_INLINING_COMMANDS.find(
" " + command +
" ") != string::npos)
2195 if (sCommandLine.find(
"$") != string::npos)
2201 for (
size_t i = 0; i < sCommandLine.length(); i++)
2203 if (sCommandLine[i] ==
'"' && (!i || sCommandLine[i-1] !=
'\\'))
2206 if (sCommandLine[i] ==
'$' && !(nQuotes % 2))
2226 size_t nProcedures = 0;
2230 if (sCommandLine.find(
'$') != string::npos && sCommandLine.find(
'(', sCommandLine.find(
'$')) != string::npos)
2235 while (sCommandLine.find(
'$', nPos) != string::npos && sCommandLine.find(
'(', sCommandLine.find(
'$', nPos)) != string::npos)
2237 nPos = sCommandLine.find(
'$', nPos) + 1;
2265vector<string>
Procedure::getInlined(
const string& sProc,
const string& sArgumentList,
const string& sFileName,
size_t nProcedures)
2274 vector<string> vProcCommandLines;
2275 string sCommandLine;
2276 static const string sSPECIALRETURNVALS =
" true false nan inf -inf ";
2284 if (nProcedureLine < 0)
2288 pair<int, ProcedureCommandLine> currentline = element->
getCurrentLine(nProcedureLine);
2301 if (sArgDef.substr(0, 6) ==
"_~~TC_")
2308 while (!element->
isLastLine(currentline.first))
2311 currentline = element->
getNextLine(currentline.first);
2312 sCommandLine = varFactory.
resolveVariables(
" " + currentline.second.getCommandLine() +
" ");
2320 inlineClusters.insert(sCommandLine.substr(0, sCommandLine.find(
'{')));
2322 else if (
findCommand(sCommandLine).sString ==
"str")
2326 inlineClusters.insert(sCommandLine.substr(0, sCommandLine.find(
'{')));
2332 sCommandLine =
"|> " + sCommandLine;
2338 vProcCommandLines.push_back(
"true");
2345 if (
findCommand(sCommandLine).sString ==
"return")
2349 sCommandLine.erase(0, pos+7);
2351 if (sCommandLine.find(
';') != string::npos)
2352 sCommandLine.erase(sCommandLine.rfind(
';'));
2361 if (sCommandLine ==
"void")
2362 vProcCommandLines.push_back(
"");
2363 else if (!sCommandLine.length())
2364 vProcCommandLines.push_back(
"true");
2365 else if (sSPECIALRETURNVALS.find(
" " + sCommandLine +
" ") != string::npos || _parser.
GetConst().find(sCommandLine) != _parser.
GetConst().end())
2366 vProcCommandLines.push_back(sCommandLine);
2370 if (nProcedures > 1)
2374 vProcCommandLines.push_back(sTempCluster +
" = " + sCommandLine +
";");
2375 vProcCommandLines.push_back(sTempCluster);
2376 inlineClusters.insert(sTempCluster.substr(0, sTempCluster.find(
'{')));
2379 vProcCommandLines.push_back(
"{" + sCommandLine +
"}");
2384 if (nProcedures > 1)
2388 vProcCommandLines.push_back(sTempCluster +
" = " + sCommandLine +
";");
2389 vProcCommandLines.push_back(sTempCluster);
2390 inlineClusters.insert(sTempCluster.substr(0, sTempCluster.find(
'{')));
2393 vProcCommandLines.push_back(
"(" + sCommandLine +
")");
2399 vProcCommandLines.push_back(sCommandLine);
2402 return vProcCommandLines;
2416 for (
size_t i = 0; i < sProcedureName.length(); i++)
2418 if (!isalnum(sProcedureName[i]) && sProcedureName[i] !=
'_' && sProcedureName[i] !=
'~')
2419 sProcedureName[i] =
'_';
2422 return sProcedureName;
2503 rethrow_exception(e_ptr);
2548 rethrow_exception(e_ptr);
2599 && sLine.substr(0, nPos).find_last_not_of(
' ') == _cmd.
nPos + _cmd.
sString.length()-1
2600 && sLine.substr(nPos2).find_first_not_of(
"; ") == std::string::npos)
2613 sLine = sLine.substr(0, nPos) + sReturn + sLine.substr(nPos2);
2614 return sReturn.length();
2618 std::string sTargetTable = sLine.substr(0, nPos);
2621 if (sTargetTable.find(
'=') != std::string::npos)
2622 sTargetTable.erase(sTargetTable.find_last_not_of(
" =")+1);
2626 if (sTargetTable.find(
'(') != std::string::npos
2627 && sTargetTable.substr(sTargetTable.find(
'(')) ==
"()"
2628 && sLine.substr(nPos2).find_first_not_of(
" ;") == std::string::npos)
2630 sTargetTable.erase(sTargetTable.find(
'('));
2635 if (!_data.
isTable(sTargetTable))
2647 _data.
getCols(sTargetTable)}));
2648 sLine = sTempVar + sLine.substr(nPos2);
2649 return sTempVar.length();
2665 sLine = sLine.substr(0, nPos) + sReplaceName + sLine.substr(nPos2);
2667 return sReplaceName.length();
2670 sLine = sLine.substr(0, nPos) +
"nan" + sLine.substr(nPos2);
2730 for (
unsigned int i = sProc.length() - 1; i >= 0; i--)
2732 if (sProc[i] ==
'\\' || sProc[i] ==
'/' || sProc[i] ==
'~')
2836 int nIncludeType = 0;
2842 string sIncludeFileName =
"";
2870 if (sIncludeFileName.find(
':') != string::npos)
2872 for (
int __i = sIncludeFileName.length() - 1; __i >= 0; __i--)
2874 if (sIncludeFileName[__i] ==
':'
2876 || (__i == 1 && sIncludeFileName.length() > (
unsigned int)__i + 1 && sIncludeFileName[__i + 1] !=
'/')))
2878 sIncludeFileName.erase(sIncludeFileName.find(
':'));
2885 if (sIncludeFileName.length())
2886 sIncludeFileName =
ValidFileName(sIncludeFileName,
".nscr");
2895 fInclude.open(sIncludeFileName.c_str());
2897 if (fInclude.fail())
2911 return nIncludeType;
CommandReturnValues commandHandler(string &sCmd)
This function is the main command handling function.
@ COMMAND_HAS_RETURNVALUE
void enable(const std::string &sExpr)
Enables the assertion handler using the passed expression.
void reset()
Resets the assertion handler.
AssertionStats getStats() const
Returns the current tests stats.
void checkAssertion(mu::value_type *v, int nNum)
Checks the return value of a muParser evaluated result.
bool isBreakpoint(const std::string &_sFilename, size_t nLine)
void info(const std::string &sMessage)
Convenience member function.
This class extends the std::vector for endlessness.
This class implements the basic input/ output file system and provides functionalities to work with f...
std::string sExecutablePath
std::string ValidFileName(std::string _sFileName, const std::string sExtension=".dat", bool checkExtension=true, bool doCleanPath=true) const
This member function evaluates, whether the passed filename is a valid filename. One may supply a pre...
std::string sTokens[7][2]
int setPath(std::string _sPath, bool bMkDir, std::string _sExePath)
This member function may be used to set the preferred file path of the current FileSystem instance.
void replaceLocalVars(std::string &sLine)
This member function is used to replace variable occurences with their (auto-determined) internal nam...
int getCurrentBlockDepth() const
Returns the current block depth while reading a flow control statement to memory.
bool getReturnSignal() const
static bool isFlowCtrlStatement(const std::string &sCmd)
This static member function returns whether the passed command is a flow control statement.
std::map< std::string, std::string > mVarMap
std::set< std::string > inlineClusters
std::string sTestClusterName
void setCommand(std::string &__sCmd, int nCurrentLine)
This member function is used to set a command line from the outside into the flow control statement c...
int getCurrentLineNumber() const
This member function returns the current line number as enumerated during passing the commands via "s...
Returnvalue getReturnValue() const
void updateTestStats()
Updates the test statistics with the total test statistics.
bool bEvaluatingFlowControlStatements
This class implements the function definition managing instance.
bool reset()
This member function resets the FunctionDefinitionManager object to a state before any function was d...
bool defineFunc(const std::string &sExpr, bool bRedefine=false, bool bFallback=false)
This function defines a custom function, by passing it to a new FunctionDefinition class instance.
void setPredefinedFuncs(const std::string &sPredefined)
This member function updates the internal list of predefined functions. If the list is whitespace-sep...
std::string getPredefinedFuncs() const
Return a list of the internal defined default functions.
bool call(std::string &sExpr, int nRecursion=0)
This function searches for known custom definitions in the passed expression and replaces them with t...
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
This class represents the central memory managing instance. It will handle all tables and clusters,...
void copyTable(const std::string &source, const std::string &target)
Copy one table to another one (and create the missing table automatically, if needed).
int getLines(StringView sTable, bool _bFull=false) const
bool isEmpty(const std::string &sTable) const
bool isTable(const std::string &sTable) const
This member function returns, whether the passed table name corresponds to a known table.
void swapTables(std::string sTable1, std::string sTable2)
bool deleteTable(const std::string &sCache)
This member function removes the selected table.
void renameTable(const std::string &sCache, const std::string &sNewName, bool bForceRenaming=false)
bool containsTablesOrClusters(const std::string &sCmdLine)
This member function evaluates, whether the passed command line contains tables or clusters.
void writeToTable(int _nLine, int _nCol, const std::string &_sCache, const mu::value_type &_dData)
int getCols(StringView sTable, bool _bFull=false) const
This class represents a whole cluster. The single items are stored as pointers to the abstract cluste...
void assignResults(Indices _idx, int nNum, mu::value_type *data)
This member function assigns calculation results as data for the cluster items in memory,...
std::vector< std::string > to_string() const
Converts all contents of this cluster to a vector of strings. Intended to be used for data transfer.
void setDoubleArray(const std::vector< mu::value_type > &vVals)
This member function assigns values as data for the all cluster items in memory. The type of the clus...
Cluster & getCluster(StringView sCluster)
This member function returns a reference to the cluster indicated by the passed cluster identifier.
std::string createTemporaryCluster(const std::string &suffix="")
This member function creates a temporary cluster with a unique name and returns this name to the call...
virtual bool isStringExpression(const std::string &sExpression) override
Returns true, if the passed expression is an expression containing strings, string variables or strin...
StringParserRetVal evalAndFormat(std::string &sLine, std::string &sCache, bool bSilent=false, bool bCheckAssertions=false)
This public member function evaluates the passed string expression and formats the results for the co...
void getStringValues(std::string &sLine)
This public member function resolves all string variable occurences and replaces them with their valu...
void removeTempStringVectorVars()
This member function removes all temporary string vector variables.
std::string createTempStringVectorVar(const std::vector< std::string > &vStringVector)
This member function is used to create a temporary string vector variable.
void throwException(SyntaxError error)
This member function shows the debugger with the corresponding error message obtained by the passed S...
void gatherInformations(ProcedureVarFactory *_varFactory, const std::string &_sErraticCommand, const std::string &_sErraticModule, unsigned int _nLineNumber)
This member function gathers all information from the current workspace and stores them internally to...
int showBreakPoint()
This member function shows the debugger for the current breakpoint and returns the debugger code (i....
void popStackItem()
This member function removes the last item from the stack.
void showError(const std::string &sTitle)
This member function shows the debugger with the passed error message.
BreakpointManager & getBreakpointManager()
void pushStackItem(const std::string &sStackItem, Procedure *_currentProcedure)
This member function adds a new stack item to the monitored stack. Additionally, it cleanes the proce...
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
static ProcedureLibrary ProcLibrary
static int evalDebuggerBreakPoint(const std::string &sCurrentCommand="")
This member function handles the creation of the debugger information for a script debugger breakpoin...
NumeRe::StringParser & getStringParser()
static bool bSupressAnswer
NumeReDebugger & getDebugger()
static void failMessage(std::string sFailMessage)
This static function may be used to print a test failure message in the terminal.
MemoryManager & getMemoryManager()
static void print(const std::string &__sLine, bool printingEnabled=true)
This member function appends the passed string as a new output line to the buffer and informs the ter...
NumeRe::Cluster & getAns()
static bool GetAsyncCancelState()
This function is used by the kernel to get informed, when the user pressed ESC or used other means of...
static std::string formatResultOutput(int nNum, mu::value_type *v)
This static function is used to format the result output in the terminal for numerical-only results.
static int * baseStackPosition
This class implements the procedure plugin system. It will be a parent class of the procedure class.
This class contains all the plot settings usable by the plotting algorithm.
std::string getArgumentList() const
@ BYTECODE_RECURSIVEEXPRESSION
@ BYTECODE_FLOWCTRLSTATEMENT
@ BYTECODE_PROCEDUREINTERFACE
This class contains the pre-parsed contents of a single procedure file.
std::pair< int, ProcedureCommandLine > getCurrentLine(int currentLine)
This function returns the selected line of the stored file. This member function will be used in comb...
bool isLastLine(int currentline)
This member function determines, whether the current line is the last line of the stored procedure fi...
void setByteCode(int _nByteCode, int nCurrentLine)
This member function can be used to store the created byte code in the current procedure command line...
int gotoProcedure(const std::string &sProcedureName)
This member function returns the line of the stored file, where the desired procedure may be found or...
std::pair< int, ProcedureCommandLine > getNextLine(int currentline)
This member function returns the line after the current selected line. This is probably not the same ...
This class implements the logic to evaluate complex procedures, which may be called recursively.
~Procedure()
Destructor ensuring that the procedure output file stream will be closed, if it is still open.
virtual int catchExceptionForTest(std::exception_ptr e_ptr, bool bSupressAnswer_back, int nLine) override
This virtual member function is inserted in some automatically catchable locations to convert an erro...
FunctionDefinitionManager _localDef
std::string sLastWrittenProcedureFile
Returnvalue execute(std::string sProc, std::string sVarList, mu::Parser &_parser, FunctionDefinitionManager &_functions, MemoryManager &_data, Settings &_option, Output &_out, PlotData &_pData, Script &_script, unsigned int nth_procedure=0)
This member function is central in the execution of the currently selected procedure as it handles al...
std::string sCallingNameSpace
virtual int evalDebuggerBreakPoint(mu::Parser &_parser, Settings &_option) override
This virtual member function handles the gathering of all relevant information for the debugger for t...
int applyInliningRuleset(const std::string &sCommandLine, const std::string &sArgumentList)
This private member function applies the internal inlining rule set for a single procedure command li...
std::vector< std::string > getInlined(const std::string &sProc, const std::string &sArgumentList, const std::string &sFileName, size_t nProcedures)
This virtual private member function returns the inlined representation of the selected procedure as ...
ProcedureVarFactory * _varFactory
int isInlineable(const std::string &sProc, const std::string &sFileName, int *nInlineFlag=nullptr)
This private member function evaluates, whether the current procedure is inlineable,...
virtual FlowCtrl::ProcedureInterfaceRetVal procedureInterface(std::string &sLine, mu::Parser &_parser, FunctionDefinitionManager &_functions, MemoryManager &_data, Output &_out, PlotData &_pData, Script &_script, Settings &_option, int nth_command=0) override
This member function handles the calls for procedures and plugins, resolves them and executes the cal...
std::string sProcCommandLine
void init()
Private initializing member function. Sets all variables to a reasonable default value.
virtual int isInline(const std::string &sProc) override
This virtual member function checks, whether the procedures in the current line are declared as inlin...
int handleIncludeSyntax(std::string &sProcCommandLine, std::ifstream &fInclude, bool bReadingFromInclude)
This member function handles the script include syntax, which one may use in other procedures.
void extractProcedureInformation(const std::string &sCmdLine, size_t nPos, std::string &sProcName, std::string &sArgList, std::string &sFileName)
This private member function extracts procedure name, argument list and the corresponding file name f...
Returnvalue ProcCalc(std::string sLine, std::string sCurrentCommand, int &nByteCode, mu::Parser &_parser, FunctionDefinitionManager &_functions, MemoryManager &_data, Settings &_option, Output &_out, PlotData &_pData, Script &_script)
This member function does the evaluation stuff regarding strings and numerical expressions for the cu...
size_t replaceReturnVal(std::string &sLine, mu::Parser &_parser, const Returnvalue &_return, unsigned int nPos, unsigned int nPos2, const std::string &sReplaceName)
This member function replaces the procedure occurence between the both passed positions using akronym...
bool setProcName(const std::string &sProc, bool bInstallFileName=false)
This member function is used to obtain the procedure file name from the selected procedure....
friend class ProcedureVarFactory
virtual int getErrorInformationForDebugger() override
This virtual member function handles the gathering of all relevant information for the debugger for t...
void resetProcedure(mu::Parser &_parser, bool bSupressAnswer)
This member function sets the current procedure object to its original state. It will be called at th...
unsigned int GetCurrentLine() const
This member function will return the current line number depending on whether a flow control statemen...
std::string sCurrentProcedureName
size_t countProceduresInLine(const std::string &sCommandLine)
This private member function simply counts the number of procedures, which may be found in the curren...
virtual int procedureCmdInterface(std::string &sLine) override
Virtual member function allowing to identify and evaluate some special procedure commands....
bool handleVariableDefinitions(std::string &sProcCommandLine, const std::string &sCommand)
This method handles the definitions of local variables.
void extractCurrentNamespace(const std::string &sProc)
This member function extracts the namespace of the currently executed procedure.
bool writeProcedure(std::string sProcedureLine)
This member function handles the procedure installation process by governing the file stream and pass...
static std::string mangleName(std::string sProcedureName)
Mangles a procedure name to be used as a usual variable.
virtual std::vector< std::string > expandInlineProcedures(std::string &sLine) override
This virtual private member function expands all procedures in the current command line,...
std::string sThisNameSpace
Procedure()
Default constructor.
ProcedureElement * getProcedureContents(const std::string &sProcedureFileName)
Returns the ProcedureElement pointer to the desired procedure file. It also creates the element,...
This class is the variable factory used by procedure instances to create their local variables and re...
std::string resolveVariables(const std::string &sProcedureCommandLine)
std::map< std::string, std::string > createProcedureArguments(std::string sArgumentList, std::string sArgumentValues)
This member function will create the procedure arguments for the current procedure.
std::string sInlineVarDef
void createLocalTables(std::string sTableList)
This member function will create the local tables for the current procedure.
std::string sInlineStringDef
void createLocalStrings(std::string sStringList)
This member function will create the local string variables for the current procedure.
bool delayDeletionOfReturnedTable(const std::string &sTableName)
Searches for a local table or a local table in the arguments with the corresponding identifier,...
std::vector< std::string > vInlineArgDef
void createLocalClusters(std::string sClusterList)
This member function will create the local clusters for the current procedure.
std::string createTestStatsCluster()
Creates a special cluster containing the test statistics.
void createLocalVars(std::string sVarList)
This member function will create the local numerical variables for the current procedure.
This class manages the setting values of the internal (kernel) settings of this application.
bool systemPrints() const
Returns, whether system messages shall be printed to the terminal.
void enableSystemPrints(bool _bSystemPrints=true)
Enables or disables the system printing functionality. This is a convenience wrapper for the direct m...
bool useDebugger() const
Returns, whether the debugger is currently active.
Common exception class for all exceptions thrown in NumeRe.
@ INLINE_PROCEDURE_IS_NOT_INLINE
@ PROCEDURE_STACK_OVERFLOW
@ IF_OR_LOOP_SEEMS_NOT_TO_BE_CLOSED
@ PRIVATE_PROCEDURE_CALLED
INSERT HERE.
@ PROCESS_ABORTED_BY_USER
static size_t invalid_position
bool isOpenEnd() const
This member function determines, whether the internal index set has an open end.
std::string to_string() const
This member function converts the vector indexes contents into a human-readable string representation...
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
bool IsLockedPause() const
Check, whether the pause mode is locked.
const valmap_type & GetConst() const
Return a map containing all parser constants.
void ClearVectorVars(bool bIgnoreProcedureVects=false)
This member function cleares the internal vector storage.
bool ActiveLoopMode() const
Check, whether the loop mode is active. This function returns true even if the loop mode is paused.
bool IsAlreadyParsed(StringView sNewEquation)
This member function checks, whether the passed expression is already parsed, so that the parsing ste...
string_type CreateTempVectorVar(const std::vector< mu::value_type > &vVar)
This member function copies the passed vector into the internal storage referencing it with a auto-ge...
std::map< std::string, std::string > * mVarMapPntr
void SetVectorVar(const std::string &sVarName, const std::vector< mu::value_type > &vVar, bool bAddVectorType=false)
This member function copies the passed vector into the internal storage referencing it with the passe...
Error class of the parser.
const string_type & GetExpr() const
gets the expression related tp this error.
Mathematical expressions parser.
string getDataElements(string &sLine, Parser &_parser, MemoryManager &_data, const Settings &_option, int options)
Searches the passed string for calls to any table or cluster and replaces them with internal vectors ...
bool isClusterCandidate(string &sLine, string &sCluster, bool doCut)
This function checks, whether the passed command line contains the syntax for a cluster candidate,...
Indices getIndices(StringView sCmd, mu::Parser &_parser, MemoryManager &_data, const Settings &_option)
Wrapper for the new getIndices function interface.
bool isValidIndexSet(const Indices &_idx)
Assertion _assertionHandler
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
CONSTCD11 std::enable_if<!std::chrono::treat_as_floating_point< T >::value, T >::type trunc(T t) NOEXCEPT
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
MUP_BASETYPE value_type
The numeric datatype used by the parser.
string promptForUserInput(const string &__sCommand)
This function is invoked, if a prompt operator ("??") was found in a string.
#define MAX_PROCEDURE_STACK_SIZE
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
This structure is central for managing the indices of a table or cluster read or write data access....
Structure for the findCommand function.
Structure as wrapper for the return value of procedures (which may be numerical or string values or a...
std::vector< std::string > vStringVal
std::string sReturnedTable
std::vector< mu::value_type > vNumVal
std::string toString(int)
Converts an integer to a string without the Settings bloat.