~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/parser/tokens.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of KDevelop
 
2
    Copyright 2002-2005 Roberto Raggi <roberto@kdevelop.org>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License version 2 as published by the Free Software Foundation.
 
7
 
 
8
   This library is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
   Library General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU Library General Public License
 
14
   along with this library; see the file COPYING.LIB.  If not, write to
 
15
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
16
   Boston, MA 02110-1301, USA.
 
17
*/
 
18
 
 
19
#include "tokens.h"
 
20
 
 
21
#include <QtCore/qglobal.h>
 
22
 
 
23
 
 
24
static char const * const _S_token_names[] = {
 
25
  "K_DCOP",
 
26
  "Q_OBJECT",
 
27
  "__attribute__",
 
28
  "__typeof",
 
29
  "and",
 
30
  "and_eq",
 
31
  "arrow",
 
32
  "asm",
 
33
  "assign",
 
34
  "auto",
 
35
  "bitand",
 
36
  "bitor",
 
37
  "bool",
 
38
  "break",
 
39
  "case",
 
40
  "catch",
 
41
  "char",
 
42
  "char_literal",
 
43
  "class",
 
44
  "comment",
 
45
  "compl",
 
46
  "concat",
 
47
  "const",
 
48
  "const_cast",
 
49
  "continue",
 
50
  "decr",
 
51
  "default",
 
52
  "delete",
 
53
  "do",
 
54
  "double",
 
55
  "dynamic_cast",
 
56
  "ellipsis",
 
57
  "else",
 
58
  //"emit",
 
59
  "enum",
 
60
  "eq",
 
61
  "explicit",
 
62
  "export",
 
63
  "extern",
 
64
  "false",
 
65
  "float",
 
66
  "for",
 
67
  "friend",
 
68
  "geq",
 
69
  "goto",
 
70
  "identifier",
 
71
  "if",
 
72
  "incr",
 
73
  "inline",
 
74
  "int",
 
75
  "k_dcop",
 
76
  "k_dcop_signals",
 
77
  "leq",
 
78
  "long",
 
79
  "mutable",
 
80
  "namespace",
 
81
  "new",
 
82
  "not",
 
83
  "not_eq",
 
84
  "number_literal",
 
85
  "operator",
 
86
  "or",
 
87
  "or_eq",
 
88
  "preproc",
 
89
  "private",
 
90
  "protected",
 
91
  "ptrmem",
 
92
  "public",
 
93
  "register",
 
94
  "reinterpret_cast",
 
95
  "return",
 
96
  "scope",
 
97
  "shift",
 
98
  "short",
 
99
  "__qt_signals__",
 
100
  "signed",
 
101
  "sizeof",
 
102
  "__qt_slots__",
 
103
  "static",
 
104
  "static_cast",
 
105
  "string_literal",
 
106
  "struct",
 
107
  "switch",
 
108
  "template",
 
109
  "this",
 
110
  "throw",
 
111
  "true",
 
112
  "try",
 
113
  "typedef",
 
114
  "typeid",
 
115
  "typename",
 
116
  "union",
 
117
  "unsigned",
 
118
  "using",
 
119
  "virtual",
 
120
  "void",
 
121
  "volatile",
 
122
  "wchar_t",
 
123
  "while",
 
124
  "whitespaces",
 
125
  "xor",
 
126
  "xor_eq",
 
127
  "__qt_signal__",
 
128
  "__qt_slot__"
 
129
};
 
130
 
 
131
static char const * const _S_token_texts[] = {
 
132
  "K_DCOP",
 
133
  "Q_OBJECT",
 
134
  "__attribute__",
 
135
  "__typeof",
 
136
  "&&",
 
137
  "&=",
 
138
  ">",
 
139
  "asm",
 
140
  "==",
 
141
  "auto",
 
142
  "&",
 
143
  "|",
 
144
  "bool",
 
145
  "break",
 
146
  "case",
 
147
  "catch",
 
148
  "char",
 
149
  "char_literal",
 
150
  "class",
 
151
  "comment",
 
152
  "~",
 
153
  "concat",
 
154
  "const",
 
155
  "const_cast",
 
156
  "continue",
 
157
  "--",
 
158
  "default",
 
159
  "delete",
 
160
  "do",
 
161
  "double",
 
162
  "dynamic_cast",
 
163
  "...",
 
164
  "else",
 
165
  //"emit",
 
166
  "enum",
 
167
  "==",
 
168
  "explicit",
 
169
  "export",
 
170
  "extern",
 
171
  "false",
 
172
  "float",
 
173
  "for",
 
174
  "friend",
 
175
  ">=",
 
176
  "goto",
 
177
  "identifier",
 
178
  "if",
 
179
  "++",
 
180
  "inline",
 
181
  "int",
 
182
  "k_dcop",
 
183
  "k_dcop_signals",
 
184
  "<=",
 
185
  "long",
 
186
  "mutable",
 
187
  "namespace",
 
188
  "new",
 
189
  "!",
 
190
  "!=",
 
191
  "number_literal",
 
192
  "operator",
 
193
  "||",
 
194
  "|=",
 
195
  "preproc",
 
196
  "private",
 
197
  "protected",
 
198
  "ptrmem",
 
199
  "public",
 
200
  "register",
 
201
  "reinterpret_cast",
 
202
  "return",
 
203
  "::",
 
204
  "shift",
 
205
  "short",
 
206
  "__qt_signals__",
 
207
  "signed",
 
208
  "sizeof",
 
209
  "__qt_slots__",
 
210
  "static",
 
211
  "static_cast",
 
212
  "string_literal",
 
213
  "struct",
 
214
  "switch",
 
215
  "template",
 
216
  "this",
 
217
  "throw",
 
218
  "true",
 
219
  "try",
 
220
  "typedef",
 
221
  "typeid",
 
222
  "typename",
 
223
  "union",
 
224
  "unsigned",
 
225
  "using",
 
226
  "virtual",
 
227
  "void",
 
228
  "volatile",
 
229
  "wchar_t",
 
230
  "while",
 
231
  "whitespaces",
 
232
  "^",
 
233
  "^=",
 
234
  "__qt_signal__",
 
235
  "__qt_slot__"
 
236
};
 
