Ryujinx-GtkSharp/generator/Ctor.cs
Rachel Hestilow 6857128f07 2002-06-21 Rachel Hestilow <hestilow@ximian.com>
* generator/ClassBase.cs: New base class for classes and interfaces.

	* generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations.

	* generator/ObjectGen.cs: Move half of this into ClassBase.

	* generator/Method.cs: Turn all applicable Get/Set functions into .NET
	accessors. Remove redundant == overload and move into Equals, as
	it was confusing "!= null".

	* generator/Parameters.cs: Alter signature creation to accept "is_set"
	option, add support for variable arguments. Add properties "Count",
	"IsVarArgs", "VAType".

	* generator/Ctor.cs: Fixup for changes in Parameters (indenting,
	signature creation).

	* generator/Signal.cs: Support generating declarations.

	* generator/SymbolTable: Change GetObjectGen to GetClassGen.

	* glib/IWrapper.cs: Move "Handle" declaration to here, so
	both classes and interfaces can benefit from it.

	* glib/Object.cs: Inherit from IWrapper.cs

	* parser/Metadata.pm: Support attribute changes on constructors,
	methods, signals, and paramater lists.

	* parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_"
	functions here.

	* parser/gapi_pp.pl: Remove boxed_type_register check, as it will
	be caught in the init funcs.

	* parser/Atk.metadata: Added.

	* parser/Gtk.metadata: Add all needed signal/method collision
	renames. Rename GtkEditable.Editable accessors to IsEditable,
	as .NET does not like accessors with the same name as their
	declaring type. Tag TreeStore constructor as varargs.

	* samples/ButtonApp.cs: s/EmitAdd/Add.

	* samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated.

svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00

108 lines
2.8 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 ns;
private XmlElement elem;
private Parameters parms;
public Ctor (string ns, XmlElement elem) {
this.ns = ns;
this.elem = elem;
XmlElement parms_elem = elem ["parameters"];
if (parms_elem != null)
parms = new Parameters (parms_elem);
}
public bool Validate ()
{
if (parms != null) {
if (!parms.Validate ()) {
Console.Write("ctor ");
Statistics.ThrottledCount++;
return false;
}
parms.CreateSignature (false);
}
return true;
}
public void Generate (StreamWriter sw, Hashtable clash_map)
{
string sigtypes = "";
string sig = "()";
string call = "()";
string isig = "();";
if (parms != null) {
call = "(" + parms.CallString + ")";
sig = "(" + parms.Signature + ")";
isig = "(" + parms.ImportSig + ");";
sigtypes = parms.SignatureTypes;
}
bool clash = false;
if (clash_map.ContainsKey(sigtypes)) {
clash = true;
} else {
clash_map[sigtypes] = elem;
}
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(\"" + SymbolTable.GetDllName(ns) + "\")]");
sw.WriteLine("\t\tstatic extern " + safety + "IntPtr " + cname + isig);
sw.WriteLine();
if (clash) {
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);
}
sw.WriteLine("\t\tpublic static " + safety + name + " " + mname + sig);
sw.WriteLine("\t\t{");
if (parms != null)
parms.Initialize(sw, false, "");
sw.WriteLine("\t\t\tIntPtr ret = " + cname + call + ";");
if (parms != null)
parms.HandleException (sw, "");
sw.WriteLine("\t\t\treturn new " + name + "(ret);");
} else {
sw.WriteLine("\t\tpublic " + safety + name + sig);
sw.WriteLine("\t\t{");
if (parms != null)
parms.Initialize(sw, false, "");
sw.WriteLine("\t\t\tRaw = " + cname + call + ";");
if (parms != null)
parms.HandleException (sw, "");
}
sw.WriteLine("\t\t}");
sw.WriteLine();
Statistics.CtorCount++;
}
}
}