From c02ee2eb1a48b63c99eab93adc56cfdcf1db2202 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Wed, 4 Oct 2017 16:14:18 -0300 Subject: [PATCH] generator: Use parent structure fields whene generating ABI for fieldless structures --- Source/generator/ClassBase.cs | 23 ++++++++++++++++++----- Source/glib/AbiStruct.cs | 3 +++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Source/generator/ClassBase.cs b/Source/generator/ClassBase.cs index 04056f647..96b3ca531 100644 --- a/Source/generator/ClassBase.cs +++ b/Source/generator/ClassBase.cs @@ -224,12 +224,24 @@ namespace GtkSharp.Generation { sw.WriteLine ("\t\tstatic public " + _new + "GLib.AbiStruct " + info_name + " {"); sw.WriteLine ("\t\t\tget {"); sw.WriteLine ("\t\t\t\tif (_" + info_name + " == null)"); - sw.WriteLine ("\t\t\t\t\t_" + info_name + " = new GLib.AbiStruct (new List{ "); // Generate Tests - if (_fields.Count > 0 && gen_info.CAbiWriter != null) { - gen_info.CAbiWriter.WriteLine("\tg_print(\"\\\"sizeof({0})\\\": \\\"%\" G_GOFFSET_FORMAT \"\\\"\\n\", sizeof({0}));", structname); - gen_info.AbiWriter.WriteLine("\t\t\tConsole.WriteLine(\"\\\"sizeof({0})\\\": \\\"\" + {1}.{2}." + info_name + ".Size + \"\\\"\");", structname, NS, Name); + var using_parent_fields = false; + if (_fields.Count > 0) { + sw.WriteLine ("\t\t\t\t\t_" + info_name + " = new GLib.AbiStruct (new List{ "); + + if (gen_info.CAbiWriter != null) { + gen_info.CAbiWriter.WriteLine("\tg_print(\"\\\"sizeof({0})\\\": \\\"%\" G_GOFFSET_FORMAT \"\\\"\\n\", sizeof({0}));", structname); + gen_info.AbiWriter.WriteLine("\t\t\tConsole.WriteLine(\"\\\"sizeof({0})\\\": \\\"\" + {1}.{2}." + info_name + ".Size + \"\\\"\");", structname, NS, Name); + } + } else { + if (cs_parent_struct != "") { + sw.WriteLine ("\t\t\t\t\t_" + info_name + " = new GLib.AbiStruct ({0}.{1}.Fields);", cs_parent_struct, info_name); + using_parent_fields = true; + } else { + sw.WriteLine ("\t\t\t\t\t_" + info_name + " = new GLib.AbiStruct (new List{ "); + using_parent_fields = false; + } } StructABIField prev = null; @@ -255,7 +267,8 @@ namespace GtkSharp.Generation { gen_info.CAbiWriter.Flush(); } - sw.WriteLine ("\t\t\t\t\t});"); + if (!using_parent_fields) + sw.WriteLine ("\t\t\t\t\t});"); sw.WriteLine (); sw.WriteLine ("\t\t\t\treturn _" + info_name + ";"); sw.WriteLine ("\t\t\t}"); diff --git a/Source/glib/AbiStruct.cs b/Source/glib/AbiStruct.cs index 6fec730d1..77236da38 100644 --- a/Source/glib/AbiStruct.cs +++ b/Source/glib/AbiStruct.cs @@ -35,6 +35,9 @@ namespace GLib { public class AbiStruct { public OrderedDictionary Fields = null; + public AbiStruct(OrderedDictionary fields) { + Fields = fields; + } public AbiStruct(List fields) { Fields = new OrderedDictionary();