ProgramGraphParser.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 19 14:11:26 CET 2004  ProgramGraphParser.hpp
00003 
00004                         ProgramGraphParser.hpp -  description
00005                            -------------------
00006     begin                : Mon January 19 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_PROGRAM_PARSER_HPP
00039 #define EXECUTION_PROGRAM_PARSER_HPP
00040 
00041 #include "parser-types.hpp"
00042 
00043 #include "CommonParser.hpp"
00044 #include "PeerParser.hpp"
00045 #include "ConditionParser.hpp"
00046 #include "CommandParser.hpp"
00047 #include "ExpressionParser.hpp"
00048 #include "../TaskContext.hpp"
00049 #include "../FunctionGraphBuilder.hpp"
00050 #include "ValueChangeParser.hpp"
00051 
00052 #include <map>
00053 #include <vector>
00054 #include <string>
00055 
00056 
00057 #include "ProgramTask.hpp"
00058 //namespace RTT {
00059 //    class ProgramTask;
00060 //}
00061 
00062 namespace RTT { namespace detail
00063 {
00073   class ProgramGraphParser
00074   {
00075       typedef FunctionGraphBuilder::CommandNode CommandNode;
00076       typedef FunctionGraphBuilder::ConditionEdge ConditionEdge;
00077       typedef FunctionGraphBuilder::Graph  Graph;
00078 
00083       TaskContext* rootc;
00084 
00088       OperationInterface* context;
00089 
00093       TaskContext* fcontext;
00094 
00098       TaskContext* peer;
00099 
00100       our_pos_iter_t& mpositer;
00101 
00102       // helper variable to detect if we are in 'try' or 'do'
00103       // which influences the 'and' behaviour
00104       bool try_cmd;
00105 
00106       // The current function we are parsing.
00107       FunctionGraphPtr mfunc;
00108 
00109       // The function we will call next
00110       FunctionGraphPtr mcallfunc;
00111 
00112       // A map of all functions
00113       typedef std::map<std::string, FunctionGraphPtr> funcmap;
00114       funcmap mfuncs;
00115 
00116       // the label that the user wants to give to the current
00117       // statement.  If this is empty, then no label is necessary..
00118       std::string mcurlabel;
00119 
00120       // The implicit termination condition we just got for the
00121       // current command from the CommandParser..
00122       ConditionInterface* implcond;
00123       std::vector<ConditionInterface*> implcond_v;
00124       std::vector<DataSourceBase::shared_ptr> callfnargs;
00125 
00126       // last seen condition
00127       ConditionInterface* mcondition;
00128       // try-block condition
00129       ConditionInterface* try_cond;
00130 
00131       void seencondition();
00132 
00133       void seencallfunclabel( iter_t begin, iter_t end );
00134 
00135       void seencontinue( );
00136 
00137       void skip_eol();
00138       void noskip_eol();
00139       void startofnewstatement( const std::string& type);
00140       void seencommandcall();
00141       void seenandcall();
00142       void seencommands();
00143       void seendostatement();
00144       void seentrystatement();
00145       void startcatchpart();
00146       void seencatchpart();
00147 
00148       void seenvaluechange();
00149 
00150       void functiondef( iter_t begin, iter_t end );
00151       void exportdef(  );
00152       void seenfunctionarg();
00153       void seenfunctionend();
00154 
00155       void seenfuncidentifier( iter_t begin, iter_t end);
00156       void seencallfuncstatement();
00157       void seencallfuncargs();
00158 
00159       void seenreturnstatement();
00160       void seenreturnlabel();
00161 
00162       void seenifstatement();
00163       void endifblock();
00164       void endifstatement();
00165 
00166       void seenwhilestatement();
00167       void endwhilestatement();
00168 
00169       void seenbreakstatement();
00170 
00171       void seenforstatement();
00172       void seenforinit();
00173       void seenforincr();
00174       void endforstatement();
00175 
00176       void startofprogram();
00177       void programdef( iter_t begin, iter_t end );
00178       void seenprogramend();
00179       void programtext(iter_t, iter_t);
00180 
00181       void setStack(OperationInterface* st);
00182       void setup();
00183       void setup2();
00184       void cleanup();
00185 
00186       rule_t newline, terminationclause, jumpdestination, terminationpart, andpart,
00187           dostatement, trystatement, statement, line, content, program, valuechange_parsers,
00188           production, valuechange, returnstatement, function, functions, arguments, funcstatement,
00189           continuepart, returnpart, callpart, ifstatement, ifblock, whilestatement, breakstatement,
00190           openbrace, closebrace, opencurly, closecurly, forstatement, semicolon,
00191           condition, catchpart, funcargs, functionarg, emitstatement ;
00192 
00193       CommonParser& commonparser;
00194       ConditionParser conditionparser;
00195       CommandParser commandparser;
00196       ValueChangeParser valuechangeparser;
00197       ExpressionParser expressionparser;
00198       ArgumentsParser* argsparser;
00199       PeerParser peerparser;
00200 
00201       boost::shared_ptr<FunctionGraphBuilder> program_builder;
00202       std::vector< FunctionGraphPtr > program_list;
00203 
00204       CommandInterface* for_init_command;
00205       CommandInterface* for_incr_command;
00206       std::string program_text;
00207       bool exportf;
00208       int ln_offset;
00209   public:
00210       ProgramGraphParser( iter_t& positer, TaskContext*, CommonParser&);
00211 
00216       std::vector<ProgramInterfacePtr> parse( iter_t& begin, iter_t end );
00217 
00218       std::vector<ProgramInterfacePtr> parseFunction( iter_t& begin, iter_t end );
00219 
00220       void initBodyParser(const std::string& name, OperationInterface* stck, int offset);
00221       rule_t& bodyParser();
00222       ProgramInterfacePtr bodyParserResult();
00223 
00224   };
00225 }}
00226 
00227 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3