corba/src/share/classes/com/sun/tools/corba/se/idl/Token.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
 * COMPONENT_NAME: idl.parser
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * ORIGINS: 27
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
 * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
package com.sun.tools.corba.se.idl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
// NOTES:
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
// -F46082.51<daz> Remove -stateful feature.
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
// -D59166<daz> Add support for keyword/identifier collision detection.  This
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
//  feature is implemented here, rather than class Scanner, to allow the Parser
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
//  to handle the problem.
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
// -F60858.1<daz> Support -corba option, level <= 2.2: identify 2.3 keywords.
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
// -D62023<daz> Support -corba option, level <= 2.3, identify 2.4 keywords.
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
// KMC Support -corba, level <= 3.0.  Added 3.0 keywords.
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
//
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
// Should escaped Identifier should be a type rather than an attribute?
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
//
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
 * Class Token represents a lexeme appearing within an IDL source.  Every
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
 * Token has a type.  Depending on its type and on the supported version
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
 * of IDL, a Token will have other associated attributes, such as a name
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
 * (identifier, e.g.), and whether it is escaped, deprecated, or is a type
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
 * that is known to be in a future version of IDL.
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
 **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
class Token
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
  // Available types
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
  static final int                // Keywords
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
      Any                  =   0, // 2.2
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
      Attribute            =   1, // |
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
      Boolean              =   2, // .
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
      Case                 =   3, // .
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
      Char                 =   4, // .
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
      Const                =   5,
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
      Context              =   6,
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
      Default              =   7,
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
      Double               =   8,
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
      Enum                 =   9,
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
      Exception            =  10,
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
      FALSE                =  11,
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
      Fixed                =  12, // New addition
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
      Float                =  13,
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
      In                   =  14,
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
      Inout                =  15,
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
      Interface            =  16,
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
      Long                 =  17,
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
      Module               =  18,
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
      Native               =  19, // New addition
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
      Object               =  20,
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
      Octet                =  21,
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
      Oneway               =  22,
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
      Out                  =  23,
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
      Raises               =  24,
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
      Readonly             =  25,
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
      Sequence             =  26,
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
      Short                =  27,
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
      String               =  28,
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
      Struct               =  29,
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
      Switch               =  30,
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
      TRUE                 =  31,
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
      Typedef              =  32,
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
      Unsigned             =  33, // .
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
      Union                =  34, // .
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
      Void                 =  35, // .
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
      Wchar                =  36, // |
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
      Wstring              =  37, // 2.2
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
      // <f46082.40> New OBV keywords...
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
      // <d62023> In 2.4rtf, "factory" is synonymous to "init" in 2.3
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
      Init                 =  38, // 2.3 only
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
      Abstract             =  39, // 2.3        2.4rtf
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
      Custom               =  40, // |          |
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
      Private              =  41, // |          |
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
      Public               =  42, // |          |
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
      Supports             =  43, // |          |
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
      Truncatable          =  44, // |          |
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
      ValueBase            =  45, // |          |
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
      Valuetype            =  46, // 2.3        2.4rtf
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
      Factory              =  47, //            2.4rtf only
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
      // Keywords in CORBA 3.0
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
      Component            =  48,
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
      Consumes             =  49,
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
      Emits                =  50,
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
      Finder               =  51,
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
      GetRaises            =  52,
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
      Home                 =  53,
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
      Import               =  54,
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
      Local                =  55,
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
      Manages              =  56,
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
      Multiple             =  57,
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
      PrimaryKey           =  58,
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
      Provides             =  59,
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
      Publishes            =  60,
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
      SetRaises            =  61,
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
      TypeId               =  62,
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
      TypePrefix           =  63,
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
      Uses                 =  64,
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
      Identifier           =  80, // Identifier
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
      MacroIdentifier      =  81, // Macro Identifier
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
      Semicolon            = 100, // Symbols
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
      LeftBrace            = 101,
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
      RightBrace           = 102,
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
      Colon                = 103,
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
      Comma                = 104,
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
      Equal                = 105,
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
      Plus                 = 106,
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
      Minus                = 107,
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
      LeftParen            = 108,
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
      RightParen           = 109,
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
      LessThan             = 110,
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
      GreaterThan          = 111,
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
      LeftBracket          = 112,
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
      RightBracket         = 113,
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
      Apostrophe           = 114,
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
      Quote                = 115,
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
      Backslash            = 116,
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
      Bar                  = 117,
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
      Carat                = 118,
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
      Ampersand            = 119,
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
      Star                 = 120,
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
      Slash                = 121,
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
      Percent              = 122,
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
      Tilde                = 123,
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
      DoubleColon          = 124,
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
      ShiftLeft            = 125,
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
      ShiftRight           = 126,
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
      Period               = 127,
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
      Hash                 = 128,
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
      Exclamation          = 129,
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
      DoubleEqual          = 130,
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
      NotEqual             = 131,
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
      GreaterEqual         = 132,
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
      LessEqual            = 133,
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
      DoubleBar            = 134,
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
      DoubleAmpersand      = 135,
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
      BooleanLiteral       = 200, // Literals
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
      CharacterLiteral     = 201,
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
      IntegerLiteral       = 202,
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
      FloatingPointLiteral = 203,
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
      StringLiteral        = 204,
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
      Literal              = 205,
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
      Define               = 300, // Directives
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
      Undef                = 301,
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
      If                   = 302,
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
      Ifdef                = 303,
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
      Ifndef               = 304,
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
      Else                 = 305,
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
      Elif                 = 306,
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
      Include              = 307,
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
      Endif                = 308,
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
      Line                 = 309,
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
      Error                = 310,
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
      Pragma               = 311,
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
      Null                 = 312,
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
      Unknown              = 313,
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
      Defined              = 400,
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
      // <f46082.40> Keyword identifiers.
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
      //Abstract             = 500,
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
      //Custom               = 501,
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
      //Init                 = 502,
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
      //Private2             = 503,
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
      //Public2              = 504,
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
      //Supports             = 505,
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
      //Truncatable          = 506,
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
      //ValueBase            = 507,
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
      //Valuetype            = 508,
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
      EOF                  = 999; // End of Input
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
  // Available types
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
  // Keywords
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
  static final String [] Keywords = {
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
      "any",         "attribute",    "boolean",
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
      "case",        "char",         "const",
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
      "context",     "default",      "double",
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
      "enum",        "exception",    "FALSE",      "fixed",
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
      "float",       "in",           "inout",
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
      "interface",   "long",         "module",     "native",
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
      "Object",      "octet",        "oneway",
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
      "out",         "raises",       "readonly",
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
      "sequence",    "short",        "string",
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
      "struct",      "switch",       "TRUE",
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
      "typedef",     "unsigned",     "union",
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
      "void",        "wchar",        "wstring",
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
      "init", // In 2.3 only
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
      "abstract",     "custom",      "private",      // 2.3 and 2.4rtf
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
      "public",       "supports",    "truncatable",
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
      "ValueBase",    "valuetype",
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
      "factory",  // In 2.4rtf only
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
      // CORBA 3.0 keywords
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
      "component",      "consumes",     "emits",
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
      "finder",         "getRaises",    "home",
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
      "import",         "local",        "manages",
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
      "multiple",       "primaryKey",   "provides",
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
      "publishes",      "setRaises",    "supports",
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
      "typeId",         "typePrefix",   "uses" } ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
  // <f46082.40> Remove keyword identifiers.
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
  //static final int
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
  //    FirstKeywordIdentifier = 500,
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
  //    LastKeywordIdentifier  = Valuetype;
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
  //
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
  //static final String[] KeywordIdentifiers = {
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
  //    "abstract",    "custom",    "init",
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
  //    "private",     "public",    "supports",
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
  //    "truncatable", "valueBase", "valuetype"};
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
   * Determine whether this token is a keyword.
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
   * @return true iff this token is a keyword.
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
  boolean isKeyword ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
    return type >= FirstKeyword && type <= LastKeyword;
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
  } // isKeyword
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
  private static final int
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
      FirstKeyword = Any, // 0
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
      LastKeyword  = Uses;
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
  // <f60858.1> Keywords in CORBA 2.2 that we support.
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
  private static final int
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
      First22Keyword = Any, // 0
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
      Last22Keyword  = Wstring;
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
  // <f60858.1> New keywords in CORBA 2.3 (preliminary) that we support.
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
  private static final int
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
      First23Keyword = Init,
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
      Last23Keyword  = Valuetype;
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
  // <d62023> New keywords in CORBA 2.4rtf (accepted 2.3) that we support.
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
  // Note that "factory" replaces "init".  Scanner must account for this in
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
  // keyword scan.
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
  private static final int
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
      First24rtfKeyword = Abstract,
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
      Last24rtfKeyword  = Factory;
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
  // New keywords in CORBA 3.0 (from CORBA components v. 1)
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
  private static final int
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
      First30Keyword    = Component,
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
      Last30Keyword     = Uses;
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
  // Current valid CORBA levels:
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
  // 2.2 (or <2.3): the default: no OBV support
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
  // 2.3: add OBV with init
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
  // >2.3: OBV with init replcaed by factory
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
  // 3.0: adds components, attr exceptions, local interfaces, type repository
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
  //      decls.
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
  private static final int CORBA_LEVEL_22 = 0 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
  private static final int CORBA_LEVEL_23 = 1 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
  private static final int CORBA_LEVEL_24RTF = 2 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
  private static final int CORBA_LEVEL_30 = 3 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
  // Do the conversion from a floating point CORBA level to an int
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
  private static int getLevel( float cLevel )
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
    if (cLevel < 2.3f)
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
        return CORBA_LEVEL_22 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
    if (Util.absDelta( cLevel, 2.3f ) < 0.001f)
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
        return CORBA_LEVEL_23 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
    if (cLevel < 3.0f)
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
        return CORBA_LEVEL_24RTF ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
    return CORBA_LEVEL_30 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
  // Return the last keyword corresponding to a particular CORBA level
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
  private static int getLastKeyword( int level )
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
    if (level == CORBA_LEVEL_22)
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
        return Last22Keyword ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
    if (level == CORBA_LEVEL_23)
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
        return Last23Keyword ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
    if (level == CORBA_LEVEL_24RTF)
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
        return Last24rtfKeyword ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
    return Last30Keyword ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
  /** Create a keyword token from a string.
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
  * Determines whether the string is an IDL keyword based on the corbaLevel.
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
  * Strings that are keywords at higher CORBA levels than the corbaLevel
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
  * argument create identifier tokens that are marked as "collidesWithKeyword", unless
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
  * escapedOK is FALSE, which is the case only when preprocessing is taking place.
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
  * In the case of the "init" keyword, which was only defined in CORBA 2.3, init is
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
  * marked deprecated in CORBA 2.3 since it is not supported in higher levels.
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
  * @param String string The string we are converting to a token.
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
  * @param float corbaLevel The CORBA level, currently in the interval [2.2, 3.0].
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
  * @param boolean escapedOK Flag set true if _ is used to escape an IDL keyword for use
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
  * as an identifier.
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
  * @param boolean[] collidesWithKeyword is an array containing one value: a flag
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
  * representing whether this string is an identifier that collides with a keyword.
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
  * This is set by this method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
  * @returns Token The resulting Token corresponding to string.
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
  */
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
  public static Token makeKeywordToken(
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
    String string, float corbaLevel, boolean escapedOK, boolean[] collision )
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
    int level = getLevel( corbaLevel ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
    int lastKeyword = getLastKeyword( level ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
    boolean deprecated = false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
    collision[0] = false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
    // If the string is a keyword token, return that token
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
    for (int i = Token.FirstKeyword; i <= Token.LastKeyword; ++i) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
        if (string.equals (Token.Keywords[i])) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
            // <f60858.1><d62023> Return identifier if lexeme is a keyword in a
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
            // greater CORBA level; collect attributes indicating future keyword/
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
            // identifier collision and deprecations.
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
            // Init is really a funny case.  I don't want to mark it as
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
            // a keyword collision in the 2.2 case, since it was only
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
            // defined to be a keyword briefly in 2.3.
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
            if (i == Token.Init) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
                if (level == CORBA_LEVEL_23)
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
                    deprecated = true ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
                else
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
                    break ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
            if (i > lastKeyword) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
                collision[0] |= escapedOK; // escapedOK true iff not preprocessing
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
                break ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
            if (string.equals ("TRUE") || string.equals ("FALSE"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
                return new Token (Token.BooleanLiteral, string) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
                return new Token (i, deprecated);
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
        } else if (string.equalsIgnoreCase (Token.Keywords[i])) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
            // <d62023> PU!  This will go away in a future release, because
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
            // case-insensitive keyword checking will be standard.  For now,
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
            // indicate that a keyword collision has occurred.
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
            collision[0] |= true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
    } // for i <= lastKeyword
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
    return null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
  } // makeKeywordToken
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
  // Keywords
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
  // Symbols
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
  static final int
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
      FirstSymbol = 100,
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
      LastSymbol  = 199;
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
  static final String [] Symbols = {
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
      ";",  "{",  "}",  ":", ",", "=", "+",  "-",
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
      "(",  ")",  "<",  ">", "[", "]", "'",  "\"",
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
      "\\", "|",  "^",  "&", "*", "/", "%",  "~",
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
      "::", "<<", ">>", ".", "#", "!", "==", "!=",
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
      ">=", "<=", "||", "&&"};
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
  // Symbols
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
  // Literals
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
  static final int
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
      FirstLiteral = 200,
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
      LastLiteral  = 299;
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
  static final String [] Literals = {
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
      Util.getMessage ("Token.boolLit"),
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
      Util.getMessage ("Token.charLit"),
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
      Util.getMessage ("Token.intLit"),
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
      Util.getMessage ("Token.floatLit"),
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
      Util.getMessage ("Token.stringLit"),
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
      Util.getMessage ("Token.literal")};
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
  // Literals
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
  // Directives
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
   * Determine whether this token is a preprocessor directive.
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
   * @return true iff this token is a preprocessor directive.
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
  boolean isDirective ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
    return type >= FirstDirective && type <= LastDirective;
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
  } // isDirective
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
  static final int
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
      FirstDirective = 300,
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
      LastDirective  = 399;
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
  static final String [] Directives = {
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
      "define", "undef",  "if",
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
      "ifdef",  "ifndef", "else",
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
      "elif",   "include","endif",
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
      "line",   "error",  "pragma",
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
      ""};
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
  // Directives
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
  // Specials
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
  static final int
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
      FirstSpecial = 400,
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
      LastSpecial  = 499;
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
  static final String [] Special = {
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
      "defined"};
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
  // Specials
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
   * Constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
   * @return a Token of the supplied type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
  Token (int tokenType)
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
    type = tokenType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
  } // ctor
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
  // <d62023>
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
   * Constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
   * @return a Token having the supplied attributes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
  Token (int tokenType, boolean deprecated)
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
    this.type = tokenType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
    this.isDeprecated = deprecated;
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
  } // ctor
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
   * Constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
   * @return a Token having the supplied attributes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
  Token (int tokenType, String tokenName)
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
    type = tokenType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
    name = tokenName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
  } // ctor
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
   * Constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
   * @return a Token having the supplied attribtues.
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
   *  having
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
  Token (int tokenType, String tokenName, boolean isWide)
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
    this (tokenType, tokenName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
    this.isWide = isWide;
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
  } // ctor
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
  // <d62023>
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
   * Constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
   * @return a Token having the supplied attributes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
  Token (int tokenType, String tokenName, boolean escaped,
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
      boolean collision, boolean deprecated)
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
    this (tokenType, tokenName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
    this.isEscaped = escaped;
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
    this.collidesWithKeyword = collision;
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
    this.isDeprecated = deprecated;
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
  } // ctor
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
  // <f46082.40> Remove keyword identifiers.
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
  ///**
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
  // * Constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
  // * @return a Token having the supplied attributes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
  // **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
  //Token (int tokenType, int tokenSubType, String tokenName)
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
  //{
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
  //  type    = tokenType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
  //  subType = tokenSubType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
  //  name    = tokenName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
  //} // ctor
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
   * Get the String representation of this Token.
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
   * @return a String containing representation of this Token.
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
  public String toString ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
    if (type == Identifier)
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
      return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
    if (type == MacroIdentifier)
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
      return name + '(';
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
    return Token.toString (type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
  } // toString
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
   * Get the String representation of a supplied Token type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
   * @return A String containing the name of the supplied Token type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
  static String toString (int type)
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
    if (type <= LastKeyword)
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
      return Keywords[type];
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
    // <f46082.40> Remove keyword identifiers.
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
    //if ( (type >= FirstKeywordIdentifier) && (type <= LastKeywordIdentifier) )
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
    //  return KeywordIdentifiers[ type - FirstKeywordIdentifier ];
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
    if (type == Identifier || type == MacroIdentifier)
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
      return Util.getMessage ("Token.identifier");
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
    if (type <= LastSymbol)
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
      return Symbols[type - FirstSymbol];
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
    if (type <= LastLiteral)
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
      return Literals[type - FirstLiteral];
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
    if (type <= LastDirective)
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
      return Directives[type - FirstDirective];
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
    if (type <= LastSpecial)
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
      return Special[type - FirstSpecial];
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
    if (type == EOF)
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
      return Util.getMessage ("Token.endOfFile");
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
    return Util.getMessage ("Token.unknown");
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
  } // toString
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
  // Accessors and Predicates
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
   * Determine whether this token equals a supplied token.
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
   * @return true iff the types and names of this and the supplied
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
   * Token are equal.
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
  boolean equals (Token that)
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
    if (this.type == that.type)
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
      if (this.name == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
        return that.name == null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
        return this.name.equals (that.name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
    return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
  } // equals
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
   * Determine whether the this token is of a supplied type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
   * @return true iff the type of this Token equals that supplied.
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
  boolean equals (int type)
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
    return this.type == type;
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
  } // equals
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
   * Determine whether this identifier has the supplied name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
   * @return true iff this Token is an identifier having the supplied name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
  boolean equals (String name)
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
    return (this.type == Identifier && this.name.equals (name));
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
  } // equals
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
  // Although isEscaped is an independent attribute, it may be true only
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
  // when type is Identifer.
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
   * Accessor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
   * @return true iff this token is an escaped identifier.
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
  public boolean isEscaped ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
    return type == Identifier && isEscaped;
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
  } // isEscaped
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
  // <d62023>
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
   * Accessor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
   * @return true iff this token is an identifier having a name matching
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
   * a keyword in a version of CORBA greater than the specified CORBA level,
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
   * or iff it matches a keyword in letter, but note case.
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
  public boolean collidesWithKeyword ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
    return collidesWithKeyword;
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
  } // collidesWithKeyword
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
  // <d62023> Storing deprecation information in a token seems a natural
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
  // means to notify the parser about deprecated types.
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
   * Accessor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
   * @return true iff this token is a deprecated lexeme or lexical type with
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
   * respect to the specified CORBA level.
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
  public boolean isDeprecated ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
    return isDeprecated;
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
  // isDeprecated
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
  public boolean isWide()
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
      return isWide ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
  // <d59166><d62023> It's more efficient if Scanner determines this attribute.
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
   * Determine whether this token collides with an IDL keyword.
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
  //public boolean collidesWithKeyword ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
  //{
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
  //  if (name != null && type == Identifier && !isEscaped)
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
  //  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
  //    String lcName = name.toLowerCase ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
  //    for (int i = FirstKeyword; i <= LastKeyword; ++i)
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
  //      if (lcName.equals (Token.Keywords [i].toLowerCase ()))
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
  //        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
  //  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
  //  return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
  //} // collidesWithKeyword
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
  // Accessors and Predicates
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
   * Code identifying the lexical class to which this token belongs, e.g.,
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
   * Keyword, Identifier, ...
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
  int type;
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
   * Lexeme extracted from the source for this token.
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
  String name = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
   * Source comment associated with this token.
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
  Comment comment = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
   * True iff this token is an escaped identifier.
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
  boolean isEscaped = false; // <d59165>
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
   * True iff this token is an identifier that is known to be a keyword
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
   * in another version of CORBA or matches a keyword in letter, but not case.
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
  boolean collidesWithKeyword = false;  // <d62023>
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
   * True iff this token is deprecated.
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
  boolean isDeprecated = false;  // <d62023>
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
  // <f46082.40> Remove keyword identifier implementation.
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
  ///**
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
  // * Non-zero only when type = [Macro]Identifier
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
  // **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
  //int subType = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
  boolean isWide = false ;  // Only for string and char literals: indicates that this is
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
                            // a wide string or char.
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
} // class Token