]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Support array_length_type for method parameters
authorEvan Nemerson <evan@coeus-group.com>
Sat, 3 Apr 2010 05:33:11 +0000 (22:33 -0700)
committerJürg Billeter <j@bitron.ch>
Tue, 27 Apr 2010 09:01:11 +0000 (11:01 +0200)
Fixes bug 529866.

codegen/valaccodemethodcallmodule.vala
vala/valaformalparameter.vala

index 752a1363dde1b4a1a8ef2ea28757bfef348537b0..5defe46ee8d4ce8c94c16ebbffdee7f89c4210b7 100644 (file)
@@ -350,7 +350,35 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                        if (!param.no_array_length && param.parameter_type is ArrayType) {
                                                var array_type = (ArrayType) param.parameter_type;
                                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                       carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), head.get_array_length_cexpression (arg, dim));
+                                                       CCodeExpression? array_length_expr = null;
+                                                       if (param.array_length_type != null) {
+                                                               if (param.direction == ParameterDirection.OUT) {
+                                                                       var temp_array_length = get_temp_variable (new CType (param.array_length_type));
+                                                                       temp_vars.insert (0, temp_array_length);
+                                                                       array_length_expr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (temp_array_length.name));
+
+                                                                       var comma = new CCodeCommaExpression ();
+                                                                       LocalVariable? temp_result = null;
+                                                                       if (!(m.return_type is VoidType)) {
+                                                                               temp_result = get_temp_variable (m.return_type);
+                                                                               temp_vars.insert (0, temp_result);
+                                                                               ccall_expr = new CCodeAssignment (get_variable_cexpression (temp_result.name), ccall_expr);
+                                                                       }
+
+                                                                       comma.append_expression (ccall_expr);
+                                                                       comma.append_expression (new CCodeAssignment (get_variable_cexpression (head.get_array_length_cname (((UnaryExpression) arg).inner.to_string (), dim)), new CCodeCastExpression (get_variable_cexpression (temp_array_length.name), int_type.get_cname ())));
+
+                                                                       if (temp_result != null) {
+                                                                               comma.append_expression (get_variable_cexpression (temp_result.name));
+                                                                       }
+                                                                       ccall_expr = comma;
+                                                               } else {
+                                                                       array_length_expr = new CCodeCastExpression (head.get_array_length_cexpression (arg, dim), param.array_length_type);
+                                                               }
+                                                       } else {
+                                                               array_length_expr = head.get_array_length_cexpression (arg, dim);
+                                                       }
+                                                       carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), array_length_expr);
                                                }
                                                multiple_cargs = true;
                                        } else if (param.parameter_type is DelegateType) {
index 5c7ca211f4d491479531c3d3893b2ac69342530b..6212b6c8363dda770390f2a9fedc5b17eace346a 100644 (file)
@@ -78,6 +78,11 @@ public class Vala.FormalParameter : Symbol {
         */
        public bool array_null_terminated { get; set; }
 
+       /**
+        * Specifies a custom type for the array length.
+        */
+       public string? array_length_type { get; set; default = null; }
+
        /**
         * Specifies the position of the parameter in the C function.
         */
@@ -169,6 +174,9 @@ public class Vala.FormalParameter : Symbol {
                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");
                }