提交 37ee6eb3 编写于 作者: L lagergren

8028434: Line number nodes were off for while nodes and do while nodes - the...

8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
Reviewed-by: jlaskey, sundar
上级 646e3ac5
......@@ -2186,15 +2186,14 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
@Override
public boolean enterWhileNode(final WhileNode whileNode) {
lineNumber(whileNode);
final Expression test = whileNode.getTest();
final Block body = whileNode.getBody();
final Label breakLabel = whileNode.getBreakLabel();
final Label continueLabel = whileNode.getContinueLabel();
final boolean isDoWhile = whileNode.isDoWhile();
final Label loopLabel = new Label("loop");
if (!whileNode.isDoWhile()) {
if (!isDoWhile) {
method._goto(continueLabel);
}
......@@ -2202,6 +2201,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
body.accept(this);
if (!whileNode.isTerminal()) {
method.label(continueLabel);
lineNumber(whileNode);
new BranchOptimizer(this, method).execute(test, loopLabel, true);
method.label(breakLabel);
}
......
......@@ -28,6 +28,7 @@ package jdk.nashorn.internal.ir.debug;
import java.util.List;
import jdk.nashorn.internal.ir.BinaryNode;
import jdk.nashorn.internal.ir.Block;
import jdk.nashorn.internal.ir.BlockStatement;
import jdk.nashorn.internal.ir.CaseNode;
import jdk.nashorn.internal.ir.CatchNode;
import jdk.nashorn.internal.ir.ExpressionStatement;
......@@ -141,7 +142,6 @@ public final class PrintVisitor extends NodeVisitor<LexicalContext> {
@Override
public boolean enterBlock(final Block block) {
sb.append(' ');
//sb.append(Debug.id(block));
sb.append('{');
indent += TABWIDTH;
......@@ -190,11 +190,16 @@ public final class PrintVisitor extends NodeVisitor<LexicalContext> {
sb.append(EOLN);
indent();
sb.append('}');
// sb.append(Debug.id(block));
return false;
}
@Override
public boolean enterBlockStatement(final BlockStatement statement) {
statement.getBlock().accept(this);
return false;
}
@Override
public boolean enterBinaryNode(final BinaryNode binaryNode) {
binaryNode.lhs().accept(this);
......@@ -233,7 +238,6 @@ public final class PrintVisitor extends NodeVisitor<LexicalContext> {
public boolean enterFunctionNode(final FunctionNode functionNode) {
functionNode.toString(sb);
enterBlock(functionNode.getBody());
//sb.append(EOLN);
return false;
}
......
......@@ -1210,21 +1210,24 @@ loop:
*/
private void whileStatement() {
// Capture WHILE token.
final int whileLine = line;
final long whileToken = token;
// WHILE tested in caller.
next();
// Construct WHILE node.
WhileNode whileNode = new WhileNode(whileLine, whileToken, Token.descPosition(whileToken), false);
WhileNode whileNode = new WhileNode(line, whileToken, Token.descPosition(whileToken), false);
lc.push(whileNode);
try {
expect(LPAREN);
whileNode = whileNode.setTest(lc, expression());
final int whileLine = line;
final Expression test = expression();
expect(RPAREN);
whileNode = whileNode.setBody(lc, getStatement());
appendStatement(whileNode);
final Block body = getStatement();
appendStatement(whileNode =
new WhileNode(whileLine, whileToken, finish, false).
setTest(lc, test).
setBody(lc, body));
} finally {
lc.pop(whileNode);
}
......@@ -1242,28 +1245,33 @@ loop:
*/
private void doStatement() {
// Capture DO token.
final int doLine = line;
final long doToken = token;
// DO tested in the caller.
next();
WhileNode doWhileNode = new WhileNode(doLine, doToken, Token.descPosition(doToken), true);
WhileNode doWhileNode = new WhileNode(-1, doToken, Token.descPosition(doToken), true);
lc.push(doWhileNode);
try {
// Get DO body.
doWhileNode = doWhileNode.setBody(lc, getStatement());
final Block body = getStatement();
expect(WHILE);
expect(LPAREN);
doWhileNode = doWhileNode.setTest(lc, expression());
final int doLine = line;
final Expression test = expression();
expect(RPAREN);
if (type == SEMICOLON) {
endOfLine();
}
doWhileNode.setFinish(finish);
appendStatement(doWhileNode);
//line number is last
appendStatement(doWhileNode =
new WhileNode(doLine, doToken, finish, true).
setBody(lc, body).
setTest(lc, test));
} finally {
lc.pop(doWhileNode);
}
......
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* JDK-8028434: Check that the line number of the tests in while and do while loops
* is correct. It needs to correspond to the line with the test expression.
*
* @test
* @run
*/
try {
while (test.apa < 0) {
print("x");
}
} catch (e) {
var st = e.getStackTrace();
if (st.length != 1) {
print("erroneous stacktrace length " + s.length);
}
if (st[0].lineNumber !== 32) {
print("erroneous stacktrace element, lineNumber=" + st[0].lineNumber + " elem=" + st);
}
}
try {
do {
print("x");
} while (test.apa < 0);
} catch (e) {
var st = e.getStackTrace();
if (st.length != 1) {
print("erroneous stacktrace length " + s.length);
}
if (st[0].lineNumber !== 48) {
print("erroneous stacktrace element, lineNumber= " + st[0].lineNumber + " elem=" + st);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册