237
 
 
238
static char _S_printable[][2] = {
 
239
  { char(32), '\0' },
 
240
  { char(33), '\0' },
 
241
  { char(34), '\0' },
 
242
  { char(35), '\0' },
 
243
  { char(36), '\0' },
 
244
  { char(37), '\0' },
 
245
  { char(38), '\0' },
 
246
  { char(39), '\0' },
 
247
  { char(40), '\0' },
 
248
  { char(41), '\0' },
 
249
  { char(42), '\0' },
 
250
  { char(43), '\0' },
 
251
  { char(44), '\0' },
 
252
  { char(45), '\0' },
 
253
  { char(46), '\0' },
 
254
  { char(47), '\0' },
 
255
  { char(48), '\0' },
 
256
  { char(49), '\0' },
 
257
  { char(50), '\0' },
 
258
  { char(51), '\0' },
 
259
  { char(52), '\0' },
 
260
  { char(53), '\0' },
 
261
  { char(54), '\0' },
 
262
  { char(55), '\0' },
 
263
  { char(56), '\0' },
 
264
  { char(57), '\0' },
 
265
  { char(58), '\0' },
 
266
  { char(59), '\0' },
 
267
  { char(60), '\0' },
 
268
  { char(61), '\0' },
 
269
  { char(62), '\0' },
 
270
  { char(63), '\0' },
 
271
  { char(64), '\0' },
 
272
  { char(65), '\0' },
 
273
  { char(66), '\0' },
 
274
  { char(67), '\0' },
 
275
  { char(68), '\0' },
 
276
  { char(69), '\0' },
 
277
  { char(70), '\0' },
 
278
  { char(71), '\0' },
 
279
  { char(72), '\0' },
 
280
  { char(73), '\0' },
 
281
  { char(74), '\0' },
 
282
  { char(75), '\0' },
 
283
  { char(76), '\0' },
 
284
  { char(77), '\0' },
 
285
  { char(78), '\0' },
 
286
  { char(79), '\0' },
 
287
  { char(80), '\0' },
 
288
  { char(81), '\0' },
 
289
  { char(82), '\0' },
 
290
  { char(83), '\0' },
 
291
  { char(84), '\0' },
 
292
  { char(85), '\0' },
 
293
  { char(86), '\0' },
 
294
  { char(87), '\0' },
 
295
  { char(88), '\0' },
 
296
  { char(89), '\0' },
 
297
  { char(90), '\0' },
 
298
  { char(91), '\0' },
 
299
  { char(92), '\0' },
 
300
  { char(93), '\0' },
 
301
  { char(94), '\0' },
 
302
  { char(95), '\0' },
 
303
  { char(96), '\0' },
 
304
  { char(97), '\0' },
 
305
  { char(98), '\0' },
 
306
  { char(99), '\0' },
 
307
  { char(100), '\0' },
 
308
  { char(101), '\0' },
 
309
  { char(102), '\0' },
 
310
  { char(103), '\0' },
 
311
  { char(104), '\0' },
 
312
  { char(105), '\0' },
 
313
  { char(106), '\0' },
 
314
  { char(107), '\0' },
 
315
  { char(108), '\0' },
 
316
  { char(109), '\0' },
 
317
  { char(110), '\0' },
 
318
  { char(111), '\0' },
 
319
  { char(112), '\0' },
 
320
  { char(113), '\0' },
 
321
  { char(114), '\0' },
 
322
  { char(115), '\0' },
 
323
  { char(116), '\0' },
 
324
  { char(117), '\0' },
 
325
  { char(118), '\0' },
 
326
  { char(119), '\0' },
 
327
  { char(120), '\0' },
 
328
  { char(121), '\0' },
 
329
  { char(122), '\0' },
 
330
  { char(123), '\0' },
 
331
  { char(124), '\0' },
 
332
  { char(125), '\0' },
 
333
  { char(126), '\0' },
 
334
  { char(127), '\0' },
 
335
};
 
336
 
 
337
char const *token_name(int token)
 
338
{
 
339
  if (token == 0)
 
340
    {
 
341
      return "eof";
 
342
    }
 
343
  else if (token >= 32 && token <= 127)
 
344
    {
 
345
      return _S_printable[token - 32];
 
346
    }
 
347
  else if (token >= 1000)
 
348
    {
 
349
      return _S_token_names[token - 1000];
 
350
    }
 
351
 
 
352
  Q_ASSERT(0);
 
353
  return 0;
 
354
}
 
355
 
 
356
char const *token_text(int token)
 
357
{
 
358
  if (token >= 32 && token <= 127)
 
359
    {
 
360
      return _S_printable[token - 32];
 
361
    }
 
362
  else if (token >= 1000)
 
363
    {
 
364
      return _S_token_texts[token - 1000];
 
365
    }
 
366
 
 
367
  return 0;
 
368
}