2002-05-23 23:43:25 +00:00
|
|
|
// GtkSharp.Generation.Method.cs - The Method Generatable.
|
|
|
|
//
|
|
|
|
// 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 Method {
|
|
|
|
|
|
|
|
private string ns;
|
|
|
|
private XmlElement elem;
|
|
|
|
private Parameters parms;
|
|
|
|
|
|
|
|
public Method (string ns, XmlElement elem)
|
|
|
|
{
|
|
|
|
this.ns = ns;
|
|
|
|
this.elem = elem;
|
|
|
|
if (elem["parameters"] != null)
|
|
|
|
parms = new Parameters (elem["parameters"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Name {
|
|
|
|
get {
|
|
|
|
return elem.GetAttribute("name");
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
elem.SetAttribute("name", value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Parameters Params {
|
|
|
|
get {
|
|
|
|
return parms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool Equals (object o)
|
|
|
|
{
|
|
|
|
if (!(o is Method))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (this == (Method) o);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool operator == (Method a, Method b)
|
|
|
|
{
|
|
|
|
if (a.Name != b.Name)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (a.Params == null)
|
|
|
|
return b.Params == null;
|
|
|
|
|
|
|
|
if (b.Params == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (a.Params.SignatureTypes == b.Params.SignatureTypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool operator != (Method a, Method b)
|
|
|
|
{
|
|
|
|
if (a.Name == b.Name)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (a.Params == null)
|
|
|
|
return b.Params != null;
|
|
|
|
|
|
|
|
if (b.Params == null)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return (a.Params.SignatureTypes != b.Params.SignatureTypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Validate ()
|
|
|
|
{
|
|
|
|
XmlElement ret_elem = elem["return-type"];
|
|
|
|
if (ret_elem == null) {
|
|
|
|
Console.Write("Missing return type in method ");
|
|
|
|
Statistics.ThrottledCount++;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
string rettype = ret_elem.GetAttribute("type");
|
|
|
|
string m_ret = SymbolTable.GetMarshalType(rettype);
|
|
|
|
string s_ret = SymbolTable.GetCSType(rettype);
|
|
|
|
if (m_ret == "" || s_ret == "") {
|
|
|
|
Console.Write("rettype: " + rettype + " method ");
|
|
|
|
Statistics.ThrottledCount++;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Params == null)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return Params.Validate ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Generate (StreamWriter sw)
|
|
|
|
{
|
|
|
|
string sig, isig, call;
|
2002-06-10 12:34:09 +00:00
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
if (parms != null) {
|
|
|
|
sig = "(" + parms.Signature + ")";
|
|
|
|
isig = "(IntPtr raw, " + parms.ImportSig + ");";
|
|
|
|
call = "(Handle, " + parms.CallString + ")";
|
|
|
|
} else {
|
|
|
|
sig = "()";
|
|
|
|
isig = "(IntPtr raw);";
|
|
|
|
call = "(Handle)";
|
|
|
|
}
|
|
|
|
|
|
|
|
string rettype = elem["return-type"].GetAttribute("type");
|
|
|
|
string m_ret = SymbolTable.GetMarshalType(rettype);
|
|
|
|
string s_ret = SymbolTable.GetCSType(rettype);
|
|
|
|
string cname = elem.GetAttribute("cname");
|
|
|
|
|
|
|
|
if (cname[0] == '_') {
|
|
|
|
Statistics.ThrottledCount++;
|
|
|
|
return;
|
|
|
|
}
|
2002-06-14 Rachel Hestilow <hestilow@ximian.com>
* glib/GException.cs: Added.
* generator/Ctor.cs, Method.cs: Tag function as unsafe if it throws
an exception. Call parms.HandleException.
* generator/Paramaters.cs: Add property ThrowsException (based
on a trailing GError**). If ThrowsException, mask GError in the
signature, initialize a GError in Initialize, and add new method
HandleException to throw an exception if error != null.
* generator/SymbolTable.cs: Add gdk-pixbuf DLL, and GError type.
* gdk.imaging, gdk.imaging/Makefile.in, gdk.imaging/makefile.win32:
Added.
* configure.in, Makefile, makefile.win32: Build gdk.imaging.
* gtk/Makefile.in, gtk/makefile.win32: Link against gdk.imaging.
* parser/gapi2xml.pl: Support namespace renaming.
* parser/build.pl: Build gdk-pixbuf as gdk.imaging.
svn path=/trunk/gtk-sharp/; revision=5281
2002-06-14 18:27:04 +00:00
|
|
|
|
|
|
|
string safety;
|
|
|
|
if (parms != null && parms.ThrowsException)
|
|
|
|
safety = "unsafe ";
|
|
|
|
else
|
|
|
|
safety = "";
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2002-06-21 00:50:45 +00:00
|
|
|
sw.WriteLine("\t\t/// <summary> " + Name + " Method </summary>");
|
|
|
|
sw.WriteLine("\t\t/// <remarks> To be completed </remarks>");
|
|
|
|
sw.WriteLine();
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) +
|
|
|
|
"\", CallingConvention=CallingConvention.Cdecl)]");
|
2002-06-14 Rachel Hestilow <hestilow@ximian.com>
* glib/GException.cs: Added.
* generator/Ctor.cs, Method.cs: Tag function as unsafe if it throws
an exception. Call parms.HandleException.
* generator/Paramaters.cs: Add property ThrowsException (based
on a trailing GError**). If ThrowsException, mask GError in the
signature, initialize a GError in Initialize, and add new method
HandleException to throw an exception if error != null.
* generator/SymbolTable.cs: Add gdk-pixbuf DLL, and GError type.
* gdk.imaging, gdk.imaging/Makefile.in, gdk.imaging/makefile.win32:
Added.
* configure.in, Makefile, makefile.win32: Build gdk.imaging.
* gtk/Makefile.in, gtk/makefile.win32: Link against gdk.imaging.
* parser/gapi2xml.pl: Support namespace renaming.
* parser/build.pl: Build gdk-pixbuf as gdk.imaging.
svn path=/trunk/gtk-sharp/; revision=5281
2002-06-14 18:27:04 +00:00
|
|
|
sw.Write("\t\tstatic extern " + safety + m_ret + " " + cname + isig);
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine();
|
|
|
|
|
2002-06-14 Rachel Hestilow <hestilow@ximian.com>
* glib/GException.cs: Added.
* generator/Ctor.cs, Method.cs: Tag function as unsafe if it throws
an exception. Call parms.HandleException.
* generator/Paramaters.cs: Add property ThrowsException (based
on a trailing GError**). If ThrowsException, mask GError in the
signature, initialize a GError in Initialize, and add new method
HandleException to throw an exception if error != null.
* generator/SymbolTable.cs: Add gdk-pixbuf DLL, and GError type.
* gdk.imaging, gdk.imaging/Makefile.in, gdk.imaging/makefile.win32:
Added.
* configure.in, Makefile, makefile.win32: Build gdk.imaging.
* gtk/Makefile.in, gtk/makefile.win32: Link against gdk.imaging.
* parser/gapi2xml.pl: Support namespace renaming.
* parser/build.pl: Build gdk-pixbuf as gdk.imaging.
svn path=/trunk/gtk-sharp/; revision=5281
2002-06-14 18:27:04 +00:00
|
|
|
sw.Write("\t\tpublic " + safety);
|
2002-06-10 12:34:09 +00:00
|
|
|
bool is_get = (parms != null && parms.IsAccessor && Name.Substring(0, 3) == "Get");
|
|
|
|
if (is_get) {
|
|
|
|
s_ret = parms.AccessorReturnType;
|
|
|
|
sw.Write(s_ret);
|
|
|
|
sw.Write(" ");
|
|
|
|
sw.Write(Name.Substring (3));
|
|
|
|
sw.Write(" { get");
|
|
|
|
} else {
|
|
|
|
if (elem.HasAttribute("new_flag"))
|
|
|
|
sw.Write("new ");
|
|
|
|
sw.WriteLine(s_ret + " " + Name + sig);
|
|
|
|
}
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine("\t\t{");
|
2002-06-10 12:34:09 +00:00
|
|
|
if (parms != null)
|
|
|
|
parms.Initialize(sw, is_get);
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.Write("\t\t\t");
|
2002-06-10 12:34:09 +00:00
|
|
|
if (is_get || m_ret == "void") {
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine(cname + call + ";");
|
|
|
|
} else {
|
2002-06-14 Rachel Hestilow <hestilow@ximian.com>
* glib/GException.cs: Added.
* generator/Ctor.cs, Method.cs: Tag function as unsafe if it throws
an exception. Call parms.HandleException.
* generator/Paramaters.cs: Add property ThrowsException (based
on a trailing GError**). If ThrowsException, mask GError in the
signature, initialize a GError in Initialize, and add new method
HandleException to throw an exception if error != null.
* generator/SymbolTable.cs: Add gdk-pixbuf DLL, and GError type.
* gdk.imaging, gdk.imaging/Makefile.in, gdk.imaging/makefile.win32:
Added.
* configure.in, Makefile, makefile.win32: Build gdk.imaging.
* gtk/Makefile.in, gtk/makefile.win32: Link against gdk.imaging.
* parser/gapi2xml.pl: Support namespace renaming.
* parser/build.pl: Build gdk-pixbuf as gdk.imaging.
svn path=/trunk/gtk-sharp/; revision=5281
2002-06-14 18:27:04 +00:00
|
|
|
sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNative(rettype, cname + call) + ";");
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
2002-06-10 12:34:09 +00:00
|
|
|
|
2002-06-14 Rachel Hestilow <hestilow@ximian.com>
* glib/GException.cs: Added.
* generator/Ctor.cs, Method.cs: Tag function as unsafe if it throws
an exception. Call parms.HandleException.
* generator/Paramaters.cs: Add property ThrowsException (based
on a trailing GError**). If ThrowsException, mask GError in the
signature, initialize a GError in Initialize, and add new method
HandleException to throw an exception if error != null.
* generator/SymbolTable.cs: Add gdk-pixbuf DLL, and GError type.
* gdk.imaging, gdk.imaging/Makefile.in, gdk.imaging/makefile.win32:
Added.
* configure.in, Makefile, makefile.win32: Build gdk.imaging.
* gtk/Makefile.in, gtk/makefile.win32: Link against gdk.imaging.
* parser/gapi2xml.pl: Support namespace renaming.
* parser/build.pl: Build gdk-pixbuf as gdk.imaging.
svn path=/trunk/gtk-sharp/; revision=5281
2002-06-14 18:27:04 +00:00
|
|
|
if (parms != null)
|
|
|
|
parms.HandleException (sw);
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2002-06-14 Rachel Hestilow <hestilow@ximian.com>
* glib/GException.cs: Added.
* generator/Ctor.cs, Method.cs: Tag function as unsafe if it throws
an exception. Call parms.HandleException.
* generator/Paramaters.cs: Add property ThrowsException (based
on a trailing GError**). If ThrowsException, mask GError in the
signature, initialize a GError in Initialize, and add new method
HandleException to throw an exception if error != null.
* generator/SymbolTable.cs: Add gdk-pixbuf DLL, and GError type.
* gdk.imaging, gdk.imaging/Makefile.in, gdk.imaging/makefile.win32:
Added.
* configure.in, Makefile, makefile.win32: Build gdk.imaging.
* gtk/Makefile.in, gtk/makefile.win32: Link against gdk.imaging.
* parser/gapi2xml.pl: Support namespace renaming.
* parser/build.pl: Build gdk-pixbuf as gdk.imaging.
svn path=/trunk/gtk-sharp/; revision=5281
2002-06-14 18:27:04 +00:00
|
|
|
if (is_get)
|
|
|
|
sw.WriteLine ("\t\t\treturn " + parms.AccessorName + ";");
|
|
|
|
else if (m_ret != "void")
|
|
|
|
sw.WriteLine ("\t\t\treturn ret;");
|
2002-06-10 12:34:09 +00:00
|
|
|
|
|
|
|
sw.Write("\t\t}");
|
|
|
|
if (is_get)
|
|
|
|
sw.Write(" }");
|
|
|
|
|
|
|
|
sw.WriteLine();
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine();
|
|
|
|
|
|
|
|
Statistics.MethodCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|