0N/A/*
2362N/A * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
4378N/A/*
4378N/A * This source code is provided to illustrate the usage of a given feature
4378N/A * or technique and has been deliberately simplified. Additional steps
4378N/A * required for a production-quality application, such as security checks,
4378N/A * input validation and proper error handling, might not be present in
4378N/A * this sample code.
4378N/A */
4378N/A
4378N/A
0N/A/* Generated By:JavaCC: Do not edit this line. ASCII_UCodeESC_CharStream.java Version 0.7pre6 */
0N/A
0N/Apackage com.sun.tools.example.debug.expr;
0N/A
0N/A/**
0N/A * An implementation of interface CharStream, where the stream is assumed to
0N/A * contain only ASCII characters (with java-like unicode escape processing).
0N/A */
0N/A
0N/Apublic final class ASCII_UCodeESC_CharStream
0N/A{
0N/A public static final boolean staticFlag = false;
0N/A static final int hexval(char c) throws java.io.IOException {
0N/A switch(c)
0N/A {
0N/A case '0' :
0N/A return 0;
0N/A case '1' :
0N/A return 1;
0N/A case '2' :
0N/A return 2;
0N/A case '3' :
0N/A return 3;
0N/A case '4' :
0N/A return 4;
0N/A case '5' :
0N/A return 5;
0N/A case '6' :
0N/A return 6;
0N/A case '7' :
0N/A return 7;
0N/A case '8' :
0N/A return 8;
0N/A case '9' :
0N/A return 9;
0N/A
0N/A case 'a' :
0N/A case 'A' :
0N/A return 10;
0N/A case 'b' :
0N/A case 'B' :
0N/A return 11;
0N/A case 'c' :
0N/A case 'C' :
0N/A return 12;
0N/A case 'd' :
0N/A case 'D' :
0N/A return 13;
0N/A case 'e' :
0N/A case 'E' :
0N/A return 14;
0N/A case 'f' :
0N/A case 'F' :
0N/A return 15;
0N/A }
0N/A
0N/A throw new java.io.IOException(); // Should never come here
0N/A }
0N/A
0N/A public int bufpos = -1;
0N/A int bufsize;
0N/A int available;
0N/A int tokenBegin;
0N/A private int bufline[];
0N/A private int bufcolumn[];
0N/A
0N/A private int column = 0;
0N/A private int line = 1;
0N/A
0N/A private java.io.InputStream inputStream;
0N/A
0N/A private boolean prevCharIsCR = false;
0N/A private boolean prevCharIsLF = false;
0N/A
0N/A private byte[] nextCharBuf;
0N/A private char[] buffer;
0N/A private int maxNextCharInd = 0;
0N/A private int nextCharInd = -1;
0N/A private int inBuf = 0;
0N/A
0N/A private final void ExpandBuff(boolean wrapAround)
0N/A {
0N/A char[] newbuffer = new char[bufsize + 2048];
0N/A int newbufline[] = new int[bufsize + 2048];
0N/A int newbufcolumn[] = new int[bufsize + 2048];
0N/A
0N/A try
0N/A {
0N/A if (wrapAround)
0N/A {
0N/A System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
0N/A System.arraycopy(buffer, 0, newbuffer,
0N/A bufsize - tokenBegin, bufpos);
0N/A buffer = newbuffer;
0N/A
0N/A System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
0N/A System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
0N/A bufline = newbufline;
0N/A
0N/A System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
0N/A System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
0N/A bufcolumn = newbufcolumn;
0N/A
0N/A bufpos += (bufsize - tokenBegin);
0N/A }
0N/A else
0N/A {
0N/A System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
0N/A buffer = newbuffer;
0N/A
0N/A System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
0N/A bufline = newbufline;
0N/A
0N/A System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
0N/A bufcolumn = newbufcolumn;
0N/A
0N/A bufpos -= tokenBegin;
0N/A }
0N/A }
0N/A catch (Throwable t)
0N/A {
0N/A throw new Error(t.getMessage());
0N/A }
0N/A
0N/A available = (bufsize += 2048);
0N/A tokenBegin = 0;
0N/A }
0N/A
0N/A private final void FillBuff() throws java.io.IOException
0N/A {
0N/A int i;
0N/A if (maxNextCharInd == 4096)
0N/A maxNextCharInd = nextCharInd = 0;
0N/A
0N/A try {
0N/A if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
0N/A 4096 - maxNextCharInd)) == -1)
0N/A {
0N/A inputStream.close();
0N/A throw new java.io.IOException();
0N/A }
0N/A else
0N/A maxNextCharInd += i;
0N/A return;
0N/A }
0N/A catch(java.io.IOException e) {
0N/A if (bufpos != 0)
0N/A {
0N/A --bufpos;
0N/A backup(0);
0N/A }
0N/A else
0N/A {
0N/A bufline[bufpos] = line;
0N/A bufcolumn[bufpos] = column;
0N/A }
0N/A throw e;
0N/A }
0N/A }
0N/A
0N/A private final byte ReadByte() throws java.io.IOException
0N/A {
0N/A if (++nextCharInd >= maxNextCharInd)
0N/A FillBuff();
0N/A
0N/A return nextCharBuf[nextCharInd];
0N/A }
0N/A
0N/A public final char BeginToken() throws java.io.IOException
0N/A {
0N/A if (inBuf > 0)
0N/A {
0N/A --inBuf;
0N/A return buffer[tokenBegin = (bufpos == bufsize - 1) ? (bufpos = 0)
0N/A : ++bufpos];
0N/A }
0N/A
0N/A tokenBegin = 0;
0N/A bufpos = -1;
0N/A
0N/A return readChar();
0N/A }
0N/A
0N/A private final void AdjustBuffSize()
0N/A {
0N/A if (available == bufsize)
0N/A {
0N/A if (tokenBegin > 2048)
0N/A {
0N/A bufpos = 0;
0N/A available = tokenBegin;
0N/A }
0N/A else
0N/A ExpandBuff(false);
0N/A }
0N/A else if (available > tokenBegin)
0N/A available = bufsize;
0N/A else if ((tokenBegin - available) < 2048)
0N/A ExpandBuff(true);
0N/A else
0N/A available = tokenBegin;
0N/A }
0N/A
0N/A private final void UpdateLineColumn(char c)
0N/A {
0N/A column++;
0N/A
0N/A if (prevCharIsLF)
0N/A {
0N/A prevCharIsLF = false;
0N/A line += (column = 1);
0N/A }
0N/A else if (prevCharIsCR)
0N/A {
0N/A prevCharIsCR = false;
0N/A if (c == '\n')
0N/A {
0N/A prevCharIsLF = true;
0N/A }
0N/A else
0N/A line += (column = 1);
0N/A }
0N/A
0N/A switch (c)
0N/A {
0N/A case '\r' :
0N/A prevCharIsCR = true;
0N/A break;
0N/A case '\n' :
0N/A prevCharIsLF = true;
0N/A break;
0N/A case '\t' :
0N/A column--;
0N/A column += (8 - (column & 07));
0N/A break;
0N/A default :
0N/A break;
0N/A }
0N/A
0N/A bufline[bufpos] = line;
0N/A bufcolumn[bufpos] = column;
0N/A }
0N/A
0N/A public final char readChar() throws java.io.IOException
0N/A {
0N/A if (inBuf > 0)
0N/A {
0N/A --inBuf;
0N/A return buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos];
0N/A }
0N/A
0N/A char c;
0N/A
0N/A if (++bufpos == available)
0N/A AdjustBuffSize();
0N/A
0N/A if (((buffer[bufpos] = c = (char)((char)0xff & ReadByte())) == '\\'))
0N/A {
0N/A UpdateLineColumn(c);
0N/A
0N/A int backSlashCnt = 1;
0N/A
0N/A for (;;) // Read all the backslashes
0N/A {
0N/A if (++bufpos == available)
0N/A AdjustBuffSize();
0N/A
0N/A try
0N/A {
0N/A if ((buffer[bufpos] = c = (char)((char)0xff & ReadByte())) != '\\')
0N/A {
0N/A UpdateLineColumn(c);
0N/A // found a non-backslash char.
0N/A if ((c == 'u') && ((backSlashCnt & 1) == 1))
0N/A {
0N/A if (--bufpos < 0)
0N/A bufpos = bufsize - 1;
0N/A
0N/A break;
0N/A }
0N/A
0N/A backup(backSlashCnt);
0N/A return '\\';
0N/A }
0N/A }
0N/A catch(java.io.IOException e)
0N/A {
0N/A if (backSlashCnt > 1)
0N/A backup(backSlashCnt);
0N/A
0N/A return '\\';
0N/A }
0N/A
0N/A UpdateLineColumn(c);
0N/A backSlashCnt++;
0N/A }
0N/A
0N/A // Here, we have seen an odd number of backslash's followed by a 'u'
0N/A try
0N/A {
0N/A while ((c = (char)((char)0xff & ReadByte())) == 'u')
0N/A ++column;
0N/A
0N/A buffer[bufpos] = c = (char)(hexval(c) << 12 |
0N/A hexval((char)((char)0xff & ReadByte())) << 8 |
0N/A hexval((char)((char)0xff & ReadByte())) << 4 |
0N/A hexval((char)((char)0xff & ReadByte())));
0N/A
0N/A column += 4;
0N/A }
0N/A catch(java.io.IOException e)
0N/A {
0N/A throw new Error("Invalid escape character at line " + line +
0N/A " column " + column + ".");
0N/A }
0N/A
0N/A if (backSlashCnt == 1)
0N/A return c;
0N/A else
0N/A {
0N/A backup(backSlashCnt - 1);
0N/A return '\\';
0N/A }
0N/A }
0N/A else
0N/A {
0N/A UpdateLineColumn(c);
0N/A return (c);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @deprecated
0N/A * @see #getEndColumn
0N/A */
0N/A @Deprecated
0N/A public final int getColumn() {
0N/A return bufcolumn[bufpos];
0N/A }
0N/A
0N/A /**
0N/A * @deprecated
0N/A * @see #getEndLine
0N/A */
0N/A @Deprecated
0N/A public final int getLine() {
0N/A return bufline[bufpos];
0N/A }
0N/A
0N/A public final int getEndColumn() {
0N/A return bufcolumn[bufpos];
0N/A }
0N/A
0N/A public final int getEndLine() {
0N/A return bufline[bufpos];
0N/A }
0N/A
0N/A public final int getBeginColumn() {
0N/A return bufcolumn[tokenBegin];
0N/A }
0N/A
0N/A public final int getBeginLine() {
0N/A return bufline[tokenBegin];
0N/A }
0N/A
0N/A public final void backup(int amount) {
0N/A
0N/A inBuf += amount;
0N/A if ((bufpos -= amount) < 0)
0N/A bufpos += bufsize;
0N/A }
0N/A
0N/A public ASCII_UCodeESC_CharStream(java.io.InputStream dstream,
0N/A int startline, int startcolumn, int buffersize)
0N/A {
0N/A inputStream = dstream;
0N/A line = startline;
0N/A column = startcolumn - 1;
0N/A
0N/A available = bufsize = buffersize;
0N/A buffer = new char[buffersize];
0N/A bufline = new int[buffersize];
0N/A bufcolumn = new int[buffersize];
0N/A nextCharBuf = new byte[4096];
0N/A }
0N/A
0N/A public ASCII_UCodeESC_CharStream(java.io.InputStream dstream,
0N/A int startline, int startcolumn)
0N/A {
0N/A this(dstream, startline, startcolumn, 4096);
0N/A }
0N/A public void ReInit(java.io.InputStream dstream,
0N/A int startline, int startcolumn, int buffersize)
0N/A {
0N/A inputStream = dstream;
0N/A line = startline;
0N/A column = startcolumn - 1;
0N/A
0N/A if (buffer == null || buffersize != buffer.length)
0N/A {
0N/A available = bufsize = buffersize;
0N/A buffer = new char[buffersize];
0N/A bufline = new int[buffersize];
0N/A bufcolumn = new int[buffersize];
0N/A nextCharBuf = new byte[4096];
0N/A }
0N/A prevCharIsLF = prevCharIsCR = false;
0N/A tokenBegin = inBuf = maxNextCharInd = 0;
0N/A nextCharInd = bufpos = -1;
0N/A }
0N/A
0N/A public void ReInit(java.io.InputStream dstream,
0N/A int startline, int startcolumn)
0N/A {
0N/A ReInit(dstream, startline, startcolumn, 4096);
0N/A }
0N/A
0N/A public final String GetImage()
0N/A {
0N/A if (bufpos >= tokenBegin)
0N/A return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
0N/A else
0N/A return new String(buffer, tokenBegin, bufsize - tokenBegin) +
0N/A new String(buffer, 0, bufpos + 1);
0N/A }
0N/A
0N/A public final char[] GetSuffix(int len)
0N/A {
0N/A char[] ret = new char[len];
0N/A
0N/A if ((bufpos + 1) >= len)
0N/A System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
0N/A else
0N/A {
0N/A System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
0N/A len - bufpos - 1);
0N/A System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
0N/A }
0N/A
0N/A return ret;
0N/A }
0N/A
0N/A public void Done()
0N/A {
0N/A nextCharBuf = null;
0N/A buffer = null;
0N/A bufline = null;
0N/A bufcolumn = null;
0N/A }
0N/A
0N/A /**
0N/A * Method to adjust line and column numbers for the start of a token.<BR>
0N/A */
0N/A public void adjustBeginLineColumn(int newLine, int newCol)
0N/A {
0N/A int start = tokenBegin;
0N/A int len;
0N/A
0N/A if (bufpos >= tokenBegin)
0N/A {
0N/A len = bufpos - tokenBegin + inBuf + 1;
0N/A }
0N/A else
0N/A {
0N/A len = bufsize - tokenBegin + bufpos + 1 + inBuf;
0N/A }
0N/A
0N/A int i = 0, j = 0, k = 0;
0N/A int nextColDiff = 0, columnDiff = 0;
0N/A
0N/A while (i < len &&
0N/A bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
0N/A {
0N/A bufline[j] = newLine;
0N/A nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
0N/A bufcolumn[j] = newCol + columnDiff;
0N/A columnDiff = nextColDiff;
0N/A i++;
0N/A }
0N/A
0N/A if (i < len)
0N/A {
0N/A bufline[j] = newLine++;
0N/A bufcolumn[j] = newCol + columnDiff;
0N/A
0N/A while (i++ < len)
0N/A {
0N/A if (bufline[j = start % bufsize] != bufline[++start % bufsize])
0N/A bufline[j] = newLine++;
0N/A else
0N/A bufline[j] = newLine;
0N/A }
0N/A }
0N/A
0N/A line = bufline[j];
0N/A column = bufcolumn[j];
0N/A }
0N/A
0N/A}