~etherpad/+junk/yuicompressor-appjet

« back to all changes in this revision

Viewing changes to .pc/token.patch/src/org/mozilla/javascript/Token.java

  • Committer: James Page
  • Date: 2011-04-18 15:29:34 UTC
  • Revision ID: james.page@canonical.com-20110418152934-cxosko5ic33gr4ra
Appjet branch of yuicompressor library.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * ***** BEGIN LICENSE BLOCK *****
 
4
 * Version: MPL 1.1/GPL 2.0
 
5
 *
 
6
 * The contents of this file are subject to the Mozilla Public License Version
 
7
 * 1.1 (the "License"); you may not use this file except in compliance with
 
8
 * the License. You may obtain a copy of the License at
 
9
 * http://www.mozilla.org/MPL/
 
10
 *
 
11
 * Software distributed under the License is distributed on an "AS IS" basis,
 
12
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
13
 * for the specific language governing rights and limitations under the
 
14
 * License.
 
15
 *
 
16
 * The Original Code is Rhino code, released
 
17
 * May 6, 1999.
 
18
 *
 
19
 * The Initial Developer of the Original Code is
 
20
 * Netscape Communications Corporation.
 
21
 * Portions created by the Initial Developer are Copyright (C) 1997-1999
 
22
 * the Initial Developer. All Rights Reserved.
 
23
 *
 
24
 * Contributor(s):
 
25
 *   Roger Lawrence
 
26
 *   Mike McCabe
 
27
 *   Igor Bukanov
 
28
 *   Bob Jervis
 
29
 *   Milen Nankov
 
30
 *
 
31
 * Alternatively, the contents of this file may be used under the terms of
 
32
 * the GNU General Public License Version 2 or later (the "GPL"), in which
 
33
 * case the provisions of the GPL are applicable instead of those above. If
 
34
 * you wish to allow use of your version of this file only under the terms of
 
35
 * the GPL and not to allow others to use your version of this file under the
 
36
 * MPL, indicate your decision by deleting the provisions above and replacing
 
37
 * them with the notice and other provisions required by the GPL. If you do
 
38
 * not delete the provisions above, a recipient may use your version of this
 
39
 * file under either the MPL or the GPL.
 
40
 *
 
41
 * ***** END LICENSE BLOCK ***** */
 
42
 
 
43
package org.mozilla.javascript;
 
44
 
 
45
/**
 
46
 * This class implements the JavaScript scanner.
 
47
 *
 
48
 * It is based on the C source files jsscan.c and jsscan.h
 
49
 * in the jsref package.
 
50
 *
 
51
 * @see org.mozilla.javascript.Parser
 
52
 *
 
53
 * @author Mike McCabe
 
54
 * @author Brendan Eich
 
55
 */
 
56
 
 
57
public class Token
 
