[vala] codegen: Use copy_value instead of get_ref_cexpression



commit f80ccc62764157db6329a87d6cc1cd7f16a64382
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat May 7 11:42:03 2011 +0200

    codegen: Use copy_value instead of get_ref_cexpression

 codegen/valaccodebasemodule.vala   |   28 ++++++++++++++--------------
 codegen/valaccodestructmodule.vala |   13 ++++---------
 codegen/valagasyncmodule.vala      |   10 ++++------
 3 files changed, 22 insertions(+), 29 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index e6afe37..405a1f0 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1641,13 +1641,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			cparam = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, cparam);
 		}
 		if (requires_copy (param_type) && !param.variable_type.value_owned && !is_unowned_delegate)  {
-			var ma = new MemberAccess.simple (param.name);
-			ma.symbol_reference = param;
-			ma.value_type = param.variable_type.copy ();
 			// directly access parameters in ref expressions
 			param.captured = false;
-			visit_member_access (ma);
-			cparam = get_ref_cexpression (param.variable_type, cparam, ma, param);
+			var value = load_parameter (param);
+			((GLibValue) value).cvalue = cparam;
+			cparam = get_cvalue_ (copy_value (value, param));
 			param.captured = true;
 		}
 
@@ -5255,7 +5253,15 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 				var decl = get_temp_variable (target_type, true, node, false);
 				emit_temp_var (decl);
-				ccode.add_assignment (get_variable_cexpression (decl.name), get_ref_cexpression (target_type, cexpr, expr, node));
+				GLibValue value;
+				if (expr != null && expr.target_value != null) {
+					value = ((GLibValue) expr.target_value).copy ();
+					value.value_type = target_type;
+					value.cvalue = cexpr;
+				} else {
+					value = new GLibValue (target_type, cexpr);
+				}
+				ccode.add_assignment (get_variable_cexpression (decl.name), get_cvalue_ (copy_value (value, node)));
 				cexpr = get_variable_cexpression (decl.name);
 			}
 		}
@@ -5639,14 +5645,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			if (f.binding == MemberBinding.INSTANCE) {
 				CCodeExpression copy = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), f.name);
 				if (requires_copy (f.variable_type))  {
-					var this_access = new MemberAccess.simple ("this");
-					this_access.value_type = get_data_type_for_symbol ((TypeSymbol) f.parent_symbol);
-					set_cvalue (this_access, new CCodeIdentifier ("(*self)"));
-					var ma = new MemberAccess (this_access, f.name);
-					ma.symbol_reference = f;
-					ma.value_type = f.variable_type.copy ();
-					visit_member_access (ma);
-					copy = get_ref_cexpression (f.variable_type, copy, ma, f);
+					var value = load_field (f, load_this_parameter ((TypeSymbol) f.parent_symbol));
+					copy = get_cvalue_ (copy_value (value, f));
 				}
 				var dest = new CCodeMemberAccess.pointer (new CCodeIdentifier ("dest"), f.name);
 
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 5b13e67..b4b4a88 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -259,18 +259,13 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 			if (f.binding == MemberBinding.INSTANCE) {
 				CCodeExpression copy = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), f.name);
 				if (requires_copy (f.variable_type))  {
-					var this_access = new MemberAccess.simple ("this");
-					this_access.value_type = get_data_type_for_symbol ((TypeSymbol) f.parent_symbol);
-					set_cvalue (this_access, new CCodeIdentifier ("(*self)"));
-					var ma = new MemberAccess (this_access, f.name);
-					ma.symbol_reference = f;
-					ma.value_type = f.variable_type.copy ();
-					visit_member_access (ma);
-					copy = get_ref_cexpression (f.variable_type, copy, ma, f);
-					if (copy == null) {
+					var value = load_field (f, load_this_parameter ((TypeSymbol) f.parent_symbol));
+					var value_copy = copy_value (value, f);
+					if (value_copy == null) {
 						// error case, continue to avoid critical
 						continue;
 					}
+					copy = get_cvalue_ (value_copy);
 				}
 				var dest = new CCodeMemberAccess.pointer (new CCodeIdentifier ("dest"), f.name);
 
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 6bd095a..e11dc7a 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -236,11 +236,7 @@ public class Vala.GAsyncModule : GSignalModule {
 				cself = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, cself);
 			}
 			if (requires_copy (this_type))  {
-				var ma = new MemberAccess.simple ("this");
-				ma.symbol_reference = m.this_parameter;
-				ma.value_type = m.this_parameter.variable_type.copy ();
-				visit_member_access (ma);
-				cself = get_ref_cexpression (m.this_parameter.variable_type, cself, ma, m.this_parameter);
+				cself = get_cvalue_ (copy_value (new GLibValue (m.this_parameter.variable_type, cself), m.this_parameter));
 			}
 
 			ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, "self"), cself);
@@ -261,7 +257,9 @@ public class Vala.GAsyncModule : GSignalModule {
 					ma.symbol_reference = param;
 					ma.value_type = param.variable_type.copy ();
 					visit_member_access (ma);
-					cparam = get_ref_cexpression (param.variable_type, cparam, ma, param);
+					var value = load_parameter (param);
+					((GLibValue) value).cvalue = cparam;
+					cparam = get_cvalue_ (copy_value (value, param));
 				}
 
 				ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, get_variable_cname (param.name)), cparam);



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