From 4d2763e425828ac35c2a03c0e675b83fa8dad668 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 1 Nov 2017 15:32:30 +0100 Subject: 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 --- src/qml/compiler/qv4codegen.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/qml/compiler/qv4codegen.cpp') 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(); -- cgit v1.2.3