~ubuntu-branches/ubuntu/wily/eclipse-linuxtools/wily

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/editors/stp/Token.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * Copyright (c) 2004, 2010, 2013 IBM Corporation and others.
3
 
 * All rights reserved. This program and the accompanying materials
4
 
 * are made available under the terms of the Eclipse Public License v1.0
5
 
 * which accompanies this distribution, and is available at
6
 
 * http://www.eclipse.org/legal/epl-v10.html
7
 
 *
8
 
 * Contributors:
9
 
 *     IBM Corporation - initial implementation
10
 
 *     Anton Leherbauer - adding tokens for preprocessing directives
11
 
 *     Markus Schorn - classification of preprocessing directives.
12
 
 *     Red Hat Inc. - used in SystemTap editor
13
 
 *******************************************************************************/
14
 
package org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp;
15
 
 
16
 
public class Token {
17
 
    public int type;
18
 
    public String text;
19
 
    public int offset;
20
 
 
21
 
    public Token(int t, String i) {
22
 
        type = t;
23
 
        text = i;
24
 
    }
25
 
    
26
 
    public Token(int t, String i, ScannerContext context) {
27
 
        set(t, i, context);
28
 
    }
29
 
 
30
 
    public void set(int t, String i, ScannerContext context) {
31
 
        type = t;
32
 
        text = i;
33
 
        offset = context.getOffset() - text.length() - context.undoStackSize();
34
 
    }
35
 
 
36
 
    @Override
37
 
        public String toString() {
38
 
        return "Token type=" + type + "  image =" + text + " offset=" + offset; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
39
 
    }
40
 
 
41
 
    public int getType() {
42
 
        return type;
43
 
    }
44
 
 
45
 
    public String getText() {
46
 
        return text;
47
 
    }
48
 
 
49
 
    public int getOffset() {
50
 
        return offset;
51
 
    }
52
 
 
53
 
    public int getLength() {
54
 
        return text.length();
55
 
    }
56
 
 
57
 
    public int getDelta(Token other) {
58
 
        return other.getOffset() + other.getLength() - getOffset();
59
 
    }
60
 
 
61
 
    public boolean looksLikeExpressionStart() {
62
 
        switch (type) {
63
 
            case tINTEGER:
64
 
            case t_false:
65
 
            case t_true:
66
 
            case tSTRING:
67
 
            case tLSTRING:
68
 
            case tFLOATINGPT:
69
 
            case tCHAR:
70
 
            case tAMPER:
71
 
            case tDOT:
72
 
            case tLPAREN:
73
 
                return true;
74
 
            default:
75
 
                break;
76
 
        }
77
 
        return false;
78
 
    }
79
 
 
80
 
    public boolean looksLikeExpressionEnd() {
81
 
        switch (type) {
82
 
            case tINTEGER:
83
 
            case tSTRING:
84
 
            case tLSTRING:
85
 
            case tFLOATINGPT:
86
 
            case tCHAR:
87
 
            case tRPAREN:
88
 
            case tIDENTIFIER:
89
 
                return true;
90
 
            default:
91
 
                break;
92
 
        }
93
 
        return false;
94
 
    }
95
 
 
96
 
    public boolean isPointer() {
97
 
        return (type == tAMPER || type == tSTAR);
98
 
    }
99
 
 
100
 
    public boolean isOperator() {
101
 
        switch (type) {
102
 
            case t_new:
103
 
            case t_delete:
104
 
            case tPLUS:
105
 
            case tMINUS:
106
 
            case tSTAR:
107
 
            case tDIV:
108
 
            case tXOR:
109
 
            case tMOD:
110
 
            case tAMPER:
111
 
            case tBITOR:
112
 
            case tCOMPL:
113
 
            case tNOT:
114
 
            case tASSIGN:
115
 
            case tLT:
116
 
            case tGT:
117
 
            case tPLUSASSIGN:
118
 
            case tMINUSASSIGN:
119
 
            case tSTARASSIGN:
120
 
            case tDIVASSIGN:
121
 
            case tMODASSIGN:
122
 
            case tBITORASSIGN:
123
 
            case tAMPERASSIGN:
124
 
            case tXORASSIGN:
125
 
            case tSHIFTL:
126
 
            case tSHIFTR:
127
 
            case tSHIFTLASSIGN:
128
 
            case tSHIFTRASSIGN:
129
 
            case tEQUAL:
130
 
            case tNOTEQUAL:
131
 
            case tLTEQUAL:
132
 
            case tGTEQUAL:
133
 
            case tAND:
134
 
            case tOR:
135
 
            case tINCR:
136
 
            case tDECR:
137
 
            case tCOMMA:
138
 
            case tDOT:
139
 
            case tDOTSTAR:
140
 
            case tARROW:
141
 
            case tARROWSTAR:
142
 
                return true;
143
 
            default:
144
 
                return false;
145
 
        }
146
 
    }
147
 
 
148
 
