[vala] girparser: Better support for arrays in return type.



commit 07103b895c45353a1a765737ab0089180c6ce7c3
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Nov 20 10:58:06 2010 +0100

    girparser: Better support for arrays in return type.

 vala/valagirparser.vala |   61 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 49 insertions(+), 12 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 30b1193..65b003e 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1233,6 +1233,33 @@ public class Vala.GirParser : CodeVisitor {
 		return name;
 	}
 
+	void set_array_ccode (Symbol sym, ParameterInfo info) {
+		if (sym is Method) {
+			var m = (Method) sym;
+			m.carray_length_parameter_position = info.vala_idx;
+		} else if (sym is Delegate) {
+			var d = (Delegate) sym;
+			d.carray_length_parameter_position = info.vala_idx;
+		} else {
+			var param = (Parameter) sym;
+			param.carray_length_parameter_position = info.vala_idx;
+			param.set_array_length_cname (info.param.name);
+		}
+		if (info.param.variable_type.to_qualified_string () != "int") {
+			var unresolved_type = (UnresolvedType) info.param.variable_type;
+			var resolved_struct = resolve_symbol (glib_ns.scope, unresolved_type.unresolved_symbol) as Struct;
+			if (resolved_struct != null) {
+				if (sym is Method) {
+					var m = (Method) sym;
+					m.array_length_type = resolved_struct.get_cname ();
+				} else {
+					var param = (Parameter) sym;
+					param.array_length_type = resolved_struct.get_cname ();
+				}
+			}
+		}
+	}
+
 	void parse_repository () {
 		start_element ("repository");
 		if (reader.get_attribute ("version") != GIR_VERSION) {
@@ -2354,6 +2381,13 @@ public class Vala.GirParser : CodeVisitor {
 			}
 			end_element ("parameters");
 		}
+		var array_length_idx = -1;
+		if (return_type is ArrayType && metadata.has_argument (ArgumentType.ARRAY_LENGTH_IDX)) {
+			array_length_idx = metadata.get_integer (ArgumentType.ARRAY_LENGTH_IDX);
+			parameters[array_length_idx].keep = false;
+			array_length_parameters.add (array_length_idx);
+		}
+
 		int i = 0, j=1;
 
 		int last = -1;
@@ -2406,18 +2440,8 @@ public class Vala.GirParser : CodeVisitor {
 						Report.error (get_current_src (), "invalid array_length index");
 						continue;
 					}
-					info.param.carray_length_parameter_position = parameters[info.array_length_idx].vala_idx;
-					var length_param = parameters[info.array_length_idx].param;
-					info.param.set_array_length_cname (parameters[info.array_length_idx].param.name);
-					if (length_param.variable_type.to_qualified_string () != "int") {
-						var unresolved_type = (UnresolvedType) length_param.variable_type;
-						var resolved_struct = resolve_symbol (glib_ns.scope, unresolved_type.unresolved_symbol) as Struct;
-						if (resolved_struct != null) {
-							info.param.array_length_type = resolved_struct.get_cname ();
-						}
-					}
-				}
-				if (info.param.variable_type is ArrayType && info.array_length_idx == -1) {
+					set_array_ccode (info.param, parameters[info.array_length_idx]);
+				} else if (info.param.variable_type is ArrayType) {
 					info.param.no_array_length = true;
 				}
 
@@ -2437,6 +2461,19 @@ public class Vala.GirParser : CodeVisitor {
 				}
 			}
 		}
+		if (array_length_idx != -1) {
+			if (array_length_idx >= parameters.size) {
+				Report.error (get_current_src (), "invalid array_length index");
+			} else {
+				set_array_ccode (s, parameters[array_length_idx]);
+			}
+		} else if (return_type is ArrayType) {
+			if (s is Method) {
+				((Method) s).no_array_length = true;
+			} else {
+				((Delegate) s).no_array_length = true;
+			}
+		}
 
 		if (throws_string == "1") {
 			s.add_error_type (new ErrorType (null, null));



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