public override void EmitCode(Generator generator, int depth, int ident) { generator.EmitLine("// This file is automatically generated.", depth); generator.EmitLine("using System;", depth); generator.EmitLine("using System.Text;", depth); generator.EmitLine("using System.Runtime.InteropServices;", depth); generator.EmitLine("using Steam4NET.Attributes;", depth); generator.EmitLine("", depth); generator.EmitLine("namespace Steam4NET", depth); generator.EmitLine("{", depth); generator.EmitLine("", depth); foreach (INode child in children) { if (child is CXXRecordNode) { CXXRecordNode recordnode = child as CXXRecordNode; INode basetype; bool constness, pointer; recordnode.ResolveType(1, out basetype, out constness, out pointer); if (basetype.GetAttribute("kind") == "class" && recordnode.ContainsVirtualMethods()) { recordnode.EmitCode(generator, depth + 1, 0); } else if (recordnode.GetChildCount() > 0) { recordnode.EmitCode(generator, depth + 1, 1); } } else if (child is EnumNode) { EnumNode enumnode = child as EnumNode; enumnode.EmitCode(generator, depth + 1, ident); } } generator.EmitLine("}", depth); generator.FlushToFile(Path.GetFileNameWithoutExtension(name)); }
private void EmitCodeStruct(Generator generator, int depth, int ident) { if (Generator.OverrideClasses.Contains(GetName())) { return; } generator.EmitLine("[StructLayout(LayoutKind.Sequential,Pack=8)]", depth); int attribMarker = generator.GetMarker(); generator.EmitLine("public struct " + GetName(), depth); generator.EmitLine("{", depth); foreach (INode child in children) { if (child is FieldNode && !String.IsNullOrEmpty(child.GetName())) { INode basetype; bool constness, pointer; bool arraytype = false; string size = ""; string types = child.ResolveType(0, out basetype, out constness, out pointer); if (basetype is ArrayTypeNode) { size = basetype.GetAttribute("size"); types = basetype.ResolveType(1, out basetype, out constness, out pointer); arraytype = true; } types = generator.ResolveType(types, constness, pointer, true, false); if (types == "CSteamID") { types = "SteamID_t"; } else if (types == "CGameID") { types = "GameID_t"; } if (arraytype) { if (types == "SByte") { types = "string"; } else { types += "[]"; } } if (types == "bool") { generator.EmitLine("[MarshalAs(UnmanagedType.I1)]", depth + 1); } else if (types == "string") { if (arraytype) { generator.EmitLine("[MarshalAs(UnmanagedType.ByValTStr, SizeConst = " + size + ")]", depth + 1); } else { types = "string"; } } else if (types == "Byte[]") { if (arraytype) { generator.EmitLine("[MarshalAs(UnmanagedType.ByValArray, SizeConst = " + size + ")]", depth + 1); } else { types = "IntPtr"; } } else if (pointer) { types = "IntPtr"; } else if (arraytype) { generator.EmitLine("[MarshalAs(UnmanagedType.ByValArray, SizeConst = " + size + ")]", depth + 1); } else if (types == child.GetName()) { continue; } generator.EmitLine(String.Format("public {0} {1};", types, child.GetName()), depth + 1); } else if (child is EnumNode) { // anonymous enum declaration EnumNode innerEnum = child as EnumNode; int callback = innerEnum.EmitCodeInnerStructCallback(generator, depth + 1); if (callback > 0) { generator.InsertLine("[CallbackIdentity(" + callback + ")]", attribMarker, depth); } } else if (child is FieldNode) { // anonymous field like union // not implemented! } } generator.EmitLine("};", depth); generator.EmitLine("", depth); }