From fb74539d7d14c2444950474ad3f45a80443bfc73 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Sat, 27 Jul 2013 15:12:22 +0200 Subject: [PATCH] Change post-increment/-decrement to not use a built-in. Change-Id: I98af408db1e5d23e73a77d2614071bc998170f5e Reviewed-by: Lars Knoll --- src/qml/compiler/qv4codegen.cpp | 34 ++++++++++++++++++++-------------- src/qml/compiler/qv4jsir_p.h | 4 ++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 969b358..e0c77cf 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -1657,13 +1657,16 @@ bool Codegen::visit(PostDecrementExpression *ast) throwReferenceError(ast->base->lastSourceLocation(), "Invalid left-hand side expression in postfix operation"); throwSyntaxErrorOnEvalOrArgumentsInStrictMode(*expr, ast->decrementToken); - if (_expr.accept(nx)) { - move(*expr, binop(V4IR::OpSub, *expr, _block->CONST(V4IR::NumberType, 1))); - } else { - V4IR::ExprList *args = _function->New(); - args->init(*expr); - _expr.code = call(_block->NAME(V4IR::Name::builtin_postdecrement, ast->lastSourceLocation().startLine, ast->lastSourceLocation().startColumn), args); - } + const unsigned oldValue = _block->newTemp(); + move(_block->TEMP(oldValue), unop(V4IR::OpUPlus, *expr)); + + const unsigned newValue = _block->newTemp(); + move(_block->TEMP(newValue), binop(V4IR::OpSub, _block->TEMP(oldValue), _block->CONST(V4IR::NumberType, 1))); + move(*expr, _block->TEMP(newValue)); + + if (!_expr.accept(nx)) + _expr.code = _block->TEMP(oldValue); + return false; } @@ -1674,13 +1677,16 @@ bool Codegen::visit(PostIncrementExpression *ast) throwReferenceError(ast->base->lastSourceLocation(), "Invalid left-hand side expression in postfix operation"); throwSyntaxErrorOnEvalOrArgumentsInStrictMode(*expr, ast->incrementToken); - if (_expr.accept(nx)) { - move(*expr, binop(V4IR::OpAdd, unop(V4IR::OpUPlus, *expr), _block->CONST(V4IR::NumberType, 1))); - } else { - V4IR::ExprList *args = _function->New(); - args->init(*expr); - _expr.code = call(_block->NAME(V4IR::Name::builtin_postincrement, ast->lastSourceLocation().startLine, ast->lastSourceLocation().startColumn), args); - } + const unsigned oldValue = _block->newTemp(); + move(_block->TEMP(oldValue), unop(V4IR::OpUPlus, *expr)); + + const unsigned newValue = _block->newTemp(); + move(_block->TEMP(newValue), binop(V4IR::OpAdd, _block->TEMP(oldValue), _block->CONST(V4IR::NumberType, 1))); + move(*expr, _block->TEMP(newValue)); + + if (!_expr.accept(nx)) + _expr.code = _block->TEMP(oldValue); + return false; } diff --git a/src/qml/compiler/qv4jsir_p.h b/src/qml/compiler/qv4jsir_p.h index d322ea8..4b1a334 100644 --- a/src/qml/compiler/qv4jsir_p.h +++ b/src/qml/compiler/qv4jsir_p.h @@ -302,8 +302,8 @@ struct Name: Expr { builtin_invalid, builtin_typeof, builtin_delete, - builtin_postincrement, - builtin_postdecrement, + builtin_postincrement, // TODO: remove + builtin_postdecrement, // TODO: remove builtin_throw, builtin_finish_try, builtin_foreach_iterator_object, -- 2.7.4