    public boolean isInfixOperator() {
149
 
        switch (type) {
150
 
            case tPLUS:
151
 
            case tMINUS:
152
 
            case tSTAR:
153
 
            case tDIV:
154
 
            case tXOR:
155
 
            case tMOD:
156
 
            case tAMPER:
157
 
            case tBITOR:
158
 
            case tASSIGN:
159
 
            case tLT:
160
 
            case tGT:
161
 
            case tPLUSASSIGN:
162
 
            case tMINUSASSIGN:
163
 
            case tSTARASSIGN:
164
 
            case tDIVASSIGN:
165
 
            case tMODASSIGN:
166
 
            case tBITORASSIGN:
167
 
            case tAMPERASSIGN:
168
 
            case tXORASSIGN:
169
 
            case tSHIFTL:
170
 
            case tSHIFTR:
171
 
            case tSHIFTLASSIGN:
172
 
            case tSHIFTRASSIGN:
173
 
            case tEQUAL:
174
 
            case tNOTEQUAL:
175
 
            case tLTEQUAL:
176
 
            case tGTEQUAL:
177
 
            case tAND:
178
 
            case tOR:
179
 
            case tCOLON:
180
 
            case tQUESTION:
181
 
                return true;
182
 
            default:
183
 
                return false;
184
 
        }
185
 
    }
186
 
 
187
 
    public boolean isPrefixOperator() {
188
 
        switch (type) {
189
 
            case tPLUS:
190
 
            case tMINUS:
191
 
            case tSTAR:
192
 
            case tAMPER:
193
 
            case tCOMPL:
194
 
            case tNOT:
195
 
            case tINCR:
196
 
            case tDECR:
197
 
                return true;
198
 
            default:
199
 
                return false;
200
 
        }
201
 
    }
202
 
 
203
 
    public boolean isPostfixOperator() {
204
 
        switch (type) {
205
 
            case tINCR:
206
 
            case tDECR:
207
 
                return true;
208
 
            default:
209
 
                return false;
210
 
        }
211
 
    }
212
 
 
213
 
    public boolean isAssignmentOperator() {
214
 
        return isAssignmentOperator(type);
215
 
    }
216
 
 
217
 
    public static boolean isAssignmentOperator(int type) {
218
 
        switch (type) {
219
 
            case tASSIGN:
220
 
            case tPLUSASSIGN:
221
 
            case tMINUSASSIGN:
222
 
            case tSTARASSIGN:
223
 
            case tDIVASSIGN:
224
 
            case tAMPERASSIGN:
225
 
            case tBITORASSIGN:
226
 
            case tXORASSIGN:
227
 
            case tMODASSIGN:
228
 
            case tSHIFTLASSIGN:
229
 
            case tSHIFTRASSIGN:
230
 
                return true;
231
 
            default:
232
 
                return false;
233
 
        }
234
 
    }
235
 
 
236
 
    public boolean isControlStmt() {
237
 
        switch (type) {
238
 
            case t_if:
239
 
            case t_else:
240
 
            case t_for:
241
 
            case t_do:
242
 
            case t_while:
243
 
            case t_switch:
244
 
            case t_try:
245
 
            case t_catch:
246
 
            case t_finally:
247
 
                return true;
248
 
            default:
249
 
                return false;
250
 
        }
251
 
    }
252
 
 
253
 
    public boolean isWhiteSpace() {
254
 
        return type == tWHITESPACE;
255
 
    }
256
 
 
257
 
    public boolean isComment() {
258
 
        return isLineComment() || isBlockComment();
259
 
    }
260
 
 
261
 
    public boolean isLineComment() {
262
 
        return type == tLINECOMMENT;
263
 
    }
264
 
 
265
 
    public boolean isBlockComment() {
266
 
        return type == tBLOCKCOMMENT;
267
 
    }
268
 
 
269
 
    public boolean isCaseLabel() {
270
 
        return type == t_case || type == t_default;
271
 
    }
272
 
 
273
 
    public boolean isStructType() {
274
 
        return isStructType(type);
275
 
    }
276
 
 
277
 
    public static boolean isStructType(int type) {
278
 
        return type == t_struct || type == t_union || type == t_class;
279
 
    }
280
 
 
281
 
    public boolean isVisibilityModifier() {
282
 
        return isVisibilityModifier(type);
283
 
    }
284
 
 
285
 
        public static boolean isVisibilityModifier(int type) {
286
 
        return type == t_public || type == t_protected || type == t_private;
287
 
        }
288
 
 
289
 
        public boolean isEndOfStatement() {
290
 
        return type == tSEMI || type == tRBRACE;
291
 
    }
292
 
    
293
 
