2003-12-03 Mike Kestner <mkestner@speakeasy.net>

* generator/CallbackGen.cs : use new sig and isig classes.
	* generator/Ctor.cs : use new sig, isig, and body classes.
	* generator/ImportSignature.cs : isig code spun out from Parameters.
	* generator/Method.cs : use new sig, isig, and body classes.
	* generator/MethodBody.cs : spun Initialize, GetCallString,
	Finish, and Exception throwing methods from Parameters.
	* generator/Parameters.cs : Slayed the evilness that was CreateSignature.
	It is now essentially a container for Parameter classes instead of a
	tangled mess of code trying to do everything remotely related to
	parameter lists. Also completely killed the VAType/IsVarArgs stuff,
	as it can be done with the array and params attrs instead.
	* generator/Property.cs : use new sig class.
	* generator/Signature.cs : new method sig generator extracted from
	Parameters class. add "params" keyword support for tagged parameters.
	* gnome/Gnome.metadata : hide IconList.GetSearchPath (to be manual)
	* gnome/gnome-api.xml : regen
	* gtk/ListStore.custom : kill unneeded overload
	* gtk/TreeStore.custom : kill unneeded overload
	* gtk/Gtk.metadata : mark params/args on *store_newv
	* gtk/gtk-api.xml : regenerated

svn path=/trunk/gtk-sharp/; revision=20755
This commit is contained in:
Mike Kestner 2003-12-03 23:08:14 +00:00
parent 7a10147c5c
commit f61ac5c89c
15 changed files with 458 additions and 378 deletions

View file

@ -1,13 +1,32 @@
2003-12-03 Mike Kestner <mkestner@speakeasy.net>
* generator/CallbackGen.cs : use new sig and isig classes.
* generator/Ctor.cs : use new sig, isig, and body classes.
* generator/ImportSignature.cs : isig code spun out from Parameters.
* generator/Method.cs : use new sig, isig, and body classes.
* generator/MethodBody.cs : spun Initialize, GetCallString,
Finish, and Exception throwing methods from Parameters.
* generator/Parameters.cs : Slayed the evilness that was CreateSignature.
It is now essentially a container for Parameter classes instead of a
tangled mess of code trying to do everything remotely related to
parameter lists. Also completely killed the VAType/IsVarArgs stuff,
as it can be done with the array and params attrs instead.
* generator/Property.cs : use new sig class.
* generator/Signature.cs : new method sig generator extracted from
Parameters class. add "params" keyword support for tagged parameters.
* gnome/Gnome.metadata : hide IconList.GetSearchPath (to be manual)
* gnome/gnome-api.xml : regen
* gtk/ListStore.custom : kill unneeded overload
* gtk/TreeStore.custom : kill unneeded overload
* gtk/Gtk.metadata : mark params/args on *store_newv
* gtk/gtk-api.xml : regenerated
2003-12-03 Ettore Perazzoli <ettore@ximian.com>
* sample/TestDnd.cs: New.
* gtk/TargetEntry.custom: New.
* glue/dragcontext.c: New.
* glib/Object.cs: New public property TypeName in class Object.
* gdk/DragContext.custom: New.
2003-11-30 Mike Kestner <mkestner@speakeasy.net>

View file

