1
/*=============================================================================
3
Copyright (c) 2002-2003 Hartmut Kaiser
4
http://spirit.sourceforge.net/
6
Permission to copy, use, modify, sell and distribute this software is
7
granted provided this copyright notice appears in all copies. This
8
software is provided "as is" without express or implied warranty, and
9
with no claim as to its suitability for any purpose.
10
=============================================================================*/
11
#if !defined(BOOST_SPIRIT_FUNDAMENTAL_IPP)
12
#define BOOST_SPIRIT_FUNDAMENTAL_IPP
14
///////////////////////////////////////////////////////////////////////////////
15
namespace boost { namespace spirit {
17
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
18
BOOST_SPIRIT_DEPENDENT_TEMPLATE_WRAPPER2(count_wrapper, count);
19
#endif // defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
23
///////////////////////////////////////////////////////////////////////////
25
// Helper template for counting the number of nodes contained in a
27
// All parser_category type parsers are counted as nodes.
29
///////////////////////////////////////////////////////////////////////////
30
template <typename CategoryT>
34
struct nodes<plain_parser_category> {
36
template <typename ParserT, typename LeafCountT>
39
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
40
enum { value = (LeafCountT::value + 1) };
44
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
47
struct nodes<unary_parser_category> {
49
template <typename ParserT, typename LeafCountT>
52
typedef typename ParserT::subject_t subject_t;
53
typedef typename subject_t::parser_category_t subject_category_t;
55
typedef nodes<subject_category_t> nodes_t;
56
typedef typename count_wrapper<nodes_t>
57
::template result_<subject_t, LeafCountT> count_t;
59
BOOST_STATIC_CONSTANT(int, value = count_t::value + 1);
64
struct nodes<action_parser_category> {
66
template <typename ParserT, typename LeafCountT>
69
typedef typename ParserT::subject_t subject_t;
70
typedef typename subject_t::parser_category_t subject_category_t;
72
typedef nodes<subject_category_t> nodes_t;
73
typedef typename count_wrapper<nodes_t>
74
::template result_<subject_t, LeafCountT> count_t;
76
BOOST_STATIC_CONSTANT(int, value = count_t::value + 1);
81
struct nodes<binary_parser_category> {
83
template <typename ParserT, typename LeafCountT>
86
typedef typename ParserT::left_t left_t;
87
typedef typename ParserT::right_t right_t;
88
typedef typename left_t::parser_category_t left_category_t;
89
typedef typename right_t::parser_category_t right_category_t;
91
typedef nodes<left_category_t> left_nodes_t;
92
typedef typename count_wrapper<left_nodes_t>
93
::template result_<left_t, LeafCountT> left_count_t;
95
typedef nodes<right_category_t> right_nodes_t;
96
typedef typename count_wrapper<right_nodes_t>
97
::template result_<right_t, LeafCountT> right_count_t;
99
BOOST_STATIC_CONSTANT(int,
100
value = (left_count_t::value + right_count_t::value + 1));
107
struct nodes<unary_parser_category> {
109
template <typename ParserT, typename LeafCountT>
112
typedef typename ParserT::subject_t subject_t;
113
typedef typename subject_t::parser_category_t subject_category_t;
115
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
116
enum { value = (nodes<subject_category_t>
117
::template count<subject_t, LeafCountT>::value + 1) };
122
struct nodes<action_parser_category> {
124
template <typename ParserT, typename LeafCountT>
127
typedef typename ParserT::subject_t subject_t;
128
typedef typename subject_t::parser_category_t subject_category_t;
130
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
131
enum { value = (nodes<subject_category_t>
132
::template count<subject_t, LeafCountT>::value + 1) };
137
struct nodes<binary_parser_category> {
139
template <typename ParserT, typename LeafCountT>
142
typedef typename ParserT::left_t left_t;
143
typedef typename ParserT::right_t right_t;
144
typedef typename left_t::parser_category_t left_category_t;
145
typedef typename right_t::parser_category_t right_category_t;
147
typedef count self_t;
149
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
151
leftcount = (nodes<left_category_t>
152
::template count<left_t, LeafCountT>::value),
153
rightcount = (nodes<right_category_t>
154
::template count<right_t, LeafCountT>::value),
155
value = ((self_t::leftcount) + (self_t::rightcount) + 1)
162
///////////////////////////////////////////////////////////////////////////
164
// Helper template for counting the number of leaf nodes contained in a
165
// given parser type.
166
// Only plain_parser_category type parsers are counted as leaf nodes.
168
///////////////////////////////////////////////////////////////////////////
169
template <typename CategoryT>
173
struct leafs<plain_parser_category> {
175
template <typename ParserT, typename LeafCountT>
178
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
179
enum { value = (LeafCountT::value + 1) };
183
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
186
struct leafs<unary_parser_category> {
188
template <typename ParserT, typename LeafCountT>
191
typedef typename ParserT::subject_t subject_t;
192
typedef typename subject_t::parser_category_t subject_category_t;
194
typedef leafs<subject_category_t> nodes_t;
195
typedef typename count_wrapper<nodes_t>
196
::template result_<subject_t, LeafCountT> count_t;
198
BOOST_STATIC_CONSTANT(int, value = count_t::value);
203
struct leafs<action_parser_category> {
205
template <typename ParserT, typename LeafCountT>
208
typedef typename ParserT::subject_t subject_t;
209
typedef typename subject_t::parser_category_t subject_category_t;
211
typedef leafs<subject_category_t> nodes_t;
212
typedef typename count_wrapper<nodes_t>
213
::template result_<subject_t, LeafCountT> count_t;
215
BOOST_STATIC_CONSTANT(int, value = count_t::value);
220
struct leafs<binary_parser_category> {
222
template <typename ParserT, typename LeafCountT>
225
typedef typename ParserT::left_t left_t;
226
typedef typename ParserT::right_t right_t;
227
typedef typename left_t::parser_category_t left_category_t;
228
typedef typename right_t::parser_category_t right_category_t;
230
typedef leafs<left_category_t> left_nodes_t;
231
typedef typename count_wrapper<left_nodes_t>
232
::template result_<left_t, LeafCountT> left_count_t;
234
typedef leafs<right_category_t> right_nodes_t;
235
typedef typename count_wrapper<right_nodes_t>
236
::template result_<right_t, LeafCountT> right_count_t;
238
BOOST_STATIC_CONSTANT(int,
239
value = (left_count_t::value + right_count_t::value));
246
struct leafs<unary_parser_category> {
248
template <typename ParserT, typename LeafCountT>
251
typedef typename ParserT::subject_t subject_t;
252
typedef typename subject_t::parser_category_t subject_category_t;
254
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
255
enum { value = (leafs<subject_category_t>
256
::template count<subject_t, LeafCountT>::value) };
261
struct leafs<action_parser_category> {
263
template <typename ParserT, typename LeafCountT>
266
typedef typename ParserT::subject_t subject_t;
267
typedef typename subject_t::parser_category_t subject_category_t;
269
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
270
enum { value = (leafs<subject_category_t>
271
::template count<subject_t, LeafCountT>::value) };
276
struct leafs<binary_parser_category> {
278
template <typename ParserT, typename LeafCountT>
281
typedef typename ParserT::left_t left_t;
282
typedef typename ParserT::right_t right_t;
283
typedef typename left_t::parser_category_t left_category_t;
284
typedef typename right_t::parser_category_t right_category_t;
286
typedef count self_t;
288
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
290
leftcount = (leafs<left_category_t>
291
::template count<left_t, LeafCountT>::value),
292
rightcount = (leafs<right_category_t>
293
::template count<right_t, LeafCountT>::value),
294
value = (self_t::leftcount + self_t::rightcount)
303
///////////////////////////////////////////////////////////////////////////////
304
}} // namespace boost::spirit
306
#endif // !defined(BOOST_SPIRIT_FUNDAMENTAL_IPP)