StateGraphParser.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef EXECUTION_STATE_PARSER_HPP
00039 #define EXECUTION_STATE_PARSER_HPP
00040
00041 #include "parser-types.hpp"
00042
00043 #include <map>
00044 #include <string>
00045 #include <boost/function.hpp>
00046 #include <boost/shared_ptr.hpp>
00047 #include "../DataSource.hpp"
00048
00049 namespace RTT
00050 {
00051 class StateDescription;
00052 class TaskContext;
00053 class FunctionGraph;
00054 class ParsedStateMachine;
00055 class ProgramInterface;
00056 class StateMachineTask;
00057 class OperationInterface;
00058 }
00059 namespace RTT { namespace detail
00060 {
00061 class StateMachineBuilder;
00062 class ProgramGraphParser;
00063 class ConditionParser;
00064 class ValueChangeParser;
00065 class ExpressionParser;
00066 class CommonParser;
00067 class PeerParser;
00068 class ArgumentsParser;
00069
00080 class StateGraphParser
00081 {
00082
00083 TaskContext* context;
00084
00085 StateMachineTask* curobject ;
00086 OperationInterface* peer;
00087 our_pos_iter_t& mpositer;
00088 our_pos_iter_t saveStartPos;
00089
00090 int ln_offset;
00091
00092 typedef boost::shared_ptr<ParsedStateMachine> ParsedStateMachinePtr;
00093 typedef std::map<std::string, ParsedStateMachinePtr> machinenamemap_t;
00094 typedef std::map<std::string, AttributeBase*> machineparams_t;
00095 typedef std::map<std::string, DataSourceBase::shared_ptr> machineparamvalues_t;
00096 typedef std::map<std::string, StateDescription*> machinestatesmap_t;
00097 typedef std::map<std::string, StateMachineBuilder*> machinebuilders_t;
00098
00099 machinenamemap_t rootmachines;
00100 machinebuilders_t machinebuilders;
00101 ParsedStateMachinePtr curtemplate;
00102 std::vector<CommandInterface*> paraminitcommands;
00103 std::vector<CommandInterface*> varinitcommands;
00104 ParsedStateMachinePtr curinstantiatedmachine;
00105 StateMachineBuilder* curmachinebuilder;
00106 std::string curinstmachinename;
00107 machineparamvalues_t curinstmachineparams;
00108 std::string curmachineinstargumentname;
00109 std::string curmachinename;
00110 bool curinitialstateflag;
00111 bool curfinalstateflag;
00112 StateDescription* curstate;
00113 StateDescription* curnonprecstate;
00114 ProgramGraphParser* progParser;
00115 boost::shared_ptr<ProgramInterface> transProgram;
00116 StateDescription* elsestate;
00117 boost::shared_ptr<ProgramInterface> elseProgram;
00118 ConditionInterface* curcondition;
00119 #if 0
00120 std::string curscvcmachinename;
00121 std::string curscvcparamname;
00122 #endif
00123
00127 int rank;
00128 bool isroot;
00129 unsigned int selectln;
00130
00131 std::vector<DataSourceBase::shared_ptr> evargs;
00132 std::string evname;
00133
00134 rule_t production;
00135 rule_t newline;
00136 rule_t rootmachineinstantiation;
00137 rule_t statemachine;
00138 rule_t machineinstantiation;
00139 rule_t statemachinecontent;
00140 rule_t varline;
00141 rule_t state;
00142 rule_t vardec;
00143 rule_t subMachinedecl;
00144 rule_t statecontent;
00145 rule_t statecontentline;
00146 rule_t entry;
00147 rule_t preconditions;
00148 rule_t precondition;
00149 rule_t run;
00150 rule_t transitions;
00151 rule_t transition;
00152 rule_t argslist;
00153 rule_t handle;
00154 rule_t exit;
00155 rule_t programBody;
00156 rule_t transline;
00157 rule_t eventline;
00158 rule_t program;
00159 rule_t progselect;
00160 rule_t ifbranch;
00161 rule_t elsebranch;
00162 rule_t selector;
00163 rule_t machineinstarguments;
00164 rule_t machineinstargument;
00165 rule_t machinememvar;
00166 rule_t machinevariable;
00167 rule_t machineparam;
00168 rule_t machineconstant;
00169 rule_t machinealias;
00170 rule_t subMachinevarchange;
00171
00172 CommonParser* commonparser;
00173 ConditionParser* conditionparser;
00174 ValueChangeParser* valuechangeparser;
00175 ExpressionParser* expressionparser;
00176 ArgumentsParser* argsparser;
00177 PeerParser* peerparser;
00178
00179 void clear();
00180
00181 void seeninitialstate();
00182 void seenfinalstate();
00183 void statedef( iter_t s, iter_t f);
00184 void seenstateend();
00185
00186 void inprogram( const std::string& name );
00187 void seenentry();
00188 void seenexit();
00189 void seenhandle();
00190 void seenrun();
00191 boost::shared_ptr<ProgramInterface> finishProgram();
00192
00193 void seencondition();
00194 void seenendcondition();
00195 void seentransprog();
00196 void seenelseprog();
00197 void seenelse();
00198 void noselect();
00199 void seenselect( iter_t s, iter_t f);
00200 void doselect(const std::string& name);
00201 void seenprecondition();
00202 void seeneventname(iter_t s, iter_t f);
00203 void seeneventtrans();
00204 void seeneventargs();
00205
00206 void seenstatemachinename( iter_t begin, iter_t end );
00207 void storeOffset();
00208 void saveText( iter_t begin, iter_t end );
00209 void startrootmachineinstantiation();
00210 void seenrootmachineinstantiation();
00211 void seenstatemachineend();
00212 void seensubMachineinstantiation();
00213
00214 void inpreconditions();
00215 void seenpreconditions();
00216
00217 void seenmachinetypename( iter_t begin, iter_t end );
00218 void seeninstmachinename( iter_t begin, iter_t end );
00219 void seenmachineinstantiation();
00220 void seenmachineinstargumentname( iter_t begin, iter_t end );
00221 void seenmachineinstargumentvalue();
00222
00223 void seenmachinevariable();
00224 void seenmachineparam();
00225
00226 #if 0
00227 void seenscvcsubMachinename( iter_t begin, iter_t end );
00228 void seenscvcparamname( iter_t begin, iter_t end );
00229 #endif
00230 public:
00231 StateGraphParser( iter_t& positer, TaskContext* tc );
00232 ~StateGraphParser();
00233
00234
00235
00236
00237
00238 std::vector<ParsedStateMachinePtr> parse( iter_t& begin, iter_t end );
00239 };
00240 }}
00241
00242 #endif