1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fixes two exceptions in the scanner (parsing firefox).

This commit is contained in:
Markus Schorn 2006-11-13 11:50:35 +00:00
parent 908501d4a6
commit d61c4d35ec
2 changed files with 45 additions and 35 deletions

View file

@ -1534,21 +1534,9 @@ abstract class BaseScanner implements IScanner {
* @see org.eclipse.cdt.core.parser.IScanner#nextToken()
*/
public IToken nextToken() throws EndOfFileException {
boolean exception = false;
if (nextToken == null && !finished) {
try {
nextToken = fetchToken();
} catch (Exception e) {
if (e instanceof OffsetLimitReachedException)
throw (OffsetLimitReachedException) e;
if (e instanceof ArrayIndexOutOfBoundsException && isCancelled)
throw new ParseError(
ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED);
exception = true;
errorHandle();
}
if (nextToken == null && !exception) {
nextToken= doFetchToken();
if (nextToken == null) {
finished = true;
}
}
@ -1578,25 +1566,15 @@ abstract class BaseScanner implements IScanner {
IToken oldToken = lastToken;
lastToken = nextToken;
try {
nextToken = fetchToken();
} catch (Exception e) {
if (e instanceof OffsetLimitReachedException)
throw (OffsetLimitReachedException) e;
nextToken = null;
exception = true;
errorHandle();
}
nextToken = doFetchToken();
if (nextToken == null) {
if (!exception)
finished = true;
} else if (nextToken.getType() == IToken.tCOMPLETION) {
finished = true;
} else if (nextToken.getType() == IToken.tPOUNDPOUND) {
// time for a pasting
IToken token2 = fetchToken();
IToken token2 = doFetchToken();
if (token2 == null) {
nextToken = null;
finished = true;
@ -1623,13 +1601,33 @@ abstract class BaseScanner implements IScanner {
.getCharImage(), nextToken.getCharImage()));
if (oldToken != null)
oldToken.setNext(lastToken);
nextToken = fetchToken();
nextToken = doFetchToken();
}
}
return lastToken;
}
private IToken doFetchToken() throws EndOfFileException {
IToken result= null;
try {
result = fetchToken();
} catch (ArrayIndexOutOfBoundsException e) {
if (isCancelled) {
throw new ParseError(ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED);
}
errorHandle();
throw e;
} catch (RuntimeException e) {
errorHandle();
throw e;
} catch (Error e) {
errorHandle();
throw e;
}
return result;
}
/**
* @throws EndOfFileException
*/

View file

@ -179,6 +179,14 @@ public class DOMScanner extends BaseScanner {
return codeReaderFactory.createCodeReaderForInclusion(this, finalPath);
}
protected void pushContext(char[] buffer) {
// called before the constructor, so check for bufferDelta to be
// initialized.
if (bufferDelta != null) {
initBufferDelta(bufferStackPos + 1);
}
super.pushContext(buffer);
}
/*
* (non-Javadoc)
*
@ -186,13 +194,7 @@ public class DOMScanner extends BaseScanner {
* java.lang.Object)
*/
protected void pushContext(char[] buffer, Object data) {
if (bufferStackPos + 1 == bufferDelta.length) {
int size = bufferDelta.length * 2;
int[] oldBufferDelta = bufferDelta;
bufferDelta = new int[size];
System.arraycopy(oldBufferDelta, 0, bufferDelta, 0,
oldBufferDelta.length);
}
initBufferDelta(bufferStackPos + 1);
if (data instanceof InclusionData) {
@ -238,6 +240,16 @@ public class DOMScanner extends BaseScanner {
super.pushContext(buffer, data);
}
private void initBufferDelta(int size) {
if (size >= bufferDelta.length) {
size = Math.max(bufferDelta.length * 2, size);
int[] oldBufferDelta = bufferDelta;
bufferDelta = new int[size];
System.arraycopy(oldBufferDelta, 0, bufferDelta, 0,
oldBufferDelta.length);
}
}
protected int fsmCount = 0;
/*