From: Evan Nemerson Date: Sat, 3 Apr 2010 05:33:11 +0000 (-0700) Subject: Support array_length_type for method parameters X-Git-Tag: 0.9.1~122 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7aba22e37c306d3e53a3937827903796e808dd58;p=thirdparty%2Fvala.git Support array_length_type for method parameters Fixes bug 529866. --- diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala index 752a1363d..5defe46ee 100644 --- a/codegen/valaccodemethodcallmodule.vala +++ b/codegen/valaccodemethodcallmodule.vala @@ -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) { diff --git a/vala/valaformalparameter.vala b/vala/valaformalparameter.vala index 5c7ca211f..6212b6c83 100644 --- a/vala/valaformalparameter.vala +++ b/vala/valaformalparameter.vala @@ -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"); }