[vala/0.40] girwriter: Write implicit parameters and properties for generics
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] girwriter: Write implicit parameters and properties for generics
- Date: Mon, 5 Aug 2019 11:38:50 +0000 (UTC)
commit bf72dbd0ba67b8038d1b68e850d382f065901b20
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Thu May 2 18:09:19 2019 +0200
girwriter: Write implicit parameters and properties for generics
codegen/valagirwriter.vala | 68 ++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 62 insertions(+), 6 deletions(-)
---
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 7068d8f3e..b6eb20625 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -454,6 +454,12 @@ public class Vala.GIRWriter : CodeVisitor {
write_indent ();
buffer.append_printf("</field>\n");
+ if (cl.base_class != null && cl.base_class.is_subtype_of (gobject_type)) {
+ foreach (var p in cl.get_type_parameters ()) {
+ write_type_parameter (p, "property");
+ }
+ }
+
hierarchy.insert (0, cl);
cl.accept_children (this);
hierarchy.remove_at (0);
@@ -969,7 +975,46 @@ public class Vala.GIRWriter : CodeVisitor {
}
}
- private void write_params_and_return (List<Parameter> params, DataType? return_type, bool
return_array_length, string? return_comment = null, bool constructor = false, DataType? instance_type = null,
bool user_data = false) {
+ private void write_type_parameter (TypeParameter type_parameter, string tag_type) {
+ write_indent ();
+ if (tag_type == "property") {
+ buffer.append_printf ("<%s name=\"%s-type\" writable=\"1\" construct-only=\"1\">\n",
tag_type, type_parameter.name.down ());
+ } else {
+ buffer.append_printf ("<%s name=\"%s_type\" transfer-ownership=\"none\">\n",
tag_type, type_parameter.name.down ());
+ }
+ indent++;
+ write_indent ();
+ buffer.append_printf ("<type name=\"GType\" c:type=\"GType\"/>\n");
+ indent--;
+ write_indent ();
+ buffer.append_printf ("</%s>\n", tag_type);
+ write_indent ();
+ if (tag_type == "property") {
+ buffer.append_printf ("<%s name=\"%s-dup-func\" writable=\"1\"
construct-only=\"1\">\n", tag_type, type_parameter.name.down ());
+ } else {
+ buffer.append_printf ("<%s name=\"%s_dup_func\" transfer-ownership=\"none\">\n",
tag_type, type_parameter.name.down ());
+ }
+ indent++;
+ write_indent ();
+ buffer.append_printf ("<type name=\"GObject.BoxedCopyFunc\" c:type=\"GBoxedCopyFunc\"/>\n");
+ indent--;
+ write_indent ();
+ buffer.append_printf ("</%s>\n", tag_type);
+ write_indent ();
+ if (tag_type == "property") {
+ buffer.append_printf ("<%s name=\"%s-destroy-func\" writable=\"1\"
construct-only=\"1\">\n", tag_type, type_parameter.name.down ());
+ } else {
+ buffer.append_printf ("<%s name=\"%s_destroy_func\" transfer-ownership=\"none\">\n",
tag_type, type_parameter.name.down ());
+ }
+ indent++;
+ write_indent ();
+ buffer.append_printf ("<type name=\"GLib.DestroyNotify\" c:type=\"GDestroyNotify\"/>\n");
+ indent--;
+ write_indent ();
+ buffer.append_printf ("</%s>\n", tag_type);
+ }
+
+ private void write_params_and_return (List<Parameter> params, List<TypeParameter>? type_params,
DataType? return_type, bool return_array_length, string? return_comment = null, bool constructor = false,
DataType? instance_type = null, bool user_data = false) {
int last_index = 0;
bool ret_is_struct = return_type != null && return_type.is_real_non_null_struct_type ();
@@ -1004,7 +1049,7 @@ public class Vala.GIRWriter : CodeVisitor {
write_param_or_return (new VoidType (), false, ref last_index, false, null,
return_comment, ParameterDirection.IN);
}
- if (params.size != 0 || instance_type != null || (return_type is ArrayType &&
return_array_length) || (return_type is DelegateType) || ret_is_struct) {
+ if (params.size != 0 || (type_params != null && type_params.size > 0) || instance_type !=
null || (return_type is ArrayType && return_array_length) || (return_type is DelegateType) || ret_is_struct) {
write_indent ();
buffer.append_printf ("<parameters>\n");
indent++;
@@ -1014,6 +1059,13 @@ public class Vala.GIRWriter : CodeVisitor {
write_param_or_return (instance_type, true, ref index, false, "self");
}
+ if (type_params != null) {
+ foreach (var p in type_params) {
+ write_type_parameter (p, "parameter");
+ index += 3;
+ }
+ }
+
foreach (Parameter param in params) {
write_param_or_return (param.variable_type, true, ref index,
get_ccode_array_length (param), param.name, get_parameter_comment (param), param.direction, false, false,
param.ellipsis);
@@ -1065,7 +1117,7 @@ public class Vala.GIRWriter : CodeVisitor {
write_doc (get_delegate_comment (cb));
- write_params_and_return (cb.get_parameters (), cb.return_type, get_ccode_array_length (cb),
get_delegate_return_comment (cb), false, null, cb.has_target);
+ write_params_and_return (cb.get_parameters (), cb.get_type_parameters (), cb.return_type,
get_ccode_array_length (cb), get_delegate_return_comment (cb), false, null, cb.has_target);
indent--;
write_indent ();
@@ -1185,7 +1237,7 @@ public class Vala.GIRWriter : CodeVisitor {
instance_type = CCodeBaseModule.get_data_type_for_symbol ((TypeSymbol)
m.parent_symbol);
}
- write_params_and_return (params, return_type, get_ccode_array_length (m), return_comment,
false, instance_type);
+ write_params_and_return (params, m.get_type_parameters (), return_type,
get_ccode_array_length (m), return_comment, false, instance_type);
indent--;
write_indent ();
@@ -1229,7 +1281,11 @@ public class Vala.GIRWriter : CodeVisitor {
write_doc (get_method_comment (m));
var datatype = CCodeBaseModule.get_data_type_for_symbol ((TypeSymbol) m.parent_symbol);
- write_params_and_return (m.get_parameters (), datatype, false, get_method_return_comment (m),
true);
+ List<TypeParameter>? type_params = null;
+ if (m.parent_symbol is Class) {
+ type_params = ((Class) m.parent_symbol).get_type_parameters ();
+ }
+ write_params_and_return (m.get_parameters (), type_params, datatype, false,
get_method_return_comment (m), true);
indent--;
write_indent ();
@@ -1302,7 +1358,7 @@ public class Vala.GIRWriter : CodeVisitor {
write_doc (get_signal_comment (sig));
- write_params_and_return (sig.get_parameters (), sig.return_type, false,
get_signal_return_comment (sig));
+ write_params_and_return (sig.get_parameters (), null, sig.return_type, false,
get_signal_return_comment (sig));
indent--;
write_indent ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]