Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2002-2003 Hartmut Kaiser
|
Chris@16
|
3 http://spirit.sourceforge.net/
|
Chris@16
|
4
|
Chris@16
|
5 Use, modification and distribution is subject to the Boost Software
|
Chris@16
|
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 =============================================================================*/
|
Chris@16
|
9 #if !defined(BOOST_SPIRIT_FUNDAMENTAL_IPP)
|
Chris@16
|
10 #define BOOST_SPIRIT_FUNDAMENTAL_IPP
|
Chris@16
|
11
|
Chris@16
|
12 #include <boost/mpl/int.hpp>
|
Chris@16
|
13
|
Chris@16
|
14 namespace boost { namespace spirit {
|
Chris@16
|
15
|
Chris@16
|
16 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
|
Chris@16
|
17
|
Chris@16
|
18 namespace impl
|
Chris@16
|
19 {
|
Chris@16
|
20 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
21 //
|
Chris@16
|
22 // Helper template for counting the number of nodes contained in a
|
Chris@16
|
23 // given parser type.
|
Chris@16
|
24 // All parser_category type parsers are counted as nodes.
|
Chris@16
|
25 //
|
Chris@16
|
26 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
27 template <typename CategoryT>
|
Chris@16
|
28 struct nodes;
|
Chris@16
|
29
|
Chris@16
|
30 template <>
|
Chris@16
|
31 struct nodes<plain_parser_category> {
|
Chris@16
|
32
|
Chris@16
|
33 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
34 struct count {
|
Chris@16
|
35
|
Chris@16
|
36 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
37 enum { value = (LeafCountT::value + 1) };
|
Chris@16
|
38 };
|
Chris@16
|
39 };
|
Chris@16
|
40
|
Chris@16
|
41 template <>
|
Chris@16
|
42 struct nodes<unary_parser_category> {
|
Chris@16
|
43
|
Chris@16
|
44 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
45 struct count {
|
Chris@16
|
46
|
Chris@16
|
47 typedef typename ParserT::subject_t subject_t;
|
Chris@16
|
48 typedef typename subject_t::parser_category_t subject_category_t;
|
Chris@16
|
49
|
Chris@16
|
50 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
51 enum { value = (nodes<subject_category_t>
|
Chris@16
|
52 ::template count<subject_t, LeafCountT>::value + 1) };
|
Chris@16
|
53 };
|
Chris@16
|
54 };
|
Chris@16
|
55
|
Chris@16
|
56 template <>
|
Chris@16
|
57 struct nodes<action_parser_category> {
|
Chris@16
|
58
|
Chris@16
|
59 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
60 struct count {
|
Chris@16
|
61
|
Chris@16
|
62 typedef typename ParserT::subject_t subject_t;
|
Chris@16
|
63 typedef typename subject_t::parser_category_t subject_category_t;
|
Chris@16
|
64
|
Chris@16
|
65 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
66 enum { value = (nodes<subject_category_t>
|
Chris@16
|
67 ::template count<subject_t, LeafCountT>::value + 1) };
|
Chris@16
|
68 };
|
Chris@16
|
69 };
|
Chris@16
|
70
|
Chris@16
|
71 template <>
|
Chris@16
|
72 struct nodes<binary_parser_category> {
|
Chris@16
|
73
|
Chris@16
|
74 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
75 struct count {
|
Chris@16
|
76
|
Chris@16
|
77 typedef typename ParserT::left_t left_t;
|
Chris@16
|
78 typedef typename ParserT::right_t right_t;
|
Chris@16
|
79 typedef typename left_t::parser_category_t left_category_t;
|
Chris@16
|
80 typedef typename right_t::parser_category_t right_category_t;
|
Chris@16
|
81
|
Chris@16
|
82 typedef count self_t;
|
Chris@16
|
83
|
Chris@16
|
84 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
85 enum {
|
Chris@16
|
86 leftcount = (nodes<left_category_t>
|
Chris@16
|
87 ::template count<left_t, LeafCountT>::value),
|
Chris@16
|
88 rightcount = (nodes<right_category_t>
|
Chris@16
|
89 ::template count<right_t, LeafCountT>::value),
|
Chris@16
|
90 value = ((self_t::leftcount) + (self_t::rightcount) + 1)
|
Chris@16
|
91 };
|
Chris@16
|
92 };
|
Chris@16
|
93 };
|
Chris@16
|
94
|
Chris@16
|
95 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
96 //
|
Chris@16
|
97 // Helper template for counting the number of leaf nodes contained in a
|
Chris@16
|
98 // given parser type.
|
Chris@16
|
99 // Only plain_parser_category type parsers are counted as leaf nodes.
|
Chris@16
|
100 //
|
Chris@16
|
101 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
102 template <typename CategoryT>
|
Chris@16
|
103 struct leafs;
|
Chris@16
|
104
|
Chris@16
|
105 template <>
|
Chris@16
|
106 struct leafs<plain_parser_category> {
|
Chris@16
|
107
|
Chris@16
|
108 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
109 struct count {
|
Chris@16
|
110
|
Chris@16
|
111 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
112 enum { value = (LeafCountT::value + 1) };
|
Chris@16
|
113 };
|
Chris@16
|
114 };
|
Chris@16
|
115
|
Chris@16
|
116 template <>
|
Chris@16
|
117 struct leafs<unary_parser_category> {
|
Chris@16
|
118
|
Chris@16
|
119 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
120 struct count {
|
Chris@16
|
121
|
Chris@16
|
122 typedef typename ParserT::subject_t subject_t;
|
Chris@16
|
123 typedef typename subject_t::parser_category_t subject_category_t;
|
Chris@16
|
124
|
Chris@16
|
125 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
126 enum { value = (leafs<subject_category_t>
|
Chris@16
|
127 ::template count<subject_t, LeafCountT>::value) };
|
Chris@16
|
128 };
|
Chris@16
|
129 };
|
Chris@16
|
130
|
Chris@16
|
131 template <>
|
Chris@16
|
132 struct leafs<action_parser_category> {
|
Chris@16
|
133
|
Chris@16
|
134 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
135 struct count {
|
Chris@16
|
136
|
Chris@16
|
137 typedef typename ParserT::subject_t subject_t;
|
Chris@16
|
138 typedef typename subject_t::parser_category_t subject_category_t;
|
Chris@16
|
139
|
Chris@16
|
140 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
141 enum { value = (leafs<subject_category_t>
|
Chris@16
|
142 ::template count<subject_t, LeafCountT>::value) };
|
Chris@16
|
143 };
|
Chris@16
|
144 };
|
Chris@16
|
145
|
Chris@16
|
146 template <>
|
Chris@16
|
147 struct leafs<binary_parser_category> {
|
Chris@16
|
148
|
Chris@16
|
149 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
150 struct count {
|
Chris@16
|
151
|
Chris@16
|
152 typedef typename ParserT::left_t left_t;
|
Chris@16
|
153 typedef typename ParserT::right_t right_t;
|
Chris@16
|
154 typedef typename left_t::parser_category_t left_category_t;
|
Chris@16
|
155 typedef typename right_t::parser_category_t right_category_t;
|
Chris@16
|
156
|
Chris@16
|
157 typedef count self_t;
|
Chris@16
|
158
|
Chris@16
|
159 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
160 enum {
|
Chris@16
|
161 leftcount = (leafs<left_category_t>
|
Chris@16
|
162 ::template count<left_t, LeafCountT>::value),
|
Chris@16
|
163 rightcount = (leafs<right_category_t>
|
Chris@16
|
164 ::template count<right_t, LeafCountT>::value),
|
Chris@16
|
165 value = (self_t::leftcount + self_t::rightcount)
|
Chris@16
|
166 };
|
Chris@16
|
167 };
|
Chris@16
|
168 };
|
Chris@16
|
169
|
Chris@16
|
170 } // namespace impl
|
Chris@16
|
171
|
Chris@16
|
172 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
173 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
|
Chris@16
|
174
|
Chris@16
|
175 }} // namespace boost::spirit
|
Chris@16
|
176
|
Chris@16
|
177 #endif // !defined(BOOST_SPIRIT_FUNDAMENTAL_IPP)
|