Chris@16
|
1 /*==============================================================================
|
Chris@16
|
2 Copyright (c) 2005-2007 Dan Marsden
|
Chris@16
|
3 Copyright (c) 2005-2010 Joel de Guzman
|
Chris@16
|
4 Copyright (c) 2010 Thomas Heller
|
Chris@16
|
5
|
Chris@16
|
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 ==============================================================================*/
|
Chris@16
|
9
|
Chris@16
|
10 #ifndef BOOST_PHOENIX_STATEMENT_TRY_CATCH_HPP
|
Chris@16
|
11 #define BOOST_PHOENIX_STATEMENT_TRY_CATCH_HPP
|
Chris@16
|
12
|
Chris@16
|
13 #include <boost/phoenix/core/limits.hpp>
|
Chris@16
|
14 #include <boost/phoenix/core/call.hpp>
|
Chris@16
|
15 #include <boost/phoenix/core/expression.hpp>
|
Chris@16
|
16 #include <boost/phoenix/core/meta_grammar.hpp>
|
Chris@16
|
17 #include <boost/phoenix/core/is_nullary.hpp>
|
Chris@16
|
18 #include <boost/proto/functional/fusion/pop_front.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 #ifdef _MSC_VER
|
Chris@16
|
21 #pragma warning(push)
|
Chris@16
|
22 #pragma warning(disable: 4355) // 'this' : used in base member initializer list
|
Chris@16
|
23 #endif
|
Chris@16
|
24
|
Chris@16
|
25 namespace boost { namespace phoenix
|
Chris@16
|
26 {
|
Chris@16
|
27 template <typename Expr>
|
Chris@16
|
28 struct try_catch_actor;
|
Chris@16
|
29
|
Chris@16
|
30 template <typename Exception>
|
Chris@16
|
31 struct catch_exception
|
Chris@16
|
32 {
|
Chris@16
|
33 typedef Exception type;
|
Chris@16
|
34 };
|
Chris@16
|
35
|
Chris@16
|
36 namespace tag
|
Chris@16
|
37 {
|
Chris@16
|
38 struct try_catch {};
|
Chris@16
|
39 struct catch_ {};
|
Chris@16
|
40 struct catch_all {};
|
Chris@16
|
41 }
|
Chris@16
|
42
|
Chris@16
|
43 namespace expression
|
Chris@16
|
44 {
|
Chris@16
|
45 template <
|
Chris@16
|
46 typename Try
|
Chris@16
|
47 , BOOST_PHOENIX_typename_A_void(BOOST_PHOENIX_CATCH_LIMIT)
|
Chris@16
|
48 , typename Dummy = void
|
Chris@16
|
49 >
|
Chris@16
|
50 struct try_catch;
|
Chris@16
|
51
|
Chris@16
|
52 // bring in the expression definitions
|
Chris@16
|
53 #include <boost/phoenix/statement/detail/try_catch_expression.hpp>
|
Chris@16
|
54
|
Chris@16
|
55 template <typename A0, typename A1>
|
Chris@16
|
56 struct catch_
|
Chris@16
|
57 : proto::binary_expr<tag::catch_, A0, A1>
|
Chris@16
|
58 {};
|
Chris@16
|
59
|
Chris@16
|
60 template <typename A0>
|
Chris@16
|
61 struct catch_all
|
Chris@16
|
62 : proto::unary_expr<tag::catch_all, A0>
|
Chris@16
|
63 {};
|
Chris@16
|
64 }
|
Chris@16
|
65
|
Chris@16
|
66 namespace rule
|
Chris@16
|
67 {
|
Chris@16
|
68 struct catch_
|
Chris@16
|
69 : expression::catch_<
|
Chris@16
|
70 proto::terminal<catch_exception<proto::_> >
|
Chris@16
|
71 , meta_grammar
|
Chris@16
|
72 >
|
Chris@16
|
73 {};
|
Chris@16
|
74
|
Chris@16
|
75 struct catch_all
|
Chris@16
|
76 : expression::catch_all<
|
Chris@16
|
77 meta_grammar
|
Chris@16
|
78 >
|
Chris@16
|
79 {};
|
Chris@16
|
80
|
Chris@16
|
81 struct try_catch
|
Chris@16
|
82 : proto::or_<
|
Chris@16
|
83 expression::try_catch<
|
Chris@16
|
84 meta_grammar
|
Chris@16
|
85 , proto::vararg<rule::catch_>
|
Chris@16
|
86 >
|
Chris@16
|
87 , expression::try_catch<
|
Chris@16
|
88 meta_grammar
|
Chris@16
|
89 , rule::catch_all
|
Chris@16
|
90 >
|
Chris@16
|
91 , expression::try_catch<
|
Chris@16
|
92 meta_grammar
|
Chris@16
|
93 , proto::vararg<rule::catch_>
|
Chris@16
|
94 , rule::catch_all
|
Chris@16
|
95 >
|
Chris@16
|
96 >
|
Chris@16
|
97 {};
|
Chris@16
|
98 }
|
Chris@16
|
99
|
Chris@16
|
100 template <typename Dummy>
|
Chris@16
|
101 struct meta_grammar::case_<tag::try_catch, Dummy>
|
Chris@16
|
102 : enable_rule<rule::try_catch, Dummy>
|
Chris@16
|
103 {};
|
Chris@16
|
104
|
Chris@16
|
105 struct try_catch_eval
|
Chris@16
|
106 {
|
Chris@16
|
107 typedef void result_type;
|
Chris@16
|
108
|
Chris@16
|
109 template <typename Try, typename Context>
|
Chris@16
|
110 void operator()(Try const &, Context const &) const
|
Chris@16
|
111 {}
|
Chris@16
|
112
|
Chris@16
|
113 // bring in the operator overloads
|
Chris@16
|
114 #include <boost/phoenix/statement/detail/try_catch_eval.hpp>
|
Chris@16
|
115 };
|
Chris@16
|
116
|
Chris@16
|
117 template <typename Dummy>
|
Chris@16
|
118 struct default_actions::when<rule::try_catch, Dummy>
|
Chris@16
|
119 : call<try_catch_eval, Dummy>
|
Chris@16
|
120 {};
|
Chris@16
|
121
|
Chris@16
|
122 namespace detail
|
Chris@16
|
123 {
|
Chris@16
|
124 struct try_catch_is_nullary
|
Chris@16
|
125 : proto::or_<
|
Chris@16
|
126 proto::when<
|
Chris@16
|
127 phoenix::rule::catch_all
|
Chris@16
|
128 , proto::call<
|
Chris@16
|
129 evaluator(
|
Chris@16
|
130 proto::_child_c<0>
|
Chris@16
|
131 , proto::_data
|
Chris@16
|
132 , proto::make<proto::empty_env()>
|
Chris@16
|
133 )
|
Chris@16
|
134 >
|
Chris@16
|
135 >
|
Chris@16
|
136 , proto::when<
|
Chris@16
|
137 phoenix::rule::catch_
|
Chris@16
|
138 , proto::call<
|
Chris@16
|
139 evaluator(
|
Chris@16
|
140 proto::_child_c<1>
|
Chris@16
|
141 , proto::_data
|
Chris@16
|
142 , proto::make<proto::empty_env()>
|
Chris@16
|
143 )
|
Chris@16
|
144 >
|
Chris@16
|
145 >
|
Chris@16
|
146 , proto::when<
|
Chris@16
|
147 phoenix::rule::try_catch
|
Chris@16
|
148 , proto::make<
|
Chris@16
|
149 mpl::and_<
|
Chris@16
|
150 proto::call<
|
Chris@16
|
151 evaluator(
|
Chris@16
|
152 proto::_child_c<0>
|
Chris@16
|
153 , proto::_data
|
Chris@16
|
154 , proto::make<proto::empty_env()>
|
Chris@16
|
155 )
|
Chris@16
|
156 >
|
Chris@16
|
157 , proto::fold<
|
Chris@16
|
158 proto::call<
|
Chris@16
|
159 proto::functional::pop_front(proto::_)
|
Chris@16
|
160 >
|
Chris@16
|
161 , proto::make<mpl::true_()>
|
Chris@16
|
162 , proto::make<
|
Chris@16
|
163 mpl::and_<
|
Chris@16
|
164 proto::_state
|
Chris@16
|
165 , proto::call<
|
Chris@16
|
166 try_catch_is_nullary(
|
Chris@16
|
167 proto::_
|
Chris@16
|
168 , proto::make<proto::empty_env()>
|
Chris@16
|
169 , proto::_data
|
Chris@16
|
170 )
|
Chris@16
|
171 >
|
Chris@16
|
172 >()
|
Chris@16
|
173 >
|
Chris@16
|
174 >
|
Chris@16
|
175 >()
|
Chris@16
|
176 >
|
Chris@16
|
177 >
|
Chris@16
|
178 >
|
Chris@16
|
179 {};
|
Chris@16
|
180
|
Chris@16
|
181 template <
|
Chris@16
|
182 typename TryCatch
|
Chris@16
|
183 , typename Exception
|
Chris@16
|
184 , typename Expr
|
Chris@16
|
185 , long Arity = proto::arity_of<TryCatch>::value
|
Chris@16
|
186 >
|
Chris@16
|
187 struct catch_push_back;
|
Chris@16
|
188
|
Chris@16
|
189 template <typename TryCatch, typename Exception, typename Expr>
|
Chris@16
|
190 struct catch_push_back<TryCatch, Exception, Expr, 1>
|
Chris@16
|
191 {
|
Chris@16
|
192 typedef
|
Chris@16
|
193 typename proto::result_of::make_expr<
|
Chris@16
|
194 phoenix::tag::catch_
|
Chris@16
|
195 , proto::basic_default_domain
|
Chris@16
|
196 , catch_exception<Exception>
|
Chris@16
|
197 , Expr
|
Chris@16
|
198 >::type
|
Chris@16
|
199 catch_expr;
|
Chris@16
|
200
|
Chris@16
|
201 typedef
|
Chris@16
|
202 phoenix::expression::try_catch<
|
Chris@16
|
203 TryCatch
|
Chris@16
|
204 , catch_expr
|
Chris@16
|
205 >
|
Chris@16
|
206 gen_type;
|
Chris@16
|
207 typedef typename gen_type::type type;
|
Chris@16
|
208
|
Chris@16
|
209 static type make(TryCatch const & try_catch, Expr const & catch_)
|
Chris@16
|
210 {
|
Chris@16
|
211 return
|
Chris@16
|
212 gen_type::make(
|
Chris@16
|
213 try_catch
|
Chris@16
|
214 , proto::make_expr<
|
Chris@16
|
215 phoenix::tag::catch_
|
Chris@16
|
216 , proto::basic_default_domain
|
Chris@16
|
217 >(catch_exception<Exception>(), catch_)
|
Chris@16
|
218 );
|
Chris@16
|
219 }
|
Chris@16
|
220 };
|
Chris@16
|
221
|
Chris@16
|
222 template <
|
Chris@16
|
223 typename TryCatch
|
Chris@16
|
224 , typename Expr
|
Chris@16
|
225 , long Arity = proto::arity_of<TryCatch>::value
|
Chris@16
|
226 >
|
Chris@16
|
227 struct catch_all_push_back;
|
Chris@16
|
228
|
Chris@16
|
229 template <typename TryCatch, typename Expr>
|
Chris@16
|
230 struct catch_all_push_back<TryCatch, Expr, 1>
|
Chris@16
|
231 {
|
Chris@16
|
232 typedef
|
Chris@16
|
233 typename proto::result_of::make_expr<
|
Chris@16
|
234 phoenix::tag::catch_all
|
Chris@16
|
235 , proto::basic_default_domain
|
Chris@16
|
236 , Expr
|
Chris@16
|
237 >::type
|
Chris@16
|
238 catch_expr;
|
Chris@16
|
239
|
Chris@16
|
240 typedef
|
Chris@16
|
241 phoenix::expression::try_catch<
|
Chris@16
|
242 TryCatch
|
Chris@16
|
243 , catch_expr
|
Chris@16
|
244 >
|
Chris@16
|
245 gen_type;
|
Chris@16
|
246 typedef typename gen_type::type type;
|
Chris@16
|
247
|
Chris@16
|
248 static type make(TryCatch const& try_catch, Expr const& catch_)
|
Chris@16
|
249 {
|
Chris@16
|
250 return
|
Chris@16
|
251 gen_type::make(
|
Chris@16
|
252 try_catch
|
Chris@16
|
253 , proto::make_expr<
|
Chris@16
|
254 phoenix::tag::catch_all
|
Chris@16
|
255 , proto::basic_default_domain
|
Chris@16
|
256 >(catch_)
|
Chris@16
|
257 );
|
Chris@16
|
258 }
|
Chris@16
|
259 };
|
Chris@16
|
260 #include <boost/phoenix/statement/detail/catch_push_back.hpp>
|
Chris@16
|
261 }
|
Chris@16
|
262
|
Chris@16
|
263 template <typename Dummy>
|
Chris@16
|
264 struct is_nullary::when<rule::try_catch, Dummy>
|
Chris@16
|
265 : proto::call<
|
Chris@16
|
266 detail::try_catch_is_nullary(
|
Chris@16
|
267 proto::_
|
Chris@16
|
268 , proto::make<proto::empty_env()>
|
Chris@16
|
269 , _context
|
Chris@16
|
270 )
|
Chris@16
|
271 >
|
Chris@16
|
272 {};
|
Chris@16
|
273
|
Chris@16
|
274 template <typename TryCatch, typename Exception>
|
Chris@16
|
275 struct catch_gen
|
Chris@16
|
276 {
|
Chris@101
|
277 catch_gen(TryCatch const& try_catch_) : try_catch(try_catch_) {}
|
Chris@16
|
278
|
Chris@16
|
279 template <typename Expr>
|
Chris@16
|
280 typename boost::disable_if<
|
Chris@16
|
281 proto::matches<
|
Chris@16
|
282 typename proto::result_of::child_c<
|
Chris@16
|
283 TryCatch
|
Chris@16
|
284 , proto::arity_of<TryCatch>::value - 1
|
Chris@16
|
285 >::type
|
Chris@16
|
286 , rule::catch_all
|
Chris@16
|
287 >
|
Chris@16
|
288 , typename detail::catch_push_back<TryCatch, Exception, Expr>::type
|
Chris@16
|
289 >::type
|
Chris@16
|
290 operator[](Expr const& expr) const
|
Chris@16
|
291 {
|
Chris@16
|
292 return
|
Chris@16
|
293 detail::catch_push_back<TryCatch, Exception, Expr>::make(
|
Chris@16
|
294 try_catch, expr
|
Chris@16
|
295 );
|
Chris@16
|
296 }
|
Chris@16
|
297
|
Chris@16
|
298 TryCatch const & try_catch;
|
Chris@16
|
299 };
|
Chris@16
|
300
|
Chris@16
|
301 template <typename TryCatch>
|
Chris@16
|
302 struct catch_all_gen
|
Chris@16
|
303 {
|
Chris@101
|
304 catch_all_gen(TryCatch const& try_catch_) : try_catch(try_catch_) {}
|
Chris@16
|
305
|
Chris@16
|
306 template <typename Expr>
|
Chris@16
|
307 typename boost::disable_if<
|
Chris@16
|
308 proto::matches<
|
Chris@16
|
309 typename proto::result_of::child_c<
|
Chris@16
|
310 TryCatch
|
Chris@16
|
311 , proto::arity_of<TryCatch>::value - 1
|
Chris@16
|
312 >::type
|
Chris@16
|
313 , rule::catch_all
|
Chris@16
|
314 >
|
Chris@16
|
315 , typename detail::catch_all_push_back<TryCatch, Expr>::type
|
Chris@16
|
316 >::type
|
Chris@16
|
317 operator[](Expr const& expr) const
|
Chris@16
|
318 {
|
Chris@16
|
319 return detail::catch_all_push_back<TryCatch, Expr>::make(
|
Chris@16
|
320 try_catch, expr
|
Chris@16
|
321 );
|
Chris@16
|
322 }
|
Chris@16
|
323
|
Chris@16
|
324 TryCatch const & try_catch;
|
Chris@16
|
325 };
|
Chris@16
|
326
|
Chris@16
|
327 template <
|
Chris@16
|
328 typename Expr
|
Chris@16
|
329 >
|
Chris@16
|
330 struct try_catch_actor;
|
Chris@16
|
331
|
Chris@16
|
332 template <typename Expr>
|
Chris@16
|
333 struct try_catch_actor
|
Chris@16
|
334 : actor<Expr>
|
Chris@16
|
335 {
|
Chris@16
|
336 typedef try_catch_actor<Expr> that_type;
|
Chris@16
|
337 typedef actor<Expr> base_type;
|
Chris@16
|
338
|
Chris@16
|
339 try_catch_actor(base_type const& expr)
|
Chris@16
|
340 : base_type(expr)
|
Chris@16
|
341 , catch_all(*this)
|
Chris@16
|
342 {
|
Chris@16
|
343 }
|
Chris@16
|
344
|
Chris@16
|
345 template <typename Exception>
|
Chris@16
|
346 catch_gen<that_type, Exception> const
|
Chris@16
|
347 catch_() const
|
Chris@16
|
348 {
|
Chris@16
|
349 return catch_gen<that_type, Exception>(*this);
|
Chris@16
|
350 }
|
Chris@16
|
351
|
Chris@16
|
352 catch_all_gen<that_type> const catch_all;
|
Chris@16
|
353 };
|
Chris@16
|
354
|
Chris@16
|
355 struct try_gen
|
Chris@16
|
356 {
|
Chris@16
|
357 template <typename Try>
|
Chris@16
|
358 typename expression::try_catch<Try>::type const
|
Chris@16
|
359 operator[](Try const & try_) const
|
Chris@16
|
360 {
|
Chris@16
|
361 return expression::try_catch<Try>::make(try_);
|
Chris@16
|
362 }
|
Chris@16
|
363 };
|
Chris@16
|
364
|
Chris@16
|
365 #ifndef BOOST_PHOENIX_NO_PREDEFINED_TERMINALS
|
Chris@16
|
366 try_gen const try_ = {};
|
Chris@16
|
367 #endif
|
Chris@16
|
368 }}
|
Chris@16
|
369
|
Chris@16
|
370 #ifdef _MSC_VER
|
Chris@16
|
371 #pragma warning(pop)
|
Chris@16
|
372 #endif
|
Chris@16
|
373
|
Chris@16
|
374 #endif
|