1 /* Generated By:JavaCC: Do not edit this line. ASCII_UCodeESC_CharStream.java Version 0.7pre6 */
2 package jde.debugger.expr;
5 * An implementation of interface CharStream, where the stream is assumed to
6 * contain only ASCII characters (with java-like unicode escape processing).
9 public final class ASCII_UCodeESC_CharStream
11 public static final boolean staticFlag = false;
12 static final int hexval(char c) throws java.io.IOException {
56 throw new java.io.IOException(); // Should never come here
59 public int bufpos = -1;
63 private int bufline[];
64 private int bufcolumn[];
66 private int column = 0;
69 private java.io.InputStream inputStream;
71 private boolean prevCharIsCR = false;
72 private boolean prevCharIsLF = false;
74 private byte[] nextCharBuf;
75 private char[] buffer;
76 private int maxNextCharInd = 0;
77 private int nextCharInd = -1;
78 private int inBuf = 0;
80 private final void ExpandBuff(boolean wrapAround)
82 char[] newbuffer = new char[bufsize + 2048];
83 int newbufline[] = new int[bufsize + 2048];
84 int newbufcolumn[] = new int[bufsize + 2048];
90 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
91 System.arraycopy(buffer, 0, newbuffer,
92 bufsize - tokenBegin, bufpos);
95 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
96 System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
99 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
100 System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
101 bufcolumn = newbufcolumn;
103 bufpos += (bufsize - tokenBegin);
107 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
110 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
111 bufline = newbufline;
113 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
114 bufcolumn = newbufcolumn;
116 bufpos -= tokenBegin;
121 throw new Error(t.getMessage());
124 available = (bufsize += 2048);
128 private final void FillBuff() throws java.io.IOException
131 if (maxNextCharInd == 4096)
132 maxNextCharInd = nextCharInd = 0;
135 if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
136 4096 - maxNextCharInd)) == -1)
139 throw new java.io.IOException();
145 catch(java.io.IOException e) {
153 bufline[bufpos] = line;
154 bufcolumn[bufpos] = column;
160 private final byte ReadByte() throws java.io.IOException
162 if (++nextCharInd >= maxNextCharInd)
165 return nextCharBuf[nextCharInd];
168 public final char BeginToken() throws java.io.IOException
173 return buffer[tokenBegin = (bufpos == bufsize - 1) ? (bufpos = 0)
183 private final void AdjustBuffSize()
185 if (available == bufsize)
187 if (tokenBegin > 2048)
190 available = tokenBegin;
195 else if (available > tokenBegin)
197 else if ((tokenBegin - available) < 2048)
200 available = tokenBegin;
203 private final void UpdateLineColumn(char c)
209 prevCharIsLF = false;
210 line += (column = 1);
212 else if (prevCharIsCR)
214 prevCharIsCR = false;
220 line += (column = 1);
233 column += (8 - (column & 07));
239 bufline[bufpos] = line;
240 bufcolumn[bufpos] = column;
243 public final char readChar() throws java.io.IOException
248 return buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos];
253 if (++bufpos == available)
256 if (((buffer[bufpos] = c = (char)((char)0xff & ReadByte())) == '\\'))
260 int backSlashCnt = 1;
262 for (;;) // Read all the backslashes
264 if (++bufpos == available)
269 if ((buffer[bufpos] = c = (char)((char)0xff & ReadByte())) != '\\')
272 // found a non-backslash char.
273 if ((c == 'u') && ((backSlashCnt & 1) == 1))
276 bufpos = bufsize - 1;
281 backup(backSlashCnt);
285 catch(java.io.IOException e)
287 if (backSlashCnt > 1)
288 backup(backSlashCnt);
297 // Here, we have seen an odd number of backslash's followed by a 'u'
300 while ((c = (char)((char)0xff & ReadByte())) == 'u')
303 buffer[bufpos] = c = (char)(hexval(c) << 12 |
304 hexval((char)((char)0xff & ReadByte())) << 8 |
305 hexval((char)((char)0xff & ReadByte())) << 4 |
306 hexval((char)((char)0xff & ReadByte())));
310 catch(java.io.IOException e)
312 throw new Error("Invalid escape character at line " + line +
313 " column " + column + ".");
316 if (backSlashCnt == 1)
320 backup(backSlashCnt - 1);
336 public final int getColumn() {
337 return bufcolumn[bufpos];
345 public final int getLine() {
346 return bufline[bufpos];
349 public final int getEndColumn() {
350 return bufcolumn[bufpos];
353 public final int getEndLine() {
354 return bufline[bufpos];
357 public final int getBeginColumn() {
358 return bufcolumn[tokenBegin];
361 public final int getBeginLine() {
362 return bufline[tokenBegin];
365 public final void backup(int amount) {
368 if ((bufpos -= amount) < 0)
372 public ASCII_UCodeESC_CharStream(java.io.InputStream dstream,
373 int startline, int startcolumn, int buffersize)
375 inputStream = dstream;
377 column = startcolumn - 1;
379 available = bufsize = buffersize;
380 buffer = new char[buffersize];
381 bufline = new int[buffersize];
382 bufcolumn = new int[buffersize];
383 nextCharBuf = new byte[4096];
386 public ASCII_UCodeESC_CharStream(java.io.InputStream dstream,
387 int startline, int startcolumn)
389 this(dstream, startline, startcolumn, 4096);
391 public void ReInit(java.io.InputStream dstream,
392 int startline, int startcolumn, int buffersize)
394 inputStream = dstream;
396 column = startcolumn - 1;
398 if (buffer == null || buffersize != buffer.length)
400 available = bufsize = buffersize;
401 buffer = new char[buffersize];
402 bufline = new int[buffersize];
403 bufcolumn = new int[buffersize];
404 nextCharBuf = new byte[4096];
406 prevCharIsLF = prevCharIsCR = false;
407 tokenBegin = inBuf = maxNextCharInd = 0;
408 nextCharInd = bufpos = -1;
411 public void ReInit(java.io.InputStream dstream,
412 int startline, int startcolumn)
414 ReInit(dstream, startline, startcolumn, 4096);
417 public final String GetImage()
419 if (bufpos >= tokenBegin)
420 return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
422 return new String(buffer, tokenBegin, bufsize - tokenBegin) +
423 new String(buffer, 0, bufpos + 1);
426 public final char[] GetSuffix(int len)
428 char[] ret = new char[len];
430 if ((bufpos + 1) >= len)
431 System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
434 System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
436 System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
451 * Method to adjust line and column numbers for the start of a token.<BR>
453 public void adjustBeginLineColumn(int newLine, int newCol)
455 int start = tokenBegin;
458 if (bufpos >= tokenBegin)
460 len = bufpos - tokenBegin + inBuf + 1;
464 len = bufsize - tokenBegin + bufpos + 1 + inBuf;
467 int i = 0, j = 0, k = 0;
468 int nextColDiff = 0, columnDiff = 0;
471 bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
473 bufline[j] = newLine;
474 nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
475 bufcolumn[j] = newCol + columnDiff;
476 columnDiff = nextColDiff;
482 bufline[j] = newLine++;
483 bufcolumn[j] = newCol + columnDiff;
487 if (bufline[j = start % bufsize] != bufline[++start % bufsize])
488 bufline[j] = newLine++;
490 bufline[j] = newLine;
495 column = bufcolumn[j];