Chris@16: /*============================================================================== Chris@16: Copyright (c) 2005-2007 Dan Marsden Chris@16: Copyright (c) 2005-2010 Joel de Guzman Chris@16: Copyright (c) 2010 Thomas Heller Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: ==============================================================================*/ Chris@16: Chris@16: #ifndef BOOST_PHOENIX_STATEMENT_TRY_CATCH_HPP Chris@16: #define BOOST_PHOENIX_STATEMENT_TRY_CATCH_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef _MSC_VER Chris@16: #pragma warning(push) Chris@16: #pragma warning(disable: 4355) // 'this' : used in base member initializer list Chris@16: #endif Chris@16: Chris@16: namespace boost { namespace phoenix Chris@16: { Chris@16: template Chris@16: struct try_catch_actor; Chris@16: Chris@16: template Chris@16: struct catch_exception Chris@16: { Chris@16: typedef Exception type; Chris@16: }; Chris@16: Chris@16: namespace tag Chris@16: { Chris@16: struct try_catch {}; Chris@16: struct catch_ {}; Chris@16: struct catch_all {}; Chris@16: } Chris@16: Chris@16: namespace expression Chris@16: { Chris@16: template < Chris@16: typename Try Chris@16: , BOOST_PHOENIX_typename_A_void(BOOST_PHOENIX_CATCH_LIMIT) Chris@16: , typename Dummy = void Chris@16: > Chris@16: struct try_catch; Chris@16: Chris@16: // bring in the expression definitions Chris@16: #include Chris@16: Chris@16: template Chris@16: struct catch_ Chris@16: : proto::binary_expr Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct catch_all Chris@16: : proto::unary_expr Chris@16: {}; Chris@16: } Chris@16: Chris@16: namespace rule Chris@16: { Chris@16: struct catch_ Chris@16: : expression::catch_< Chris@16: proto::terminal > Chris@16: , meta_grammar Chris@16: > Chris@16: {}; Chris@16: Chris@16: struct catch_all Chris@16: : expression::catch_all< Chris@16: meta_grammar Chris@16: > Chris@16: {}; Chris@16: Chris@16: struct try_catch Chris@16: : proto::or_< Chris@16: expression::try_catch< Chris@16: meta_grammar Chris@16: , proto::vararg Chris@16: > Chris@16: , expression::try_catch< Chris@16: meta_grammar Chris@16: , rule::catch_all Chris@16: > Chris@16: , expression::try_catch< Chris@16: meta_grammar Chris@16: , proto::vararg Chris@16: , rule::catch_all Chris@16: > Chris@16: > Chris@16: {}; Chris@16: } Chris@16: Chris@16: template Chris@16: struct meta_grammar::case_ Chris@16: : enable_rule Chris@16: {}; Chris@16: Chris@16: struct try_catch_eval Chris@16: { Chris@16: typedef void result_type; Chris@16: Chris@16: template Chris@16: void operator()(Try const &, Context const &) const Chris@16: {} Chris@16: Chris@16: // bring in the operator overloads Chris@16: #include Chris@16: }; Chris@16: Chris@16: template Chris@16: struct default_actions::when Chris@16: : call Chris@16: {}; Chris@16: Chris@16: namespace detail Chris@16: { Chris@16: struct try_catch_is_nullary Chris@16: : proto::or_< Chris@16: proto::when< Chris@16: phoenix::rule::catch_all Chris@16: , proto::call< Chris@16: evaluator( Chris@16: proto::_child_c<0> Chris@16: , proto::_data Chris@16: , proto::make Chris@16: ) Chris@16: > Chris@16: > Chris@16: , proto::when< Chris@16: phoenix::rule::catch_ Chris@16: , proto::call< Chris@16: evaluator( Chris@16: proto::_child_c<1> Chris@16: , proto::_data Chris@16: , proto::make Chris@16: ) Chris@16: > Chris@16: > Chris@16: , proto::when< Chris@16: phoenix::rule::try_catch Chris@16: , proto::make< Chris@16: mpl::and_< Chris@16: proto::call< Chris@16: evaluator( Chris@16: proto::_child_c<0> Chris@16: , proto::_data Chris@16: , proto::make Chris@16: ) Chris@16: > Chris@16: , proto::fold< Chris@16: proto::call< Chris@16: proto::functional::pop_front(proto::_) Chris@16: > Chris@16: , proto::make Chris@16: , proto::make< Chris@16: mpl::and_< Chris@16: proto::_state Chris@16: , proto::call< Chris@16: try_catch_is_nullary( Chris@16: proto::_ Chris@16: , proto::make Chris@16: , proto::_data Chris@16: ) Chris@16: > Chris@16: >() Chris@16: > Chris@16: > Chris@16: >() Chris@16: > Chris@16: > Chris@16: > Chris@16: {}; Chris@16: Chris@16: template < Chris@16: typename TryCatch Chris@16: , typename Exception Chris@16: , typename Expr Chris@16: , long Arity = proto::arity_of::value Chris@16: > Chris@16: struct catch_push_back; Chris@16: Chris@16: template Chris@16: struct catch_push_back Chris@16: { Chris@16: typedef Chris@16: typename proto::result_of::make_expr< Chris@16: phoenix::tag::catch_ Chris@16: , proto::basic_default_domain Chris@16: , catch_exception Chris@16: , Expr Chris@16: >::type Chris@16: catch_expr; Chris@16: Chris@16: typedef Chris@16: phoenix::expression::try_catch< Chris@16: TryCatch Chris@16: , catch_expr Chris@16: > Chris@16: gen_type; Chris@16: typedef typename gen_type::type type; Chris@16: Chris@16: static type make(TryCatch const & try_catch, Expr const & catch_) Chris@16: { Chris@16: return Chris@16: gen_type::make( Chris@16: try_catch Chris@16: , proto::make_expr< Chris@16: phoenix::tag::catch_ Chris@16: , proto::basic_default_domain Chris@16: >(catch_exception(), catch_) Chris@16: ); Chris@16: } Chris@16: }; Chris@16: Chris@16: template < Chris@16: typename TryCatch Chris@16: , typename Expr Chris@16: , long Arity = proto::arity_of::value Chris@16: > Chris@16: struct catch_all_push_back; Chris@16: Chris@16: template Chris@16: struct catch_all_push_back Chris@16: { Chris@16: typedef Chris@16: typename proto::result_of::make_expr< Chris@16: phoenix::tag::catch_all Chris@16: , proto::basic_default_domain Chris@16: , Expr Chris@16: >::type Chris@16: catch_expr; Chris@16: Chris@16: typedef Chris@16: phoenix::expression::try_catch< Chris@16: TryCatch Chris@16: , catch_expr Chris@16: > Chris@16: gen_type; Chris@16: typedef typename gen_type::type type; Chris@16: Chris@16: static type make(TryCatch const& try_catch, Expr const& catch_) Chris@16: { Chris@16: return Chris@16: gen_type::make( Chris@16: try_catch Chris@16: , proto::make_expr< Chris@16: phoenix::tag::catch_all Chris@16: , proto::basic_default_domain Chris@16: >(catch_) Chris@16: ); Chris@16: } Chris@16: }; Chris@16: #include Chris@16: } Chris@16: Chris@16: template Chris@16: struct is_nullary::when Chris@16: : proto::call< Chris@16: detail::try_catch_is_nullary( Chris@16: proto::_ Chris@16: , proto::make Chris@16: , _context Chris@16: ) Chris@16: > Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct catch_gen Chris@16: { Chris@101: catch_gen(TryCatch const& try_catch_) : try_catch(try_catch_) {} Chris@16: Chris@16: template Chris@16: typename boost::disable_if< Chris@16: proto::matches< Chris@16: typename proto::result_of::child_c< Chris@16: TryCatch Chris@16: , proto::arity_of::value - 1 Chris@16: >::type Chris@16: , rule::catch_all Chris@16: > Chris@16: , typename detail::catch_push_back::type Chris@16: >::type Chris@16: operator[](Expr const& expr) const Chris@16: { Chris@16: return Chris@16: detail::catch_push_back::make( Chris@16: try_catch, expr Chris@16: ); Chris@16: } Chris@16: Chris@16: TryCatch const & try_catch; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct catch_all_gen Chris@16: { Chris@101: catch_all_gen(TryCatch const& try_catch_) : try_catch(try_catch_) {} Chris@16: Chris@16: template Chris@16: typename boost::disable_if< Chris@16: proto::matches< Chris@16: typename proto::result_of::child_c< Chris@16: TryCatch Chris@16: , proto::arity_of::value - 1 Chris@16: >::type Chris@16: , rule::catch_all Chris@16: > Chris@16: , typename detail::catch_all_push_back::type Chris@16: >::type Chris@16: operator[](Expr const& expr) const Chris@16: { Chris@16: return detail::catch_all_push_back::make( Chris@16: try_catch, expr Chris@16: ); Chris@16: } Chris@16: Chris@16: TryCatch const & try_catch; Chris@16: }; Chris@16: Chris@16: template < Chris@16: typename Expr Chris@16: > Chris@16: struct try_catch_actor; Chris@16: Chris@16: template Chris@16: struct try_catch_actor Chris@16: : actor Chris@16: { Chris@16: typedef try_catch_actor that_type; Chris@16: typedef actor base_type; Chris@16: Chris@16: try_catch_actor(base_type const& expr) Chris@16: : base_type(expr) Chris@16: , catch_all(*this) Chris@16: { Chris@16: } Chris@16: Chris@16: template Chris@16: catch_gen const Chris@16: catch_() const Chris@16: { Chris@16: return catch_gen(*this); Chris@16: } Chris@16: Chris@16: catch_all_gen const catch_all; Chris@16: }; Chris@16: Chris@16: struct try_gen Chris@16: { Chris@16: template Chris@16: typename expression::try_catch::type const Chris@16: operator[](Try const & try_) const Chris@16: { Chris@16: return expression::try_catch::make(try_); Chris@16: } Chris@16: }; Chris@16: Chris@16: #ifndef BOOST_PHOENIX_NO_PREDEFINED_TERMINALS Chris@16: try_gen const try_ = {}; Chris@16: #endif Chris@16: }} Chris@16: Chris@16: #ifdef _MSC_VER Chris@16: #pragma warning(pop) Chris@16: #endif Chris@16: Chris@16: #endif