]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Add GLibValue.ctype to be used with lvalues
authorLuca Bruno <lucabru@src.gnome.org>
Sun, 15 May 2011 12:30:12 +0000 (14:30 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Sun, 15 May 2011 12:47:45 +0000 (14:47 +0200)
Cast the assigned rvalue to the ctype of the lvalue.

codegen/valaccodeassignmentmodule.vala
codegen/valaccodebasemodule.vala
codegen/valaccodememberaccessmodule.vala

index 9ff063568ba9376e2d532de17dd7a7ee95dc2cf8..01af22a23bae282e4ff2cd00fc0bb919b8cb31ab 100644 (file)
@@ -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);
index 9b860930636a55414bd1e50bf0cb6cae2026ae63..161e7d37be3e4539dba4213335a543adefe71fb3 100644 (file)
@@ -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) {
index 704feb4cb9c337d36d66f92109b3f34f035ec598..8dd8b2ff782ebb46f24acc2596a919172d509dcd 100644 (file)
@@ -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;