[vala/staging] codegen: Remove hardcoded "int" length type and use ArrayType.length_type



commit c0709493ef75f3404eb29cfd495542f21d948859
Author: George Barrett <bob bob131 so>
Date:   Tue Dec 12 14:37:38 2017 +1100

    codegen: Remove hardcoded "int" length type and use ArrayType.length_type
    
    https://gitlab.gnome.org/GNOME/vala/issues/607

 codegen/valaccode.vala                   |  6 +++-
 codegen/valaccodearraymodule.vala        |  5 +---
 codegen/valaccodebasemodule.vala         | 49 +++++++++++++++++---------------
 codegen/valaccodedelegatemodule.vala     | 14 ++++-----
 codegen/valaccodememberaccessmodule.vala |  4 +--
 codegen/valaccodemethodcallmodule.vala   | 33 +++++++--------------
 codegen/valaccodemethodmodule.vala       |  8 +++---
 codegen/valaccodestructmodule.vala       |  6 ++--
 codegen/valagasyncmodule.vala            |  6 ++--
 codegen/valagsignalmodule.vala           | 12 ++++++--
 codegen/valagtypemodule.vala             | 25 +++++++++-------
 codegen/valagvariantmodule.vala          |  9 +++---
 12 files changed, 90 insertions(+), 87 deletions(-)
