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 #if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
|
Chris@16
|
19 BOOST_SPIRIT_DEPENDENT_TEMPLATE_WRAPPER2(count_wrapper, count);
|
Chris@16
|
20 #endif // defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
|
Chris@16
|
21
|
Chris@16
|
22 namespace impl
|
Chris@16
|
23 {
|
Chris@16
|
24 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
25 //
|
Chris@16
|
26 // Helper template for counting the number of nodes contained in a
|
Chris@16
|
27 // given parser type.
|
Chris@16
|
28 // All parser_category type parsers are counted as nodes.
|
Chris@16
|
29 //
|
Chris@16
|
30 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
31 template <typename CategoryT>
|
Chris@16
|
32 struct nodes;
|
Chris@16
|
33
|
Chris@16
|
34 template <>
|
Chris@16
|
35 struct nodes<plain_parser_category> {
|
Chris@16
|
36
|
Chris@16
|
37 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
38 struct count {
|
Chris@16
|
39
|
Chris@16
|
40 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
41 enum { value = (LeafCountT::value + 1) };
|
Chris@16
|
42 };
|
Chris@16
|
43 };
|
Chris@16
|
44
|
Chris@16
|
45 #if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
|
Chris@16
|
46
|
Chris@16
|
47 template <>
|
Chris@16
|
48 struct nodes<unary_parser_category> {
|
Chris@16
|
49
|
Chris@16
|
50 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
51 struct count {
|
Chris@16
|
52
|
Chris@16
|
53 typedef typename ParserT::subject_t subject_t;
|
Chris@16
|
54 typedef typename subject_t::parser_category_t subject_category_t;
|
Chris@16
|
55
|
Chris@16
|
56 typedef nodes<subject_category_t> nodes_t;
|
Chris@16
|
57 typedef typename count_wrapper<nodes_t>
|
Chris@16
|
58 ::template result_<subject_t, LeafCountT> count_t;
|
Chris@16
|
59
|
Chris@16
|
60 BOOST_STATIC_CONSTANT(int, value = count_t::value + 1);
|
Chris@16
|
61 };
|
Chris@16
|
62 };
|
Chris@16
|
63
|
Chris@16
|
64 template <>
|
Chris@16
|
65 struct nodes<action_parser_category> {
|
Chris@16
|
66
|
Chris@16
|
67 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
68 struct count {
|
Chris@16
|
69
|
Chris@16
|
70 typedef typename ParserT::subject_t subject_t;
|
Chris@16
|
71 typedef typename subject_t::parser_category_t subject_category_t;
|
Chris@16
|
72
|
Chris@16
|
73 typedef nodes<subject_category_t> nodes_t;
|
Chris@16
|
74 typedef typename count_wrapper<nodes_t>
|
Chris@16
|
75 ::template result_<subject_t, LeafCountT> count_t;
|
Chris@16
|
76
|
Chris@16
|
77 BOOST_STATIC_CONSTANT(int, value = count_t::value + 1);
|
Chris@16
|
78 };
|
Chris@16
|
79 };
|
Chris@16
|
80
|
Chris@16
|
81 template <>
|
Chris@16
|
82 struct nodes<binary_parser_category> {
|
Chris@16
|
83
|
Chris@16
|
84 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
85 struct count {
|
Chris@16
|
86
|
Chris@16
|
87 typedef typename ParserT::left_t left_t;
|
Chris@16
|
88 typedef typename ParserT::right_t right_t;
|
Chris@16
|
89 typedef typename left_t::parser_category_t left_category_t;
|
Chris@16
|
90 typedef typename right_t::parser_category_t right_category_t;
|
Chris@16
|
91
|
Chris@16
|
92 typedef nodes<left_category_t> left_nodes_t;
|
Chris@16
|
93 typedef typename count_wrapper<left_nodes_t>
|
Chris@16
|
94 ::template result_<left_t, LeafCountT> left_count_t;
|
Chris@16
|
95
|
Chris@16
|
96 typedef nodes<right_category_t> right_nodes_t;
|
Chris@16
|
97 typedef typename count_wrapper<right_nodes_t>
|
Chris@16
|
98 ::template result_<right_t, LeafCountT> right_count_t;
|
Chris@16
|
99
|
Chris@16
|
100 BOOST_STATIC_CONSTANT(int,
|
Chris@16
|
101 value = (left_count_t::value + right_count_t::value + 1));
|
Chris@16
|
102 };
|
Chris@16
|
103 };
|
Chris@16
|
104
|
Chris@16
|
105 #else
|
Chris@16
|
106
|
Chris@16
|
107 template <>
|
Chris@16
|
108 struct nodes<unary_parser_category> {
|
Chris@16
|
109
|
Chris@16
|
110 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
111 struct count {
|
Chris@16
|
112
|
Chris@16
|
113 typedef typename ParserT::subject_t subject_t;
|
Chris@16
|
114 typedef typename subject_t::parser_category_t subject_category_t;
|
Chris@16
|
115
|
Chris@16
|
116 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
117 enum { value = (nodes<subject_category_t>
|
Chris@16
|
118 ::template count<subject_t, LeafCountT>::value + 1) };
|
Chris@16
|
119 };
|
Chris@16
|
120 };
|
Chris@16
|
121
|
Chris@16
|
122 template <>
|
Chris@16
|
123 struct nodes<action_parser_category> {
|
Chris@16
|
124
|
Chris@16
|
125 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
126 struct count {
|
Chris@16
|
127
|
Chris@16
|
128 typedef typename ParserT::subject_t subject_t;
|
Chris@16
|
129 typedef typename subject_t::parser_category_t subject_category_t;
|
Chris@16
|
130
|
Chris@16
|
131 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
132 enum { value = (nodes<subject_category_t>
|
Chris@16
|
133 ::template count<subject_t, LeafCountT>::value + 1) };
|
Chris@16
|
134 };
|
Chris@16
|
135 };
|
Chris@16
|
136
|
Chris@16
|
137 template <>
|
Chris@16
|
138 struct nodes<binary_parser_category> {
|
Chris@16
|
139
|
Chris@16
|
140 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
141 struct count {
|
Chris@16
|
142
|
Chris@16
|
143 typedef typename ParserT::left_t left_t;
|
Chris@16
|
144 typedef typename ParserT::right_t right_t;
|
Chris@16
|
145 typedef typename left_t::parser_category_t left_category_t;
|
Chris@16
|
146 typedef typename right_t::parser_category_t right_category_t;
|
Chris@16
|
147
|
Chris@16
|
148 typedef count self_t;
|
Chris@16
|
149
|
Chris@16
|
150 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
151 enum {
|
Chris@16
|
152 leftcount = (nodes<left_category_t>
|
Chris@16
|
153 ::template count<left_t, LeafCountT>::value),
|
Chris@16
|
154 rightcount = (nodes<right_category_t>
|
Chris@16
|
155 ::template count<right_t, LeafCountT>::value),
|
Chris@16
|
156 value = ((self_t::leftcount) + (self_t::rightcount) + 1)
|
Chris@16
|
157 };
|
Chris@16
|
158 };
|
Chris@16
|
159 };
|
Chris@16
|
160
|
Chris@16
|
161 #endif
|
Chris@16
|
162
|
Chris@16
|
163 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
164 //
|
Chris@16
|
165 // Helper template for counting the number of leaf nodes contained in a
|
Chris@16
|
166 // given parser type.
|
Chris@16
|
167 // Only plain_parser_category type parsers are counted as leaf nodes.
|
Chris@16
|
168 //
|
Chris@16
|
169 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
170 template <typename CategoryT>
|
Chris@16
|
171 struct leafs;
|
Chris@16
|
172
|
Chris@16
|
173 template <>
|
Chris@16
|
174 struct leafs<plain_parser_category> {
|
Chris@16
|
175
|
Chris@16
|
176 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
177 struct count {
|
Chris@16
|
178
|
Chris@16
|
179 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
180 enum { value = (LeafCountT::value + 1) };
|
Chris@16
|
181 };
|
Chris@16
|
182 };
|
Chris@16
|
183
|
Chris@16
|
184 #if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
|
Chris@16
|
185
|
Chris@16
|
186 template <>
|
Chris@16
|
187 struct leafs<unary_parser_category> {
|
Chris@16
|
188
|
Chris@16
|
189 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
190 struct count {
|
Chris@16
|
191
|
Chris@16
|
192 typedef typename ParserT::subject_t subject_t;
|
Chris@16
|
193 typedef typename subject_t::parser_category_t subject_category_t;
|
Chris@16
|
194
|
Chris@16
|
195 typedef leafs<subject_category_t> nodes_t;
|
Chris@16
|
196 typedef typename count_wrapper<nodes_t>
|
Chris@16
|
197 ::template result_<subject_t, LeafCountT> count_t;
|
Chris@16
|
198
|
Chris@16
|
199 BOOST_STATIC_CONSTANT(int, value = count_t::value);
|
Chris@16
|
200 };
|
Chris@16
|
201 };
|
Chris@16
|
202
|
Chris@16
|
203 template <>
|
Chris@16
|
204 struct leafs<action_parser_category> {
|
Chris@16
|
205
|
Chris@16
|
206 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
207 struct count {
|
Chris@16
|
208
|
Chris@16
|
209 typedef typename ParserT::subject_t subject_t;
|
Chris@16
|
210 typedef typename subject_t::parser_category_t subject_category_t;
|
Chris@16
|
211
|
Chris@16
|
212 typedef leafs<subject_category_t> nodes_t;
|
Chris@16
|
213 typedef typename count_wrapper<nodes_t>
|
Chris@16
|
214 ::template result_<subject_t, LeafCountT> count_t;
|
Chris@16
|
215
|
Chris@16
|
216 BOOST_STATIC_CONSTANT(int, value = count_t::value);
|
Chris@16
|
217 };
|
Chris@16
|
218 };
|
Chris@16
|
219
|
Chris@16
|
220 template <>
|
Chris@16
|
221 struct leafs<binary_parser_category> {
|
Chris@16
|
222
|
Chris@16
|
223 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
224 struct count {
|
Chris@16
|
225
|
Chris@16
|
226 typedef typename ParserT::left_t left_t;
|
Chris@16
|
227 typedef typename ParserT::right_t right_t;
|
Chris@16
|
228 typedef typename left_t::parser_category_t left_category_t;
|
Chris@16
|
229 typedef typename right_t::parser_category_t right_category_t;
|
Chris@16
|
230
|
Chris@16
|
231 typedef leafs<left_category_t> left_nodes_t;
|
Chris@16
|
232 typedef typename count_wrapper<left_nodes_t>
|
Chris@16
|
233 ::template result_<left_t, LeafCountT> left_count_t;
|
Chris@16
|
234
|
Chris@16
|
235 typedef leafs<right_category_t> right_nodes_t;
|
Chris@16
|
236 typedef typename count_wrapper<right_nodes_t>
|
Chris@16
|
237 ::template result_<right_t, LeafCountT> right_count_t;
|
Chris@16
|
238
|
Chris@16
|
239 BOOST_STATIC_CONSTANT(int,
|
Chris@16
|
240 value = (left_count_t::value + right_count_t::value));
|
Chris@16
|
241 };
|
Chris@16
|
242 };
|
Chris@16
|
243
|
Chris@16
|
244 #else
|
Chris@16
|
245
|
Chris@16
|
246 template <>
|
Chris@16
|
247 struct leafs<unary_parser_category> {
|
Chris@16
|
248
|
Chris@16
|
249 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
250 struct count {
|
Chris@16
|
251
|
Chris@16
|
252 typedef typename ParserT::subject_t subject_t;
|
Chris@16
|
253 typedef typename subject_t::parser_category_t subject_category_t;
|
Chris@16
|
254
|
Chris@16
|
255 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
256 enum { value = (leafs<subject_category_t>
|
Chris@16
|
257 ::template count<subject_t, LeafCountT>::value) };
|
Chris@16
|
258 };
|
Chris@16
|
259 };
|
Chris@16
|
260
|
Chris@16
|
261 template <>
|
Chris@16
|
262 struct leafs<action_parser_category> {
|
Chris@16
|
263
|
Chris@16
|
264 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
265 struct count {
|
Chris@16
|
266
|
Chris@16
|
267 typedef typename ParserT::subject_t subject_t;
|
Chris@16
|
268 typedef typename subject_t::parser_category_t subject_category_t;
|
Chris@16
|
269
|
Chris@16
|
270 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
271 enum { value = (leafs<subject_category_t>
|
Chris@16
|
272 ::template count<subject_t, LeafCountT>::value) };
|
Chris@16
|
273 };
|
Chris@16
|
274 };
|
Chris@16
|
275
|
Chris@16
|
276 template <>
|
Chris@16
|
277 struct leafs<binary_parser_category> {
|
Chris@16
|
278
|
Chris@16
|
279 template <typename ParserT, typename LeafCountT>
|
Chris@16
|
280 struct count {
|
Chris@16
|
281
|
Chris@16
|
282 typedef typename ParserT::left_t left_t;
|
Chris@16
|
283 typedef typename ParserT::right_t right_t;
|
Chris@16
|
284 typedef typename left_t::parser_category_t left_category_t;
|
Chris@16
|
285 typedef typename right_t::parser_category_t right_category_t;
|
Chris@16
|
286
|
Chris@16
|
287 typedef count self_t;
|
Chris@16
|
288
|
Chris@16
|
289 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
|
Chris@16
|
290 enum {
|
Chris@16
|
291 leftcount = (leafs<left_category_t>
|
Chris@16
|
292 ::template count<left_t, LeafCountT>::value),
|
Chris@16
|
293 rightcount = (leafs<right_category_t>
|
Chris@16
|
294 ::template count<right_t, LeafCountT>::value),
|
Chris@16
|
295 value = (self_t::leftcount + self_t::rightcount)
|
Chris@16
|
296 };
|
Chris@16
|
297 };
|
Chris@16
|
298 };
|
Chris@16
|
299
|
Chris@16
|
300 #endif
|
Chris@16
|
301
|
Chris@16
|
302 } // namespace impl
|
Chris@16
|
303
|
Chris@16
|
304 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
305 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
|
Chris@16
|
306
|
Chris@16
|
307 }} // namespace boost::spirit
|
Chris@16
|
308
|
Chris@16
|
309 #endif // !defined(BOOST_SPIRIT_FUNDAMENTAL_IPP)
|