mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-25 06:55:36 +00:00
967e3e9c5a
* generator/ClassBase.cs: Change hasDefaultConstructor to protected, adjust now that it is an attr and not a subnode. Also add virtual property AssignToName (for ctors). * generator/Ctor.cs: Add property ForceStatic. (Generate): Optimize return code a bit for the static case. * generator/Method.cs: Assign to a "raw_ret" pointer before calling FromNativeReturn. * generator/Parameters.cs: Change "out ref" to "out", not "ref". * generator/Property.cs: Fix to work correctly with all object and struct types (mostly just some if-cases added). * generator/SignalHandler.cs: Remove args_type and argfields (unused). (Generate): Initialize struct if necessary. * generator/StructBase.cs: Massive reworking to support methods, ctors, etc. * generator/SymbolTable.cs: Add GdkAtom and gconstpointer simple types. * glib/Boxed.cs: Accept both IntPtr and object ctors. Add access for both. * glib/Opaque.cs: Fix copy/pasted copyright notice, remove data and event fields. Fix docs. * glib/Value.cs: Work correctly with boxed properties. * gnome/Modules.cs: Use new struct ctors. * gnome/Program.custom: Remove Get, this is being generated now. * parser/Gdk.metadata: Fix the drawable classes to inherit correctly. * parser/Metadata.pm: Change per-class attributes to actually be attributes. * parser/Gtk.metadata: Add a dummy attribute value for disabledefaultctor. * parser/gapi2xml.pl: Add hacks for the (broken) Drawable and Bitmap typedefs. * sample/test/TestColorSelection.cs: Display color string in hex format, update to use IsNull instead of == null, and size dialog to look pretty. * sample/Size.cs: Added. svn path=/trunk/gtk-sharp/; revision=6264
165 lines
4.3 KiB
C#
165 lines
4.3 KiB
C#
// GtkSharp.Generation.Ctor.cs - The Constructor Generation Class.
|
|
//
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
//
|
|
// (c) 2001-2002 Mike Kestner
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
using System;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using System.Xml;
|
|
|
|
public class Ctor {
|
|
|
|
private string libname;
|
|
private XmlElement elem;
|
|
private Parameters parms;
|
|
private bool preferred;
|
|
private String clashName = null;
|
|
private ClassBase container_type;
|
|
private bool force_static;
|
|
|
|
public bool Preferred {
|
|
get { return preferred; }
|
|
set { preferred = value; }
|
|
}
|
|
|
|
public bool ForceStatic {
|
|
get { return force_static; }
|
|
set { force_static = value; }
|
|
}
|
|
|
|
public Ctor (string libname, XmlElement elem, ClassBase container_type) {
|
|
this.libname = libname;
|
|
this.elem = elem;
|
|
this.container_type = container_type;
|
|
XmlElement parms_elem = elem ["parameters"];
|
|
if (parms_elem != null)
|
|
parms = new Parameters (parms_elem);
|
|
if (elem.HasAttribute ("preferred"))
|
|
preferred = true;
|
|
}
|
|
|
|
public bool Validate ()
|
|
{
|
|
if (parms != null) {
|
|
if (!parms.Validate ()) {
|
|
Console.Write("ctor ");
|
|
Statistics.ThrottledCount++;
|
|
return false;
|
|
}
|
|
parms.CreateSignature (false);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void InitClashMap (Hashtable clash_map)
|
|
{
|
|
string sigtypes = (parms != null) ? parms.SignatureTypes : "";
|
|
if (clash_map.ContainsKey (sigtypes)) {
|
|
int num = (int) clash_map[sigtypes];
|
|
clash_map[sigtypes] = ++num;
|
|
}
|
|
else
|
|
clash_map[sigtypes] = 0;
|
|
}
|
|
|
|
public void Initialize (Hashtable clash_map)
|
|
{
|
|
string sig = "()";
|
|
string sigtypes = "";
|
|
if (parms != null) {
|
|
sig = "(" + parms.Signature + ")";
|
|
sigtypes = parms.SignatureTypes;
|
|
}
|
|
int clashes = (int) clash_map[sigtypes];
|
|
string cname = elem.GetAttribute("cname");
|
|
if (force_static || (clashes > 0 && !Preferred)) {
|
|
String mname = cname.Substring(cname.IndexOf("new"));
|
|
mname = mname.Substring(0,1).ToUpper() + mname.Substring(1);
|
|
int idx;
|
|
while ((idx = mname.IndexOf("_")) > 0) {
|
|
mname = mname.Substring(0, idx) + mname.Substring(idx+1, 1).ToUpper() + mname.Substring(idx+2);
|
|
}
|
|
clashName = mname + sig;
|
|
}
|
|
}
|
|
|
|
public void Generate (StreamWriter sw)
|
|
{
|
|
string sigtypes = "";
|
|
string sig = "()";
|
|
string call = "()";
|
|
string isig = "();";
|
|
if (parms != null) {
|
|
call = "(" + parms.CallString + ")";
|
|
sig = "(" + parms.Signature + ")";
|
|
isig = "(" + parms.ImportSig + ");";
|
|
sigtypes = parms.SignatureTypes;
|
|
}
|
|
|
|
string cname = elem.GetAttribute("cname");
|
|
string name = ((XmlElement)elem.ParentNode).GetAttribute("name");
|
|
string safety;
|
|
if (parms != null && parms.ThrowsException)
|
|
safety = "unsafe ";
|
|
else
|
|
safety = "";
|
|
|
|
sw.WriteLine("\t\t[DllImport(\"" + libname + "\")]");
|
|
sw.WriteLine("\t\tstatic extern " + safety + "IntPtr " + cname + isig);
|
|
sw.WriteLine();
|
|
|
|
sw.WriteLine("\t\t/// <summary> " + name + " Constructor </summary>");
|
|
sw.WriteLine("\t\t/// <remarks> To be completed </remarks>");
|
|
if (clashName != null) {
|
|
string modifiers = "";
|
|
Ctor dup = null;
|
|
ObjectGen parent = (ObjectGen) container_type.Parent;
|
|
while (dup == null && parent != null) {
|
|
foreach (Ctor c in parent.Ctors) {
|
|
if (c.clashName == clashName) {
|
|
dup = c;
|
|
modifiers = "new ";
|
|
break;
|
|
}
|
|
}
|
|
parent = (ObjectGen) parent.Parent;
|
|
}
|
|
|
|
sw.WriteLine("\t\tpublic static " + safety + modifiers + name + " " + clashName);
|
|
sw.WriteLine("\t\t{");
|
|
|
|
if (parms != null)
|
|
parms.HandleException (sw, "");
|
|
|
|
sw.Write("\t\t\treturn ");
|
|
if (container_type is StructBase)
|
|
sw.Write ("{0}.New (", name);
|
|
else
|
|
sw.Write ("new {0} (", name);
|
|
sw.WriteLine (cname + call + ");");
|
|
} else {
|
|
sw.WriteLine("\t\tpublic " + safety + name + sig);
|
|
sw.WriteLine("\t\t{");
|
|
|
|
if (parms != null)
|
|
parms.Initialize(sw, false, "");
|
|
sw.WriteLine("\t\t\t{0} = {1}{2};", container_type.AssignToName, cname, call);
|
|
if (parms != null)
|
|
parms.HandleException (sw, "");
|
|
|
|
}
|
|
|
|
sw.WriteLine("\t\t}");
|
|
sw.WriteLine();
|
|
|
|
Statistics.CtorCount++;
|
|
}
|
|
}
|
|
}
|
|
|