8005703: Offsets miscalculated for blocks

Reviewed-by: lagergren
This commit is contained in:
Petr Hejl 2013-01-07 14:41:16 -04:00 committed by Jim Laskey
parent 24e583d55f
commit 569e8ef170
3 changed files with 13 additions and 2 deletions

View File

@ -185,6 +185,9 @@ public class Block extends Node {
public void addStatement(final Node statement) {
if (statement != null) {
statements.add(statement);
if (getFinish() < statement.getFinish()) {
setFinish(statement.getFinish());
}
}
}

View File

@ -429,6 +429,8 @@ public abstract class AbstractParser {
// Create literal node.
final Object value = getValue();
// Advance to have a correct finish
next();
LiteralNode<?> node = null;
@ -452,7 +454,6 @@ public abstract class AbstractParser {
assert false : "unknown type for LiteralNode: " + value.getClass();
}
next();
return node;
}
}

View File

@ -938,7 +938,11 @@ loop:
// If is a statement then handle end of line.
if (isStatement) {
boolean semicolon = type == SEMICOLON;
endOfLine();
if (semicolon) {
block.setFinish(finish);
}
}
return vars;
@ -954,7 +958,8 @@ loop:
*/
private void emptyStatement() {
if (context._empty_statements) {
block.addStatement(new EmptyNode(source, token, Token.descPosition(token)));
block.addStatement(new EmptyNode(source, token,
Token.descPosition(token) + Token.descLength(token)));
}
// SEMICOLON checked in caller.
@ -988,6 +993,7 @@ loop:
if (executeNode != null) {
executeNode.setFinish(finish);
block.setFinish(finish);
}
}
@ -1571,6 +1577,7 @@ loop:
// Get CASE body.
final Block statements = getBlock(false);
final CaseNode caseNode = new CaseNode(source, caseToken, finish, caseExpression, statements);
statements.setFinish(finish);
if (caseExpression == null) {
defaultCase = caseNode;