[vala] codegen: Return TargetValue from copy_value



commit bf9e4baaa9f4dd707c3a3f421c88f010902fe28f
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat May 7 10:19:01 2011 +0200

    codegen: Return TargetValue from copy_value

 codegen/valaccodearraymodule.vala       |    8 ++++----
 codegen/valaccodebasemodule.vala        |   19 +++++++++++--------
 codegen/valaccodecontrolflowmodule.vala |    2 +-
 codegen/valagasyncmodule.vala           |    2 +-
 4 files changed, 17 insertions(+), 14 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index d5622da..4f8a918 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -409,7 +409,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 		cfile.add_function (fun);
 	}
 
-	public override CCodeExpression? copy_value (TargetValue value, Expression? expr, CodeNode node) {
+	public override TargetValue? copy_value (TargetValue value, Expression? expr, CodeNode node) {
 		var type = value.value_type;
 		var cexpr = get_cvalue_ (value);
 
@@ -434,7 +434,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 			ccomma.append_expression (copy_call);
 			ccomma.append_expression (ctemp);
 
-			return ccomma;
+			return new GLibValue (type, ccomma);
 		} else {
 			return base.copy_value (value, expr, node);
 		}
@@ -525,7 +525,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 			                   new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier ("i"), new CCodeIdentifier ("length")),
 			                   new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("i")));
 
-			ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("result"), new CCodeIdentifier ("i")), copy_value (new GLibValue (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i"))), null, array_type));
+			ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("result"), new CCodeIdentifier ("i")), get_cvalue_ (copy_value (new GLibValue (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i"))), null, array_type)));
 			ccode.close ();
 
 			ccode.add_return (new CCodeIdentifier ("result"));
@@ -579,7 +579,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 			                   new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("i")));
 
 
-			ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("dest"), new CCodeIdentifier ("i")), copy_value (new GLibValue (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i"))), null, array_type));
+			ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("dest"), new CCodeIdentifier ("i")), get_cvalue_ (copy_value (new GLibValue (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i"))), null, array_type)));
 		} else {
 			cfile.add_include ("string.h");
 
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index afa97fe..5ad7b80 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3702,15 +3702,18 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			value.delegate_target_cvalue = get_delegate_target_cvalue (expr.target_value);
 			value.delegate_target_destroy_notify_cvalue = get_delegate_target_destroy_notify_cvalue (expr.target_value);
 		}
-		return copy_value (value, expr, node);
+		var result = copy_value (value, expr, node);
+		return get_cvalue_ (result);
 	}
 
-	public virtual CCodeExpression? copy_value (TargetValue value, Expression? expr, CodeNode node) {
+	public virtual TargetValue? copy_value (TargetValue value, Expression? expr, CodeNode node) {
 		var type = value.value_type;
 		var cexpr = get_cvalue_ (value);
 
 		if (type is DelegateType) {
-			return cexpr;
+			var result = ((GLibValue) value).copy ();
+			result.delegate_target_destroy_notify_cvalue = new CCodeConstant ("NULL");
+			return result;
 		}
 
 		if (type is ValueType && !type.nullable) {
@@ -3749,13 +3752,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				ccode.add_else ();
 
 				// g_value_init/copy must not be called for uninitialized values
-				ccode.add_assignment (ctemp, cexpr);
+				store_local (decl, value, true);
 				ccode.close ();
 			} else {
 				ccode.add_expression (copy_call);
 			}
 
-			return ctemp;
+			return get_local_cvalue (decl);
 		}
 
 		/* (temp = expr, temp == NULL ? NULL : ref (temp))
@@ -3805,7 +3808,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 			var ccall = new CCodeFunctionCall (new CCodeIdentifier (dup0_func));
 			ccall.add_argument (cexpr);
-			return ccall;
+			return new GLibValue (type, ccall);
 		}
 
 		var ccall = new CCodeFunctionCall (dupexpr);
@@ -3815,7 +3818,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			// expression is non-null
 			ccall.add_argument (get_cvalue (expr));
 			
-			return ccall;
+			return new GLibValue (type, ccall);
 		} else {
 			var decl = get_temp_variable (type, false, node, false);
 			emit_temp_var (decl);
@@ -3871,7 +3874,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				ccomma.append_expression (ctemp);
 			}
 
-			return ccomma;
+			return new GLibValue (type, ccomma);
 		}
 	}
 
diff --git a/codegen/valaccodecontrolflowmodule.vala b/codegen/valaccodecontrolflowmodule.vala
index 6d9c37e..29b1412 100644
--- a/codegen/valaccodecontrolflowmodule.vala
+++ b/codegen/valaccodecontrolflowmodule.vala
@@ -328,7 +328,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
 			CCodeExpression element_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_item);
 
 			if (stmt.type_reference.value_owned) {
-				element_expr = copy_value (new GLibValue (stmt.type_reference, element_expr), null, new StructValueType (gvalue_type));
+				element_expr = get_cvalue_ (copy_value (new GLibValue (stmt.type_reference, element_expr), null, new StructValueType (gvalue_type)));
 			}
 
 			visit_local_variable (stmt.element_variable);
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 8bcdfd8..370961c 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -444,7 +444,7 @@ public class Vala.GAsyncModule : GSignalModule {
 			// structs are returned via out parameter
 			CCodeExpression cexpr = new CCodeMemberAccess.pointer (data_var, "result");
 			if (requires_copy (return_type)) {
-				cexpr = copy_value (new GLibValue (return_type, cexpr), null, return_type);
+				cexpr = get_cvalue_ (copy_value (new GLibValue (return_type, cexpr), null, return_type));
 			}
 			ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("result")), cexpr);
 		} else if (!(return_type is VoidType)) {



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