From: Rico Tzschichholz Date: Sun, 28 Apr 2019 15:52:40 +0000 (+0200) Subject: girwriter: Properly write attributes for non-GObject classes X-Git-Tag: 0.45.1~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5284e6bda7582cdd011e6fce545c02ae3dd4f3bb;p=thirdparty%2Fvala.git girwriter: Properly write attributes for non-GObject classes --- diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala index c125f5467..4cc2e587a 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 ("\n"); indent++; write_indent (); - buffer.append_printf ("\n", gi_type_name (cl.base_class), get_ccode_name (cl.base_class)); + if (cl.base_class == null) { + buffer.append_printf ("\n", gi_type_name (gtypeinstance_type), get_ccode_name (gtypeinstance_type)); + } else { + buffer.append_printf ("\n", gi_type_name (cl.base_class), get_ccode_name (cl.base_class)); + } indent--; write_indent (); buffer.append_printf("\n"); + if (cl.base_class == null) { + write_indent (); + buffer.append_printf ("\n"); + indent++; + write_indent (); + buffer.append_printf ("\n"); + indent--; + write_indent (); + buffer.append_printf("\n"); + } + write_indent (); buffer.append_printf ("\n"); indent++; @@ -385,7 +412,12 @@ public class Vala.GIRWriter : CodeVisitor { buffer.append_printf ("\n"); indent++; write_indent (); - buffer.append_printf ("\n", gi_type_name (cl.base_class), get_ccode_name (cl.base_class)); + if (cl.base_class == null) { + //FIXME GObject.TypeClass vs GType + buffer.append_printf ("\n", "GObject.Type", get_ccode_name (gtype_type)); + } else { + buffer.append_printf ("\n", gi_type_name (cl.base_class), get_ccode_name (cl.base_class)); + } indent--; write_indent (); buffer.append_printf ("\n"); diff --git a/tests/girwriter/GirTest-1.0.gir-expected b/tests/girwriter/GirTest-1.0.gir-expected index 18ae0bbdc..a8bf8181d 100644 --- a/tests/girwriter/GirTest-1.0.gir-expected +++ b/tests/girwriter/GirTest-1.0.gir-expected @@ -31,7 +31,16 @@ - + + + + + + + + + + @@ -52,7 +61,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + @@ -882,20 +916,50 @@ - + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + diff --git a/tests/girwriter/girtest.vala b/tests/girwriter/girtest.vala index 2e7c522bd..ef35e8ec8 100644 --- a/tests/girwriter/girtest.vala +++ b/tests/girwriter/girtest.vala @@ -86,6 +86,9 @@ namespace GirTest { public string some_property { get; set; } } + public class SubTypeTest : TypeTest { + } + public class ObjectTest : Object { private static ObjectTest global_instance = new ObjectTest (); diff --git a/tests/girwriter/girtest.vapi-expected b/tests/girwriter/girtest.vapi-expected index 0b6e574a7..4a0709bc2 100644 --- a/tests/girwriter/girtest.vapi-expected +++ b/tests/girwriter/girtest.vapi-expected @@ -76,6 +76,10 @@ namespace GirTest { public SkippedClass (); } [CCode (cheader_filename = "girtest.h")] + public class SubTypeTest : GirTest.TypeTest { + public SubTypeTest (); + } + [CCode (cheader_filename = "girtest.h")] public class TypeTest { public TypeTest (); public string some_property { get; set; }