summaryrefslogtreecommitdiff
path: root/codegen
diff options
context:
space:
mode:
authorPrinceton Ferro <princetonferro@gmail.com>2021-07-15 02:32:00 -0400
committerRico Tzschichholz <ricotz@ubuntu.com>2021-08-18 13:47:50 +0200
commitcf3a4087bcc5dd443f1eb99b893fe8cb2c536ab8 (patch)
tree173b0285b376ea8a34f75d87dce453273faa8df1 /codegen
parent9471ab001c713598702c0a35ac9c93d01b6233ef (diff)
downloadvala-cf3a4087bcc5dd443f1eb99b893fe8cb2c536ab8.tar.gz
girwriter: Improve struct creation method binding
Struct creation methods are supposed to have `void` return type and take an implicit `self` as the first instance parameter.
Diffstat (limited to 'codegen')
-rw-r--r--codegen/valagirwriter.vala11
1 files changed, 7 insertions, 4 deletions
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 997d899ff..22b024513 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -1207,8 +1207,8 @@ public class Vala.GIRWriter : CodeVisitor {
}
if (constructor && ret_is_struct) {
- // struct constructor has its result as first parameter
- write_param_or_return (return_type, "parameter", ref index, false, "result", return_comment, ParameterDirection.OUT, constructor, true);
+ // struct constructor has a caller-allocates / out-parameter as instance
+ write_param_or_return (return_type, "instance-parameter", ref index, false, "self", return_comment, ParameterDirection.OUT, constructor, true);
}
if (type_params != null) {
@@ -1422,12 +1422,14 @@ public class Vala.GIRWriter : CodeVisitor {
bool is_struct = m.parent_symbol is Struct;
// GI doesn't like constructors that return void type
- string tag_name = is_struct ? "function" : "constructor";
+ string tag_name = is_struct ? "method" : "constructor";
if (m.parent_symbol is Class && m == ((Class)m.parent_symbol).default_construction_method ||
m.parent_symbol is Struct && m == ((Struct)m.parent_symbol).default_construction_method) {
string m_name = is_struct ? "init" : "new";
buffer.append_printf ("<%s name=\"%s\" c:identifier=\"%s\"", tag_name, m_name, get_ccode_name (m));
+ } else if (is_struct) {
+ buffer.append_printf ("<%s name=\"init_%s\" c:identifier=\"%s\"", tag_name, m.name, get_ccode_name (m));
} else {
buffer.append_printf ("<%s name=\"%s\" c:identifier=\"%s\"", tag_name, m.name, get_ccode_name (m));
}
@@ -1565,7 +1567,8 @@ public class Vala.GIRWriter : CodeVisitor {
unowned DelegateType? delegate_type = type as DelegateType;
unowned ArrayType? array_type = type as ArrayType;
- if (type != null && ((type.value_owned && delegate_type == null) || (constructor && !type.type_symbol.is_subtype_of (ginitiallyunowned_type)))) {
+ if (type != null && ((type.value_owned && delegate_type == null) || (constructor
+ && !(type.type_symbol is Struct || type.type_symbol.is_subtype_of (ginitiallyunowned_type))))) {
var any_owned = false;
foreach (var generic_arg in type.get_type_arguments ()) {
any_owned |= generic_arg.value_owned;