string GetInterfaceImplExtra() { if (Elem.HasAttribute("iequatable") && Elem.GetAttribute("iequatable") == "1") { return(" : IEquatable<" + Name + ">"); } return(string.Empty); }
protected new void GenEqualsAndHash(StreamWriter sw) { int bitfields = 0; bool need_field = true; StringBuilder sb = new StringBuilder(); sw.WriteLine("\t\tpublic bool Equals ({0} other)", Name); sw.WriteLine("\t\t{"); foreach (StructField field in fields) { if (field.IsBitfield) { if (need_field) { sw.WriteLine("\t\tif (!_bitfield{0}.Equals (other._bitfield{0})) return false;", bitfields); if (sb.Length > 0) { sb.Append(" ^ "); } sb.Append("_bitfield"); sb.Append(bitfields++); sb.Append(".GetHashCode ()"); need_field = false; } } else { need_field = true; sw.WriteLine("\t\t\tif (!{0}.Equals (other.{0})) return false;", field.EqualityName); if (sb.Length > 0) { sb.Append(" ^ "); } sb.Append(field.EqualityName); sb.Append(".GetHashCode ()"); } } sw.WriteLine("\t\t\treturn true;"); sw.WriteLine("\t\t}"); sw.WriteLine(); sw.WriteLine("\t\tpublic override bool Equals (object other)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\treturn other is {0} && Equals (({0}) other);", Name); sw.WriteLine("\t\t}"); sw.WriteLine(); if (Elem.GetAttribute("nohash") == "true") { return; } sw.WriteLine("\t\tpublic override int GetHashCode ()"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\treturn {0};", sb.ToString()); sw.WriteLine("\t\t}"); sw.WriteLine(); }
public override void Generate(GenerationInfo gen_info) { StreamWriter sw = gen_info.OpenStream(Name, NS); sw.WriteLine("namespace " + NS + " {"); sw.WriteLine(); sw.WriteLine("\tusing System;"); sw.WriteLine("\tusing System.Runtime.InteropServices;"); sw.WriteLine(); sw.WriteLine("#region Autogenerated code"); if (Elem.GetAttribute("type") == "flags") { sw.WriteLine("\t[Flags]"); } if (Elem.HasAttribute("gtype")) { sw.WriteLine("\t[GLib.GType (typeof (" + NS + "." + Name + "GType))]"); } string access = IsInternal ? "internal" : "public"; sw.WriteLine("\t" + access + " enum " + Name + enum_type + " {"); sw.WriteLine(); foreach (string member in members) { sw.WriteLine(member); } sw.WriteLine("\t}"); if (Elem.HasAttribute("gtype")) { sw.WriteLine(); sw.WriteLine("\tinternal class " + Name + "GType {"); var funcname = Elem.GetAttribute("gtype"); sw.WriteLine("\t\tdelegate IntPtr d_" + funcname + "();"); sw.WriteLine("\t\tstatic d_" + funcname + " " + funcname + " = FuncLoader.LoadFunction<d_" + funcname + ">(FuncLoader.GetProcAddress(GLibrary.Load(\"" + LibraryName + "\"), \"" + funcname + "\"));"); sw.WriteLine(); sw.WriteLine("\t\tpublic static GLib.GType GType {"); sw.WriteLine("\t\t\tget {"); sw.WriteLine("\t\t\t\treturn new GLib.GType (" + Elem.GetAttribute("gtype") + " ());"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine("\t}"); } sw.WriteLine("#endregion"); sw.WriteLine("}"); sw.Close(); Statistics.EnumCount++; }
public override void Generate(GenerationInfo gen_info) { StreamWriter sw = gen_info.OpenStream(Name, NS); sw.WriteLine("namespace " + NS + " {"); sw.WriteLine(); sw.WriteLine("\tusing System;"); sw.WriteLine("\tusing System.Runtime.InteropServices;"); sw.WriteLine(); sw.WriteLine("#region Autogenerated code"); if (Elem.GetAttribute("type") == "flags") { sw.WriteLine("\t[Flags]"); } if (Elem.HasAttribute("gtype")) { sw.WriteLine("\t[GLib.GType (typeof (" + NS + "." + Name + "GType))]"); } string access = IsInternal ? "internal" : "public"; sw.WriteLine("\t" + access + " enum " + Name + enum_type + " {"); sw.WriteLine(); foreach (string member in members) { sw.WriteLine(member); } sw.WriteLine("\t}"); if (Elem.HasAttribute("gtype")) { sw.WriteLine(); sw.WriteLine("\tinternal class " + Name + "GType {"); sw.WriteLine("\t\t[DllImport (\"" + LibraryName + "\", CallingConvention = CallingConvention.Cdecl)]"); sw.WriteLine("\t\tstatic extern IntPtr " + Elem.GetAttribute("gtype") + " ();"); sw.WriteLine(); sw.WriteLine("\t\tpublic static GLib.GType GType {"); sw.WriteLine("\t\t\tget {"); sw.WriteLine("\t\t\t\treturn new GLib.GType (" + Elem.GetAttribute("gtype") + " ());"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine("\t}"); } sw.WriteLine("#endregion"); sw.WriteLine("}"); sw.Close(); Statistics.EnumCount++; }
bool CheckABIStructParent(LogWriter log, out string cs_parent_struct) { cs_parent_struct = null; if (!CanGenerateABIStruct(log)) { return(false); } var parent = SymbolTable.Table[Elem.GetAttribute("parent")]; string cs_parent = SymbolTable.Table.GetCSType(Elem.GetAttribute("parent")); var parent_can_generate = true; cs_parent_struct = null; if (parent != null) { // FIXME Add that information to ManualGen and use it. if (parent.CName == "GInitiallyUnowned" || parent.CName == "GObject") { cs_parent_struct = "GLib.Object"; } else { parent_can_generate = false; var _parent = parent as ClassBase; if (_parent != null) { string tmp; parent_can_generate = _parent.CheckABIStructParent(log, out tmp); } if (parent_can_generate) { cs_parent_struct = cs_parent; } } if (!parent_can_generate) { log.Warn("Can't generate ABI structrure as the parent structure '" + parent.CName + "' can't be generated."); return(false); } } else { cs_parent_struct = ""; } return(parent_can_generate); }
protected void GenEqualsAndHash(StreamWriter sw) { StringBuilder hashcode = new StringBuilder(); StringBuilder equals = new StringBuilder(); sw.WriteLine("\t\tpublic bool Equals ({0} other)", Name); sw.WriteLine("\t\t{"); hashcode.Append("this.GetType().FullName.GetHashCode()"); equals.Append("true"); foreach (StructField field in fields) { if (field.IsPadding || !field.Visible || field.IsBitfield) { continue; } equals.Append(" && "); equals.Append(field.EqualityName); equals.Append(".Equals (other."); equals.Append(field.EqualityName); equals.Append(")"); hashcode.Append(" ^ "); hashcode.Append(field.EqualityName); hashcode.Append(".GetHashCode ()"); } sw.WriteLine("\t\t\treturn {0};", equals.ToString()); sw.WriteLine("\t\t}"); sw.WriteLine(); sw.WriteLine("\t\tpublic override bool Equals (object other)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\treturn other is {0} && Equals (({0}) other);", Name); sw.WriteLine("\t\t}"); sw.WriteLine(); if (Elem.GetAttribute("nohash") == "true") { return; } sw.WriteLine("\t\tpublic override int GetHashCode ()"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\treturn {0};", hashcode.ToString()); sw.WriteLine("\t\t}"); sw.WriteLine(); }
public override void Generate(GenerationInfo gen_info) { StreamWriter sw = gen_info.OpenStream(Name); sw.WriteLine("namespace " + NS + " {"); sw.WriteLine(); sw.WriteLine("\tusing System;"); sw.WriteLine("\tusing System.Runtime.InteropServices;"); sw.WriteLine(); sw.WriteLine("#region Autogenerated code"); if (Elem.GetAttribute("type") == "flags") { sw.WriteLine("\t[Flags]"); } if (Elem.HasAttribute("gtype")) { sw.WriteLine("\t[{0}]", Name); } string access = IsInternal ? "internal" : "public"; sw.WriteLine("\t" + access + " enum " + Name + enum_type + " {"); sw.WriteLine(); foreach (string member in members) { sw.WriteLine(member); } sw.WriteLine("\t}"); if (Elem.HasAttribute("gtype")) { AttributeHelper.Gen(sw, Name, LibraryName, Elem.GetAttribute("gtype")); } sw.WriteLine("#endregion"); sw.WriteLine("}"); sw.Close(); Statistics.EnumCount++; }
public override void Generate(GenerationInfo gen_info) { gen_info.CurrentType = QualifiedName; StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name, NS); sw.WriteLine("namespace " + NS + " {"); sw.WriteLine(); sw.WriteLine("\tusing System;"); sw.WriteLine("\tusing System.Collections;"); sw.WriteLine("\tusing System.Collections.Generic;"); sw.WriteLine("\tusing System.Runtime.InteropServices;"); sw.WriteLine(); sw.WriteLine("#region Autogenerated code"); SymbolTable table = SymbolTable.Table; Method ref_, unref, dispose, set_gvalue; GetSpecialMethods(out ref_, out unref, out dispose, out set_gvalue); if (IsDeprecated) { sw.WriteLine("\t[Obsolete]"); } sw.Write("\t{0} partial {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : String.Empty); string cs_parent = table.GetCSType(Elem.GetAttribute("parent")); if (cs_parent != "") { sw.Write(" : " + cs_parent); } else { sw.Write(" : GLib.Opaque"); } foreach (string iface in managed_interfaces) { if (Parent != null && Parent.Implements(iface)) { continue; } sw.Write(", " + iface); } sw.WriteLine(" {"); sw.WriteLine(); GenConstants(gen_info); GenFields(gen_info); GenMethods(gen_info, null, null); GenCtors(gen_info); if (ref_ != null) { ref_.GenerateImport(sw); sw.WriteLine("\t\tprotected override void Ref (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tif (!Owned) {"); sw.WriteLine("\t\t\t\t" + ref_.CName + " (raw);"); sw.WriteLine("\t\t\t\tOwned = true;"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(); if (ref_.IsDeprecated) { sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]"); if (ref_.ReturnType == "void") { sw.WriteLine("\t\tpublic void Ref () {}"); } else { sw.WriteLine("\t\tpublic " + Name + " Ref () { return this; }"); } sw.WriteLine(); } } bool finalizer_needed = false; if (unref != null) { unref.GenerateImport(sw); sw.WriteLine("\t\tprotected override void Unref (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tif (Owned) {"); sw.WriteLine("\t\t\t\t" + unref.CName + " (raw);"); sw.WriteLine("\t\t\t\tOwned = false;"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(); if (unref.IsDeprecated) { sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]"); sw.WriteLine("\t\tpublic void Unref () {}"); sw.WriteLine(); } finalizer_needed = true; } if (dispose != null) { dispose.GenerateImport(sw); sw.WriteLine("\t\tprotected override void Free (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\t" + dispose.CName + " (raw);"); sw.WriteLine("\t\t}"); sw.WriteLine(); if (dispose.IsDeprecated) { sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now freed automatically\")]"); sw.WriteLine("\t\tpublic void " + dispose.Name + " () {}"); sw.WriteLine(); } finalizer_needed = true; } if (finalizer_needed) { sw.WriteLine("\t\tclass FinalizerInfo {"); sw.WriteLine("\t\t\tIntPtr handle;"); sw.WriteLine(); sw.WriteLine("\t\t\tpublic FinalizerInfo (IntPtr handle)"); sw.WriteLine("\t\t\t{"); sw.WriteLine("\t\t\t\tthis.handle = handle;"); sw.WriteLine("\t\t\t}"); sw.WriteLine(); sw.WriteLine("\t\t\tpublic bool Handler ()"); sw.WriteLine("\t\t\t{"); if (dispose != null) { sw.WriteLine("\t\t\t\t{0} (handle);", dispose.CName); } else if (unref != null) { sw.WriteLine("\t\t\t\t{0} (handle);", unref.CName); } sw.WriteLine("\t\t\t\treturn false;"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(); sw.WriteLine("\t\t~{0} ()", Name); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tif (!Owned)"); sw.WriteLine("\t\t\t\treturn;"); sw.WriteLine("\t\t\tFinalizerInfo info = new FinalizerInfo (Handle);"); sw.WriteLine("\t\t\tGLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));"); sw.WriteLine("\t\t}"); sw.WriteLine(); } #if false Method copy = Methods ["Copy"] as Method; if (copy != null && copy.Parameters.Count == 0) { sw.WriteLine("\t\tprotected override GLib.Opaque Copy (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tGLib.Opaque result = new " + QualifiedName + " (" + copy.CName + " (raw));"); sw.WriteLine("\t\t\tresult.Owned = true;"); sw.WriteLine("\t\t\treturn result;"); sw.WriteLine("\t\t}"); sw.WriteLine(); } #endif if (set_gvalue != null) { sw.WriteLine("\t\tdelegate IntPtr d_{0}(ref GLib.Value val, IntPtr obj);", set_gvalue.CName); sw.WriteLine("\t\tstatic d_{0} {0} = FuncLoader.LoadFunction<d_{0}>(FuncLoader.GetProcAddress(GLibrary.Load(\"{1}\"), \"{0}\"));", set_gvalue.CName, LibraryName); sw.WriteLine(); sw.WriteLine("\t\tpublic void SetGValue (ref GLib.Value val)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\t{0} (ref val, Handle);", set_gvalue.CName); sw.WriteLine("\t\t}"); sw.WriteLine(); } GenerateStructureABI(gen_info); sw.WriteLine("#endregion"); sw.WriteLine("\t}"); sw.WriteLine("}"); sw.Close(); gen_info.Writer = null; Statistics.OpaqueCount++; }
public override void Generate(GenerationInfo gen_info) { gen_info.CurrentType = Name; string asm_name = gen_info.AssemblyName.Length == 0 ? NS.ToLower() + "-sharp" : gen_info.AssemblyName; DirectoryInfo di = GetDirectoryInfo(gen_info.Dir, asm_name); StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name); sw.WriteLine("namespace " + NS + " {"); sw.WriteLine(); sw.WriteLine("\tusing System;"); sw.WriteLine("\tusing System.Collections;"); sw.WriteLine("\tusing System.Runtime.InteropServices;"); sw.WriteLine(); SymbolTable table = SymbolTable.Table; sw.WriteLine("#region Autogenerated code"); if (IsDeprecated) { sw.WriteLine("\t[Obsolete]"); } foreach (string attr in custom_attrs) { sw.WriteLine("\t" + attr); } sw.Write("\t{0} {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : ""); string cs_parent = table.GetCSType(Elem.GetAttribute("parent")); if (cs_parent != "") { di.objects.Add(CName, QualifiedName); sw.Write(" : " + cs_parent); } foreach (string iface in interfaces) { if (Parent != null && Parent.Implements(iface)) { continue; } sw.Write(", " + table.GetCSType(iface)); } foreach (string iface in managed_interfaces) { if (Parent != null && Parent.Implements(iface)) { continue; } sw.Write(", " + iface); } sw.WriteLine(" {"); sw.WriteLine(); GenCtors(gen_info); GenProperties(gen_info, null); GenFields(gen_info); GenChildProperties(gen_info); bool has_sigs = (sigs != null && sigs.Count > 0); if (!has_sigs) { foreach (string iface in interfaces) { ClassBase igen = table.GetClassGen(iface); if (igen != null && igen.Signals != null) { has_sigs = true; break; } } } if (has_sigs && Elem.HasAttribute("parent")) { GenSignals(gen_info, null); } if (vm_nodes.Count > 0) { if (gen_info.GlueEnabled) { GenVirtualMethods(gen_info); } else { Statistics.VMIgnored = true; Statistics.ThrottledCount += vm_nodes.Count; } } GenMethods(gen_info, null, null); if (interfaces.Count != 0) { Hashtable all_methods = new Hashtable(); foreach (Method m in Methods.Values) { all_methods[m.Name] = m; } Hashtable collisions = new Hashtable(); foreach (string iface in interfaces) { ClassBase igen = table.GetClassGen(iface); foreach (Method m in igen.Methods.Values) { Method collision = all_methods[m.Name] as Method; if (collision != null && collision.Signature.Types == m.Signature.Types) { collisions[m.Name] = true; } else { all_methods[m.Name] = m; } } } foreach (string iface in interfaces) { if (Parent != null && Parent.Implements(iface)) { continue; } ClassBase igen = table.GetClassGen(iface); igen.GenMethods(gen_info, collisions, this); igen.GenProperties(gen_info, this); igen.GenSignals(gen_info, this); } } foreach (XmlElement str in strings) { sw.Write("\t\tpublic static string " + str.GetAttribute("name")); sw.WriteLine(" {\n\t\t\t get { return \"" + str.GetAttribute("value") + "\"; }\n\t\t}"); } if (cs_parent != String.Empty && GetExpected(CName) != QualifiedName) { sw.WriteLine(); sw.WriteLine("\t\tstatic " + Name + " ()"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tGtkSharp." + Studlify(asm_name) + ".ObjectManager.Initialize ();"); sw.WriteLine("\t\t}"); } sw.WriteLine("#endregion"); AppendCustom(sw, gen_info.CustomDir); sw.WriteLine("\t}"); sw.WriteLine("}"); sw.Close(); gen_info.Writer = null; Statistics.ObjectCount++; }
public override void Generate(GenerationInfo gen_info) { gen_info.CurrentType = Name; StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name); sw.WriteLine("namespace " + NS + " {"); sw.WriteLine(); sw.WriteLine("\tusing System;"); sw.WriteLine("\tusing System.Collections;"); sw.WriteLine("\tusing System.Runtime.InteropServices;"); sw.WriteLine(); sw.WriteLine("#region Autogenerated code"); SymbolTable table = SymbolTable.Table; Method ref_, unref, dispose; GetSpecialMethods(out ref_, out unref, out dispose); if (IsDeprecated) { sw.WriteLine("\t[Obsolete]"); } GenerateAttribute(sw); sw.Write("\t{0} class " + Name, IsInternal ? "internal" : "public"); string cs_parent = table.GetCSType(Elem.GetAttribute("parent")); if (cs_parent != "") { sw.Write(" : " + cs_parent); } else { sw.Write(" : GLib.Opaque"); } sw.WriteLine(" {"); sw.WriteLine(); GenFields(gen_info); GenMethods(gen_info, null, null); GenCtors(gen_info); if (ref_ != null) { ref_.GenerateImport(sw); sw.WriteLine("\t\tprotected override void Ref (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tif (!Owned) {"); sw.WriteLine("\t\t\t\t" + ref_.CName + " (raw);"); sw.WriteLine("\t\t\t\tOwned = true;"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(); if (ref_.IsDeprecated) { sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]"); if (ref_.ReturnType == "void") { sw.WriteLine("\t\tpublic void Ref () {}"); } else { sw.WriteLine("\t\tpublic " + Name + " Ref () { return this; }"); } sw.WriteLine(); } } if (unref != null) { unref.GenerateImport(sw); sw.WriteLine("\t\tprotected override void Unref (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tif (Owned) {"); sw.WriteLine("\t\t\t\t" + unref.CName + " (raw);"); sw.WriteLine("\t\t\t\tOwned = false;"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(); if (unref.IsDeprecated) { sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]"); sw.WriteLine("\t\tpublic void Unref () {}"); sw.WriteLine(); } } if (dispose != null) { dispose.GenerateImport(sw); sw.WriteLine("\t\tprotected override void Free (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\t" + dispose.CName + " (raw);"); sw.WriteLine("\t\t}"); sw.WriteLine(); if (dispose.IsDeprecated) { sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now freed automatically\")]"); sw.WriteLine("\t\tpublic void " + dispose.Name + " () {}"); sw.WriteLine(); } } #if false Method copy = Methods ["Copy"] as Method; if (copy != null && copy.Parameters.Count == 0) { sw.WriteLine("\t\tprotected override GLib.Opaque Copy (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tGLib.Opaque result = new " + QualifiedName + " (" + copy.CName + " (raw));"); sw.WriteLine("\t\t\tresult.Owned = true;"); sw.WriteLine("\t\t\treturn result;"); sw.WriteLine("\t\t}"); sw.WriteLine(); } #endif sw.WriteLine("#endregion"); AppendCustom(sw, gen_info.CustomDir); sw.WriteLine("\t}"); var parentGType = GetParentWithGType(this); if (parentGType == this) { var method = parentGType.GetMethod("GetType") ?? parentGType.GetMethod("GetGType"); AttributeHelper.Gen(sw, Name, LibraryName, method.CName); } sw.WriteLine("}"); sw.Close(); gen_info.Writer = null; Statistics.OpaqueCount++; }
protected override void GenCtors(GenerationInfo gen_info) { if (!Elem.HasAttribute("parent")) { return; } string defaultconstructoraccess = Elem.HasAttribute("defaultconstructoraccess") ? Elem.GetAttribute("defaultconstructoraccess") : "public"; gen_info.Writer.WriteLine("\t\t" + defaultconstructoraccess + " " + Name + " (IntPtr raw) : base(raw) {}"); if (ctors.Count == 0 && !DisableVoidCtor) { gen_info.Writer.WriteLine(); gen_info.Writer.WriteLine("\t\tprotected " + Name + "() : base(IntPtr.Zero)"); gen_info.Writer.WriteLine("\t\t{"); gen_info.Writer.WriteLine("\t\t\tCreateNativeObject (new string [0], new GLib.Value [0]);"); gen_info.Writer.WriteLine("\t\t}"); } gen_info.Writer.WriteLine(); base.GenCtors(gen_info); }
public override void Generate(GenerationInfo gen_info) { gen_info.CurrentType = QualifiedName; string asm_name = gen_info.AssemblyName.Length == 0 ? NS.ToLower() + "-sharp" : gen_info.AssemblyName; DirectoryInfo di = GetDirectoryInfo(gen_info.Dir, asm_name); StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name, NS); sw.WriteLine("namespace " + NS + " {"); sw.WriteLine(); sw.WriteLine("\tusing System;"); sw.WriteLine("\tusing System.Collections;"); sw.WriteLine("\tusing System.Collections.Generic;"); sw.WriteLine("\tusing System.Runtime.InteropServices;"); sw.WriteLine(); SymbolTable table = SymbolTable.Table; sw.WriteLine("#region Autogenerated code"); if (IsDeprecated) { sw.WriteLine("\t[Obsolete]"); } foreach (string attr in customAttrs) { sw.WriteLine("\t" + attr); } sw.Write("\t{0} {1}partial class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : ""); string csParent = table.GetCSType(Elem.GetAttribute("parent")); if (!string.IsNullOrEmpty(csParent)) { di.objects.Add(CName, QualifiedName); sw.Write(" : " + csParent); } foreach (string iface in interfaces) { if (Parent != null && Parent.Implements(iface)) { continue; } sw.Write(", " + table.GetCSType(iface)); } foreach (string iface in managed_interfaces) { if (Parent != null && Parent.Implements(iface)) { continue; } sw.Write(", " + iface); } sw.WriteLine(" {"); sw.WriteLine(); GenCtors(gen_info); GenProperties(gen_info, null); GenFields(gen_info); GenChildProperties(gen_info); bool has_sigs = (sigs != null && sigs.Count > 0); if (!has_sigs) { foreach (string iface in interfaces) { if (table.GetClassGen(iface) is InterfaceGen iGen && iGen.Signals != null) { has_sigs = true; break; } } } if (has_sigs && Elem.HasAttribute("parent")) { GenSignals(gen_info, null); } GenConstants(gen_info); GenClassMembers(gen_info, csParent); GenMethods(gen_info, null, null); if (interfaces.Count != 0) { var all_methods = new Dictionary <string, Method> (); foreach (Method m in Methods.Values) { all_methods[m.Name] = m; } var collisions = new Dictionary <string, bool> (); foreach (string iface in interfaces) { ClassBase igen = table.GetClassGen(iface); foreach (Method m in igen.Methods.Values) { if (m.Name.StartsWith("Get") || m.Name.StartsWith("Set")) { if (GetProperty(m.Name.Substring(3)) != null) { collisions[m.Name] = true; continue; } } all_methods.TryGetValue(m.Name, out Method collision); if (collision != null && collision.Signature.Types == m.Signature.Types) { collisions[m.Name] = true; } else { all_methods[m.Name] = m; } } } foreach (string iface in interfaces) { if (Parent != null && Parent.Implements(iface)) { continue; } InterfaceGen igen = table.GetClassGen(iface) as InterfaceGen; igen.GenMethods(gen_info, collisions, this); igen.GenProperties(gen_info, this); igen.GenSignals(gen_info, this); igen.GenVirtualMethods(gen_info, this); } } foreach (XmlElement str in strings) { sw.Write("\t\tpublic static string " + str.GetAttribute("name")); sw.WriteLine(" {\n\t\t\t get { return \"" + str.GetAttribute("value") + "\"; }\n\t\t}"); } if (!string.IsNullOrEmpty(csParent) && GetExpected(CName) != QualifiedName) { sw.WriteLine(); sw.WriteLine("\t\tstatic " + Name + " ()"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tGtkSharp." + Studlify(asm_name) + ".ObjectManager.Initialize ();"); sw.WriteLine("\t\t}"); } GenerateStructureABI(gen_info); sw.WriteLine("#endregion"); sw.WriteLine("\t}"); sw.WriteLine("}"); sw.Close(); gen_info.Writer = null; Statistics.ObjectCount++; }
public override void Generate(GenerationInfo gen_info) { gen_info.CurrentType = QualifiedName; StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name, NS); sw.WriteLine("namespace " + NS + " {"); sw.WriteLine(); sw.WriteLine("\tusing System;"); sw.WriteLine("\tusing System.Collections;"); sw.WriteLine("\tusing System.Collections.Generic;"); sw.WriteLine("\tusing System.Runtime.InteropServices;"); sw.WriteLine(); sw.WriteLine("#region Autogenerated code"); SymbolTable table = SymbolTable.Table; Method ref_, unref, dispose, set_gvalue; GetSpecialMethods(out ref_, out unref, out dispose, out set_gvalue); if (IsDeprecated) { sw.WriteLine("\t[Obsolete]"); } sw.Write("\t{0} partial {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : String.Empty); string cs_parent = table.GetCSType(Elem.GetAttribute("parent")); if (cs_parent != "") { sw.Write(" : " + cs_parent); } else { sw.Write(" : GLib.Opaque"); } foreach (string iface in managed_interfaces) { if (Parent != null && Parent.Implements(iface)) { continue; } sw.Write(", " + iface); } sw.WriteLine(" {"); sw.WriteLine(); GenConstants(gen_info); GenFields(gen_info); GenMethods(gen_info, null, null); GenCtors(gen_info); if (ref_ != null) { ref_.GenerateImport(sw); sw.WriteLine("\t\tprotected override void Ref (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tif (!Owned) {"); sw.WriteLine("\t\t\t\t" + ref_.CName + " (raw);"); sw.WriteLine("\t\t\t\tOwned = true;"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(); if (ref_.IsDeprecated) { sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]"); if (ref_.ReturnType == "void") { sw.WriteLine("\t\tpublic void Ref () {}"); } else { sw.WriteLine("\t\tpublic " + Name + " Ref () { return this; }"); } sw.WriteLine(); } } // GtkWidgetPath has both gtk_widget_path_unref and gtk_widget_path_free // If this happens add only one and prefer unref over free bool disposeUnmanagedFuncAdded = false; if (unref != null) { unref.GenerateImport(sw); sw.WriteLine("\t\tprotected override void Unref (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tif (Owned) {"); sw.WriteLine("\t\t\t\t" + unref.CName + " (raw);"); sw.WriteLine("\t\t\t\tOwned = false;"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(); sw.WriteLine("\t\tprotected override Action<IntPtr> DisposeUnmanagedFunc {"); sw.WriteLine("\t\t\tget {"); sw.WriteLine("\t\t\t\treturn " + unref.CName + ";"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(); disposeUnmanagedFuncAdded = true; if (unref.IsDeprecated) { sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]"); sw.WriteLine("\t\tpublic void Unref () {}"); sw.WriteLine(); } } if (dispose != null) { dispose.GenerateImport(sw); sw.WriteLine("\t\tprotected override void Free (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\t" + dispose.CName + " (raw);"); sw.WriteLine("\t\t}"); sw.WriteLine(); if (!disposeUnmanagedFuncAdded) { sw.WriteLine("\t\tprotected override Action<IntPtr> DisposeUnmanagedFunc {"); sw.WriteLine("\t\t\tget {"); sw.WriteLine("\t\t\t\treturn " + dispose.CName + ";"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(); } if (dispose.IsDeprecated) { sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now freed automatically\")]"); sw.WriteLine("\t\tpublic void " + dispose.Name + " () {}"); sw.WriteLine(); } } #if false Method copy = Methods ["Copy"] as Method; if (copy != null && copy.Parameters.Count == 0) { sw.WriteLine("\t\tprotected override GLib.Opaque Copy (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tGLib.Opaque result = new " + QualifiedName + " (" + copy.CName + " (raw));"); sw.WriteLine("\t\t\tresult.Owned = true;"); sw.WriteLine("\t\t\treturn result;"); sw.WriteLine("\t\t}"); sw.WriteLine(); } #endif if (set_gvalue != null) { sw.WriteLine("\t\t[DllImport(\"{0}\", CallingConvention = CallingConvention.Cdecl)]", LibraryName); sw.WriteLine("\t\tstatic extern void {0}(ref GLib.Value val, IntPtr obj);", set_gvalue.CName); sw.WriteLine(); sw.WriteLine("\t\tpublic void SetGValue (ref GLib.Value val)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\t{0} (ref val, Handle);", set_gvalue.CName); sw.WriteLine("\t\t}"); sw.WriteLine(); } GenerateStructureABI(gen_info); sw.WriteLine("#endregion"); sw.WriteLine("\t}"); sw.WriteLine("}"); sw.Close(); gen_info.Writer = null; Statistics.OpaqueCount++; }
protected ClassBase(XmlElement ns, XmlElement elem) : base(ns, elem) { deprecated = elem.GetAttributeAsBoolean("deprecated"); isabstract = elem.GetAttributeAsBoolean("abstract"); abi_fields_valid = true; string parent_type = Elem.GetAttribute("parent"); int num_abi_fields = 0; foreach (XmlNode node in elem.ChildNodes) { if (!(node is XmlElement)) { continue; } XmlElement member = (XmlElement)node; StructABIField abi_field = null; // Make sure ABI fields are taken into account, even when hidden. if (node.Name == "field") { num_abi_fields += 1; // Skip instance parent struct if present, taking into account // bindinator broken behaviour concerning parent field (ie. // marking it as pointer, somehow risky but good enough for now.) if (num_abi_fields != 1 || parent_type == "" || (member.GetAttribute("type").Replace("*", "") != parent_type )) { abi_field = new StructABIField(member, this, "abi_info"); abi_fields.Add(abi_field); } } else if (node.Name == "union") { abi_field = new UnionABIField(member, this, "abi_info"); abi_fields.Add(abi_field); } if (member.GetAttributeAsBoolean("hidden")) { continue; } string name; switch (node.Name) { case "method": name = member.GetAttribute("name"); while (methods.ContainsKey(name)) { name += "mangled"; } methods.Add(name, new Method(member, this)); break; case "property": name = member.GetAttribute("name"); while (props.ContainsKey(name)) { name += "mangled"; } props.Add(name, new Property(member, this)); break; case "field": // FIXME Generate callbacks. if (member.GetAttributeAsBoolean("is_callback")) { continue; } name = member.GetAttribute("name"); while (fields.ContainsKey(name)) { name += "mangled"; } var field = new ObjectField(member, this); field.abi_field = abi_field; fields.Add(name, field); break; case "implements": ParseImplements(member); break; case "constructor": ctors.Add(new Ctor(member, this)); break; case "constant": name = member.GetAttribute("name"); constants.Add(name, new Constant(member)); break; default: break; } } }
public override void Generate(GenerationInfo gen_info) { gen_info.CurrentType = Name; string asm_name = gen_info.AssemblyName.Length == 0 ? NS.ToLower() + "-sharp" : gen_info.AssemblyName; DirectoryInfo di = GetDirectoryInfo(gen_info.Dir, asm_name); StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name); sw.WriteLine("namespace " + NS + " {"); sw.WriteLine(); sw.WriteLine("\tusing System;"); sw.WriteLine("\tusing System.Collections;"); sw.WriteLine("\tusing System.Runtime.InteropServices;"); sw.WriteLine(); SymbolTable table = SymbolTable.Table; sw.WriteLine("#region Autogenerated code"); if (IsDeprecated) { sw.WriteLine("\t[Obsolete]"); } foreach (string attr in custom_attrs) { sw.WriteLine("\t" + attr); } sw.Write("\t{0} {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : ""); string cs_parent = table.GetCSType(Elem.GetAttribute("parent")); if (cs_parent != "") { di.objects.Add(CName, QualifiedName); sw.Write(" : " + cs_parent); } foreach (string iface in managed_interfaces) { if (Parent != null && Parent.Implements(iface)) { continue; } sw.Write(", " + iface); } sw.WriteLine(" {"); sw.WriteLine(); GenCtors(gen_info); GenFields(gen_info); GenClassMembers(gen_info, cs_parent); GenMethods(gen_info, null, null); foreach (XmlElement str in strings) { sw.Write("\t\tpublic static string " + str.GetAttribute("name")); sw.WriteLine(" {\n\t\t\t get { return \"" + str.GetAttribute("value") + "\"; }\n\t\t}"); } if (cs_parent != String.Empty && GetExpected(CName) != QualifiedName) { sw.WriteLine(); sw.WriteLine("\t\tstatic " + Name + " ()"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tGtkSharp." + Studlify(asm_name) + ".ObjectManager.Initialize ();"); sw.WriteLine("\t\t}"); } sw.WriteLine("#endregion"); AppendCustom(sw, gen_info.CustomDir); sw.WriteLine("\t}"); sw.WriteLine("}"); sw.Close(); gen_info.Writer = null; Statistics.ObjectCount++; }
public override void Generate(GenerationInfo gen_info) { gen_info.CurrentType = Name; StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name); sw.WriteLine("namespace " + NS + " {"); sw.WriteLine(); sw.WriteLine("\tusing System;"); sw.WriteLine("\tusing System.Collections;"); sw.WriteLine("\tusing System.Runtime.InteropServices;"); sw.WriteLine(); sw.WriteLine("#region Autogenerated code"); SymbolTable table = SymbolTable.Table; Method ref_, unref, dispose; GetSpecialMethods(out ref_, out unref, out dispose); if (IsDeprecated) { sw.WriteLine("\t[Obsolete]"); } sw.Write("\t{0} class " + Name, IsInternal ? "internal" : "public"); string cs_parent = table.GetCSType(Elem.GetAttribute("parent")); if (cs_parent != "") { sw.Write(" : " + cs_parent); } else { sw.Write(" : GLib.Opaque"); } sw.WriteLine(" {"); sw.WriteLine(); GenFields(gen_info); GenMethods(gen_info, null, null); GenCtors(gen_info); if (ref_ != null) { ref_.GenerateImport(sw); sw.WriteLine("\t\tprotected override void Ref (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tif (!Owned) {"); sw.WriteLine("\t\t\t\t" + ref_.CName + " (raw);"); sw.WriteLine("\t\t\t\tOwned = true;"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(); if (ref_.IsDeprecated) { sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]"); if (ref_.ReturnType == "void") { sw.WriteLine("\t\tpublic void Ref () {}"); } else { sw.WriteLine("\t\tpublic " + Name + " Ref () { return this; }"); } sw.WriteLine(); } } bool finalizer_needed = false; if (unref != null) { unref.GenerateImport(sw); sw.WriteLine("\t\tprotected override void Unref (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tif (Owned) {"); sw.WriteLine("\t\t\t\t" + unref.CName + " (raw);"); sw.WriteLine("\t\t\t\tOwned = false;"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(); if (unref.IsDeprecated) { sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]"); sw.WriteLine("\t\tpublic void Unref () {}"); sw.WriteLine(); } finalizer_needed = true; } if (dispose != null) { dispose.GenerateImport(sw); sw.WriteLine("\t\tprotected override void Free (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\t" + dispose.CName + " (raw);"); sw.WriteLine("\t\t}"); sw.WriteLine(); if (dispose.IsDeprecated) { sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now freed automatically\")]"); sw.WriteLine("\t\tpublic void " + dispose.Name + " () {}"); sw.WriteLine(); } finalizer_needed = true; } if (finalizer_needed) { sw.WriteLine("\t\tclass FinalizerInfo {"); sw.WriteLine("\t\t\tIntPtr handle;"); sw.WriteLine(); sw.WriteLine("\t\t\tpublic FinalizerInfo (IntPtr handle)"); sw.WriteLine("\t\t\t{"); sw.WriteLine("\t\t\t\tthis.handle = handle;"); sw.WriteLine("\t\t\t}"); sw.WriteLine(); sw.WriteLine("\t\t\tpublic bool Handler ()"); sw.WriteLine("\t\t\t{"); if (dispose != null) { sw.WriteLine("\t\t\t\t{0} (handle);", dispose.CName); } else if (unref != null) { sw.WriteLine("\t\t\t\t{0} (handle);", unref.CName); } sw.WriteLine("\t\t\t\treturn false;"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(); sw.WriteLine("\t\t~{0} ()", Name); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tif (!Owned)"); sw.WriteLine("\t\t\t\treturn;"); sw.WriteLine("\t\t\tFinalizerInfo info = new FinalizerInfo (Handle);"); sw.WriteLine("\t\t\tGLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));"); sw.WriteLine("\t\t}"); sw.WriteLine(); } #if false Method copy = Methods ["Copy"] as Method; if (copy != null && copy.Parameters.Count == 0) { sw.WriteLine("\t\tprotected override GLib.Opaque Copy (IntPtr raw)"); sw.WriteLine("\t\t{"); sw.WriteLine("\t\t\tGLib.Opaque result = new " + QualifiedName + " (" + copy.CName + " (raw));"); sw.WriteLine("\t\t\tresult.Owned = true;"); sw.WriteLine("\t\t\treturn result;"); sw.WriteLine("\t\t}"); sw.WriteLine(); } #endif sw.WriteLine("#endregion"); AppendCustom(sw, gen_info.CustomDir); sw.WriteLine("\t}"); sw.WriteLine("}"); sw.Close(); gen_info.Writer = null; Statistics.OpaqueCount++; }