throw.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*==============================================================================
  2. Copyright (c) 2005-2007 Dan Marsden
  3. Copyright (c) 2005-2010 Joel de Guzman
  4. Copyright (c) 2010 Thomas Heller
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ==============================================================================*/
  8. #ifndef BOOST_PHOENIX_STATEMENT_THROW_HPP
  9. #define BOOST_PHOENIX_STATEMENT_THROW_HPP
  10. #include <boost/phoenix/core/limits.hpp>
  11. #include <boost/phoenix/core/actor.hpp>
  12. #include <boost/phoenix/core/call.hpp>
  13. #include <boost/phoenix/core/meta_grammar.hpp>
  14. #include <boost/phoenix/core/expression.hpp>
  15. #include <boost/phoenix/core/terminal.hpp>
  16. #include <boost/phoenix/core/value.hpp>
  17. namespace boost { namespace phoenix
  18. {
  19. namespace tag
  20. {
  21. struct throw_ {};
  22. }
  23. namespace expression
  24. {
  25. template <typename A>
  26. struct throw_
  27. : expr<tag::throw_, A>
  28. {};
  29. }
  30. namespace rule
  31. {
  32. struct throw_
  33. : expression::throw_<meta_grammar>
  34. {};
  35. }
  36. template <typename Dummy>
  37. struct meta_grammar::case_<tag::throw_, Dummy>
  38. : enable_rule<rule::throw_, Dummy>
  39. {};
  40. struct throw_eval
  41. {
  42. typedef void result_type;
  43. template <typename ThrowExpr, typename Context>
  44. result_type
  45. operator()(ThrowExpr const& throw_expr, Context const & ctx) const
  46. {
  47. throw boost::phoenix::eval(throw_expr, ctx);
  48. }
  49. };
  50. template <typename Dummy>
  51. struct default_actions::when<rule::throw_, Dummy>
  52. : call<throw_eval>
  53. {};
  54. template <typename ThrowExpr>
  55. inline
  56. typename expression::throw_<ThrowExpr>::type const
  57. throw_(ThrowExpr const& throw_expr)
  58. {
  59. return expression::throw_<ThrowExpr>::make(throw_expr);
  60. }
  61. namespace detail
  62. {
  63. struct rethrow {};
  64. }
  65. namespace expression
  66. {
  67. struct rethrow
  68. : expression::value<detail::rethrow>
  69. {};
  70. }
  71. template<typename Dummy>
  72. struct is_custom_terminal<detail::rethrow, Dummy>
  73. : mpl::true_
  74. {};
  75. template<typename Dummy>
  76. struct custom_terminal<detail::rethrow, Dummy>
  77. {
  78. typedef void result_type;
  79. //#ifndef BOOST_PHOENIX_NO_SPECIALIZE_CUSTOM_TERMINAL
  80. typedef void _is_throw_custom_terminal; // fix for #7730
  81. //#endif
  82. template <typename Context>
  83. void operator()(detail::rethrow, Context &) const
  84. {
  85. throw;
  86. }
  87. };
  88. inline
  89. expression::rethrow::type const
  90. throw_()
  91. {
  92. return expression::rethrow::make(detail::rethrow());
  93. }
  94. }}
  95. #endif