[vala/0.36] girwriter: Properly output variadic methods and use introspectable="0"
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.36] girwriter: Properly output variadic methods and use introspectable="0"
- Date: Mon, 21 May 2018 16:47:23 +0000 (UTC)
commit 90ec9c95f64cab5043a899c3b8f6e6fbd53d2141
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat May 19 21:28:36 2018 +0200
girwriter: Properly output variadic methods and use introspectable="0"
This also fixes several criticals caused by "ellipsis" parameter
codegen/valagirwriter.vala | 47 ++++++++++++++++++++++++++-----------------
1 files changed, 28 insertions(+), 19 deletions(-)
---
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 209113d..390a5cf 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -832,7 +832,7 @@ public class Vala.GIRWriter : CodeVisitor {
buffer.append_printf ("</field>\n");
}
- private void write_implicit_params (DataType type, ref int index, bool has_array_length, string name,
ParameterDirection direction) {
+ private void write_implicit_params (DataType? type, ref int index, bool has_array_length, string?
name, ParameterDirection direction) {
if (type is ArrayType && has_array_length) {
var int_type = new IntegerType (CodeContext.get ().root.scope.lookup ("int") as
Struct);
for (var i = 0; i < ((ArrayType) type).rank; i++) {
@@ -851,7 +851,7 @@ public class Vala.GIRWriter : CodeVisitor {
}
}
- void skip_implicit_params (DataType type, ref int index, bool has_array_length) {
+ void skip_implicit_params (DataType? type, ref int index, bool has_array_length) {
if (type is ArrayType && has_array_length) {
index += ((ArrayType) type).rank;
} else if (type is DelegateType) {
@@ -909,7 +909,7 @@ public class Vala.GIRWriter : CodeVisitor {
}
foreach (Parameter param in params) {
- write_param_or_return (param.variable_type, true, ref index,
CCodeBaseModule.get_ccode_array_length (param), param.name, get_parameter_comment (param), param.direction);
+ write_param_or_return (param.variable_type, true, ref index,
CCodeBaseModule.get_ccode_array_length (param), param.name, get_parameter_comment (param), param.direction,
false, false, param.ellipsis);
write_implicit_params (param.variable_type, ref index,
CCodeBaseModule.get_ccode_array_length (param), param.name, param.direction);
}
@@ -978,11 +978,6 @@ public class Vala.GIRWriter : CodeVisitor {
return;
}
- // check for unsupported types
- if (!check_signature (m)) {
- return;
- }
-
string tag_name = "method";
var parent = this.hierarchy.get (0);
if (parent is Enum) {
@@ -1001,7 +996,7 @@ public class Vala.GIRWriter : CodeVisitor {
}
}
- bool check_type (DataType type) {
+ bool is_type_introspectable (DataType type) {
// gobject-introspection does not currently support va_list parameters
if (CCodeBaseModule.get_ccode_name (type) == "va_list") {
return false;
@@ -1010,12 +1005,12 @@ public class Vala.GIRWriter : CodeVisitor {
return true;
}
- bool check_signature (Method m) {
- if (!check_type (m.return_type)) {
+ bool is_introspectable (Method m) {
+ if (!is_type_introspectable (m.return_type)) {
return false;
}
foreach (var param in m.get_parameters ()) {
- if (param.variable_type == null || !check_type (param.variable_type)) {
+ if (param.ellipsis || !is_type_introspectable (param.variable_type)) {
return false;
}
}
@@ -1064,6 +1059,9 @@ public class Vala.GIRWriter : CodeVisitor {
buffer.append_printf (" throws=\"1\"");
}
write_symbol_attributes (m);
+ if (!is_introspectable (m)) {
+ buffer.append_printf (" introspectable=\"0\"");
+ }
buffer.append_printf (">\n");
indent++;
@@ -1117,6 +1115,9 @@ public class Vala.GIRWriter : CodeVisitor {
if (m.tree_can_fail) {
buffer.append_printf (" throws=\"1\"");
}
+ if (!is_introspectable (m)) {
+ buffer.append_printf (" introspectable=\"0\"");
+ }
buffer.append_printf (">\n");
indent++;
@@ -1225,10 +1226,13 @@ public class Vala.GIRWriter : CodeVisitor {
}
- private void write_param_or_return (DataType type, bool is_parameter, ref int index, bool
has_array_length, string? name = null, string? comment = null, ParameterDirection direction =
ParameterDirection.IN, bool constructor = false, bool caller_allocates = false) {
+ private void write_param_or_return (DataType? type, bool is_parameter, ref int index, bool
has_array_length, string? name = null, string? comment = null, ParameterDirection direction =
ParameterDirection.IN, bool constructor = false, bool caller_allocates = false, bool ellipsis = false) {
write_indent ();
string tag = is_parameter ? "parameter" : "return-value";
buffer.append_printf ("<%s", tag);
+ if (ellipsis) {
+ name = "...";
+ }
if (name != null) {
buffer.append_printf (" name=\"%s\"", name);
}
@@ -1240,7 +1244,7 @@ public class Vala.GIRWriter : CodeVisitor {
DelegateType delegate_type = type as DelegateType;
- if ((type.value_owned && delegate_type == null) || (constructor &&
!type.data_type.is_subtype_of (ginitiallyunowned_type))) {
+ if (type != null && ((type.value_owned && delegate_type == null) || (constructor &&
!type.data_type.is_subtype_of (ginitiallyunowned_type)))) {
var any_owned = false;
foreach (var generic_arg in type.get_type_arguments ()) {
any_owned |= generic_arg.value_owned;
@@ -1256,7 +1260,7 @@ public class Vala.GIRWriter : CodeVisitor {
if (caller_allocates) {
buffer.append_printf (" caller-allocates=\"1\"");
}
- if (type.nullable) {
+ if (type != null && type.nullable) {
buffer.append_printf (" allow-none=\"1\"");
}
@@ -1280,11 +1284,16 @@ public class Vala.GIRWriter : CodeVisitor {
write_doc (comment);
- int length_param_index = -1;
- if (has_array_length) {
- length_param_index = is_parameter ? index + 1 : index;
+ if (ellipsis) {
+ write_indent ();
+ buffer.append ("<varargs/>\n");
+ } else if (type != null) {
+ int length_param_index = -1;
+ if (has_array_length) {
+ length_param_index = is_parameter ? index + 1 : index;
+ }
+ write_type (type, length_param_index, direction);
}
- write_type (type, length_param_index, direction);
indent--;
write_indent ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]