]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Move UnaryExpression tranformation into code transformer
authorLuca Bruno <lucabru@src.gnome.org>
Sat, 25 Feb 2012 20:25:57 +0000 (21:25 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 1 Apr 2020 08:17:51 +0000 (10:17 +0200)
codegen/valaccodetransformer.vala
vala/valaunaryexpression.vala

index 916478952fa4634bb8e211700d462963166e2b17..56c18643db83c6bbb3e8693c8b9b0d431eee2cf8 100644 (file)
@@ -299,6 +299,32 @@ public class Vala.CCodeTransformer : CodeTransformer {
                }
        }
 
+       public override void visit_unary_expression (UnaryExpression expr) {
+               var parent_statement = expr.parent_statement;
+               if (parent_statement == null) {
+                       base.visit_unary_expression (expr);
+                       return;
+               }
+
+               if (expr.operator == UnaryOperator.INCREMENT || expr.operator == UnaryOperator.DECREMENT) {
+                       var target_type = copy_type (expr.target_type);
+                       begin_replace_expression (expr);
+
+                       Expression replacement;
+                       if (expr.operator == UnaryOperator.INCREMENT) {
+                               replacement = expression (@"$(expr.inner) = $(expr.inner) + 1");
+                       } else {
+                               replacement = expression (@"$(expr.inner) = $(expr.inner) - 1");
+                       }
+                       replacement.target_type = target_type;
+
+                       end_replace_expression (replacement);
+                       return;
+               }
+
+               base.visit_unary_expression (expr);
+       }
+
        public override void visit_object_creation_expression (ObjectCreationExpression expr) {
                if (expr.tree_can_fail) {
                        if (expr.parent_node is LocalVariable || expr.parent_node is ExpressionStatement) {
index 488cef8e9ad88acd7041c76a5615d8e127a8e1d2..bd60b2ecf28042aed63d2ad7e26604836e06f171 100644 (file)
@@ -214,14 +214,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);
+                       value_type = inner.value_type.copy ();
                        return true;
                case UnaryOperator.REF:
                case UnaryOperator.OUT: