StateGraphParser.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Apr 22 20:40:59 CEST 2004  StateGraphParser.hpp
00003 
00004                         StateGraphParser.hpp -  description
00005                            -------------------
00006     begin                : Thu April 22 2004
00007     copyright            : (C) 2004 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
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       // Our task we are loaded in :
00083       TaskContext* context;
00084       // The TaskObject of the current StateMachine
00085       StateMachineTask* curobject ;
00086       OperationInterface* peer;
00087       our_pos_iter_t& mpositer;
00088       our_pos_iter_t saveStartPos;
00089       // offset relative to StateMachine text.
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     // tries to parse, returns the instantiated root machines.  On all
00235     // returned machines setName() will have been called with the
00236     // correct name.
00237     // will throw an file_parse_exception on error
00238     std::vector<ParsedStateMachinePtr> parse( iter_t& begin, iter_t end );
00239   };
00240 }}
00241 
00242 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3