@ -13,11 +13,15 @@ namespace GtkSharp.Generation {
public class CallbackGen : GenBase, IGeneratable {
private Parameters parms;
private Signature sig = null;
private ImportSignature isig = null;
public CallbackGen (XmlElement ns, XmlElement elem) : base (ns, elem)
{
if (elem ["parameters"] != null)
if (elem ["parameters"] != null) {
parms = new Parameters (elem ["parameters"], NS);
parms.HideData = true;
}
}
public string MarshalType {
@ -59,6 +63,8 @@ namespace GtkSharp.Generation {
string wrapper = Name + "Native";
string qualname = ns + "Sharp." + wrapper;
isig = new ImportSignature (parms, NS);
StreamWriter sw = gen_info.OpenStream (qualname);
sw.WriteLine ("namespace " + ns + "Sharp {");
@ -67,15 +73,6 @@ namespace GtkSharp.Generation {
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
string import_sig = "";
string sig = "";
if (parms != null)
{
parms.HideData = true;
parms.CreateSignature (false);
import_sig = parms.ImportSig;
sig = parms.Signature;
}
SymbolTable table = SymbolTable.Table;
@ -85,7 +82,7 @@ namespace GtkSharp.Generation {
string s_ret = table.GetCSType (rettype);
ClassBase ret_wrapper = table.GetClassGen (rettype);
sw.WriteLine ("\tinternal delegate " + m_ret + " " + wrapper + "(" + import_sig + ");");
sw.WriteLine ("\tinternal delegate " + m_ret + " " + wrapper + "(" + isig.ToString() + ");");
sw.WriteLine ();
sw.WriteLine ("\tinternal class " + Name + "Wrapper : GLib.DelegateWrapper {");
@ -100,7 +97,7 @@ namespace GtkSharp.Generation {
}
sw.WriteLine ();
sw.WriteLine ("\t\tpublic " + m_ret + " NativeCallback (" + import_sig + ")");
sw.WriteLine ("\t\tpublic " + m_ret + " NativeCallback (" + isig.ToString() + ")");
sw.WriteLine ("\t\t{");
int count = (parms != null) ? parms.Count : 0;
@ -220,20 +217,15 @@ namespace GtkSharp.Generation {
parms = null;
}
StreamWriter sw = gen_info.OpenStream (Name);
sig = new Signature (parms);
string sig = "";
if (parms != null) {
parms.HideData = true;
parms.CreateSignature (false);
sig = parms.Signature;
}
StreamWriter sw = gen_info.OpenStream (Name);
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ();
sw.WriteLine ("\tpublic delegate " + s_ret + " " + Name + "(" + sig + ");");
sw.WriteLine ("\tpublic delegate " + s_ret + " " + Name + "(" + sig.ToString() + ");");
sw.WriteLine ();
sw.WriteLine ("}");

View file

@ -16,6 +16,9 @@ namespace GtkSharp.Generation {
private string libname;
private XmlElement elem;
private Parameters parms;
private Signature sig = null;
private ImportSignature isig = null;
private MethodBody body = null;
private bool preferred;
private String clashName = null;
private ClassBase container_type;
@ -54,68 +57,53 @@ namespace GtkSharp.Generation {
Statistics.ThrottledCount++;
return false;
}
parms.CreateSignature (false);
}
sig = new Signature (parms);
isig = new ImportSignature (parms, container_type.NS);
body = new MethodBody (parms, container_type.NS);
return true;
}
public void InitClashMap (Hashtable clash_map)
{
string sigtypes = (parms != null) ? parms.SignatureTypes : "";
if (clash_map.ContainsKey (sigtypes)) {
int num = (int) clash_map[sigtypes];
clash_map[sigtypes] = ++num;
if (clash_map.ContainsKey (sig.Types)) {
int num = (int) clash_map[sig.Types];
clash_map[sig.Types] = ++num;
}
else
clash_map[sigtypes] = 0;
clash_map[sig.Types] = 0;
}
public void Initialize (Hashtable clash_map)
{
string sig = "()";
string sigtypes = "";
if (parms != null) {
sig = "(" + parms.Signature + ")";
sigtypes = parms.SignatureTypes;
}
int clashes = (int) clash_map[sigtypes];
int clashes = (int) clash_map[sig.Types];
string cname = elem.GetAttribute("cname");
if (force_static || (clashes > 0 && !Preferred)) {
String mname = cname.Substring(cname.IndexOf("new"));
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);
}
clashName = mname + sig;
clashName = mname + "(" + sig.ToString () + ")";
}
}
public void Generate (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
string sigtypes = "";
string sig = "()";
string call = "()";
string isig = "();";
if (parms != null) {
call = "(" + parms.CallString + ")";
sig = "(" + parms.Signature + ")";
isig = "(" + parms.ImportSig + ");";
sigtypes = parms.SignatureTypes;
}
string cname = elem.GetAttribute("cname");
string name = ((XmlElement)elem.ParentNode).GetAttribute("name");
string safety;
if (parms != null && parms.ThrowsException)
if (body.ThrowsException)
safety = "unsafe ";
else
safety = "";
sw.WriteLine("\t\t[DllImport(\"" + libname + "\")]");
sw.WriteLine("\t\tstatic extern " + safety + "IntPtr " + cname + isig);
sw.WriteLine("\t\tstatic extern " + safety + "IntPtr " + cname + "(" + isig.ToString () + ");");
sw.WriteLine();
if (clashName != null) {
@ -136,25 +124,21 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\tpublic static " + safety + modifiers + name + " " + clashName);
sw.WriteLine("\t\t{");
if (parms != null)
parms.Initialize(gen_info, false, false, "");
body.Initialize(gen_info, false, false, "");
sw.Write("\t\t\treturn ");
if (container_type is StructBase)
sw.Write ("{0}.New (", name);
else
sw.Write ("new {0} (", name);
sw.WriteLine (cname + call + ");");
sw.WriteLine (cname + "(" + body.GetCallString (false) + "));");
} else {
sw.WriteLine("\t\tpublic " + safety + name + sig);
sw.WriteLine("\t\tpublic " + safety + name + "(" + sig.ToString() + ")");
sw.WriteLine("\t\t{");
if (parms != null)
parms.Initialize(gen_info, false, false, "");
sw.WriteLine("\t\t\t{0} = {1}{2};", container_type.AssignToName, cname, call);
if (parms != null)
parms.HandleException (sw, "");
body.Initialize(gen_info, false, false, "");
sw.WriteLine("\t\t\t{0} = {1}({2});", container_type.AssignToName, cname, body.GetCallString (false));
body.HandleException (sw, "");
}
sw.WriteLine("\t\t}");

View file

@ -0,0 +1,55 @@
// GtkSharp.Generation.ImportSignature.cs - The ImportSignature Generation Class.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001-2003 Mike Kestner, (c) 2003 Novell, Inc.
namespace GtkSharp.Generation {
using System;
using System.Collections;
public class ImportSignature {
Parameters parameters;
string impl_ns;
public ImportSignature (Parameters parms, string impl_ns)
{
parameters = parms;
this.impl_ns = impl_ns;
}
private bool UsesHandle (IGeneratable igen)
{
return igen is ManualGen || igen is ObjectGen || igen is InterfaceGen || igen is OpaqueGen;
}
public override string ToString ()
{
if (parameters == null)
return "";
string[] parms = new string [parameters.Count];
for (int i = 0; i < parameters.Count; i++) {
Parameter p = parameters [i];
string m_type = p.MarshalType;
if (p.Generatable is CallbackGen)
m_type = impl_ns + "Sharp" + p.MarshalType.Substring(p.MarshalType.IndexOf("."));
parms [i] = "";
if (p.CType == "GError**")
parms [i] += "out ";
else if (p.PassAs != "" && (!m_type.EndsWith ("IntPtr") || UsesHandle (p.Generatable)))
parms [i] += p.PassAs + " ";
parms [i] += m_type + " " + p.Name;
}
string import_sig = String.Join (", ", parms);
import_sig = import_sig.Replace ("out ref", "out");
import_sig = import_sig.Replace ("ref ref", "ref");
return import_sig;
}
}
}

View file

@ -2,7 +2,7 @@
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001-2002 Mike Kestner
// (c) 2001-2003 Mike Kestner, (c) 2003 Novell, Inc.
namespace GtkSharp.Generation {
@ -16,10 +16,13 @@ namespace GtkSharp.Generation {
private string libname;
private XmlElement elem;
private Parameters parms;
private Signature sig;
private ImportSignature isig;
private MethodBody body;
private ClassBase container_type;
private bool initialized = false;
private string sig, isig, call;
private string call;
private string rettype, m_ret, s_ret;
private string element_type = null;
private string name, cname, safety;
@ -30,13 +33,13 @@ namespace GtkSharp.Generation {
public Method (string libname, XmlElement elem, ClassBase container_type)
{
this.elem = elem;
if (elem["parameters"] != null)
if (elem["parameters"] != null) {
parms = new Parameters (elem["parameters"], container_type.NS);
}
this.container_type = container_type;
this.name = elem.GetAttribute("name");
if (name == "GetType")
name = "GetGType";
// override library - used in pixbuf API fixage
if (elem.HasAttribute ("library"))
this.libname = elem.GetAttribute ("library");
else
@ -59,6 +62,12 @@ namespace GtkSharp.Generation {
}
}
private bool IsShared {
get {
return elem.HasAttribute("shared");
}
}
public string Name {
get {
return name;
@ -68,12 +77,6 @@ namespace GtkSharp.Generation {
}
}
public Parameters Params {
get {
return parms;
}
}
public string Protection {
get {
return protection;
@ -89,48 +92,31 @@ namespace GtkSharp.Generation {
}
}
public Signature Signature {
get {
return sig;
}
}
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 == null)
return (b
*/
Method a = this;
Method b = (Method) o;
if (a.Name != b.Name)
return false;
if (a.Params == null)
return b.Params == null;
if (a.Signature == null)
return b.Signature == null;
if (b.Params == null)
if (b.Signature == null)
return false;
return (a.Params.SignatureTypes == b.Params.SignatureTypes);
return (a.Signature.Types == b.Signature.Types);
}
/*
public static bool operator != (Method a, Method b)
{
return !(
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);
}
*/
private bool Initialize ()
{
if (initialized)
@ -156,32 +142,27 @@ namespace GtkSharp.Generation {
cname = elem.GetAttribute("cname");
if (ret_elem.HasAttribute("element_type"))
element_type = ret_elem.GetAttribute("element_type");
bool is_shared = elem.HasAttribute("shared");
if (ret_elem.HasAttribute("array")) {
s_ret += "[]";
m_ret += "[]";
}
if (parms != null && parms.ThrowsException)
safety = "unsafe ";
else
safety = "";
is_get = (((parms != null && ((parms.IsAccessor && s_ret == "void") || (parms.Count == 0 && s_ret != "void"))) || (parms == null && s_ret != "void")) && Name.Length > 3 && (Name.StartsWith ("Get") || Name.StartsWith ("Is") || Name.StartsWith ("Has")));
is_set = ((parms != null && (parms.IsAccessor || (parms.Count == 1 && s_ret == "void"))) && (Name.Length > 3 && Name.Substring(0, 3) == "Set"));
if (parms != null) {
parms.Static = is_shared;
parms.CreateSignature (is_set);
sig = "(" + parms.Signature + ")";
isig = "(" + (is_shared ? "" : container_type.MarshalType + " raw, ") + parms.ImportSig + ");";
call = "(" + (is_shared ? "" : container_type.CallByName () + ", ") + parms.CallString + ")";
} else {
sig = "()";
isig = "(" + (is_shared ? "" : container_type.MarshalType + " raw") + ");";
call = "(" + (is_shared ? "" : container_type.CallByName ()) + ")";
}
if (parms != null)
parms.Static = IsShared;
sig = new Signature (parms);
isig = new ImportSignature (parms, container_type.NS);
body = new MethodBody (parms, container_type.NS);
call = "(" + (IsShared ? "" : container_type.CallByName () + (parms != null ? ", " : "")) + body.GetCallString (is_set) + ")";
if (body.ThrowsException)
safety = "unsafe ";
else
safety = "";
initialized = true;
return true;
@ -217,16 +198,17 @@ namespace GtkSharp.Generation {
sw.Write("static ");
sw.Write(safety);
Method dup = null;
if (Name == "ToString" && Params == null)
if (container_type != null)
dup = container_type.GetMethodRecursively (Name);
if (implementor != null)
dup = implementor.GetMethodRecursively (Name);
if (Name == "ToString" && parms == null)
sw.Write("override ");
else if (Name == "GetGType" && container_type is ObjectGen)
sw.Write("new ");
else if (elem.HasAttribute("new_flag") || (container_type != null && (dup = container_type.GetMethodRecursively (Name)) != null) || (implementor != null && (dup = implementor.GetMethodRecursively (Name)) != null)) {
if (dup != null && dup.parms != null)
dup.parms.CreateSignature (false);
if (elem.HasAttribute("new_flag") || (dup != null && ((dup.parms != null && dup.parms.Signature == parms.Signature) || (dup.parms == null && parms == null))))
else if (elem.HasAttribute("new_flag") || (dup != null && dup.Initialize () && ((dup.Signature != null && sig != null && dup.Signature.ToString() == sig.ToString()) || (dup.Signature == null && sig == null))))
sw.Write("new ");
}
if (is_get || is_set) {
if (s_ret == "void")
@ -239,7 +221,7 @@ namespace GtkSharp.Generation {
sw.Write (Name);
sw.WriteLine(" { ");
} else {
sw.Write(s_ret + " " + Name + sig);
sw.Write(s_ret + " " + Name + "(" + (sig != null ? sig.ToString() : "") + ")");
}
}
@ -282,8 +264,11 @@ namespace GtkSharp.Generation {
public void GenerateImport (StreamWriter sw)
{
string import_sig = IsShared ? "" : container_type.MarshalType + " raw";
import_sig += !IsShared && parms != null ? ", " : "";
import_sig += isig.ToString();
sw.WriteLine("\t\t[DllImport(\"" + libname + "\")]");
sw.WriteLine("\t\tstatic extern " + safety + m_ret + " " + cname + isig);
sw.WriteLine("\t\tstatic extern " + safety + m_ret + " " + cname + "(" + import_sig + ");");
sw.WriteLine();
}
@ -308,8 +293,7 @@ namespace GtkSharp.Generation {
if (comp != null && is_set && parms.AccessorReturnType != comp.s_ret)
{
is_set = false;
parms.CreateSignature (false);
call = "(Handle, " + parms.CallString + ")";
call = "(Handle, " + body.GetCallString (false) + ")";
comp = null;
}
/* some setters take more than one arg */
@ -358,8 +342,7 @@ namespace GtkSharp.Generation {
{
StreamWriter sw = gen_info.Writer;
sw.WriteLine(" {");
if (parms != null)
parms.Initialize(gen_info, is_get, is_set, indent);
body.Initialize(gen_info, is_get, is_set, indent);
SymbolTable table = SymbolTable.Table;
@ -388,10 +371,8 @@ namespace GtkSharp.Generation {
}
}
if (parms != null) {
parms.Finish (sw, indent);
parms.HandleException (sw, indent);
}
body.Finish (sw, indent);
body.HandleException (sw, indent);
if (is_get && parms != null)
sw.WriteLine (indent + "\t\t\treturn " + parms.AccessorName + ";");

179
generator/MethodBody.cs Normal file
View file

@ -0,0 +1,179 @@
// GtkSharp.Generation.MethodBody.cs - The MethodBody Generation Class.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001-2003 Mike Kestner, (c) 2003 Novell, Inc.
namespace GtkSharp.Generation {
using System;
using System.Collections;
using System.IO;
public class MethodBody {
Parameters parameters;
private string impl_ns;
public MethodBody (Parameters parms, string impl_ns) {
parameters = parms;
this.impl_ns = impl_ns;
}
private bool UsesHandle (IGeneratable igen)
{
return igen is ManualGen || igen is ObjectGen || igen is InterfaceGen || igen is OpaqueGen;
}
private string CastFromInt (string type)
{
return type != "int" ? "(" + type + ") " : "";
}
private string CallArrayLength (Parameter array, Parameter length)
{
string result = array.NullOk ? array.Name + " != null ? " : "";
result += CastFromInt (length.CSType) + array.Name + ".Length";
result += array.NullOk ? ": 0" : "";
return result;
}
public string GetCallString (bool is_set)
{
if (parameters == null)
return "";
string[] result = new string [parameters.Count];
for (int i = 0; i < parameters.Count; i++) {
Parameter p = parameters [i];
IGeneratable igen = p.Generatable;
if (p.IsCount) {
if (i > 0 && parameters [i - 1].IsArray) {
result[i] = CallArrayLength (parameters[i - 1], p);
continue;
} else if (i < parameters.Count - 1 && parameters [i + 1].IsArray) {
result[i] = CallArrayLength (parameters[i + 1], p);
continue;
}
}
if (i > 0 && parameters [i - 1].IsString && p.IsLength) {
result[i] = CastFromInt (p.CSType) + parameters [i - 1].Name + ".Length";
continue;
}
string call_parm = p.CallByName (is_set && i == 0 ? "value" : p.Name);
if (p.CType == "GError**") {
result [i] += "out ";
} else if (p.PassAs != "") {
if (!p.MarshalType.EndsWith ("IntPtr"))
result [i] += p.PassAs + " ";
if (igen is EnumGen)
call_parm = p.Name + "_as_int";
else if (UsesHandle (igen) || p.CSType == "GLib.Value") {
call_parm = p.PassAs + " " + call_parm.Replace (".Handle", "_handle");
}
}
if (p.CType == "GError**") {
call_parm = call_parm.Replace (p.Name, "error");
} else if (p.IsUserData && !parameters.HideData && (i == parameters.Count - 1)) {
call_parm = "IntPtr.Zero";
}
result [i] += call_parm;
}
string call_string = String.Join (", ", result);
call_string = call_string.Replace ("out ref", "out");
call_string = call_string.Replace ("ref ref", "ref");
return call_string;
}
public void Initialize (GenerationInfo gen_info, bool is_get, bool is_set, string indent)
{
if (parameters == null)
return;
StreamWriter sw = gen_info.Writer;
for (int i = 0; i < parameters.Count; i++) {
Parameter p = parameters [i];
IGeneratable gen = p.Generatable;
string name = p.Name;
if (is_set)
name = "value";
if (is_get) {
sw.WriteLine (indent + "\t\t\t" + p.CSType + " " + name + ";");
if (gen is ObjectGen || gen is OpaqueGen || p.CSType == "GLib.Value")
sw.WriteLine(indent + "\t\t\t" + name + " = new " + p.CSType + "();");
}
if ((is_get || p.PassAs == "out") && (UsesHandle (gen) || p.CSType == "GLib.Value"))
sw.WriteLine(indent + "\t\t\tIntPtr " + name + "_handle;");
if (p.PassAs == "out" && gen is EnumGen)
sw.WriteLine(indent + "\t\t\tint " + name + "_as_int;");
if (gen is CallbackGen) {
CallbackGen cbgen = gen as CallbackGen;
string wrapper = cbgen.GenWrapper(impl_ns, gen_info);
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = null;", wrapper, name);
sw.Write (indent + "\t\t\t");
if (p.NullOk)
sw.Write ("if ({0} != null) ", name);
sw.WriteLine ("{1}_wrapper = new {0} ({1}, {2});", wrapper, p.Name, parameters.Static ? "null" : "this");
}
}
if (ThrowsException)
sw.WriteLine (indent + "\t\t\tIntPtr error = IntPtr.Zero;");
}
public void Finish (StreamWriter sw, string indent)
{
if (parameters == null)
return;
bool ref_owned_needed = true;
for (int i = 0; i < parameters.Count; i++) {
Parameter p = parameters [i];
if (p.PassAs == "out" && p.Generatable is EnumGen) {
sw.WriteLine(indent + "\t\t\t" + p.Name + " = (" + p.CSType + ") " + p.Name + "_as_int;");
}
IGeneratable gen = p.Generatable;
if (ref_owned_needed && (gen is ObjectGen || gen is InterfaceGen) && p.PassAs == "out") {
ref_owned_needed = false;
sw.WriteLine(indent + "\t\t\tbool ref_owned = false;");
}
if (p.PassAs == "out" && (UsesHandle (gen) || p.CSType == "GLib.Value"))
sw.WriteLine(indent + "\t\t\t" + p.Name + " = " + gen.FromNativeReturn (p.Name + "_handle") + ";");
}
}
public void HandleException (StreamWriter sw, string indent)
{
if (!ThrowsException)
return;
sw.WriteLine (indent + "\t\t\tif (error != IntPtr.Zero) throw new GLib.GException (error);");
}
public bool ThrowsException {
get {
if (parameters == null || parameters.Count < 1)
return false;
return parameters [parameters.Count - 1].CType == "GError**";
}
}
}
}

View file

@ -35,6 +35,8 @@ namespace GtkSharp.Generation {
if (cstype == "void")
cstype = "System.IntPtr";
if (IsArray) {
if (IsParams)
cstype = "params " + cstype;
cstype += "[]";
cstype = cstype.Replace ("ref ", "");
}
@ -100,6 +102,12 @@ namespace GtkSharp.Generation {
}
}
public bool IsParams {
get {
return elem.HasAttribute("params");
}
}
public bool IsString {
get {
return (CSType == "string");
@ -108,7 +116,7 @@ namespace GtkSharp.Generation {
public bool IsUserData {
get {
return CType == "gpointer" && (Name.EndsWith ("data") || Name.EndsWith ("data_or_owner"));
return CSType == "IntPtr" && (Name.EndsWith ("data") || Name.EndsWith ("data_or_owner"));
}
}
@ -155,6 +163,24 @@ namespace GtkSharp.Generation {
}
}
public string CallByName (string call_parm_name)
{
string call_parm;
if (Generatable is CallbackGen)
call_parm = SymbolTable.Table.CallByName (CType, call_parm_name + "_wrapper");
else
call_parm = SymbolTable.Table.CallByName(CType, call_parm_name);
if (NullOk && !CSType.EndsWith ("IntPtr") && !(Generatable is StructBase))
call_parm = String.Format ("({0} != null) ? {1} : {2}", call_parm_name, call_parm, Generatable is CallbackGen ? "null" : "IntPtr.Zero");
if (IsArray)
call_parm = call_parm.Replace ("ref ", "");
return call_parm;
}
public string StudlyName {
get {
string name = elem.GetAttribute("name");
@ -177,10 +203,6 @@ namespace GtkSharp.Generation {
private ArrayList param_list;
private XmlElement elem;
private string impl_ns;
private string import_sig = "";
private string call_string = "";
private string signature = "";
private string signature_types = "";
private bool hide_data;
private bool is_static;
@ -196,12 +218,6 @@ namespace GtkSharp.Generation {
}
}
public string CallString {
get {
return call_string;
}
}
public int Count {
get {
return param_list.Count;
@ -214,30 +230,13 @@ namespace GtkSharp.Generation {
}
}
public string ImportSig {
get {
return import_sig;
}
}
public string Signature {
get {
return signature;
}
}
public string SignatureTypes {
get {
return signature_types;
}
}
public bool HideData {
get { return hide_data; }
set { hide_data = value; }
}
public bool Static {
get { return is_static; }
set { is_static = value; }
}
@ -260,209 +259,12 @@ namespace GtkSharp.Generation {
return true;
}
public void CreateSignature (bool is_set)
{
import_sig = call_string = signature = signature_types = "";
bool need_sep = false;
bool has_callback = hide_data;
SymbolTable table = SymbolTable.Table;
for (int i = 0; i < Count; i++) {
string type = this [i].CType;
string cs_type = this [i].CSType;
string m_type = this [i].MarshalType;
string name = this [i].Name;
if (i > 0 && this [i - 1].IsArray && this [i].IsCount) {
call_string += ", " + this[i-1].Name + " != null ? " + (cs_type != "int" ? "(" + cs_type + ") " : "") + this [i - 1].Name + ".Length : 0";
import_sig += ", " + m_type + " " + name;
continue;
}
if (i > 0 && this [i - 1].IsString && this [i].IsLength) {
call_string += ", " + (cs_type != "int" ? "(" + cs_type + ") " : "") + this [i - 1].Name + ".Length";
import_sig += ", " + m_type + " " + name;
continue;
}
string call_parm_name = name;
if (is_set && i == 0)
call_parm_name = "value";
string call_parm;
if (table.IsCallback (type)) {
has_callback = true;
call_parm = table.CallByName (type, call_parm_name + "_wrapper");
} else
call_parm = table.CallByName(type, call_parm_name);
if (this [i].NullOk && (this [i].IsArray || (!cs_type.EndsWith ("IntPtr") && !table.IsStruct (type))))
call_parm = String.Format ("({0} != null) ? {1} : {2}", call_parm_name, call_parm, table.IsCallback (type) || this[i].IsArray ? "null" : "IntPtr.Zero");
if (this [i].IsArray)
call_parm = call_parm.Replace ("ref ", "");
if (IsVarArgs && i == (Count - 1) && VAType == "length_param") {
cs_type = "params " + cs_type + "[]";
m_type += "[]";
}
if (need_sep) {
call_string += ", ";
import_sig += ", ";
if (type != "GError**" && !(IsVarArgs && i == (Count - 1) && VAType == "length_param"))
{
signature += ", ";
signature_types += ":";
}
} else {
need_sep = true;
}
if (type == "GError**") {
call_string += "out ";
import_sig += "out ";
} else if (this [i].PassAs != "" && !IsVarArgs) {
signature += this [i].PassAs + " ";
// We only need to do this for value types
if (type != "GError**" && m_type != "IntPtr" && m_type != "System.IntPtr")
{
import_sig += this [i].PassAs + " ";
call_string += this [i].PassAs + " ";
}
if (table.IsEnum (type))
call_parm = name + "_as_int";
else if (table.IsObject (type) || table.IsInterface (type) || table.IsOpaque (type) || cs_type == "GLib.Value") {
call_parm = this [i].PassAs + " " + call_parm.Replace (".Handle", "_handle");
import_sig += this [i].PassAs + " ";
}
}
if (IsVarArgs && i == (Count - 2) && VAType == "length_param") {
call_string += this [Count - 1].Name + ".Length";
} else {
if (!(type == "GError**" || (has_callback && (type == "gpointer" || type == "void*") && (i == Count - 1) && (name.EndsWith ("data") || name.EndsWith ("data_or_owner"))))) {
signature += (cs_type + " " + name);
signature_types += cs_type;
} else if (type == "GError**") {
call_parm = call_parm.Replace (name, "error");
} else if ((type == "gpointer" || type == "void*") && (i == Count - 1) && (name.EndsWith ("data") || name.EndsWith ("data_or_owner"))) {
call_parm = "IntPtr.Zero";
}
call_string += call_parm;
}
if (table.IsCallback (type))
m_type = impl_ns + "Sharp" + m_type.Substring(m_type.IndexOf("."));
import_sig += (m_type + " " + name);
}
// FIXME: lame
call_string = call_string.Replace ("out ref", "out");
import_sig = import_sig.Replace ("out ref", "out");
call_string = call_string.Replace ("ref ref", "ref");
import_sig = import_sig.Replace ("ref ref", "ref");
// FIXME: this is also lame, I need to fix the need_sep algo
if (signature.EndsWith (", "))
signature = signature.Remove (signature.Length - 2, 2);
}
public void Initialize (GenerationInfo gen_info, bool is_get, bool is_set, string indent)
{
StreamWriter sw = gen_info.Writer;
foreach (Parameter p in param_list) {
IGeneratable gen = p.Generatable;
string name = p.Name;
if (is_set)
name = "value";
if (is_get) {
sw.WriteLine (indent + "\t\t\t" + p.CSType + " " + name + ";");
if (gen is ObjectGen || gen is OpaqueGen || p.CSType == "GLib.Value")
sw.WriteLine(indent + "\t\t\t" + name + " = new " + p.CSType + "();");
}
if ((is_get || p.PassAs == "out") && (gen is ObjectGen || gen is InterfaceGen || gen is OpaqueGen || p.CSType == "GLib.Value"))
sw.WriteLine(indent + "\t\t\tIntPtr " + name + "_handle;");
if (p.PassAs == "out" && gen is EnumGen)
sw.WriteLine(indent + "\t\t\tint " + name + "_as_int;");
if (gen is CallbackGen) {
CallbackGen cbgen = gen as CallbackGen;
string wrapper = cbgen.GenWrapper(impl_ns, gen_info);
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = null;", wrapper, name);
sw.Write (indent + "\t\t\t");
if (p.NullOk)
sw.Write ("if ({0} != null) ", name);
sw.WriteLine ("{1}_wrapper = new {0} ({1}, {2});", wrapper, name, is_static ? "null" : "this");
}
}
if (ThrowsException)
sw.WriteLine (indent + "\t\t\tIntPtr error = IntPtr.Zero;");
}
public void Finish (StreamWriter sw, string indent)
{
bool ref_owned_needed = true;
foreach (Parameter p in param_list) {
if (p.PassAs == "out" && p.Generatable is EnumGen) {
sw.WriteLine(indent + "\t\t\t" + p.Name + " = (" + p.CSType + ") " + p.Name + "_as_int;");
}
IGeneratable gen = p.Generatable;
if (ref_owned_needed && (gen is ObjectGen || gen is InterfaceGen) && p.PassAs == "out") {
ref_owned_needed = false;
sw.WriteLine(indent + "\t\t\tbool ref_owned = false;");
}
if (p.PassAs == "out" && (gen is ObjectGen || gen is InterfaceGen || gen is OpaqueGen || p.CSType == "GLib.Value"))
sw.WriteLine(indent + "\t\t\t" + p.Name + " = " + gen.FromNativeReturn (p.Name + "_handle") + ";");
}
}
public void HandleException (StreamWriter sw, string indent)
{
if (!ThrowsException)
return;
sw.WriteLine (indent + "\t\t\tif (error != IntPtr.Zero) throw new GLib.GException (error);");
}
public bool IsAccessor {
get {
return Count == 1 && this [0].PassAs == "out";
}
}
public bool ThrowsException {
get {
if (Count < 1)
return false;
return this [Count - 1].CType == "GError**";
}
}
public bool IsVarArgs {
get {
return elem.HasAttribute ("va_type");
}
}
public string VAType {
get {
return elem.GetAttribute ("va_type");
}
}
public string AccessorReturnType {
get {
if (Count > 0)

View file

@ -103,8 +103,8 @@ namespace GtkSharp.Generation {
setter.GenerateImport(sw);
}
if (has_setter && setter.Params[0].CSType != cs_type)
cs_type = setter.Params[0].CSType;
if (has_setter && setter.Signature.Types != cs_type)
cs_type = setter.Signature.Types;
else if (has_getter && getter.ReturnType != cs_type)
cs_type = getter.ReturnType;

75
generator/Signature.cs Normal file
View file

@ -0,0 +1,75 @@
// GtkSharp.Generation.Signature.cs - The Signature Generation Class.
//
// Author: Mike Kestner <mkestner@ximian.com>
//
// (c) 2003 Novell, Inc.
namespace GtkSharp.Generation {
using System;
using System.Collections;
using System.Xml;
public class Signature {
private ArrayList parms = new ArrayList ();
public Signature (Parameters parms)
{
if (parms == null)
return;
bool has_cb = parms.HideData;
for (int i = 0; i < parms.Count; i++) {
Parameter p = parms [i];
if (i > 0 && p.IsLength && parms [i - 1].IsString)
continue;
if (p.IsCount && ((i > 0 && parms [i - 1].IsArray) || (i < parms.Count - 1 && parms [i + 1].IsArray)))
continue;
has_cb = has_cb || p.Generatable is CallbackGen;
if (p.IsUserData && has_cb && (i == parms.Count - 1))
continue;
if (p.CType == "GError**")
continue;
this.parms.Add (p);
}
}
public override string ToString ()
{
if (parms.Count == 0)
return "";
string[] result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms) {
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
result [i++] += p.CSType + " " + p.Name;
}
return String.Join (", ", result);
}
public string Types {
get {
if (parms.Count == 0)
return "";
string[] result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms)
result [i++] = p.CSType;
return String.Join (":", result);
}
}
}
}

View file

@ -66,6 +66,7 @@
<attr path="//object[@cname='GnomeIconList']/signal[@name='FocusIcon']" name="name">IconFocused</attr>
<attr path="//object[@cname='GnomeIconList']/signal[@name='SelectIcon']" name="name">IconSelected</attr>
<attr path="//object[@cname='GnomeIconList']/signal[@name='UnselectIcon']" name="name">IconUnselected</attr>
<attr path="//object[@cname='GnomeIconTheme']/method[@name='GetSearchPath']" name="hidden">1</attr>
<attr path="//object[@cname='GnomePrintConfig']/method/*/*[@type='const-guchar*']" name="type">const-gchar*</attr>
<attr path="//object[@cname='GnomePrintConfig']/method[@name='Get']/return-type" name="type">gchar*</attr>
<attr path="//object[@cname='GnomePrintDialog']/method/*/*[@type='const-guchar*']" name="type">const-gchar*</attr>

View file

@ -3866,7 +3866,7 @@
<method name="GetExampleIconName" cname="gnome_icon_theme_get_example_icon_name">
<return-type type="char*" />
</method>
<method name="GetSearchPath" cname="gnome_icon_theme_get_search_path">
<method name="GetSearchPath" cname="gnome_icon_theme_get_search_path" hidden="1">
<return-type type="void" />
<parameters>
<parameter type="char**" array="true" name="path" />

View file

@ -104,7 +104,8 @@
<attr path="/api/namespace/object[@cname='GtkLayout']/method[@name='SetHadjustment']/*/*[@type='GtkAdjustment*']" name="null_ok">1</attr>
<attr path="/api/namespace/object[@cname='GtkLayout']/method[@name='SetVadjustment']/*/*[@type='GtkAdjustment*']" name="null_ok">1</attr>
<attr path="/api/namespace/object[@cname='GtkLayout']/signal[@name='SetScrollAdjustments']" name="name">ScrollAdjustmentsSet</attr>
<attr path="/api/namespace/object[@cname='GtkListStore']/constructor[@cname='gtk_list_store_newv']/parameters" name="va_type">length_param</attr>
<attr path="/api/namespace/object[@cname='GtkListStore']/constructor[@cname='gtk_list_store_newv']/*/*[@name='types']" name="array">1</attr>
<attr path="/api/namespace/object[@cname='GtkListStore']/constructor[@cname='gtk_list_store_newv']/*/*[@name='types']" name="params">1</attr>
<attr path="/api/namespace/object[@cname='GtkListStore']/method[@name='Append']/*/*[@name='iter']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkListStore']/method[@name='InsertAfter']/*/*[@name='iter']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkListStore']/method[@name='InsertBefore']/*/*[@name='iter']" name="pass_as">out</attr>
@ -188,7 +189,8 @@
<attr path="/api/namespace/object[@cname='GtkTreeModelSort']/method[@name='ConvertChildIterToIter']/*/*[@name='sort_iter']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkTreeModelSort']/method[@name='ConvertIterToChildIter']/*/*[@name='child_iter']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkTreeSelection']/method[@name='GetSelected']/*/*" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkTreeStore']/constructor[@cname='gtk_tree_store_newv']/parameters" name="va_type">length_param</attr>
<attr path="/api/namespace/object[@cname='GtkTreeStore']/constructor[@cname='gtk_tree_store_newv']/*/*[@name='types']" name="array">1</attr>
<attr path="/api/namespace/object[@cname='GtkTreeStore']/constructor[@cname='gtk_tree_store_newv']/*/*[@name='types']" name="params">1</attr>
<attr path="/api/namespace/object[@cname='GtkTreeStore']/method[@name='Append']/*/*[@name='iter']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkTreeStore']/method[@name='InsertAfter']/*/*[@name='iter']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkTreeStore']/method[@name='InsertBefore']/*/*[@name='iter']" name="pass_as">out</attr>

View file

@ -30,11 +30,6 @@
return ret;
}
public void SetColumnTypes (params uint[] types)
{
SetColumnTypes (types.Length, types);
}
public void SetValue (Gtk.TreeIter iter, int column, bool value) {
SetValue (iter, column, new GLib.Value (value));
}

View file

@ -110,11 +110,6 @@
return ret;
}
public void SetColumnTypes (params uint[] types)
{
SetColumnTypes (types.Length, types);
}
public void SetValue (Gtk.TreeIter iter, int column, bool value) {
SetValue (iter, column, new GLib.Value (value));
}

View file

@ -4396,9 +4396,9 @@
</parameters>
</constructor>
<constructor cname="gtk_list_store_newv">
<parameters va_type="length_param">
<parameters>
<parameter type="gint" name="n_columns" />
<parameter type="GType*" name="types" />
<parameter type="GType*" name="types" array="1" params="1" />
</parameters>
</constructor>
<method name="Prepend" cname="gtk_list_store_prepend">
@ -8449,9 +8449,9 @@
</parameters>
</constructor>
<constructor cname="gtk_tree_store_newv">
<parameters va_type="length_param">
<parameters>
<parameter type="gint" name="n_columns" />
<parameter type="GType*" name="types" />
<parameter type="GType*" name="types" array="1" params="1" />
</parameters>
</constructor>
<method name="Prepend" cname="gtk_tree_store_prepend">