]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Fix use of property assignments as subexpressions
authorJürg Billeter <j@bitron.ch>
Sat, 2 Apr 2011 21:39:04 +0000 (23:39 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 2 Apr 2011 21:39:04 +0000 (23:39 +0200)
Fixes bug 640171.

codegen/valaccodeassignmentmodule.vala
codegen/valaccodebasemodule.vala

index ab9285b2ee25641a9b032e2f34af42bacf9b9f25..ed25014f0d4892770fb0c720e5d52295f3d8b600 100644 (file)
@@ -156,9 +156,25 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
                        var ma = assignment.left as MemberAccess;
                        var prop = (Property) assignment.left.symbol_reference;
 
-                       store_property (prop, ma.inner, assignment.right.target_value);
+                       if (assignment.parent_node is ExpressionStatement) {
+                               store_property (prop, ma.inner, assignment.right.target_value);
 
-                       set_cvalue (assignment, get_ccodenode (assignment.right));
+                               set_cvalue (assignment, get_ccodenode (assignment.right));
+                       } else {
+                               // when load_variable is changed to use temporary
+                               // variables, this exception is no longer necessary
+
+                               var temp_decl = get_temp_variable (prop.property_type);
+                               emit_temp_var (temp_decl);
+                               ccode.add_assignment (get_variable_cexpression (temp_decl.name), get_cvalue_ (assignment.right.target_value));
+
+                               var target_value = ((GLibValue) assignment.right.target_value).copy ();
+                               target_value.cvalue = get_variable_cexpression (temp_decl.name);
+
+                               store_property (prop, ma.inner, target_value);
+
+                               assignment.target_value = target_value;
+                       }
                } else {
                        var array_type = assignment.left.value_type as ArrayType;
                        if (array_type != null && array_type.fixed_length) {
index 0d9cb222da1e888e3b1aa406fb8b512d9d138ea5..764815cc60803e4fdee617fb32c5120ca2dd6170 100644 (file)
@@ -6018,4 +6018,20 @@ public class Vala.GLibValue : TargetValue {
                }
                array_length_cvalues.add (length_cvalue);
        }
+
+       public GLibValue copy () {
+               var result = new GLibValue (value_type.copy (), cvalue);
+
+               if (array_length_cvalues != null) {
+                       foreach (var cexpr in array_length_cvalues) {
+                               result.append_array_length_cvalue (cexpr);
+                       }
+               }
+               result.array_size_cvalue = array_size_cvalue;
+
+               result.delegate_target_cvalue = delegate_target_cvalue;
+               result.delegate_target_destroy_notify_cvalue = delegate_target_destroy_notify_cvalue;
+
+               return result;
+       }
 }