58
{
 
59
 
 
60
    // debug flags
 
61
    public static final boolean printTrees = false;
 
62
    static final boolean printICode = false;
 
63
    static final boolean printNames = printTrees || printICode;
 
64
 
 
65
    /**
 
66
     * Token types.  These values correspond to JSTokenType values in
 
67
     * jsscan.c.
 
68
     */
 
69
 
 
70
    public final static int
 
71
    // start enum
 
72
        ERROR          = -1, // well-known as the only code < EOF
 
73
        EOF            = 0,  // end of file token - (not EOF_CHAR)
 
74
        EOL            = 1,  // end of line
 
75
 
 
76
        // Interpreter reuses the following as bytecodes
 
77
        FIRST_BYTECODE_TOKEN    = 2,
 
78
 
 
79
        ENTERWITH      = 2,
 
80
        LEAVEWITH      = 3,
 
81
        RETURN         = 4,
 
82
        GOTO           = 5,
 
83
        IFEQ           = 6,
 
84
        IFNE           = 7,
 
85
        SETNAME        = 8,
 
86
        BITOR          = 9,
 
87
        BITXOR         = 10,
 
88
        BITAND         = 11,
 
89
        EQ             = 12,
 
90
        NE             = 13,
 
91
        LT             = 14,
 
92
        LE             = 15,
 
93
        GT             = 16,
 
94
        GE             = 17,
 
95
        LSH            = 18,
 
96
        RSH            = 19,
 
97
        URSH           = 20,
 
98
        ADD            = 21,
 
99
        SUB            = 22,
 
100
        MUL            = 23,
 
101
        DIV            = 24,
 
102
        MOD            = 25,
 
103
        NOT            = 26,
 
104
        BITNOT         = 27,
 
105
        POS            = 28,
 
106
        NEG            = 29,
 
107
        NEW            = 30,
 
108
        DELPROP        = 31,
 
109
        TYPEOF         = 32,
 
110
        GETPROP        = 33,
 
111
        GETPROPNOWARN  = 34,
 
112
        SETPROP        = 35,
 
113
        GETELEM        = 36,
 
114
        SETELEM        = 37,
 
115
        CALL           = 38,
 
116
        NAME           = 39,
 
117
        NUMBER         = 40,
 
118
        STRING         = 41,
 
119
        NULL           = 42,
 
120
        THIS           = 43,
 
121
        FALSE          = 44,
 
122
        TRUE           = 45,
 
123
        SHEQ           = 46,   // shallow equality (===)
 
124
        SHNE           = 47,   // shallow inequality (!==)
 
125
        REGEXP         = 48,
 
126
        BINDNAME       = 49,
 
127
        THROW          = 50,
 
128
        RETHROW        = 51, // rethrow caught exception: catch (e if ) use it
 
129
        IN             = 52,
 
130
        INSTANCEOF     = 53,
 
131
        LOCAL_LOAD     = 54,
 
132
        GETVAR         = 55,
 
133
        SETVAR         = 56,
 
134
        CATCH_SCOPE    = 57,
 
135
        ENUM_INIT_KEYS = 58,
 
136
        ENUM_INIT_VALUES = 59,
 
137
        ENUM_INIT_ARRAY= 60,
 
138
        ENUM_NEXT      = 61,
 
139
        ENUM_ID        = 62,
 
140
        THISFN         = 63,
 
141
        RETURN_RESULT  = 64, // to return previously stored return result
 
142
        ARRAYLIT       = 65, // array literal
 
143
        OBJECTLIT      = 66, // object literal
 
144
        GET_REF        = 67, // *reference
 
145
        SET_REF        = 68, // *reference    = something
 
146
        DEL_REF        = 69, // delete reference
 
147
        REF_CALL       = 70, // f(args)    = something or f(args)++
 
148
        REF_SPECIAL    = 71, // reference for special properties like __proto
 
149
        YIELD          = 72,  // JS 1.7 yield pseudo keyword
 
150
 
 
151
        // For XML support:
 
152
        DEFAULTNAMESPACE = 73, // default xml namespace =
 
153
        ESCXMLATTR     = 74,
 
154
        ESCXMLTEXT     = 75,
 
155
        REF_MEMBER     = 76, // Reference for x.@y, x..y etc.
 
156
        REF_NS_MEMBER  = 77, // Reference for x.ns::y, x..ns::y etc.
 
157
        REF_NAME       = 78, // Reference for @y, @[y] etc.
 
158
        REF_NS_NAME    = 79; // Reference for ns::y, @ns::y@[y] etc.
 
159
 
 
160
        // End of interpreter bytecodes
 
161
    public final static int
 
162
        LAST_BYTECODE_TOKEN    = REF_NS_NAME,
 
163
 
 
164
        TRY            = 80,
 
165
        SEMI           = 81,  // semicolon
 
166
        LB             = 82,  // left and right brackets
 
167
        RB             = 83,
 
168
        LC             = 84,  // left and right curlies (braces)
 
169
        RC             = 85,
 
170
        LP             = 86,  // left and right parentheses
 
171
        RP             = 87,
 
172
        COMMA          = 88,  // comma operator
 
173
 
 
174
        ASSIGN         = 89,  // simple assignment  (=)
 
175
        ASSIGN_BITOR   = 90,  // |=
 
176
        ASSIGN_BITXOR  = 91,  // ^=
 
177
        ASSIGN_BITAND  = 92,  // |=
 
178
        ASSIGN_LSH     = 93,  // <<=
 
179
        ASSIGN_RSH     = 94,  // >>=
 
180
        ASSIGN_URSH    = 95,  // >>>=
 
181
        ASSIGN_ADD     = 96,  // +=
 
182
        ASSIGN_SUB     = 97,  // -=
 
183
        ASSIGN_MUL     = 98,  // *=
 
184
        ASSIGN_DIV     = 99,  // /=
 
185
        ASSIGN_MOD     = 100;  // %=
 
186
 
 
187
    public final static int
 
188
        FIRST_ASSIGN   = ASSIGN,
 
189
        LAST_ASSIGN    = ASSIGN_MOD,
 
190
 
 
191
        HOOK           = 101, // conditional (?:)
 
192
        COLON          = 102,
 
193
        OR             = 103, // logical or (||)
 
194
        AND            = 104, // logical and (&&)
 
195
        INC            = 105, // increment/decrement (++ --)
 
196
        DEC            = 106,
 
197
        DOT            = 107, // member operator (.)
 
198
        FUNCTION       = 108, // function keyword
 
199
        EXPORT         = 109, // export keyword
 
200
        IMPORT         = 110, // import keyword
 
201
        IF             = 111, // if keyword
 
202
        ELSE           = 112, // else keyword
 
203
        SWITCH         = 113, // switch keyword
 
204
        CASE           = 114, // case keyword
 
205
        DEFAULT        = 115, // default keyword
 
206
        WHILE          = 116, // while keyword
 
207
        DO             = 117, // do keyword
 
208
        FOR            = 118, // for keyword
 
209
        BREAK          = 119, // break keyword
 
210
        CONTINUE       = 120, // continue keyword
 
211
        VAR            = 121, // var keyword
 
212
        WITH           = 122, // with keyword
 
213
        CATCH          = 123, // catch keyword
 
214
        FINALLY        = 124, // finally keyword
 
215
        VOID           = 125, // void keyword
 
216
        RESERVED       = 126, // reserved keywords
 
217
 
 
218
        EMPTY          = 127,
 
219
 
 
220
        /* types used for the parse tree - these never get returned
 
221
         * by the scanner.
 
222
         */
 
223
 
 
224
        BLOCK          = 128, // statement block
 
225
        LABEL          = 129, // label
 
226
        TARGET         = 130,
 
227
        LOOP           = 131,
 
228
        EXPR_VOID      = 132, // expression statement in functions
 
229
        EXPR_RESULT    = 133, // expression statement in scripts
 
230
        JSR            = 134,
 
231
        SCRIPT         = 135, // top-level node for entire script
 
232
        TYPEOFNAME     = 136, // for typeof(simple-name)
 
233
        USE_STACK      = 137,
 
234
        SETPROP_OP     = 138, // x.y op= something
 
235
        SETELEM_OP     = 139, // x[y] op= something
 
236
        LOCAL_BLOCK    = 140,
 
237
        SET_REF_OP     = 141, // *reference op= something
 
238
 
 
239
        // For XML support:
 
240
        DOTDOT         = 142,  // member operator (..)
 
241
        COLONCOLON     = 143,  // namespace::name
 
242
        XML            = 144,  // XML type
 
243
        DOTQUERY       = 145,  // .() -- e.g., x.emps.emp.(name == "terry")
 
244
        XMLATTR        = 146,  // @
 
245
        XMLEND         = 147,
 
246
 
 
247
        // Optimizer-only-tokens
 
248
        TO_OBJECT      = 148,
 
249
        TO_DOUBLE      = 149,
 
250
 
 
251
        GET            = 150,  // JS 1.5 get pseudo keyword
 
252
        SET            = 151,  // JS 1.5 set pseudo keyword
 
253
        LET            = 152,  // JS 1.7 let pseudo keyword
 
254
        CONST          = 153,
 
255
        SETCONST       = 154,
 
256
        SETCONSTVAR    = 155,
 
257
        ARRAYCOMP      = 156,  // array comprehension
 
258
        LETEXPR        = 157,
 
259
        WITHEXPR       = 158,
 
260
        DEBUGGER       = 159,
 
261
        LAST_TOKEN     = 159;
 
262
 
 
263
    public static String name(int token)
 
264
    {
 
265
        if (!printNames) {
 
266
            return String.valueOf(token);
 
267
        }
 
268
        switch (token) {
 
269
          case ERROR:           return "ERROR";
 
270
          case EOF:             return "EOF";
 
271
          case EOL:             return "EOL";
 
272
          case ENTERWITH:       return "ENTERWITH";
 
273
          case LEAVEWITH:       return "LEAVEWITH";
 
274
          case RETURN:          return "RETURN";
 
275
          case GOTO:            return "GOTO";
 
276
          case IFEQ:            return "IFEQ";
 
277
          case IFNE:            return "IFNE";
 
278
          case SETNAME:         return "SETNAME";
 
279
          case BITOR:           return "BITOR";
 
280
          case BITXOR:          return "BITXOR";
 
281
          case BITAND:          return "BITAND";
 
282
          case EQ:              return "EQ";
 
283
          case NE:              return "NE";
 
284
          case LT:              return "LT";
 
285
          case LE:              return "LE";
 
286
          case GT:              return "GT";
 
287
          case GE:              return "GE";
 
288
          case LSH:             return "LSH";
 
289
          case RSH:             return "RSH";
 
290
          case URSH:            return "URSH";
 
291
          case ADD:             return "ADD";
 
292
          case SUB:             return "SUB";
 
293
          case MUL:             return "MUL";
 
294
          case DIV:             return "DIV";
 
295
          case MOD:             return "MOD";
 
296
          case NOT:             return "NOT";
 
297
          case BITNOT:          return "BITNOT";
 
298
          case POS:             return "POS";
 
299
          case NEG:             return "NEG";
 
300
          case NEW:             return "NEW";
 
301
          case DELPROP:         return "DELPROP";
 
302
          case TYPEOF:          return "TYPEOF";
 
303
          case GETPROP:         return "GETPROP";
 
304
          case GETPROPNOWARN:   return "GETPROPNOWARN";
 
305
          case SETPROP:         return "SETPROP";
 
306
          case GETELEM:         return "GETELEM";
 
307
          case SETELEM:         return "SETELEM";
 
308
          case CALL:            return "CALL";
 
309
          case NAME:            return "NAME";
 
310
          case NUMBER:          return "NUMBER";
 
311
          case STRING:          return "STRING";
 
312
          case NULL:            return "NULL";
 
313
          case THIS:            return "THIS";
 
314
          case FALSE:           return "FALSE";
 
315
          case TRUE:            return "TRUE";
 
316
          case SHEQ:            return "SHEQ";
 
317
          case SHNE:            return "SHNE";
 
318
          case REGEXP:          return "OBJECT";
 
319
          case BINDNAME:        return "BINDNAME";
 
320
          case THROW:           return "THROW";
 
321
          case RETHROW:         return "RETHROW";
 
322
          case IN:              return "IN";
 
323
          case INSTANCEOF:      return "INSTANCEOF";
 
324
          case LOCAL_LOAD:      return "LOCAL_LOAD";
 
325
          case GETVAR:          return "GETVAR";
 
326
          case SETVAR:          return "SETVAR";
 
327
          case CATCH_SCOPE:     return "CATCH_SCOPE";
 
328
          case ENUM_INIT_KEYS:  return "ENUM_INIT_KEYS";
 
329
          case ENUM_INIT_VALUES:return "ENUM_INIT_VALUES";
 
330
          case ENUM_INIT_ARRAY: return "ENUM_INIT_ARRAY";
 
331
          case ENUM_NEXT:       return "ENUM_NEXT";
 
332
          case ENUM_ID:         return "ENUM_ID";
 
333
          case THISFN:          return "THISFN";
 
334
          case RETURN_RESULT:   return "RETURN_RESULT";
 
335
          case ARRAYLIT:        return "ARRAYLIT";
 
336
          case OBJECTLIT:       return "OBJECTLIT";
 
337
          case GET_REF:         return "GET_REF";
 
338
          case SET_REF:         return "SET_REF";
 
339
          case DEL_REF:         return "DEL_REF";
 
340
          case REF_CALL:        return "REF_CALL";
 
341
          case REF_SPECIAL:     return "REF_SPECIAL";
 
342
          case DEFAULTNAMESPACE:return "DEFAULTNAMESPACE";
 
343
          case ESCXMLTEXT:      return "ESCXMLTEXT";
 
344
          case ESCXMLATTR:      return "ESCXMLATTR";
 
345
          case REF_MEMBER:      return "REF_MEMBER";
 
346
          case REF_NS_MEMBER:   return "REF_NS_MEMBER";
 
347
          case REF_NAME:        return "REF_NAME";
 
348
          case REF_NS_NAME:     return "REF_NS_NAME";
 
349
          case TRY:             return "TRY";
 
350
          case SEMI:            return "SEMI";
 
351
          case LB:              return "LB";
 
352
          case RB:              return "RB";
 
353
          case LC:              return "LC";
 
354
          case RC:              return "RC";
 
355
          case LP:              return "LP";
 
356
          case RP:              return "RP";
 
357
          case COMMA:           return "COMMA";
 
358
          case ASSIGN:          return "ASSIGN";
 
359
          case ASSIGN_BITOR:    return "ASSIGN_BITOR";
 
360
          case ASSIGN_BITXOR:   return "ASSIGN_BITXOR";
 
361
          case ASSIGN_BITAND:   return "ASSIGN_BITAND";
 
362
          case ASSIGN_LSH:      return "ASSIGN_LSH";
 
363
          case ASSIGN_RSH:      return "ASSIGN_RSH";
 
364
          case ASSIGN_URSH:     return "ASSIGN_URSH";
 
365
          case ASSIGN_ADD:      return "ASSIGN_ADD";
 
366
          case ASSIGN_SUB:      return "ASSIGN_SUB";
 
367
          case ASSIGN_MUL:      return "ASSIGN_MUL";
 
368
          case ASSIGN_DIV:      return "ASSIGN_DIV";
 
369
          case ASSIGN_MOD:      return "ASSIGN_MOD";
 
370
          case HOOK:            return "HOOK";
 
371
          case COLON:           return "COLON";
 
372
          case OR:              return "OR";
 
373
          case AND:             return "AND";
 
374
          case INC:             return "INC";
 
375
          case DEC:             return "DEC";
 
376
          case DOT:             return "DOT";
 
377
          case FUNCTION:        return "FUNCTION";
 
378
          case EXPORT:          return "EXPORT";
 
379
          case IMPORT:          return "IMPORT";
 
380
          case IF:              return "IF";
 
381
          case ELSE:            return "ELSE";
 
382
          case SWITCH:          return "SWITCH";
 
383
          case CASE:            return "CASE";
 
384
          case DEFAULT:         return "DEFAULT";
 
385
          case WHILE:           return "WHILE";
 
386
          case DO:              return "DO";
 
387
          case FOR:             return "FOR";
 
388
          case BREAK:           return "BREAK";
 
389
          case CONTINUE:        return "CONTINUE";
 
390
          case VAR:             return "VAR";
 
391
          case WITH:            return "WITH";
 
392
          case CATCH:           return "CATCH";
 
393
          case FINALLY:         return "FINALLY";
 
394
          case VOID:            return "VOID";
 
395
          case RESERVED:        return "RESERVED";
 
396
          case EMPTY:           return "EMPTY";
 
397
          case BLOCK:           return "BLOCK";
 
398
          case LABEL:           return "LABEL";
 
399
          case TARGET:          return "TARGET";
 
400
          case LOOP:            return "LOOP";
 
401
          case EXPR_VOID:       return "EXPR_VOID";
 
402
          case EXPR_RESULT:     return "EXPR_RESULT";
 
403
          case JSR:             return "JSR";
 
404
          case SCRIPT:          return "SCRIPT";
 
405
          case TYPEOFNAME:      return "TYPEOFNAME";
 
406
          case USE_STACK:       return "USE_STACK";
 
407
          case SETPROP_OP:      return "SETPROP_OP";
 
408
          case SETELEM_OP:      return "SETELEM_OP";
 
409
          case LOCAL_BLOCK:     return "LOCAL_BLOCK";
 
410
          case SET_REF_OP:      return "SET_REF_OP";
 
411
          case DOTDOT:          return "DOTDOT";
 
412
          case COLONCOLON:      return "COLONCOLON";
 
413
          case XML:             return "XML";
 
414
          case DOTQUERY:        return "DOTQUERY";
 
415
          case XMLATTR:         return "XMLATTR";
 
416
          case XMLEND:          return "XMLEND";
 
417
          case TO_OBJECT:       return "TO_OBJECT";
 
418
          case TO_DOUBLE:       return "TO_DOUBLE";
 
419
          case GET:             return "GET";
 
420
          case SET:             return "SET";
 
421
          case LET:             return "LET";
 
422
          case YIELD:           return "YIELD";
 
423
          case CONST:           return "CONST";
 
424
          case SETCONST:        return "SETCONST";
 
425
          case ARRAYCOMP:       return "ARRAYCOMP";
 
426
          case WITHEXPR:        return "WITHEXPR";
 
427
          case LETEXPR:         return "LETEXPR";
 
428
          case DEBUGGER:        return "DEBUGGER";
 
429
        }
 
430
 
 
431
        // Token without name
 
432
        throw new IllegalStateException(String.valueOf(token));
 
433
    }
 
434
}