ProcedureNwas.hpp

Go to the documentation of this file.
00001 #ifndef PROCEDURE_NWAS_HPP
00002 #define PROCEDURE_NWAS_HPP
00003 
00004 #include "Nwa.hpp"
00005 
00006 #include <map>
00007 #include <string>
00008 
00009 #include <boost/function.hpp>
00010 
00011 namespace opennwa {
00012     ///
00013     /// Maps name of procedure to the procedure NWA
00014     typedef std::map<std::string, NwaRefPtr> ProcedureMap;
00015 
00016     
00017     struct CallReturnTransitionInserter {
00018       const Symbol call_symbol;
00019       const Symbol return_symbol;
00020 
00021       CallReturnTransitionInserter(Symbol _call_symbol,
00022                                    Symbol _return_symbol)
00023         : call_symbol(_call_symbol)
00024         , return_symbol(_return_symbol)
00025       {}
00026 
00027       void operator() (Nwa & nwa, State source, State target) {
00028         nwa.addCallTrans(source, call_symbol, target);
00029       }
00030 
00031       void operator() (Nwa & nwa, State source, State pred, State target) {
00032         nwa.addReturnTrans(source, pred, return_symbol, target);
00033       }
00034     };
00035     
00036 
00037     struct EpsilonTransitionInserter {
00038       void operator() (Nwa & nwa, State source, State target) {
00039         nwa.addInternalTrans(source, EPSILON, target);
00040       }
00041 
00042       void operator() (Nwa & nwa, State source, State pred, State target) {
00043         (void) pred;
00044         nwa.addInternalTrans(source, EPSILON, target);
00045       }
00046     };
00047 
00048     /// Assembles all NWAs in 'procedures' into one large
00049     /// NWA. Replaces any transition labeled with a symbol
00050     /// '__call__<procname>' with a call transition from the source
00051     /// state to the initial state of the NWA with procedure name
00052     /// 'procname' and a return transition from the final state of the
00053     /// NWA with name 'procname' to the original transition's target
00054     /// state (with the original transition's source state as a
00055     /// predecessor).
00056     ///
00057     /// The initial state of the NWA named 'main' is the full NWA's
00058     /// start state, and the accepting state of 'main' is the full
00059     /// NWA's accepting state.
00060     NwaRefPtr
00061     assemble_nwa(ProcedureMap const & procedures,
00062                  boost::function<void (Nwa &, State, State)> call_inserter,
00063                  boost::function<void (Nwa &, State, State, State)> return_inserter);
00064 
00065 
00066 }
00067 
00068 
00069 // Yo, Emacs!
00070 // Local Variables:
00071 //   c-file-style: "ellemtel"
00072 //   c-basic-offset: 2
00073 // End:
00074 
00075 #endif