NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
debugger.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2016 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19
20
21#include "debugger.hpp"
22#include "../../kernel.hpp"
23#include "../utils/tools.hpp"
24#include "../procedure/procedurevarfactory.hpp"
25
26#define DEFAULT_NUM_PRECISION 7
27#define DEFAULT_MINMAX_PRECISION 5
28#define MAXSTRINGLENGTH 1024
29
30using namespace std;
31
32
37{
39 nLineNumber = string::npos;
40 sErraticCommand = "";
41 sErraticModule = "";
42 sErrorMessage = "";
43 bAlreadyThrown = false;
44 bDebuggerActive = false;
45 bExceptionHandled = false;
46}
47
48
58void NumeReDebugger::showError(exception_ptr e_ptr)
59{
60 if (!bDebuggerActive)
61 return;
62
63 // Rethrow the obtained exception to determine its
64 // type and its message
65 ErrorType type = getErrorType(e_ptr);
67
68 switch (type)
69 {
70 case TYPE_MATHERROR:
71 showError(_lang.get("ERR_MUP_HEAD_DBG"));
72 break;
76 showError(_lang.get("ERR_NR_HEAD_DBG"));
77 break;
80 showError(_lang.get("ERR_STD_INTERNAL_HEAD_DBG"));
81 break;
82 default:
83 return;
84 }
85}
86
87
96void NumeReDebugger::showError(const string& sTitle)
97{
99 return;
100
101 // Convert dollars into line breaks
103
104 bExceptionHandled = true;
105 showEvent(sTitle);
106 resetBP();
107}
108
109
121{
122 // do not show the debugger, if the user simply pressed ESC
124 {
125 if (error.getToken().length() && (error.errorcode == SyntaxError::PROCEDURE_THROW || error.errorcode == SyntaxError::LOOP_THROW))
126 {
127 sErrorMessage = _lang.get("ERR_NR_HEAD") + "\n\n" + error.getToken();
128 }
129 else
130 {
131 sErrorMessage = _lang.get("ERR_NR_" + toString((int)error.errorcode) + "_0_*", error.getToken(), toString(error.getIndices()[0]), toString(error.getIndices()[1]), toString(error.getIndices()[2]),
132 toString(error.getIndices()[3]));
133
134 if (sErrorMessage.substr(0, 7) == "ERR_NR_")
135 {
136 sErrorMessage = _lang.get("ERR_GENERIC_0", toString((int)error.errorcode));
137 }
138 }
139
140 sErrorMessage = _lang.get("ERR_NR_HEAD") + "\n\n" + sErrorMessage;
141
142 showError(_lang.get("ERR_NR_HEAD_DBG"));
143 }
144
145 throw error;
146}
147
148
159{
160 sErrorMessage.clear();
161 int nDebuggerCode = showEvent(_lang.get("DBG_HEADLINE"));
162 resetBP();
163
164 return nDebuggerCode;
165}
166
167
178int NumeReDebugger::showEvent(const string& sTitle)
179{
180 if (!bDebuggerActive)
182
183 // Show the debugger, if valid information is
184 // available
186 {
189
190 // Return the obtained debugger code
192 }
193
194 // Always return CONTINUE - we don't want to
195 // block the kernel due to lacking debugger
196 // information
198}
199
200
211{
212 for (size_t i = 1; i < sErrorMessage.length(); i++)
213 {
214 if (sErrorMessage[i] == '$' && sErrorMessage[i-1] != '\\')
215 sErrorMessage[i] = '\n';
216 else if (sErrorMessage[i] == '$' && sErrorMessage[i-1] == '\\')
217 {
218 sErrorMessage.erase(i-1, 1);
219 i--;
220 }
221 }
222}
223
224
235string NumeReDebugger::decodeType(string& sArgumentValue, const std::string& sArgumentName)
236{
240
241 // Only try to decode the arguments, if the user decided to
242 // do so
243 if (!NumeReKernel::getInstance()->getSettings().decodeArguments())
244 return "\t1 x 1\t(...)\t";
245
246 std::string isRef = "";
247
249 {
250 // Is the current argument a reference?
251 if (vStackTrace[nCurrentStackElement].second->_varFactory->isReference(sArgumentValue))
252 isRef = "(&) ";
253 }
254
255 // Is the current argument value a table?
256 if (_data.isTable(sArgumentValue))
257 {
258 string sCache = sArgumentValue.substr(0, sArgumentValue.find('('));
259
260 // Replace the value with its actual value and mark the
261 // argument type as reference
262 sArgumentValue = "{" + toString(_data.min(sCache, "")[0], DEFAULT_MINMAX_PRECISION) + ", ..., " + toString(_data.max(sCache, "")[0], DEFAULT_MINMAX_PRECISION) + "}";
263
264 std::string sDim = toString(_data.getLines(sCache, false)) + " x " + toString(_data.getCols(sCache, false));
265
266 // Determine whether this is a templated variable
267 if (sArgumentName.length() && sArgumentName.find("()") == std::string::npos)
268 isRef = isRef.length() ? "(&@) " : "(@) ";
269
270 return "\t" + sDim + "\t" + isRef + "table\t";
271 }
272
273 // Is the current argument value a cluster?
274 if (_data.isCluster(sArgumentValue))
275 {
276 NumeRe::Cluster& cluster = _data.getCluster(sArgumentValue.substr(0, sArgumentValue.find('{')));
277
278 // Replace the value with its actual value and mark the
279 // argument type as reference
280 sArgumentValue = cluster.getShortVectorRepresentation(MAXSTRINGLENGTH);
281
282 // Determine whether this is a reference or a templated
283 // variable
284 if (sArgumentName.length() && sArgumentName.find("{}") == std::string::npos)
285 isRef = isRef.length() ? "(&@) " : "(@) ";
286
287 return "\t" + toString(cluster.size()) + " x 1\t" + isRef + "cluster\t";
288 }
289
290 // Is the current value surrounded from braces?
291 if (sArgumentValue.front() == '{' && sArgumentValue.back() == '}')
292 {
293 size_t nDim = 0;
294 string sArg = sArgumentValue.substr(1, sArgumentValue.length()-2);
295
296 while (sArg.length())
297 {
298 nDim++;
299 getNextArgument(sArg, true);
300 }
301
302 return "\t" + toString(nDim) + " x 1\tcluster\t";
303 }
304
305 // Is the current argument a string variable?
306 if (_stringParser.getStringVars().find(sArgumentValue) != _stringParser.getStringVars().end())
307 {
308 // Replace the value with its actual value and mark the
309 // argument type as reference
310 sArgumentValue = "\"" + (_stringParser.getStringVars().find(sArgumentValue)->second) + "\"";
311 return "\t1 x 1\t" + isRef + "string\t";
312 }
313
314 // Equals the current argument the string table?
315 if (sArgumentValue.substr(0, 7) == "string(")
316 {
317 // Replace the value with its actual value and mark the
318 // argument type as reference
319 sArgumentValue = "{\"" + replaceControlCharacters(_data.minString()) + "\", ..., \"" + replaceControlCharacters(_data.maxString()) + "\"}";
320
321 // Determine whether this is a templated variable
322 if (sArgumentName.length() && sArgumentName.find("()") == std::string::npos)
323 return "\t" + toString(_data.getStringSize()) + " x " + toString(_data.getStringCols()) + "\t(&@) string\t";
324
325 return "\t" + toString(_data.getStringSize()) + " x " + toString(_data.getStringCols()) + "\t(&) string\t";
326 }
327
328 // Is the current argument a numerical variable?
329 if (_parser.GetVar().find(sArgumentValue) != _parser.GetVar().end())
330 {
331 // Replace the value with its actual value and mark the
332 // argument type as reference
333 mu::value_type* address = _parser.GetVar().find(sArgumentValue)->second;
334 sArgumentValue = toString(*address, (address->imag() ? 2*DEFAULT_NUM_PRECISION : DEFAULT_NUM_PRECISION));
335
336 if (address->imag())
337 return "\t1 x 1\t" + isRef + "complex\t";
338
339 return "\t1 x 1\t" + isRef + "double\t";
340 }
341
342 // Is it a constant numerical expression or value?
343 if (sArgumentValue.find_first_not_of("0123456789.eEi-+*/^!&|<>=(){},") == string::npos)
344 return "\t1 x 1\tdouble\t";
345
346 // Is the current argument a string expression?
347 // This heuristic is potentially wrong
348 if (containsStrings(sArgumentValue))
349 return "\t1 x 1\tstring\t";
350
351 // Does it not contain any special characters?
352 if (sArgumentValue.find_first_of("$\"#?:") == string::npos)
353 return "\t1 x 1\tdouble\t";
354
355 // We cannot decode it
356 return "\t1 x 1\t(...)\t";
357}
358
359
370bool NumeReDebugger::select(size_t nStackElement)
371{
372 // Ensure that the selected element exists
373 if (nStackElement >= vStackTrace.size())
374 return false;
375
376 // Get the procedure pointer
377 Procedure* _curProcedure = vStackTrace[nStackElement].second;
378
379 // Do nothing, if it does not exist
380 // (for some reason)
381 if (!_curProcedure)
382 return false;
383
384 // Store the new stack position
385 nCurrentStackElement = nStackElement;
386
387 // Clear the breakpoint information
388 resetBP();
389
390 // If the current procedure is evaluating a flow control
391 // statement, obtain the corresponding information here
392 if (_curProcedure->bEvaluatingFlowControlStatements)
393 {
394 gatherLoopBasedInformations(_curProcedure->getCurrentCommand(), _curProcedure->getCurrentLineNumber(), _curProcedure->mVarMap, _curProcedure->vVarArray, _curProcedure->sVarArray);
395 }
396
397 // Obtain the remaining information here
398 gatherInformations(_curProcedure->_varFactory, _curProcedure->sProcCommandLine, _curProcedure->sCurrentProcedureName, _curProcedure->GetCurrentLine());
399
400 // Jump to the selected file and the selected line number
402
403 return true;
404}
405
406
415{
416 vStackTrace.clear();
417 sErrorMessage.clear();
418 resetBP();
419 return;
420}
421
422
432{
433 nLineNumber = string::npos;
434 sErraticCommand = "";
435 sErraticModule = "";
436 mLocalVars.clear();
437 mLocalStrings.clear();
438 mLocalTables.clear();
439 mLocalClusters.clear();
440 mArguments.clear();
441 bAlreadyThrown = false;
442 return;
443}
444
445
457void NumeReDebugger::pushStackItem(const string& sStackItem, Procedure* _currentProcedure)
458{
459 vStackTrace.push_back(pair<string, Procedure*>(sStackItem, _currentProcedure));
460
461 // Insert a leading backslash, if it missing
462 for (unsigned int i = 0; i < vStackTrace.back().first.length(); i++)
463 {
464 if ((!i && vStackTrace.back().first[i] == '$') || (i && vStackTrace.back().first[i] == '$' && vStackTrace.back().first[i-1] != '\\'))
465 vStackTrace.back().first.insert(i,1,'\\');
466 }
467
468 // Insert the single quotation marks for explicit procedure
469 // paths
470 if (vStackTrace.back().first.find('/') != string::npos && vStackTrace.back().first.find('/') < vStackTrace.back().first.find('('))
471 {
472 vStackTrace.back().first.insert(vStackTrace.back().first.find('$')+1, "'");
473 vStackTrace.back().first.insert(vStackTrace.back().first.find('('), "'");
474 }
475
477
478 return;
479}
480
481
490{
491 if (vStackTrace.size())
492 vStackTrace.pop_back();
493
494 if (vStackTrace.size())
496
497 return;
498}
499
500
516void NumeReDebugger::gatherInformations(ProcedureVarFactory* _varFactory, const string& _sErraticCommand, const string& _sErraticModule, unsigned int _nLineNumber)
517{
519 return;
520
521 if (!_varFactory)
522 {
523 bAlreadyThrown = true;
524 return;
525 }
526
527 gatherInformations(_varFactory->mLocalVars, _varFactory->mLocalStrings, _varFactory->mLocalTables, _varFactory->mLocalClusters, _varFactory->mArguments,
528 _sErraticCommand, _sErraticModule, _nLineNumber);
529}
530
531
549void NumeReDebugger:: gatherInformations(const std::map<std::string, std::pair<std::string, mu::value_type*>>& _mLocalVars,
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)
555{
556 if (!bDebuggerActive)
557 return;
558
559 if (bAlreadyThrown)
560 return;
561
562 // Get the instance of the kernel
564
565 // If the instance is zero, something really bad happened
566 if (!instance)
567 return;
568
569 // Store the command line containing the error
570 if (!sErraticCommand.length())
571 sErraticCommand = _sErraticCommand;
572
573 // Removes the leading and trailing whitespaces
575
576 sErraticModule = _sErraticModule;
577
578 if (nLineNumber == string::npos)
579 nLineNumber = _nLineNumber;
580
581 bAlreadyThrown = true;
582
583 // Store the local numerical variables and replace their
584 // occurence with their definition in the command lines
585 for (const auto& iter : _mLocalVars)
586 {
587 // Replace the occurences
588 if (iter.first != iter.second.first)
589 replaceAll(sErraticCommand, iter.second.first.c_str(), iter.first.c_str());
590
591 mLocalVars[iter.first + "\t" + iter.second.first] = *iter.second.second;
592 }
593
594 // Store the local string variables and replace their
595 // occurence with their definition in the command lines
596 for (const auto& iter : _mLocalStrings)
597 {
598 // Replace the occurences
599 if (iter.first != iter.second.first)
600 replaceAll(sErraticCommand, iter.second.first.c_str(), iter.first.c_str());
601
602 const std::string sValue = toExternalString(instance->getStringParser().getStringVars().at(iter.second.first));
603 mLocalStrings[iter.first + "\t" + iter.second.first] = replaceControlCharacters(ellipsize(sValue, MAXSTRINGLENGTH));
604 }
605
606 // Store the local tables and replace their
607 // occurence with their definition in the command lines
608 for (const auto& iter : _mLocalTables)
609 {
610 // Replace the occurences
611 if (iter.first != iter.second)
612 replaceAll(sErraticCommand, (iter.second + (iter.second.back() == '(' ? "" : "(")).c_str(), (iter.first + (iter.first.back() == '(' ? "" : "(")).c_str());
613
614 string sTableData;
615
616 // Extract the minimal and maximal values of the tables
617 // to display them in the variable viewer panel
618 if (iter.second == "string")
619 {
620 sTableData = toString(instance->getMemoryManager().getStringElements()) + " x " + toString(instance->getMemoryManager().getStringCols());
621 sTableData += "\tstring\t{\"" + replaceControlCharacters(instance->getMemoryManager().minString()) + "\", ..., \""
622 + replaceControlCharacters(instance->getMemoryManager().maxString()) + "\"}\tstring()";
623 }
624 else
625 {
626 sTableData = toString(instance->getMemoryManager().getLines(iter.second, false)) + " x " + toString(instance->getMemoryManager().getCols(iter.second, false));
627 sTableData += "\ttable\t{" + toString(instance->getMemoryManager().min(iter.second, "")[0], DEFAULT_MINMAX_PRECISION) + ", ..., " + toString(instance->getMemoryManager().max(iter.second, "")[0], DEFAULT_MINMAX_PRECISION) + "}\t" + iter.second + "()";
628 }
629
630 mLocalTables[iter.first + "()"] = sTableData;
631 }
632
633 // Store the local clusters and replace their
634 // occurence with their definition in the command lines
635 for (const auto& iter : _mLocalClusters)
636 {
637 // Replace the occurences
638 if (iter.first != iter.second)
639 replaceAll(sErraticCommand, (iter.second + (iter.second.back() == '{' ? "" : "{")).c_str(), (iter.first + (iter.first.back() == '{' ? "" : "{")).c_str());
640
641 string sTableData;
642
643 // Extract the minimal and maximal values of the tables
644 // to display them in the variable viewer panel
645 sTableData = toString(instance->getMemoryManager().getCluster(iter.second).size()) + " x 1";
646 sTableData += "\tcluster\t"
648 + iter.second + "{}";
649
650 mLocalClusters[iter.first + "{}"] = sTableData;
651 }
652
653 // Is this procedure a macro?
654 bool isMacro = nCurrentStackElement < vStackTrace.size() ? vStackTrace[nCurrentStackElement].second->getProcedureFlags() & ProcedureCommandLine::FLAG_MACRO : false;
655
656 // Store the arguments
657 for (const auto& iter : _mArguments)
658 {
659 if (iter.first.back() == '(')
660 {
661 // Replace the occurences
662 if (!isMacro && iter.first != iter.second)
663 replaceAll(sErraticCommand, (iter.second + "(").c_str(), iter.first.c_str());
664
665 mArguments[iter.first + ")\t" + iter.second] = iter.second;
666 }
667 else if (iter.first.back() == '{')
668 {
669 // Replace the occurences
670 if (!isMacro && iter.first != iter.second)
671 replaceAll(sErraticCommand, (iter.second + "{").c_str(), iter.first.c_str());
672
673 mArguments[iter.first + "}\t" + iter.second] = iter.second;
674 }
675 else
676 {
677 // Replace the occurences
678 if (!isMacro && iter.first != iter.second)
679 replaceAll(sErraticCommand, iter.second.c_str(), iter.first.c_str());
680
681 mArguments[iter.first + "\t" + iter.second] = iter.second;
682 }
683 }
684}
685
686
701void NumeReDebugger::gatherLoopBasedInformations(const string& _sErraticCommand, unsigned int _nLineNumber, map<string, string>& mVarMap, const std::vector<mu::value_type>& vVarArray, const std::vector<std::string>& sVarArray)
702{
703 if (!bDebuggerActive)
704 return;
705
706 if (bAlreadyThrown)
707 return;
708
709 // Store command line and line number
710 sErraticCommand = _sErraticCommand;
711
712 if (sErraticCommand.substr(sErraticCommand.find_first_not_of(' '), 2) == "|>")
713 sErraticCommand.erase(sErraticCommand.find_first_not_of(' '), 2);
714
715 nLineNumber = _nLineNumber;
717
718 // store variable names and replace their occurences with
719 // their definitions
720 for (size_t i = 0; i < sVarArray.size(); i++)
721 {
722 for (auto iter = mVarMap.begin(); iter != mVarMap.end(); ++iter)
723 {
724 if (iter->second == sVarArray[i])
725 {
726 size_t nBracePos = sVarArray[i].find('{');
727
728 // Store the variables
729 if (nBracePos != std::string::npos)
730 {
731 NumeRe::Cluster& iterData = instance->getMemoryManager().getCluster(sVarArray[i]);
732 size_t nItem = 0;
733
734 if (nBracePos < sVarArray[i].length()-2)
735 nItem = StrToInt(sVarArray[i].substr(nBracePos+1, sVarArray[i].length()-1-nBracePos-1))-1;
736
737 if (iterData.getType(nItem) == NumeRe::ClusterItem::ITEMTYPE_DOUBLE)
738 mLocalVars[iter->first + "@" + iter->second] = iterData.getDouble(nItem);
739 else if (iterData.getType(nItem) == NumeRe::ClusterItem::ITEMTYPE_STRING)
740 mLocalStrings[iter->first + "@" + iter->second] = iterData.getString(nItem);
741 }
742 else if (instance->getStringParser().isStringVar(sVarArray[i]))
743 mLocalStrings[iter->first + "\t" + iter->second] = toExternalString(instance->getStringParser().getStringValue(sVarArray[i]));
744 else
745 mLocalVars[iter->first + "\t" + iter->second] = vVarArray[i];
746
747 // Replace the variables
748 while (sErraticCommand.find(iter->second) != string::npos)
749 sErraticCommand.replace(sErraticCommand.find(iter->second), (iter->second).length(), iter->first);
750 }
751 }
752 }
753}
754
755
764{
765 vector<string> vModule;
766 vModule.push_back(sErraticCommand);
767 vModule.push_back(sErraticModule);
768 vModule.push_back(toString(nLineNumber+1));
769 vModule.push_back(sErrorMessage);
770 return vModule;
771}
772
773
782{
783 vector<string> vStack;
784
785 // Return a corresponding message, if the stack is empty
786 // Append the line number and the file name, though
787 if (!vStackTrace.size())
788 {
789 vStack.push_back(_lang.get("DBG_STACK_EMPTY") + "\t" + sErraticModule + "\t" + toString(nLineNumber+1));
790 return vStack;
791 }
792
793 // Return the stack and append the current procedure
794 // name and the line number
795 for (int i = vStackTrace.size()-1; i >= 0; i--)
796 {
797 Procedure* _curProc = vStackTrace[i].second;
798 vStack.push_back("$" + vStackTrace[i].first + "\t" + _curProc->sCurrentProcedureName + "\t" + toString(_curProc->GetCurrentLine()+1));
799 }
800
801 return vStack;
802}
803
804
813{
814 vector<string> vNumVars;
815
816 for (auto iter = mLocalVars.begin(); iter != mLocalVars.end(); ++iter)
817 {
818 char sepChar = (iter->first.find('@') != std::string::npos ? '@' : '\t');
819
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")
823 + toString(iter->second, 2*DEFAULT_NUM_PRECISION) + "\t" + (iter->first).substr((iter->first).find(sepChar)+1));
824 else
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")
827 + toString(iter->second, DEFAULT_NUM_PRECISION) + "\t" + (iter->first).substr((iter->first).find(sepChar)+1));
828 }
829
830 return vNumVars;
831}
832
833
842{
843 vector<string> vStringVars;
844
845 for (auto iter = mLocalStrings.begin(); iter != mLocalStrings.end(); ++iter)
846 {
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));
851 }
852
853 return vStringVars;
854}
855
856
865{
866 vector<string> vTables;
867
868 for (auto iter = mLocalTables.begin(); iter != mLocalTables.end(); ++iter)
869 {
870 vTables.push_back(iter->first + "\t" + iter->second);
871 }
872
873 return vTables;
874}
875
876
885{
886 vector<string> vClusters;
887
888 for (auto iter = mLocalClusters.begin(); iter != mLocalClusters.end(); ++iter)
889 {
890 vClusters.push_back(iter->first + "\t" + iter->second);
891 }
892
893 return vClusters;
894}
895
896
905{
906 vector<string> vArguments;
907
908 for (auto iter = mArguments.begin(); iter != mArguments.end(); ++iter)
909 {
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')));
912 }
913
914 return vArguments;
915}
916
917
926{
927 vector<string> vGlobals;
928
929 if (!vStackTrace.size())
930 return vGlobals;
931
932 map<string,string> mGlobals;
933
937
938 // Is there anything in the string object?
939 if (_data.getStringElements())
940 {
941 mGlobals["string()"] = toString(_data.getStringElements()) + " x " + toString(_data.getStringCols())
942 + "\tstring\t{\"" + replaceControlCharacters(_data.minString()) + "\", ...,\""
943 + replaceControlCharacters(_data.maxString()) + "\"}";
944 }
945
946 // List all relevant caches
947 for (auto iter = _data.getTableMap().begin(); iter != _data.getTableMap().end(); ++iter)
948 {
949 if (iter->first.substr(0, 2) != "_~")
950 {
951 mGlobals[iter->first + "()"] = toString(_data.getLines(iter->first, false)) + " x " + toString(_data.getCols(iter->first, false))
952 + "\ttable\t{" + toString(_data.min(iter->first, "")[0], DEFAULT_MINMAX_PRECISION) + ", ..., "
953 + toString(_data.max(iter->first, "")[0], DEFAULT_MINMAX_PRECISION) + "}";
954 }
955 }
956
957 // List all relevant clusters
958 for (auto iter = _data.getClusterMap().begin(); iter != _data.getClusterMap().end(); ++iter)
959 {
960 if (iter->first.substr(0, 2) != "_~")
961 {
962 mGlobals[iter->first + "{}"] = toString(iter->second.size()) + " x 1" + "\tcluster\t"
963 + replaceControlCharacters(iter->second.getShortVectorRepresentation(MAXSTRINGLENGTH));
964 }
965 }
966
967 // List all relevant string variables
968 for (auto iter = _stringParser.getStringVars().begin(); iter != _stringParser.getStringVars().end(); ++iter)
969 {
970 if (iter->first.substr(0, 2) != "_~")
971 mGlobals[iter->first] = "1 x 1\tstring\t" + replaceControlCharacters(ellipsize(toExternalString(iter->second), MAXSTRINGLENGTH));
972 }
973
974 // List all relevant numerical variables
975 for (auto iter = _parser.GetVar().begin(); iter != _parser.GetVar().end(); ++iter)
976 {
977 if (iter->first.substr(0, 2) != "_~")
978 {
979 if ((*iter->second).imag() && !(isnan((*iter->second).real()) && isnan((*iter->second).imag())))
980 mGlobals[iter->first] = "1 x 1\tcomplex\t" + toString(*iter->second, 2*DEFAULT_NUM_PRECISION);
981 else
982 mGlobals[iter->first] = "1 x 1\tdouble\t" + toString(*iter->second, DEFAULT_NUM_PRECISION);
983 }
984 }
985
986 // Push everything into the vector
987 for (auto iter = mGlobals.begin(); iter != mGlobals.end(); ++iter)
988 {
989 vGlobals.push_back(iter->first + "\t" + iter->second + "\t" + iter->first);
990 }
991
992 // Return the vector filled with the global variables
993 return vGlobals;
994}
995
996
std::vector< value_type > vVarArray
Definition: flowctrl.hpp:103
std::vector< std::string > sVarArray
Definition: flowctrl.hpp:104
std::map< std::string, std::string > mVarMap
Definition: flowctrl.hpp:118
int getCurrentLineNumber() const
This member function returns the current line number as enumerated during passing the commands via "s...
Definition: flowctrl.cpp:4691
std::string getCurrentCommand() const
This member function returns the current command line, which will or has been evaluated in the curren...
Definition: flowctrl.cpp:4708
bool bEvaluatingFlowControlStatements
Definition: flowctrl.hpp:123
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 ...
Definition: language.cpp:292
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...
Definition: cluster.hpp:325
size_t size() const
This member function returns the size of the internal memory buffer as items.
Definition: cluster.cpp:356
std::string getString(size_t i) const
This member function returns the data of the i-th cluster item in memory as a string.
Definition: cluster.cpp:745
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.
Definition: cluster.cpp:541
std::string getShortVectorRepresentation(size_t maxStringLength) const
This member function constructs a short version of a plain vector from the data in memory,...
Definition: cluster.cpp:962
unsigned short getType(size_t i) const
This member function returns the type of the i-th cluster item in the internal memory buffer.
Definition: cluster.cpp:524
Cluster & getCluster(StringView sCluster)
This member function returns a reference to the cluster indicated by the passed cluster identifier.
Definition: cluster.cpp:2077
bool isCluster(StringView sCluster) const
This member function returns true, if the passed cluster identifier can be found in the internal map.
Definition: cluster.cpp:2041
const std::map< std::string, Cluster > & getClusterMap() const
Definition: cluster.hpp:475
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.
Definition: debugger.cpp:812
unsigned int nLineNumber
Definition: debugger.hpp:47
void throwException(SyntaxError error)
This member function shows the debugger with the corresponding error message obtained by the passed S...
Definition: debugger.cpp:120
void formatMessage()
This function replaces unmasked dollars with regular line break characters and also removes the maski...
Definition: debugger.cpp:210
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...
Definition: debugger.cpp:516
int showBreakPoint()
This member function shows the debugger for the current breakpoint and returns the debugger code (i....
Definition: debugger.cpp:158
bool bExceptionHandled
Definition: debugger.hpp:57
std::string sErrorMessage
Definition: debugger.hpp:50
void reset()
This member function resets the debugger after a thrown and displayed error.
Definition: debugger.cpp:414
bool bAlreadyThrown
Definition: debugger.hpp:56
bool bDebuggerActive
Definition: debugger.hpp:60
std::vector< std::string > getClusters()
This member function returns the clusters as a vector.
Definition: debugger.cpp:884
std::map< std::string, mu::value_type > mLocalVars
Definition: debugger.hpp:51
std::vector< std::string > getGlobals()
This member function returns the current global variables as a vector.
Definition: debugger.cpp:925
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...
Definition: debugger.cpp:701
std::map< std::string, std::string > mArguments
Definition: debugger.hpp:55
std::map< std::string, std::string > mLocalClusters
Definition: debugger.hpp:54
std::vector< std::pair< std::string, Procedure * > > vStackTrace
Definition: debugger.hpp:46
std::string sErraticModule
Definition: debugger.hpp:49
void resetBP()
This member function resets the debugger after an evaluated breakpoint. This excludes resetting the s...
Definition: debugger.cpp:431
bool validDebuggingInformations() const
Definition: debugger.hpp:81
std::vector< std::string > getStringVars()
This member function returns the string variables as a vector.
Definition: debugger.cpp:841
size_t nCurrentStackElement
Definition: debugger.hpp:58
std::vector< std::string > getTables()
This member function returns the tables as a vector.
Definition: debugger.cpp:864
std::map< std::string, std::string > mLocalTables
Definition: debugger.hpp:53
int showEvent(const std::string &sTitle)
This private member function shows the debugger for the current selected event and returns the debugg...
Definition: debugger.cpp:178
std::vector< std::string > getStackTrace()
This member function returns the stack trace as a vector.
Definition: debugger.cpp:781
bool select(size_t nStackElement)
This member function can be used to select a specific element in the current stack trace to read the ...
Definition: debugger.cpp:370
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...
Definition: debugger.cpp:235
std::map< std::string, std::string > mLocalStrings
Definition: debugger.hpp:52
void popStackItem()
This member function removes the last item from the stack.
Definition: debugger.cpp:489
std::vector< std::string > getModuleInformations()
This member function returns the module informations as a vector.
Definition: debugger.cpp:763
std::string sErraticCommand
Definition: debugger.hpp:48
void showError(const std::string &sTitle)
This member function shows the debugger with the passed error message.
Definition: debugger.cpp:96
std::vector< std::string > getArguments()
This member function returns the procedure argument as a vector.
Definition: debugger.cpp:904
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...
Definition: debugger.cpp:457
NumeReDebugger()
Constructor.
Definition: debugger.cpp:36
This class provides the interface to the core of NumeRe. It provides all functionalities,...
Definition: kernel.hpp:97
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
Definition: kernel.hpp:221
NumeRe::StringParser & getStringParser()
Definition: kernel.hpp:286
mu::Parser & getParser()
Definition: kernel.hpp:281
MemoryManager & getMemoryManager()
Definition: kernel.hpp:263
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...
Definition: kernel.cpp:3405
@ DEBUGGER_CONTINUE
Definition: kernel.hpp:131
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.
Definition: kernel.cpp:3098
static int waitForContinue()
This static function waits until the user sends a continuation command via the debugger and returns t...
Definition: kernel.cpp:3440
This class implements the logic to evaluate complex procedures, which may be called recursively.
Definition: procedure.hpp:56
ProcedureVarFactory * _varFactory
Definition: procedure.hpp:74
std::string sProcCommandLine
Definition: procedure.hpp:69
unsigned int GetCurrentLine() const
This member function will return the current line number depending on whether a flow control statemen...
Definition: procedure.cpp:2563
std::string sCurrentProcedureName
Definition: procedure.hpp:63
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.
Definition: error.hpp:32
std::string getToken() const
Returns the error token containing additional information about the error.
Definition: error.hpp:438
ErrorCode errorcode
Definition: error.hpp:234
@ LOOP_THROW
Definition: error.hpp:152
@ PROCEDURE_THROW
Definition: error.hpp:199
@ PROCESS_ABORTED_BY_USER
Definition: error.hpp:202
const int * getIndices() const
Returns a pointer to the internal array of 4 error indices.
Definition: error.hpp:458
const varmap_type & GetVar() const
Return a map containing the used variables only.
Mathematical expressions parser.
Definition: muParser.h:51
Language _lang
Definition: kernel.cpp:39
#define MAXSTRINGLENGTH
Definition: debugger.cpp:28
#define DEFAULT_NUM_PRECISION
Definition: debugger.cpp:26
#define DEFAULT_MINMAX_PRECISION
Definition: debugger.cpp:27
ErrorType getErrorType(std::exception_ptr e_ptr)
This function obtains the error type of a catched exception and sets the last error message.
Definition: error.cpp:42
std::string getLastErrorMessage()
Return the last error message, which was catched by the getErrorType() function.
Definition: error.cpp:121
ErrorType
Defines the possible error types, which can be thrown in this application.
Definition: error.hpp:469
@ TYPE_INTERNALERROR
Definition: error.hpp:476
@ TYPE_ASSERTIONERROR
Definition: error.hpp:474
@ TYPE_SYNTAXERROR
Definition: error.hpp:473
@ TYPE_MATHERROR
Definition: error.hpp:472
@ TYPE_CRITICALERROR
Definition: error.hpp:477
@ TYPE_CUSTOMERROR
Definition: error.hpp:475
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
bool isnan(const value_type &v)
Definition: muParserDef.h:379
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 replaceControlCharacters(std::string sToModify)
This function is a simple wrapper for replaceAll() and specialized to remove control characters from ...
std::string toExternalString(std::string sStr)
Converts an internal string to the external representation in the terminal.
std::string ellipsize(const std::string &sLongString, size_t nMaxStringLength)
Shortens the passed string by introducing a ellipsis in the middle of the string, if the string is lo...
std::string getNextArgument(std::string &sArgList, bool bCut)
Definition: tools.cpp:2294
void replaceAll(std::string &sToModify, const char *sToRep, const char *sNewValue, size_t nStart, size_t nEnd)
This function replaces all occurences of the string sToRep in the string sToModify with the new value...
std::string toString(int)
Converts an integer to a string without the Settings bloat.
bool containsStrings(const string &sLine)
This function checks, whether the passed expression contains strings or valtostring parser.
Definition: tools.cpp:2470