GtkSharp/generator/Ctor.cs
Mike Kestner 6d30cf0c3e refactoring to remove substantial code duplication thoughout the generator
2002-05-23  Mike Kestner <mkestner@speakeasy.net>

	* generator/BoxedGen.cs : Update for Static SymbolTable
	* generator/CallbackGen.cs : Use GenBase and Parameters classes
	* generator/CodeGenerator.cs : Update for Static SymbolTable
	* generator/Ctor.cs : code from StructBase using Parameters class
	* generator/EnumGen.cs : Use GenBase
	* generator/GenBase.cs : Abstract Stream Writer creation, stream
	  boilerplate, and common *Name properties
	* generator/IGeneratable.cs : Update for Static SymbolTable
	* generator/InterfaceGen.cs : Use GenBase
	* generator/Method.cs : code from StructBase using Parameters class
	* generator/ObjectGen.cs : Major refactoring. Use GenBase. Build
	  tables of Member generatables at construct time to facilitate
	  future name collision resolution logic.
	* generator/Parameters.cs : new generatable to abstract duplicated
	  parameter parsing logic.
	* generator/Parser.cs : Update for Static SymbolTable
	* generator/Property.cs : code from ObjectGen
	* generator/Signal.cs : code from ObjectGen
	* generator/SignalHandler.cs : Update for Static SymbolTable
	* generator/StructBase.cs : Update for Static SymbolTable
	* generator/StructGen.cs : Update for Static SymbolTable
	* generator/SymbolTable.cs : Make all methods and private members
	  static.  There is no reason to ever have multiple tables.

svn path=/trunk/gtk-sharp/; revision=4895
2002-05-23 23:43:25 +00:00

90 lines
2.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 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) && !parms.Validate ()) {
Console.Write("ctor ");
Statistics.ThrottledCount++;
return 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");
sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) + "\")]");
sw.WriteLine("\t\tstatic extern 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 " + name + " " + mname + sig);
sw.WriteLine("\t\t{");
sw.WriteLine("\t\t\treturn new " + name + "(" + cname + call + ");");
} else {
sw.WriteLine("\t\tpublic " + name + sig);
sw.WriteLine("\t\t{");
sw.WriteLine("\t\t\tRaw = " + cname + call + ";");
}
sw.WriteLine("\t\t}");
sw.WriteLine();
Statistics.CtorCount++;
}
}
}