[vala/wip/code-transformer: 21/27] Move UnaryExpression tranformation into CCodeTransformer



commit 1ae25b7f2ed66b92bb350eb711145d9ae19917cd
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Feb 25 21:25:57 2012 +0100

    Move UnaryExpression tranformation into CCodeTransformer

 codegen/valaccodetransformer.vala | 26 ++++++++++++++++++++++++++
 vala/valaunaryexpression.vala     |  9 +--------
 2 files changed, 27 insertions(+), 8 deletions(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index dddade94d..f342018ee 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -318,6 +318,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) {
diff --git a/vala/valaunaryexpression.vala b/vala/valaunaryexpression.vala
index d371d39d9..8c8665d3e 100644
--- a/vala/valaunaryexpression.vala
+++ b/vala/valaunaryexpression.vala
@@ -209,14 +209,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;
                } else if (operator == UnaryOperator.REF || operator == UnaryOperator.OUT) {
                        var ea = inner as ElementAccess;


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