---
diff --git a/codegen/valaccode.vala b/codegen/valaccode.vala
index 1bb92171e..bc29b259d 100644
--- a/codegen/valaccode.vala
+++ b/codegen/valaccode.vala
@@ -247,7 +247,11 @@ namespace Vala {
        }
 
        public static string? get_ccode_array_length_type (CodeNode node) {
-               return get_ccode_attribute(node).array_length_type;
+               if (node is ArrayType) {
+                       return get_ccode_name (((ArrayType) node).length_type);
+               } else {
+                       return get_ccode_attribute(node).array_length_type;
+               }
        }
 
        public static bool get_ccode_array_null_terminated (CodeNode node) {
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 1730da7f6..c3ad53fc7 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -744,10 +744,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                }
 
                if (!array_type.fixed_length && get_ccode_array_length (param)) {
-                       string length_ctype = "int";
-                       if (get_ccode_array_length_type (param) != null) {
-                               length_ctype = get_ccode_array_length_type (param);
-                       }
+                       var length_ctype = get_ccode_array_length_type (array_type);
                        if (param.direction != ParameterDirection.IN) {
                                length_ctype = "%s*".printf (length_ctype);
                        }
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index e37042044..5dae5e1bf 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1069,10 +1069,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        var array_type = (ArrayType) f.variable_type;
 
                        if (!array_type.fixed_length) {
-                               for (int dim = 1; dim <= array_type.rank; dim++) {
-                                       var len_type = int_type.copy ();
+                               var length_ctype = get_ccode_array_length_type (array_type);
 
-                                       cdecl = new CCodeDeclaration (get_ccode_name (len_type));
+                               for (int dim = 1; dim <= array_type.rank; dim++) {
+                                       cdecl = new CCodeDeclaration (length_ctype);
                                        cdecl.add_declarator (new CCodeVariableDeclarator 
(get_array_length_cname (get_ccode_name (f), dim)));
                                        if (f.is_private_symbol ()) {
                                                cdecl.modifiers = CCodeModifiers.STATIC;
@@ -1282,10 +1282,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                        var array_type = (ArrayType) f.variable_type;
 
                                        if (!array_type.fixed_length) {
-                                               for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                       var len_type = int_type.copy ();
+                                               var length_ctype = get_ccode_array_length_type (array_type);
 
-                                                       var len_def = new CCodeDeclaration (get_ccode_name 
(len_type));
+                                               for (int dim = 1; dim <= array_type.rank; dim++) {
+                                                       var len_def = new CCodeDeclaration (length_ctype);
                                                        len_def.add_declarator (new CCodeVariableDeclarator 
(get_array_length_cname (get_ccode_name (f), dim), new CCodeConstant ("0")));
                                                        if (!f.is_private_symbol ()) {
                                                                len_def.modifiers = CCodeModifiers.EXTERN;
@@ -1296,9 +1296,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                                }
 
                                                if (array_type.rank == 1 && f.is_internal_symbol ()) {
-                                                       var len_type = int_type.copy ();
-
-                                                       var cdecl = new CCodeDeclaration (get_ccode_name 
(len_type));
+                                                       var cdecl = new CCodeDeclaration (length_ctype);
                                                        cdecl.add_declarator (new CCodeVariableDeclarator 
(get_array_size_cname (get_ccode_name (f)), new CCodeConstant ("0")));
                                                        cdecl.modifiers = CCodeModifiers.STATIC;
                                                        cfile.add_type_member_declaration (cdecl);
@@ -1563,8 +1561,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                if (acc.value_type is ArrayType) {
                        var array_type = (ArrayType) acc.value_type;
+                       var length_ctype = get_ccode_array_length_type (array_type);
                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                               function.add_parameter (new CCodeParameter (get_array_length_cname 
(acc.readable ? "result" : "value", dim), acc.readable ? "int*" : "int"));
+                               function.add_parameter (new CCodeParameter (get_array_length_cname 
(acc.readable ? "result" : "value", dim), acc.readable ? length_ctype + "*" : length_ctype));
                        }
                } else if ((acc.value_type is DelegateType) && ((DelegateType) 
acc.value_type).delegate_symbol.has_target) {
                        function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? 
"result" : "value"), acc.readable ? "gpointer*" : "gpointer"));
@@ -1665,8 +1664,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                        if (acc.value_type is ArrayType) {
                                var array_type = (ArrayType) acc.value_type;
+                               var length_ctype = get_ccode_array_length_type (array_type);
                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                       function.add_parameter (new CCodeParameter (get_array_length_cname 
(acc.readable ? "result" : "value", dim), acc.readable ? "int*" : "int"));
+                                       function.add_parameter (new CCodeParameter (get_array_length_cname 
(acc.readable ? "result" : "value", dim), acc.readable ? length_ctype + "*": length_ctype));
                                }
                        } else if ((acc.value_type is DelegateType) && ((DelegateType) 
acc.value_type).delegate_symbol.has_target) {
                                function.add_parameter (new CCodeParameter (get_delegate_target_cname 
(acc.readable ? "result" : "value"), acc.readable ? "gpointer*" : "gpointer"));
@@ -1788,8 +1788,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                        if (acc.value_type is ArrayType) {
                                var array_type = (ArrayType) acc.value_type;
+                               var length_ctype = get_ccode_array_length_type (array_type);
                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                       function.add_parameter (new CCodeParameter (get_array_length_cname 
(acc.readable ? "result" : "value", dim), acc.readable ? "int*" : "int"));
+                                       function.add_parameter (new CCodeParameter (get_array_length_cname 
(acc.readable ? "result" : "value", dim), acc.readable ? length_ctype + "*" : length_ctype));
                                }
                        } else if ((acc.value_type is DelegateType) && ((DelegateType) 
acc.value_type).delegate_symbol.has_target) {
                                function.add_parameter (new CCodeParameter (get_delegate_target_cname 
(acc.readable ? "result" : "value"), acc.readable ? "gpointer*" : "gpointer"));
@@ -1844,7 +1845,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                        get_call.add_argument (new CCodeIdentifier (is_virtual ? "base" : 
"self"));
 
                                        if (property_type is ArrayType) {
-                                               ccode.add_declaration ("int", new CCodeVariableDeclarator 
("old_value_length"));
+                                               ccode.add_declaration (get_ccode_array_length_type 
(property_type), new CCodeVariableDeclarator ("old_value_length"));
                                                get_call.add_argument (new CCodeUnaryExpression 
(CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("old_value_length")));
                                                ccode.open_if (new CCodeBinaryExpression 
(CCodeBinaryOperator.INEQUALITY, get_call, new CCodeIdentifier ("value")));
                                        } else if (property_type.compatible (string_type)) {
@@ -1933,8 +1934,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                var deleg_type = param.variable_type as DelegateType;
 
                if (array_type != null && get_ccode_array_length (param)) {
+                       var length_ctype = get_ccode_array_length_type (array_type);
                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                               data.add_field ("gint", get_parameter_array_length_cname (param, dim));
+                               data.add_field (length_ctype, get_parameter_array_length_cname (param, dim));
                        }
                } else if (deleg_type != null && deleg_type.delegate_symbol.has_target) {
                        data.add_field ("gpointer", get_ccode_delegate_target_name (param));
@@ -2000,10 +2002,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                                        if (local.variable_type is ArrayType && !((ArrayType) 
local.variable_type).fixed_length) {
                                                var array_type = (ArrayType) local.variable_type;
+                                               var length_ctype = get_ccode_array_length_type (array_type);
                                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                       data.add_field ("gint", get_array_length_cname 
(get_local_cname (local), dim));
+                                                       data.add_field (length_ctype, get_array_length_cname 
(get_local_cname (local), dim));
                                                }
-                                               data.add_field ("gint", get_array_size_cname (get_local_cname 
(local)));
+                                               data.add_field (length_ctype, get_array_size_cname 
(get_local_cname (local)));
                                        } else if (local.variable_type is DelegateType && ((DelegateType) 
local.variable_type).delegate_symbol.has_target) {
                                                data.add_field ("gpointer", get_delegate_target_cname 
(get_local_cname (local)));
                                                if (local.variable_type.is_disposable ()) {
@@ -2448,13 +2451,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                                if (!array_type.fixed_length) {
                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                               var len_var = new LocalVariable (int_type.copy (), 
get_array_length_cname (get_local_cname (local), dim));
+                                               var len_var = new LocalVariable (array_type.length_type.copy 
(), get_array_length_cname (get_local_cname (local), dim));
                                                len_var.init = local.initializer == null;
                                                emit_temp_var (len_var);
                                        }
 
                                        if (array_type.rank == 1) {
-                                               var size_var = new LocalVariable (int_type.copy (), 
get_array_size_cname (get_local_cname (local)));
+                                               var size_var = new LocalVariable (array_type.length_type.copy 
(), get_array_size_cname (get_local_cname (local)));
                                                size_var.init = local.initializer == null;
                                                emit_temp_var (size_var);
                                        }
@@ -2506,7 +2509,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                emit_temp_var (local);
                if (array_type != null) {
                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                               var len_var = new LocalVariable (int_type.copy (), get_array_length_cname 
(local.name, dim), null, node_reference.source_reference);
+                               var len_var = new LocalVariable (array_type.length_type.copy (), 
get_array_length_cname (local.name, dim), null, node_reference.source_reference);
                                len_var.init = init;
                                emit_temp_var (len_var);
                        }
@@ -5205,10 +5208,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        // return array length if appropriate
                        // tmp = _variant_get (variant, &tmp_length);
                        var array_type = (ArrayType) to;
-
+                       var length_ctype = get_ccode_array_length_type (array_type);
                        for (int dim = 1; dim <= array_type.rank; dim++) {
                                ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, 
get_array_length_cvalue (result, dim)));
-                               cfunc.add_parameter (new CCodeParameter (get_array_length_cname ("result", 
dim), "int*"));
+                               cfunc.add_parameter (new CCodeParameter (get_array_length_cname ("result", 
dim), length_ctype + "*"));
                        }
                }
 
@@ -5977,10 +5980,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        if (type is ArrayType) {
                                // return array length if appropriate
                                var array_type = (ArrayType) type;
-
+                               var length_ctype = get_ccode_array_length_type (array_type);
                                for (int dim = 1; dim <= array_type.rank; dim++) {
                                        ccall.add_argument (get_array_length_cvalue (value, dim));
-                                       cfunc.add_parameter (new CCodeParameter (get_array_length_cname 
("value", dim), "gint"));
+                                       cfunc.add_parameter (new CCodeParameter (get_array_length_cname 
("value", dim), length_ctype));
                                }
                        }
 
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 478302969..8251e4fa9 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -61,9 +61,9 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                        if (get_ccode_array_length (param) && param.variable_type is ArrayType) {
                                var array_type = (ArrayType) param.variable_type;
 
-                               var length_ctype = "int";
+                               var length_ctype = get_ccode_array_length_type (array_type);
                                if (param.direction != ParameterDirection.IN) {
-                                       length_ctype = "int*";
+                                       length_ctype += "*";
                                }
 
                                for (int dim = 1; dim <= array_type.rank; dim++) {
@@ -88,11 +88,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                if (get_ccode_array_length (d) && d.return_type is ArrayType) {
                        // return array length if appropriate
                        var array_type = (ArrayType) d.return_type;
-                       var array_length_type = get_ccode_array_length_type (d) != null ? 
get_ccode_array_length_type (d) : "int";
-                       array_length_type += "*";
+                       var length_ctype = get_ccode_array_length_type (array_type) + "*";
 
                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                               var cparam = new CCodeParameter (get_array_length_cname ("result", dim), 
array_length_type);
+                               var cparam = new CCodeParameter (get_array_length_cname ("result", dim), 
length_ctype);
                                cfundecl.add_parameter (cparam);
                        }
                } else if (d.return_type is DelegateType) {
@@ -239,11 +238,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                if (get_ccode_array_length (d) && d.return_type is ArrayType) {
                        // return array length if appropriate
                        var array_type = (ArrayType) d.return_type;
-                       var array_length_type = get_ccode_array_length_type (d) != null ? 
get_ccode_array_length_type (d) : "int";
-                       array_length_type += "*";
+                       var length_ctype = get_ccode_array_length_type (array_type) + "*";
 
                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                               var cparam = new CCodeParameter (get_array_length_cname ("result", dim), 
array_length_type);
+                               var cparam = new CCodeParameter (get_array_length_cname ("result", dim), 
length_ctype);
                                cparam_map.set (get_param_pos (get_ccode_array_length_pos (d) + 0.01 * dim), 
cparam);
                        }
                } else if (d.return_type is DelegateType) {
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 400448643..ca8b6b6df 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -727,10 +727,10 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                                        result.append_array_length_cvalue (new CCodeConstant ("-1"));
                                }
                                result.lvalue = false;
-                       } else if (get_ccode_array_length_type (variable) != null) {
+                       } else if (get_ccode_array_length_type (variable.variable_type) != 
get_ccode_array_length_type (array_type)) {
                                for (int dim = 1; dim <= array_type.rank; dim++) {
                                        // cast if variable does not use int for array length
-                                       result.array_length_cvalues[dim - 1] = new CCodeCastExpression 
(result.array_length_cvalues[dim - 1], "gint");
+                                       result.array_length_cvalues[dim - 1] = new CCodeCastExpression 
(result.array_length_cvalues[dim - 1], get_ccode_array_length_type (array_type));
                                }
                                result.lvalue = false;
                        }
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 1bca80aee..8b92c78c2 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -366,17 +366,12 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                        if (unary == null || unary.operator != UnaryOperator.OUT) {
                                                if (get_ccode_array_length (param) && param.variable_type is 
ArrayType && !((ArrayType) param.variable_type).fixed_length) {
                                                        var array_type = (ArrayType) param.variable_type;
+                                                       var length_ctype = get_ccode_array_length_type 
(array_type);
+                                                       if (unary != null && unary.operator == 
UnaryOperator.REF) {
+                                                               length_ctype = "%s*".printf (length_ctype);
+                                                       }
                                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                               CCodeExpression? array_length_expr = null;
-                                                               if (get_ccode_array_length_type (param) != 
null) {
-                                                                       string length_ctype = 
get_ccode_array_length_type (param);
-                                                                       if (unary != null && unary.operator 
== UnaryOperator.REF) {
-                                                                               length_ctype = "%s*".printf 
(length_ctype);
-                                                                       }
-                                                                       array_length_expr = new 
CCodeCastExpression (get_array_length_cexpression (arg, dim), length_ctype);
-                                                               } else {
-                                                                       array_length_expr = 
get_array_length_cexpression (arg, dim);
-                                                               }
+                                                               var array_length_expr = new 
CCodeCastExpression (get_array_length_cexpression (arg, dim), length_ctype);
                                                                carg_map.set (get_param_pos 
(get_ccode_array_length_pos (param) + 0.01 * dim), array_length_expr);
                                                        }
                                                } else if (param.variable_type is DelegateType) {
@@ -432,12 +427,9 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
                                                if (get_ccode_array_length (param) && param.variable_type is 
ArrayType && !((ArrayType) param.variable_type).fixed_length) {
                                                        var array_type = (ArrayType) param.variable_type;
-                                                       var array_length_type = int_type;
-                                                       if (get_ccode_array_length_type (param) != null) {
-                                                               array_length_type = new CType 
(get_ccode_array_length_type (param));
-                                                       }
+                                                       var length_ctype = get_ccode_array_length_type 
(array_type);
                                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                               var temp_array_length = get_temp_variable 
(array_length_type);
+                                                               var temp_array_length = get_temp_variable 
(new CType (length_ctype));
                                                                emit_temp_var (temp_array_length);
                                                                append_array_length (arg, 
get_variable_cexpression (temp_array_length.name));
                                                                carg_map.set (get_param_pos 
(get_ccode_array_length_pos (param) + 0.01 * dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, 
get_array_lengths (arg).get (dim - 1)));
@@ -512,13 +504,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
                                        append_array_length (expr, len_call);
                                } else if (get_ccode_array_length (m)) {
-                                       LocalVariable temp_var;
-
-                                       if (get_ccode_array_length_type (m) == null) {
-                                               temp_var = get_temp_variable (int_type, true, null, true);
-                                       } else {
-                                               temp_var = get_temp_variable (new CType 
(get_ccode_array_length_type (m)), true, null, true);
-                                       }
+                                       var length_ctype = get_ccode_array_length_type (array_type);
+                                       var temp_var = get_temp_variable (new CType (length_ctype), true, 
null, true);
                                        var temp_ref = get_variable_cexpression (temp_var.name);
 
                                        emit_temp_var (temp_var);
@@ -581,7 +568,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
                                        append_array_length (expr, len_call);
                                } else if (get_ccode_array_length (deleg)) {
-                                       var temp_var = get_temp_variable (int_type, true, null, true);
+                                       var temp_var = get_temp_variable (new CType 
(get_ccode_array_length_type (array_type)), true, null, true);
                                        var temp_ref = get_variable_cexpression (temp_var.name);
 
                                        emit_temp_var (temp_var);
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index cdedbee67..b8740002f 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -80,11 +80,10 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                } else if (get_ccode_array_length (m) && m.return_type is ArrayType) {
                        // return array length if appropriate
                        var array_type = (ArrayType) m.return_type;
-                       var array_length_type = get_ccode_array_length_type (m) != null ? 
get_ccode_array_length_type (m) : "int";
-                       array_length_type += "*";
+                       var length_ctype = get_ccode_array_length_type (array_type) + "*";
 
                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                               var cparam = new CCodeParameter (get_array_length_cname ("result", dim), 
array_length_type);
+                               var cparam = new CCodeParameter (get_array_length_cname ("result", dim), 
length_ctype);
                                cparam_map.set (get_param_pos (get_ccode_array_length_pos (m) + 0.01 * dim), 
cparam);
                                if (carg_map != null) {
                                        carg_map.set (get_param_pos (get_ccode_array_length_pos (m) + 0.01 * 
dim), get_variable_cexpression (cparam.name));
@@ -580,9 +579,10 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                                        var array_type = (ArrayType) param.variable_type;
 
                                                        if (!array_type.fixed_length) {
+                                                               var length_ctype = 
get_ccode_array_length_type (array_type);
                                                                for (int dim = 1; dim <= array_type.rank; 
dim++) {
                                                                        vardecl = new 
CCodeVariableDeclarator.zero (get_array_length_cname (get_variable_cname ("_vala_%s".printf (param.name)), 
dim), new CCodeConstant ("0"));
-                                                                       ccode.add_declaration ("int", 
vardecl);
+                                                                       ccode.add_declaration (length_ctype, 
vardecl);
                                                                }
                                                        }
                                                } else if (param.variable_type is DelegateType) {
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index d9237e656..4460cba11 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -79,7 +79,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                                        var array_type = (ArrayType) f.variable_type;
 
                                        if (!array_type.fixed_length) {
-                                               var len_type = int_type.copy ();
+                                               var length_ctype = get_ccode_array_length_type (array_type);
 
                                                for (int dim = 1; dim <= array_type.rank; dim++) {
                                                        string length_cname;
@@ -88,11 +88,11 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                                                        } else {
                                                                length_cname = get_array_length_cname 
(get_ccode_name (f), dim);
                                                        }
-                                                       instance_struct.add_field (get_ccode_name (len_type), 
length_cname);
+                                                       instance_struct.add_field (length_ctype, 
length_cname);
                                                }
 
                                                if (array_type.rank == 1 && f.is_internal_symbol ()) {
-                                                       instance_struct.add_field (get_ccode_name (len_type), 
get_array_size_cname (get_ccode_name (f)));
+                                                       instance_struct.add_field (length_ctype, 
get_array_size_cname (get_ccode_name (f)));
                                                }
                                        }
                                } else if (f.variable_type is DelegateType && get_ccode_delegate_target (f)) {
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 89da47c40..c63d9fc65 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -58,8 +58,9 @@ public class Vala.GAsyncModule : GtkModule {
                        if (param.variable_type is ArrayType) {
                                var array_type = (ArrayType) param.variable_type;
                                if (get_ccode_array_length (param)) {
+                                       var length_ctype = get_ccode_array_length_type (array_type);
                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                               data.add_field ("gint", get_parameter_array_length_cname 
(param, dim));
+                                               data.add_field (length_ctype, 
get_parameter_array_length_cname (param, dim));
                                        }
                                }
                        } else if (param.variable_type is DelegateType) {
@@ -84,8 +85,9 @@ public class Vala.GAsyncModule : GtkModule {
                        if (m.return_type is ArrayType) {
                                var array_type = (ArrayType) m.return_type;
                                if (get_ccode_array_length (m)) {
+                                       var length_ctype = get_ccode_array_length_type (array_type);
                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                               data.add_field ("gint", get_array_length_cname ("result", 
dim));
+                                               data.add_field (length_ctype, get_array_length_cname 
("result", dim));
                                        }
                                }
                        } else if (m.return_type is DelegateType) {
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index 439d181e9..a924ee17c 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -193,8 +193,12 @@ public class Vala.GSignalModule : GObjectModule {
                        callback_decl.add_parameter (new CCodeParameter ("arg_%d".printf (n_params), 
get_value_type_name_from_parameter (p)));
                        n_params++;
                        if (p.variable_type.is_array ()) {
-                               for (var j = 0; j < ((ArrayType) p.variable_type).rank; j++) {
-                                       callback_decl.add_parameter (new CCodeParameter ("arg_%d".printf 
(n_params), "gint"));
+                               var array_type = (ArrayType) p.variable_type;
+                               //FIXME Only int length-type
+                               //var length_ctype = get_ccode_array_length_type (array_type);
+                               var length_ctype = get_ccode_name (int_type);
+                               for (var j = 0; j < array_type.rank; j++) {
+                                       callback_decl.add_parameter (new CCodeParameter ("arg_%d".printf 
(n_params), length_ctype));
                                        n_params++;
                                }
                        }
@@ -266,7 +270,9 @@ public class Vala.GSignalModule : GObjectModule {
                        fc.add_argument (inner_fc);
                        i++;
                        if (is_array) {
-                               for (var j = 0; j < ((ArrayType) p.variable_type).rank; j++) {
+                               var array_type = (ArrayType) p.variable_type;
+                               for (var j = 0; j < array_type.rank; j++) {
+                                       //FIXME Only int length-type
                                        inner_fc = new CCodeFunctionCall (new CCodeIdentifier 
("g_value_get_int"));
                                        inner_fc.add_argument (new CCodeBinaryExpression 
(CCodeBinaryOperator.PLUS, new CCodeIdentifier ("param_values"), new CCodeIdentifier (i.to_string ())));
                                        fc.add_argument (inner_fc);
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 4b39cbbee..19eb85971 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -349,8 +349,9 @@ public class Vala.GTypeModule : GErrorModule {
 
                        var array_type = prop.property_type as ArrayType;
                        if (array_type != null) {
+                               var length_ctype = get_ccode_array_length_type (array_type) + "*";
                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                       vdeclarator.add_parameter (new CCodeParameter (get_array_length_cname 
("result", dim), "int*"));
+                                       vdeclarator.add_parameter (new CCodeParameter (get_array_length_cname 
("result", dim), length_ctype));
                                }
                        } else if ((prop.property_type is DelegateType) && ((DelegateType) 
prop.property_type).delegate_symbol.has_target) {
                                vdeclarator.add_parameter (new CCodeParameter (get_delegate_target_cname 
("result"), "gpointer*"));
@@ -379,8 +380,9 @@ public class Vala.GTypeModule : GErrorModule {
 
                        var array_type = prop.property_type as ArrayType;
                        if (array_type != null) {
+                               var length_ctype = get_ccode_array_length_type (array_type);
                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                       vdeclarator.add_parameter (new CCodeParameter (get_array_length_cname 
("value", dim), "int"));
+                                       vdeclarator.add_parameter (new CCodeParameter (get_array_length_cname 
("value", dim), length_ctype));
                                }
                        } else if ((prop.property_type is DelegateType) && ((DelegateType) 
prop.property_type).delegate_symbol.has_target) {
                                vdeclarator.add_parameter (new CCodeParameter (get_delegate_target_cname 
("value"), "gpointer"));
@@ -413,7 +415,7 @@ public class Vala.GTypeModule : GErrorModule {
                                var array_type = (ArrayType) f.variable_type;
 
                                if (!array_type.fixed_length) {
-                                       var len_type = int_type.copy ();
+                                       var length_ctype = get_ccode_array_length_type (array_type);
 
                                        for (int dim = 1; dim <= array_type.rank; dim++) {
                                                string length_cname;
@@ -422,11 +424,11 @@ public class Vala.GTypeModule : GErrorModule {
                                                } else {
                                                        length_cname = get_array_length_cname (get_ccode_name 
(f), dim);
                                                }
-                                               instance_struct.add_field (get_ccode_name (len_type), 
length_cname);
+                                               instance_struct.add_field (length_ctype, length_cname);
                                        }
 
                                        if (array_type.rank == 1 && f.is_internal_symbol ()) {
-                                               instance_struct.add_field (get_ccode_name (len_type), 
get_array_size_cname (get_ccode_name (f)));
+                                               instance_struct.add_field (length_ctype, get_array_size_cname 
(get_ccode_name (f)));
                                        }
                                }
                        } else if (f.variable_type is DelegateType && get_ccode_delegate_target (f)) {
@@ -513,9 +515,10 @@ public class Vala.GTypeModule : GErrorModule {
                                        if (f.variable_type is ArrayType && get_ccode_array_length (f)) {
                                                // create fields to store array dimensions
                                                var array_type = (ArrayType) f.variable_type;
-                                               var len_type = int_type.copy ();
 
                                                if (!array_type.fixed_length) {
+                                                       var length_ctype = get_ccode_array_length_type 
(array_type);
+
                                                        for (int dim = 1; dim <= array_type.rank; dim++) {
                                                                string length_cname;
                                                                if (get_ccode_array_length_name (f) != null) {
@@ -523,11 +526,11 @@ public class Vala.GTypeModule : GErrorModule {
                                                                } else {
                                                                        length_cname = get_array_length_cname 
(get_ccode_name (f), dim);
                                                                }
-                                                               instance_priv_struct.add_field 
(get_ccode_name (len_type), length_cname);
+                                                               instance_priv_struct.add_field (length_ctype, 
length_cname);
                                                        }
 
                                                        if (array_type.rank == 1 && f.is_internal_symbol ()) {
-                                                               instance_priv_struct.add_field 
(get_ccode_name (len_type), get_array_size_cname (get_ccode_name (f)));
+                                                               instance_priv_struct.add_field (length_ctype, 
get_array_size_cname (get_ccode_name (f)));
                                                        }
                                                }
                                        } else if (f.variable_type is DelegateType && 
get_ccode_delegate_target (f)) {
@@ -2165,8 +2168,9 @@ public class Vala.GTypeModule : GErrorModule {
 
                                        var array_type = prop.property_type as ArrayType;
                                        if (array_type != null) {
+                                               var length_ctype = get_ccode_array_length_type (array_type) + 
"*";
                                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                       vdeclarator.add_parameter (new CCodeParameter 
(get_array_length_cname ("result", dim), "int*"));
+                                                       vdeclarator.add_parameter (new CCodeParameter 
(get_array_length_cname ("result", dim), length_ctype));
                                                }
                                        }
 
@@ -2187,8 +2191,9 @@ public class Vala.GTypeModule : GErrorModule {
 
                                        var array_type = prop.property_type as ArrayType;
                                        if (array_type != null) {
+                                               var length_ctype = get_ccode_array_length_type (array_type);
                                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                       vdeclarator.add_parameter (new CCodeParameter 
(get_array_length_cname ("value", dim), "int"));
+                                                       vdeclarator.add_parameter (new CCodeParameter 
(get_array_length_cname ("value", dim), length_ctype));
                                                }
                                        }
 
diff --git a/codegen/valagvariantmodule.vala b/codegen/valagvariantmodule.vala
index b6d36b6eb..061b8f5ab 100644
--- a/codegen/valagvariantmodule.vala
+++ b/codegen/valagvariantmodule.vala
@@ -280,9 +280,10 @@ public class Vala.GVariantModule : GAsyncModule {
                // add one extra element for NULL-termination
                new_call.add_argument (new CCodeConstant ("5"));
 
+               var length_ctype = get_ccode_array_length_type (array_type);
                ccode.add_declaration (get_ccode_name (array_type), new CCodeVariableDeclarator (temp_name, 
new_call));
-               ccode.add_declaration ("int", new CCodeVariableDeclarator (temp_name + "_length", new 
CCodeConstant ("0")));
-               ccode.add_declaration ("int", new CCodeVariableDeclarator (temp_name + "_size", new 
CCodeConstant ("4")));
+               ccode.add_declaration (length_ctype, new CCodeVariableDeclarator (temp_name + "_length", new 
CCodeConstant ("0")));
+               ccode.add_declaration (length_ctype, new CCodeVariableDeclarator (temp_name + "_size", new 
CCodeConstant ("4")));
 
                deserialize_array_dim (array_type, 1, temp_name, variant_expr, expr);
 
@@ -300,7 +301,7 @@ public class Vala.GVariantModule : GAsyncModule {
                string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
                string element_name = "_tmp%d_".printf (next_temp_var_id++);
 
-               ccode.add_declaration ("int", new CCodeVariableDeclarator ("%s_length%d".printf (temp_name, 
dim), new CCodeConstant ("0")));
+               ccode.add_declaration (get_ccode_array_length_type (array_type), new CCodeVariableDeclarator 
("%s_length%d".printf (temp_name, dim), new CCodeConstant ("0")));
                ccode.add_declaration ("GVariantIter", new CCodeVariableDeclarator (subiter_name));
                ccode.add_declaration ("GVariant*", new CCodeVariableDeclarator (element_name));
 
@@ -627,7 +628,7 @@ public class Vala.GVariantModule : GAsyncModule {
                string index_name = "_tmp%d_".printf (next_temp_var_id++);
 
                ccode.add_declaration ("GVariantBuilder", new CCodeVariableDeclarator (builder_name));
-               ccode.add_declaration ("int", new CCodeVariableDeclarator (index_name));
+               ccode.add_declaration (get_ccode_array_length_type (array_type), new CCodeVariableDeclarator 
(index_name));
 
                var gvariant_type = new CCodeFunctionCall (new CCodeIdentifier ("G_VARIANT_TYPE"));
                ArrayType array_type_copy = (ArrayType) array_type.copy ();


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