From: Marc-André Lureau Date: Sun, 28 Mar 2010 23:20:33 +0000 (+0200) Subject: Write CCode attributes for property accessors in VAPI files X-Git-Tag: 0.9.5~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc1786d8a21ff9e9c41c289a2a4c6fb926ee9dfc;p=thirdparty%2Fvala.git Write CCode attributes for property accessors in VAPI files Fixes bug 614206. --- diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index 89d848fdc..75963fb92 100644 --- a/vala/valacodewriter.vala +++ b/vala/valacodewriter.vala @@ -1134,6 +1134,18 @@ public class Vala.CodeWriter : CodeVisitor { write_identifier (prop.name); write_string (" {"); if (prop.get_accessor != null) { + var ccode_params = new StringBuilder (); + var separator = ""; + + if (prop.get_accessor.get_cname () != prop.get_accessor.get_default_cname ()) { + ccode_params.append_printf ("%scname = \"%s\"", separator, prop.get_accessor.get_cname ()); + separator = ", "; + } + if (ccode_params.len > 0) { + write_indent (); + write_string ("[CCode (%s)]".printf (ccode_params.str)); + } + if (context.profile != Profile.DOVA && prop.get_accessor.value_type.is_disposable ()) { write_string (" owned"); } @@ -1142,6 +1154,18 @@ public class Vala.CodeWriter : CodeVisitor { write_code_block (prop.get_accessor.body); } if (prop.set_accessor != null) { + var ccode_params = new StringBuilder (); + var separator = ""; + + if (prop.set_accessor.get_cname () != prop.set_accessor.get_default_cname ()) { + ccode_params.append_printf ("%scname = \"%s\"", separator, prop.set_accessor.get_cname ()); + separator = ", "; + } + if (ccode_params.len > 0) { + write_indent (); + write_string ("[CCode (%s)]".printf (ccode_params.str)); + } + if (context.profile != Profile.DOVA && prop.set_accessor.value_type.value_owned) { write_string (" owned"); } diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala index ca0a1c5a6..ee65a99f8 100644 --- a/vala/valapropertyaccessor.vala +++ b/vala/valapropertyaccessor.vala @@ -96,6 +96,16 @@ public class Vala.PropertyAccessor : Symbol { */ public LocalVariable? result_var { get; set; } + public virtual string get_default_cname () { + var t = (TypeSymbol) prop.parent_symbol; + + if (readable) { + return "%sget_%s".printf (t.get_lower_case_cprefix (), prop.name); + } else { + return "%sset_%s".printf (t.get_lower_case_cprefix (), prop.name); + } + } + /** * The publicly accessible name of the function that performs the * access in C code. @@ -104,14 +114,7 @@ public class Vala.PropertyAccessor : Symbol { if (_cname != null) { return _cname; } - - var t = (TypeSymbol) prop.parent_symbol; - - if (readable) { - return "%sget_%s".printf (t.get_lower_case_cprefix (), prop.name); - } else { - return "%sset_%s".printf (t.get_lower_case_cprefix (), prop.name); - } + return get_default_cname (); } private DataType _value_type;