[vala/staging: 5/5] codegen: Use array_length_cexpr to support fixed-arrays for return-values
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 5/5] codegen: Use array_length_cexpr to support fixed-arrays for return-values
- Date: Sat, 8 Jul 2017 19:16:06 +0000 (UTC)
commit 27d48d19f3737070dd47439d57ce765cd89c17b6
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Jul 8 13:15:50 2017 +0200
codegen: Use array_length_cexpr to support fixed-arrays for return-values
Based on patch by David Lechner
https://bugzilla.gnome.org/show_bug.cgi?id=784691
codegen/valaccodemethodcallmodule.vala | 2 ++
tests/Makefile.am | 1 +
tests/gir/array-fixed-length.test | 2 +-
tests/methods/bug784691.vala | 11 +++++++++++
vala/valagirparser.vala | 15 ++++++++-------
5 files changed, 23 insertions(+), 8 deletions(-)
---
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 1df7f5e..d101f44 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -518,6 +518,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
out_arg_map.set (get_param_pos (get_ccode_array_length_pos (m) + 0.01
* dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
append_array_length (expr, temp_ref);
+ } else if (get_ccode_array_length_expr (m) != null) {
+ append_array_length (expr, new CCodeConstant
(get_ccode_array_length_expr (m)));
} else {
append_array_length (expr, new CCodeConstant ("-1"));
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cf536c2..1153c37 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -94,6 +94,7 @@ TESTS = \
methods/bug771964.vala \
methods/bug774060.vala \
methods/bug775466.test \
+ methods/bug784691.vala \
methods/generics.vala \
methods/printf-invalid.test \
methods/printf-constructor.vala \
diff --git a/tests/gir/array-fixed-length.test b/tests/gir/array-fixed-length.test
index 0d7e70e..d4ea017 100644
--- a/tests/gir/array-fixed-length.test
+++ b/tests/gir/array-fixed-length.test
@@ -62,7 +62,7 @@ Output:
public static void change_array ([CCode (array_length = false)] ref uint8 array[2]);
[CCode (cheader_filename = "test.h")]
public static void get_array_out ([CCode (array_length = false)] out uint8 array[8]);
-[CCode (array_length = false, cheader_filename = "test.h")]
+[CCode (array_length = false, array_length_cexpr = "16", cheader_filename = "test.h")]
public static unowned uint8[] get_array_return ();
[CCode (cheader_filename = "test.h")]
public static void set_array ([CCode (array_length = false)] uint8 array[4]);
diff --git a/tests/methods/bug784691.vala b/tests/methods/bug784691.vala
new file mode 100644
index 0000000..7f11eee
--- /dev/null
+++ b/tests/methods/bug784691.vala
@@ -0,0 +1,11 @@
+const int[] FOO = { 0, 1, 2 };
+
+[CCode (array_length = false, array_length_cexpr = "3")]
+unowned int[] get_foo () {
+ assert (FOO.length == 3);
+ return FOO;
+}
+
+void main () {
+ assert (get_foo ().length == 3);
+}
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 8a1353b..79f0fe5 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -2397,13 +2397,6 @@ public class Vala.GirParser : CodeVisitor {
}
type = element_get_type (type, true, ref no_array_length, ref array_null_terminated);
- // FIXME No support for fixed-size array as return-value
- var array_type = type as ArrayType;
- if (array_type != null && array_type.fixed_length) {
- array_type.fixed_length = false;
- array_type.length = null;
- }
-
end_element ("return-value");
return type;
}
@@ -3084,6 +3077,14 @@ public class Vala.GirParser : CodeVisitor {
s.comment = comment;
s.external = true;
+ // Transform fixed-array properties of return-type into ccode-attribute
+ var array_type = return_type as ArrayType;
+ if (array_type != null && array_type.fixed_length) {
+ s.set_attribute_string ("CCode", "array_length_cexpr", ((IntegerLiteral)
array_type.length).value);
+ array_type.fixed_length = false;
+ array_type.length = null;
+ }
+
if (s is Signal) {
if (current.girdata["name"] != name.replace ("_", "-")) {
s.set_attribute_string ("CCode", "cname", current.girdata["name"]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]