2003-05-18 Mike Kestner <mkestner@speakeasy.net>

* generator/CallbackGen.cs : use non-static symtab, kill doc comments
	* generator/ClassBase.cs : use non-static symtab
	* generator/CodeGenerator.cs : use non-static symtab
	* generator/EnumGen.cs : kill doc comments, don't gen using System here
	* generator/GenBase.cs : gen using System here for all types
	* generator/InterfaceGen.cs : don't gen using System here.
	* generator/Method.cs : use non-static symtab
	* generator/ObjectGen.cs : kill doc comments, use non-static symtab
	* generator/OpaqueGen.cs : don't gen using System here.
	* generator/Parameters.cs : use non static symtab.
	* generator/Parser.cs : use non static symtab. add SimpleGen's and
	ManualGen's
	* generator/Property.cs : use non static symtab
	* generator/SignalHandler.cs : use non static symtab
	* generator/StructBase.cs : use non static symtab
	* generator/SymbolTable.cs : major refactoring. now uses SimpleGen and
	ManualGen IGeneratables to simplify the method and prop code.  Is now
	instance based with a static prop to get the singleton instance, so that
	a this indexer can be provided to access the IGeneratables nicely. Gearing
	up to remove even more code from here by accessing IGeneratables directly.

svn path=/trunk/gtk-sharp/; revision=14687
This commit is contained in:
Mike Kestner 2003-05-19 02:45:17 +00:00
parent 9066fcac16
commit b6114fef1e
16 changed files with 285 additions and 347 deletions

View File

@ -1,3 +1,26 @@
2003-05-18 Mike Kestner <mkestner@speakeasy.net>
* generator/CallbackGen.cs : use non-static symtab, kill doc comments
* generator/ClassBase.cs : use non-static symtab
* generator/CodeGenerator.cs : use non-static symtab
* generator/EnumGen.cs : kill doc comments, don't gen using System here
* generator/GenBase.cs : gen using System here for all types
* generator/InterfaceGen.cs : don't gen using System here.
* generator/Method.cs : use non-static symtab
* generator/ObjectGen.cs : kill doc comments, use non-static symtab
* generator/OpaqueGen.cs : don't gen using System here.
* generator/Parameters.cs : use non static symtab.
* generator/Parser.cs : use non static symtab. add SimpleGen's and
ManualGen's
* generator/Property.cs : use non static symtab
* generator/SignalHandler.cs : use non static symtab
* generator/StructBase.cs : use non static symtab
* generator/SymbolTable.cs : major refactoring. now uses SimpleGen and
ManualGen IGeneratables to simplify the method and prop code. Is now
instance based with a static prop to get the singleton instance, so that
a this indexer can be provided to access the IGeneratables nicely. Gearing
up to remove even more code from here by accessing IGeneratables directly.
2003-05-18 Mike Kestner <mkestner@speakeasy.net> 2003-05-18 Mike Kestner <mkestner@speakeasy.net>
* generator/ClassBase.cs : Use QualifiedName in spew * generator/ClassBase.cs : Use QualifiedName in spew

View File

