8005703: Offsets miscalculated for blocks
authorjlaskey
Mon, 07 Jan 2013 14:41:16 -0400
changeset 16153 60de45bf54b0
parent 16152 ea430b83d74d
child 16154 de44634fa4ec
8005703: Offsets miscalculated for blocks Reviewed-by: lagergren Contributed-by: petr.hejl@oracle.com
nashorn/src/jdk/nashorn/internal/ir/Block.java
nashorn/src/jdk/nashorn/internal/parser/AbstractParser.java
nashorn/src/jdk/nashorn/internal/parser/Parser.java
--- a/nashorn/src/jdk/nashorn/internal/ir/Block.java	Mon Jan 07 19:31:36 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/ir/Block.java	Mon Jan 07 14:41:16 2013 -0400
@@ -185,6 +185,9 @@
     public void addStatement(final Node statement) {
         if (statement != null) {
             statements.add(statement);
+            if (getFinish() < statement.getFinish()) {
+                setFinish(statement.getFinish());
+            }
         }
     }
 
--- a/nashorn/src/jdk/nashorn/internal/parser/AbstractParser.java	Mon Jan 07 19:31:36 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/parser/AbstractParser.java	Mon Jan 07 14:41:16 2013 -0400
@@ -429,6 +429,8 @@
 
         // Create literal node.
         final Object value = getValue();
+        // Advance to have a correct finish
+        next();
 
         LiteralNode<?> node = null;
 
@@ -452,7 +454,6 @@
             assert false : "unknown type for LiteralNode: " + value.getClass();
         }
 
-        next();
         return node;
     }
 }
--- a/nashorn/src/jdk/nashorn/internal/parser/Parser.java	Mon Jan 07 19:31:36 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/parser/Parser.java	Mon Jan 07 14:41:16 2013 -0400
@@ -938,7 +938,11 @@
 
         // 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 @@
      */
     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 @@
 
         if (executeNode != null) {
             executeNode.setFinish(finish);
+            block.setFinish(finish);
         }
     }
 
@@ -1571,6 +1577,7 @@
                 // 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;