|
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 #include "Token.h" |
|
62 #include "Literals.h" |
|
63 |
|
64 using namespace CPlusPlus; |
|
65 |
|
66 static const char *token_names[] = { |
|
67 (""), ("<error>"), |
|
68 |
|
69 ("<C++ comment>"), ("<C++ doxy comment>"), |
|
70 ("<comment>"), ("<doxy comment>"), |
|
71 |
|
72 ("<identifier>"), ("<numeric literal>"), ("<char literal>"), |
|
73 ("<wide char literal>"), ("<string literal>"), ("<wide char literal>"), |
|
74 ("<@string literal>"), ("<angle string literal>"), |
|
75 |
|
76 ("&"), ("&&"), ("&="), ("->"), ("->*"), ("^"), ("^="), (":"), ("::"), |
|
77 (","), ("/"), ("/="), ("."), ("..."), (".*"), ("="), ("=="), ("!"), |
|
78 ("!="), (">"), (">="), (">>"), (">>="), ("{"), ("["), ("<"), ("<="), |
|
79 ("<<"), ("<<="), ("("), ("-"), ("-="), ("--"), ("%"), ("%="), ("|"), |
|
80 ("|="), ("||"), ("+"), ("+="), ("++"), ("#"), ("##"), ("?"), ("}"), |
|
81 ("]"), (")"), (";"), ("*"), ("*="), ("~"), ("~="), |
|
82 |
|
83 ("asm"), ("auto"), ("bool"), ("break"), ("case"), ("catch"), ("char"), |
|
84 ("class"), ("const"), ("const_cast"), ("continue"), ("default"), |
|
85 ("delete"), ("do"), ("double"), ("dynamic_cast"), ("else"), ("enum"), |
|
86 ("explicit"), ("export"), ("extern"), ("false"), ("float"), ("for"), |
|
87 ("friend"), ("goto"), ("if"), ("inline"), ("int"), ("long"), |
|
88 ("mutable"), ("namespace"), ("new"), ("operator"), ("private"), |
|
89 ("protected"), ("public"), ("register"), ("reinterpret_cast"), |
|
90 ("return"), ("short"), ("signed"), ("sizeof"), ("static"), |
|
91 ("static_cast"), ("struct"), ("switch"), ("template"), ("this"), |
|
92 ("throw"), ("true"), ("try"), ("typedef"), ("typeid"), ("typename"), |
|
93 ("union"), ("unsigned"), ("using"), ("virtual"), ("void"), |
|
94 ("volatile"), ("wchar_t"), ("while"), |
|
95 |
|
96 // gnu |
|
97 ("__attribute__"), ("__typeof__"), |
|
98 |
|
99 // objc @keywords |
|
100 ("@catch"), ("@class"), ("@compatibility_alias"), ("@defs"), ("@dynamic"), |
|
101 ("@encode"), ("@end"), ("@finally"), ("@implementation"), ("@interface"), |
|
102 ("@not_keyword"), ("@optional"), ("@package"), ("@private"), ("@property"), |
|
103 ("@protected"), ("@protocol"), ("@public"), ("@required"), ("@selector"), |
|
104 ("@synchronized"), ("@synthesize"), ("@throw"), ("@try"), |
|
105 |
|
106 ("SIGNAL"), ("SLOT"), ("Q_SIGNAL"), ("Q_SLOT"), ("signals"), ("slots"), |
|
107 ("Q_FOREACH"), ("Q_D"), ("Q_Q"), |
|
108 #ifdef ICHECK_BUILD |
|
109 ("Q_INVOKABLE"), ("Q_PROPERTY"), ("Q_ENUMS"), ("Q_FLAGS"), ("Q_DECLARE_FLAGS") |
|
110 #endif |
|
111 }; |
|
112 |
|
113 Token::Token() : |
|
114 flags(0), offset(0), ptr(0) |
|
115 { |
|
116 } |
|
117 |
|
118 Token::~Token() |
|
119 { |
|
120 } |
|
121 |
|
122 void Token::reset() |
|
123 { |
|
124 flags = 0; |
|
125 offset = 0; |
|
126 ptr = 0; |
|
127 } |
|
128 |
|
129 const char *Token::name(int kind) |
|
130 { return token_names[kind]; } |
|
131 |
|
132 const char *Token::spell() const |
|
133 { |
|
134 switch (f.kind) { |
|
135 case T_IDENTIFIER: |
|
136 return identifier->chars(); |
|
137 |
|
138 case T_NUMERIC_LITERAL: |
|
139 case T_CHAR_LITERAL: |
|
140 case T_STRING_LITERAL: |
|
141 case T_AT_STRING_LITERAL: |
|
142 case T_ANGLE_STRING_LITERAL: |
|
143 case T_WIDE_CHAR_LITERAL: |
|
144 case T_WIDE_STRING_LITERAL: |
|
145 return literal->chars(); |
|
146 |
|
147 default: |
|
148 return token_names[f.kind]; |
|
149 } // switch |
|
150 } |
|
151 |
|
152 |