Mercurial > projects > qtd
annotate generator/parser/rpp/pp-scanner.h @ 382:1d56b2a2e10c
Fixes to debugging stuff. Added size_t as primitive type to workaround Qwt build failure in debug
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Mon, 12 Jul 2010 20:36:07 +0300 |
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_SCANNER_H | |
45 #define PP_SCANNER_H | |
46 | |
47 namespace rpp { | |
48 | |
49 struct pp_skip_blanks | |
50 { | |
51 int lines; | |
52 | |
53 template <typename _InputIterator> | |
54 _InputIterator operator () (_InputIterator __first, _InputIterator __last) | |
55 { | |
56 lines = 0; | |
57 | |
58 for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) | |
59 { | |
60 if (*__first == '\\') | |
61 { | |
62 _InputIterator __begin = __first; | |
63 ++__begin; | |
64 | |
65 if (__begin != __last && *__begin == '\n') | |
66 ++__first; | |
67 else | |
68 break; | |
69 } | |
70 else if (*__first == '\n' || !pp_isspace (*__first)) | |
71 break; | |
72 } | |
73 | |
74 return __first; | |
75 } | |
76 }; | |
77 | |
78 struct pp_skip_whitespaces | |
79 { | |
80 int lines; | |
81 | |
82 template <typename _InputIterator> | |
83 _InputIterator operator () (_InputIterator __first, _InputIterator __last) | |
84 { | |
85 lines = 0; | |
86 | |
87 for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) | |
88 { | |
89 if (! pp_isspace (*__first)) | |
90 break; | |
91 } | |
92 | |
93 return __first; | |
94 } | |
95 }; | |
96 | |
97 struct pp_skip_comment_or_divop | |
98 { | |
99 int lines; | |
100 | |
101 template <typename _InputIterator> | |
102 _InputIterator operator () (_InputIterator __first, _InputIterator __last) | |
103 { | |
104 enum { | |
105 MAYBE_BEGIN, | |
106 BEGIN, | |
107 MAYBE_END, | |
108 END, | |
109 IN_COMMENT, | |
110 IN_CXX_COMMENT | |
111 } state (MAYBE_BEGIN); | |
112 | |
113 lines = 0; | |
114 | |
115 for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) | |
116 { | |
117 switch (state) | |
118 { | |
119 default: | |
120 assert (0); | |
121 break; | |
122 | |
123 case MAYBE_BEGIN: | |
124 if (*__first != '/') | |
125 return __first; | |
126 | |
127 state = BEGIN; | |
128 break; | |
129 | |
130 case BEGIN: | |
131 if (*__first == '*') | |
132 state = IN_COMMENT; | |
133 else if (*__first == '/') | |
134 state = IN_CXX_COMMENT; | |
135 else | |
136 return __first; | |
137 break; | |
138 | |
139 case IN_COMMENT: | |
140 if (*__first == '*') | |
141 state = MAYBE_END; | |
142 break; | |
143 | |
144 case IN_CXX_COMMENT: | |
145 if (*__first == '\n') | |
146 return __first; | |
147 break; | |
148 | |
149 case MAYBE_END: | |
150 if (*__first == '/') | |
151 state = END; | |
152 else if (*__first != '*') | |
153 state = IN_COMMENT; | |
154 break; | |
155 | |
156 case END: | |
157 return __first; | |
158 } | |
159 } | |
160 | |
161 return __first; | |
162 } | |
163 }; | |
164 | |
165 struct pp_skip_identifier | |
166 { | |
167 int lines; | |
168 | |
169 template <typename _InputIterator> | |
170 _InputIterator operator () (_InputIterator __first, _InputIterator __last) | |
171 { | |
172 lines = 0; | |
173 | |
174 for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) | |
175 { | |
176 if (! pp_isalnum (*__first) && *__first != '_') | |
177 break; | |
178 } | |
179 | |
180 return __first; | |
181 } | |
182 }; | |
183 | |
184 struct pp_skip_number | |
185 { | |
186 int lines; | |
187 | |
188 template <typename _InputIterator> | |
189 _InputIterator operator () (_InputIterator __first, _InputIterator __last) | |
190 { | |
191 lines = 0; | |
192 | |
193 for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) | |
194 { | |
195 if (! pp_isalnum (*__first) && *__first != '.') | |
196 break; | |
197 } | |
198 | |
199 return __first; | |
200 } | |
201 }; | |
202 | |
203 struct pp_skip_string_literal | |
204 { | |
205 int lines; | |
206 | |
207 template <typename _InputIterator> | |
208 _InputIterator operator () (_InputIterator __first, _InputIterator __last) | |
209 { | |
210 enum { | |
211 BEGIN, | |
212 IN_STRING, | |
213 QUOTE, | |
214 END | |
215 } state (BEGIN); | |
216 | |
217 lines = 0; | |
218 | |
219 for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) | |
220 { | |
221 switch (state) | |
222 { | |
223 default: | |
224 assert (0); | |
225 break; | |
226 | |
227 case BEGIN: | |
228 if (*__first != '\"') | |
229 return __first; | |
230 state = IN_STRING; | |
231 break; | |
232 | |
233 case IN_STRING: | |
234 assert (*__first != '\n'); | |
235 | |
236 if (*__first == '\"') | |
237 state = END; | |
238 else if (*__first == '\\') | |
239 state = QUOTE; | |
240 break; | |
241 | |
242 case QUOTE: | |
243 state = IN_STRING; | |
244 break; | |
245 | |
246 case END: | |
247 return __first; | |
248 } | |
249 } | |
250 | |
251 return __first; | |
252 } | |
253 }; | |
254 | |
255 struct pp_skip_char_literal | |
256 { | |
257 int lines; | |
258 | |
259 template <typename _InputIterator> | |
260 _InputIterator operator () (_InputIterator __first, _InputIterator __last) | |
261 { | |
262 enum { | |
263 BEGIN, | |
264 IN_STRING, | |
265 QUOTE, | |
266 END | |
267 } state (BEGIN); | |
268 | |
269 lines = 0; | |
270 | |
271 for (; state != END && __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) | |
272 { | |
273 switch (state) | |
274 { | |
275 default: | |
276 assert (0); | |
277 break; | |
278 | |
279 case BEGIN: | |
280 if (*__first != '\'') | |
281 return __first; | |
282 state = IN_STRING; | |
283 break; | |
284 | |
285 case IN_STRING: | |
286 assert (*__first != '\n'); | |
287 | |
288 if (*__first == '\'') | |
289 state = END; | |
290 else if (*__first == '\\') | |
291 state = QUOTE; | |
292 break; | |
293 | |
294 case QUOTE: | |
295 state = IN_STRING; | |
296 break; | |
297 } | |
298 } | |
299 | |
300 return __first; | |
301 } | |
302 }; | |
303 | |
304 struct pp_skip_argument | |
305 { | |
306 pp_skip_identifier skip_number; | |
307 pp_skip_identifier skip_identifier; | |
308 pp_skip_string_literal skip_string_literal; | |
309 pp_skip_char_literal skip_char_literal; | |
310 pp_skip_comment_or_divop skip_comment_or_divop; | |
311 int lines; | |
312 | |
313 template <typename _InputIterator> | |
314 _InputIterator operator () (_InputIterator __first, _InputIterator __last) | |
315 { | |
316 int depth = 0; | |
317 lines = 0; | |
318 | |
319 while (__first != __last) | |
320 { | |
321 if (!depth && (*__first == ')' || *__first == ',')) | |
322 break; | |
323 else if (*__first == '(') | |
324 ++depth, ++__first; | |
325 else if (*__first == ')') | |
326 --depth, ++__first; | |
327 else if (*__first == '\"') | |
328 { | |
329 __first = skip_string_literal (__first, __last); | |
330 lines += skip_string_literal.lines; | |
331 } | |
332 else if (*__first == '\'') | |
333 { | |
334 __first = skip_char_literal (__first, __last); | |
335 lines += skip_char_literal.lines; | |
336 } | |
337 else if (*__first == '/') | |
338 { | |
339 __first = skip_comment_or_divop (__first, __last); | |
340 lines += skip_comment_or_divop.lines; | |
341 } | |
342 else if (pp_isalpha (*__first) || *__first == '_') | |
343 { | |
344 __first = skip_identifier (__first, __last); | |
345 lines += skip_identifier.lines; | |
346 } | |
347 else if (pp_isdigit (*__first)) | |
348 { | |
349 __first = skip_number (__first, __last); | |
350 lines += skip_number.lines; | |
351 } | |
352 else if (*__first == '\n') | |
353 { | |
354 ++__first; | |
355 ++lines; | |
356 } | |
357 else | |
358 ++__first; | |
359 } | |
360 | |
361 return __first; | |
362 } | |
363 }; | |
364 | |
365 } // namespace rpp | |
366 | |
367 #endif // PP_SCANNER_H | |
368 | |
369 // kate: space-indent on; indent-width 2; replace-tabs on; |