|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63515 - in sandbox/SOC/2010/phoenix3: boost/phoenix/statement libs/phoenix/test/statement
From: thom.heller_at_[hidden]
Date: 2010-07-02 14:56:18
Author: theller
Date: 2010-07-02 04:00:43 EDT (Fri, 02 Jul 2010)
New Revision: 63515
URL: http://svn.boost.org/trac/boost/changeset/63515
Log:
+ finished try/catch
Text files modified:
sandbox/SOC/2010/phoenix3/boost/phoenix/statement/try_catch.hpp | 187 +++++++++++++++++++++++++++++++--------
sandbox/SOC/2010/phoenix3/libs/phoenix/test/statement/exceptions.cpp | 2
2 files changed, 149 insertions(+), 40 deletions(-)
Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/statement/try_catch.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/statement/try_catch.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/statement/try_catch.hpp 2010-07-02 04:00:43 EDT (Fri, 02 Jul 2010)
@@ -11,6 +11,7 @@
#ifndef PHOENIX_STATEMENT_TRY_CATCH_HPP
#define PHOENIX_STATEMENT_TRY_CATCH_HPP
+#include <boost/phoenix/core/compose.hpp>
#include <boost/phoenix/support/element_at.hpp>
#include <boost/phoenix/support/iterate.hpp>
@@ -25,17 +26,23 @@
};
}
- template <PHOENIX_typename_A_void(PHOENIX_CATCH_LIMIT), typename Dummy = void>
+ template <PHOENIX_typename_A_void(PHOENIX_CATCH_LIMIT),
+ typename Dummy = void>
struct try_catch_eval;
+ template <PHOENIX_typename_A_void(PHOENIX_CATCH_LIMIT),
+ typename Dummy = void>
+ struct try_catch_all_eval;
+
template<>
- struct try_catch_eval<>
+ struct try_catch_all_eval<>
{
typedef void result_type;
template <typename Env, typename Try, typename CatchAll>
result_type
- operator()(Env& env, Try const& try_block, CatchAll const& catch_all) const
+ operator()(
+ Env& env, Try const& try_block, CatchAll const& catch_all) const
{
try
{
@@ -48,13 +55,22 @@
}
};
-#define CATCH_EXCEPTION(_, n, __) \
- BOOST_PP_COMMA_IF(n) typename CatchBlock ## n = void, typename Exception ## n = void
+#define CATCH_EXCEPTION(_, n, __) \
+ BOOST_PP_COMMA_IF(n) \
+ typename CatchBlock ## n = void, typename Exception ## n = void
+
template <
typename Try
, BOOST_PP_REPEAT(PHOENIX_CATCH_LIMIT, CATCH_EXCEPTION, _)
, typename Dummy = void>
struct make_try_catch;
+
+ template <
+ typename Try
+ , BOOST_PP_REPEAT(PHOENIX_CATCH_LIMIT, CATCH_EXCEPTION, _)
+ , typename CatchAll = void
+ , typename Dummy = void>
+ struct make_try_catch_all;
template <
typename Exception
@@ -62,16 +78,25 @@
, BOOST_PP_REPEAT(BOOST_PP_DEC(PHOENIX_CATCH_LIMIT), CATCH_EXCEPTION, _)
, typename Dummy = void>
struct catch_gen;
+
+ template <
+ typename Try
+ , BOOST_PP_REPEAT(PHOENIX_CATCH_LIMIT, CATCH_EXCEPTION, _)
+ , typename Dummy = void>
+ struct catch_all_gen;
+
#undef CATCH_EXCEPTION
template<typename Expr>
struct try_catch_actor0;
template <typename Try>
- struct make_try_catch<Try> : compose_ex<try_catch_eval<>, try_catch_actor0, Try> {};
+ struct make_try_catch<Try>
+ : compose_ex<try_catch_eval<>, try_catch_actor0, Try> {};
template <typename Try, typename CatchAll>
- struct make_try_catch<Try, CatchAll> : compose<try_catch_eval<>, Try, CatchAll> {};
+ struct make_try_catch_all<Try, CatchAll>
+ : compose<try_catch_all_eval<>, Try, CatchAll> {};
template <typename Exception, typename Try>
struct catch_gen<Exception, Try>
@@ -82,22 +107,23 @@
typename make_try_catch<Try, CatchBlock, Exception>::type const
operator[](CatchBlock const& catch_block) const
{
- return make_try_catch<Try, CatchBlock, Exception>()(try_block, catch_block);
+ return make_try_catch<
+ Try, CatchBlock, Exception>()(try_block, catch_block);
};
Try const& try_block;
};
template <typename Try>
- struct catch_all_gen
+ struct catch_all_gen<Try>
{
catch_all_gen(Try const& try_block) : try_block(try_block) {}
template <typename CatchAll>
- typename make_try_catch<Try, CatchAll>::type const
+ typename make_try_catch_all<Try, CatchAll>::type const
operator[](CatchAll const& catch_all) const
{
- return make_try_catch<Try, CatchAll>()(try_block, catch_all);
+ return make_try_catch_all<Try, CatchAll>()(try_block, catch_all);
}
Try const& try_block;
@@ -136,7 +162,8 @@
{
typedef actor<Expr> base_type;
- BOOST_PP_CAT(try_catch_actor, BOOST_PP_INC(PHOENIX_CATCH_LIMIT))(base_type const& base)
+ BOOST_PP_CAT(try_catch_actor, BOOST_PP_INC(PHOENIX_CATCH_LIMIT))(
+ base_type const& base)
: base_type(base)
, catch_all(element_at_c<0>(*this))
{}
@@ -164,32 +191,67 @@
#else
-#define PHOENIX_typename_Exception BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, typename Exception)
-#define PHOENIX_Exception BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, Exception)
-#define PHOENIX_Exception_ref BOOST_PP_ENUM_BINARY_PARAMS(PHOENIX_ITERATION, Exception, & BOOST_PP_INTERCEPT)
+#define PHOENIX_typename_Exception \
+ BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, typename Exception)
+#define PHOENIX_Exception \
+ BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, Exception)
+#define PHOENIX_Exception_ref \
+ BOOST_PP_ENUM_BINARY_PARAMS( \
+ PHOENIX_ITERATION, Exception, & BOOST_PP_INTERCEPT)
+
+#define INIT_a(_,n,__) BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(a,n)(BOOST_PP_CAT(a,n))
+#define CATCH_BLOCK(_, n, __) A ## n const& a ## n;
template <typename Exception, typename Try, PHOENIX_typename_A>
struct catch_gen<Exception, Try, PHOENIX_A>
{
-#define INIT_a(_,n,__) BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(a,n)(BOOST_PP_CAT(a,n))
catch_gen(Try const& try_block, PHOENIX_A_const_ref_a)
: try_block(try_block)
, BOOST_PP_REPEAT(PHOENIX_ITERATION, INIT_a, _)
{}
template <typename CatchBlock>
- typename make_try_catch<Try, PHOENIX_A, CatchBlock, Exception>::type const
+ typename make_try_catch<
+ Try, PHOENIX_A, CatchBlock, Exception>::type const
operator[](CatchBlock const& catch_block) const
{
- return make_try_catch<Try, PHOENIX_A, CatchBlock, Exception>()(try_block, PHOENIX_a, catch_block);
+ return make_try_catch<
+ Try, PHOENIX_A, CatchBlock, Exception>()(
+ try_block, PHOENIX_a, catch_block);
};
Try const& try_block;
-#define CATCH_BLOCK(_, n, __) A ## n const& a ## n;
BOOST_PP_REPEAT(PHOENIX_ITERATION, CATCH_BLOCK, _)
-#undef CATCH_BLOCK
};
+ template <typename Try, PHOENIX_typename_A>
+ struct catch_all_gen<Try, PHOENIX_A>
+ {
+ catch_all_gen(Try const& try_block, PHOENIX_A_const_ref_a)
+ : try_block(try_block)
+ , BOOST_PP_REPEAT(PHOENIX_ITERATION, INIT_a, _)
+ {}
+
+ template <typename CatchAll>
+ typename make_try_catch_all<Try, PHOENIX_A, CatchAll>::type const
+ operator[](CatchAll const& catch_all) const
+ {
+ return make_try_catch_all<
+ Try, PHOENIX_A, CatchAll>()(try_block, PHOENIX_a, catch_all);
+ }
+
+ Try const& try_block;
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, CATCH_BLOCK, _)
+ };
+#undef CATCH_BLOCK
+#undef INIT_a
+
+#define CATCH(_, n, __) \
+ catch(Exception ## n &) \
+ { \
+ eval(a ## n, env); \
+ }
+
template <PHOENIX_typename_Exception>
struct try_catch_eval<PHOENIX_Exception>
{
@@ -203,31 +265,68 @@
{
eval(try_, env);
}
-#define CATCH(_, n, __) \
- catch(Exception ## n &) \
- { \
- eval(a ## n, env); \
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, CATCH, _)
+ }
+ };
+
+ template <PHOENIX_typename_Exception>
+ struct try_catch_all_eval<PHOENIX_Exception>
+ {
+ typedef void result_type;
+
+ template <typename Env, typename Try, PHOENIX_typename_A, typename CatchAll>
+ result_type
+ operator()(
+ Env& env,
+ Try const& try_,
+ PHOENIX_A_const_ref_a,
+ CatchAll const& catch_all) const
+ {
+ try
+ {
+ eval(try_, env);
}
BOOST_PP_REPEAT(PHOENIX_ITERATION, CATCH, _)
-#undef CATCH
+ catch(...)
+ {
+ eval(catch_all, env);
+ }
}
};
- template <typename Expr> struct BOOST_PP_CAT(try_catch_actor, PHOENIX_ITERATION);
+#undef CATCH
-#define CATCH_EXCEPTION_typename(_, n, __) \
+ template <typename Expr>
+ struct BOOST_PP_CAT(try_catch_actor, PHOENIX_ITERATION);
+
+#define CATCH_EXCEPTION_typename(_, n, __) \
BOOST_PP_COMMA_IF(n) typename CatchBlock ## n, typename Exception ## n
-#define CATCH_EXCEPTION(_, n, __) \
+#define CATCH_EXCEPTION(_, n, __) \
BOOST_PP_COMMA_IF(n) CatchBlock ## n, Exception ## n
- template <typename Try, BOOST_PP_REPEAT(PHOENIX_ITERATION, CATCH_EXCEPTION_typename, _)>
- struct make_try_catch<Try, BOOST_PP_REPEAT(PHOENIX_ITERATION, CATCH_EXCEPTION, _)>
+ template <typename Try,
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, CATCH_EXCEPTION_typename, _)>
+ struct make_try_catch<Try,
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, CATCH_EXCEPTION, _)>
+ : compose_ex<
+ try_catch_eval<BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, Exception)>
+ , BOOST_PP_CAT(try_catch_actor, PHOENIX_ITERATION)
+ , Try
+ , BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, CatchBlock)
+ > {};
+
+ template <typename Try,
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, CATCH_EXCEPTION_typename, _),
+ typename CatchAll>
+ struct make_try_catch_all<Try,
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, CATCH_EXCEPTION, _), CatchAll>
: compose_ex<
try_catch_eval<BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, Exception)>
, BOOST_PP_CAT(try_catch_actor, PHOENIX_ITERATION)
, Try
, BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, CatchBlock)
+ , CatchAll
> {};
template <typename Expr>
@@ -240,21 +339,33 @@
: base_type(base)
, catch_all(element_at_c<0>(*this))
{}
+
+#undef CATCH_EXCEPTION
+#undef CATCH_EXCEPTION_typename
- typedef typename result_of::element_value_at_c<Expr, 0>::type try_type;
-#define CATCH_BLOCK_TYPES(_, n, __) \
- typedef typename result_of::element_value_at_c<Expr, n>::type catch_block_type ## n;
- BOOST_PP_REPEAT_FROM_TO(1, PHOENIX_ITERATION, CATCH_BLOCK_TYPES, _)
-#undef CATCH_BLOCK_TYPES
+#define TRY_CATCH_BLOCK_TYPES(_, n, __) \
+ typedef typename \
+ result_of::element_value_at_c<Expr, n>::type try_catch_type ## n;
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, TRY_CATCH_BLOCK_TYPES, _)
+#undef TRY_CATCH_BLOCK_TYPES
+
template <typename Exception>
- catch_gen<Exception, try_type> const
+ catch_gen<Exception,
+ BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, try_catch_type)> const
catch_() const
{
- return catch_gen<Exception, try_type>(element_at_c<0>(*this));
+#define ELEMENT_AT_C(_,n,__) BOOST_PP_COMMA_IF(n) element_at_c< n >(*this)
+
+ return catch_gen<
+ Exception
+ , BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, try_catch_type)
+ >(BOOST_PP_REPEAT(PHOENIX_ITERATION, ELEMENT_AT_C, _));
+#undef ELEMENT_AT_C
}
- const catch_all_gen<try_type> catch_all;
+ const catch_all_gen<
+ BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, try_catch_type)> catch_all;
};
#undef PHOENIX_typename_Exception
Modified: sandbox/SOC/2010/phoenix3/libs/phoenix/test/statement/exceptions.cpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/statement/exceptions.cpp (original)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/statement/exceptions.cpp 2010-07-02 04:00:43 EDT (Fri, 02 Jul 2010)
@@ -75,7 +75,6 @@
BOOST_TEST(caught_exception);
}
-/*
{
bool caught_correct_exception = false;
try_
@@ -99,6 +98,5 @@
BOOST_TEST(caught_correct_exception);
}
-*/
return boost::report_errors();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk