corba/src/share/classes/com/sun/tools/corba/se/idl/Preprocessor.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, 2000, 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
// -D57110<daz> Allow ID pragma directive to be applied to modules and update
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
//  feature in accordance to CORBA 2.3.
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
// -D59165<daz> Enable escaped identifiers when processing pragmas.
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
// -f60858.1<daz> Support -corba option, level = 2.2: Accept identifiers that
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
//  collide with keywords, in letter but not case, and issue a warning.
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
// -d62023 <daz> support -noWarn option; suppress inappropriate warnings when
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
//  parsing IBM-specific pragmas (#meta <interface_name> abstract).
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import java.io.File;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import java.io.FileNotFoundException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import java.math.BigInteger;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import java.util.Stack;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import java.util.Vector;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import com.sun.tools.corba.se.idl.RepositoryID;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import com.sun.tools.corba.se.idl.constExpr.*;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
 * This class should be extended if new pragmas are desired.  If the
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
 * preprocessor encounters a pragma name which it doesn't recognize
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
 * (anything other than ID, prefix, or version), it calls the method
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
 * otherPragmas.  This is the only method which need be overridden.
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
 * The Preprocessor base class has a number of utility-like methods
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
 * which can be used by the overridden otherPragmas method.
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
 **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
public class Preprocessor
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
   * Public zero-argument constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
  Preprocessor ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
  } // ctor
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
  void init (Parser p)
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
    parser  = p;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
    symbols = p.symbols;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
    macros  = p.macros;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
  } // init
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
  protected Object clone ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
    return new Preprocessor ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
  } // clone
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
  Token process (Token t) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    token   = t;
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
    scanner = parser.scanner;
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    // <f46082.40> Deactivate escaped identifier processing in Scanner while
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
    // preprocessing.
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
    //scanner.underscoreOK = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
    scanner.escapedOK = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
    try
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
      switch (token.type)
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
        case Token.Include:
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
          include ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
          break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        case Token.If:
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
          ifClause ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
          break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
        case Token.Ifdef:
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
          ifdef (false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
          break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        case Token.Ifndef:
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
          ifdef (true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
          break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
        case Token.Else:
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
          if (alreadyProcessedABranch.empty ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
            throw ParseException.elseNoIf (scanner);
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
          else if (((Boolean)alreadyProcessedABranch.peek ()).booleanValue ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
            skipToEndif ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
          else
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
          {
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
            alreadyProcessedABranch.pop ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
            alreadyProcessedABranch.push (new Boolean (true));
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
            token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
          }
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
          break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
        case Token.Elif:
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
          elif ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
          break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
        case Token.Endif:
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
          if (alreadyProcessedABranch.empty ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
            throw ParseException.endNoIf (scanner);
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
          else
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
          {
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
            alreadyProcessedABranch.pop ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
            token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
          }
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
        case Token.Define:
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
          define ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
          break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
        case Token.Undef:
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
          undefine ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
          break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
        case Token.Pragma:
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
          pragma ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
          break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
        case Token.Unknown:
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
          if (!parser.noWarn)
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
            ParseException.warning (scanner, Util.getMessage ("Preprocessor.unknown", token.name));
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        case Token.Error:
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
        case Token.Line:
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        case Token.Null:
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
          // ignore
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
        default:
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
          scanner.skipLineComment ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
          token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
    catch (IOException e)
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
      // <f46082.40> Underscore may now precede any identifier, so underscoreOK
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
      // is vestigal.  The Preprocessor must reset escapedOK so that Scanner
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
      // will process escaped identifiers according to specification.
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
      //scanner.underscoreOK = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
      scanner.escapedOK = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
      throw e;
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
    catch (ParseException e)
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
      // <f46082.40> See above.
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
      //scanner.underscoreOK = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
      scanner.escapedOK = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
      throw e;
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
    // <f46082.40> See above.
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
    //scanner.underscoreOK = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
    scanner.escapedOK = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
    return token;
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
  } // process
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
  private void include () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
    match (Token.Include);
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
    IncludeEntry include = parser.stFactory.includeEntry (parser.currentModule);
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
    include.sourceFile (scanner.fileEntry ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
    scanner.fileEntry ().addInclude (include);
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
    if (token.type == Token.StringLiteral)
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
      include2 (include);
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
    else if (token.type == Token.LessThan)
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
      include3 (include);
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
      int[] expected = {Token.StringLiteral, Token.LessThan};
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
      throw ParseException.syntaxError (scanner, expected, token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
    if (parser.currentModule instanceof ModuleEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
      ((ModuleEntry)parser.currentModule).addContained (include);
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
    else if (parser.currentModule instanceof InterfaceEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
      ((InterfaceEntry)parser.currentModule).addContained (include);
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
  } // include
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
  private void include2 (IncludeEntry include) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
    include.name ('"' + token.name + '"');
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
    include4 (include, token.name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
    match (Token.StringLiteral);
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
  } // include2
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
  private void include3 (IncludeEntry include) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
    if (token.type != Token.LessThan)
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
      // match will throw an exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
      match (Token.LessThan);
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
      try
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
        String includeFile = getUntil ('>');
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
        token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
        include.name ('<' + includeFile + '>');
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
        include4 (include, includeFile);
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
        match (Token.GreaterThan);
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
      catch (IOException e)
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
        throw ParseException.syntaxError (scanner, ">", "EOF");
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
  } // include3
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
  private void include4 (IncludeEntry include, String filename) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
    try
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
      // If the #include is at the global scope, it is treated as
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
      // an import statement.  If it is within some other scope, it
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
      // is treated as a normal #include.
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
      boolean includeIsImport = parser.currentModule == parser.topLevelModule;
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
      //daz
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
      include.absFilename (Util.getAbsolutePath (filename, parser.paths));
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
      scanner.scanIncludedFile (include, getFilename (filename), includeIsImport);
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
    catch (IOException e)
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
      ParseException.generic (scanner, e.toString ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
  } // include4
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
  private void define () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
    match (Token.Define);
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
    if (token.equals (Token.Identifier))
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
      String symbol = scanner.getStringToEOL ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
      symbols.put (token.name, symbol.trim ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
      match (Token.Identifier);
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
    else if (token.equals (Token.MacroIdentifier))
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
      symbols.put (token.name, '(' + scanner.getStringToEOL () . trim ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
      macros.addElement (token.name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
      match (Token.MacroIdentifier);
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
      throw ParseException.syntaxError (scanner, Token.Identifier, token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
  } // define
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
  private void undefine () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
    match (Token.Undef);
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
    if (token.equals (Token.Identifier))
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
      symbols.remove (token.name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
      macros.removeElement (token.name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
      match (Token.Identifier);
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
      throw ParseException.syntaxError (scanner, Token.Identifier, token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
  } // undefine
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
  private void ifClause () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
    match (Token.If);
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
    constExpr ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
  } // ifClause
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
  private void constExpr () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
    SymtabEntry dummyEntry = new SymtabEntry (parser.currentModule);
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
    dummyEntry.container (parser.currentModule);
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
    parser.parsingConditionalExpr = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
    Expression boolExpr = booleanConstExpr (dummyEntry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
    parser.parsingConditionalExpr = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
    boolean expr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
    if (boolExpr.value () instanceof Boolean)
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
      expr = ((Boolean)boolExpr.value ()).booleanValue ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
      expr = ((Number)boolExpr.value ()).longValue () != 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
    alreadyProcessedABranch.push (new Boolean (expr));
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
    if (!expr)
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
      skipToEndiforElse ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
  } // constExpr
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
  Expression booleanConstExpr (SymtabEntry entry) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
    Expression expr = orExpr (null, entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
    try
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
      expr.evaluate ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
    catch (EvaluationException e)
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
      ParseException.evaluationError (scanner, e.toString ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
    return expr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
  } // booleanConstExpr
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
  private Expression orExpr (Expression e, SymtabEntry entry) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
    if (e == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
      e = andExpr (null, entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
      BinaryExpr b = (BinaryExpr)e;
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
      b.right (andExpr (null, entry));
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
      e.rep (e.rep () + b.right ().rep ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
    if (token.equals (Token.DoubleBar))
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
      match (token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
      BooleanOr or = parser.exprFactory.booleanOr (e, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
      or.rep (e.rep () + " || ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
      return orExpr (or, entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
      return e;
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
  } // orExpr
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
  private Expression andExpr (Expression e, SymtabEntry entry) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
    if (e == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
      e = notExpr (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
      BinaryExpr b = (BinaryExpr)e;
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
      b.right (notExpr (entry));
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
      e.rep (e.rep () + b.right ().rep ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
    if (token.equals (Token.DoubleAmpersand))
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
      match (token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
      BooleanAnd and = parser.exprFactory.booleanAnd (e, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
      and.rep (e.rep () + " && ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
      return andExpr (and, entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
      return e;
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
  } // andExpr
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
  private Expression notExpr (/*boolean alreadySawExclamation, */SymtabEntry entry) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
    Expression e;
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
    if (token.equals (Token.Exclamation))
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
      match (Token.Exclamation);
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
      e = parser.exprFactory.booleanNot (definedExpr (entry));
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
      e.rep ("!" + ((BooleanNot)e).operand ().rep ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
      e = definedExpr (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
    return e;
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
  } // notExpr
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
  private Expression definedExpr (SymtabEntry entry) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
    if (token.equals (Token.Identifier) && token.name.equals ("defined"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
      match (Token.Identifier);
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
    return equalityExpr (null, entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
  } // definedExpr
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
  private Expression equalityExpr (Expression e, SymtabEntry entry) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
    if (e == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
      parser.token = token; // Since parser to parse, give it this token
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
      e = parser.constExp (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
      token = parser.token; // Since parser last parsed, get its token
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
      BinaryExpr b = (BinaryExpr)e;
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
      parser.token = token; // Since parser to parse, give it this token
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
      Expression constExpr = parser.constExp (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
      token = parser.token; // Since parser last parsed, get its token
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
      b.right (constExpr);
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
      e.rep (e.rep () + b.right ().rep ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
    if (token.equals (Token.DoubleEqual))
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
      match (token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
      Equal eq = parser.exprFactory.equal (e, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
      eq.rep (e.rep () + " == ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
      return equalityExpr (eq, entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
    else if (token.equals (Token.NotEqual))
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
      match (token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
      NotEqual n = parser.exprFactory.notEqual (e, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
      n.rep (e.rep () + " != ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
      return equalityExpr (n, entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
    else if (token.equals (Token.GreaterThan))
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
      match (token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
      GreaterThan g = parser.exprFactory.greaterThan (e, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
      g.rep (e.rep () + " > ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
      return equalityExpr (g, entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
    else if (token.equals (Token.GreaterEqual))
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
      match (token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
      GreaterEqual g = parser.exprFactory.greaterEqual (e, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
      g.rep (e.rep () + " >= ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
      return equalityExpr (g, entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
    else if (token.equals (Token.LessThan))
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
      match (token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
      LessThan l = parser.exprFactory.lessThan (e, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
      l.rep (e.rep () + " < ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
      return equalityExpr (l, entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
    else if (token.equals (Token.LessEqual))
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
      match (token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
      LessEqual l = parser.exprFactory.lessEqual (e, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
      l.rep (e.rep () + " <= ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
      return equalityExpr (l, entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
      return e;
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
  } // equalityExpr
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
  Expression primaryExpr (SymtabEntry entry) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
    Expression primary = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
    switch (token.type)
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
      case Token.Identifier:
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
        // If an identifier gets this far, it means that no
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
        // preprocessor variable was defined with that name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
        // Generate a FALSE boolean expr.
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
        //daz        primary = parser.exprFactory.terminal ("0", new Long (0));
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
        primary = parser.exprFactory.terminal ("0", BigInteger.valueOf (0));
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
        token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
      case Token.BooleanLiteral:
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
      case Token.CharacterLiteral:
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
      case Token.IntegerLiteral:
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
      case Token.FloatingPointLiteral:
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
      case Token.StringLiteral:
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
        //daz        primary = parser.literal ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
        primary = parser.literal (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
        token = parser.token;
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
      case Token.LeftParen:
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
        match (Token.LeftParen);
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
        primary = booleanConstExpr (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
        match (Token.RightParen);
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
        primary.rep ('(' + primary.rep () + ')');
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
      default:
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
        int[] expected = {Token.Literal, Token.LeftParen};
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
        throw ParseException.syntaxError (scanner, expected, token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
    return primary;
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
  } // primaryExpr
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
  private void ifDefine (boolean inParens, boolean not) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
    if (token.equals (Token.Identifier))
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
      if ((not && symbols.containsKey (token.name)) || (!not && !symbols.containsKey (token.name)))
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
        alreadyProcessedABranch.push (new Boolean (false));
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
        skipToEndiforElse ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
        alreadyProcessedABranch.push (new Boolean (true));
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
        match (Token.Identifier);
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
        if (inParens)
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
          match (Token.RightParen);
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
      throw ParseException.syntaxError (scanner, Token.Identifier, token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
  } // ifDefine
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
  private void ifdef (boolean not) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
    if (not)
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
      match (Token.Ifndef);
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
      match (Token.Ifdef);
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
    if (token.equals (Token.Identifier))
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
      if ((not && symbols.containsKey (token.name)) || (!not && !symbols.containsKey (token.name)))
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
        alreadyProcessedABranch.push (new Boolean (false));
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
        skipToEndiforElse ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
        alreadyProcessedABranch.push (new Boolean (true));
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
        match (Token.Identifier);
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
      throw ParseException.syntaxError (scanner, Token.Identifier, token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
  } // ifdef
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
  private void elif () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
    if (alreadyProcessedABranch.empty ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
      throw ParseException.elseNoIf (scanner);
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
    else if (((Boolean)alreadyProcessedABranch.peek ()).booleanValue ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
      skipToEndif ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
      match (Token.Elif);
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
      constExpr ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
  } // elif
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
  private void skipToEndiforElse () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
    while (!token.equals (Token.Endif) && !token.equals (Token.Else) && !token.equals (Token.Elif))
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
      if (token.equals (Token.Ifdef) || token.equals (Token.Ifndef))
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
        alreadyProcessedABranch.push (new Boolean (true));
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
        skipToEndif ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
        token = scanner.skipUntil ('#');
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
    process (token);
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
  } // skipToEndiforElse
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
  private void skipToEndif () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
    while (!token.equals (Token.Endif))
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
      token = scanner.skipUntil ('#');
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
      if (token.equals (Token.Ifdef) || token.equals (Token.Ifndef))
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
        alreadyProcessedABranch.push (new Boolean (true));
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
        skipToEndif ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
    alreadyProcessedABranch.pop ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
    match (Token.Endif);
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
  } // skipToEndif
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
  // For Pragma
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
  private void pragma () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
    match (Token.Pragma);
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
    String pragmaType = token.name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
    // <d59165> Enable escaped identifiers while processing pragma internals.
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
    // Don't enable until scanning pragma name!
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
    scanner.escapedOK = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
    match (Token.Identifier);
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
    // Add pragma entry to container
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
    PragmaEntry pragmaEntry = parser.stFactory.pragmaEntry (parser.currentModule);
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
    pragmaEntry.name (pragmaType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
    pragmaEntry.sourceFile (scanner.fileEntry ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
    pragmaEntry.data (scanner.currentLine ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
    if (parser.currentModule instanceof ModuleEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
      ((ModuleEntry)parser.currentModule).addContained (pragmaEntry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
    else if (parser.currentModule instanceof InterfaceEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
      ((InterfaceEntry)parser.currentModule).addContained (pragmaEntry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
    // If the token was an identifier, then pragmaType WILL be non-null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
    if (pragmaType.equals ("ID"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
      idPragma ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
    else if (pragmaType.equals ("prefix"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
      prefixPragma ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
    else if (pragmaType.equals ("version"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
      versionPragma ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
    // we are adding extensions to the Sun's idlj compiler to
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
    // handle correct code generation for local Objects, where
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
    // the OMG is taking a long time to formalize stuff.  Good
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
    // example of this is poa.idl.  Two proprietory pragmas
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
    // sun_local and sun_localservant are defined.  sun_local
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
    // generates only Holder and Helper classes, where read
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
    // and write methods throw marshal exceptions.  sun_localservant
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
    // is to generate Helper, Holder, and only Skel with _invoke
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
    // throwing an exception, since it does not make sense for
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
    // local objects.
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
    else if (pragmaType.equals ("sun_local"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
      localPragma();
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
    else if (pragmaType.equals ("sun_localservant"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
      localServantPragma();
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
      otherPragmas (pragmaType, tokenToString ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
      token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
    scanner.escapedOK = false; // <d59165> Disable escaped identifiers.
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
  } // pragma
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
  // <d57110> Pragma ID can be appiled to modules and it is an error to
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
  // name a type in more than one ID pragma directive.
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
  private Vector PragmaIDs = new Vector ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
  private void localPragma () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
    // Before I can use a parser method, I must make sure it has the current token.
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
    parser.token = token;
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
    // this makes sense only for interfaces, if specified for modules,
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
    // parser should throw an error
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
    SymtabEntry anErrorOccurred = new SymtabEntry ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
    SymtabEntry entry = parser.scopedName (parser.currentModule, anErrorOccurred);
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
    // Was the indicated type found in the symbol table?
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
    if (entry == anErrorOccurred)
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
        System.out.println("Error occured ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
      // Don't have to generate an error, scopedName already has.
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
      scanner.skipLineComment ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
      token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
      // by this time we have already parsed the ModuleName and the
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
      // pragma type, therefore setInterfaceType
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
      if (entry instanceof InterfaceEntry) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
          InterfaceEntry ent = (InterfaceEntry) entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
          ent.setInterfaceType (InterfaceEntry.LOCAL_SIGNATURE_ONLY);
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
      token = parser.token;
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
      String string = token.name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
      match (Token.StringLiteral);
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
      // for non-interfaces it doesn't make sense, so just ignore it
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
  } // localPragma
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
  private void localServantPragma () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
    // Before I can use a parser method, I must make sure it has the current token.
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
    parser.token = token;
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
    // this makes sense only for interfaces, if specified for modules,
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
    // parser should throw an error
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
    SymtabEntry anErrorOccurred = new SymtabEntry ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
    SymtabEntry entry = parser.scopedName (parser.currentModule, anErrorOccurred);
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
    // Was the indicated type found in the symbol table?
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
    if (entry == anErrorOccurred)
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
      // Don't have to generate an error, scopedName already has.
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
      scanner.skipLineComment ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
      token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
        System.out.println("Error occured ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
      // by this time we have already parsed the ModuleName and the
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
      // pragma type, therefore setInterfaceType
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
      if (entry instanceof InterfaceEntry) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
          InterfaceEntry ent = (InterfaceEntry) entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
          ent.setInterfaceType (InterfaceEntry.LOCALSERVANT);
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
      token = parser.token;
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
      String string = token.name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
      match (Token.StringLiteral);
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
      // for non-interfaces it doesn't make sense, so just ignore it
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
  } // localServantPragma
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
  private void idPragma () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
    // Before I can use a parser method, I must make sure it has the current token.
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
    parser.token = token;
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
    // <d57110> This flag will relax the restriction that the scopedNamed
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
    // in this ID pragma directive cannot resolve to a module.
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
    parser.isModuleLegalType (true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
    SymtabEntry anErrorOccurred = new SymtabEntry ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
    SymtabEntry entry = parser.scopedName (parser.currentModule, anErrorOccurred);
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
    parser.isModuleLegalType (false);  // <57110>
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
    // Was the indicated type found in the symbol table?
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
    if (entry == anErrorOccurred)
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
      // Don't have to generate an error, scopedName already has.
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
      scanner.skipLineComment ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
      token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
    // <d57110>
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
    //else if (PragmaIDs.contains (entry))
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
    //{
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
    //  ParseException.badRepIDAlreadyAssigned (scanner, entry.name ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
    //  scanner.skipLineComment ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
    //  token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
    //}
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
      token = parser.token;
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
      String string = token.name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
      // Do not match token until after raise exceptions, otherwise
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
      // incorrect messages will be emitted!
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
      if (PragmaIDs.contains (entry)) // <d57110>
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
        ParseException.badRepIDAlreadyAssigned (scanner, entry.name ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
      else if (!RepositoryID.hasValidForm (string)) // <d57110>
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
        ParseException.badRepIDForm (scanner, string);
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
        entry.repositoryID (new RepositoryID (string));
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
        PragmaIDs.addElement (entry); // <d57110>
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
      match (Token.StringLiteral);
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
  } // idPragma
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
  private void prefixPragma () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
    String string = token.name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
    match (Token.StringLiteral);
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
    ((IDLID)parser.repIDStack.peek ()).prefix (string);
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
    ((IDLID)parser.repIDStack.peek ()).name ("");
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
  } // prefixPragma
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
  private void versionPragma () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
    // Before I can use a parser method, I must make sure it has the current token.
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
    parser.token = token;
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
    // This flag will relax the restriction that the scopedNamed
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
    // in this Version pragma directive cannot resolve to a module.
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
    parser.isModuleLegalType (true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
    SymtabEntry anErrorOccurred = new SymtabEntry ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
    SymtabEntry entry = parser.scopedName (parser.currentModule, anErrorOccurred);
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
    // reset the flag to original value
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
    parser.isModuleLegalType (false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
    if (entry == anErrorOccurred)
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
      // Don't have to generate an error, scopedName already has.
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
      scanner.skipLineComment ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
      token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
      token = parser.token;
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
      String string = token.name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
      match (Token.FloatingPointLiteral);
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
      if (entry.repositoryID () instanceof IDLID)
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
        ((IDLID)entry.repositoryID ()).version (string);
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
  } // versionPragma
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
  private Vector pragmaHandlers = new Vector ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
  void registerPragma (PragmaHandler handler)
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
    pragmaHandlers.addElement (handler);
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
  } // registerPragma
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
  private void otherPragmas (String pragmaType, String currentToken) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
    for (int i = pragmaHandlers.size () - 1; i >= 0; --i)
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
      PragmaHandler handler = (PragmaHandler)pragmaHandlers.elementAt (i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
      if (handler.process (pragmaType, currentToken))
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
  } // otherPragmas
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
  /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
   * These protected methods are used by extenders, by the code
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
   * which implements otherPragma.
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
   */
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
   * Get the current token.
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
  String currentToken ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
    return tokenToString ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
  } // currentToken
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
   * This method, given an entry name, returns the entry with that name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
   * It can take fully or partially qualified names and returns the
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
   * appropriate entry defined within the current scope.  If no entry
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
   * exists, null is returned.
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
  SymtabEntry getEntryForName (String string)
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
    boolean partialScope = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
    boolean globalScope  = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
    // Change all ::'s to /'s
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
    if (string.startsWith ("::"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
      globalScope = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
      string = string.substring (2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
    int index = string.indexOf ("::");
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
    while (index >= 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
      partialScope = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
      string = string.substring (0, index) + '/' + string.substring (index + 2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
      index = string.indexOf ("::");
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
    // Get the entry for that string
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
    SymtabEntry entry = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
    if (globalScope)
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
      entry = parser.recursiveQualifiedEntry (string);
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
    else if (partialScope)
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
      entry = parser.recursivePQEntry (string, parser.currentModule);
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
      entry = parser.unqualifiedEntryWMod (string, parser.currentModule);
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
    return entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
  } // getEntryForName
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
   * This method returns a string of all of the characters from the
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
   * input file from the current position up to, but not including,
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
   * the end-of-line character(s).
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
  String getStringToEOL () throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
    return scanner.getStringToEOL ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
  } // getStringToEOL
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
   * This method returns a string of all of the characters from the
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
   * input file from the current position up to, but not including,
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
   * the given character.  It encapsulates parenthesis and quoted strings,
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
   * meaning it does not stop if the given character is found within
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
   * parentheses or quotes.  For instance, given the input of
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
   * `start(inside)end', getUntil ('n') will return "start(inside)e"
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
  String getUntil (char c) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
    return scanner.getUntil (c);
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
  } // getUntil
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
  private boolean lastWasMacroID = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
  private String tokenToString ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
    if (token.equals (Token.MacroIdentifier))
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
      lastWasMacroID = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
      return token.name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
    else if (token.equals (Token.Identifier))
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
      return token.name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
      return token.toString ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
  } // tokenToString
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
   * This method returns the next token String from the input file.
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
  String nextToken () throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
    if (lastWasMacroID)
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
      lastWasMacroID = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
      return "(";
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
      token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
      return tokenToString ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
  } // nextToken
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
   * This method assumes that the current token marks the beginning
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
   * of a scoped name.  It then parses the subsequent identifier and
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
   * double colon tokens, builds the scoped name, and finds the symbol
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
   * table entry with that name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
  SymtabEntry scopedName () throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
    boolean     globalScope  = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
    boolean     partialScope = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
    String      name         = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
    SymtabEntry entry        = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
    try
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   994
      if (token.equals (Token.DoubleColon))
02bb8761fcce Initial load
duke
parents:
diff changeset
   995
        globalScope = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   996
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   997
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   998
        if (token.equals (Token.Object))
02bb8761fcce Initial load
duke
parents:
diff changeset
   999
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1000
          name = "Object";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1001
          match (Token.Object);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1002
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1003
        else if (token.type == Token.ValueBase)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1004
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1005
          name = "ValueBase";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1006
          match (Token.ValueBase);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1007
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1008
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1009
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1010
          name = token.name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1011
          match (Token.Identifier);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1012
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1013
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1014
      while (token.equals (Token.DoubleColon))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1015
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1016
        match (Token.DoubleColon);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1017
        partialScope = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1018
        if (name != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1019
          name = name + '/' + token.name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1020
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1021
          name = token.name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1022
        match (Token.Identifier);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1023
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1024
      if (globalScope)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1025
        entry = parser.recursiveQualifiedEntry (name);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1026
      else if (partialScope)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1027
        entry = parser.recursivePQEntry (name, parser.currentModule);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1028
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1029
        entry = parser.unqualifiedEntryWMod (name, parser.currentModule);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1030
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1031
    catch (ParseException e)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1032
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1033
      entry = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1034
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1035
    return entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1036
  } // scopedName
02bb8761fcce Initial load
duke
parents:
diff changeset
  1037
02bb8761fcce Initial load
duke
parents:
diff changeset
  1038
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1039
   * Skip to the end of the line.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1040
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1041
  void skipToEOL () throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1042
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1043
    scanner.skipLineComment ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1044
  } // skipToEOL
02bb8761fcce Initial load
duke
parents:
diff changeset
  1045
02bb8761fcce Initial load
duke
parents:
diff changeset
  1046
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1047
   * This method skips the data in the input file until the specified
02bb8761fcce Initial load
duke
parents:
diff changeset
  1048
   * character is encountered, then it returns the next token.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1049
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1050
  String skipUntil (char c) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1051
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1052
    if (!(lastWasMacroID && c == '('))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1053
      token = scanner.skipUntil (c);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1054
    return tokenToString ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1055
  } // skipUntil
02bb8761fcce Initial load
duke
parents:
diff changeset
  1056
02bb8761fcce Initial load
duke
parents:
diff changeset
  1057
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1058
   * This method displays a Parser Exception complete with line number
02bb8761fcce Initial load
duke
parents:
diff changeset
  1059
   * and position information with the given message string.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1060
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1061
  void parseException (String message)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1062
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1063
    // <d62023> Suppress warnings
02bb8761fcce Initial load
duke
parents:
diff changeset
  1064
    if (!parser.noWarn)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1065
      ParseException.warning (scanner, message);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1066
  } // parseException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1067
02bb8761fcce Initial load
duke
parents:
diff changeset
  1068
  // For Pragma
02bb8761fcce Initial load
duke
parents:
diff changeset
  1069
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
  1070
  // For macro expansion
02bb8761fcce Initial load
duke
parents:
diff changeset
  1071
02bb8761fcce Initial load
duke
parents:
diff changeset
  1072
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1073
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1074
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1075
  String expandMacro (String macroDef, Token t) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1076
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1077
    token = t;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1078
    // Get the parameter values from the macro 'call'
02bb8761fcce Initial load
duke
parents:
diff changeset
  1079
    Vector parmValues = getParmValues ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1080
02bb8761fcce Initial load
duke
parents:
diff changeset
  1081
    // Get the parameter names from the macro definition
02bb8761fcce Initial load
duke
parents:
diff changeset
  1082
    // NOTE:  a newline character is appended here so that when
02bb8761fcce Initial load
duke
parents:
diff changeset
  1083
    // getStringToEOL is called, it stops scanning at the end
02bb8761fcce Initial load
duke
parents:
diff changeset
  1084
    // of this string.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1085
    scanner.scanString (macroDef + '\n');
02bb8761fcce Initial load
duke
parents:
diff changeset
  1086
    Vector parmNames = new Vector ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1087
    macro (parmNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1088
02bb8761fcce Initial load
duke
parents:
diff changeset
  1089
    if (parmValues.size () < parmNames.size ())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1090
      throw ParseException.syntaxError (scanner, Token.Comma, Token.RightParen);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1091
    else if (parmValues.size () > parmNames.size ())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1092
      throw ParseException.syntaxError (scanner, Token.RightParen, Token.Comma);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1093
02bb8761fcce Initial load
duke
parents:
diff changeset
  1094
    macroDef = scanner.getStringToEOL ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1095
    for (int i = 0; i < parmNames.size (); ++i)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1096
      macroDef = replaceAll (macroDef, (String)parmNames.elementAt (i), (String)parmValues.elementAt (i));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1097
    return removeDoublePound (macroDef);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1098
  } // expandMacro
02bb8761fcce Initial load
duke
parents:
diff changeset
  1099
02bb8761fcce Initial load
duke
parents:
diff changeset
  1100
  // This method is only used by the macro expansion methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1101
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1102
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1103
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1104
  private void miniMatch (int type) throws ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1105
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1106
    // A normal production would now execute:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1107
    // match (type);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1108
    // But match reads the next token.  I don't want to do that now.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1109
    // Just make sure the current token is a 'type'.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1110
    if (!token.equals (type))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1111
      throw ParseException.syntaxError (scanner, type, token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1112
  } // miniMatch
02bb8761fcce Initial load
duke
parents:
diff changeset
  1113
02bb8761fcce Initial load
duke
parents:
diff changeset
  1114
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1115
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1116
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1117
  private Vector getParmValues () throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1118
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1119
    Vector values = new Vector ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1120
    if (token.equals (Token.Identifier))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1121
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1122
      match (Token.Identifier);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1123
      miniMatch (Token.LeftParen);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1124
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1125
    else if (!token.equals (Token.MacroIdentifier))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1126
      throw ParseException.syntaxError (scanner, Token.Identifier, token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1127
02bb8761fcce Initial load
duke
parents:
diff changeset
  1128
    if (!token.equals (Token.RightParen))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1129
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1130
      values.addElement (scanner.getUntil (',', ')').trim ());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1131
      token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1132
      macroParmValues (values);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1133
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1134
    return values;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1135
  } // getParmValues
02bb8761fcce Initial load
duke
parents:
diff changeset
  1136
02bb8761fcce Initial load
duke
parents:
diff changeset
  1137
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1138
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1139
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1140
  private void macroParmValues (Vector values) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1141
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1142
    while (!token.equals (Token.RightParen))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1143
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1144
      miniMatch (Token.Comma);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1145
      values.addElement (scanner.getUntil (',', ')').trim ());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1146
      token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1147
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1148
  } // macroParmValues
02bb8761fcce Initial load
duke
parents:
diff changeset
  1149
02bb8761fcce Initial load
duke
parents:
diff changeset
  1150
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1151
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1152
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1153
  private void macro (Vector parmNames) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1154
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1155
    match (token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1156
    match (Token.LeftParen);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1157
    macroParms (parmNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1158
    miniMatch (Token.RightParen);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1159
  } // macro
02bb8761fcce Initial load
duke
parents:
diff changeset
  1160
02bb8761fcce Initial load
duke
parents:
diff changeset
  1161
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1162
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1163
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1164
  private void macroParms (Vector parmNames) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1165
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1166
    if (!token.equals (Token.RightParen))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1167
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1168
      parmNames.addElement (token.name);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1169
      match (Token.Identifier);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1170
      macroParms2 (parmNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1171
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1172
  } // macroParms
02bb8761fcce Initial load
duke
parents:
diff changeset
  1173
02bb8761fcce Initial load
duke
parents:
diff changeset
  1174
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1175
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1176
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1177
  private void macroParms2 (Vector parmNames) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1178
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1179
    while (!token.equals (Token.RightParen))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1180
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1181
      match (Token.Comma);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1182
      parmNames.addElement (token.name);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1183
      match (Token.Identifier);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1184
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1185
  } // macroParms2
02bb8761fcce Initial load
duke
parents:
diff changeset
  1186
02bb8761fcce Initial load
duke
parents:
diff changeset
  1187
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1188
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1189
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1190
  private String replaceAll (String string, String from, String to)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1191
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1192
    int index = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1193
    while (index != -1)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1194
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1195
      index = string.indexOf (from, index);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1196
      if (index != -1)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1197
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1198
        if (!embedded (string, index, index + from.length ()))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1199
          if (index > 0 && string.charAt(index) == '#')
02bb8761fcce Initial load
duke
parents:
diff changeset
  1200
            string = string.substring (0, index) + '"' + to + '"' + string.substring (index + from.length ());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1201
          else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1202
            string = string.substring (0, index) + to + string.substring (index + from.length ());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1203
        index += to.length ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1204
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1205
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1206
    return string;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1207
  } // replaceAll
02bb8761fcce Initial load
duke
parents:
diff changeset
  1208
02bb8761fcce Initial load
duke
parents:
diff changeset
  1209
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1210
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1211
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1212
  private boolean embedded (String string, int index, int endIndex)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1213
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1214
    // Don't replace if found substring is not an independent id.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1215
    // For example, don't replace "thither".indexOf ("it", 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1216
    boolean ret    = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1217
    char    preCh  = index == 0 ? ' ' : string.charAt (index - 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1218
    char    postCh = endIndex >= string.length () - 1 ? ' ' : string.charAt (endIndex);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1219
    if ((preCh >= 'a' && preCh <= 'z') || (preCh >= 'A' && preCh <= 'Z'))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1220
      ret = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1221
    else if ((postCh >= 'a' && postCh <= 'z') || (postCh >= 'A' && postCh <= 'Z') || (postCh >= '0' && postCh <= '9') || postCh == '_')
02bb8761fcce Initial load
duke
parents:
diff changeset
  1222
      ret = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1223
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1224
      ret = inQuotes (string, index);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1225
    return ret;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1226
  } // embedded
02bb8761fcce Initial load
duke
parents:
diff changeset
  1227
02bb8761fcce Initial load
duke
parents:
diff changeset
  1228
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1229
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1230
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1231
  private boolean inQuotes (String string, int index)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1232
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1233
    int quoteCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1234
    for (int i = 0; i < index; ++i)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1235
      if (string.charAt (i) == '"') ++quoteCount;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1236
    // If there are an odd number of quotes before this region,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1237
    // then this region is within quotes
02bb8761fcce Initial load
duke
parents:
diff changeset
  1238
    return quoteCount % 2 != 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1239
  } // inQuotes
02bb8761fcce Initial load
duke
parents:
diff changeset
  1240
02bb8761fcce Initial load
duke
parents:
diff changeset
  1241
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1242
   * Remove any occurrences of ##.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1243
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1244
  private String removeDoublePound (String string)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1245
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1246
    int index = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1247
    while (index != -1)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1248
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1249
      index = string.indexOf ("##", index);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1250
      if (index != -1)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1251
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1252
        int startSkip = index - 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1253
        int stopSkip  = index + 2;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1254
        if (startSkip < 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1255
          startSkip = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1256
        if (stopSkip >= string.length ())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1257
          stopSkip = string.length () - 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1258
        while (startSkip > 0 &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1259
               (string.charAt (startSkip) == ' ' ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  1260
               string.charAt (startSkip) == '\t'))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1261
          --startSkip;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1262
        while (stopSkip < string.length () - 1 &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1263
               (string.charAt (stopSkip) == ' ' ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  1264
               string.charAt (stopSkip) == '\t'))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1265
          ++stopSkip;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1266
        string = string.substring (0, startSkip + 1) + string.substring (stopSkip);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1267
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1268
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1269
    return string;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1270
  } // removeDoublePound
02bb8761fcce Initial load
duke
parents:
diff changeset
  1271
02bb8761fcce Initial load
duke
parents:
diff changeset
  1272
  // For macro expansion
02bb8761fcce Initial load
duke
parents:
diff changeset
  1273
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
  1274
02bb8761fcce Initial load
duke
parents:
diff changeset
  1275
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1276
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1277
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1278
  private String getFilename (String name) throws FileNotFoundException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1279
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1280
    String fullName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1281
    File file = new File (name);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1282
    if (file.canRead ())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1283
      fullName = name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1284
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1285
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1286
      Enumeration pathList = parser.paths.elements ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1287
      while (!file.canRead () && pathList.hasMoreElements ())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1288
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1289
        fullName = (String)pathList.nextElement () + File.separatorChar + name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1290
        file = new File (fullName);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1291
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1292
      if (!file.canRead ())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1293
        throw new FileNotFoundException (name);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1294
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1295
    return fullName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1296
  } // getFilename
02bb8761fcce Initial load
duke
parents:
diff changeset
  1297
02bb8761fcce Initial load
duke
parents:
diff changeset
  1298
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1299
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1300
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1301
  private void match (int type) throws IOException, ParseException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1302
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1303
    if (!token.equals (type))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1304
      throw ParseException.syntaxError (scanner, type, token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1305
    token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1306
02bb8761fcce Initial load
duke
parents:
diff changeset
  1307
    // <d62023> Added for convenience, but commented-out because there is
02bb8761fcce Initial load
duke
parents:
diff changeset
  1308
    // no reason to issue warnings for tokens scanned during preprocessing.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1309
    // See issueTokenWarnings().
02bb8761fcce Initial load
duke
parents:
diff changeset
  1310
    //issueTokenWarnings ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1311
02bb8761fcce Initial load
duke
parents:
diff changeset
  1312
    //System.out.println ("Preprocessor.match token = " + token.type);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1313
    //if (token.equals (Token.Identifier) || token.equals (Token.MacroIdentifier))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1314
    //  System.out.println ("Preprocessor.match token name = " + token.name);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1315
02bb8761fcce Initial load
duke
parents:
diff changeset
  1316
    // If the token is a defined thingy, scan the defined string
02bb8761fcce Initial load
duke
parents:
diff changeset
  1317
    // instead of the input stream for a while.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1318
    if (token.equals (Token.Identifier) || token.equals (Token.MacroIdentifier))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1319
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1320
      String string = (String)symbols.get (token.name);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1321
      if (string != null && !string.equals (""))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1322
        // If this is a macro, parse the macro
02bb8761fcce Initial load
duke
parents:
diff changeset
  1323
        if (macros.contains (token.name))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1324
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1325
          scanner.scanString (expandMacro (string, token));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1326
          token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1327
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1328
        // else this is just a normal define
02bb8761fcce Initial load
duke
parents:
diff changeset
  1329
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1330
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1331
          scanner.scanString (string);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1332
          token = scanner.getToken ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1333
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1334
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1335
  } // match
02bb8761fcce Initial load
duke
parents:
diff changeset
  1336
02bb8761fcce Initial load
duke
parents:
diff changeset
  1337
  // <d62023>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1338
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1339
   * Issue warnings about tokens scanned during preprocessing.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1340
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1341
  private void issueTokenWarnings ()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1342
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1343
    if (parser.noWarn)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1344
      return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1345
02bb8761fcce Initial load
duke
parents:
diff changeset
  1346
    // There are no keywords defined for preprocessing (only directives), so:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1347
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1348
    // 1.) Do not issue warnings for identifiers known to be keywords in
02bb8761fcce Initial load
duke
parents:
diff changeset
  1349
    //     another level of IDL.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1350
    // 2.) Do not issue warnings for identifiers that collide with keywords
02bb8761fcce Initial load
duke
parents:
diff changeset
  1351
    //     in letter, but not case.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1352
    // 3.) Do not issue warnings for deprecated keywords.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1353
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1354
    // Should we warn when a macro identifier replaces a keyword?  Hmmm.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1355
02bb8761fcce Initial load
duke
parents:
diff changeset
  1356
    // Deprecated directives?  None to date.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1357
    //if (token.isDirective () && token.isDeprecated ())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1358
    //  ParseException.warning (scanner, Util.getMesage ("Deprecated.directive", token.name));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1359
  } // issueTokenWarnings
02bb8761fcce Initial load
duke
parents:
diff changeset
  1360
02bb8761fcce Initial load
duke
parents:
diff changeset
  1361
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1362
   * This method is called when the parser encounters a left curly brace.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1363
   * An extender of PragmaHandler may find scope information useful.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1364
   * For example, the prefix pragma takes effect as soon as it is
02bb8761fcce Initial load
duke
parents:
diff changeset
  1365
   * encountered and stays in effect until the current scope is closed.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1366
   * If a similar pragma extension is desired, then the openScope and
02bb8761fcce Initial load
duke
parents:
diff changeset
  1367
   * closeScope methods are available for overriding.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1368
   * @param entry the symbol table entry whose scope has just been opened.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1369
   *  Be aware that, since the scope has just been entered, this entry is
02bb8761fcce Initial load
duke
parents:
diff changeset
  1370
   *  incomplete at this point.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1371
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1372
  void openScope (SymtabEntry entry)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1373
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1374
    for (int i = pragmaHandlers.size () - 1; i >= 0; --i)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1375
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1376
      PragmaHandler handler = (PragmaHandler)pragmaHandlers.elementAt (i);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1377
      handler.openScope (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1378
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1379
  } // openScope
02bb8761fcce Initial load
duke
parents:
diff changeset
  1380
02bb8761fcce Initial load
duke
parents:
diff changeset
  1381
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1382
   * This method is called when the parser encounters a right curly brace.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1383
   * An extender of PragmaHandler may find scope information useful.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1384
   * For example, the prefix pragma takes effect as soon as it is
02bb8761fcce Initial load
duke
parents:
diff changeset
  1385
   * encountered and stays in effect until the current scope is closed.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1386
   * If a similar pragma extension is desired, then the openScope and
02bb8761fcce Initial load
duke
parents:
diff changeset
  1387
   * closeScope methods are available for overriding.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1388
   * @param entry the symbol table entry whose scope has just been closed.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1389
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1390
  void closeScope (SymtabEntry entry)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1391
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1392
    for (int i = pragmaHandlers.size () - 1; i >= 0; --i)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1393
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1394
      PragmaHandler handler = (PragmaHandler)pragmaHandlers.elementAt (i);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1395
      handler.closeScope (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1396
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1397
  } // closeScope
02bb8761fcce Initial load
duke
parents:
diff changeset
  1398
02bb8761fcce Initial load
duke
parents:
diff changeset
  1399
  private Parser    parser;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1400
  private Scanner   scanner;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1401
  private Hashtable symbols;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1402
  private Vector    macros;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1403
02bb8761fcce Initial load
duke
parents:
diff changeset
  1404
  // The logic associated with this stack is scattered above.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1405
  // A concise map of the logic is:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1406
  // case #if false, #ifdef false, #ifndef true
02bb8761fcce Initial load
duke
parents:
diff changeset
  1407
  //   push (false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1408
  //   skipToEndifOrElse ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1409
  // case #if true, #ifdef true, #ifndef false
02bb8761fcce Initial load
duke
parents:
diff changeset
  1410
  //   push (true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1411
  // case #elif <conditional>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1412
  //   if (top == true)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1413
  //     skipToEndif ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1414
  //   else if (conditional == true)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1415
  //     pop ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1416
  //     push (true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1417
  //   else if (conditional == false)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1418
  //     skipToEndifOrElse ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1419
  // case #else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1420
  //   if (top == true)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1421
  //     skipToEndif ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1422
  //   else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1423
  //     pop ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1424
  //     push (true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1425
  // case #endif
02bb8761fcce Initial load
duke
parents:
diff changeset
  1426
  //   pop ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1427
  private        Stack  alreadyProcessedABranch = new Stack ();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1428
                 Token  token;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1429
02bb8761fcce Initial load
duke
parents:
diff changeset
  1430
  private static String indent = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1431
}