Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:22:45

0001 /*=============================================================================
0002     Copyright (c) 2005-2010 Joel de Guzman
0003     Copyright (c) 2010 Eric Niebler
0004     Copyright (c) 2010 Thomas Heller
0005 
0006     Distributed under the Boost Software License, Version 1.0. (See accompanying 
0007     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 ==============================================================================*/
0009 #ifndef BOOST_PHOENIX_CORE_META_GRAMMAR_HPP
0010 #define BOOST_PHOENIX_CORE_META_GRAMMAR_HPP
0011 
0012 #include <boost/phoenix/core/limits.hpp>
0013 #include <boost/mpl/deref.hpp>
0014 #include <boost/phoenix/core/environment.hpp>
0015 #include <boost/proto/matches.hpp>
0016 #include <boost/proto/transform/call.hpp>
0017 #include <boost/proto/transform/default.hpp>
0018 
0019 namespace boost { namespace phoenix
0020 {
0021     /////////////////////////////////////////////////////////////////////////////
0022     // The grammar defining valid phoenix expressions
0023     struct meta_grammar
0024         : proto::switch_<meta_grammar>
0025     {
0026         template <typename Tag, typename Dummy = void>
0027         struct case_
0028             : proto::not_<proto::_>
0029         {};
0030     };
0031 
0032     struct evaluator
0033     {
0034         BOOST_PROTO_TRANSFORM(evaluator)
0035 
0036         template <typename Expr, typename State, typename Data>
0037         struct impl
0038             : proto::transform_impl<Expr, State, Data>
0039         {
0040             typedef meta_grammar::impl<Expr, State, Data> what;
0041 
0042             typedef typename what::result_type result_type;
0043 
0044             result_type operator()(
0045                 typename impl::expr_param e
0046               , typename impl::state_param s
0047               , typename impl::data_param d
0048             ) const
0049             {
0050                 return what()(e, s, d);
0051             }
0052         };
0053 
0054         template <typename Expr, typename State>
0055         struct impl<Expr, State, proto::empty_env>
0056             : proto::transform_impl<Expr, State, proto::empty_env>
0057         {
0058             typedef
0059                 meta_grammar::impl<
0060                     Expr
0061                   , typename result_of::env<State>::type
0062                   , typename result_of::actions<State>::type
0063                 >
0064                 what;
0065 
0066             typedef typename what::result_type result_type;
0067 
0068             result_type operator()(
0069                 typename impl::expr_param e
0070               , typename impl::state_param s
0071               , typename impl::data_param
0072             ) const
0073             {
0074                 return what()(e, phoenix::env(s), actions(s));
0075             }
0076         };
0077         
0078         template <typename Expr, typename State>
0079         struct impl<Expr, State, unused>
0080             : proto::transform_impl<Expr, State, unused>
0081         {
0082             typedef
0083                 meta_grammar::impl<
0084                     Expr
0085                   , typename result_of::env<State>::type
0086                   , typename result_of::actions<State>::type
0087                 >
0088                 what;
0089 
0090             typedef typename what::result_type result_type;
0091 
0092             result_type operator()(
0093                 typename impl::expr_param e
0094               , typename impl::state_param s
0095               , typename impl::data_param
0096             ) const
0097             {
0098                 return what()(e, phoenix::env(s), actions(s));
0099             }
0100         };
0101     };
0102 
0103     /////////////////////////////////////////////////////////////////////////////
0104     // Set of default actions. Extend this whenever you add a new phoenix
0105     // construct
0106     struct default_actions
0107     {
0108         template <typename Rule, typename Dummy = void>
0109         struct when
0110             : proto::_default<meta_grammar>
0111         {};
0112     };
0113 
0114     template <typename Rule, typename Dummy = void>
0115     struct enable_rule
0116         : proto::when<Rule, proto::external_transform>
0117     {};
0118 
0119     namespace result_of
0120     {
0121         template <typename Expr, typename Context>
0122         struct eval
0123             : boost::result_of< ::boost::phoenix::evaluator(Expr, Context)>
0124         {};
0125     }
0126 
0127     /////////////////////////////////////////////////////////////////////////////
0128     // A function we can call to evaluate our expression
0129     template <typename Expr, typename Context>
0130     inline
0131     typename meta_grammar::template impl<
0132         Expr const&
0133       , typename result_of::env<Context const&>::type
0134       , typename result_of::actions<Context const&>::type
0135     >::result_type
0136     eval(Expr const& expr, Context const & ctx)
0137     {
0138         static evaluator const e = {};
0139         return e(expr, ctx);
0140     }
0141     
0142     template <typename Expr, typename Context>
0143     inline
0144     typename meta_grammar::template impl<
0145         Expr &
0146       , typename result_of::env<Context const&>::type
0147       , typename result_of::actions<Context const&>::type
0148     >::result_type
0149     eval(Expr & expr, Context const & ctx)
0150     {
0151         static evaluator const e = {};
0152         return e(expr, ctx);
0153     }
0154 }}
0155 
0156 #endif