[vala/0.50] girparser: Set CCode.type_cname for classes if it doesn't match our default



commit 50f5ffc9c6a7c2378729dec0dc5027d73d1b411b
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Jan 31 14:21:19 2021 +0100

    girparser: Set CCode.type_cname for classes if it doesn't match our default

 tests/Makefile.am                |  1 +
 tests/gir/gtype-struct-name.test | 47 ++++++++++++++++++++++++++++++++++++++++
 vala/valagirparser.vala          |  9 +++++---
 3 files changed, 54 insertions(+), 3 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cef1bea68..5b14532dc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -705,6 +705,7 @@ TESTS = \
        gir/delegate-error-pos.test \
        gir/enum.test \
        gir/errordomain.test \
+       gir/gtype-struct-name.test \
        gir/instance-parameter-owned.test \
        gir/method-array-length-type.test \
        gir/parameter-array-length-type.test \
diff --git a/tests/gir/gtype-struct-name.test b/tests/gir/gtype-struct-name.test
new file mode 100644
index 000000000..3ad28cac5
--- /dev/null
+++ b/tests/gir/gtype-struct-name.test
@@ -0,0 +1,47 @@
+GIR
+
+Input:
+
+<interface name="Foo"
+           c:symbol-prefix="foo"
+           c:type="TestFoo"
+           glib:type-name="TestFoo"
+           glib:get-type="test_foo_get_type"
+           glib:type-struct="FooInterface">
+</interface>
+<record name="FooInterface"
+        c:type="TestFooInterface"
+        glib:is-gtype-struct-for="Foo">
+  <field name="parent" readable="0" private="1">
+    <type name="GObject.TypeInterface" c:type="GTypeInterface"/>
+  </field>
+</record>
+<class name="Bar"
+       c:symbol-prefix="bar"
+       c:type="TestBar"
+       parent="GObject.Object"
+       glib:type-name="TestBar"
+       glib:get-type="test_bar_get_type"
+       glib:type-struct="BarKlass">
+  <field name="parent" readable="0" private="1">
+    <type name="GObject.Object" c:type="GObject"/>
+  </field>
+</class>
+<record name="BarKlass"
+        c:type="TestBarKlass"
+        glib:is-gtype-struct-for="Bar">
+  <field name="parent" readable="0" private="1">
+    <type name="GObject.ObjectClass" c:type="GObjectClass"/>
+  </field>
+</record>
+
+Output:
+
+[CCode (cheader_filename = "test.h", type_cname = "TestBarKlass", type_id = "test_bar_get_type ()")]
+public class Bar : GLib.Object {
+       [CCode (has_construct_function = false)]
+       protected Bar ();
+}
+[CCode (cheader_filename = "test.h", type_cname = "TestFooInterface", type_id = "test_foo_get_type ()")]
+public interface Foo : GLib.Object {
+}
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 05ef1f942..c33e64aad 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1215,10 +1215,13 @@ public class Vala.GirParser : CodeVisitor {
                                                // record for a gtype
                                                var gtype_struct_for = girdata["glib:is-gtype-struct-for"];
                                                if (gtype_struct_for != null) {
-                                                       var iface = parser.resolve_node (parent, 
parser.parse_symbol_from_string (gtype_struct_for, source_reference));
-                                                       if (iface != null && iface.symbol is Interface && 
"%sIface".printf (iface.get_cname ()) != get_cname ()) {
+                                                       var obj = parser.resolve_node (parent, 
parser.parse_symbol_from_string (gtype_struct_for, source_reference));
+                                                       if (obj != null && obj.symbol is Interface && 
"%sIface".printf (obj.get_cname ()) != get_cname ()) {
                                                                // set the interface struct name
-                                                               iface.symbol.set_attribute_string ("CCode", 
"type_cname", get_cname ());
+                                                               obj.symbol.set_attribute_string ("CCode", 
"type_cname", get_cname ());
+                                                       } else if (obj != null && obj.symbol is Class && 
"%sClass".printf (obj.get_cname ()) != get_cname ()) {
+                                                               // set the class struct name
+                                                               obj.symbol.set_attribute_string ("CCode", 
"type_cname", get_cname ());
                                                        }
                                                        merged = true;
                                                }


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