]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Support array_length_type for delegate return values
authorMichal Hruby <michal.mhr@gmail.com>
Wed, 9 Mar 2011 19:13:27 +0000 (20:13 +0100)
committerLuca Bruno <lucabru@src.gnome.org>
Mon, 4 Apr 2011 14:34:26 +0000 (16:34 +0200)
Partially fixes bug 644420.

codegen/valaccodedelegatemodule.vala
codegen/valaccodemethodmodule.vala
vala/valacodewriter.vala
vala/valadelegate.vala
vala/valalambdaexpression.vala
vala/valamethod.vala

index cef9219288cec6d14f2f4e3aee44123bd57e3df2..c225ce95e360e03f8113ff9f7478103023b39d0b 100644 (file)
@@ -83,9 +83,11 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                if (!d.no_array_length && d.return_type is ArrayType) {
                        // return array length if appropriate
                        var array_type = (ArrayType) d.return_type;
+                       var array_length_type = d.array_length_type != null ? d.array_length_type : "int";
+                       array_length_type += "*";
 
                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                               var cparam = new CCodeParameter (get_array_length_cname ("result", dim), "int*");
+                               var cparam = new CCodeParameter (get_array_length_cname ("result", dim), array_length_type);
                                cfundecl.add_parameter (cparam);
                        }
                } else if (d.return_type is DelegateType) {
@@ -230,9 +232,11 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                if (!d.no_array_length && d.return_type is ArrayType) {
                        // return array length if appropriate
                        var array_type = (ArrayType) d.return_type;
+                       var array_length_type = d.array_length_type != null ? d.array_length_type : "int";
+                       array_length_type += "*";
 
                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                               var cparam = new CCodeParameter (get_array_length_cname ("result", dim), "int*");
+                               var cparam = new CCodeParameter (get_array_length_cname ("result", dim), array_length_type);
                                cparam_map.set (get_param_pos (d.carray_length_parameter_position + 0.01 * dim), cparam);
                        }
                } else if (d.return_type is DelegateType) {
index 0b8c81af8a0969c4b1e4a3cff57f93336c6ca37b..96355a72452318ced2a3eb5a5dd4bc901be8e948 100644 (file)
@@ -88,9 +88,11 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                } else if (!m.no_array_length && m.return_type is ArrayType) {
                        // return array length if appropriate
                        var array_type = (ArrayType) m.return_type;
+                       var array_length_type = m.array_length_type != null ? m.array_length_type : "int";
+                       array_length_type += "*";
 
                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                               var cparam = new CCodeParameter (get_array_length_cname ("result", dim), "int*");
+                               var cparam = new CCodeParameter (get_array_length_cname ("result", dim), array_length_type);
                                cparam_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), cparam);
                                if (carg_map != null) {
                                        carg_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), get_variable_cexpression (cparam.name));
index 4a5aaf13ba98a4ea715cb5c73dede40ad3b9140c..6b83956f5297a6eee6bc1f943e08eee3670e6bed 100644 (file)
@@ -965,6 +965,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        write_string (", has_target = false");
                } else if (!float_equal (cb.cinstance_parameter_position, -2)) {
                        write_string (", instance_pos = %g".printf (cb.cinstance_parameter_position));
+               } else if (cb.array_length_type != null) {
+                       write_string (", array_length_type = \"%s\"".printf (cb.array_length_type));
                }
 
                write_string (")]");
index ebe5daeb30a35780382078e403ac978254e3db43..ddaba923861865fea707fc9f1ae3089ff4d22070 100644 (file)
@@ -74,6 +74,11 @@ public class Vala.Delegate : TypeSymbol {
         */
        public bool array_null_terminated { get; set; }
 
+       /**
+        * Specifies a custom type for the array length parameter.
+        */
+       public string? array_length_type { get; set; default = null; }
+
        private List<TypeParameter> type_parameters = new ArrayList<TypeParameter> ();
 
        private List<Parameter> parameters = new ArrayList<Parameter> ();
@@ -287,6 +292,9 @@ public class Vala.Delegate : TypeSymbol {
                if (a.has_argument ("array_length")) {
                        no_array_length = !a.get_bool ("array_length");
                }
+               if (a.has_argument ("array_length_type")) {
+                       array_length_type = a.get_string ("array_length_type");
+               }
                if (a.has_argument ("array_null_terminated")) {
                        array_null_terminated = a.get_bool ("array_null_terminated");
                }
index 7b9e03f1db17076c448d91537ba2274be2eceb52..c09aea82ba8fcee625dec4f7851760d659e9f18b 100644 (file)
@@ -135,6 +135,9 @@ public class Vala.LambdaExpression : Expression {
                var cb = (Delegate) ((DelegateType) target_type).delegate_symbol;
                var return_type = cb.return_type.get_actual_type (target_type, null, this);
                method = new Method (get_lambda_name (context), return_type, source_reference);
+               method.no_array_length = cb.no_array_length;
+               method.array_null_terminated = cb.array_null_terminated;
+               method.array_length_type = cb.array_length_type;
                // track usage for flow analyzer
                method.used = true;
                method.check_deprecated (source_reference);
index 82fca11b4be73587ddd0c71285466b5cac17ccc3..d974db1c0892a3eb9dd114e218c83489dcd76f04 100644 (file)
@@ -176,7 +176,7 @@ public class Vala.Method : Subroutine {
        public bool array_null_terminated { get; set; }
 
        /**
-        * Specified a custom type for the array length parameter.
+        * Specifies a custom type for the array length parameter.
         */
        public string? array_length_type { get; set; default = null; }