OSDN Git Service

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