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