2002-05-23 23:43:25 +00:00
|
|
|
// GtkSharp.Generation.Parameters.cs - The Parameters Generation Class.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2001-2002 Mike Kestner
|
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
2002-06-10 12:34:09 +00:00
|
|
|
using System.IO;
|
2002-05-23 23:43:25 +00:00
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
public class Parameters {
|
|
|
|
|
|
|
|
private XmlElement elem;
|
|
|
|
private string import_sig;
|
|
|
|
private string call_string;
|
|
|
|
private string signature;
|
|
|
|
private string signature_types;
|
|
|
|
|
|
|
|
public Parameters (XmlElement elem) {
|
|
|
|
|
|
|
|
this.elem = elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string CallString {
|
|
|
|
get {
|
|
|
|
return call_string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string ImportSig {
|
|
|
|
get {
|
|
|
|
return import_sig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Signature {
|
|
|
|
get {
|
|
|
|
return signature;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string SignatureTypes {
|
|
|
|
get {
|
|
|
|
return signature_types;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Validate ()
|
|
|
|
{
|
|
|
|
signature_types = signature = import_sig = call_string = "";
|
|
|
|
bool need_sep = false;
|
|
|
|
|
|
|
|
foreach (XmlNode parm in elem.ChildNodes) {
|
|
|
|
if (parm.Name != "parameter") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlElement p_elem = (XmlElement) parm;
|
|
|
|
string type = p_elem.GetAttribute("type");
|
|
|
|
string cs_type = SymbolTable.GetCSType(type);
|
|
|
|
string m_type = SymbolTable.GetMarshalType(type);
|
|
|
|
string name = MangleName(p_elem.GetAttribute("name"));
|
|
|
|
string call_parm = SymbolTable.CallByName(type, name);
|
|
|
|
|
|
|
|
if ((cs_type == "") || (name == "") ||
|
|
|
|
(m_type == "") || (call_parm == "")) {
|
|
|
|
Console.Write("Name: " + name + " Type: " + type + " ");
|
|
|
|
return false;
|
|
|
|
}
|
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
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
if (p_elem.HasAttribute("array")) {
|
|
|
|
cs_type += "[]";
|
|
|
|
m_type += "[]";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_sep) {
|
|
|
|
call_string += ", ";
|
|
|
|
import_sig += ", ";
|
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 (type != "GError**")
|
|
|
|
{
|
|
|
|
signature += ", ";
|
|
|
|
signature_types += ":";
|
|
|
|
}
|
2002-05-23 23:43:25 +00:00
|
|
|
} else {
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
|
2002-06-10 12:34:09 +00:00
|
|
|
if (p_elem.HasAttribute("pass_as")) {
|
|
|
|
signature += p_elem.GetAttribute("pass_as") + " ";
|
|
|
|
}
|
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
|
|
|
|
2002-06-20 01:45:13 +00:00
|
|
|
if (type == "GError**") {
|
|
|
|
call_string += "out ";
|
|
|
|
import_sig += "out ";
|
|
|
|
} 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
|
|
|
signature += (cs_type + " " + name);
|
|
|
|
signature_types += cs_type;
|
|
|
|
}
|
2002-05-23 23:43:25 +00:00
|
|
|
call_string += call_parm;
|
|
|
|
import_sig += (m_type + " " + name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2002-06-10 12:34:09 +00:00
|
|
|
|
|
|
|
public void Initialize (StreamWriter sw, bool is_get)
|
|
|
|
{
|
2002-06-19 23:25:12 +00:00
|
|
|
string name = "";
|
2002-06-10 12:34:09 +00:00
|
|
|
foreach (XmlNode parm in elem.ChildNodes) {
|
|
|
|
if (parm.Name != "parameter") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlElement p_elem = (XmlElement) parm;
|
|
|
|
|
|
|
|
string type = SymbolTable.GetCSType(p_elem.GetAttribute ("type"));
|
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
|
|
|
name = MangleName(p_elem.GetAttribute("name"));
|
2002-06-10 12:34:09 +00:00
|
|
|
if (is_get) {
|
|
|
|
sw.WriteLine ("\t\t\t" + type + " " + name + ";");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_get || (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out")) {
|
|
|
|
sw.WriteLine("\t\t\t" + name + " = new " + type + "();");
|
|
|
|
}
|
|
|
|
}
|
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 (ThrowsException)
|
2002-06-20 01:45:13 +00:00
|
|
|
sw.WriteLine ("\t\t\tIntPtr error;");
|
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
|
|
|
public void HandleException (StreamWriter sw)
|
|
|
|
{
|
|
|
|
if (!ThrowsException)
|
|
|
|
return;
|
2002-06-20 01:45:13 +00:00
|
|
|
sw.WriteLine ("\t\t\tif (error != IntPtr.Zero) throw new GLib.GException (error);");
|
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
|
|
|
}
|
|
|
|
|
2002-06-10 12:34:09 +00:00
|
|
|
public bool IsAccessor {
|
|
|
|
get {
|
|
|
|
int length = 0;
|
2002-06-19 23:25:12 +00:00
|
|
|
string pass_as = "";
|
2002-06-10 12:34:09 +00:00
|
|
|
foreach (XmlNode parm in elem.ChildNodes) {
|
|
|
|
if (parm.Name != "parameter") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlElement p_elem = (XmlElement) parm;
|
|
|
|
length++;
|
|
|
|
if (length > 1)
|
|
|
|
return false;
|
|
|
|
if (p_elem.HasAttribute("pass_as"))
|
|
|
|
pass_as = p_elem.GetAttribute("pass_as");
|
|
|
|
}
|
|
|
|
|
|
|
|
return (length == 1 && pass_as == "out");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
public bool ThrowsException {
|
|
|
|
get {
|
2002-06-20 01:45:13 +00:00
|
|
|
if ((elem.ChildNodes == null) || (elem.ChildNodes.Count < 1))
|
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
|
|
|
return false;
|
2002-06-20 01:45:13 +00:00
|
|
|
|
|
|
|
XmlElement p_elem = (XmlElement) elem.ChildNodes[elem.ChildNodes.Count - 1];
|
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 type = p_elem.GetAttribute("type");
|
|
|
|
return (type == "GError**");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-10 12:34:09 +00:00
|
|
|
public string AccessorReturnType {
|
|
|
|
get {
|
|
|
|
foreach (XmlNode parm in elem.ChildNodes) {
|
|
|
|
if (parm.Name != "parameter")
|
|
|
|
continue;
|
|
|
|
XmlElement p_elem = (XmlElement) parm;
|
|
|
|
return SymbolTable.GetCSType(p_elem.GetAttribute ("type"));
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string AccessorName {
|
|
|
|
get {
|
|
|
|
foreach (XmlNode parm in elem.ChildNodes) {
|
|
|
|
if (parm.Name != "parameter")
|
|
|
|
continue;
|
|
|
|
XmlElement p_elem = (XmlElement) parm;
|
|
|
|
return MangleName (p_elem.GetAttribute("name"));
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
private string MangleName(string name)
|
|
|
|
{
|
|
|
|
switch (name) {
|
|
|
|
case "string":
|
|
|
|
return "str1ng";
|
|
|
|
case "event":
|
|
|
|
return "evnt";
|
|
|
|
case "object":
|
|
|
|
return "objekt";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|