[vala] codegen: Fix use of property assignments as subexpressions



commit 15bb27974b6c2e253744d7cc0de5a6f27a6ebbb4
Author: Jürg Billeter <j bitron ch>
Date:   Sat Apr 2 23:39:04 2011 +0200

    codegen: Fix use of property assignments as subexpressions
    
    Fixes bug 640171.

 codegen/valaccodeassignmentmodule.vala |   20 ++++++++++++++++++--
 codegen/valaccodebasemodule.vala       |   16 ++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index ab9285b..ed25014 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -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) {
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 0d9cb22..764815c 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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;
+	}
 }



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