File indexing completed on 2025-01-18 09:52:22
0001
0002
0003
0004
0005
0006
0007
0008
0009 #if !defined(BOOST_SPIRIT_CONTEXT_OCTOBER_31_2008_0654PM)
0010 #define BOOST_SPIRIT_CONTEXT_OCTOBER_31_2008_0654PM
0011
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015
0016 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
0017 #include <boost/spirit/home/support/nonterminal/expand_arg.hpp>
0018 #include <boost/spirit/home/support/assert_msg.hpp>
0019 #include <boost/spirit/home/support/argument.hpp>
0020 #include <boost/spirit/home/support/limits.hpp>
0021 #include <boost/fusion/include/at.hpp>
0022 #include <boost/fusion/include/size.hpp>
0023 #include <boost/fusion/include/as_list.hpp>
0024 #include <boost/fusion/include/transform.hpp>
0025 #include <boost/mpl/size.hpp>
0026 #include <boost/mpl/at.hpp>
0027 #include <boost/phoenix/core/actor.hpp>
0028 #include <boost/phoenix/core/terminal.hpp>
0029 #include <boost/phoenix/core/v2_eval.hpp>
0030 #include <boost/proto/proto_fwd.hpp> // for transform placeholders
0031
0032
0033 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0034
0035 #define SPIRIT_DECLARE_ATTRIBUTE(z, n, data) \
0036 typedef phoenix::actor<attribute<n> > \
0037 BOOST_PP_CAT(BOOST_PP_CAT(_r, n), _type); \
0038 phoenix::actor<attribute<n> > const \
0039 BOOST_PP_CAT(_r, n) = BOOST_PP_CAT(BOOST_PP_CAT(_r, n), _type)();
0040
0041 #define SPIRIT_USING_ATTRIBUTE(z, n, data) \
0042 using spirit::BOOST_PP_CAT(BOOST_PP_CAT(_r, n), _type); \
0043 using spirit::BOOST_PP_CAT(_r, n); \
0044
0045
0046 #else
0047
0048 #define SPIRIT_DECLARE_ATTRIBUTE(z, n, data) \
0049 typedef phoenix::actor<attribute<n> > \
0050 BOOST_PP_CAT(BOOST_PP_CAT(_r, n), _type); \
0051
0052 #define SPIRIT_USING_ATTRIBUTE(z, n, data) \
0053 using spirit::BOOST_PP_CAT(BOOST_PP_CAT(_r, n), _type); \
0054
0055
0056 #endif
0057
0058 namespace boost { namespace spirit
0059 {
0060 template <int>
0061 struct attribute;
0062
0063 template <int>
0064 struct local_variable;
0065 }}
0066
0067 BOOST_PHOENIX_DEFINE_CUSTOM_TERMINAL(
0068 template <int N>
0069 , boost::spirit::attribute<N>
0070 , mpl::false_
0071 , v2_eval(
0072 proto::make<
0073 boost::spirit::attribute<N>()
0074 >
0075 , proto::call<
0076 functional::env(proto::_state)
0077 >
0078 )
0079 )
0080
0081 BOOST_PHOENIX_DEFINE_CUSTOM_TERMINAL(
0082 template <int N>
0083 , boost::spirit::local_variable<N>
0084 , mpl::false_
0085 , v2_eval(
0086 proto::make<
0087 boost::spirit::local_variable<N>()
0088 >
0089 , proto::call<
0090 functional::env(proto::_state)
0091 >
0092 )
0093 )
0094
0095 namespace boost { namespace spirit
0096 {
0097 template <typename Attributes, typename Locals>
0098 struct context
0099 {
0100 typedef Attributes attributes_type;
0101 typedef Locals locals_type;
0102
0103 context(typename Attributes::car_type attribute)
0104 : attributes(attribute, fusion::nil_()), locals() {}
0105
0106 template <typename Args, typename Context>
0107 context(
0108 typename Attributes::car_type attribute
0109 , Args const& args
0110 , Context& caller_context
0111 ) : attributes(
0112 attribute
0113 , fusion::as_list(
0114 fusion::transform(
0115 args
0116 , detail::expand_arg<Context>(caller_context)
0117 )
0118 )
0119 )
0120 , locals() {}
0121
0122 context(Attributes const& attributes_)
0123 : attributes(attributes_), locals() {}
0124
0125 Attributes attributes;
0126 Locals locals;
0127 };
0128
0129 template <typename Context>
0130 struct attributes_of
0131 {
0132 typedef typename Context::attributes_type type;
0133 };
0134
0135 template <typename Context>
0136 struct attributes_of<Context const>
0137 {
0138 typedef typename Context::attributes_type const type;
0139 };
0140
0141 template <typename Context>
0142 struct attributes_of<Context &>
0143 : attributes_of<Context>
0144 {};
0145
0146 template <typename Context>
0147 struct locals_of
0148 {
0149 typedef typename Context::locals_type type;
0150 };
0151
0152 template <typename Context>
0153 struct locals_of<Context const>
0154 {
0155 typedef typename Context::locals_type const type;
0156 };
0157
0158 template <typename Context>
0159 struct locals_of<Context &>
0160 {
0161 typedef typename Context::locals_type type;
0162 };
0163
0164 template <int N>
0165 struct attribute
0166 {
0167 typedef mpl::true_ no_nullary;
0168
0169 template <typename Env>
0170 struct result
0171 {
0172 typedef typename
0173 attributes_of<typename
0174 mpl::at_c<typename Env::args_type, 1>::type
0175 >::type
0176 attributes_type;
0177
0178 typedef typename
0179 fusion::result_of::size<attributes_type>::type
0180 attributes_size;
0181
0182
0183 BOOST_SPIRIT_ASSERT_MSG(
0184 (N < attributes_size::value),
0185 index_is_out_of_bounds, ());
0186
0187 typedef typename
0188 fusion::result_of::at_c<attributes_type, N>::type
0189 type;
0190 };
0191
0192 template <typename Env>
0193 typename result<Env>::type
0194 eval(Env const& env) const
0195 {
0196 return fusion::at_c<N>((fusion::at_c<1>(env.args())).attributes);
0197 }
0198 };
0199
0200 template <int N>
0201 struct local_variable
0202 {
0203 typedef mpl::true_ no_nullary;
0204
0205 template <typename Env>
0206 struct result
0207 {
0208 typedef typename
0209 locals_of<typename
0210 mpl::at_c<typename Env::args_type, 1>::type
0211 >::type
0212 locals_type;
0213
0214 typedef typename
0215 fusion::result_of::size<locals_type>::type
0216 locals_size;
0217
0218
0219 BOOST_SPIRIT_ASSERT_MSG(
0220 (N < locals_size::value),
0221 index_is_out_of_bounds, ());
0222
0223 typedef typename
0224 fusion::result_of::at_c<locals_type, N>::type
0225 type;
0226 };
0227
0228 template <typename Env>
0229 typename result<Env>::type
0230 eval(Env const& env) const
0231 {
0232 return get_arg<N>((fusion::at_c<1>(env.args())).locals);
0233 }
0234 };
0235
0236 typedef phoenix::actor<attribute<0> > _val_type;
0237 typedef phoenix::actor<attribute<0> > _r0_type;
0238 typedef phoenix::actor<attribute<1> > _r1_type;
0239 typedef phoenix::actor<attribute<2> > _r2_type;
0240
0241 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0242
0243
0244 _val_type const _val = _val_type();
0245 _r0_type const _r0 = _r0_type();
0246 _r1_type const _r1 = _r1_type();
0247 _r2_type const _r2 = _r2_type();
0248 #endif
0249
0250
0251 BOOST_PP_REPEAT_FROM_TO(
0252 3, SPIRIT_ATTRIBUTES_LIMIT, SPIRIT_DECLARE_ATTRIBUTE, _)
0253
0254 typedef phoenix::actor<local_variable<0> > _a_type;
0255 typedef phoenix::actor<local_variable<1> > _b_type;
0256 typedef phoenix::actor<local_variable<2> > _c_type;
0257 typedef phoenix::actor<local_variable<3> > _d_type;
0258 typedef phoenix::actor<local_variable<4> > _e_type;
0259 typedef phoenix::actor<local_variable<5> > _f_type;
0260 typedef phoenix::actor<local_variable<6> > _g_type;
0261 typedef phoenix::actor<local_variable<7> > _h_type;
0262 typedef phoenix::actor<local_variable<8> > _i_type;
0263 typedef phoenix::actor<local_variable<9> > _j_type;
0264
0265 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0266
0267 _a_type const _a = _a_type();
0268 _b_type const _b = _b_type();
0269 _c_type const _c = _c_type();
0270 _d_type const _d = _d_type();
0271 _e_type const _e = _e_type();
0272 _f_type const _f = _f_type();
0273 _g_type const _g = _g_type();
0274 _h_type const _h = _h_type();
0275 _i_type const _i = _i_type();
0276 _j_type const _j = _j_type();
0277 #endif
0278
0279
0280
0281 namespace labels
0282 {
0283 BOOST_PP_REPEAT(SPIRIT_ARGUMENTS_LIMIT, SPIRIT_USING_ARGUMENT, _)
0284 BOOST_PP_REPEAT(SPIRIT_ATTRIBUTES_LIMIT, SPIRIT_USING_ATTRIBUTE, _)
0285
0286 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0287 using spirit::_val;
0288 using spirit::_a;
0289 using spirit::_b;
0290 using spirit::_c;
0291 using spirit::_d;
0292 using spirit::_e;
0293 using spirit::_f;
0294 using spirit::_g;
0295 using spirit::_h;
0296 using spirit::_i;
0297 using spirit::_j;
0298 #endif
0299 }
0300 }}
0301
0302 #endif