Change post-increment/-decrement to not use a built-in.
authorErik Verbruggen <erik.verbruggen@me.com>
Sat, 27 Jul 2013 13:12:22 +0000 (15:12 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 13 Aug 2013 12:52:27 +0000 (14:52 +0200)
Change-Id: I98af408db1e5d23e73a77d2614071bc998170f5e
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/compiler/qv4codegen.cpp
src/qml/compiler/qv4jsir_p.h

index 969b358..e0c77cf 100644 (file)
@@ -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<V4IR::ExprList>();
-        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<V4IR::ExprList>();
-        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;
 }
 
index d322ea8..4b1a334 100644 (file)
@@ -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,