[vala/wip/issue/606: 1/3] girwriter: Properly write attributes for non-GObject classes
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/606: 1/3] girwriter: Properly write attributes for non-GObject classes
- Date: Sun, 28 Apr 2019 20:08:22 +0000 (UTC)
commit c7a373a93edd5548164d27c226c754d6528a7ab9
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Apr 28 17:52:40 2019 +0200
girwriter: Properly write attributes for non-GObject classes
codegen/valagirwriter.vala | 29 +++++++++++++++++++---
tests/girwriter/GirTest-1.0.gir-expected | 42 +++++++++++++++++++++++++++++---
2 files changed, 64 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index c125f5467..c0957197c 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -112,6 +112,8 @@ public class Vala.GIRWriter : CodeVisitor {
private TypeSymbol gobject_type;
private TypeSymbol ginitiallyunowned_type;
private TypeSymbol gtypeinterface_type;
+ private TypeSymbol gtypeinstance_type;
+ private TypeSymbol gtype_type;
private struct GIRNamespace {
public GIRNamespace (string ns, string version) {
@@ -155,6 +157,8 @@ public class Vala.GIRWriter : CodeVisitor {
gobject_type = (TypeSymbol) glib_ns.scope.lookup ("Object");
ginitiallyunowned_type = (TypeSymbol) glib_ns.scope.lookup ("InitiallyUnowned");
gtypeinterface_type = (TypeSymbol) glib_ns.scope.lookup ("TypeInterface");
+ gtypeinstance_type = (TypeSymbol) glib_ns.scope.lookup ("TypeInstance");
+ gtype_type = (TypeSymbol) glib_ns.scope.lookup ("Type");
write_package (package);
@@ -322,14 +326,22 @@ public class Vala.GIRWriter : CodeVisitor {
return;
}
- if (cl.is_subtype_of (gobject_type)) {
+ if (!cl.is_compact) {
string gtype_struct_name = get_gir_name (cl) + "Class";
write_indent ();
buffer.append_printf ("<class name=\"%s\"", get_gir_name (cl));
write_gtype_attributes (cl);
buffer.append_printf (" glib:type-struct=\"%s\"", gtype_struct_name);
- buffer.append_printf (" parent=\"%s\"", gi_type_name (cl.base_class));
+ if (cl.base_class == null) {
+ buffer.append_printf (" glib:fundamental=\"1\"");
+ buffer.append_printf (" glib:ref-func=\"%s\"", get_ccode_ref_function (cl));
+ buffer.append_printf (" glib:unref-func=\"%s\"", get_ccode_unref_function
(cl));
+ buffer.append_printf (" glib:set-value-func=\"%s\"",
get_ccode_set_value_function (cl));
+ buffer.append_printf (" glib:get-value-func=\"%s\"",
get_ccode_get_value_function (cl));
+ } else {
+ buffer.append_printf (" parent=\"%s\"", gi_type_name (cl.base_class));
+ }
if (cl.is_abstract) {
buffer.append_printf (" abstract=\"1\"");
}
@@ -352,7 +364,11 @@ public class Vala.GIRWriter : CodeVisitor {
buffer.append_printf ("<field name=\"parent_instance\">\n");
indent++;
write_indent ();
- buffer.append_printf ("<type name=\"%s\" c:type=\"%s\"/>\n", gi_type_name
(cl.base_class), get_ccode_name (cl.base_class));
+ if (cl.is_subtype_of (gobject_type)) {
+ buffer.append_printf ("<type name=\"%s\" c:type=\"%s\"/>\n", gi_type_name
(cl.base_class), get_ccode_name (cl.base_class));
+ } else {
+ buffer.append_printf ("<type name=\"%s\" c:type=\"%s\"/>\n", gi_type_name
(gtypeinstance_type), get_ccode_name (gtypeinstance_type));
+ }
indent--;
write_indent ();
buffer.append_printf("</field>\n");
@@ -385,7 +401,12 @@ public class Vala.GIRWriter : CodeVisitor {
buffer.append_printf ("<field name=\"parent_class\">\n");
indent++;
write_indent ();
- buffer.append_printf ("<type name=\"%sClass\" c:type=\"%sClass\"/>\n", gi_type_name
(cl.base_class), get_ccode_name (cl.base_class));
+ if (cl.is_subtype_of (gobject_type)) {
+ buffer.append_printf ("<type name=\"%sClass\" c:type=\"%sClass\"/>\n",
gi_type_name (cl.base_class), get_ccode_name (cl.base_class));
+ } else {
+ //FIXME GObject.TypeClass vs GType
+ buffer.append_printf ("<type name=\"%sClass\" c:type=\"%sClass\"/>\n",
"GObject.Type", get_ccode_name (gtype_type));
+ }
indent--;
write_indent ();
buffer.append_printf ("</field>\n");
diff --git a/tests/girwriter/GirTest-1.0.gir-expected b/tests/girwriter/GirTest-1.0.gir-expected
index 18ae0bbdc..efc7e0a85 100644
--- a/tests/girwriter/GirTest-1.0.gir-expected
+++ b/tests/girwriter/GirTest-1.0.gir-expected
@@ -31,7 +31,13 @@
<member name="smelly" c:identifier="GIR_TEST_ERROR_TEST_SMELLY" value="1"/>
<member name="fishy" c:identifier="GIR_TEST_ERROR_TEST_FISHY" value="23"/>
</enumeration>
- <record name="TypeTest">
+ <class name="TypeTest" c:type="GirTestTypeTest" glib:type-name="GirTestTypeTest"
glib:get-type="gir_test_typetest_get_type" glib:type-struct="TypeTestClass" glib:fundamental="1"
glib:ref-func="gir_test_typetest_ref" glib:unref-func="gir_test_typetest_unref"
glib:set-value-func="gir_test_value_set_typetest" glib:get-value-func="gir_test_value_get_typetest">
+ <field name="parent_instance">
+ <type name="GObject.TypeInstance" c:type="GTypeInstance"/>
+ </field>
+ <field name="priv">
+ <type name="TypeTestPrivate" c:type="GirTestTypeTestPrivate*"/>
+ </field>
<constructor name="new" c:identifier="gir_test_typetest_new">
<return-value transfer-ownership="full">
<type name="GirTest.TypeTest" c:type="GirTestTypeTest*"/>
@@ -52,7 +58,13 @@
</parameter>
</parameters>
</method>
+ </class>
+ <record name="TypeTestClass" c:type="GirTestTypeTestClass" glib:is-gtype-struct-for="TypeTest">
+ <field name="parent_class">
+ <type name="GObject.TypeClass" c:type="GTypeClass"/>
+ </field>
</record>
+ <record name="TypeTestPrivate" c:type="GirTestTypeTestPrivate" disguised="1"/>
<class name="ObjectTest" c:type="GirTestObjectTest" glib:type-name="GirTestObjectTest"
glib:get-type="gir_test_object_test_get_type" glib:type-struct="ObjectTestClass" parent="GObject.Object">
<field name="parent_instance">
<type name="GObject.Object" c:type="GObject"/>
@@ -882,20 +894,44 @@
</field>
</record>
<record name="ImplementionTestPrivate" c:type="GirTestImplementionTestPrivate" disguised="1"/>
- <record name="SkippedClass" introspectable="0">
+ <class name="SkippedClass" c:type="GirTestSkippedClass" glib:type-name="GirTestSkippedClass"
glib:get-type="gir_test_skippedclass_get_type" glib:type-struct="SkippedClassClass" glib:fundamental="1"
glib:ref-func="gir_test_skippedclass_ref" glib:unref-func="gir_test_skippedclass_unref"
glib:set-value-func="gir_test_value_set_skippedclass" glib:get-value-func="gir_test_value_get_skippedclass"
introspectable="0">
+ <field name="parent_instance">
+ <type name="GObject.TypeInstance" c:type="GTypeInstance"/>
+ </field>
+ <field name="priv">
+ <type name="SkippedClassPrivate" c:type="GirTestSkippedClassPrivate*"/>
+ </field>
<constructor name="new" c:identifier="gir_test_skippedclass_new">
<return-value transfer-ownership="full">
<type name="GirTest.SkippedClass" c:type="GirTestSkippedClass*"/>
</return-value>
</constructor>
+ </class>
+ <record name="SkippedClassClass" c:type="GirTestSkippedClassClass"
glib:is-gtype-struct-for="SkippedClass">
+ <field name="parent_class">
+ <type name="GObject.TypeClass" c:type="GTypeClass"/>
+ </field>
</record>
- <record name="DeprecatedClassTest" deprecated="1" deprecated-version="0.1.2" version="0.1.0">
+ <record name="SkippedClassPrivate" c:type="GirTestSkippedClassPrivate" disguised="1"/>
+ <class name="DeprecatedClassTest" c:type="GirTestDeprecatedClassTest"
glib:type-name="GirTestDeprecatedClassTest" glib:get-type="gir_test_deprecated_class_test_get_type"
glib:type-struct="DeprecatedClassTestClass" glib:fundamental="1"
glib:ref-func="gir_test_deprecated_class_test_ref" glib:unref-func="gir_test_deprecated_class_test_unref"
glib:set-value-func="gir_test_value_set_deprecated_class_test"
glib:get-value-func="gir_test_value_get_deprecated_class_test" deprecated="1" deprecated-version="0.1.2"
version="0.1.0">
+ <field name="parent_instance">
+ <type name="GObject.TypeInstance" c:type="GTypeInstance"/>
+ </field>
+ <field name="priv">
+ <type name="DeprecatedClassTestPrivate" c:type="GirTestDeprecatedClassTestPrivate*"/>
+ </field>
<constructor name="new" c:identifier="gir_test_deprecated_class_test_new">
<return-value transfer-ownership="full">
<type name="GirTest.DeprecatedClassTest"
c:type="GirTestDeprecatedClassTest*"/>
</return-value>
</constructor>
+ </class>
+ <record name="DeprecatedClassTestClass" c:type="GirTestDeprecatedClassTestClass"
glib:is-gtype-struct-for="DeprecatedClassTest">
+ <field name="parent_class">
+ <type name="GObject.TypeClass" c:type="GTypeClass"/>
+ </field>
</record>
+ <record name="DeprecatedClassTestPrivate" c:type="GirTestDeprecatedClassTestPrivate" disguised="1"/>
<interface name="InterfaceTest" c:type="GirTestInterfaceTest" glib:type-name="GirTestInterfaceTest"
glib:get-type="gir_test_interface_test_get_type" glib:type-struct="InterfaceTestIface">
<prerequisite name="GObject.Object"/>
<method name="int8_in" c:identifier="gir_test_interface_test_int8_in">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]