NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
flowctrl.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2014 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// Header zu Klasse "Loop"
21
22#ifndef FLOWCTRL_HPP
23#define FLOWCTRL_HPP
24
25#include <string>
26#include <vector>
27#include <map>
28#include <set>
29
30#include "../ParserLib/muParser.h"
31#include "../datamanagement/memorymanager.hpp"
32#include "../maths/define.hpp"
33#include "../settings.hpp"
34#include "../io/output.hpp"
35#include "../plotting/plotdata.hpp"
36#include "../script.hpp"
37
38
39using namespace mu;
40
41struct FlowCtrlCommand;
42
43
45{
47
48 private:
50
58
59 protected:
61 {
81 CALCTYPE_ASSERT = 0x40000
82 };
83
85 {
90 };
91
93 {
100 };
101
102 std::vector<FlowCtrlCommand> vCmdArray;
103 std::vector<value_type> vVarArray;
104 std::vector<std::string> sVarArray;
106 std::vector<std::vector<int>> nJumpTable;
107 std::vector<int> nCalcType;
108 std::string sLoopNames;
109
111
117 std::string sLoopPlotCompose;
118 std::map<std::string,std::string> mVarMap;
119 std::set<std::string> inlineClusters;
121 bool bMask;
127 std::string sTestClusterName;
129
132
133 int for_loop(int nth_Cmd = 0, int nth_Loop = 0);
134 int range_based_for_loop(int nth_Cmd = 0, int nth_Loop = 0);
135 int while_loop(int nth_Cmd = 0, int nth_Loop = 0);
136 int if_fork(int nth_Cmd = 0, int nth_Loop = -1);
137 int switch_fork(int nth_Cmd = 0, int nth_Loop = -1);
138 int try_catch(int nth_Cmd = 0, int nth_Loop = -1);
139
140 typedef int(FlowCtrl::*FlowCtrlFunction)(int, int);
141
142 int compile(std::string sLine, int nthCmd);
143 int calc(StringView sLine, int nthCmd);
144 value_type* evalHeader(int& nNum, std::string& sHeadExpression, bool bIsForHead, int nth_Cmd, const std::string& sHeadCommand);
145 NumeRe::Cluster evalRangeBasedHeader(std::string& sHeadExpression, int nth_Cmd, const std::string& sHeadCommand);
146 int evalForkFlowCommands(int __j, int nth_loop);
147
148 void replaceLocalVars(std::string& sLine);
149 void replaceLocalVars(const std::string& sOldVar, const std::string& sNewVar, size_t from = 0, size_t to = std::string::npos);
150
151 bool checkFlowControlArgument(const std::string& sFlowControlArgument, bool isForLoop = false);
152 bool checkCaseValue(const std::string& sCaseDefinition);
153
154 std::string extractFlagsAndIndexVariables();
156 void prepareSwitchExpression(int nSwitchStart);
158 void prepareLocalVarsAndReplace(std::string& sVars);
159 void updateTestStats();
160
161
162 virtual int procedureCmdInterface(std::string& sLine);
163 virtual ProcedureInterfaceRetVal procedureInterface(std::string& sLine, Parser& _parser, FunctionDefinitionManager& _functions, MemoryManager& _data, Output& _out, PlotData& _pData, Script& _script, Settings& _option, int nth_command);
164 virtual int isInline(const std::string& sProc);
165 virtual int evalDebuggerBreakPoint(Parser& _parser, Settings& _option);
166 virtual int getErrorInformationForDebugger();
167 virtual std::vector<std::string> expandInlineProcedures(std::string& sLine);
168 virtual int catchExceptionForTest(std::exception_ptr e_ptr, bool bSupressAnswer_back, int nLine);
169
170 public:
171 FlowCtrl();
172 virtual ~FlowCtrl();
173
174 int getCurrentBlockDepth() const;
175 inline std::string getCurrentBlock() const
176 {
177 if (sLoopNames.length())
178 return sLoopNames.substr(sLoopNames.rfind(';')+1);
179 else
180 return "";
181 }
183 {
184 return ReturnVal;
185 }
186 inline bool getReturnSignal() const
187 {
188 return bReturnSignal;
189 }
190 void setCommand(std::string& __sCmd, int nCurrentLine);
191 void eval();
192 void reset();
193
194 int getCurrentLineNumber() const;
195 std::string getCurrentCommand() const;
196
197 static bool isFlowCtrlStatement(const std::string& sCmd);
198 static bool isAnyFlowCtrlStatement(const std::string& sCmd);
199
200};
201
202
204{
205 std::string sCommand;
208 std::string sFlowCtrlHeader;
211
213
214
215 FlowCtrlCommand(const std::string& sCmd, int nLine, bool bStatement = false, FlowCtrl::FlowCtrlFunction fn = nullptr)
216 : sCommand(sCmd), nInputLine(nLine), bFlowCtrlStatement(bStatement), sFlowCtrlHeader(""), nVarIndex(-1), nRFStepping(0u), fcFn(fn) {}
217};
218
219#endif
220
221
int if_fork(int nth_Cmd=0, int nth_Loop=-1)
This member function realizes the IF-ELSE control flow statement. The return value is either an error...
Definition: flowctrl.cpp:843
MemoryManager * _dataRef
Definition: flowctrl.hpp:52
void replaceLocalVars(std::string &sLine)
This member function is used to replace variable occurences with their (auto-determined) internal nam...
Definition: flowctrl.cpp:3969
int calc(StringView sLine, int nthCmd)
This member function does the hard work and calculates the numerical and std::string results for the ...
Definition: flowctrl.cpp:3329
int nLoopSafety
Definition: flowctrl.hpp:124
void eval()
This member function prepares the command array by pre-evaluating all constant stuff or function call...
Definition: flowctrl.cpp:2340
void fillJumpTableAndExpandRecursives()
Go again through the whole command set and fill the jump table with the corresponding block ends and ...
Definition: flowctrl.cpp:4194
std::vector< std::vector< int > > nJumpTable
Definition: flowctrl.hpp:106
bool bFunctionsReplaced
Definition: flowctrl.hpp:116
Script * _scriptRef
Definition: flowctrl.hpp:57
int getCurrentBlockDepth() const
Returns the current block depth while reading a flow control statement to memory.
Definition: flowctrl.cpp:119
std::vector< value_type > vVarArray
Definition: flowctrl.hpp:103
Parser * _parserRef
Definition: flowctrl.hpp:51
virtual int procedureCmdInterface(std::string &sLine)
Dummy implementation.
Definition: flowctrl.cpp:4791
bool checkCaseValue(const std::string &sCaseDefinition)
This member function checks, whether the entered case definition is valid or not.
Definition: flowctrl.cpp:4078
NumeRe::Cluster evalRangeBasedHeader(std::string &sHeadExpression, int nth_Cmd, const std::string &sHeadCommand)
This member function handles the evaluation of the range-based flow control headers....
Definition: flowctrl.cpp:1696
bool getReturnSignal() const
Definition: flowctrl.hpp:186
bool bReturnSignal
Definition: flowctrl.hpp:131
void prepareSwitchExpression(int nSwitchStart)
This member function will prepare the single logical switch expression.
Definition: flowctrl.cpp:4448
bool bMask
Definition: flowctrl.hpp:121
std::vector< std::string > sVarArray
Definition: flowctrl.hpp:104
static bool isAnyFlowCtrlStatement(const std::string &sCmd)
This static member function returns whether the passed command is any of the known flow control state...
Definition: flowctrl.cpp:4742
static bool isFlowCtrlStatement(const std::string &sCmd)
This static member function returns whether the passed command is a flow control statement.
Definition: flowctrl.cpp:4726
virtual int evalDebuggerBreakPoint(Parser &_parser, Settings &_option)
Dummy implementation.
Definition: flowctrl.cpp:4818
std::string sLoopPlotCompose
Definition: flowctrl.hpp:117
void checkParsingModeAndExpandDefinitions()
If the loop parsing mode is active, ensure that only inline procedures are used in this case....
Definition: flowctrl.cpp:4511
friend FlowCtrlCommand
Definition: flowctrl.hpp:46
Returnvalue ReturnVal
Definition: flowctrl.hpp:113
int switch_fork(int nth_Cmd=0, int nth_Loop=-1)
This member function realizes the SWITCH-CASE control flow statement. The return value is either an e...
Definition: flowctrl.cpp:1092
varmap_type vVars
Definition: flowctrl.hpp:105
std::map< std::string, std::string > mVarMap
Definition: flowctrl.hpp:118
bool bLoopSupressAnswer
Definition: flowctrl.hpp:49
std::set< std::string > inlineClusters
Definition: flowctrl.hpp:119
virtual int getErrorInformationForDebugger()
Dummy implementation.
Definition: flowctrl.cpp:4830
int evalForkFlowCommands(int __j, int nth_loop)
This member function handles the evaluation of flow control statements from the viewpoint of an if-el...
Definition: flowctrl.cpp:1888
std::string sLoopNames
Definition: flowctrl.hpp:108
std::string sTestClusterName
Definition: flowctrl.hpp:127
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...
Definition: flowctrl.cpp:1948
void prepareLocalVarsAndReplace(std::string &sVars)
This method prepares the local variables including their names and replaces them in the command lines...
Definition: flowctrl.cpp:4615
std::string getCurrentBlock() const
Definition: flowctrl.hpp:175
bool bLockedPauseMode
Definition: flowctrl.hpp:115
PlotData * _pDataRef
Definition: flowctrl.hpp:56
int nReturnType
Definition: flowctrl.hpp:130
bool bPrintedStatus
Definition: flowctrl.hpp:122
virtual int isInline(const std::string &sProc)
Dummy implementation.
Definition: flowctrl.cpp:4804
std::vector< int > nCalcType
Definition: flowctrl.hpp:107
int while_loop(int nth_Cmd=0, int nth_Loop=0)
This member function realizes the WHILE control flow statement. The return value is either an error v...
Definition: flowctrl.cpp:679
Output * _outRef
Definition: flowctrl.hpp:53
int nthRecursion
Definition: flowctrl.hpp:128
bool checkFlowControlArgument(const std::string &sFlowControlArgument, bool isForLoop=false)
This member function checks, whether the passed flow control argument is valid or not.
Definition: flowctrl.cpp:4043
bool bUseLoopParsingMode
Definition: flowctrl.hpp:114
void reset()
This function clears the memory of this FlowCtrl object and sets everything back to its original stat...
Definition: flowctrl.cpp:2534
int range_based_for_loop(int nth_Cmd=0, int nth_Loop=0)
This member function realizes the FOR control flow statement for range based indices....
Definition: flowctrl.cpp:377
virtual std::vector< std::string > expandInlineProcedures(std::string &sLine)
Dummy implementation.
Definition: flowctrl.cpp:4843
int(FlowCtrl::* FlowCtrlFunction)(int, int)
Definition of a generic FlowCtrl entry point.
Definition: flowctrl.hpp:140
virtual ~FlowCtrl()
Destructor. Cleanes the memory, if necessary.
Definition: flowctrl.cpp:107
int nFlowCtrlStatements[FC_COUNT]
Definition: flowctrl.hpp:110
AssertionStats baseline
Definition: flowctrl.hpp:126
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 extractFlagsAndIndexVariables()
Read the flow control statements only and extract the index variables and the flow control flags.
Definition: flowctrl.cpp:4117
int nDebuggerCode
Definition: flowctrl.hpp:125
bool bSilent
Definition: flowctrl.hpp:120
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
value_type * evalHeader(int &nNum, std::string &sHeadExpression, bool bIsForHead, int nth_Cmd, const std::string &sHeadCommand)
This member function abstracts the evaluation of all flow control headers. It will return an array of...
Definition: flowctrl.cpp:1490
CalculationType
Definition: flowctrl.hpp:61
@ CALCTYPE_EXPLICIT
Definition: flowctrl.hpp:73
@ CALCTYPE_RECURSIVEEXPRESSION
Definition: flowctrl.hpp:79
@ CALCTYPE_TOCOMMAND
Definition: flowctrl.hpp:74
@ CALCTYPE_COMMAND
Definition: flowctrl.hpp:63
@ CALCTYPE_BREAKCMD
Definition: flowctrl.hpp:77
@ CALCTYPE_PROCEDURECMDINTERFACE
Definition: flowctrl.hpp:75
@ CALCTYPE_SUPPRESSANSWER
Definition: flowctrl.hpp:80
@ CALCTYPE_PROGRESS
Definition: flowctrl.hpp:67
@ CALCTYPE_PROMPT
Definition: flowctrl.hpp:78
@ CALCTYPE_DEBUGBREAKPOINT
Definition: flowctrl.hpp:72
@ CALCTYPE_CONTINUECMD
Definition: flowctrl.hpp:76
@ CALCTYPE_DEFINITION
Definition: flowctrl.hpp:69
@ CALCTYPE_NONE
Definition: flowctrl.hpp:62
@ CALCTYPE_COMPOSE
Definition: flowctrl.hpp:68
@ CALCTYPE_NUMERICAL
Definition: flowctrl.hpp:64
@ CALCTYPE_RETURNCOMMAND
Definition: flowctrl.hpp:70
@ CALCTYPE_ASSERT
Definition: flowctrl.hpp:81
@ CALCTYPE_THROWCOMMAND
Definition: flowctrl.hpp:71
@ CALCTYPE_STRING
Definition: flowctrl.hpp:65
@ CALCTYPE_DATAACCESS
Definition: flowctrl.hpp:66
int compile(std::string sLine, int nthCmd)
This member function does the hard work and compiles the numerical and std::string results for the cu...
Definition: flowctrl.cpp:2646
int nCurrentCommand
Definition: flowctrl.hpp:112
int try_catch(int nth_Cmd=0, int nth_Loop=-1)
Implements a try-catch block.
Definition: flowctrl.cpp:1240
Settings * _optionRef
Definition: flowctrl.hpp:54
Returnvalue getReturnValue() const
Definition: flowctrl.hpp:182
int for_loop(int nth_Cmd=0, int nth_Loop=0)
This member function realizes the FOR control flow statement. The return value is either an error val...
Definition: flowctrl.cpp:143
void updateTestStats()
Updates the test statistics with the total test statistics.
Definition: flowctrl.cpp:4669
virtual int catchExceptionForTest(std::exception_ptr e_ptr, bool bSupressAnswer_back, int nLine)
Dummy implementation.
Definition: flowctrl.cpp:4858
ProcedureInterfaceRetVal
Definition: flowctrl.hpp:85
@ INTERFACE_VALUE
Definition: flowctrl.hpp:89
@ INTERFACE_NONE
Definition: flowctrl.hpp:88
@ INTERFACE_EMPTY
Definition: flowctrl.hpp:86
@ INTERFACE_ERROR
Definition: flowctrl.hpp:87
bool bEvaluatingFlowControlStatements
Definition: flowctrl.hpp:123
std::vector< FlowCtrlCommand > vCmdArray
Definition: flowctrl.hpp:102
FunctionDefinitionManager * _functionRef
Definition: flowctrl.hpp:55
FlowCtrlStatement
Definition: flowctrl.hpp:93
@ FC_COUNT
Definition: flowctrl.hpp:99
@ FC_SWITCH
Definition: flowctrl.hpp:97
@ FC_WHILE
Definition: flowctrl.hpp:96
virtual ProcedureInterfaceRetVal procedureInterface(std::string &sLine, Parser &_parser, FunctionDefinitionManager &_functions, MemoryManager &_data, Output &_out, PlotData &_pData, Script &_script, Settings &_option, int nth_command)
Dummy implementation.
Definition: flowctrl.cpp:4778
FlowCtrl()
Default constructor.
Definition: flowctrl.cpp:66
This class implements the function definition managing instance.
Definition: define.hpp:74
This class represents the central memory managing instance. It will handle all tables and clusters,...
This class represents a whole cluster. The single items are stored as pointers to the abstract cluste...
Definition: cluster.hpp:325
This class contains all the plot settings usable by the plotting algorithm.
Definition: plotdata.hpp:42
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
Mathematical expressions parser.
Definition: muParser.h:51
Namespace for mathematical applications.
Definition: muParser.cpp:53
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
Definition: muParserDef.h:273
This structure accumulates the statistics for the assertion handler.
Definition: error.hpp:496
bool bFlowCtrlStatement
Definition: flowctrl.hpp:207
size_t nRFStepping
Definition: flowctrl.hpp:210
std::string sFlowCtrlHeader
Definition: flowctrl.hpp:208
FlowCtrl::FlowCtrlFunction fcFn
Definition: flowctrl.hpp:212
std::string sCommand
Definition: flowctrl.hpp:205
FlowCtrlCommand(const std::string &sCmd, int nLine, bool bStatement=false, FlowCtrl::FlowCtrlFunction fn=nullptr)
Definition: flowctrl.hpp:215
Structure as wrapper for the return value of procedures (which may be numerical or string values or a...