Set source location for all loop body-to-front jumps

Task-number: QTBUG-59204
Change-Id: Id1a73b228cd3386c7fcc7712c2485f387238b65e
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
This commit is contained in:
Ulf Hermann 2017-03-01 10:42:47 +01:00 committed by Simon Hausmann
parent 7fe0d1a068
commit d5d12e1d6f
2 changed files with 24 additions and 9 deletions

View File

@ -2256,7 +2256,7 @@ bool Codegen::visit(DoWhileStatement *ast)
_block = loopbody;
statement(ast->statement);
_block->JUMP(loopcond);
setLocation(_block->JUMP(loopcond), ast->statement->lastSourceLocation());
_block = loopcond;
condition(ast->expression, loopbody, loopend);
@ -2321,7 +2321,7 @@ bool Codegen::visit(ForEachStatement *ast)
return false;
move(*init, _block->TEMP(temp));
statement(ast->statement);
_block->JUMP(foreachin);
setLocation(_block->JUMP(foreachin), ast->lastSourceLocation());
_block = foreachin;
@ -2360,7 +2360,7 @@ bool Codegen::visit(ForStatement *ast)
_block = forbody;
statement(ast->statement);
_block->JUMP(forstep);
setLocation(_block->JUMP(forstep), ast->lastSourceLocation());
_block = forstep;
statement(ast->expression);
@ -2460,7 +2460,7 @@ bool Codegen::visit(LocalForEachStatement *ast)
int temp = _block->newTemp();
move(identifier(ast->declaration->name.toString()), _block->TEMP(temp));
statement(ast->statement);
_block->JUMP(foreachin);
setLocation(_block->JUMP(foreachin), ast->lastSourceLocation());
_block = foreachin;
@ -2800,7 +2800,7 @@ bool Codegen::visit(WhileStatement *ast)
_block = whilebody;
statement(ast->statement);
_block->JUMP(whilecond);
setLocation(_block->JUMP(whilecond), ast->lastSourceLocation());
_block = whileend;
leaveLoop();

View File

@ -327,8 +327,9 @@ private slots:
void evaluateExpression();
void stepToEndOfScript();
void lastLineOfLoop();
void lastLineOfLoop_data();
void lastLineOfLoop();
private:
QV4Debugger *debugger() const
{
@ -787,16 +788,30 @@ void tst_qv4debugger::stepToEndOfScript()
QCOMPARE(state.lineNumber, -4); // A return instruction without proper line number.
}
void tst_qv4debugger::lastLineOfLoop_data()
{
QTest::addColumn<QString>("loopHead");
QTest::addColumn<QString>("loopTail");
QTest::newRow("for") << "for (var i = 0; i < 10; ++i) {\n" << "}\n";
QTest::newRow("for..in") << "for (var i in [0, 1, 2, 3, 4]) {\n" << "}\n";
QTest::newRow("while") << "while (ret < 10) {\n" << "}\n";
QTest::newRow("do..while") << "do {\n" << "} while (ret < 10);\n";
}
void tst_qv4debugger::lastLineOfLoop()
{
QFETCH(QString, loopHead);
QFETCH(QString, loopTail);
QString script =
"var ret = 0;\n"
"for (var i = 0; i < 10; ++i) {\n"
" if (i == 2)\n"
+ loopHead +
" if (ret == 2)\n"
" ret += 4;\n" // breakpoint, then step over
" else \n"
" ret += 1;\n"
"}\n"; // after step over
+ loopTail;
debugger()->addBreakPoint("trueBranch", 4);
m_debuggerAgent->m_resumeSpeed = QV4Debugger::StepOver;