Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:53:04

0001 // Copyright 2008 Christophe Henry
0002 // henry UNDERSCORE christophe AT hotmail DOT com
0003 // This is an extended version of the state machine available in the boost::mpl library
0004 // Distributed under the same license as the original.
0005 // Copyright for the original version:
0006 // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
0007 // under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at
0009 // http://www.boost.org/LICENSE_1_0.txt)
0010 
0011 #ifndef BOOST_MSM_FRONT_EUML_STT_GRAMMAR_H
0012 #define BOOST_MSM_FRONT_EUML_STT_GRAMMAR_H
0013 
0014 #include <boost/msm/front/euml/common.hpp>
0015 #include <boost/mpl/vector.hpp>
0016 #include <boost/mpl/eval_if.hpp>
0017 
0018 #include <boost/msm/front/euml/operator.hpp>
0019 #include <boost/msm/front/euml/guard_grammar.hpp>
0020 #include <boost/msm/front/euml/state_grammar.hpp>
0021 
0022 namespace proto = boost::proto;
0023 
0024 namespace boost { namespace msm { namespace front { namespace euml
0025 {
0026 
0027 template <class SOURCE,class EVENT,class TARGET,class ACTION=none,class GUARD=none>
0028 struct TempRow
0029 {
0030     typedef SOURCE  Source;
0031     typedef EVENT   Evt;
0032     typedef TARGET  Target;
0033     typedef ACTION  Action;
0034     typedef GUARD   Guard;
0035 };
0036 
0037 template <class TEMP_ROW>
0038 struct convert_to_row
0039 {
0040     typedef Row<typename TEMP_ROW::Source,typename TEMP_ROW::Evt,typename TEMP_ROW::Target,
0041                 typename TEMP_ROW::Action,typename TEMP_ROW::Guard> type;
0042 };
0043 template <class TEMP_ROW>
0044 struct convert_to_internal_row
0045 {
0046     typedef Internal<typename TEMP_ROW::Evt,
0047                      typename TEMP_ROW::Action,typename TEMP_ROW::Guard> type;
0048 };
0049 // explicit + fork + entry point + exit point grammar
0050 struct BuildEntry
0051     : proto::or_<
0052         proto::when<
0053                     proto::function<proto::terminal<proto::_>,proto::terminal<state_tag>,proto::terminal<state_tag> >,
0054                     get_fct<proto::_child_c<0>,get_state_name<proto::_child_c<1>() >(),get_state_name<proto::_child_c<2>() >() >()
0055         >
0056     >
0057 {};
0058 
0059 // row grammar
0060 struct BuildNextStates
0061    : proto::or_<
0062         proto::when<
0063                     proto::terminal<state_tag>,
0064                     get_state_name<proto::_>()
0065         >,
0066         proto::when<
0067                       BuildEntry,
0068                       BuildEntry
0069         >,
0070         proto::when<
0071                     proto::comma<BuildEntry,BuildEntry >,
0072                     ::boost::mpl::push_back<
0073                         make_vector_one_row<BuildEntry(proto::_left)>(),
0074                         BuildEntry(proto::_right)>()
0075         >,
0076         proto::when <
0077                     proto::comma<BuildNextStates,BuildEntry >,
0078                     ::boost::mpl::push_back<
0079                                 BuildNextStates(proto::_left),
0080                                 BuildEntry(proto::_right) >()                
0081         >
0082    >
0083 {};
0084 
0085 template <class EventGuard,class ActionClass>
0086 struct fusion_event_action_guard 
0087 {
0088     typedef TempRow<none,typename EventGuard::Evt,none,typename ActionClass::Action,typename EventGuard::Guard> type;
0089 };
0090 
0091 template <class SourceGuard,class ActionClass>
0092 struct fusion_source_action_guard 
0093 {
0094     typedef TempRow<typename SourceGuard::Source,none,none,typename ActionClass::Action,typename SourceGuard::Guard> type;
0095 };
0096 
0097 template <class SourceClass,class EventClass>
0098 struct fusion_source_event_action_guard 
0099 {
0100     typedef TempRow<typename SourceClass::Source,typename EventClass::Evt,
0101                     none,typename EventClass::Action,typename EventClass::Guard> type;
0102 };
0103 template <class Left,class Right>
0104 struct fusion_left_right 
0105 {
0106     typedef TempRow<typename Right::Source,typename Right::Evt,typename Left::Target
0107                    ,typename Right::Action,typename Right::Guard> type;
0108 };
0109 
0110 struct BuildEventPlusGuard
0111     : proto::or_<
0112         proto::when<
0113             proto::subscript<proto::terminal<event_tag>, GuardGrammar >,
0114             TempRow<none,proto::_left,none,none, GuardGrammar(proto::_right)>(proto::_right)
0115         >
0116     >
0117  {};
0118 
0119 struct BuildSourceState
0120    : proto::or_<
0121         proto::when<
0122                     proto::terminal<state_tag>,
0123                     get_state_name<proto::_>()
0124         >,
0125         proto::when<
0126                     BuildEntry,
0127                     BuildEntry
0128         >
0129    >
0130 {};
0131 
0132 struct BuildSourcePlusGuard
0133     : proto::when<
0134             proto::subscript<BuildSourceState,GuardGrammar >,
0135             TempRow<BuildSourceState(proto::_left),none,none,none,GuardGrammar(proto::_right)>(proto::_right)
0136         >
0137 {};
0138 
0139 struct BuildEvent
0140     : proto::or_<
0141         // just event without guard/action
0142          proto::when<
0143                 proto::terminal<event_tag>,
0144                 TempRow<none,proto::_,none>() >
0145         // event / action
0146        , proto::when<
0147                 proto::divides<proto::terminal<event_tag>,ActionGrammar >,
0148                 TempRow<none,proto::_left,none,ActionGrammar(proto::_right) >(proto::_right) >
0149         // event [ guard ]
0150        , proto::when<
0151                 proto::subscript<proto::terminal<event_tag>,GuardGrammar >,
0152                 TempRow<none,proto::_left,none,none,GuardGrammar(proto::_right)>(proto::_right) >
0153         // event [ guard ] / action 
0154        , proto::when<
0155                 proto::divides<BuildEventPlusGuard, ActionGrammar>,
0156                 fusion_event_action_guard<BuildEventPlusGuard(proto::_left),
0157                                           TempRow<none,none,none,ActionGrammar(proto::_right)>(proto::_right)
0158                                            >() 
0159                 >
0160         >
0161 {};
0162 struct BuildSource
0163     : proto::or_<
0164         // after == if just state without event or guard/action
0165          proto::when<
0166                 BuildSourceState,
0167                 TempRow<BuildSourceState(proto::_),none,none>() >
0168         // == source / action
0169        , proto::when<
0170                 proto::divides<BuildSourceState,ActionGrammar >,
0171                 TempRow<BuildSourceState(proto::_left),none,none,ActionGrammar(proto::_right) >(proto::_right) >
0172         // == source [ guard ]
0173        , proto::when<
0174                 proto::subscript<BuildSourceState,GuardGrammar >,
0175                 TempRow<BuildSourceState(proto::_left),none,none,none,GuardGrammar(proto::_right)>(proto::_right) >
0176         // == source [ guard ] / action 
0177        , proto::when<
0178                 proto::divides<BuildSourcePlusGuard,
0179                                ActionGrammar >,
0180                 fusion_source_action_guard<BuildSourcePlusGuard(proto::_left),
0181                                            TempRow<none,none,none,ActionGrammar(proto::_right)>(proto::_right)
0182                                            >() 
0183                 >
0184         >
0185 {};
0186 
0187 struct BuildRight
0188     : proto::or_<
0189          proto::when<
0190                 proto::plus<BuildSource,BuildEvent >,
0191                 fusion_source_event_action_guard<BuildSource(proto::_left),BuildEvent(proto::_right)>()
0192          >,
0193          proto::when<
0194                 BuildSource,
0195                 BuildSource
0196          >
0197     >
0198 {};
0199 
0200 struct BuildRow
0201     : proto::or_<
0202         // grammar 1
0203         proto::when<
0204             proto::equal_to<BuildNextStates,BuildRight >,
0205             convert_to_row<
0206                 fusion_left_right<TempRow<none,none,BuildNextStates(proto::_left)>,BuildRight(proto::_right)> >()
0207         >,
0208         // internal events
0209         proto::when<
0210             BuildRight,
0211             convert_to_row<
0212                 fusion_left_right<TempRow<none,none,none>,BuildRight(proto::_)> >()
0213         >,
0214         // grammar 2
0215         proto::when<
0216             proto::equal_to<BuildRight,BuildNextStates>,
0217             convert_to_row<
0218                 fusion_left_right<TempRow<none,none,BuildNextStates(proto::_right)>,BuildRight(proto::_left)> >()
0219         >
0220     >
0221 {};
0222 
0223 // stt grammar
0224 struct BuildStt
0225    : proto::or_<
0226         proto::when<
0227                     proto::comma<BuildStt,BuildStt>,
0228                     boost::mpl::push_back<BuildStt(proto::_left),BuildRow(proto::_right)>()
0229                 >,
0230         proto::when <
0231                     BuildRow,
0232                     make_vector_one_row<BuildRow(proto::_)>()
0233         >
0234    >
0235 {};
0236 
0237 template <class Expr>
0238 typename ::boost::mpl::eval_if<
0239     typename proto::matches<Expr,BuildStt>::type,
0240     boost::result_of<BuildStt(Expr)>,
0241     make_invalid_type>::type
0242 build_stt(Expr const&)
0243 {
0244     return typename boost::result_of<BuildStt(Expr)>::type();
0245 }
0246 
0247 // internal stt grammar
0248 struct BuildInternalRow
0249     :   proto::when<
0250             BuildEvent,
0251             convert_to_internal_row<
0252                 fusion_left_right<TempRow<none,none,none>,BuildEvent(proto::_)> >()
0253         >
0254 {};
0255 struct BuildInternalStt
0256    : proto::or_<
0257         proto::when<
0258                     proto::comma<BuildInternalStt,BuildInternalStt>,
0259                     boost::mpl::push_back<BuildInternalStt(proto::_left),BuildInternalRow(proto::_right)>()
0260                 >,
0261         proto::when <
0262                     BuildInternalRow,
0263                     make_vector_one_row<BuildInternalRow(proto::_)>()
0264         >
0265    >
0266 {};
0267 
0268 template <class Expr>
0269 typename ::boost::mpl::eval_if<
0270     typename proto::matches<Expr,BuildInternalStt>::type,
0271     boost::result_of<BuildInternalStt(Expr)>,
0272     make_invalid_type>::type
0273 build_internal_stt(Expr const&)
0274 {
0275     return typename boost::result_of<BuildInternalStt(Expr)>::type();
0276 }
0277 
0278 
0279 }}}}
0280 #endif //BOOST_MSM_FRONT_EUML_STT_GRAMMAR_H