[vala] codegen: Add GLibValue.ctype to be used with lvalues



commit 814880a84a42a7dec933d10ec86e56346a26fa41
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun May 15 14:30:12 2011 +0200

    codegen: Add GLibValue.ctype to be used with lvalues
    
    Cast the assigned rvalue to the ctype of the lvalue.

 codegen/valaccodeassignmentmodule.vala   |   12 ++----------
 codegen/valaccodebasemodule.vala         |    8 ++++++++
 codegen/valaccodememberaccessmodule.vala |    2 ++
 3 files changed, 12 insertions(+), 10 deletions(-)
---
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index 9ff0635..01af22a 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -208,17 +208,9 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
 			return;
 		}
 
-		string ctype;
-		if (variable is Field) {
-			ctype = ((Field) variable).get_ctype ();
-		} else if (variable is Parameter) {
-			ctype = ((Parameter) variable).ctype;
-		} else {
-			ctype = null;
-		}
 		var cexpr = get_cvalue_ (value);
-		if (ctype != null) {
-			cexpr = new CCodeCastExpression (cexpr, ctype);
+		if (get_ctype (lvalue) != null) {
+			cexpr = new CCodeCastExpression (cexpr, get_ctype (lvalue));
 		}
 
 		ccode.add_assignment (get_cvalue_ (lvalue), cexpr);
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 9b86093..161e7d3 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5761,6 +5761,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return glib_value.non_null;
 	}
 
+
+	public string? get_ctype (TargetValue value) {
+		var glib_value = (GLibValue) value;
+		return glib_value.ctype;
+	}
+
 	public bool get_array_null_terminated (TargetValue value) {
 		var glib_value = (GLibValue) value;
 		return glib_value.array_null_terminated;
@@ -5775,6 +5781,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 public class Vala.GLibValue : TargetValue {
 	public CCodeExpression cvalue;
 	public bool non_null;
+	public string? ctype;
 
 	public List<CCodeExpression> array_length_cvalues;
 	public CCodeExpression? array_size_cvalue;
@@ -5799,6 +5806,7 @@ public class Vala.GLibValue : TargetValue {
 	public GLibValue copy () {
 		var result = new GLibValue (value_type.copy (), cvalue);
 		result.non_null = non_null;
+		result.ctype = ctype;
 
 		if (array_length_cvalues != null) {
 			foreach (var cexpr in array_length_cvalues) {
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 704feb4..8dd8b2f 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -402,6 +402,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 		if (param.has_array_length_cexpr) {
 			result.array_length_cexpr = new CCodeConstant (param.get_array_length_cexpr ());
 		}
+		result.ctype = param.ctype;
 
 		var array_type = result.value_type as ArrayType;
 		var delegate_type = result.value_type as DelegateType;
@@ -521,6 +522,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 		if (field.has_array_length_cexpr) {
 			result.array_length_cexpr = new CCodeConstant (field.get_array_length_cexpr ());
 		}
+		result.ctype = field.get_ctype ();
 
 		var array_type = result.value_type as ArrayType;
 		var delegate_type = result.value_type as DelegateType;



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