2004-12-27 Mike Kestner <mkestner@novell.com>
* generator/CallbackGen.cs : use ReturnValue and more of Parameter. * generator/GenBase.cs : remove unused NSElem prop. svn path=/trunk/gtk-sharp/; revision=38115
This commit is contained in:
parent
f3b891e758
commit
4f2d941b51
3 changed files with 34 additions and 64 deletions
|
@ -1,3 +1,8 @@
|
|||
2004-12-27 Mike Kestner <mkestner@novell.com>
|
||||
|
||||
* generator/CallbackGen.cs : use ReturnValue and more of Parameter.
|
||||
* generator/GenBase.cs : remove unused NSElem prop.
|
||||
|
||||
2004-12-27 Jeroen Zwartepoorte <jeroen@xs4all.nl>
|
||||
|
||||
* gnomevfs/Directory.cs: s/uint/FilePermissions/.
|
||||
|
|
|
@ -30,9 +30,11 @@ namespace GtkSharp.Generation {
|
|||
private Parameters parms;
|
||||
private Signature sig = null;
|
||||
private ImportSignature isig = null;
|
||||
private ReturnValue retval;
|
||||
|
||||
public CallbackGen (XmlElement ns, XmlElement elem) : base (ns, elem)
|
||||
{
|
||||
retval = new ReturnValue (elem ["return-type"]);
|
||||
if (elem ["parameters"] != null) {
|
||||
parms = new Parameters (elem ["parameters"], NS);
|
||||
parms.HideData = true;
|
||||
|
@ -68,92 +70,72 @@ namespace GtkSharp.Generation {
|
|||
sw.WriteLine ();
|
||||
sw.WriteLine ("\tusing System;");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("#region Autogenerated code");
|
||||
|
||||
SymbolTable table = SymbolTable.Table;
|
||||
|
||||
XmlElement ret_elem = Elem["return-type"];
|
||||
string rettype = ret_elem.GetAttribute("type");
|
||||
string m_ret = table.GetMarshalReturnType (rettype);
|
||||
string s_ret = table.GetCSType (rettype);
|
||||
ClassBase ret_wrapper = table.GetClassGen (rettype);
|
||||
|
||||
sw.WriteLine ("\tinternal delegate " + m_ret + " " + wrapper + "(" + isig.ToString() + ");");
|
||||
sw.WriteLine ("\tinternal delegate " + retval.MarshalType + " " + wrapper + "(" + isig.ToString() + ");");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("\tinternal class " + Name + "Wrapper : GLib.DelegateWrapper {");
|
||||
if (m_ret != "void") {
|
||||
if (table.IsEnum (rettype)) {
|
||||
sw.WriteLine ("\t\tstatic int _dummy;");
|
||||
} else if (ret_wrapper != null && (ret_wrapper is ObjectGen || ret_wrapper is OpaqueGen)) {
|
||||
// Do nothing
|
||||
} else if (!table.IsStruct (rettype) && !table.IsBoxed (rettype)) {
|
||||
sw.WriteLine ("\t\tstatic {0} _dummy;", m_ret);
|
||||
}
|
||||
}
|
||||
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\tpublic " + m_ret + " NativeCallback (" + isig.ToString() + ")");
|
||||
sw.WriteLine ("\t\tpublic " + retval.MarshalType + " NativeCallback (" + isig.ToString() + ")");
|
||||
sw.WriteLine ("\t\t{");
|
||||
|
||||
int count = (parms != null) ? parms.Count : 0;
|
||||
int idx = 0;
|
||||
bool need_sep = false;
|
||||
string call_str = "";
|
||||
string cleanup_str = "";
|
||||
for (int i = 0; i < count; i++)
|
||||
for (int i = 0, idx = 0; i < count; i++)
|
||||
{
|
||||
string parm_name = parms[i].Name;
|
||||
string ctype = parms[i].CType;
|
||||
Parameter p = parms [i];
|
||||
|
||||
if (i > 0 && parms[i].IsLength && parms[i-1].IsString)
|
||||
if (i > 0 && p.IsLength && parms[i-1].IsString)
|
||||
continue;
|
||||
|
||||
if ((i == count - 1) && ctype == "gpointer" && (parm_name.EndsWith ("data") || parm_name.EndsWith ("data_or_owner")))
|
||||
if ((i == count - 1) && p.IsUserData)
|
||||
continue;
|
||||
|
||||
if (ctype == "GError**") {
|
||||
sw.WriteLine ("\t\t\t" + parm_name + " = IntPtr.Zero;");
|
||||
if (p.CType == "GError**") {
|
||||
sw.WriteLine ("\t\t\t" + p.Name + " = IntPtr.Zero;");
|
||||
continue;
|
||||
}
|
||||
|
||||
string cstype = parms[i].CSType;
|
||||
sw.Write("\t\t\t" + cstype + " _arg" + idx);
|
||||
if (parms[i].PassAs == "out") {
|
||||
IGeneratable gen = p.Generatable;
|
||||
|
||||
sw.Write("\t\t\t" + p.CSType + " _arg" + idx);
|
||||
if (p.PassAs == "out") {
|
||||
sw.WriteLine(";");
|
||||
cleanup_str += "\t\t\t" + parm_name + " = " + table.CallByName (ctype, "_arg" + idx) + ";\n";
|
||||
cleanup_str += "\t\t\t" + p.Name + " = " + gen.CallByName ("_arg" + idx) + ";\n";
|
||||
} else
|
||||
sw.WriteLine(" = " + table.FromNative (ctype, parm_name) + ";");
|
||||
sw.WriteLine(" = " + gen.FromNative (p.Name) + ";");
|
||||
|
||||
if (need_sep)
|
||||
call_str += ", ";
|
||||
else
|
||||
need_sep = true;
|
||||
call_str += String.Format ("{0} _arg{1}", parms[i].PassAs, idx);
|
||||
call_str += String.Format ("{0} _arg{1}", p.PassAs, idx);
|
||||
idx++;
|
||||
}
|
||||
|
||||
sw.Write ("\t\t\t");
|
||||
string invoke = "_managed (" + call_str + ")";
|
||||
if (m_ret != "void") {
|
||||
if (retval.MarshalType != "void") {
|
||||
if (cleanup_str == "")
|
||||
sw.Write ("return ");
|
||||
else {
|
||||
sw.Write (m_ret + " ret = ");
|
||||
sw.Write (retval.MarshalType + " ret = ");
|
||||
cleanup_str += "\t\t\treturn ret;\n";
|
||||
}
|
||||
|
||||
SymbolTable table = SymbolTable.Table;
|
||||
ClassBase ret_wrapper = table.GetClassGen (retval.CType);
|
||||
if (ret_wrapper != null && (ret_wrapper is ObjectGen || ret_wrapper is OpaqueGen))
|
||||
sw.WriteLine ("(({0}) {1}).Handle;", s_ret, invoke);
|
||||
else if (table.IsStruct (rettype) || table.IsBoxed (rettype)) {
|
||||
sw.WriteLine ("(({0}) {1}).Handle;", retval.CSType, invoke);
|
||||
else if (table.IsStruct (retval.CType) || table.IsBoxed (retval.CType)) {
|
||||
// Shoot. I have no idea what to do here.
|
||||
Console.WriteLine ("Struct return type {0} in callback {1}", rettype, CName);
|
||||
Console.WriteLine ("Struct return type {0} in callback {1}", retval.CType, CName);
|
||||
sw.WriteLine ("IntPtr.Zero;");
|
||||
} else if (table.IsEnum (rettype))
|
||||
} else if (table.IsEnum (retval.CType))
|
||||
sw.WriteLine ("(int) {0};", invoke);
|
||||
else
|
||||
sw.WriteLine ("({0}) {1};", m_ret, table.ToNativeReturn (rettype, invoke));
|
||||
sw.WriteLine ("({0}) {1};", retval.MarshalType, table.ToNativeReturn (retval.CType, invoke));
|
||||
} else
|
||||
sw.WriteLine (invoke + ";");
|
||||
|
||||
|
@ -181,19 +163,8 @@ namespace GtkSharp.Generation {
|
|||
|
||||
public override void Generate (GenerationInfo gen_info)
|
||||
{
|
||||
XmlElement ret_elem = Elem["return-type"];
|
||||
if (ret_elem == null) {
|
||||
Console.WriteLine("No return type in callback " + CName);
|
||||
Statistics.ThrottledCount++;
|
||||
return;
|
||||
}
|
||||
|
||||
SymbolTable table = SymbolTable.Table;
|
||||
|
||||
string rettype = ret_elem.GetAttribute("type");
|
||||
string s_ret = table.GetCSType (rettype);
|
||||
if (s_ret == "") {
|
||||
Console.WriteLine("rettype: " + rettype + " in callback " + CName);
|
||||
if (!retval.Validate ()) {
|
||||
Console.WriteLine("rettype: " + retval.CType + " in callback " + CName);
|
||||
Statistics.ThrottledCount++;
|
||||
return;
|
||||
}
|
||||
|
@ -212,7 +183,7 @@ namespace GtkSharp.Generation {
|
|||
sw.WriteLine ();
|
||||
sw.WriteLine ("\tusing System;");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\tpublic delegate " + s_ret + " " + Name + "(" + sig.ToString() + ");");
|
||||
sw.WriteLine ("\tpublic delegate " + retval.CSType + " " + Name + "(" + sig.ToString() + ");");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("}");
|
||||
|
||||
|
|
|
@ -75,12 +75,6 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
private XmlElement NSElem {
|
||||
get {
|
||||
return ns;
|
||||
}
|
||||
}
|
||||
|
||||
public string QualifiedName {
|
||||
get {
|
||||
return NS + "." + Name;
|
||||
|
|
Loading…
Reference in a new issue