]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Use store_local and store_parameter for simple assignments
authorJürg Billeter <j@bitron.ch>
Wed, 16 Feb 2011 09:25:49 +0000 (10:25 +0100)
committerJürg Billeter <j@bitron.ch>
Tue, 22 Feb 2011 14:58:29 +0000 (15:58 +0100)
codegen/valaccodeassignmentmodule.vala
codegen/valaccodebasemodule.vala
codegen/valadovaassignmentmodule.vala
codegen/valadovamemberaccessmodule.vala
vala/valaassignment.vala
vala/valacodegenerator.vala

index 657d0e48ebd1c8945f71be4972602213834af954..136712ea16e166f5a10d1539dae80f566538626c 100644 (file)
@@ -223,4 +223,8 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
        public override void store_local (LocalVariable local, TargetValue value, bool initializer) {
                store_variable (local, get_local_cvalue (local), value, initializer);
        }
+
+       public override void store_parameter (Parameter param, TargetValue value) {
+               store_variable (param, get_parameter_cvalue (param), value, false);
+       }
 }
index bc8604e8b746ce6d8725f83570c2402570f2f562..35d098ba82e86d89ba5164bb4b55bffeb28ea4d8 100644 (file)
@@ -3706,10 +3706,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                assert_not_reached ();
        }
 
-       public virtual TargetValue load_parameter (Parameter param) {
-               assert_not_reached ();
-       }
-
        public virtual string get_delegate_target_cname (string delegate_cname) {
                assert_not_reached ();
        }
index 837c873a72aae6d97cca021dd583e6f8a170f419..1338b024fb3531e596615552feac509616287e4e 100644 (file)
@@ -144,4 +144,8 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
        public override void store_local (LocalVariable local, TargetValue value, bool initializer) {
                store_variable (local, get_local_cvalue (local), value, initializer);
        }
+
+       public override void store_parameter (Parameter param, TargetValue value) {
+               store_variable (param, get_parameter_cvalue (param), value, false);
+       }
 }
index 9fa27aac7d26f1f36b4a91ddcf6ec207bc4fbf49..7cc3d6752dd09814590381a487b4e137065eca4e 100644 (file)
@@ -291,7 +291,7 @@ public abstract class Vala.DovaMemberAccessModule : DovaControlFlowModule {
                return load_variable (local, get_local_cvalue (local));
        }
 
-       public TargetValue load_parameter (Parameter param) {
+       public override TargetValue load_parameter (Parameter param) {
                return load_variable (param, get_parameter_cvalue (param));
        }
 
index f95906099304f3c914df11c220b71862fc6258da..199226fd8e8872213954ed01e96af5e9787ccf06 100644 (file)
@@ -1,6 +1,6 @@
 /* valaassignment.vala
  *
- * Copyright (C) 2006-2010  Jürg Billeter
+ * Copyright (C) 2006-2011  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -443,17 +443,62 @@ public class Vala.Assignment : Expression {
                return !error;
        }
 
+       bool is_array_add () {
+               var binary = right as BinaryExpression;
+               if (binary != null && binary.left.value_type is ArrayType) {
+                       if (binary.operator == BinaryOperator.PLUS) {
+                               if (left.symbol_reference == binary.left.symbol_reference) {
+                                       return true;
+                               }
+                       }
+               }
+
+               return false;
+       }
+
        public override void emit (CodeGenerator codegen) {
                var ma = left as MemberAccess;
                var ea = left as ElementAccess;
                var pi = left as PointerIndirection;
                if (ma != null) {
+                       var local = ma.symbol_reference as LocalVariable;
+                       var param = ma.symbol_reference as Parameter;
                        var field = ma.symbol_reference as Field;
                        var property = ma.symbol_reference as Property;
 
                        bool instance = (field != null && field.binding == MemberBinding.INSTANCE)
                                || (property != null && property.binding == MemberBinding.INSTANCE);
 
+                       if (operator == AssignmentOperator.SIMPLE &&
+                           (local != null || param != null) &&
+                           !is_array_add ()) {
+                               // visit_assignment not necessary
+                               if (instance) {
+                                       ma.inner.emit (codegen);
+                               }
+
+                               right.emit (codegen);
+                               var new_value = right.target_value;
+
+                               if (local != null) {
+                                       codegen.store_local (local, new_value, false);
+                               } else if (param != null) {
+                                       codegen.store_parameter (param, new_value);
+                               }
+
+                               // when load_variable is changed to use temporary
+                               // variables, replace following code with this line
+                               // target_value = new_value;
+                               if (local != null) {
+                                       target_value = codegen.load_local (local);
+                               } else if (param != null) {
+                                       target_value = codegen.load_parameter (param);
+                               }
+
+                               codegen.visit_expression (this);
+                               return;
+                       }
+
                        if (field != null) {
                                // always process full lvalue
                                // current codegen depends on it
index 65624f4fbb862e0c61d4108acacaca64e8381788..d3ca065d61ae0481ae2bf244125ece929bd2862c 100644 (file)
@@ -1,6 +1,6 @@
 /* valacodegenerator.vala
  *
- * Copyright (C) 2007-2010  Jürg Billeter
+ * Copyright (C) 2007-2011  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -37,4 +37,8 @@ public abstract class Vala.CodeGenerator : CodeVisitor {
        public abstract TargetValue load_local (LocalVariable local);
 
        public abstract void store_local (LocalVariable local, TargetValue value, bool initializer);
+
+       public abstract TargetValue load_parameter (Parameter param);
+
+       public abstract void store_parameter (Parameter param, TargetValue value);
 }