diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2018-05-19 21:28:36 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2018-05-21 21:15:10 +0200 |
commit | 4bfef5908ea4c909feaa10e9b4000b7c58a6cfd6 (patch) | |
tree | aec02c2778a3c4d4bb49302002a41d4dfc70de4d | |
parent | 97b22ac8fb03d8d2739ccc4174c3ff69b859d773 (diff) | |
download | vala-4bfef5908ea4c909feaa10e9b4000b7c58a6cfd6.tar.gz |
girwriter: Properly output variadic methods and use introspectable="0"
This also fixes several criticals caused by "ellipsis" parameter
-rw-r--r-- | codegen/valagirwriter.vala | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala index 22042f19e..57e224b86 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++; @@ -1221,10 +1222,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); } @@ -1236,7 +1240,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; @@ -1252,7 +1256,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\""); } @@ -1276,11 +1280,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 (); |