@ -83,22 +83,24 @@ namespace GtkSharp.Generation {
sig = parms.Signature; sig = parms.Signature;
} }
SymbolTable table = SymbolTable.Table;
XmlElement ret_elem = Elem["return-type"]; XmlElement ret_elem = Elem["return-type"];
string rettype = ret_elem.GetAttribute("type"); string rettype = ret_elem.GetAttribute("type");
string m_ret = SymbolTable.GetMarshalReturnType (rettype); string m_ret = table.GetMarshalReturnType (rettype);
string s_ret = SymbolTable.GetCSType (rettype); string s_ret = table.GetCSType (rettype);
ClassBase ret_wrapper = SymbolTable.GetClassGen (rettype); ClassBase ret_wrapper = table.GetClassGen (rettype);
sw.WriteLine ("\tinternal delegate " + m_ret + " " + wrapper + "(" + import_sig + ");"); sw.WriteLine ("\tinternal delegate " + m_ret + " " + wrapper + "(" + import_sig + ");");
sw.WriteLine (); sw.WriteLine ();
sw.WriteLine ("\tpublic class " + Name + "Wrapper : GLib.DelegateWrapper {"); sw.WriteLine ("\tpublic class " + Name + "Wrapper : GLib.DelegateWrapper {");
if (m_ret != "void") { if (m_ret != "void") {
if (SymbolTable.IsEnum (rettype)) { if (table.IsEnum (rettype)) {
sw.WriteLine ("\t\tstatic int _dummy;"); sw.WriteLine ("\t\tstatic int _dummy;");
} else if (ret_wrapper != null && (ret_wrapper is ObjectGen || ret_wrapper is OpaqueGen)) { } else if (ret_wrapper != null && (ret_wrapper is ObjectGen || ret_wrapper is OpaqueGen)) {
// Do nothing // Do nothing
} else if (!SymbolTable.IsStruct (rettype) && !SymbolTable.IsBoxed (rettype)) { } else if (!table.IsStruct (rettype) && !table.IsBoxed (rettype)) {
sw.WriteLine ("\t\tstatic {0} _dummy;", s_ret); sw.WriteLine ("\t\tstatic {0} _dummy;", s_ret);
} }
} }
@ -108,7 +110,7 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\t\tpublic " + m_ret + " NativeCallback (" + import_sig + ")"); sw.WriteLine ("\t\tpublic " + m_ret + " NativeCallback (" + import_sig + ")");
sw.WriteLine ("\t\t{"); sw.WriteLine ("\t\t{");
sw.Write ("\t\t\tif (RemoveIfNotAlive ()) return "); sw.Write ("\t\t\tif (RemoveIfNotAlive ()) return ");
if (SymbolTable.IsStruct (rettype) || SymbolTable.IsBoxed (rettype)) if (table.IsStruct (rettype) || table.IsBoxed (rettype))
sw.WriteLine ("IntPtr.Zero;"); sw.WriteLine ("IntPtr.Zero;");
else if (ret_wrapper != null && (ret_wrapper is ObjectGen || ret_wrapper is OpaqueGen)) else if (ret_wrapper != null && (ret_wrapper is ObjectGen || ret_wrapper is OpaqueGen))
sw.WriteLine ("IntPtr.Zero;"); sw.WriteLine ("IntPtr.Zero;");
@ -134,9 +136,9 @@ namespace GtkSharp.Generation {
string cstype = parms[i].CSType; string cstype = parms[i].CSType;
// FIXME: Too much code copy/pasted here. Refactor? // FIXME: Too much code copy/pasted here. Refactor?
ClassBase parm_wrapper = SymbolTable.GetClassGen (ctype); ClassBase parm_wrapper = table.GetClassGen (ctype);
sw.WriteLine("\t\t\t_args[" + idx + "] = " + SymbolTable.FromNative (ctype, parm_name) + ";"); sw.WriteLine("\t\t\t_args[" + idx + "] = " + table.FromNative (ctype, parm_name) + ";");
if ((parm_wrapper != null && ((parm_wrapper is OpaqueGen))) || SymbolTable.IsManuallyWrapped (ctype)) { if ((parm_wrapper != null && ((parm_wrapper is OpaqueGen))) || table.IsManuallyWrapped (ctype)) {
sw.WriteLine("\t\t\tif (_args[" + idx + "] == null)"); sw.WriteLine("\t\t\tif (_args[" + idx + "] == null)");
sw.WriteLine("\t\t\t\t_args[{0}] = new {1}({2});", idx, cstype, parm_name); sw.WriteLine("\t\t\t\t_args[{0}] = new {1}({2});", idx, cstype, parm_name);
} }
@ -153,11 +155,11 @@ namespace GtkSharp.Generation {
if (m_ret != "void") { if (m_ret != "void") {
if (ret_wrapper != null && (ret_wrapper is ObjectGen || ret_wrapper is OpaqueGen)) if (ret_wrapper != null && (ret_wrapper is ObjectGen || ret_wrapper is OpaqueGen))
sw.WriteLine ("return (({0}) {1}).Handle;", s_ret, invoke); sw.WriteLine ("return (({0}) {1}).Handle;", s_ret, invoke);
else if (SymbolTable.IsStruct (rettype) || SymbolTable.IsBoxed (rettype)) { else if (table.IsStruct (rettype) || table.IsBoxed (rettype)) {
// Shoot. I have no idea what to do here. // Shoot. I have no idea what to do here.
sw.WriteLine ("return IntPtr.Zero;"); sw.WriteLine ("return IntPtr.Zero;");
} }
else if (SymbolTable.IsEnum (rettype)) else if (table.IsEnum (rettype))
sw.WriteLine ("return (int) {0};", invoke); sw.WriteLine ("return (int) {0};", invoke);
else else
sw.WriteLine ("return ({0}) {1};", s_ret, invoke); sw.WriteLine ("return ({0}) {1};", s_ret, invoke);
@ -196,8 +198,10 @@ namespace GtkSharp.Generation {
return; return;
} }
SymbolTable table = SymbolTable.Table;
string rettype = ret_elem.GetAttribute("type"); string rettype = ret_elem.GetAttribute("type");
string s_ret = SymbolTable.GetCSType (rettype); string s_ret = table.GetCSType (rettype);
if (s_ret == "") { if (s_ret == "") {
Console.WriteLine("rettype: " + rettype + " in callback " + CName); Console.WriteLine("rettype: " + rettype + " in callback " + CName);
Statistics.ThrottledCount++; Statistics.ThrottledCount++;

View File

@ -38,7 +38,7 @@ namespace GtkSharp.Generation {
public ClassBase Parent { public ClassBase Parent {
get { get {
string parent = Elem.GetAttribute("parent"); string parent = Elem.GetAttribute("parent");
return SymbolTable.GetClassGen(parent); return SymbolTable.Table.GetClassGen(parent);
} }
} }
@ -250,7 +250,7 @@ namespace GtkSharp.Generation {
if (check_self && p == null && interfaces != null) { if (check_self && p == null && interfaces != null) {
foreach (string iface in interfaces) { foreach (string iface in interfaces) {
ClassBase igen = SymbolTable.GetClassGen (iface); ClassBase igen = SymbolTable.Table.GetClassGen (iface);
p = igen.GetMethodRecursively (name, true); p = igen.GetMethodRecursively (name, true);
if (p != null) if (p != null)
break; break;
@ -287,7 +287,7 @@ namespace GtkSharp.Generation {
if (check_self && p == null && interfaces != null) { if (check_self && p == null && interfaces != null) {
foreach (string iface in interfaces) { foreach (string iface in interfaces) {
ClassBase igen = SymbolTable.GetClassGen (iface); ClassBase igen = SymbolTable.Table.GetClassGen (iface);
p = igen.GetSignalRecursively (name, true); p = igen.GetSignalRecursively (name, true);
if (p != null) if (p != null)
break; break;

View File

@ -32,10 +32,8 @@ namespace GtkSharp.Generation {
Parser p = new Parser (arg); Parser p = new Parser (arg);
p.Parse (generate); p.Parse (generate);
} }
Console.WriteLine (SymbolTable.Count + " types parsed.");
foreach (IGeneratable gen in SymbolTable.Generatables) { foreach (IGeneratable gen in SymbolTable.Table.Generatables) {
gen.Generate (); gen.Generate ();
} }

View File

@ -50,16 +50,9 @@ namespace GtkSharp.Generation {
StreamWriter sw = CreateWriter (); StreamWriter sw = CreateWriter ();
if (Elem.GetAttribute("type") == "flags") { if (Elem.GetAttribute("type") == "flags") {
sw.WriteLine ("\tusing System;");
sw.WriteLine (); sw.WriteLine ();
}
sw.WriteLine("\t\t/// <summary> " + Name + " enumeration </summary>");
sw.WriteLine("\t\t/// <remarks>");
sw.WriteLine("\t\t/// </remarks>");
if (Elem.GetAttribute("type") == "flags")
sw.WriteLine ("\t[Flags]"); sw.WriteLine ("\t[Flags]");
}
// Ok, this is obscene. We need to go through the enums first // Ok, this is obscene. We need to go through the enums first
// to find "large" values. If we find some, we need to change // to find "large" values. If we find some, we need to change

View File

@ -82,6 +82,8 @@ namespace GtkSharp.Generation {
sw.WriteLine (); sw.WriteLine ();
sw.WriteLine ("namespace " + NS + " {"); sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine (); sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ();
return sw; return sw;
} }

View File

@ -21,9 +21,6 @@ namespace GtkSharp.Generation {
StreamWriter sw = CreateWriter (); StreamWriter sw = CreateWriter ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code"); sw.WriteLine ("#region Autogenerated code");
sw.WriteLine ("\tpublic interface " + Name + " : GLib.IWrapper {"); sw.WriteLine ("\tpublic interface " + Name + " : GLib.IWrapper {");
sw.WriteLine (); sw.WriteLine ();

View File

@ -148,9 +148,11 @@ namespace GtkSharp.Generation {
return false; return false;
} }
SymbolTable table = SymbolTable.Table;
rettype = ret_elem.GetAttribute("type"); rettype = ret_elem.GetAttribute("type");
m_ret = SymbolTable.GetMarshalReturnType(rettype); m_ret = table.GetMarshalReturnType(rettype);
s_ret = SymbolTable.GetCSType(rettype); s_ret = table.GetCSType(rettype);
cname = elem.GetAttribute("cname"); cname = elem.GetAttribute("cname");
if (ret_elem.HasAttribute("element_type")) if (ret_elem.HasAttribute("element_type"))
element_type = ret_elem.GetAttribute("element_type"); element_type = ret_elem.GetAttribute("element_type");
@ -385,17 +387,19 @@ namespace GtkSharp.Generation {
if (parms != null) if (parms != null)
parms.Initialize(sw, is_get, is_set, indent); parms.Initialize(sw, is_get, is_set, indent);
SymbolTable table = SymbolTable.Table;
sw.Write(indent + "\t\t\t"); sw.Write(indent + "\t\t\t");
if (m_ret == "void") { if (m_ret == "void") {
sw.WriteLine(cname + call + ";"); sw.WriteLine(cname + call + ";");
} else { } else {
if (SymbolTable.IsObject (rettype) || SymbolTable.IsOpaque (rettype)) if (table.IsObject (rettype) || table.IsOpaque (rettype))
{ {
sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";"); sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";");
sw.WriteLine(indent +"\t\t\t" + s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, "raw_ret") + ";"); sw.WriteLine(indent +"\t\t\t" + s_ret + " ret = " + table.FromNativeReturn(rettype, "raw_ret") + ";");
if (needs_ref) if (needs_ref)
sw.WriteLine(indent + "\t\t\tret.Ref ();"); sw.WriteLine(indent + "\t\t\tret.Ref ();");
if (SymbolTable.IsOpaque (rettype)) if (table.IsOpaque (rettype))
sw.WriteLine(indent + "\t\t\tif (ret == null) ret = new " + s_ret + "(raw_ret);"); sw.WriteLine(indent + "\t\t\tif (ret == null) ret = new " + s_ret + "(raw_ret);");
} }
else { else {
@ -404,7 +408,7 @@ namespace GtkSharp.Generation {
string raw_parms = "raw_ret"; string raw_parms = "raw_ret";
if (element_type != null) if (element_type != null)
raw_parms += ", typeof (" + element_type + ")"; raw_parms += ", typeof (" + element_type + ")";
sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, raw_parms) + ";"); sw.WriteLine(s_ret + " ret = " + table.FromNativeReturn(rettype, raw_parms) + ";");
} }
} }

View File

@ -58,25 +58,22 @@ namespace GtkSharp.Generation {
StreamWriter sw = CreateWriter (); StreamWriter sw = CreateWriter ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Collections;"); sw.WriteLine ("\tusing System.Collections;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;"); sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine (); sw.WriteLine ();
sw.WriteLine("\t\t/// <summary> " + Name + " Class</summary>"); SymbolTable table = SymbolTable.Table;
sw.WriteLine("\t\t/// <remarks>");
sw.WriteLine("\t\t/// </remarks>");
sw.WriteLine ("#region Autogenerated code"); sw.WriteLine ("#region Autogenerated code");
sw.Write ("\tpublic class " + Name); sw.Write ("\tpublic class " + Name);
string cs_parent = SymbolTable.GetCSType(Elem.GetAttribute("parent")); string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));
if (cs_parent != "") if (cs_parent != "")
sw.Write (" : " + cs_parent); sw.Write (" : " + cs_parent);
if (interfaces != null) { if (interfaces != null) {
foreach (string iface in interfaces) { foreach (string iface in interfaces) {
if (Parent != null && Parent.Implements (iface)) if (Parent != null && Parent.Implements (iface))
continue; continue;
sw.Write (", " + SymbolTable.GetCSType (iface)); sw.Write (", " + table.GetCSType (iface));
} }
} }
sw.WriteLine (" {"); sw.WriteLine (" {");
@ -88,7 +85,7 @@ namespace GtkSharp.Generation {
bool has_sigs = (sigs != null); bool has_sigs = (sigs != null);
if (!has_sigs) { if (!has_sigs) {
foreach (string iface in interfaces) { foreach (string iface in interfaces) {
ClassBase igen = SymbolTable.GetClassGen (iface); ClassBase igen = table.GetClassGen (iface);
if (igen.Signals != null) { if (igen.Signals != null) {
has_sigs = true; has_sigs = true;
break; break;
@ -108,7 +105,7 @@ namespace GtkSharp.Generation {
Hashtable all_methods = new Hashtable (); Hashtable all_methods = new Hashtable ();
Hashtable collisions = new Hashtable (); Hashtable collisions = new Hashtable ();
foreach (string iface in interfaces) { foreach (string iface in interfaces) {
ClassBase igen = SymbolTable.GetClassGen (iface); ClassBase igen = table.GetClassGen (iface);
foreach (Method m in igen.Methods.Values) { foreach (Method m in igen.Methods.Values) {
if (all_methods.Contains (m.Name)) if (all_methods.Contains (m.Name))
collisions[m.Name] = true; collisions[m.Name] = true;
@ -120,7 +117,7 @@ namespace GtkSharp.Generation {
foreach (string iface in interfaces) { foreach (string iface in interfaces) {
if (Parent != null && Parent.Implements (iface)) if (Parent != null && Parent.Implements (iface))
continue; continue;
ClassBase igen = SymbolTable.GetClassGen (iface); ClassBase igen = table.GetClassGen (iface);
igen.GenMethods (sw, collisions, this, false); igen.GenMethods (sw, collisions, this, false);
igen.GenSignals (sw, this); igen.GenSignals (sw, this);
} }

View File

@ -34,7 +34,6 @@ namespace GtkSharp.Generation {
StreamWriter sw = CreateWriter (); StreamWriter sw = CreateWriter ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Collections;"); sw.WriteLine ("\tusing System.Collections;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;"); sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine (); sw.WriteLine ();

View File

@ -30,7 +30,7 @@ namespace GtkSharp.Generation {
public string CSType { public string CSType {
get { get {
string cstype = SymbolTable.GetCSType( elem.GetAttribute("type")); string cstype = SymbolTable.Table.GetCSType( elem.GetAttribute("type"));
if (cstype == "void") if (cstype == "void")
cstype = "System.IntPtr"; cstype = "System.IntPtr";
if (elem.HasAttribute("array")) { if (elem.HasAttribute("array")) {
@ -56,7 +56,7 @@ namespace GtkSharp.Generation {
public string MarshalType { public string MarshalType {
get { get {
string type = SymbolTable.GetMarshalType( elem.GetAttribute("type")); string type = SymbolTable.Table.GetMarshalType( elem.GetAttribute("type"));
if (type == "void") if (type == "void")
type = "System.IntPtr"; type = "System.IntPtr";
if (elem.HasAttribute("array")) { if (elem.HasAttribute("array")) {
@ -191,7 +191,7 @@ namespace GtkSharp.Generation {
Parameter p = new Parameter (p_elem); Parameter p = new Parameter (p_elem);
if ((p.CSType == "") || (p.Name == "") || if ((p.CSType == "") || (p.Name == "") ||
(p.MarshalType == "") || (SymbolTable.CallByName(p.CType, p.Name) == "")) { (p.MarshalType == "") || (SymbolTable.Table.CallByName(p.CType, p.Name) == "")) {
Console.Write("Name: " + p.Name + " Type: " + p.CType + " "); Console.Write("Name: " + p.Name + " Type: " + p.CType + " ");
return false; return false;
} }
@ -208,6 +208,7 @@ namespace GtkSharp.Generation {
bool last_was_user_data = false; bool last_was_user_data = false;
bool has_user_data = false; bool has_user_data = false;
SymbolTable table = SymbolTable.Table;
int len = 0; int len = 0;
Parameter last_param = null; Parameter last_param = null;
foreach (XmlNode parm in elem.ChildNodes) { foreach (XmlNode parm in elem.ChildNodes) {
@ -250,14 +251,14 @@ namespace GtkSharp.Generation {
call_parm_name = "value"; call_parm_name = "value";
string call_parm; string call_parm;
if (SymbolTable.IsCallback (type)) { if (table.IsCallback (type)) {
has_callback = true; has_callback = true;
call_parm = SymbolTable.CallByName (type, call_parm_name + "_wrapper"); call_parm = table.CallByName (type, call_parm_name + "_wrapper");
} else } else
call_parm = SymbolTable.CallByName(type, call_parm_name); call_parm = table.CallByName(type, call_parm_name);
if (p_elem.HasAttribute ("null_ok") && cs_type != "IntPtr" && cs_type != "System.IntPtr" && !SymbolTable.IsStruct (type)) if (p_elem.HasAttribute ("null_ok") && cs_type != "IntPtr" && cs_type != "System.IntPtr" && !table.IsStruct (type))
call_parm = String.Format ("({0} != null) ? {1} : {2}", call_parm_name, call_parm, SymbolTable.IsCallback (type) ? "null" : "IntPtr.Zero"); call_parm = String.Format ("({0} != null) ? {1} : {2}", call_parm_name, call_parm, table.IsCallback (type) ? "null" : "IntPtr.Zero");
if (p_elem.HasAttribute("array")) if (p_elem.HasAttribute("array"))
call_parm = call_parm.Replace ("ref ", ""); call_parm = call_parm.Replace ("ref ", "");
@ -289,7 +290,7 @@ namespace GtkSharp.Generation {
call_string += pass_as + " "; call_string += pass_as + " ";
} }
if (SymbolTable.IsEnum (type)) if (table.IsEnum (type))
call_parm = name + "_as_int"; call_parm = name + "_as_int";
} }
else if (type == "GError**") else if (type == "GError**")
@ -340,6 +341,8 @@ namespace GtkSharp.Generation {
{ {
string name = ""; string name = "";
SymbolTable table = SymbolTable.Table;
foreach (XmlNode parm in elem.ChildNodes) { foreach (XmlNode parm in elem.ChildNodes) {
if (parm.Name != "parameter") { if (parm.Name != "parameter") {
continue; continue;
@ -361,11 +364,11 @@ namespace GtkSharp.Generation {
sw.WriteLine (indent + "\t\t\t" + type + " " + name + ";"); sw.WriteLine (indent + "\t\t\t" + type + " " + name + ";");
} }
if ((is_get || (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out")) && (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type) || type == "GLib.Value")) { if ((is_get || (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out")) && (table.IsObject (c_type) || table.IsOpaque (c_type) || type == "GLib.Value")) {
sw.WriteLine(indent + "\t\t\t" + name + " = new " + type + "();"); sw.WriteLine(indent + "\t\t\t" + name + " = new " + type + "();");
} }
if (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out" && SymbolTable.IsEnum (c_type)) { if (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out" && table.IsEnum (c_type)) {
sw.WriteLine(indent + "\t\t\tint " + name + "_as_int;"); sw.WriteLine(indent + "\t\t\tint " + name + "_as_int;");
} }
} }
@ -390,7 +393,7 @@ namespace GtkSharp.Generation {
name = p.Name; name = p.Name;
} }
if (SymbolTable.IsCallback (c_type)) { if (table.IsCallback (c_type)) {
type = type.Replace(".", "Sharp.") + "Wrapper"; type = type.Replace(".", "Sharp.") + "Wrapper";
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = null;", type, name); sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = null;", type, name);
@ -417,7 +420,7 @@ namespace GtkSharp.Generation {
string name = p.Name; string name = p.Name;
string type = p.CSType; string type = p.CSType;
if (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out" && SymbolTable.IsEnum (c_type)) { if (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out" && SymbolTable.Table.IsEnum (c_type)) {
sw.WriteLine(indent + "\t\t\t" + name + " = (" + type + ") " + name + "_as_int;"); sw.WriteLine(indent + "\t\t\t" + name + " = (" + type + ") " + name + "_as_int;");
} }
} }
@ -500,7 +503,7 @@ namespace GtkSharp.Generation {
if (parm.Name != "parameter") if (parm.Name != "parameter")
continue; continue;
XmlElement p_elem = (XmlElement) parm; XmlElement p_elem = (XmlElement) parm;
return SymbolTable.GetCSType(p_elem.GetAttribute ("type")); return SymbolTable.Table.GetCSType(p_elem.GetAttribute ("type"));
} }
return null; return null;
} }

View File

@ -77,7 +77,7 @@ namespace GtkSharp.Generation {
string atype = elem.GetAttribute("type"); string atype = elem.GetAttribute("type");
if ((aname == "") || (atype == "")) if ((aname == "") || (atype == ""))
continue; continue;
SymbolTable.AddAlias (aname, atype); SymbolTable.Table.AddAlias (aname, atype);
break; break;
case "boxed": case "boxed":
@ -117,7 +117,7 @@ namespace GtkSharp.Generation {
if (igen != null) { if (igen != null) {
igen.DoGenerate = generate; igen.DoGenerate = generate;
SymbolTable.AddType (igen); SymbolTable.Table.AddType (igen);
} }
} }
} }
@ -129,9 +129,9 @@ namespace GtkSharp.Generation {
string name = symbol.GetAttribute ("name"); string name = symbol.GetAttribute ("name");
if (type == "simple") if (type == "simple")
SymbolTable.AddSimpleType (cname, name); SymbolTable.Table.AddType (new SimpleGen (cname, name));
else if (type == "manual") else if (type == "manual")
SymbolTable.AddManualType (cname, name); SymbolTable.Table.AddType (new ManualGen (cname, name));
else else
Console.WriteLine ("Unexpected symbol type " + type); Console.WriteLine ("Unexpected symbol type " + type);
} }

View File

@ -31,7 +31,8 @@ namespace GtkSharp.Generation {
public bool Validate () public bool Validate ()
{ {
string c_type = elem.GetAttribute("type"); string c_type = elem.GetAttribute("type");
string cs_type = SymbolTable.GetCSType(c_type); SymbolTable table = SymbolTable.Table;
string cs_type = table.GetCSType(c_type);
if (cs_type == "") { if (cs_type == "") {
Console.Write("Property has unknown Type {0} ", c_type); Console.Write("Property has unknown Type {0} ", c_type);
@ -39,7 +40,7 @@ namespace GtkSharp.Generation {
return false; return false;
} }
if (SymbolTable.IsInterface(c_type)) { if (table.IsInterface(c_type)) {
// FIXME: Handle interface props properly. // FIXME: Handle interface props properly.
Console.Write("Interface property detected "); Console.Write("Interface property detected ");
Statistics.ThrottledCount++; Statistics.ThrottledCount++;
@ -51,8 +52,10 @@ namespace GtkSharp.Generation {
public void Generate (StreamWriter sw) public void Generate (StreamWriter sw)
{ {
SymbolTable table = SymbolTable.Table;
string c_type = elem.GetAttribute("type"); string c_type = elem.GetAttribute("type");
string cs_type = SymbolTable.GetCSType(c_type); string cs_type = table.GetCSType(c_type);
string modifiers = ""; string modifiers = "";
if (elem.HasAttribute("new_flag") || (container_type.Parent != null && container_type.Parent.GetPropertyRecursively (Name) != null)) if (elem.HasAttribute("new_flag") || (container_type.Parent != null && container_type.Parent.GetPropertyRecursively (Name) != null))
@ -66,18 +69,18 @@ namespace GtkSharp.Generation {
string cname = "\"" + elem.GetAttribute("cname") + "\""; string cname = "\"" + elem.GetAttribute("cname") + "\"";
string v_type = ""; string v_type = "";
if (SymbolTable.IsEnum(c_type)) { if (table.IsEnum(c_type)) {
v_type = "(int) (GLib.EnumWrapper)"; v_type = "(int) (GLib.EnumWrapper)";
} else if (SymbolTable.IsInterface(c_type)) { } else if (table.IsInterface(c_type)) {
// FIXME: Handle interface props properly. // FIXME: Handle interface props properly.
Console.Write("Interface property detected "); Console.Write("Interface property detected ");
Statistics.ThrottledCount++; Statistics.ThrottledCount++;
return; return;
} else if (SymbolTable.IsObject(c_type)) { } else if (table.IsObject(c_type)) {
v_type = "(GLib.UnwrappedObject)"; v_type = "(GLib.UnwrappedObject)";
} else if (SymbolTable.IsBoxed (c_type)) { } else if (table.IsBoxed (c_type)) {
v_type = "(GLib.Boxed)"; v_type = "(GLib.Boxed)";
} else if (SymbolTable.IsOpaque (c_type)) { } else if (table.IsOpaque (c_type)) {
v_type = "(GLib.Opaque)"; v_type = "(GLib.Opaque)";
} }
@ -118,10 +121,10 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\t\tget {"); sw.WriteLine("\t\t\tget {");
sw.WriteLine("\t\t\t\tGLib.Value val = new GLib.Value (Handle, " + cname + ");"); sw.WriteLine("\t\t\t\tGLib.Value val = new GLib.Value (Handle, " + cname + ");");
sw.WriteLine("\t\t\t\tGetProperty(" + cname + ", val);"); sw.WriteLine("\t\t\t\tGetProperty(" + cname + ", val);");
if (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type) || SymbolTable.IsBoxed (c_type)) { if (table.IsObject (c_type) || table.IsOpaque (c_type) || table.IsBoxed (c_type)) {
sw.WriteLine("\t\t\t\tSystem.IntPtr raw_ret = (System.IntPtr) {0} val;", v_type); sw.WriteLine("\t\t\t\tSystem.IntPtr raw_ret = (System.IntPtr) {0} val;", v_type);
sw.WriteLine("\t\t\t\t" + cs_type + " ret = " + SymbolTable.FromNativeReturn(c_type, "raw_ret") + ";"); sw.WriteLine("\t\t\t\t" + cs_type + " ret = " + table.FromNativeReturn(c_type, "raw_ret") + ";");
if (!SymbolTable.IsBoxed (c_type)) if (!table.IsBoxed (c_type))
sw.WriteLine("\t\t\t\tif (ret == null) ret = new " + cs_type + "(raw_ret);"); sw.WriteLine("\t\t\t\tif (ret == null) ret = new " + cs_type + "(raw_ret);");
} else { } else {
sw.Write("\t\t\t\t" + cs_type + " ret = "); sw.Write("\t\t\t\t" + cs_type + " ret = ");
@ -143,12 +146,12 @@ namespace GtkSharp.Generation {
} else if (elem.HasAttribute("writeable") && !elem.HasAttribute("construct-only")) { } else if (elem.HasAttribute("writeable") && !elem.HasAttribute("construct-only")) {
sw.WriteLine("\t\t\tset {"); sw.WriteLine("\t\t\tset {");
sw.Write("\t\t\t\tSetProperty(" + cname + ", new GLib.Value("); sw.Write("\t\t\t\tSetProperty(" + cname + ", new GLib.Value(");
if (SymbolTable.IsEnum(c_type)) { if (table.IsEnum(c_type)) {
sw.WriteLine("Handle, " + cname + ", new GLib.EnumWrapper ((int) value, {0})));", SymbolTable.IsEnumFlags (c_type) ? "true" : "false"); sw.WriteLine("Handle, " + cname + ", new GLib.EnumWrapper ((int) value, {0})));", table.IsEnumFlags (c_type) ? "true" : "false");
} else if (SymbolTable.IsBoxed (c_type)) { } else if (table.IsBoxed (c_type)) {
sw.WriteLine("Handle, " + cname + ", new GLib.Boxed (value)));"); sw.WriteLine("Handle, " + cname + ", new GLib.Boxed (value)));");
} else { } else {
if (v_type != "" && !(SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type))) { if (v_type != "" && !(table.IsObject (c_type) || table.IsOpaque (c_type))) {
sw.Write(v_type + " "); sw.Write(v_type + " ");
} }
sw.WriteLine("value));"); sw.WriteLine("value));");

View File

@ -2,7 +2,7 @@
// //
// Author: Mike Kestner <mkestner@speakeasy.net> // Author: Mike Kestner <mkestner@speakeasy.net>
// //
// (c) 2002 Mike Kestner // (c) 2002-2003 Mike Kestner
namespace GtkSharp.Generation { namespace GtkSharp.Generation {
@ -27,8 +27,10 @@ namespace GtkSharp.Generation {
return ""; return "";
} }
string s_ret = SymbolTable.GetCSType(retval); SymbolTable table = SymbolTable.Table;
string p_ret = SymbolTable.GetMarshalReturnType(retval);
string s_ret = table.GetCSType(retval);
string p_ret = table.GetMarshalReturnType(retval);
if ((s_ret == "") || (p_ret == "")) { if ((s_ret == "") || (p_ret == "")) {
Console.Write("Funky type: " + retval); Console.Write("Funky type: " + retval);
return ""; return "";
@ -36,7 +38,7 @@ namespace GtkSharp.Generation {
string key = retval; string key = retval;
string pinv = ""; string pinv = "";
string name = SymbolTable.GetName(retval); string name = table.GetName(retval);
int pcnt = 0; int pcnt = 0;
ArrayList parms = new ArrayList(); ArrayList parms = new ArrayList();
@ -52,7 +54,7 @@ namespace GtkSharp.Generation {
XmlElement elem = (XmlElement) parm; XmlElement elem = (XmlElement) parm;
string type = elem.GetAttribute("type"); string type = elem.GetAttribute("type");
string ptype = SymbolTable.GetMarshalType(type); string ptype = table.GetMarshalType(type);
if (ptype == "") { if (ptype == "") {
Console.Write("Funky type: " + type); Console.Write("Funky type: " + type);
return ""; return "";
@ -64,11 +66,11 @@ namespace GtkSharp.Generation {
pinv += (ptype + " arg" + pcnt); pinv += (ptype + " arg" + pcnt);
parms.Add(type); parms.Add(type);
if (SymbolTable.IsObject(type) || SymbolTable.IsInterface(type)) { if (table.IsObject(type) || table.IsInterface(type)) {
name += "Object"; name += "Object";
key += "Object"; key += "Object";
} else { } else {
name += SymbolTable.GetName(type); name += table.GetName(type);
key += type; key += type;
} }
pcnt++; pcnt++;
@ -131,22 +133,22 @@ namespace GtkSharp.Generation {
} }
for (int idx=1; idx < parms.Count; idx++) { for (int idx=1; idx < parms.Count; idx++) {
string ctype = (string) parms[idx]; string ctype = (string) parms[idx];
ClassBase wrapper = SymbolTable.GetClassGen (ctype); ClassBase wrapper = table.GetClassGen (ctype);
if ((wrapper != null && !(wrapper is StructBase)) || SymbolTable.IsManuallyWrapped (ctype)) { if ((wrapper != null && !(wrapper is StructBase)) || table.IsManuallyWrapped (ctype)) {
sw.WriteLine("\t\t\tif (arg{0} == IntPtr.Zero)", idx); sw.WriteLine("\t\t\tif (arg{0} == IntPtr.Zero)", idx);
sw.WriteLine("\t\t\t\targs.Args[{0}] = null;", idx - 1); sw.WriteLine("\t\t\t\targs.Args[{0}] = null;", idx - 1);
sw.WriteLine("\t\t\telse {"); sw.WriteLine("\t\t\telse {");
if (wrapper != null && wrapper is ObjectGen) if (wrapper != null && wrapper is ObjectGen)
sw.WriteLine("\t\t\t\targs.Args[" + (idx-1) + "] = GLib.Object.GetObject(arg" + idx + ");"); sw.WriteLine("\t\t\t\targs.Args[" + (idx-1) + "] = GLib.Object.GetObject(arg" + idx + ");");
else else
sw.WriteLine("\t\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";"); sw.WriteLine("\t\t\t\targs.Args[" + (idx-1) + "] = " + table.FromNative (ctype, "arg" + idx) + ";");
if ((wrapper != null && (wrapper is OpaqueGen)) || SymbolTable.IsManuallyWrapped (ctype)) { if ((wrapper != null && (wrapper is OpaqueGen)) || table.IsManuallyWrapped (ctype)) {
sw.WriteLine("\t\t\t\tif (args.Args[" + (idx-1) + "] == null)"); sw.WriteLine("\t\t\t\tif (args.Args[" + (idx-1) + "] == null)");
sw.WriteLine("\t\t\t\t\targs.Args[{0}] = new {1}(arg{2});", idx-1, SymbolTable.GetCSType (ctype), idx); sw.WriteLine("\t\t\t\t\targs.Args[{0}] = new {1}(arg{2});", idx-1, table.GetCSType (ctype), idx);
} }
sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t\t}");
} else { } else {
sw.WriteLine("\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";"); sw.WriteLine("\t\t\targs.Args[" + (idx-1) + "] = " + table.FromNative (ctype, "arg" + idx) + ";");
} }
} }
sw.WriteLine("\t\t\tobject[] argv = new object[2];"); sw.WriteLine("\t\t\tobject[] argv = new object[2];");
@ -160,7 +162,7 @@ namespace GtkSharp.Generation {
else else
sw.WriteLine ("\t\t\t\tthrow new Exception(\"args.RetVal unset in callback\");"); sw.WriteLine ("\t\t\t\tthrow new Exception(\"args.RetVal unset in callback\");");
sw.WriteLine("\t\t\treturn (" + p_ret + ") " + SymbolTable.CallByName (retval, "((" + s_ret + ")args.RetVal)") + ";"); sw.WriteLine("\t\t\treturn (" + p_ret + ") " + table.CallByName (retval, "((" + s_ret + ")args.RetVal)") + ";");
} }
sw.WriteLine("\t\t}"); sw.WriteLine("\t\t}");
sw.WriteLine(); sw.WriteLine();

View File

@ -112,13 +112,13 @@ namespace GtkSharp.Generation {
{ {
name = ""; name = "";
c_type = field.GetAttribute ("type"); c_type = field.GetAttribute ("type");
type = SymbolTable.GetCSType (c_type); type = SymbolTable.Table.GetCSType (c_type);
if (IsBit (field)) { if (IsBit (field)) {
type = "uint"; type = "uint";
} else if ((IsPointer (field) || SymbolTable.IsOpaque (c_type)) && type != "string") { } else if ((IsPointer (field) || SymbolTable.Table.IsOpaque (c_type)) && type != "string") {
type = "IntPtr"; type = "IntPtr";
name = "_"; name = "_";
} else if (SymbolTable.IsCallback (c_type)) { } else if (SymbolTable.Table.IsCallback (c_type)) {
type = "IntPtr"; type = "IntPtr";
} else { } else {
if (type == "") { if (type == "") {
@ -149,34 +149,35 @@ namespace GtkSharp.Generation {
if (field.HasAttribute("array_len")) if (field.HasAttribute("array_len"))
Console.WriteLine ("warning: array field {0}.{1} probably incorrectly generated", QualifiedName, name); Console.WriteLine ("warning: array field {0}.{1} probably incorrectly generated", QualifiedName, name);
SymbolTable table = SymbolTable.Table;
string wrapped = SymbolTable.GetCSType (c_type); string wrapped = table.GetCSType (c_type);
string wrapped_name = MangleName (field.GetAttribute ("cname")); string wrapped_name = MangleName (field.GetAttribute ("cname"));
if (SymbolTable.IsObject (c_type)) { if (table.IsObject (c_type)) {
sw.WriteLine (); sw.WriteLine ();
sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {"); sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {");
sw.WriteLine ("\t\t\tget { "); sw.WriteLine ("\t\t\tget { ");
sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + SymbolTable.FromNativeReturn(c_type, name) + ";"); sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + table.FromNativeReturn(c_type, name) + ";");
sw.WriteLine ("\t\t\t\tret.Ref ();"); sw.WriteLine ("\t\t\t\tret.Ref ();");
sw.WriteLine ("\t\t\t\treturn ret;"); sw.WriteLine ("\t\t\t\treturn ret;");
sw.WriteLine ("\t\t\t}"); sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t\tset { " + name + " = " + SymbolTable.CallByName (c_type, "value") + "; }"); sw.WriteLine ("\t\t\tset { " + name + " = " + table.CallByName (c_type, "value") + "; }");
sw.WriteLine ("\t\t}"); sw.WriteLine ("\t\t}");
} else if (SymbolTable.IsOpaque (c_type)) { } else if (table.IsOpaque (c_type)) {
sw.WriteLine (); sw.WriteLine ();
sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {"); sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {");
sw.WriteLine ("\t\t\tget { "); sw.WriteLine ("\t\t\tget { ");
sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + SymbolTable.FromNativeReturn(c_type, name) + ";"); sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + table.FromNativeReturn(c_type, name) + ";");
sw.WriteLine ("\t\t\t\tif (ret == null) ret = new " + wrapped + "(" + name + ");"); sw.WriteLine ("\t\t\t\tif (ret == null) ret = new " + wrapped + "(" + name + ");");
sw.WriteLine ("\t\t\t\treturn ret;"); sw.WriteLine ("\t\t\t\treturn ret;");
sw.WriteLine ("\t\t\t}"); sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t\tset { " + name + " = " + SymbolTable.CallByName (c_type, "value") + "; }"); sw.WriteLine ("\t\t\tset { " + name + " = " + table.CallByName (c_type, "value") + "; }");
sw.WriteLine ("\t\t}"); sw.WriteLine ("\t\t}");
} else if (IsPointer (field) && (SymbolTable.IsStruct (c_type) || SymbolTable.IsBoxed (c_type))) { } else if (IsPointer (field) && (table.IsStruct (c_type) || table.IsBoxed (c_type))) {
sw.WriteLine (); sw.WriteLine ();
sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {"); sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {");
sw.WriteLine ("\t\t\tget { return " + SymbolTable.FromNativeReturn (c_type, name) + "; }"); sw.WriteLine ("\t\t\tget { return " + table.FromNativeReturn (c_type, name) + "; }");
sw.WriteLine ("\t\t}"); sw.WriteLine ("\t\t}");
} }
@ -210,7 +211,6 @@ namespace GtkSharp.Generation {
{ {
StreamWriter sw = CreateWriter (); StreamWriter sw = CreateWriter ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Collections;"); sw.WriteLine ("\tusing System.Collections;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;"); sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine (); sw.WriteLine ();

View File

@ -2,7 +2,7 @@
// //
// Author: Mike Kestner <mkestner@speakeasy.net> // Author: Mike Kestner <mkestner@speakeasy.net>
// //
// (c) 2001-2002 Mike Kestner // (c) 2001-2003 Mike Kestner
namespace GtkSharp.Generation { namespace GtkSharp.Generation {
@ -11,109 +11,116 @@ namespace GtkSharp.Generation {
public class SymbolTable { public class SymbolTable {
private static Hashtable alias = new Hashtable (); static SymbolTable table = null;
private static Hashtable complex_types = new Hashtable ();
private static Hashtable simple_types; Hashtable alias = new Hashtable ();
private static Hashtable manually_wrapped_types; Hashtable types = new Hashtable ();
static SymbolTable () public static SymbolTable Table {
get {
if (table == null)
table = new SymbolTable ();
return table;
}
}
public SymbolTable ()
{ {
simple_types = new Hashtable (); Hashtable alias = new Hashtable ();
simple_types.Add ("void", "void"); Hashtable types = new Hashtable ();
simple_types.Add ("gboolean", "bool");
simple_types.Add ("gint", "int"); AddType (new SimpleGen ("void", "void"));
simple_types.Add ("guint", "uint"); AddType (new SimpleGen ("gboolean", "bool"));
simple_types.Add ("glong", "long"); AddType (new SimpleGen ("gint", "int"));
simple_types.Add ("gshort", "short"); AddType (new SimpleGen ("guint", "uint"));
simple_types.Add ("gushort", "ushort"); AddType (new SimpleGen ("glong", "long"));
simple_types.Add ("guint32", "uint"); AddType (new SimpleGen ("gshort", "short"));
simple_types.Add ("guint64", "ulong"); AddType (new SimpleGen ("gushort", "ushort"));
simple_types.Add ("const-gchar", "string"); AddType (new SimpleGen ("guint32", "uint"));
simple_types.Add ("const-char", "string"); AddType (new SimpleGen ("guint64", "ulong"));
simple_types.Add ("gchar", "string"); AddType (new SimpleGen ("const-gchar", "string"));
simple_types.Add ("GObject", "GLib.Object"); AddType (new SimpleGen ("const-char", "string"));
simple_types.Add ("gfloat", "float"); AddType (new SimpleGen ("gchar", "string"));
simple_types.Add ("gdouble", "double"); AddType (new SimpleGen ("gfloat", "float"));
simple_types.Add ("gint8", "byte"); AddType (new SimpleGen ("gdouble", "double"));
simple_types.Add ("guint8", "byte"); AddType (new SimpleGen ("gint8", "sbyte"));
simple_types.Add ("gint16", "short"); AddType (new SimpleGen ("guint8", "byte"));
simple_types.Add ("gint32", "int"); AddType (new SimpleGen ("gint16", "short"));
simple_types.Add ("gint64", "long"); AddType (new SimpleGen ("gint32", "int"));
simple_types.Add ("guint16", "ushort"); AddType (new SimpleGen ("gint64", "long"));
simple_types.Add ("guint1", "bool"); AddType (new SimpleGen ("guint16", "ushort"));
simple_types.Add ("gpointer", "System.IntPtr"); AddType (new SimpleGen ("guint1", "bool"));
simple_types.Add ("guchar", "byte"); AddType (new SimpleGen ("gpointer", "IntPtr"));
simple_types.Add ("long", "long"); AddType (new SimpleGen ("guchar", "byte"));
simple_types.Add ("gulong", "ulong"); AddType (new SimpleGen ("long", "long"));
simple_types.Add ("GQuark", "int"); AddType (new SimpleGen ("gulong", "ulong"));
simple_types.Add ("int", "int"); AddType (new SimpleGen ("GQuark", "int"));
simple_types.Add ("char", "string"); AddType (new SimpleGen ("int", "int"));
simple_types.Add ("double", "double"); AddType (new SimpleGen ("char", "string"));
simple_types.Add ("float", "float"); AddType (new SimpleGen ("double", "double"));
simple_types.Add ("gunichar", "string"); AddType (new SimpleGen ("float", "float"));
simple_types.Add ("uint1", "bool"); AddType (new SimpleGen ("gunichar", "string"));
simple_types.Add ("GPtrArray", "System.IntPtr[]"); AddType (new SimpleGen ("uint1", "bool"));
simple_types.Add ("GType", "uint"); AddType (new SimpleGen ("GPtrArray", "IntPtr[]"));
simple_types.Add ("GError", "IntPtr"); AddType (new SimpleGen ("GType", "uint"));
AddType (new SimpleGen ("GError", "IntPtr"));
// gsize is a system-specific typedef in glibconfig.h, // gsize is a system-specific typedef in glibconfig.h,
// but this should work for now // but this should work for now
simple_types.Add ("gsize", "uint"); AddType (new SimpleGen ("gsize", "uint"));
simple_types.Add ("gssize", "int"); AddType (new SimpleGen ("gssize", "int"));
simple_types.Add ("size_t", "int"); AddType (new SimpleGen ("size_t", "int"));
// FIXME: These ought to be handled properly. // FIXME: These ought to be handled properly.
simple_types.Add ("GMemChunk", "System.IntPtr"); AddType (new SimpleGen ("GMemChunk", "IntPtr"));
simple_types.Add ("GTimeVal", "System.IntPtr"); AddType (new SimpleGen ("GTimeVal", "IntPtr"));
simple_types.Add ("GClosure", "System.IntPtr"); AddType (new SimpleGen ("GClosure", "IntPtr"));
simple_types.Add ("GArray", "System.IntPtr"); AddType (new SimpleGen ("GArray", "IntPtr"));
simple_types.Add ("GData", "System.IntPtr"); AddType (new SimpleGen ("GData", "IntPtr"));
simple_types.Add ("GTypeModule", "GLib.Object"); AddType (new SimpleGen ("GTypeModule", "GLib.Object"));
simple_types.Add ("GHashTable", "System.IntPtr"); AddType (new SimpleGen ("GHashTable", "System.IntPtr"));
simple_types.Add ("va_list", "System.IntPtr"); AddType (new SimpleGen ("va_list", "IntPtr"));
simple_types.Add ("GParamSpec", "System.IntPtr"); AddType (new SimpleGen ("GParamSpec", "IntPtr"));
simple_types.Add ("gconstpointer", "System.IntPtr"); AddType (new SimpleGen ("gconstpointer", "IntPtr"));
manually_wrapped_types = new Hashtable (); AddType (new ManualGen ("GSList", "GLib", "SList"));
manually_wrapped_types.Add ("GSList", "GLib.SList"); AddType (new ManualGen ("GList", "GLib", "List"));
manually_wrapped_types.Add ("GList", "GLib.List"); AddType (new ManualGen ("GValue", "GLib", "Value"));
manually_wrapped_types.Add ("GValue", "GLib.Value"); AddType (new ManualGen ("GObject", "GLib", "Object"));
} }
public static void AddAlias (string name, string type) public void AddAlias (string name, string type)
{ {
type = type.TrimEnd(' ', '\t'); type = type.TrimEnd(' ', '\t');
alias [name] = type; alias [name] = type;
} }
public static void AddType (IGeneratable gen) public void AddType (IGeneratable gen)
{ {
complex_types [gen.CName] = gen; types [gen.CName] = gen;
} }
public static void AddSimpleType (string cname, string name) public int Count {
{
simple_types.Add (cname, name);
}
public static void AddManualType (string cname, string name)
{
manually_wrapped_types.Add (cname, name);
}
public static int Count {
get get
{ {
return complex_types.Count; return types.Count;
} }
} }
public static IEnumerable Generatables { public IEnumerable Generatables {
get { get {
return complex_types.Values; return types.Values;
} }
} }
private static string Trim(string type) public IGeneratable this [string ctype] {
get {
ctype = DeAlias (ctype);
return types [ctype] as IGeneratable;
}
}
private string Trim(string type)
{ {
// HACK: If we don't detect this here, there is no // HACK: If we don't detect this here, there is no
// way of indicating it in the symbol table // way of indicating it in the symbol table
@ -124,243 +131,149 @@ namespace GtkSharp.Generation {
return trim_type; return trim_type;
} }
private static string DeAlias (string type) private string DeAlias (string type)
{ {
type = Trim (type);
while (alias.ContainsKey(type)) while (alias.ContainsKey(type))
type = (string) alias[type]; type = (string) alias[type];
return type; return type;
} }
public static string FromNativeReturn(string c_type, string val) public string FromNativeReturn(string c_type, string val)
{ {
return FromNative (c_type, val, true); IGeneratable gen = this[c_type];
if (gen == null)
return "";
return gen.FromNativeReturn (val);
} }
public static string FromNative(string c_type, string val) public string FromNative(string c_type, string val)
{ {
return FromNative (c_type, val, false); IGeneratable gen = this[c_type];
if (gen == null)
return "";
return gen.FromNative (val);
} }
public static string FromNative(string c_type, string val, bool ret) public string GetCSType(string c_type)
{ {
c_type = Trim(c_type); IGeneratable gen = this[c_type];
c_type = DeAlias(c_type); if (gen == null)
if (simple_types.ContainsKey(c_type)) {
return val;
} else if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (ret)
return gen.FromNativeReturn(val);
else
return gen.FromNative(val);
} else if (manually_wrapped_types.ContainsKey(c_type)) {
string cs_type = (string) manually_wrapped_types[c_type];
return String.Format ("new {0} ({1})", cs_type, val);
} else {
return ""; return "";
} return gen.QualifiedName;
} }
public static string GetCSType(string c_type) public string GetName(string c_type)
{ {
c_type = Trim(c_type); IGeneratable gen = this[c_type];
c_type = DeAlias(c_type); if (gen == null)
if (simple_types.ContainsKey(c_type)) {
return (string) simple_types[c_type];
} else if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
return gen.QualifiedName;
} else if (manually_wrapped_types.ContainsKey(c_type)) {
return (string) manually_wrapped_types[c_type];
} else {
return ""; return "";
} return gen.Name;
} }
public static string GetName(string c_type) public string GetMarshalReturnType(string c_type)
{ {
c_type = Trim(c_type); IGeneratable gen = this[c_type];
c_type = DeAlias(c_type); if (gen == null)
if (simple_types.ContainsKey(c_type) || manually_wrapped_types.ContainsKey(c_type)) {
string stype;
if (simple_types.ContainsKey(c_type))
stype = (string) simple_types[c_type];
else
stype = (string) manually_wrapped_types[c_type];
int dotidx = stype.IndexOf(".");
if (dotidx == -1) {
return stype;
} else {
return stype.Substring(dotidx+1);
}
} else if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
return gen.Name;
} else {
return ""; return "";
} return gen.MarshalReturnType;
} }
public static string GetMarshalReturnType(string c_type) public string GetMarshalType(string c_type)
{ {
return GetMarshalType (c_type, true); IGeneratable gen = this[c_type];
} if (gen == null)
public static string GetMarshalType(string c_type)
{
return GetMarshalType (c_type, false);
}
public static string GetMarshalType(string c_type, bool ret)
{
c_type = Trim(c_type);
c_type = DeAlias(c_type);
if (simple_types.ContainsKey(c_type)) {
return (string) simple_types[c_type];
} else if (manually_wrapped_types.ContainsKey(c_type)) {
return "IntPtr";
} else if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (ret)
return gen.MarshalReturnType;
else
return gen.MarshalType;
} else {
return ""; return "";
} return gen.MarshalType;
} }
public static string CallByName(string c_type, string var_name) public string CallByName(string c_type, string var_name)
{ {
c_type = Trim(c_type); IGeneratable gen = this[c_type];
c_type = DeAlias(c_type); if (gen == null)
if (simple_types.ContainsKey(c_type)) {
return var_name;
} else if (manually_wrapped_types.ContainsKey(c_type)) {
return var_name + ".Handle";
} else if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
return gen.CallByName(var_name);
} else {
return ""; return "";
} return gen.CallByName(var_name);
} }
public static bool IsOpaque(string c_type) public bool IsOpaque(string c_type)
{ {
c_type = Trim(c_type); if (this[c_type] is OpaqueGen)
c_type = DeAlias(c_type); return true;
if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (gen is OpaqueGen) {
return true;
}
}
return false; return false;
} }
public static bool IsBoxed(string c_type) public bool IsBoxed(string c_type)
{ {
c_type = Trim(c_type); if (this[c_type] is BoxedGen)
c_type = DeAlias(c_type); return true;
if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (gen is BoxedGen) {
return true;
}
}
return false; return false;
} }
public static bool IsStruct(string c_type) public bool IsStruct(string c_type)
{ {
c_type = Trim(c_type); if (this[c_type] is StructGen)
c_type = DeAlias(c_type); return true;
if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (gen is StructGen) {
return true;
}
}
return false; return false;
} }
public static bool IsEnum(string c_type) public bool IsEnum(string c_type)
{ {
c_type = Trim(c_type); if (this[c_type] is EnumGen)
c_type = DeAlias(c_type); return true;
if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (gen is EnumGen) {
return true;
}
}
return false; return false;
} }
public static bool IsEnumFlags(string c_type) public bool IsEnumFlags(string c_type)
{ {
c_type = Trim(c_type); c_type = Trim(c_type);
c_type = DeAlias(c_type); c_type = DeAlias(c_type);
if (complex_types.ContainsKey(c_type)) { if (types.ContainsKey(c_type)) {
EnumGen gen = complex_types[c_type] as EnumGen; EnumGen gen = types[c_type] as EnumGen;
return (gen != null && gen.Elem.GetAttribute ("type") == "flags"); return (gen != null && gen.Elem.GetAttribute ("type") == "flags");
} }
return false; return false;
} }
public static bool IsInterface(string c_type) public bool IsInterface(string c_type)
{ {
c_type = Trim(c_type); if (this[c_type] is InterfaceGen)
c_type = DeAlias(c_type); return true;
if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (gen is InterfaceGen) {
return true;
}
}
return false; return false;
} }
public static ClassBase GetClassGen(string c_type) public ClassBase GetClassGen(string c_type)
{ {
c_type = Trim(c_type); return this[c_type] as ClassBase;
c_type = DeAlias(c_type);
return (complex_types[c_type] as ClassBase);
} }
public static bool IsObject(string c_type) public bool IsObject(string c_type)
{ {
c_type = Trim(c_type); if (this[c_type] is ObjectGen)
c_type = DeAlias(c_type); return true;
if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (gen is ObjectGen) {
return true;
}
}
return false; return false;
} }
public static bool IsCallback(string c_type) public bool IsCallback(string c_type)
{ {
c_type = Trim(c_type); if (this[c_type] is CallbackGen)
c_type = DeAlias(c_type); return true;
if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (gen is CallbackGen) {
return true;
}
}
return false; return false;
} }
public static bool IsManuallyWrapped(string c_type) public bool IsManuallyWrapped(string c_type)
{ {
c_type = Trim(c_type); if (this[c_type] is ManualGen)
c_type = DeAlias(c_type); return true;
return manually_wrapped_types.ContainsKey(c_type);
return false;
} }
} }