aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4codegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-11-01 15:32:30 +0100
committerUlf Hermann <ulf.hermann@qt.io>2017-11-08 16:27:30 +0000
commit4d2763e425828ac35c2a03c0e675b83fa8dad668 (patch)
tree753ef220cf8fe941cc7117140d64fdb5361c802a /src/qml/compiler/qv4codegen.cpp
parentba775d50571f8cb445500f0c91ec35b777fa947e (diff)
Set Jump locations for loops
We don't need them for if/else anymore as there are not block terminators anymore. Change-Id: I1ac384e7176cc35faf28028cd274c63dfaa96146 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r--src/qml/compiler/qv4codegen.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index 331132de3b..3cee80e977 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -67,6 +67,27 @@ using namespace QV4;
using namespace QV4::Compiler;
using namespace QQmlJS::AST;
+static inline void setJumpOutLocation(QV4::Moth::BytecodeGenerator *bytecodeGenerator,
+ const Statement *body, const SourceLocation &fallback)
+{
+ switch (body->kind) {
+ // Statements where we might never execute the last line.
+ // Use the fallback.
+ case Statement::Kind_ConditionalExpression:
+ case Statement::Kind_ForEachStatement:
+ case Statement::Kind_ForStatement:
+ case Statement::Kind_IfStatement:
+ case Statement::Kind_LocalForEachStatement:
+ case Statement::Kind_LocalForStatement:
+ case Statement::Kind_WhileStatement:
+ bytecodeGenerator->setLocation(fallback);
+ break;
+ default:
+ bytecodeGenerator->setLocation(body->lastSourceLocation());
+ break;
+ }
+}
+
Codegen::Codegen(QV4::Compiler::JSUnitGenerator *jsUnitGenerator, bool strict)
: _module(0)
, _returnAddress(0)
@@ -2261,6 +2282,7 @@ bool Codegen::visit(DoWhileStatement *ast)
ControlFlowLoop flow(this, &end, &cond);
statement(ast->statement);
+ setJumpOutLocation(bytecodeGenerator, ast->statement, ast->semicolonToken);
cond.link();
@@ -2329,6 +2351,7 @@ bool Codegen::visit(ForEachStatement *ast)
BytecodeGenerator::Label body = bytecodeGenerator->label();
statement(ast->statement);
+ setJumpOutLocation(bytecodeGenerator, ast->statement, ast->forToken);
in.link();
@@ -2367,6 +2390,7 @@ bool Codegen::visit(ForStatement *ast)
body.link();
statement(ast->statement);
+ setJumpOutLocation(bytecodeGenerator, ast->statement, ast->forToken);
step.link();
statement(ast->expression);
@@ -2473,6 +2497,7 @@ bool Codegen::visit(LocalForEachStatement *ast)
Reference it = referenceForName(ast->declaration->name.toString(), true).asLValue();
statement(ast->statement);
+ setJumpOutLocation(bytecodeGenerator, ast->statement, ast->forToken);
in.link();
@@ -2509,6 +2534,7 @@ bool Codegen::visit(LocalForStatement *ast)
body.link();
statement(ast->statement);
+ setJumpOutLocation(bytecodeGenerator, ast->statement, ast->forToken);
step.link();
statement(ast->expression);
@@ -2729,6 +2755,7 @@ bool Codegen::visit(WhileStatement *ast)
start.link();
statement(ast->statement);
+ setJumpOutLocation(bytecodeGenerator, ast->statement, ast->whileToken);
bytecodeGenerator->jump().link(cond);
end.link();