|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com> |
|
42 // |
|
43 // Permission is hereby granted, free of charge, to any person obtaining a copy |
|
44 // of this software and associated documentation files (the "Software"), to deal |
|
45 // in the Software without restriction, including without limitation the rights |
|
46 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
47 // copies of the Software, and to permit persons to whom the Software is |
|
48 // furnished to do so, subject to the following conditions: |
|
49 // |
|
50 // The above copyright notice and this permission notice shall be included in |
|
51 // all copies or substantial portions of the Software. |
|
52 // |
|
53 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
54 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
55 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
56 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
57 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
58 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
59 // THE SOFTWARE. |
|
60 |
|
61 #ifndef CPLUSPLUS_TOKEN_H |
|
62 #define CPLUSPLUS_TOKEN_H |
|
63 |
|
64 #include "CPlusPlusForwardDeclarations.h" |
|
65 |
|
66 namespace CPlusPlus { |
|
67 |
|
68 enum Kind { |
|
69 T_EOF_SYMBOL = 0, |
|
70 T_ERROR, |
|
71 |
|
72 T_CPP_COMMENT, |
|
73 T_CPP_DOXY_COMMENT, |
|
74 T_COMMENT, |
|
75 T_DOXY_COMMENT, |
|
76 T_IDENTIFIER, |
|
77 |
|
78 T_FIRST_LITERAL, |
|
79 T_NUMERIC_LITERAL = T_FIRST_LITERAL, |
|
80 T_CHAR_LITERAL, |
|
81 T_WIDE_CHAR_LITERAL, |
|
82 T_STRING_LITERAL, |
|
83 T_WIDE_STRING_LITERAL, |
|
84 T_AT_STRING_LITERAL, |
|
85 T_ANGLE_STRING_LITERAL, |
|
86 T_LAST_LITERAL = T_ANGLE_STRING_LITERAL, |
|
87 |
|
88 T_FIRST_OPERATOR, |
|
89 T_AMPER = T_FIRST_OPERATOR, |
|
90 T_AMPER_AMPER, |
|
91 T_AMPER_EQUAL, |
|
92 T_ARROW, |
|
93 T_ARROW_STAR, |
|
94 T_CARET, |
|
95 T_CARET_EQUAL, |
|
96 T_COLON, |
|
97 T_COLON_COLON, |
|
98 T_COMMA, |
|
99 T_SLASH, |
|
100 T_SLASH_EQUAL, |
|
101 T_DOT, |
|
102 T_DOT_DOT_DOT, |
|
103 T_DOT_STAR, |
|
104 T_EQUAL, |
|
105 T_EQUAL_EQUAL, |
|
106 T_EXCLAIM, |
|
107 T_EXCLAIM_EQUAL, |
|
108 T_GREATER, |
|
109 T_GREATER_EQUAL, |
|
110 T_GREATER_GREATER, |
|
111 T_GREATER_GREATER_EQUAL, |
|
112 T_LBRACE, |
|
113 T_LBRACKET, |
|
114 T_LESS, |
|
115 T_LESS_EQUAL, |
|
116 T_LESS_LESS, |
|
117 T_LESS_LESS_EQUAL, |
|
118 T_LPAREN, |
|
119 T_MINUS, |
|
120 T_MINUS_EQUAL, |
|
121 T_MINUS_MINUS, |
|
122 T_PERCENT, |
|
123 T_PERCENT_EQUAL, |
|
124 T_PIPE, |
|
125 T_PIPE_EQUAL, |
|
126 T_PIPE_PIPE, |
|
127 T_PLUS, |
|
128 T_PLUS_EQUAL, |
|
129 T_PLUS_PLUS, |
|
130 T_POUND, |
|
131 T_POUND_POUND, |
|
132 T_QUESTION, |
|
133 T_RBRACE, |
|
134 T_RBRACKET, |
|
135 T_RPAREN, |
|
136 T_SEMICOLON, |
|
137 T_STAR, |
|
138 T_STAR_EQUAL, |
|
139 T_TILDE, |
|
140 T_TILDE_EQUAL, |
|
141 T_LAST_OPERATOR = T_TILDE_EQUAL, |
|
142 |
|
143 T_FIRST_KEYWORD, |
|
144 T_ASM = T_FIRST_KEYWORD, |
|
145 T_AUTO, |
|
146 T_BOOL, |
|
147 T_BREAK, |
|
148 T_CASE, |
|
149 T_CATCH, |
|
150 T_CHAR, |
|
151 T_CLASS, |
|
152 T_CONST, |
|
153 T_CONST_CAST, |
|
154 T_CONTINUE, |
|
155 T_DEFAULT, |
|
156 T_DELETE, |
|
157 T_DO, |
|
158 T_DOUBLE, |
|
159 T_DYNAMIC_CAST, |
|
160 T_ELSE, |
|
161 T_ENUM, |
|
162 T_EXPLICIT, |
|
163 T_EXPORT, |
|
164 T_EXTERN, |
|
165 T_FALSE, |
|
166 T_FLOAT, |
|
167 T_FOR, |
|
168 T_FRIEND, |
|
169 T_GOTO, |
|
170 T_IF, |
|
171 T_INLINE, |
|
172 T_INT, |
|
173 T_LONG, |
|
174 T_MUTABLE, |
|
175 T_NAMESPACE, |
|
176 T_NEW, |
|
177 T_OPERATOR, |
|
178 T_PRIVATE, |
|
179 T_PROTECTED, |
|
180 T_PUBLIC, |
|
181 T_REGISTER, |
|
182 T_REINTERPRET_CAST, |
|
183 T_RETURN, |
|
184 T_SHORT, |
|
185 T_SIGNED, |
|
186 T_SIZEOF, |
|
187 T_STATIC, |
|
188 T_STATIC_CAST, |
|
189 T_STRUCT, |
|
190 T_SWITCH, |
|
191 T_TEMPLATE, |
|
192 T_THIS, |
|
193 T_THROW, |
|
194 T_TRUE, |
|
195 T_TRY, |
|
196 T_TYPEDEF, |
|
197 T_TYPEID, |
|
198 T_TYPENAME, |
|
199 T_UNION, |
|
200 T_UNSIGNED, |
|
201 T_USING, |
|
202 T_VIRTUAL, |
|
203 T_VOID, |
|
204 T_VOLATILE, |
|
205 T_WCHAR_T, |
|
206 T_WHILE, |
|
207 |
|
208 T___ATTRIBUTE__, |
|
209 T___TYPEOF__, |
|
210 |
|
211 // obj c++ @ keywords |
|
212 T_FIRST_OBJC_AT_KEYWORD, |
|
213 |
|
214 T_AT_CATCH = T_FIRST_OBJC_AT_KEYWORD, |
|
215 T_AT_CLASS, |
|
216 T_AT_COMPATIBILITY_ALIAS, |
|
217 T_AT_DEFS, |
|
218 T_AT_DYNAMIC, |
|
219 T_AT_ENCODE, |
|
220 T_AT_END, |
|
221 T_AT_FINALLY, |
|
222 T_AT_IMPLEMENTATION, |
|
223 T_AT_INTERFACE, |
|
224 T_AT_NOT_KEYWORD, |
|
225 T_AT_OPTIONAL, |
|
226 T_AT_PACKAGE, |
|
227 T_AT_PRIVATE, |
|
228 T_AT_PROPERTY, |
|
229 T_AT_PROTECTED, |
|
230 T_AT_PROTOCOL, |
|
231 T_AT_PUBLIC, |
|
232 T_AT_REQUIRED, |
|
233 T_AT_SELECTOR, |
|
234 T_AT_SYNCHRONIZED, |
|
235 T_AT_SYNTHESIZE, |
|
236 T_AT_THROW, |
|
237 T_AT_TRY, |
|
238 |
|
239 T_LAST_OBJC_AT_KEYWORD = T_AT_TRY, |
|
240 |
|
241 T_FIRST_QT_KEYWORD, |
|
242 |
|
243 // Qt keywords |
|
244 T_SIGNAL = T_FIRST_QT_KEYWORD, |
|
245 T_SLOT, |
|
246 T_Q_SIGNAL, |
|
247 T_Q_SLOT, |
|
248 T_Q_SIGNALS, |
|
249 T_Q_SLOTS, |
|
250 T_Q_FOREACH, |
|
251 T_Q_D, |
|
252 T_Q_Q, |
|
253 #ifndef ICHECK_BUILD |
|
254 T_LAST_KEYWORD = T_Q_Q, |
|
255 #else |
|
256 T_Q_INVOKABLE, |
|
257 T_Q_PROPERTY, |
|
258 T_Q_ENUMS, |
|
259 T_Q_FLAGS, |
|
260 T_Q_DECLARE_FLAGS, |
|
261 T_LAST_KEYWORD = T_Q_DECLARE_FLAGS, |
|
262 #endif |
|
263 // aliases |
|
264 T_OR = T_PIPE_PIPE, |
|
265 T_AND = T_AMPER_AMPER, |
|
266 T_NOT = T_EXCLAIM, |
|
267 T_XOR = T_CARET, |
|
268 T_BITOR = T_PIPE, |
|
269 T_COMPL = T_TILDE, |
|
270 T_OR_EQ = T_PIPE_EQUAL, |
|
271 T_AND_EQ = T_AMPER_EQUAL, |
|
272 T_BITAND = T_AMPER, |
|
273 T_NOT_EQ = T_EXCLAIM_EQUAL, |
|
274 T_XOR_EQ = T_CARET_EQUAL, |
|
275 |
|
276 T___ASM = T_ASM, |
|
277 T___ASM__ = T_ASM, |
|
278 |
|
279 T_TYPEOF = T___TYPEOF__, |
|
280 T___TYPEOF = T___TYPEOF__, |
|
281 |
|
282 T___INLINE = T_INLINE, |
|
283 T___INLINE__ = T_INLINE, |
|
284 |
|
285 T___CONST = T_CONST, |
|
286 T___CONST__ = T_CONST, |
|
287 |
|
288 T___VOLATILE = T_VOLATILE, |
|
289 T___VOLATILE__ = T_VOLATILE, |
|
290 |
|
291 T___ATTRIBUTE = T___ATTRIBUTE__ |
|
292 }; |
|
293 |
|
294 class CPLUSPLUS_EXPORT Token |
|
295 { |
|
296 public: |
|
297 Token(); |
|
298 ~Token(); |
|
299 |
|
300 inline bool is(unsigned k) const { return f.kind == k; } |
|
301 inline bool isNot(unsigned k) const { return f.kind != k; } |
|
302 const char *spell() const; |
|
303 void reset(); |
|
304 |
|
305 inline unsigned kind() const { return f.kind; } |
|
306 inline bool newline() const { return f.newline; } |
|
307 inline bool whitespace() const { return f.whitespace; } |
|
308 inline bool joined() const { return f.joined; } |
|
309 inline bool expanded() const { return f.expanded; } |
|
310 inline bool generated() const { return f.generated; } |
|
311 inline unsigned length() const { return f.length; } |
|
312 |
|
313 inline unsigned begin() const |
|
314 { return offset; } |
|
315 |
|
316 inline unsigned end() const |
|
317 { return offset + f.length; } |
|
318 |
|
319 inline bool isLiteral() const |
|
320 { return f.kind >= T_FIRST_LITERAL && f.kind <= T_LAST_LITERAL; } |
|
321 |
|
322 inline bool isOperator() const |
|
323 { return f.kind >= T_FIRST_OPERATOR && f.kind <= T_LAST_OPERATOR; } |
|
324 |
|
325 inline bool isKeyword() const |
|
326 { return f.kind >= T_FIRST_KEYWORD && f.kind < T_FIRST_QT_KEYWORD; } |
|
327 |
|
328 inline bool isComment() const |
|
329 { return f.kind == T_COMMENT || f.kind == T_DOXY_COMMENT || |
|
330 f.kind == T_CPP_COMMENT || f.kind == T_CPP_DOXY_COMMENT; } |
|
331 |
|
332 inline bool isObjCAtKeyword() const |
|
333 { return f.kind >= T_FIRST_OBJC_AT_KEYWORD && f.kind <= T_LAST_OBJC_AT_KEYWORD; } |
|
334 |
|
335 static const char *name(int kind); |
|
336 |
|
337 public: |
|
338 struct Flags { |
|
339 unsigned kind : 8; |
|
340 unsigned newline : 1; |
|
341 unsigned whitespace : 1; |
|
342 unsigned joined : 1; |
|
343 unsigned expanded : 1; |
|
344 unsigned generated : 1; |
|
345 unsigned pad : 3; |
|
346 unsigned length : 16; |
|
347 }; |
|
348 union { |
|
349 unsigned flags; |
|
350 Flags f; |
|
351 }; |
|
352 |
|
353 unsigned offset; |
|
354 |
|
355 union { |
|
356 void *ptr; |
|
357 const Literal *literal; |
|
358 const NumericLiteral *number; |
|
359 const StringLiteral *string; |
|
360 const Identifier *identifier; |
|
361 unsigned close_brace; |
|
362 unsigned lineno; |
|
363 }; |
|
364 }; |
|
365 |
|
366 } // end of namespace CPlusPlus |
|
367 |
|
368 |
|
369 #endif // CPLUSPLUS_TOKEN_H |