1 /*=============================================================================
2 Copyright (c) 2001-2007 Joel de Guzman
3 Copyright (c) 2001-2009 Hartmut Kaiser
4 http://spirit.sourceforge.net/
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #if !defined(BOOST_SPIRIT_VALUES_JAN_07_2007_0802PM)
10 #define BOOST_SPIRIT_VALUES_JAN_07_2007_0802PM
12 #include <boost/fusion/include/is_sequence.hpp>
13 #include <boost/fusion/include/vector.hpp>
14 #include <boost/spirit/home/support/unused.hpp>
15 #include <boost/utility/enable_if.hpp>
16 #include <boost/mpl/bool.hpp>
17 #include <boost/mpl/and.hpp>
18 #include <boost/variant.hpp>
20 namespace boost
{ namespace spirit
{ namespace detail
26 template <BOOST_VARIANT_ENUM_PARAMS(typename T
)>
27 struct not_is_variant
<boost::variant
<BOOST_VARIANT_ENUM_PARAMS(T
)> >
30 ///////////////////////////////////////////////////////////////////////////
31 // All parsers and generators have specific attribute or parameter types.
32 // Spirit parsers are passed an attribute and Spirit generators
33 // are passed a parameter; these are either references to the expected
34 // type, or an unused_type -- to flag that we do not care about the
35 // attribute/parameter. For semantic actions, however, we need to have a
36 // real value to pass to the semantic action. If the client did not
37 // provide one, we will have to synthesize the value. This class
38 // takes care of that.
39 ///////////////////////////////////////////////////////////////////////////
40 template <typename ValueType
>
43 static ValueType
call(unused_type
)
45 return ValueType(); // synthesize the attribute/parameter
49 static T
& call(T
& value
)
51 return value
; // just pass the one provided
55 static T
const& call(T
const& value
)
57 return value
; // just pass the one provided
61 template <typename ValueType
>
62 struct make_value
<ValueType
&> : make_value
<ValueType
>
67 struct make_value
<unused_type
>
69 static unused_type
call(unused_type
)
75 ///////////////////////////////////////////////////////////////////////////
76 // pass_value determines how we pass attributes and parameters to semantic
77 // actions. Basically, all SAs receive the arguments in a tuple. So, if
78 // the argument to be passed is not a tuple, wrap it in one.
79 ///////////////////////////////////////////////////////////////////////////
80 template <typename ValueType
>
85 fusion::traits::is_sequence
<ValueType
>
86 , detail::not_is_variant
<ValueType
>
94 , fusion::vector
<ValueType
&> const
99 call(ValueType
& arg
, mpl::true_
)
101 // arg is a fusion sequence (except a variant) return it as-is.
105 static fusion::vector
<ValueType
&> const
106 call(ValueType
& seq
, mpl::false_
)
108 // arg is a not fusion sequence wrap it in a fusion::vector.
109 return fusion::vector
<ValueType
&>(seq
);
115 return call(arg
, is_sequence());