Mercurial > projects > qtd
annotate generator/parser/rpp/pp-engine.h @ 414:b2a803c73b89 default tip
Declare tabArray const.
author | David Nadlinger <code@klickverbot.at> |
---|---|
date | Fri, 06 May 2011 13:39:49 +0200 |
parents | 09a0f1d048f2 |
children |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
52
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
3 ** Copyright (C) 1992-2009 Nokia. All rights reserved. |
1 | 4 ** Copyright 2005 Roberto Raggi <roberto@kdevelop.org> |
5 ** | |
6 ** This file is part of Qt Jambi. | |
7 ** | |
52
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
8 ** Commercial Usage |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
9 Licensees holding valid Qt Commercial licenses may use this file in |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
10 accordance with the Qt Commercial License Agreement provided with the |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
11 Software or, alternatively, in accordance with the terms contained in |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
12 a written agreement between you and Nokia. |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
13 |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
14 GNU Lesser General Public License Usage |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
15 Alternatively, this file may be used under the terms of the GNU Lesser |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
16 General Public License version 2.1 as published by the Free Software |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
17 Foundation and appearing in the file LICENSE.LGPL included in the |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
18 packaging of this file. Please review the following information to |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
19 ensure the GNU Lesser General Public License version 2.1 requirements |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
20 will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
21 |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
22 In addition, as a special exception, Nokia gives you certain |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
23 additional rights. These rights are described in the Nokia Qt LGPL |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
24 Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
25 package. |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
26 |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
27 GNU General Public License Usage |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
28 Alternatively, this file may be used under the terms of the GNU |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
29 General Public License version 3.0 as published by the Free Software |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
30 Foundation and appearing in the file LICENSE.GPL included in the |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
31 packaging of this file. Please review the following information to |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
32 ensure the GNU General Public License version 3.0 requirements will be |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
33 met: http://www.gnu.org/copyleft/gpl.html. |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
34 |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
35 If you are unsure which license is appropriate for your use, please |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
36 contact the sales department at qt-sales@nokia.com. |
1 | 37 |
38 ** | |
39 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
40 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
41 ** | |
42 ****************************************************************************/ | |
43 | |
44 #ifndef PP_ENGINE_H | |
45 #define PP_ENGINE_H | |
46 | |
47 namespace rpp { | |
48 | |
49 struct Value | |
50 { | |
51 enum Kind { | |
52 Kind_Long, | |
53 Kind_ULong, | |
54 }; | |
55 | |
56 Kind kind; | |
57 | |
58 union { | |
59 long l; | |
60 unsigned long ul; | |
61 }; | |
62 | |
63 inline bool is_ulong () const { return kind == Kind_ULong; } | |
64 | |
65 inline void set_ulong (unsigned long v) | |
66 { | |
67 ul = v; | |
68 kind = Kind_ULong; | |
69 } | |
70 | |
71 inline void set_long (long v) | |
72 { | |
73 l = v; | |
74 kind = Kind_Long; | |
75 } | |
76 | |
77 inline bool is_zero () const { return l == 0; } | |
78 | |
79 #define PP_DEFINE_BIN_OP(name, op) \ | |
80 inline Value &name (const Value &other) \ | |
81 { \ | |
82 if (is_ulong () || other.is_ulong ()) \ | |
83 set_ulong (ul op other.ul); \ | |
84 else \ | |
85 set_long (l op other.l); \ | |
86 return *this; \ | |
87 } | |
88 | |
89 PP_DEFINE_BIN_OP(op_add, +) | |
90 PP_DEFINE_BIN_OP(op_sub, -) | |
91 PP_DEFINE_BIN_OP(op_mult, *) | |
92 PP_DEFINE_BIN_OP(op_div, /) | |
93 PP_DEFINE_BIN_OP(op_mod, %) | |
94 PP_DEFINE_BIN_OP(op_lhs, <<) | |
95 PP_DEFINE_BIN_OP(op_rhs, >>) | |
96 PP_DEFINE_BIN_OP(op_lt, <) | |
97 PP_DEFINE_BIN_OP(op_gt, >) | |
98 PP_DEFINE_BIN_OP(op_le, <=) | |
99 PP_DEFINE_BIN_OP(op_ge, >=) | |
100 PP_DEFINE_BIN_OP(op_eq, ==) | |
101 PP_DEFINE_BIN_OP(op_ne, !=) | |
102 PP_DEFINE_BIN_OP(op_bit_and, &) | |
103 PP_DEFINE_BIN_OP(op_bit_or, |) | |
104 PP_DEFINE_BIN_OP(op_bit_xor, ^) | |
105 PP_DEFINE_BIN_OP(op_and, &&) | |
106 PP_DEFINE_BIN_OP(op_or, ||) | |
107 | |
108 #undef PP_DEFINE_BIN_OP | |
109 }; | |
110 | |
111 class pp | |
112 { | |
113 pp_environment &env; | |
114 pp_macro_expander expand; | |
115 pp_skip_identifier skip_identifier; | |
116 pp_skip_comment_or_divop skip_comment_or_divop; | |
117 pp_skip_blanks skip_blanks; | |
118 pp_skip_number skip_number; | |
119 std::vector<std::string> include_paths; | |
120 std::string _M_current_text; | |
121 | |
122 enum { MAX_LEVEL = 512 }; | |
123 int _M_skipping[MAX_LEVEL]; | |
124 int _M_true_test[MAX_LEVEL]; | |
125 int iflevel; | |
126 | |
127 union | |
128 { | |
129 long token_value; | |
130 unsigned long token_uvalue; | |
131 std::string *token_text; | |
132 }; | |
133 | |
134 enum INCLUDE_POLICY | |
135 { | |
136 INCLUDE_GLOBAL, | |
137 INCLUDE_LOCAL | |
138 }; | |
139 | |
140 enum TOKEN_TYPE | |
141 { | |
142 TOKEN_NUMBER = 1000, | |
143 TOKEN_UNUMBER, | |
144 TOKEN_IDENTIFIER, | |
145 TOKEN_DEFINED, | |
146 TOKEN_LT_LT, | |
147 TOKEN_LT_EQ, | |
148 TOKEN_GT_GT, | |
149 TOKEN_GT_EQ, | |
150 TOKEN_EQ_EQ, | |
151 TOKEN_NOT_EQ, | |
152 TOKEN_OR_OR, | |
153 TOKEN_AND_AND, | |
154 }; | |
155 | |
156 enum PP_DIRECTIVE_TYPE | |
157 { | |
158 PP_UNKNOWN_DIRECTIVE, | |
159 PP_DEFINE, | |
160 PP_INCLUDE, | |
161 PP_INCLUDE_NEXT, | |
162 PP_ELIF, | |
163 PP_ELSE, | |
164 PP_ENDIF, | |
165 PP_IF, | |
166 PP_IFDEF, | |
167 PP_IFNDEF, | |
168 PP_UNDEF, | |
169 PP_PRAGMA, | |
52
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
170 PP_ERROR, |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
171 PP_WARNING |
1 | 172 }; |
173 | |
174 public: | |
175 pp (pp_environment &__env); | |
176 | |
177 inline std::back_insert_iterator<std::vector<std::string> > include_paths_inserter (); | |
178 | |
179 inline void push_include_path (std::string const &__path); | |
180 | |
181 inline std::vector<std::string>::iterator include_paths_begin (); | |
182 inline std::vector<std::string>::iterator include_paths_end (); | |
183 | |
184 inline std::vector<std::string>::const_iterator include_paths_begin () const; | |
185 inline std::vector<std::string>::const_iterator include_paths_end () const; | |
186 | |
187 template <typename _InputIterator> | |
188 inline _InputIterator eval_expression (_InputIterator __first, _InputIterator __last, Value *result); | |
189 | |
190 template <typename _OutputIterator> | |
191 void file (std::string const &filename, _OutputIterator __result); | |
192 | |
193 template <typename _OutputIterator> | |
194 void file (FILE *fp, _OutputIterator __result); | |
195 | |
196 template <typename _InputIterator, typename _OutputIterator> | |
197 void operator () (_InputIterator __first, _InputIterator __last, _OutputIterator __result); | |
198 | |
199 private: | |
200 inline bool file_isdir (std::string const &__filename) const; | |
201 inline bool file_exists (std::string const &__filename) const; | |
202 FILE *find_include_file (std::string const &__filename, std::string *__filepath, | |
203 INCLUDE_POLICY __include_policy, bool __skip_current_path = false) const; | |
204 | |
205 inline int skipping() const; | |
206 bool test_if_level(); | |
207 | |
208 inline std::string fix_file_path (std::string const &filename) const; | |
209 inline bool is_absolute (std::string const &filename) const; | |
210 | |
211 PP_DIRECTIVE_TYPE find_directive (char const *__directive, std::size_t __size) const; | |
212 | |
213 template <typename _InputIterator> | |
214 bool find_header_protection (_InputIterator __first, _InputIterator __last, std::string *__prot); | |
215 | |
216 template <typename _InputIterator> | |
217 _InputIterator skip (_InputIterator __first, _InputIterator __last); | |
218 | |
219 template <typename _InputIterator> | |
220 _InputIterator eval_primary(_InputIterator __first, _InputIterator __last, Value *result); | |
221 | |
222 template <typename _InputIterator> | |
223 _InputIterator eval_multiplicative(_InputIterator __first, _InputIterator __last, Value *result); | |
224 | |
225 template <typename _InputIterator> | |
226 _InputIterator eval_additive(_InputIterator __first, _InputIterator __last, Value *result); | |
227 | |
228 template <typename _InputIterator> | |
229 _InputIterator eval_shift(_InputIterator __first, _InputIterator __last, Value *result); | |
230 | |
231 template <typename _InputIterator> | |
232 _InputIterator eval_relational(_InputIterator __first, _InputIterator __last, Value *result); | |
233 | |
234 template <typename _InputIterator> | |
235 _InputIterator eval_equality(_InputIterator __first, _InputIterator __last, Value *result); | |
236 | |
237 template <typename _InputIterator> | |
238 _InputIterator eval_and(_InputIterator __first, _InputIterator __last, Value *result); | |
239 | |
240 template <typename _InputIterator> | |
241 _InputIterator eval_xor(_InputIterator __first, _InputIterator __last, Value *result); | |
242 | |
243 template <typename _InputIterator> | |
244 _InputIterator eval_or(_InputIterator __first, _InputIterator __last, Value *result); | |
245 | |
246 template <typename _InputIterator> | |
247 _InputIterator eval_logical_and(_InputIterator __first, _InputIterator __last, Value *result); | |
248 | |
249 template <typename _InputIterator> | |
250 _InputIterator eval_logical_or(_InputIterator __first, _InputIterator __last, Value *result); | |
251 | |
252 template <typename _InputIterator> | |
253 _InputIterator eval_constant_expression(_InputIterator __first, _InputIterator __last, Value *result); | |
254 | |
255 template <typename _InputIterator, typename _OutputIterator> | |
256 _InputIterator handle_directive(char const *__directive, std::size_t __size, | |
257 _InputIterator __first, _InputIterator __last, _OutputIterator __result); | |
258 | |
259 template <typename _InputIterator, typename _OutputIterator> | |
260 _InputIterator handle_include(bool skip_current_path, _InputIterator __first, _InputIterator __last, | |
261 _OutputIterator __result); | |
262 | |
263 template <typename _InputIterator> | |
264 _InputIterator handle_define (_InputIterator __first, _InputIterator __last); | |
265 | |
266 template <typename _InputIterator> | |
267 _InputIterator handle_if (_InputIterator __first, _InputIterator __last); | |
268 | |
269 template <typename _InputIterator> | |
270 _InputIterator handle_else (_InputIterator __first, _InputIterator __last); | |
271 | |
272 template <typename _InputIterator> | |
273 _InputIterator handle_elif (_InputIterator __first, _InputIterator __last); | |
274 | |
275 template <typename _InputIterator> | |
276 _InputIterator handle_endif (_InputIterator __first, _InputIterator __last); | |
277 | |
278 template <typename _InputIterator> | |
279 _InputIterator handle_ifdef (bool check_undefined, _InputIterator __first, _InputIterator __last); | |
280 | |
281 template <typename _InputIterator> | |
282 _InputIterator handle_undef(_InputIterator __first, _InputIterator __last); | |
283 | |
284 template <typename _InputIterator> | |
285 inline char peek_char (_InputIterator __first, _InputIterator __last); | |
286 | |
287 template <typename _InputIterator> | |
288 _InputIterator next_token (_InputIterator __first, _InputIterator __last, int *kind); | |
289 }; | |
290 | |
291 } // namespace rpp | |
292 | |
293 #endif // PP_ENGINE_H | |
294 | |
295 // kate: space-indent on; indent-width 2; replace-tabs on; |