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