[vala/switch-to-gir: 18/47] girparser: Better support for arrays in return type.
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/switch-to-gir: 18/47] girparser: Better support for arrays in return type.
- Date: Thu, 6 Jan 2011 11:51:04 +0000 (UTC)
commit 3b0e782c4e6626c99266218238f6bfeda5d0be52
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 4ae9462..c8b8c6a 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) {
@@ -2353,6 +2380,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;
@@ -2405,18 +2439,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;
}
@@ -2436,6 +2460,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]