jdk/src/jdk.rmic/share/classes/sun/tools/java/Scanner.java
author amlu
Tue, 10 Feb 2015 12:28:02 -0500
changeset 28856 1c525c8d1cf7
parent 25859 3317bb8137f4
permissions -rw-r--r--
8069255: Suppress deprecation warnings in jdk.rmic module (jdk repo) Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
28856
1c525c8d1cf7 8069255: Suppress deprecation warnings in jdk.rmic module (jdk repo)
amlu
parents: 25859
diff changeset
     2
 * Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.java;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A Scanner for Java tokens. Errors are reported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * to the environment object.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The scanner keeps track of the current token,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * the value of the current token (if any), and the start
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * position of the current token.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The scan() method advances the scanner to the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * token in the input.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The match() method is used to quickly match opening
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * brackets (ie: '(', '{', or '[') with their closing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * counter part. This is useful during error recovery.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * An position consists of: ((linenr << WHEREOFFSETBITS) | offset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * this means that both the line number and the exact offset into
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * the file are encoded in each position value.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * The compiler treats either "\n", "\r" or "\r\n" as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * end of a line.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * WARNING: The contents of this source file are not part of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * supported API.  Code that depends on them does so at its own risk:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * they are subject to change or removal without notice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author      Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
28856
1c525c8d1cf7 8069255: Suppress deprecation warnings in jdk.rmic module (jdk repo)
amlu
parents: 25859
diff changeset
    61
@SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
class Scanner implements Constants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * The increment for each character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static final long OFFSETINC = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * The increment for each line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static final long LINEINC = 1L << WHEREOFFSETBITS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * End of input
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static final int EOF = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Where errors are reported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public Environment env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Input reader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected ScannerInputReader in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * If true, present all comments as tokens.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Contents are not saved, but positions are recorded accurately,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * so the comment can be recovered from the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Line terminations are also returned as comment tokens,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * and may be distinguished by their start and end positions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * which are equal (meaning, these tokens contain no chars).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
   public boolean scanComments = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Current token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public int token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * The position of the current token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public long pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * The position of the previous token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public long prevPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * The current character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    protected int ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Token values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public char charValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public int intValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public long longValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public float floatValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public double doubleValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public String stringValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public Identifier idValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public int radix;   // Radix, when reading int or long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * A doc comment preceding the most recent token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public String docComment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * A growable character buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private char buffer[] = new char[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private void growBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        char newBuffer[] = new char[buffer.length * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        buffer = newBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    // The following two methods have been hand-inlined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    // scanDocComment.  If you make changes here, you should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    // check to see if scanDocComment also needs modification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private void putc(int ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (count == buffer.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            growBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        buffer[count++] = (char)ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private String bufferString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return new String(buffer, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Create a scanner to scan an input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public Scanner(Environment env, InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        this.env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        useInputStream(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Setup input from the given input stream,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * and scan the first token from it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    protected void useInputStream(InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            this.in = new ScannerInputReader(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            env.setCharacterEncoding(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            this.in = new ScannerInputReader(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        ch = this.in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        prevPos = this.in.pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        scan();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Create a scanner to scan an input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    protected Scanner(Environment env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        this.env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        // Expect the subclass to call useInputStream at the right time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Define a keyword.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    private static void defineKeyword(int val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        Identifier.lookup(opNames[val]).setType(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Initialized keyword and token Hashtables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        // Statement keywords
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        defineKeyword(FOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        defineKeyword(IF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        defineKeyword(ELSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        defineKeyword(WHILE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        defineKeyword(DO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        defineKeyword(SWITCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        defineKeyword(CASE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        defineKeyword(DEFAULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        defineKeyword(BREAK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        defineKeyword(CONTINUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        defineKeyword(RETURN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        defineKeyword(TRY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        defineKeyword(CATCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        defineKeyword(FINALLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        defineKeyword(THROW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        // Type defineKeywords
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        defineKeyword(BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        defineKeyword(CHAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        defineKeyword(SHORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        defineKeyword(INT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        defineKeyword(LONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        defineKeyword(FLOAT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        defineKeyword(DOUBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        defineKeyword(VOID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        defineKeyword(BOOLEAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        // Expression keywords
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        defineKeyword(INSTANCEOF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        defineKeyword(TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        defineKeyword(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        defineKeyword(NEW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        defineKeyword(THIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        defineKeyword(SUPER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        defineKeyword(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        // Declaration keywords
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        defineKeyword(IMPORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        defineKeyword(CLASS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        defineKeyword(EXTENDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        defineKeyword(IMPLEMENTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        defineKeyword(INTERFACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        defineKeyword(PACKAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        defineKeyword(THROWS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        // Modifier keywords
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        defineKeyword(PRIVATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        defineKeyword(PUBLIC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        defineKeyword(PROTECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        defineKeyword(STATIC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        defineKeyword(TRANSIENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        defineKeyword(SYNCHRONIZED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        defineKeyword(NATIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        defineKeyword(ABSTRACT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        defineKeyword(VOLATILE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        defineKeyword(FINAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        defineKeyword(STRICTFP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // reserved keywords
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        defineKeyword(CONST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        defineKeyword(GOTO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Scan a comment. This method should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * called once the initial /, * and the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * character have been read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private void skipComment() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
              case EOF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                env.error(pos, "eof.in.comment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
              case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                if ((ch = in.read()) == '/')  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Scan a doc comment. This method should be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * once the initial /, * and * have been read. It gathers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * the content of the comment (witout leading spaces and '*'s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * in the string buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    private String scanDocComment() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        // Note: this method has been hand-optimized to yield
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        // better performance.  This was done after it was noted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        // that javadoc spent a great deal of its time here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        // This should also help the performance of the compiler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        // as well -- it scans the doc comments to find
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        // @deprecated tags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        // The logic of the method has been completely rewritten
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        // to avoid the use of flags that need to be looked at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        // for every character read.  Members that are accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        // more than once have been stored in local variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        // The methods putc() and bufferString() have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        // inlined by hand.  Extra cases have been added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        // switch statements to trick the compiler into generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        // a tableswitch instead of a lookupswitch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        // This implementation aims to preserve the previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        // behavior of this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        // Put `in' in a local variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        final ScannerInputReader in = this.in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // We maintain the buffer locally rather than calling putc().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        char[] buffer = this.buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        // We are called pointing at the second star of the doc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        // comment:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // Input: /** the rest of the comment ... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        //          ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        // We rely on this in the code below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        // Consume any number of stars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        while ((c = in.read()) == '*')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // Is the comment of the form /**/, /***/, /****/, etc.?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (c == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            // Set ch and return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        // Skip a newline on the first line of the comment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (c == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    outerLoop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        // The outerLoop processes the doc comment, looping once
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        // for each line.  For each line, it first strips off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        // whitespace, then it consumes any stars, then it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        // puts the rest of the line into our buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            // The wsLoop consumes whitespace from the beginning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            // of each line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        wsLoop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                case '\t':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    // We could check for other forms of whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    // as well, but this is left as is for minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    // disturbance of functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    // Just skip whitespace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                // We have added extra cases here to trick the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                // compiler into using a tableswitch instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                // a lookupswitch.  They can be removed without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                // a change in meaning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                case 10: case 11: case 12: case 13: case 14: case 15:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                case 16: case 17: case 18: case 19: case 20: case 21:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                case 22: case 23: case 24: case 25: case 26: case 27:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                case 28: case 29: case 30: case 31:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    // We've seen something that isn't whitespace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    // jump out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    break wsLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            } // end wsLoop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            // Are there stars here?  If so, consume them all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            // and check for the end of comment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (c == '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                // Skip all of the stars...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                } while (c == '*');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                // ...then check for the closing slash.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                if (c == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    // We're done with the doc comment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    // Set ch and break out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    break outerLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            // The textLoop processes the rest of the characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            // on the line, adding them to our buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        textLoop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                case EOF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    // We've seen a premature EOF.  Break out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    // of the loop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    env.error(pos, "eof.in.comment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    ch = EOF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    break outerLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    // Is this just a star?  Or is this the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    // end of a comment?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    if (c == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                        // This is the end of the comment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                        // set ch and return our buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                        ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                        break outerLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    // This is just an ordinary star.  Add it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    // the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    if (count == buffer.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                        growBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                        buffer = this.buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    buffer[count++] = '*';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    // We've seen a newline.  Add it to our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    // buffer and break out of this loop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    // starting fresh on a new line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    if (count == buffer.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        growBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        buffer = this.buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    buffer[count++] = '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    break textLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                // Again, the extra cases here are a trick
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                // to get the compiler to generate a tableswitch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                case 0: case 1: case 2: case 3: case 4: case 5:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                case 6: case 7: case 8: case 11: case 12: case 13:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                case 14: case 15: case 16: case 17: case 18: case 19:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                case 20: case 21: case 22: case 23: case 24: case 25:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                case 26: case 27: case 28: case 29: case 30: case 31:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                case 32: case 33: case 34: case 35: case 36: case 37:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                case 38: case 39: case 40:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    // Add the character to our buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    if (count == buffer.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                        growBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                        buffer = this.buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    buffer[count++] = (char)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            } // end textLoop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        } // end outerLoop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        // We have scanned our doc comment.  It is stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        // buffer.  The previous implementation of scanDocComment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        // stripped off all trailing spaces and stars from the comment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        // We will do this as well, so as to cause a minimum of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        // disturbance.  Is this what we want?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            int i = count - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        trailLoop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            while (i > -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                switch (buffer[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                case '\t':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    i--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                // And again, the extra cases here are a trick
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                // to get the compiler to generate a tableswitch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                case 0: case 1: case 2: case 3: case 4: case 5:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                case 6: case 7: case 8: case 10: case 11: case 12:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                case 13: case 14: case 15: case 16: case 17: case 18:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                case 19: case 20: case 21: case 22: case 23: case 24:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                case 25: case 26: case 27: case 28: case 29: case 30:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                case 31: case 33: case 34: case 35: case 36: case 37:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                case 38: case 39: case 40:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    break trailLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            count = i + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            // Return the text of the doc comment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            return new String(buffer, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Scan a number. The first digit of the number should be the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * character.  We may be scanning hex, decimal, or octal at this point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     */
23740
1d63a6c00b26 8039864: Fix fallthrough lint warnings in other libs
darcy
parents: 5506
diff changeset
   515
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    private void scanNumber() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        boolean seenNonOctal = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        boolean overflow = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        boolean seenDigit = false; // used to detect invalid hex number 0xL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        radix = (ch == '0' ? 8 : 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        long value = ch - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        putc(ch);               // save character in buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    numberLoop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
              case '.':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                if (radix == 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    break numberLoop; // an illegal character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                scanReal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
              case '8': case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                // We can't yet throw an error if reading an octal.  We might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                // discover we're really reading a real.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                seenNonOctal = true;
23740
1d63a6c00b26 8039864: Fix fallthrough lint warnings in other libs
darcy
parents: 5506
diff changeset
   537
                // Fall through
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
              case '0': case '1': case '2': case '3':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
              case '4': case '5': case '6': case '7':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                seenDigit = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                putc(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                if (radix == 10) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    overflow = overflow || (value * 10)/10 != value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    value = (value * 10) + (ch - '0');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    overflow = overflow || (value - 1 < -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                } else if (radix == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    overflow = overflow || (value >>> 61) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    value = (value << 3) + (ch - '0');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    overflow = overflow || (value >>> 60) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    value = (value << 4) + (ch - '0');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
              case 'd': case 'D': case 'e': case 'E': case 'f': case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                if (radix != 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    scanReal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                // fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
              case 'a': case 'A': case 'b': case 'B': case 'c': case 'C':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                seenDigit = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                putc(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                if (radix != 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    break numberLoop; // an illegal character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                overflow = overflow || (value >>> 60) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                value = (value << 4) + 10 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                         Character.toLowerCase((char)ch) - 'a';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
              case 'l': case 'L':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                ch = in.read(); // skip over 'l'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                longValue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                token = LONGVAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                break numberLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
              case 'x': case 'X':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                // if the first character is a '0' and this is the second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                // letter, then read in a hexadecimal number.  Otherwise, error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                if (count == 1 && radix == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                    radix = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                    seenDigit = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    // we'll get an illegal character error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    break numberLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                intValue = (int)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                token = INTVAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                break numberLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        } // while true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        // We have just finished reading the number.  The next thing better
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        // not be a letter or digit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        // Note:  There will be deprecation warnings against these uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        // of Character.isJavaLetterOrDigit and Character.isJavaLetter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        // Do not fix them yet; allow the compiler to run on pre-JDK1.1 VMs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if (Character.isJavaLetterOrDigit((char)ch) || ch == '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            env.error(in.pos, "invalid.number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            do { ch = in.read(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            while (Character.isJavaLetterOrDigit((char)ch) || ch == '.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            intValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            token = INTVAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        } else if (radix == 8 && seenNonOctal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            // A bogus octal literal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            intValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            token = INTVAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            env.error(pos, "invalid.octal.number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        } else if (radix == 16 && seenDigit == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            // A hex literal with no digits, 0xL, for example.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            intValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            token = INTVAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            env.error(pos, "invalid.hex.number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            if (token == INTVAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                // Check for overflow.  Note that base 10 literals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                // have different rules than base 8 and 16.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                overflow = overflow ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                    (value & 0xFFFFFFFF00000000L) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                    (radix == 10 && value > 2147483648L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                if (overflow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    intValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    // Give a specific error message which tells
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                    // the user the range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                    switch (radix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    case 8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                        env.error(pos, "overflow.int.oct");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    case 10:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                        env.error(pos, "overflow.int.dec");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                    case 16:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                        env.error(pos, "overflow.int.hex");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                        throw new CompilerError("invalid radix");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                if (overflow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                    longValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                    // Give a specific error message which tells
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    // the user the range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                    switch (radix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                    case 8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                        env.error(pos, "overflow.long.oct");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                    case 10:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                        env.error(pos, "overflow.long.dec");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                    case 16:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                        env.error(pos, "overflow.long.hex");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                        throw new CompilerError("invalid radix");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * Scan a float.  We are either looking at the decimal, or we have already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * seen it and put it into the buffer.  We haven't seen an exponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * Scan a float.  Should be called with the current character is either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * the 'e', 'E' or '.'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     */
23740
1d63a6c00b26 8039864: Fix fallthrough lint warnings in other libs
darcy
parents: 5506
diff changeset
   674
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    private void scanReal() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        boolean seenExponent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        boolean isSingleFloat = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        char lastChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        if (ch == '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            putc(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    numberLoop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        for ( ; ; ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                case '0': case '1': case '2': case '3': case '4':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                case '5': case '6': case '7': case '8': case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                    putc(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                case 'e': case 'E':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                    if (seenExponent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                        break numberLoop; // we'll get a format error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                    putc(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                    seenExponent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                case '+': case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    lastChar = buffer[count - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                    if (lastChar != 'e' && lastChar != 'E')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                        break numberLoop; // this isn't an error, though!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    putc(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                case 'f': case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                    ch = in.read(); // skip over 'f'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                    isSingleFloat = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                    break numberLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                case 'd': case 'D':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    ch = in.read(); // skip over 'd'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    // fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                    break numberLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            } // sswitch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        } // loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        // we have just finished reading the number.  The next thing better
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        // not be a letter or digit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        if (Character.isJavaLetterOrDigit((char)ch) || ch == '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            env.error(in.pos, "invalid.number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            do { ch = in.read(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            while (Character.isJavaLetterOrDigit((char)ch) || ch == '.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            doubleValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            token = DOUBLEVAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            token = isSingleFloat ? FLOATVAL : DOUBLEVAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                lastChar = buffer[count - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                if (lastChar == 'e' || lastChar == 'E'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                       || lastChar == '+' || lastChar == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                    env.error(in.pos -1, "float.format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                } else if (isSingleFloat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                    String string = bufferString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                    floatValue = Float.valueOf(string).floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                    if (Float.isInfinite(floatValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                        env.error(pos, "overflow.float");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                    } else if (floatValue == 0 && !looksLikeZero(string)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                        env.error(pos, "underflow.float");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                    String string = bufferString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                    doubleValue = Double.valueOf(string).doubleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    if (Double.isInfinite(doubleValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                        env.error(pos, "overflow.double");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    } else if (doubleValue == 0 && !looksLikeZero(string)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                        env.error(pos, "underflow.double");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            } catch (NumberFormatException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                env.error(pos, "float.format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                doubleValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                floatValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    // We have a token that parses as a number.  Is this token possibly zero?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    // i.e. does it have a non-zero value in the mantissa?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    private static boolean looksLikeZero(String token) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        int length = token.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        for (int i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            switch (token.charAt(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                case 0: case '.':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                case '1': case '2': case '3': case '4': case '5':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                case '6': case '7': case '8': case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                case 'e': case 'E': case 'f': case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * Scan an escape character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @return the character or -1 if it escaped an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * end-of-line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    private int scanEscapeChar() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        long p = in.pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
          case '0': case '1': case '2': case '3':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
          case '4': case '5': case '6': case '7': {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            int n = ch - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            for (int i = 2 ; i > 0 ; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                  case '0': case '1': case '2': case '3':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                  case '4': case '5': case '6': case '7':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                    n = (n << 3) + ch - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                    if (n > 0xFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                        env.error(p, "invalid.escape.char");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                    return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            if (n > 0xFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                env.error(p, "invalid.escape.char");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
          case 'r':  ch = in.read(); return '\r';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
          case 'n':  ch = in.read(); return '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
          case 'f':  ch = in.read(); return '\f';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
          case 'b':  ch = in.read(); return '\b';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
          case 't':  ch = in.read(); return '\t';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
          case '\\': ch = in.read(); return '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
          case '\"': ch = in.read(); return '\"';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
          case '\'': ch = in.read(); return '\'';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        env.error(p, "invalid.escape.char");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * Scan a string. The current character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * should be the opening " of the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    private void scanString() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        token = STRINGVAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        // Scan a String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
              case EOF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                env.error(pos, "eof.in.string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                stringValue = bufferString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
              case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
              case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                env.error(pos, "newline.in.string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                stringValue = bufferString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
              case '"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                stringValue = bufferString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
              case '\\': {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                int c = scanEscapeChar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                if (c >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                    putc((char)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                putc(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * Scan a character. The current character should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * the opening ' of the character constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    private void scanCharacter() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        token = CHARVAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
          case '\\':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            int c = scanEscapeChar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            charValue = (char)((c >= 0) ? c : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        case '\'':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            // There are two standard problems this case deals with.  One
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            // is the malformed single quote constant (i.e. the programmer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            // uses ''' instead of '\'') and the other is the empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            // character constant (i.e. '').  Just consume any number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            // single quotes and emit an error message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            charValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            env.error(pos, "invalid.char.constant");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            while (ch == '\'') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
          case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
          case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            charValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            env.error(pos, "invalid.char.constant");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            charValue = (char)ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        if (ch == '\'') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            env.error(pos, "invalid.char.constant");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                  case '\'':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                  case ';':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                  case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                  case EOF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * Scan an Identifier. The current character should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * be the first character of the identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    private void scanIdentifier() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            putc(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
              case 'a': case 'b': case 'c': case 'd': case 'e':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
              case 'f': case 'g': case 'h': case 'i': case 'j':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
              case 'k': case 'l': case 'm': case 'n': case 'o':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
              case 'p': case 'q': case 'r': case 's': case 't':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
              case 'u': case 'v': case 'w': case 'x': case 'y':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
              case 'z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
              case 'A': case 'B': case 'C': case 'D': case 'E':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
              case 'F': case 'G': case 'H': case 'I': case 'J':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
              case 'K': case 'L': case 'M': case 'N': case 'O':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
              case 'P': case 'Q': case 'R': case 'S': case 'T':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
              case 'U': case 'V': case 'W': case 'X': case 'Y':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
              case 'Z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
              case '0': case '1': case '2': case '3': case '4':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
              case '5': case '6': case '7': case '8': case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
              case '$': case '_':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                if (!Character.isJavaLetterOrDigit((char)ch)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                    idValue = Identifier.lookup(bufferString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                    token = idValue.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * The ending position of the current token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    // Note: This should be part of the pos itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    public long getEndPos() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        return in.pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * If the current token is IDENT, return the identifier occurrence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * It will be freshly allocated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    public IdentifierToken getIdToken() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        return (token != IDENT) ? null : new IdentifierToken(pos, idValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * Scan the next token.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * @return the position of the previous token.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
   public long scan() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
       return xscan();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
23740
1d63a6c00b26 8039864: Fix fallthrough lint warnings in other libs
darcy
parents: 5506
diff changeset
   991
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    protected long xscan() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        final ScannerInputReader in = this.in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        long retPos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        prevPos = in.pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        docComment = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            pos = in.pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
              case EOF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                token = EOF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
              case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                if (scanComments) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                    ch = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                    // Avoid this path the next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                    // Do not just call in.read; we want to present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                    // a null token (and also avoid read-ahead).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                    token = COMMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                }
23740
1d63a6c00b26 8039864: Fix fallthrough lint warnings in other libs
darcy
parents: 5506
diff changeset
  1014
                // Fall through
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
              case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
              case '\t':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
              case '\f':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
              case '/':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                  case '/':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                    // Parse a // comment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                    while (((ch = in.read()) != EOF) && (ch != '\n'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                    if (scanComments) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                        token = COMMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                        return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                  case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                    if (ch == '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                        docComment = scanDocComment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                        skipComment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                    if (scanComments) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                        return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                  case '=':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                    token = ASGDIV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                    token = DIV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
              case '"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                scanString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
              case '\'':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                scanCharacter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
              case '0': case '1': case '2': case '3': case '4':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
              case '5': case '6': case '7': case '8': case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                scanNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
              case '.':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                  case '0': case '1': case '2': case '3': case '4':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                  case '5': case '6': case '7': case '8': case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                    count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                    putc('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                    scanReal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                    token = FIELD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
              case '{':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                token = LBRACE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
              case '}':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                token = RBRACE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
              case '(':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                token = LPAREN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
              case ')':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                token = RPAREN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
              case '[':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                token = LSQBRACKET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
              case ']':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                token = RSQBRACKET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
              case ',':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                token = COMMA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
              case ';':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                token = SEMICOLON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
              case '?':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                token = QUESTIONMARK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
              case '~':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                token = BITNOT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
              case ':':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                token = COLON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
              case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                  case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                    token = DEC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                  case '=':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                    token = ASGSUB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                token = SUB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
              case '+':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                  case '+':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                    token = INC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                  case '=':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                    token = ASGADD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                token = ADD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
              case '<':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                  case '<':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                    if ((ch = in.read()) == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                        ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                        token = ASGLSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                        return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                    token = LSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                  case '=':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                    token = LE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                token = LT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
              case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                  case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                    switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                      case '=':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                        ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                        token = ASGRSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                        return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                      case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                        if ((ch = in.read()) == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                            token = ASGURSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                            return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                        token = URSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                        return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                    token = RSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                  case '=':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                    token = GE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                token = GT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
              case '|':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                  case '|':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                    token = OR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                  case '=':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                    token = ASGBITOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                token = BITOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
              case '&':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                  case '&':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                    token = AND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                  case '=':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                    token = ASGBITAND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                token = BITAND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
              case '=':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                if ((ch = in.read()) == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                    token = EQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                token = ASSIGN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
              case '%':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                if ((ch = in.read()) == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                    token = ASGREM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                token = REM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
              case '^':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                if ((ch = in.read()) == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                    token = ASGBITXOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                token = BITXOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
              case '!':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                if ((ch = in.read()) == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                    token = NE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                token = NOT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
              case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                if ((ch = in.read()) == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                    token = ASGMUL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                token = MUL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
              case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
              case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
              case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
              case 's': case 't': case 'u': case 'v': case 'w': case 'x':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
              case 'y': case 'z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
              case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
              case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
              case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
              case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
              case 'Y': case 'Z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
              case '$': case '_':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                scanIdentifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
              case '\u001a':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                // Our one concession to DOS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                if ((ch = in.read()) == EOF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                    token = EOF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                env.error(pos, "funny.char");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                if (Character.isJavaLetter((char)ch)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                    scanIdentifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                    return retPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                env.error(pos, "funny.char");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     * Scan to a matching '}', ']' or ')'. The current token must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * a '{', '[' or '(';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    public void match(int open, int close) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        int depth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            scan();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            if (token == open) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                depth++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            } else if (token == close) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                if (--depth == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            } else if (token == EOF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                env.error(pos, "unbalanced.paren");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
}