[vala/wip/transform: 75/97] Move postfix transformation from the codegen to the transformer



commit bef0d9f2adf1a03e066b83ae98647e2ee848b2fb
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 +++++++++++++++
 2 files changed, 16 insertions(+), 41 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 5f4b40f27..1c4cbe3a3 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4254,47 +4254,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                set_cvalue (expr, generate_instance_cast (get_this_cexpression (), 
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 (GenericType 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 4b8c68a0d..850cd4283 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);
        }


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