From: Rico Tzschichholz Date: Tue, 4 Jan 2022 15:20:45 +0000 (+0100) Subject: girparser: Set length_type for arrays instead of CCode.array_length_type X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b891e21d9e9bfe08b72163a3ec1a81cb3e8b39f0;p=thirdparty%2Fvala.git girparser: Set length_type for arrays instead of CCode.array_length_type See https://gitlab.gnome.org/GNOME/vala/issues/607 --- diff --git a/tests/gir/bug651773.test b/tests/gir/bug651773.test index 7f499de5b..ff97bc290 100644 --- a/tests/gir/bug651773.test +++ b/tests/gir/bug651773.test @@ -20,5 +20,5 @@ Input: Output: -[CCode (array_length_pos = 0.1, array_length_type = "gsize", cheader_filename = "test.h")] -public static unowned uint8[] get_array (); +[CCode (array_length_pos = 0.1, cheader_filename = "test.h")] +public static unowned uint8[:size_t] get_array (); diff --git a/tests/gir/bug788775.test b/tests/gir/bug788775.test index 80ae7cd21..08a6a90e5 100644 --- a/tests/gir/bug788775.test +++ b/tests/gir/bug788775.test @@ -25,5 +25,5 @@ Input: Output: -[CCode (array_length = true, array_length_pos = 1.1, array_length_type = "gsize", array_null_terminated = true, cheader_filename = "test.h")] -public static string[] get_string_list (string key); +[CCode (array_length = true, array_length_pos = 1.1, array_null_terminated = true, cheader_filename = "test.h")] +public static string[:size_t] get_string_list (string key); diff --git a/tests/gir/delegate-array-length-type.test b/tests/gir/delegate-array-length-type.test index 127ac8a76..798955dd3 100644 --- a/tests/gir/delegate-array-length-type.test +++ b/tests/gir/delegate-array-length-type.test @@ -24,5 +24,5 @@ Input: Output: -[CCode (array_length_pos = 0.1, array_length_type = "gsize", cheader_filename = "test.h", instance_pos = 0.9)] -public delegate string[] Foo (); +[CCode (array_length_pos = 0.1, cheader_filename = "test.h", instance_pos = 0.9)] +public delegate string[:size_t] Foo (); diff --git a/tests/gir/method-array-length-type.test b/tests/gir/method-array-length-type.test index b7ebccfc5..b13df3967 100644 --- a/tests/gir/method-array-length-type.test +++ b/tests/gir/method-array-length-type.test @@ -17,5 +17,5 @@ Input: Output: -[CCode (array_length_pos = 0.1, array_length_type = "gsize", cheader_filename = "test.h")] -public static string[] function (); +[CCode (array_length_pos = 0.1, cheader_filename = "test.h")] +public static string[:size_t] function (); diff --git a/tests/gir/parameter-array-length-type.test b/tests/gir/parameter-array-length-type.test index 3bbbe9ec6..9c2b22921 100644 --- a/tests/gir/parameter-array-length-type.test +++ b/tests/gir/parameter-array-length-type.test @@ -21,4 +21,4 @@ Input: Output: [CCode (cheader_filename = "test.h")] -public static void function ([CCode (array_length_cname = "foo_length", array_length_pos = 1.1, array_length_type = "gsize")] string[] foo); +public static void function ([CCode (array_length_cname = "foo_length", array_length_pos = 1.1)] string[:size_t] foo); diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index 3babf7424..b68d9d993 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -1195,13 +1195,7 @@ public class Vala.GirParser : CodeVisitor { var length_field = (Field) array_length.symbol; // array has length field.set_attribute_string ("CCode", "array_length_cname", length_field.name); - var length_type = length_field.variable_type.to_qualified_string (); - if (length_type != "int") { - var st = parser.root.lookup (length_type); - if (st != null) { - field.set_attribute_string ("CCode", "array_length_type", st.get_cname ()); - } - } + ((ArrayType) field.variable_type).length_type = length_field.variable_type.copy (); field.remove_attribute_argument ("CCode", "array_length"); field.remove_attribute_argument ("CCode", "array_null_terminated"); } @@ -1990,17 +1984,13 @@ public class Vala.GirParser : CodeVisitor { void set_array_ccode (Symbol sym, ParameterInfo info) { sym.set_attribute_double ("CCode", "array_length_pos", info.vala_idx); + var length_type = info.param.variable_type.copy (); + length_type.nullable = false; if (sym is Parameter) { sym.set_attribute_string ("CCode", "array_length_cname", info.param.name); - } - var type_name = info.param.variable_type.to_qualified_string (); - if (type_name != "int") { - var st = root.lookup (type_name); - if (st != null) { - if (sym is Callable || sym is Parameter) { - sym.set_attribute_string ("CCode", "array_length_type", st.get_cname ()); - } - } + ((ArrayType) ((Parameter) sym).variable_type).length_type = length_type; + } else if (sym is Callable) { + ((ArrayType) ((Callable) sym).return_type).length_type = length_type; } }