]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Move transformation of unary increment/decrement to codegen
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 13 Aug 2020 17:05:49 +0000 (19:05 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 5 Sep 2020 14:09:03 +0000 (16:09 +0200)
In preparation for https://gitlab.gnome.org/GNOME/vala/issues/1061

codegen/valaccodebasemodule.vala
vala/valaunaryexpression.vala

index 666cd6e44b05501658440754918cbdf11c744c05..46fb3077388185026e8ff3792b83b5a6c9b7bdd3 100644 (file)
@@ -5226,6 +5226,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;
                if (expr.operator == UnaryOperator.PLUS) {
                        op = CCodeUnaryOperator.PLUS;
index 13988136423ca57b9c70af99f04b8ec959be491f..c0635290188600824b2fc32a5d1e349207a749b8 100644 (file)
@@ -219,15 +219,7 @@ 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;
                } else if (operator == UnaryOperator.REF || operator == UnaryOperator.OUT) {
                        var ea = inner as ElementAccess;
                        if (inner.symbol_reference is Field || inner.symbol_reference is Parameter || inner.symbol_reference is LocalVariable ||