[vala] Support array_length_type for delegate return values



commit b31963e1db2f461858661854c44a21752226054b
Author: Michal Hruby <michal mhr gmail com>
Date:   Wed Mar 9 20:13:27 2011 +0100

    Support array_length_type for delegate return values
    
    Partially fixes bug 644420.

 codegen/valaccodedelegatemodule.vala |    8 ++++++--
 codegen/valaccodemethodmodule.vala   |    4 +++-
 vala/valacodewriter.vala             |    2 ++
 vala/valadelegate.vala               |    8 ++++++++
 vala/valalambdaexpression.vala       |    3 +++
 vala/valamethod.vala                 |    2 +-
 6 files changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index cef9219..c225ce9 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -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) {
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 0b8c81a..96355a7 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -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));
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index 4a5aaf1..6b83956 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -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 (")]");
diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala
index ebe5dae..ddaba92 100644
--- a/vala/valadelegate.vala
+++ b/vala/valadelegate.vala
@@ -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");
 		}
diff --git a/vala/valalambdaexpression.vala b/vala/valalambdaexpression.vala
index 7b9e03f..c09aea8 100644
--- a/vala/valalambdaexpression.vala
+++ b/vala/valalambdaexpression.vala
@@ -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);
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 82fca11..d974db1 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -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; }
 



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