public StructField Generate(GenerationInfo gen_info, string indent, string parent_name, StructAbiField prev_field, StructAbiField next, string struct_parent_name, TextWriter tw) { StreamWriter sw = gen_info.Writer; var name = Elem.GetAttribute("name"); var cname = Elem.GetAttribute("cname"); if (!unique_field) { parent_name = parent_name + '.' + name; } StructAbiField next_field = null; sw.WriteLine(indent + "// union struct " + parent_name); for (int i = 0; i < fields.Count; i++) { var field = fields[i]; next_field = fields.Count > i + 1 ? fields[i + 1] : null; field.ParentStructureName = parent_name; field.Generate(gen_info, indent, prev_field, next_field, struct_parent_name, tw); prev_field = field; } sw.WriteLine(indent + "// End " + parent_name); sw.WriteLine(); return(prev_field); }
public override StructAbiField Generate(GenerationInfo generationInfo, string indent, StructAbiField previousField, StructAbiField nextField, string parent_name, TextWriter textWriter) { StreamWriter sw = generationInfo.Writer; var name = _element.GetAttribute("name"); var cname = _element.GetAttribute("cname"); foreach (UnionSubstruct _struct in substructs) { _struct.EnsureParentStructName(cname); } foreach (UnionSubstruct _struct in substructs) { _struct.Generate(generationInfo, indent + "\t", cname, previousField, nextField, parent_name, textWriter); } base.Generate(generationInfo, indent, previousField, nextField, parent_name, null); return(this); }
public virtual StructAbiField Generate(GenerationInfo generationInfo, string indent, StructAbiField previousField, StructAbiField nextField, string parentName, TextWriter textWriter) { var streamWriter = generationInfo.Writer; streamWriter.WriteLine("{0}\tnew GLib.AbiField(\"{1}\"", indent, CName); indent = $"{indent}\t\t"; if (previousField != null) { streamWriter.WriteLine($"{indent}, -1"); } else { streamWriter.WriteLine(parentName != "" ? $"{indent}, {parentName}.{AbiInfoName}.Fields" : $"{indent}, 0"); } streamWriter.WriteLine($"{indent}, {GenerateGetSizeOf(string.Empty)}"); var previousFieldName = previousField != null ? $"\"{previousField.CName}\"" : "null"; streamWriter.WriteLine($"{indent}, {previousFieldName}"); var nextFieldName = nextField != null ? $"\"{nextField.CName}\"" : "null"; streamWriter.WriteLine($"{indent}, {nextFieldName}"); var generatable = SymbolTable.Table[CType]; var containerName = ContainerType.CName.Replace(".", "_"); var sanitizedName = CName.Replace(".", "_"); var alignStructName = $"{containerName}_{sanitizedName}Align"; if (textWriter != null) { var minAlign = generatable?.GenerateAlign(); // Do not generate structs if the type is a simple pointer. if (IsCPointer()) { minAlign = "(uint) Marshal.SizeOf(typeof(IntPtr))"; } if (IsBitfield) { minAlign = "1"; } if (minAlign == null) { const string fixedIndent = "\t\t"; textWriter.WriteLine($"{fixedIndent}[StructLayout(LayoutKind.Sequential)]"); textWriter.WriteLine($"{fixedIndent}public struct {alignStructName}"); textWriter.WriteLine($"{fixedIndent}{{"); textWriter.WriteLine($"{fixedIndent}\tsbyte f1;"); Generate(generationInfo, $"{fixedIndent}\t", true, textWriter); textWriter.WriteLine($"{fixedIndent}}}"); textWriter.WriteLine(); var fieldname = SymbolTable.Table.MangleName(CName).Replace(".", "_"); if (IsArray && IsNullTermArray) { fieldname += "Ptr"; } streamWriter.WriteLine( $"{indent}, (long) Marshal.OffsetOf(typeof({alignStructName}), \"{fieldname}\")"); } else { streamWriter.WriteLine($"{indent}, {minAlign}"); } } generationInfo.Writer = streamWriter; var bitsstr = Element.GetAttribute(Constants.Bits); uint bits = 0; if (!string.IsNullOrEmpty(bitsstr)) { bits = uint.Parse(bitsstr); } streamWriter.WriteLine($"{indent}, {bits}"); streamWriter.WriteLine($"{indent}),"); return(this); }