generator: Use parent structure fields whene generating ABI for fieldless structures

This commit is contained in:
Thibault Saunier 2017-10-04 16:14:18 -03:00
parent 7d7036c9c6
commit c02ee2eb1a
2 changed files with 21 additions and 5 deletions

View file

@ -224,13 +224,25 @@ 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<GLib.AbiField>{ ");
// Generate Tests
if (_fields.Count > 0 && gen_info.CAbiWriter != null) {
var using_parent_fields = false;
if (_fields.Count > 0) {
sw.WriteLine ("\t\t\t\t\t_" + info_name + " = new GLib.AbiStruct (new List<GLib.AbiField>{ ");
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<GLib.AbiField>{ ");
using_parent_fields = false;
}
}
StructABIField prev = null;
StructABIField next = null;
@ -255,6 +267,7 @@ namespace GtkSharp.Generation {
gen_info.CAbiWriter.Flush();
}
if (!using_parent_fields)
sw.WriteLine ("\t\t\t\t\t});");
sw.WriteLine ();
sw.WriteLine ("\t\t\t\treturn _" + info_name + ";");

View file

@ -35,6 +35,9 @@ namespace GLib {
public class AbiStruct {
public OrderedDictionary Fields = null;
public AbiStruct(OrderedDictionary fields) {
Fields = fields;
}
public AbiStruct(List<GLib.AbiField> fields) {
Fields = new OrderedDictionary();