[vala/0.44] girwriter: Write implicit fields for arrays and delegates



commit 0c73045bf82aa0f048a1bb45f142320b67e0aaf1
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Fri May 3 15:32:04 2019 +0200

    girwriter: Write implicit fields for arrays and delegates

 codegen/valagirwriter.vala               | 43 ++++++++++++++++++++++++++++++++
 tests/girwriter/GirTest-1.0.gir-expected | 17 +++++++++++++
 tests/girwriter/girtest.vala             |  2 ++
 tests/girwriter/girtest.vapi-expected    |  2 ++
 4 files changed, 64 insertions(+)
---
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 590a887c3..0c7c5b987 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -942,6 +942,49 @@ public class Vala.GIRWriter : CodeVisitor {
                indent--;
                write_indent ();
                buffer.append_printf ("</field>\n");
+
+               if (f.variable_type is ArrayType && get_ccode_array_length (f)) {
+                       var array_type = (ArrayType) f.variable_type;
+                       if (!array_type.fixed_length) {
+                               for (var i = 0; i < array_type.rank; i++) {
+                                       write_indent ();
+                                       buffer.append_printf ("<field name=\"%s_length%i\"", get_ccode_name 
(f), i + 1);
+                                       write_symbol_attributes (f);
+                                       buffer.append_printf (">\n");
+                                       indent++;
+                                       write_type (array_type.length_type);
+                                       indent--;
+                                       write_indent ();
+                                       buffer.append_printf ("</field>\n");
+                               }
+                       }
+               } else if (f.variable_type is DelegateType) {
+                       var deleg_type = (DelegateType) f.variable_type;
+                       if (deleg_type.delegate_symbol.has_target) {
+                               write_indent ();
+                               buffer.append_printf ("<field name=\"%s\"", get_ccode_delegate_target_name 
(f));
+                               write_symbol_attributes (f);
+                               buffer.append_printf (">\n");
+                               indent++;
+                               write_indent ();
+                               buffer.append_printf ("<type name=\"gpointer\" c:type=\"gpointer\"/>\n");
+                               indent--;
+                               write_indent ();
+                               buffer.append_printf ("</field>\n");
+                               if (deleg_type.is_disposable ()) {
+                                       write_indent ();
+                                       buffer.append_printf ("<field name=\"%s\"", 
get_ccode_delegate_target_destroy_notify_name (f));
+                                       write_symbol_attributes (f);
+                                       buffer.append_printf (">\n");
+                                       indent++;
+                                       write_indent ();
+                                       buffer.append_printf ("<type name=\"GLib.DestroyNotify\" 
c:type=\"GDestroyNotify\"/>\n");
+                                       indent--;
+                                       write_indent ();
+                                       buffer.append_printf ("</field>\n");
+                               }
+                       }
+               }
        }
 
        private void write_implicit_params (DataType? type, ref int index, bool has_array_length, string? 
name, ParameterDirection direction) {
diff --git a/tests/girwriter/GirTest-1.0.gir-expected b/tests/girwriter/GirTest-1.0.gir-expected
index 9aba2a5f8..034f48418 100644
--- a/tests/girwriter/GirTest-1.0.gir-expected
+++ b/tests/girwriter/GirTest-1.0.gir-expected
@@ -75,6 +75,23 @@
                <field name="priv">
                        <type name="SubTypeTestPrivate" c:type="GirTestSubTypeTestPrivate*"/>
                </field>
+               <field name="array_field">
+                       <array c:type="gchar**">
+                               <type name="utf8" c:type="gchar*"/>
+                       </array>
+               </field>
+               <field name="array_field_length1">
+                       <type name="gint" c:type="gint"/>
+               </field>
+               <field name="delegate_field">
+                       <type name="GirTest.DelegateTest" c:type="GirTestDelegateTest"/>
+               </field>
+               <field name="delegate_field_target">
+                       <type name="gpointer" c:type="gpointer"/>
+               </field>
+               <field name="delegate_field_target_destroy_notify">
+                       <type name="GLib.DestroyNotify" c:type="GDestroyNotify"/>
+               </field>
                <constructor name="new" c:identifier="gir_test_sub_type_test_new">
                        <return-value transfer-ownership="full">
                                <type name="GirTest.SubTypeTest" c:type="GirTestSubTypeTest*"/>
diff --git a/tests/girwriter/girtest.vala b/tests/girwriter/girtest.vala
index 1164ab1da..3ace08a5b 100644
--- a/tests/girwriter/girtest.vala
+++ b/tests/girwriter/girtest.vala
@@ -87,6 +87,8 @@ namespace GirTest {
        }
 
        public class SubTypeTest : TypeTest {
+               public string[] array_field;
+               public DelegateTest delegate_field;
        }
 
        public class ObjectTest : Object {
diff --git a/tests/girwriter/girtest.vapi-expected b/tests/girwriter/girtest.vapi-expected
index 8e3b3b697..52d23d16a 100644
--- a/tests/girwriter/girtest.vapi-expected
+++ b/tests/girwriter/girtest.vapi-expected
@@ -87,6 +87,8 @@ namespace GirTest {
        }
        [CCode (cheader_filename = "girtest.h")]
        public class SubTypeTest : GirTest.TypeTest {
+               public string[] array_field;
+               public GirTest.DelegateTest delegate_field;
                public SubTypeTest ();
        }
        [CCode (cheader_filename = "girtest.h")]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]