[vala/wip/transform: 197/214] Move postfix transformation from the codegen to the transformer



commit 043b437f343ee41bcf4e4315ac9492f7c0076aa4
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Feb 1 18:37:50 2014 +0100

    Move postfix transformation from the codegen to the transformer

 codegen/valaccodebasemodule.vala  |   41 -------------------------------------
 codegen/valaccodetransformer.vala |   16 ++++++++++++++
 vala/valapostfixexpression.vala   |    5 ++++
 3 files changed, 21 insertions(+), 41 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 6d3289a..33d930f 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4046,47 +4046,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                set_cvalue (expr, generate_instance_cast (this_access, expr.value_type.data_type));
        }
 
-       public override void visit_postfix_expression (PostfixExpression expr) {
-               MemberAccess ma = find_property_access (expr.inner);
-               if (ma != null) {
-                       // property postfix expression
-                       var prop = (Property) ma.symbol_reference;
-
-                       // increment/decrement property
-                       var op = expr.increment ? CCodeBinaryOperator.PLUS : CCodeBinaryOperator.MINUS;
-                       var cexpr = new CCodeBinaryExpression (op, get_cvalue (expr.inner), new CCodeConstant 
("1"));
-                       store_property (prop, ma.inner, new GLibValue (expr.value_type, cexpr));
-
-                       // return previous value
-                       expr.target_value = expr.inner.target_value;
-                       return;
-               }
-
-               // assign current value to temp variable
-               var temp_value = store_temp_value (expr.inner.target_value, expr);
-
-               // increment/decrement variable
-               var op = expr.increment ? CCodeBinaryOperator.PLUS : CCodeBinaryOperator.MINUS;
-               var cexpr = new CCodeBinaryExpression (op, get_cvalue_ (temp_value), new CCodeConstant ("1"));
-               ccode.add_assignment (get_cvalue (expr.inner), cexpr);
-
-               // return previous value
-               expr.target_value = temp_value;
-       }
-       
-       private MemberAccess? find_property_access (Expression expr) {
-               if (!(expr is MemberAccess)) {
-                       return null;
-               }
-               
-               var ma = (MemberAccess) expr;
-               if (ma.symbol_reference is Property) {
-                       return ma;
-               }
-               
-               return null;
-       }
-
        bool is_limited_generic_type (DataType type) {
                var cl = type.type_parameter.parent_symbol as Class;
                var st = type.type_parameter.parent_symbol as Struct;
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index ed870ad..fd6c050 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -561,6 +561,22 @@ public class Vala.CCodeTransformer : CodeTransformer {
                check (replacement);
        }
 
+       public override void visit_postfix_expression (PostfixExpression expr) {
+               push_builder (new CodeBuilder (context, expr.parent_statement, expr.source_reference));
+
+               var result = b.add_temp_declaration (copy_type (expr.value_type), expr.inner);
+               var op = expr.increment ? "+ 1" : "- 1";
+               b.add_expression (expression (@"$(expr.inner) = $result $op"));
+
+               var replacement = return_temp_access (result, expr.value_type, expr.target_type);
+
+               context.analyzer.replaced_nodes.add (expr);
+               expr.parent_node.replace_expression (expr, replacement);
+               b.check (this);
+               pop_builder ();
+               check (replacement);
+       }
+
        public override void visit_assignment (Assignment a) {
                a.accept_children (this);
        }
diff --git a/vala/valapostfixexpression.vala b/vala/valapostfixexpression.vala
index 65303eb..63b4442 100644
--- a/vala/valapostfixexpression.vala
+++ b/vala/valapostfixexpression.vala
@@ -154,4 +154,9 @@ public class Vala.PostfixExpression : Expression {
 
                codegen.visit_expression (this);
        }
+
+       public override string to_string () {
+               var op = increment ? "++" : "--";
+               return @"($inner$op)";
+       }
 }


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