summaryrefslogtreecommitdiff
path: root/vala/valamethod.vala
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2020-01-15 15:52:49 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2020-01-15 15:52:49 +0100
commit98ab3da89640b8b8a6c67044b4df1194672774bb (patch)
treedf8c01f363a605cc9fed4ae6df8d09bb4fc81f6d /vala/valamethod.vala
parent8021ad3876ede6b19a8e075ab0f0a23a999d0b50 (diff)
downloadvala-98ab3da89640b8b8a6c67044b4df1194672774bb.tar.gz
Add further support for params arrays
This brings support for params-arrays in normal vala source code. The parameter is a null-terminated array which is represented as variadic parameter in generated C. This feature is considered experimental for now. Fixes https://gitlab.gnome.org/GNOME/vala/issues/128
Diffstat (limited to 'vala/valamethod.vala')
-rw-r--r--vala/valamethod.vala29
1 files changed, 28 insertions, 1 deletions
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index b1b4cc77c..f6ce67d31 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -175,6 +175,8 @@ public class Vala.Method : Subroutine, Callable {
}
}
+ public LocalVariable? params_array_var { get; private set; }
+
public weak Signal signal_reference { get; set; }
public bool closure { get; set; }
@@ -826,7 +828,7 @@ public class Vala.Method : Subroutine, Callable {
error = true;
Report.error (param.source_reference, "Reference parameters are not supported for async methods");
}
- if (!external_package && coroutine && (param.ellipsis || param.variable_type.type_symbol == context.analyzer.va_list_type.type_symbol)) {
+ if (!external_package && coroutine && (param.ellipsis || param.params_array || param.variable_type.type_symbol == context.analyzer.va_list_type.type_symbol)) {
error = true;
Report.error (param.source_reference, "Variadic parameters are not supported for async methods");
return false;
@@ -840,6 +842,28 @@ public class Vala.Method : Subroutine, Callable {
} else if (param.initializer != null) {
optional_param = true;
}
+
+ // Add local variable to provide access to params arrays which will be constructed out of the given va-args
+ if (param.params_array && body != null) {
+ if (params_array_var != null) {
+ Report.error (param.source_reference, "Only one params-array parameter is allowed");
+ continue;
+ }
+ if (!context.experimental) {
+ Report.warning (param.source_reference, "Support of params-arrays is experimental");
+ }
+ var type = (ArrayType) param.variable_type.copy ();
+ type.element_type.value_owned = type.value_owned;
+ type.value_owned = true;
+ if (type.element_type.is_real_struct_type () && !type.element_type.nullable) {
+ Report.error (param.source_reference, "Only nullable struct elements are supported in params-array");
+ }
+ if (type.length != null) {
+ Report.error (param.source_reference, "Passing length to params-array is not supported yet");
+ }
+ params_array_var = new LocalVariable (type, param.name, null, param.source_reference);
+ body.insert_statement (0, new DeclarationStatement (params_array_var, param.source_reference));
+ }
}
if (coroutine) {
@@ -1228,6 +1252,9 @@ public class Vala.Method : Subroutine, Callable {
if (result_var != null) {
collection.add (result_var);
}
+ if (params_array_var != null) {
+ collection.add (params_array_var);
+ }
// capturing variables is only supported if they are initialized
// therefore assume that captured variables are initialized