22#include "../../kernel.hpp"
23#include "../utils/tools.hpp"
24#include "../procedure/procedurevarfactory.hpp"
26#define DEFAULT_NUM_PRECISION 7
27#define DEFAULT_MINMAX_PRECISION 5
28#define MAXSTRINGLENGTH 1024
164 return nDebuggerCode;
244 return "\t1 x 1\t(...)\t";
246 std::string isRef =
"";
256 if (_data.
isTable(sArgumentValue))
258 string sCache = sArgumentValue.substr(0, sArgumentValue.find(
'('));
267 if (sArgumentName.length() && sArgumentName.find(
"()") == std::string::npos)
268 isRef = isRef.length() ?
"(&@) " :
"(@) ";
270 return "\t" + sDim +
"\t" + isRef +
"table\t";
284 if (sArgumentName.length() && sArgumentName.find(
"{}") == std::string::npos)
285 isRef = isRef.length() ?
"(&@) " :
"(@) ";
287 return "\t" +
toString(cluster.
size()) +
" x 1\t" + isRef +
"cluster\t";
291 if (sArgumentValue.front() ==
'{' && sArgumentValue.back() ==
'}')
294 string sArg = sArgumentValue.substr(1, sArgumentValue.length()-2);
296 while (sArg.length())
302 return "\t" +
toString(nDim) +
" x 1\tcluster\t";
310 sArgumentValue =
"\"" + (_stringParser.
getStringVars().find(sArgumentValue)->second) +
"\"";
311 return "\t1 x 1\t" + isRef +
"string\t";
315 if (sArgumentValue.substr(0, 7) ==
"string(")
322 if (sArgumentName.length() && sArgumentName.find(
"()") == std::string::npos)
329 if (_parser.
GetVar().find(sArgumentValue) != _parser.
GetVar().end())
337 return "\t1 x 1\t" + isRef +
"complex\t";
339 return "\t1 x 1\t" + isRef +
"double\t";
343 if (sArgumentValue.find_first_not_of(
"0123456789.eEi-+*/^!&|<>=(){},") == string::npos)
344 return "\t1 x 1\tdouble\t";
349 return "\t1 x 1\tstring\t";
352 if (sArgumentValue.find_first_of(
"$\"#?:") == string::npos)
353 return "\t1 x 1\tdouble\t";
356 return "\t1 x 1\t(...)\t";
459 vStackTrace.push_back(pair<string, Procedure*>(sStackItem, _currentProcedure));
462 for (
unsigned int i = 0; i <
vStackTrace.back().first.length(); i++)
528 _sErraticCommand, _sErraticModule, _nLineNumber);
550 const std::map<std::string, std::pair<std::string, std::string>>& _mLocalStrings,
551 const std::map<std::string, std::string>& _mLocalTables,
552 const std::map<std::string, std::string>& _mLocalClusters,
553 const std::map<std::string, std::string>& _mArguments,
554 const string& _sErraticCommand,
const string& _sErraticModule,
unsigned int _nLineNumber)
585 for (
const auto& iter : _mLocalVars)
588 if (iter.first != iter.second.first)
591 mLocalVars[iter.first +
"\t" + iter.second.first] = *iter.second.second;
596 for (
const auto& iter : _mLocalStrings)
599 if (iter.first != iter.second.first)
608 for (
const auto& iter : _mLocalTables)
611 if (iter.first != iter.second)
612 replaceAll(
sErraticCommand, (iter.second + (iter.second.back() ==
'(' ?
"" :
"(")).c_str(), (iter.first + (iter.first.back() ==
'(' ?
"" :
"(")).c_str());
618 if (iter.second ==
"string")
635 for (
const auto& iter : _mLocalClusters)
638 if (iter.first != iter.second)
639 replaceAll(
sErraticCommand, (iter.second + (iter.second.back() ==
'{' ?
"" :
"{")).c_str(), (iter.first + (iter.first.back() ==
'{' ?
"" :
"{")).c_str());
646 sTableData +=
"\tcluster\t"
648 + iter.second +
"{}";
657 for (
const auto& iter : _mArguments)
659 if (iter.first.back() ==
'(')
662 if (!isMacro && iter.first != iter.second)
665 mArguments[iter.first +
")\t" + iter.second] = iter.second;
667 else if (iter.first.back() ==
'{')
670 if (!isMacro && iter.first != iter.second)
673 mArguments[iter.first +
"}\t" + iter.second] = iter.second;
678 if (!isMacro && iter.first != iter.second)
681 mArguments[iter.first +
"\t" + iter.second] = iter.second;
720 for (
size_t i = 0; i < sVarArray.size(); i++)
722 for (
auto iter = mVarMap.begin(); iter != mVarMap.end(); ++iter)
724 if (iter->second == sVarArray[i])
726 size_t nBracePos = sVarArray[i].find(
'{');
729 if (nBracePos != std::string::npos)
734 if (nBracePos < sVarArray[i].length()-2)
735 nItem =
StrToInt(sVarArray[i].substr(nBracePos+1, sVarArray[i].length()-1-nBracePos-1))-1;
745 mLocalVars[iter->first +
"\t" + iter->second] = vVarArray[i];
765 vector<string> vModule;
783 vector<string> vStack;
814 vector<string> vNumVars;
818 char sepChar = (iter->first.find(
'@') != std::string::npos ?
'@' :
'\t');
820 if (iter->second.imag() && !(
isnan(iter->second.real()) &&
isnan(iter->second.imag())))
821 vNumVars.push_back((iter->first).substr(0, (iter->first).find(sepChar))
822 + (sepChar ==
'@' ?
"\t1 x 1\t(@) complex\t" :
"\t1 x 1\tcomplex\t")
825 vNumVars.push_back((iter->first).substr(0, (iter->first).find(sepChar))
826 + (sepChar ==
'@' ?
"\t1 x 1\t(@) double\t" :
"\t1 x 1\tdouble\t")
843 vector<string> vStringVars;
847 char sepChar = (iter->first.find(
'@') != std::string::npos ?
'@' :
'\t');
848 vStringVars.push_back((iter->first).substr(0, (iter->first).find(sepChar))
849 + (sepChar ==
'@' ?
"\t1 x 1\t(@) string\t" :
"\t1 x 1\tstring\t")
850 + iter->second +
"\t" + (iter->first).substr((iter->first).find(sepChar)+1));
866 vector<string> vTables;
870 vTables.push_back(iter->first +
"\t" + iter->second);
886 vector<string> vClusters;
890 vClusters.push_back(iter->first +
"\t" + iter->second);
906 vector<string> vArguments;
910 string sValue = iter->second;
911 vArguments.push_back((iter->first).substr(0, (iter->first).find(
'\t')) +
decodeType(sValue, (iter->first).substr(0, (iter->first).find(
'\t'))) + sValue + (iter->first).substr((iter->first).find(
'\t')));
927 vector<string> vGlobals;
932 map<string,string> mGlobals;
949 if (iter->first.substr(0, 2) !=
"_~")
960 if (iter->first.substr(0, 2) !=
"_~")
962 mGlobals[iter->first +
"{}"] =
toString(iter->second.size()) +
" x 1" +
"\tcluster\t"
970 if (iter->first.substr(0, 2) !=
"_~")
975 for (
auto iter = _parser.
GetVar().begin(); iter != _parser.
GetVar().end(); ++iter)
977 if (iter->first.substr(0, 2) !=
"_~")
979 if ((*iter->second).imag() && !(
isnan((*iter->second).real()) &&
isnan((*iter->second).imag())))
987 for (
auto iter = mGlobals.begin(); iter != mGlobals.end(); ++iter)
989 vGlobals.push_back(iter->first +
"\t" + iter->second +
"\t" + iter->first);
std::vector< value_type > vVarArray
std::vector< std::string > sVarArray
std::map< std::string, std::string > mVarMap
int getCurrentLineNumber() const
This member function returns the current line number as enumerated during passing the commands via "s...
std::string getCurrentCommand() const
This member function returns the current command line, which will or has been evaluated in the curren...
bool bEvaluatingFlowControlStatements
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,...
std::vector< mu::value_type > min(const std::string &sTable, std::string sDir) const
int getLines(StringView sTable, bool _bFull=false) const
const std::map< std::string, std::pair< size_t, size_t > > & getTableMap() const
bool isTable(const std::string &sTable) const
This member function returns, whether the passed table name corresponds to a known table.
std::vector< mu::value_type > max(const std::string &sTable, std::string sDir) const
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...
size_t size() const
This member function returns the size of the internal memory buffer as items.
std::string getString(size_t i) const
This member function returns the data of the i-th cluster item in memory as a string.
mu::value_type getDouble(size_t i) const
This member function returns the data of the i-th cluster item in memory as a value.
std::string getShortVectorRepresentation(size_t maxStringLength) const
This member function constructs a short version of a plain vector from the data in memory,...
unsigned short getType(size_t i) const
This member function returns the type of the i-th cluster item in the internal memory buffer.
Cluster & getCluster(StringView sCluster)
This member function returns a reference to the cluster indicated by the passed cluster identifier.
bool isCluster(StringView sCluster) const
This member function returns true, if the passed cluster identifier can be found in the internal map.
const std::map< std::string, Cluster > & getClusterMap() const
This class is the central string expression parser. It is designed as being a singleton with a persis...
bool isStringVar(const std::string &sVarName) const
Determine, whether the passed string is the identifier of a string variable.
std::string getStringValue(const std::string &sVar) const
Returns the value of the selected string variable.
const std::map< std::string, std::string > & getStringVars() const
std::vector< std::string > getNumVars()
This member function returns the numerical variables as a vector.
void throwException(SyntaxError error)
This member function shows the debugger with the corresponding error message obtained by the passed S...
void formatMessage()
This function replaces unmasked dollars with regular line break characters and also removes the maski...
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....
std::string sErrorMessage
void reset()
This member function resets the debugger after a thrown and displayed error.
std::vector< std::string > getClusters()
This member function returns the clusters as a vector.
std::map< std::string, mu::value_type > mLocalVars
std::vector< std::string > getGlobals()
This member function returns the current global variables as a vector.
void gatherLoopBasedInformations(const std::string &_sErraticCommand, unsigned int _nLineNumber, std::map< std::string, std::string > &mVarMap, const std::vector< mu::value_type > &vVarArray, const std::vector< std::string > &sVarArray)
This member funciton gathers the necessary debugging informations from the current executed control f...
std::map< std::string, std::string > mArguments
std::map< std::string, std::string > mLocalClusters
std::vector< std::pair< std::string, Procedure * > > vStackTrace
std::string sErraticModule
void resetBP()
This member function resets the debugger after an evaluated breakpoint. This excludes resetting the s...
bool validDebuggingInformations() const
std::vector< std::string > getStringVars()
This member function returns the string variables as a vector.
size_t nCurrentStackElement
std::vector< std::string > getTables()
This member function returns the tables as a vector.
std::map< std::string, std::string > mLocalTables
int showEvent(const std::string &sTitle)
This private member function shows the debugger for the current selected event and returns the debugg...
std::vector< std::string > getStackTrace()
This member function returns the stack trace as a vector.
bool select(size_t nStackElement)
This member function can be used to select a specific element in the current stack trace to read the ...
std::string decodeType(std::string &sArgumentValue, const std::string &sArgumentName="")
This private member function decodes the type of the arguments by looking at their values and apply s...
std::map< std::string, std::string > mLocalStrings
void popStackItem()
This member function removes the last item from the stack.
std::vector< std::string > getModuleInformations()
This member function returns the module informations as a vector.
std::string sErraticCommand
void showError(const std::string &sTitle)
This member function shows the debugger with the passed error message.
std::vector< std::string > getArguments()
This member function returns the procedure argument as a vector.
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...
NumeReDebugger()
Constructor.
This class provides the interface to the core of NumeRe. It provides all functionalities,...
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
NumeRe::StringParser & getStringParser()
MemoryManager & getMemoryManager()
static void showDebugEvent(const std::string &sTitle, const std::vector< std::string > &vStacktrace)
This member function passes the debugging information to the GUI to be displayed in the debugger wind...
static void gotoLine(const std::string &sFile, unsigned int nLine=0)
This member function handles opening files and jumping to lines as requested by the kernel.
static int waitForContinue()
This static function waits until the user sends a continuation command via the debugger and returns t...
This class implements the logic to evaluate complex procedures, which may be called recursively.
ProcedureVarFactory * _varFactory
std::string sProcCommandLine
unsigned int GetCurrentLine() const
This member function will return the current line number depending on whether a flow control statemen...
std::string sCurrentProcedureName
This class is the variable factory used by procedure instances to create their local variables and re...
std::map< std::string, std::string > mLocalClusters
std::map< std::string, std::string > mArguments
std::map< std::string, std::pair< std::string, std::string > > mLocalStrings
std::map< std::string, std::string > mLocalTables
std::map< std::string, std::pair< std::string, mu::value_type * > > mLocalVars
std::string maxString(unsigned int i1=0, unsigned int i2=std::string::npos, unsigned int nCol=0)
int getStringSize(unsigned int nCol=std::string::npos) const
unsigned int getStringCols() const
unsigned int getStringElements(unsigned int nCol=std::string::npos) const
std::string minString(unsigned int i1=0, unsigned int i2=std::string::npos, unsigned int nCol=0)
Common exception class for all exceptions thrown in NumeRe.
std::string getToken() const
Returns the error token containing additional information about the error.
@ PROCESS_ABORTED_BY_USER
const int * getIndices() const
Returns a pointer to the internal array of 4 error indices.
const varmap_type & GetVar() const
Return a map containing the used variables only.
Mathematical expressions parser.
#define DEFAULT_NUM_PRECISION
#define DEFAULT_MINMAX_PRECISION
ErrorType getErrorType(std::exception_ptr e_ptr)
This function obtains the error type of a catched exception and sets the last error message.
std::string getLastErrorMessage()
Return the last error message, which was catched by the getErrorType() function.
ErrorType
Defines the possible error types, which can be thrown in this application.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
bool isnan(const value_type &v)
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
int StrToInt(const std::string &)
Converts a string into an integer.
std::string toString(int)
Converts an integer to a string without the Settings bloat.