[vala/0.48] vala: Move transformation of unary increment/decrement to codegen



commit 22c78b2346264b7d5395bf564d8ebcbb81e7629f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Aug 13 19:05:49 2020 +0200

    vala: Move transformation of unary increment/decrement to codegen
    
    In preparation for https://gitlab.gnome.org/GNOME/vala/issues/1061

 codegen/valaccodebasemodule.vala | 22 ++++++++++++++++++++++
 vala/valaunaryexpression.vala    | 11 ++---------
 2 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 97a2a1c22..b70a7d81e 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5235,6 +5235,28 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        return;
                }
 
+               if (expr.operator == UnaryOperator.INCREMENT || expr.operator == UnaryOperator.DECREMENT) {
+                       // increment/decrement variable
+                       var op = expr.operator == UnaryOperator.INCREMENT ? CCodeBinaryOperator.PLUS : 
CCodeBinaryOperator.MINUS;
+                       var cexpr = new CCodeBinaryExpression (op, get_cvalue_ (expr.inner.target_value), new 
CCodeConstant ("1"));
+                       ccode.add_assignment (get_cvalue (expr.inner), cexpr);
+
+                       // assign new value to temp variable
+                       var temp_value = store_temp_value (expr.inner.target_value, expr);
+
+                       MemberAccess ma = find_property_access (expr.inner);
+                       if (ma != null) {
+                               // property postfix expression
+                               var prop = (Property) ma.symbol_reference;
+
+                               store_property (prop, ma.inner, temp_value);
+                       }
+
+                       // return new value
+                       expr.target_value = temp_value;
+                       return;
+               }
+
                CCodeUnaryOperator op;
                switch (expr.operator) {
                case UnaryOperator.PLUS:
diff --git a/vala/valaunaryexpression.vala b/vala/valaunaryexpression.vala
index 0ab66ddef..bb11ddfc7 100644
--- a/vala/valaunaryexpression.vala
+++ b/vala/valaunaryexpression.vala
@@ -214,15 +214,8 @@ public class Vala.UnaryExpression : Expression {
                                return false;
                        }
 
-                       var old_value = new MemberAccess (ma.inner, ma.member_name, inner.source_reference);
-                       var bin = new BinaryExpression (operator == UnaryOperator.INCREMENT ? 
BinaryOperator.PLUS : BinaryOperator.MINUS, old_value, new IntegerLiteral ("1"), source_reference);
-
-                       var assignment = new Assignment (ma, bin, AssignmentOperator.SIMPLE, 
source_reference);
-                       assignment.target_type = target_type;
-                       context.analyzer.replaced_nodes.add (this);
-                       parent_node.replace_expression (this, assignment);
-                       assignment.check (context);
-                       return true;
+                       value_type = inner.value_type;
+                       break;
                case UnaryOperator.REF:
                case UnaryOperator.OUT:
                        unowned ElementAccess? ea = inner as ElementAccess;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]