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:
parent
908501d4a6
commit
d61c4d35ec
2 changed files with 45 additions and 35 deletions
|
@ -1534,21 +1534,9 @@ abstract class BaseScanner implements IScanner {
|
||||||
* @see org.eclipse.cdt.core.parser.IScanner#nextToken()
|
* @see org.eclipse.cdt.core.parser.IScanner#nextToken()
|
||||||
*/
|
*/
|
||||||
public IToken nextToken() throws EndOfFileException {
|
public IToken nextToken() throws EndOfFileException {
|
||||||
boolean exception = false;
|
|
||||||
if (nextToken == null && !finished) {
|
if (nextToken == null && !finished) {
|
||||||
try {
|
nextToken= doFetchToken();
|
||||||
nextToken = fetchToken();
|
if (nextToken == null) {
|
||||||
} 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) {
|
|
||||||
finished = true;
|
finished = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1578,25 +1566,15 @@ abstract class BaseScanner implements IScanner {
|
||||||
IToken oldToken = lastToken;
|
IToken oldToken = lastToken;
|
||||||
lastToken = nextToken;
|
lastToken = nextToken;
|
||||||
|
|
||||||
try {
|
nextToken = doFetchToken();
|
||||||
nextToken = fetchToken();
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (e instanceof OffsetLimitReachedException)
|
|
||||||
throw (OffsetLimitReachedException) e;
|
|
||||||
|
|
||||||
nextToken = null;
|
|
||||||
exception = true;
|
|
||||||
errorHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nextToken == null) {
|
if (nextToken == null) {
|
||||||
if (!exception)
|
finished = true;
|
||||||
finished = true;
|
|
||||||
} else if (nextToken.getType() == IToken.tCOMPLETION) {
|
} else if (nextToken.getType() == IToken.tCOMPLETION) {
|
||||||
finished = true;
|
finished = true;
|
||||||
} else if (nextToken.getType() == IToken.tPOUNDPOUND) {
|
} else if (nextToken.getType() == IToken.tPOUNDPOUND) {
|
||||||
// time for a pasting
|
// time for a pasting
|
||||||
IToken token2 = fetchToken();
|
IToken token2 = doFetchToken();
|
||||||
if (token2 == null) {
|
if (token2 == null) {
|
||||||
nextToken = null;
|
nextToken = null;
|
||||||
finished = true;
|
finished = true;
|
||||||
|
@ -1623,13 +1601,33 @@ abstract class BaseScanner implements IScanner {
|
||||||
.getCharImage(), nextToken.getCharImage()));
|
.getCharImage(), nextToken.getCharImage()));
|
||||||
if (oldToken != null)
|
if (oldToken != null)
|
||||||
oldToken.setNext(lastToken);
|
oldToken.setNext(lastToken);
|
||||||
nextToken = fetchToken();
|
nextToken = doFetchToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lastToken;
|
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
|
* @throws EndOfFileException
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -179,6 +179,14 @@ public class DOMScanner extends BaseScanner {
|
||||||
return codeReaderFactory.createCodeReaderForInclusion(this, finalPath);
|
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)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
@ -186,13 +194,7 @@ public class DOMScanner extends BaseScanner {
|
||||||
* java.lang.Object)
|
* java.lang.Object)
|
||||||
*/
|
*/
|
||||||
protected void pushContext(char[] buffer, Object data) {
|
protected void pushContext(char[] buffer, Object data) {
|
||||||
if (bufferStackPos + 1 == bufferDelta.length) {
|
initBufferDelta(bufferStackPos + 1);
|
||||||
int size = bufferDelta.length * 2;
|
|
||||||
int[] oldBufferDelta = bufferDelta;
|
|
||||||
bufferDelta = new int[size];
|
|
||||||
System.arraycopy(oldBufferDelta, 0, bufferDelta, 0,
|
|
||||||
oldBufferDelta.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data instanceof InclusionData) {
|
if (data instanceof InclusionData) {
|
||||||
|
|
||||||
|
@ -238,6 +240,16 @@ public class DOMScanner extends BaseScanner {
|
||||||
super.pushContext(buffer, data);
|
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;
|
protected int fsmCount = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Reference in a new issue