    public boolean isCPPToken() {
294
 
        switch (type) {
295
 
        case tCOLONCOLON:
296
 
        case t_class:
297
 
        case t_namespace:
298
 
        case t_using:
299
 
        case t_template:
300
 
        case t_public:
301
 
        case t_protected:
302
 
        case t_private:
303
 
        case t_operator:
304
 
        case t_virtual:
305
 
        case t_inline:
306
 
        case t_friend:
307
 
        case t_mutable:
308
 
        case t_new:
309
 
        case t_delete:
310
 
        case t_reinterpret_cast:
311
 
        case t_dynamic_cast:
312
 
        case t_static_cast:
313
 
        case t_finally:
314
 
            return true;
315
 
        default:
316
 
            return false;
317
 
        }
318
 
    }
319
 
 
320
 
    // overrider
321
 
    public boolean isStringLiteral() {
322
 
        return type == tSTRING || type == tLSTRING;
323
 
    }
324
 
 
325
 
    // overrider
326
 
    public boolean isCharacterLiteral() {
327
 
        return type == tCHAR;
328
 
    }
329
 
 
330
 
    // overrider
331
 
    public boolean isPreprocessor() {
332
 
        switch (type) {
333
 
        case tPREPROCESSOR:
334
 
        case tPREPROCESSOR_DEFINE:
335
 
        case tPREPROCESSOR_INCLUDE:
336
 
            return true;
337
 
        }
338
 
        return false;
339
 
    }
340
 
    
341
 
    // overrider
342
 
    public boolean isIncludeDirective() {
343
 
        return type == tPREPROCESSOR_INCLUDE;
344
 
    }
345
 
    // overrider
346
 
    public boolean isMacroDefinition() {
347
 
        return type == tPREPROCESSOR_DEFINE;
348
 
    }
349
 
    
350
 
    // Special Token types (non-grammar tokens)
351
 
    public static final int tWHITESPACE = 1000;
352
 
    public static final int tLINECOMMENT = 1001;
353
 
    public static final int tBLOCKCOMMENT = 1002;
354
 
    public static final int tPREPROCESSOR = 1003;
355
 
    public static final int tPREPROCESSOR_INCLUDE = 1004;
356
 
    public static final int tPREPROCESSOR_DEFINE  = 1005;
357
 
    public static final int tBADCHAR = 1006;
358
 
 
359
 
    // Token types
360
 
    static public final int tIDENTIFIER = 1;
361
 
    static public final int tINTEGER = 2;
362
 
    static public final int tCOLONCOLON = 3;
363
 
    static public final int tCOLON = 4;
364
 
    static public final int tSEMI = 5;
365
 
    static public final int tCOMMA = 6;
366
 
    static public final int tQUESTION = 7;
367
 
    static public final int tLPAREN = 8;
368
 
    static public final int tRPAREN = 9;
369
 
    static public final int tLBRACKET = 10;
370
 
    static public final int tRBRACKET = 11;
371
 
    static public final int tLBRACE = 12;
372
 
    static public final int tRBRACE = 13;
373
 
    static public final int tPLUSASSIGN = 14;
374
 
    static public final int tINCR = 15;
375
 
    static public final int tPLUS = 16;
376
 
    static public final int tMINUSASSIGN = 17;
377
 
    static public final int tDECR = 18;
378
 
    static public final int tARROWSTAR = 19;
379
 
    static public final int tARROW = 20;
380
 
    static public final int tMINUS = 21;
381
 
    static public final int tSTARASSIGN = 22;
382
 
    static public final int tSTAR = 23;
383
 
    static public final int tMODASSIGN = 24;
384
 
    static public final int tMOD = 25;
385
 
    static public final int tXORASSIGN = 26;
386
 
    static public final int tXOR = 27;
387
 
    static public final int tAMPERASSIGN = 28;
388
 
    static public final int tAND = 29;
389
 
    static public final int tAMPER = 30;
390
 
    static public final int tBITORASSIGN = 31;
391
 
    static public final int tOR = 32;
392
 
    static public final int tBITOR = 33;
393
 
    static public final int tCOMPL = 34;
394
 
    static public final int tNOTEQUAL = 35;
395
 
    static public final int tNOT = 36;
396
 
    static public final int tEQUAL = 37;
397
 
    static public final int tASSIGN = 38;
398
 
    static public final int tSHIFTL = 40;
399
 
    static public final int tLTEQUAL = 41;
400
 
    static public final int tLT = 42;
401
 
    static public final int tSHIFTRASSIGN = 43;
402
 
    static public final int tSHIFTR = 44;
403
 
    static public final int tGTEQUAL = 45;
404
 
    static public final int tGT = 46;
405
 
    static public final int tSHIFTLASSIGN = 47;
406
 
    static public final int tELIPSE = 48;
407
 
    static public final int tDOTSTAR = 49;
408
 
    static public final int tDOT = 50;
409
 
    static public final int tDIVASSIGN = 51;
410
 
    static public final int tDIV = 52;
411
 
    static public final int tCLASSNAME = 53;
412
 
    static public final int t_and = 54;
413
 
    static public final int t_and_eq = 55;
414
 
    static public final int t_asm = 56;
415
 
    static public final int t_auto = 57;
416
 
    static public final int t_bitand = 58;
417
 
    static public final int t_bitor = 59;
418
 
    static public final int t_bool = 60;
419
 
    static public final int t_break = 61;
420
 
    static public final int t_case = 62;
421
 
    static public final int t_catch = 63;
422
 
    static public final int t_char = 64;
423
 
    static public final int t_class = 65;
424
 
    static public final int t_compl = 66;
425
 
    static public final int t_const = 67;
426
 
    static public final int t_const_cast = 69;
427
 
    static public final int t_continue = 70;
428
 
    static public final int t_default = 71;
429
 
    static public final int t_delete = 72;
430
 
    static public final int t_do = 73;
431
 
    static public final int t_double = 74;
432
 
    static public final int t_dynamic_cast = 75;
433
 
    static public final int t_else = 76;
434
 
    static public final int t_enum = 77;
435
 
    static public final int t_explicit = 78;
436
 
    static public final int t_export = 79;
437
 
    static public final int t_extern = 80;
438
 
    static public final int t_false = 81;
439
 
    static public final int t_float = 82;
440
 
    static public final int t_for = 83;
441
 
    static public final int t_friend = 84;
442
 
    static public final int t_goto = 85;
443
 
    static public final int t_if = 86;
444
 
    static public final int t_inline = 87;
445
 
    static public final int t_int = 88;
446
 
    static public final int t_long = 89;
447
 
    static public final int t_mutable = 90;
448
 
    static public final int t_namespace = 91;
449
 
    static public final int t_new = 92;
450
 
    static public final int t_not = 93;
451
 
    static public final int t_not_eq = 94;
452
 
    static public final int t_operator = 95;
453
 
    static public final int t_or = 96;
454
 
    static public final int t_or_eq = 97;
455
 
    static public final int t_private = 98;
456
 
    static public final int t_protected = 99;
457
 
    static public final int t_public = 100;
458
 
    static public final int t_register = 101;
459
 
    static public final int t_reinterpret_cast = 102;
460
 
    static public final int t_return = 103;
461
 
    static public final int t_short = 104;
462
 
    static public final int t_sizeof = 105;
463
 
    static public final int t_static = 106;
464
 
    static public final int t_static_cast = 107;
465
 
    static public final int t_signed = 108;
466
 
    static public final int t_struct = 109;
467
 
    static public final int t_switch = 110;
468
 
    static public final int t_template = 111;
469
 
    static public final int t_this = 112;
470
 
    static public final int t_throw = 113;
471
 
    static public final int t_true = 114;
472
 
    static public final int t_try = 115;
473
 
    static public final int t_typedef = 116;
474
 
    static public final int t_typeid = 117;
475
 
    static public final int t_typename = 118;
476
 
    static public final int t_union = 119;
477
 
    static public final int t_unsigned = 120;
478
 
    static public final int t_using = 121;
479
 
    static public final int t_virtual = 122;
480
 
    static public final int t_void = 123;
481
 
    static public final int t_volatile = 124;
482
 
    static public final int t_wchar_t = 125;
483
 
    static public final int t_while = 126;
484
 
    static public final int t_xor = 127;
485
 
    static public final int t_xor_eq = 128;
486
 
    static public final int tSTRING = 129;
487
 
    static public final int tFLOATINGPT = 130;
488
 
    static public final int tLSTRING = 131;
489
 
    static public final int tCHAR = 132;
490
 
    static public final int tRSTRING = 133;
491
 
    static public final int t_restrict = 136;
492
 
    static public final int t_interface = 200;
493
 
    static public final int t_import = 201;
494
 
    static public final int t_instanceof = 202;
495
 
    static public final int t_extends = 203;
496
 
    static public final int t_implements = 204;
497
 
    static public final int t_final = 205;
498
 
    static public final int t_super = 206;
499
 
    static public final int t_package = 207;
500
 
    static public final int t_boolean = 208;
501
 
    static public final int t_abstract = 209;
502
 
    static public final int t_finally = 210;
503
 
    static public final int t_null = 211;
504
 
    static public final int t_synchronized = 212;
505
 
    static public final int t_throws = 213;
506
 
    static public final int t_byte = 214;
507
 
    static public final int t_transient = 215;
508
 
    static public final int t_native = 216;
509
 
}