2005-01-24 Mike Kestner <mkestner@novell.com>

* gda/Makefile.am : add new custom.
	* gda/XmlConnection.custom : add backcompat static ctor.
	* generator/ClassBase.cs : refactor lookup logic to here from Ctor
	and improve the collision resolution.
	* generator/Ctor.cs : refactor to use MethodBase.
	* generator/Makefile.am : add new file.
	* generator/MethodBase.cs : new base class for ctors and methods.
	* generator/Method.cs : refactor to use MethodBase.
	* generator/StructBase.cs : move some logic from here to Ctor.
	* gnome/CanvasPathDef.custom : add backcompat static ctor.
	* gnome/GPPath.custom : add backcompat static ctor.
	* gnome/Makefile.am : add new custom.
	* gtk/Gtk.metadata : mark a colliding Button ctor shared.

svn path=/trunk/gtk-sharp/; revision=39431
This commit is contained in:
Mike Kestner 2005-01-24 18:25:02 +00:00
parent 0ca2169a8f
commit ea489c2353
19 changed files with 445 additions and 290 deletions

View File

@ -1,3 +1,19 @@
2005-01-24 Mike Kestner <mkestner@novell.com>
* gda/Makefile.am : add new custom.
* gda/XmlConnection.custom : add backcompat static ctor.
* generator/ClassBase.cs : refactor lookup logic to here from Ctor
and improve the collision resolution.
* generator/Ctor.cs : refactor to use MethodBase.
* generator/Makefile.am : add new file.
* generator/MethodBase.cs : new base class for ctors and methods.
* generator/Method.cs : refactor to use MethodBase.
* generator/StructBase.cs : move some logic from here to Ctor.
* gnome/CanvasPathDef.custom : add backcompat static ctor.
* gnome/GPPath.custom : add backcompat static ctor.
* gnome/Makefile.am : add new custom.
* gtk/Gtk.metadata : mark a colliding Button ctor shared.
2005-01-23 Jeroen Zwartepoorte <jeroen@xs4all.nl>
* gtk/ActionGroup.custom: Add a string index for the GetAction method.

View File

@ -229,5 +229,19 @@ Gets / Sets the data source name for the object.
<remarks>Chain to this constructor if you have manually registered a native <see cref="T:GLib.GType" /> value for your subclass.</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public XmlConnection (string filename);" />
<MemberType>Constructor</MemberType>
<ReturnValue />
<Parameters>
<Parameter Name="filename" Type="System.String" />
</Parameters>
<Docs>
<summary>Creates a Connection object from the contents of file.</summary>
<param name="filename">a path to a .connection file.</param>
<returns>a <see cref="T:Gda.XmlConnection" /></returns>
<remarks>The file must be a properly formatted .connection file.</remarks>
</Docs>
</Member>
</Members>
</Type>
</Type>

View File

@ -420,22 +420,6 @@ namespace GtkDemo
<remarks>This is an overload to <see cref="M:Gdk.PixbufLoader.Write(System.Byte[],System.UInt32)" />, which determines the length automatically.</remarks>
</Docs>
</Member>
<Member MemberName="NewWithMimeType">
<MemberSignature Language="C#" Value="public static Gdk.PixbufLoader NewWithMimeType (string mime_type);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>Gdk.PixbufLoader</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="mime_type" Type="System.String" />
</Parameters>
<Docs>
<summary>To be added</summary>
<param name="mime_type">a <see cref="T:System.String" /></param>
<returns>a <see cref="T:Gdk.PixbufLoader" /></returns>
<remarks>To be added</remarks>
</Docs>
</Member>
<Member MemberName="NewWithType">
<MemberSignature Language="C#" Value="public static Gdk.PixbufLoader NewWithType (string image_type);" />
<MemberType>Method</MemberType>
@ -452,5 +436,19 @@ namespace GtkDemo
<remarks>To be added</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public PixbufLoader (string mime_type);" />
<MemberType>Constructor</MemberType>
<ReturnValue />
<Parameters>
<Parameter Name="mime_type" Type="System.String" />
</Parameters>
<Docs>
<summary>To be added</summary>
<param name="mime_type">a <see cref="T:System.String" /></param>
<returns>a <see cref="T:Gdk.PixbufLoader" /></returns>
<remarks>To be added</remarks>
</Docs>
</Member>
</Members>
</Type>
</Type>

View File

@ -516,5 +516,19 @@
<remarks>To be added</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public CanvasPathDef (Art.Bpath bpath);" />
<MemberType>Constructor</MemberType>
<ReturnValue />
<Parameters>
<Parameter Name="bpath" Type="Art.Bpath" />
</Parameters>
<Docs>
<summary>To be added</summary>
<param name="bpath">a <see cref="T:Art.Bpath" /></param>
<returns>a <see cref="T:Gnome.CanvasPathDef" /></returns>
<remarks>To be added</remarks>
</Docs>
</Member>
</Members>
</Type>

View File

@ -516,5 +516,19 @@
<remarks>To be added</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public GPPath (Art.Bpath bpath);" />
<MemberType>Constructor</MemberType>
<ReturnValue />
<Parameters>
<Parameter Name="bpath" Type="Art.Bpath" />
</Parameters>
<Docs>
<summary>To be added</summary>
<param name="bpath">a <see cref="T:Art.Bpath" /></param>
<returns>a <see cref="T:Gnome.GPPath" /></returns>
<remarks>To be added</remarks>
</Docs>
</Member>
</Members>
</Type>

View File

@ -32,26 +32,6 @@
</Attribute>
</Attributes>
<Members>
<Member MemberName="NewFromFileAtSize">
<MemberSignature Language="C#" Value="public static Gnome.Pixmap NewFromFileAtSize (string filename, int width, int height);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>Gnome.Pixmap</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="filename" Type="System.String" />
<Parameter Name="width" Type="System.Int32" />
<Parameter Name="height" Type="System.Int32" />
</Parameters>
<Docs>
<summary>To be added</summary>
<param name="filename">a <see cref="T:System.String" /></param>
<param name="width">a <see cref="T:System.Int32" /></param>
<param name="height">a <see cref="T:System.Int32" /></param>
<returns>a <see cref="T:Gnome.Pixmap" /></returns>
<remarks>To be added</remarks>
</Docs>
</Member>
<Member MemberName="NewFromXpmD">
<MemberSignature Language="C#" Value="public static Gnome.Pixmap NewFromXpmD (string xpm_data);" />
<MemberType>Method</MemberType>
@ -238,5 +218,23 @@
<remarks>Returns the native <see cref="T:GLib.GType" /> value for <see cref="T:Gnome.Pixmap" />.</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public Pixmap (string filename, int width, int height);" />
<MemberType>Constructor</MemberType>
<ReturnValue />
<Parameters>
<Parameter Name="filename" Type="System.String" />
<Parameter Name="width" Type="System.Int32" />
<Parameter Name="height" Type="System.Int32" />
</Parameters>
<Docs>
<summary>To be added</summary>
<param name="filename">a <see cref="T:System.String" /></param>
<param name="width">a <see cref="T:System.Int32" /></param>
<param name="height">a <see cref="T:System.Int32" /></param>
<returns>a <see cref="T:Gnome.Pixmap" /></returns>
<remarks>To be added</remarks>
</Docs>
</Member>
</Members>
</Type>
</Type>

View File

@ -31,22 +31,6 @@
</Interfaces>
<Attributes />
<Members>
<Member MemberName="NewWithMarkup">
<MemberSignature Language="C#" Value="public static Gtk.CellView NewWithMarkup (string markup);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>Gtk.CellView</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="markup" Type="System.String" />
</Parameters>
<Docs>
<summary>Creates a new <see cref="T:Gtk.CellView" /> widget, adds a <see cref="T:Gtk.CellRendererText" /> to it, and makes it show <paramref name="markup" />.</summary>
<param name="markup">a <see cref="T:System.String" /></param>
<returns>a <see cref="T:Gtk.CellView" /></returns>
<remarks />
</Docs>
</Member>
<Member MemberName="NewWithText">
<MemberSignature Language="C#" Value="public static Gtk.CellView NewWithText (string text);" />
<MemberType>Method</MemberType>
@ -393,7 +377,21 @@
<summary>Sets the attribute to model column bindings for a renderer.</summary>
<param name="cell">a <see cref="T:Gtk.CellRenderer" /></param>
<param name="attrs">a <see cref="T:System.Object" /></param>
<remarks>The <paramref name="attrs"/> array should consist of pairs of attribute name and column index.</remarks>
<remarks>The <paramref name="attrs" /> array should consist of pairs of attribute name and column index.</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public CellView (string markup);" />
<MemberType>Constructor</MemberType>
<ReturnValue />
<Parameters>
<Parameter Name="markup" Type="System.String" />
</Parameters>
<Docs>
<summary>Creates a new <see cref="T:Gtk.CellView" /> widget, adds a <see cref="T:Gtk.CellRendererText" /> to it, and makes it show <paramref name="markup" />.</summary>
<param name="markup">a <see cref="T:System.String" /></param>
<returns>a <see cref="T:Gtk.CellView" /></returns>
<remarks />
</Docs>
</Member>
</Members>

View File

@ -12,7 +12,8 @@ references = ../glib/glib-sharp.dll
sources = \
Application.cs
customs =
customs = \
XmlConnection.custom
add_dist = gda-sharp-2.0.pc.in

26
gda/XmlConnection.custom Normal file
View File

@ -0,0 +1,26 @@
// Gda.XmlConnection.custom - XmlConnection class customizations
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (C) 2005 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
public static XmlConnection NewFromFile (string filename)
{
return new XmlConnection (gda_xml_connection_new_from_file (filename));
}

View File

@ -83,7 +83,7 @@ namespace GtkSharp.Generation {
name = member.GetAttribute("name");
while (methods.ContainsKey(name))
name += "mangled";
methods.Add (name, new Method (LibraryName, member, this));
methods.Add (name, new Method (member, this));
break;
case "property":
@ -105,7 +105,7 @@ namespace GtkSharp.Generation {
break;
case "constructor":
ctors.Add (new Ctor (LibraryName, member, this));
ctors.Add (new Ctor (member, this));
break;
default:
@ -332,45 +332,52 @@ namespace GtkSharp.Generation {
public ArrayList Ctors { get { return ctors; } }
bool HasStaticCtor (string name)
{
if (Parent != null && Parent.HasStaticCtor (name))
return true;
foreach (Ctor ctor in Ctors)
if (ctor.StaticName == name)
return true;
return false;
}
private void InitializeCtors ()
{
if (ctors_initted)
return;
if (Parent != null)
Parent.InitializeCtors ();
ArrayList valid_ctors = new ArrayList();
clash_map = new Hashtable();
bool has_preferred = false;
foreach (Ctor ctor in ctors) {
if (ctor.Validate ()) {
ctor.InitClashMap (clash_map);
if (ctor.Preferred)
has_preferred = true;
if (clash_map.Contains (ctor.Signature.Types)) {
Ctor clash = clash_map [ctor.Signature.Types] as Ctor;
Ctor alter = ctor.Preferred ? clash : ctor;
alter.IsStatic = true;
if (Parent != null && Parent.HasStaticCtor (alter.StaticName))
alter.Modifiers = "new ";
} else
clash_map [ctor.Signature.Types] = ctor;
valid_ctors.Add (ctor);
}
else
Console.WriteLine("in Object " + QualifiedName);
} else
Console.WriteLine("in Type " + QualifiedName);
}
ctors = valid_ctors;
if (!has_preferred && ctors.Count > 0)
((Ctor) ctors[0]).Preferred = true;
foreach (Ctor ctor in ctors)
ctor.Initialize (clash_map);
ctors_initted = true;
}
protected virtual void GenCtors (GenerationInfo gen_info)
{
ClassBase klass = this;
while (klass != null) {
klass.InitializeCtors ();
klass = klass.Parent;
}
InitializeCtors ();
foreach (Ctor ctor in ctors)
ctor.Generate (gen_info);
}

View File

@ -1,9 +1,9 @@
// GtkSharp.Generation.Ctor.cs - The Constructor Generation Class.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2004 Novell, Inc.
// Copyright (c) 2004-2005 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
@ -27,147 +27,88 @@ namespace GtkSharp.Generation {
using System.IO;
using System.Xml;
public class Ctor {
public class Ctor : MethodBase {
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;
private bool force_static;
private string name;
private bool needs_chaining = false;
public Ctor (XmlElement elem, ClassBase implementor) : base (elem, implementor)
{
if (elem.HasAttribute ("preferred"))
preferred = true;
if (implementor is ObjectGen)
needs_chaining = true;
name = implementor.Name;
}
public bool Preferred {
get { return preferred; }
set { preferred = value; }
}
public bool ForceStatic {
get { return force_static; }
set { force_static = value; }
}
public Parameters Params {
get { return parms; }
}
public string StaticName {
get {
if (!IsStatic)
return String.Empty;
public Ctor (string libname, XmlElement elem, ClassBase container_type) {
this.libname = libname;
this.elem = elem;
this.container_type = container_type;
XmlElement parms_elem = elem ["parameters"];
if (parms_elem != null)
parms = new Parameters (parms_elem, container_type.NS);
if (elem.HasAttribute ("preferred"))
preferred = true;
if (container_type is ObjectGen)
needs_chaining = true;
}
string[] toks = CName.Substring(CName.IndexOf("new")).Split ('_');
string result = String.Empty;
public bool Validate ()
{
if (parms != null) {
if (!parms.Validate ()) {
Console.Write("in ctor ");
Statistics.ThrottledCount++;
return false;
}
foreach (string tok in toks)
result += tok.Substring(0,1).ToUpper() + tok.Substring(1);
return result;
}
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)
public void GenerateImport (StreamWriter sw)
{
if (clash_map.ContainsKey (sig.Types)) {
int num = (int) clash_map[sig.Types];
clash_map[sig.Types] = ++num;
}
sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\")]");
sw.WriteLine("\t\tstatic extern " + Safety + "IntPtr " + CName + "(" + ImportSignature + ");");
sw.WriteLine();
}
public void GenerateStatic (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
sw.WriteLine("\t\tpublic static " + Safety + Modifiers + name + " " + StaticName + "(" + Signature + ")");
sw.WriteLine("\t\t{");
Body.Initialize(gen_info, false, false, "");
sw.Write("\t\t\treturn ");
if (container_type is StructBase)
sw.Write ("{0}.New (", name);
else
clash_map[sig.Types] = 0;
sw.Write ("new {0} (", name);
sw.WriteLine (CName + "(" + Body.GetCallString (false) + "));");
}
public void Initialize (Hashtable clash_map)
{
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"));
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.ToString () + ")";
}
}
public void Generate (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
string cname = elem.GetAttribute("cname");
string name = ((XmlElement)elem.ParentNode).GetAttribute("name");
string safety;
if (body.ThrowsException)
safety = "unsafe ";
else
safety = "";
SymbolTable table = SymbolTable.Table;
sw.WriteLine("\t\t[DllImport(\"" + libname + "\")]");
sw.WriteLine("\t\tstatic extern " + safety + "IntPtr " + cname + "(" + isig.ToString () + ");");
sw.WriteLine();
GenerateImport (sw);
if (clashName != null) {
string modifiers = "";
Ctor dup = null;
ObjectGen parent = (ObjectGen) container_type.Parent;
while (dup == null && parent != null) {
foreach (Ctor c in parent.Ctors) {
if (c.clashName == clashName) {
dup = c;
modifiers = "new ";
break;
}
}
parent = (ObjectGen) parent.Parent;
}
sw.WriteLine("\t\tpublic static " + safety + modifiers + name + " " + clashName);
sw.WriteLine("\t\t{");
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 + "(" + body.GetCallString (false) + "));");
} else {
sw.WriteLine("\t\tpublic {0}{1} ({2}) {3}", safety, name, sig.ToString(), needs_chaining ? ": base (IntPtr.Zero)" : "");
if (IsStatic)
GenerateStatic (gen_info);
else {
sw.WriteLine("\t\tpublic {0}{1} ({2}) {3}", Safety, name, Signature.ToString(), needs_chaining ? ": base (IntPtr.Zero)" : "");
sw.WriteLine("\t\t{");
if (needs_chaining) {
sw.WriteLine ("\t\t\tif (GetType () != typeof (" + name + ")) {");
if (Params == null || Params.Count == 0) {
if (Parameters == null || Parameters.Count == 0) {
sw.WriteLine ("\t\t\t\tCreateNativeObject (new string [0], new GLib.Value[0]);");
sw.WriteLine ("\t\t\t\treturn;");
} else {
ArrayList names = new ArrayList ();
ArrayList values = new ArrayList ();
for (int i = 0; i < Params.Count; i++) {
Parameter p = Params[i];
for (int i = 0; i < Parameters.Count; i++) {
Parameter p = Parameters[i];
if (container_type.GetPropertyRecursively (p.StudlyName) != null) {
names.Add (p.Name);
values.Add (p.Name);
@ -177,11 +118,11 @@ namespace GtkSharp.Generation {
}
}
if (names.Count == Params.Count) {
if (names.Count == Parameters.Count) {
sw.WriteLine ("\t\t\t\tArrayList vals = new ArrayList();");
sw.WriteLine ("\t\t\t\tArrayList names = new ArrayList();");
for (int i = 0; i < names.Count; i++) {
Parameter p = Params [i];
Parameter p = Parameters [i];
string indent = "\t\t\t\t";
if (p.NullOk && p.Generatable is ObjectGen) {
sw.WriteLine (indent + "if (" + p.Name + " != null) {");
@ -208,9 +149,9 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\t\t\t}");
}
body.Initialize(gen_info, false, false, "");
sw.WriteLine("\t\t\t{0} = {1}({2});", container_type.AssignToName, cname, body.GetCallString (false));
body.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

@ -29,6 +29,7 @@ sources = \
ManagedCallString.cs \
ManualGen.cs \
MarshalGen.cs \
MethodBase.cs \
MethodBody.cs \
Method.cs \
ObjectGen.cs \

View File

@ -27,53 +27,25 @@ namespace GtkSharp.Generation {
using System.IO;
using System.Xml;
public class Method {
public class Method : MethodBase {
private string libname;
private XmlElement elem;
private ReturnValue retval;
private Parameters parms;
private Signature sig;
private ImportSignature isig;
private MethodBody body;
private ClassBase container_type;
private bool initialized = false;
private string call;
private string name;
private string protection = "public";
private bool is_get, is_set;
private bool needs_ref = false;
private bool deprecated = false;
public Method (string libname, XmlElement elem, ClassBase container_type)
public Method (XmlElement elem, ClassBase container_type) : base (elem, container_type)
{
this.elem = elem;
this.retval = new ReturnValue (elem["return-type"]);
if (elem["parameters"] != null) {
parms = new Parameters (elem["parameters"], container_type.NS);
parms.Static = IsShared;
}
this.container_type = container_type;
if (!container_type.IsDeprecated && elem.HasAttribute ("deprecated"))
deprecated = elem.GetAttribute ("deprecated") == "1";
this.name = elem.GetAttribute("name");
if (name == "GetType")
name = "GetGType";
if (elem.HasAttribute ("library"))
this.libname = elem.GetAttribute ("library");
else
this.libname = libname;
// caller does not own reference?
if (elem.HasAttribute ("needs_ref"))
this.needs_ref = (elem.GetAttribute ("needs_ref") == "1");
}
public string CName {
get {
return elem.GetAttribute ("cname");
}
}
public bool IsDeprecated {
@ -94,12 +66,6 @@ namespace GtkSharp.Generation {
}
}
private bool IsShared {
get {
return elem.GetAttribute ("shared") == "true";
}
}
public string Name {
get {
return name;
@ -124,21 +90,6 @@ namespace GtkSharp.Generation {
}
}
string Safety {
get {
if (body.ThrowsException && !(container_type is InterfaceGen))
return "unsafe ";
else
return "";
}
}
public Signature Signature {
get {
return sig;
}
}
public override bool Equals (object o)
{
if (!(o is Method))
@ -168,32 +119,26 @@ namespace GtkSharp.Generation {
if (initialized)
return true;
Parameters parms = Parameters;
is_get = (((parms != null && ((parms.IsAccessor && retval.CSType == "void") || (parms.Count == 0 && retval.CSType != "void"))) || (parms == null && retval.CSType != "void")) && Name.Length > 3 && (Name.StartsWith ("Get") || Name.StartsWith ("Is") || Name.StartsWith ("Has")));
is_set = ((parms != null && (parms.IsAccessor || (parms.Count == 1 && retval.CSType == "void"))) && (Name.Length > 3 && Name.Substring(0, 3) == "Set"));
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) + ")";
call = "(" + (IsStatic ? "" : container_type.CallByName () + (parms != null ? ", " : "")) + Body.GetCallString (is_set) + ")";
initialized = true;
return true;
}
public bool Validate ()
public override bool Validate ()
{
if (!Initialize ())
if (!Initialize () || !base.Validate ())
return false;
if (parms != null && !parms.Validate ()) {
Console.Write ("in method " + Name + " ");
return false;
}
if (!retval.Validate ()) {
Console.Write(" in method " + Name + " ");
return false;
}
return true;
}
@ -205,18 +150,18 @@ namespace GtkSharp.Generation {
else
complement = 'G';
return container_type.GetMethod (complement + elem.GetAttribute("name").Substring (1));
return container_type.GetMethod (complement + name.Substring (1));
}
public string Declaration {
get {
return retval.CSType + " " + Name + " (" + (sig != null ? sig.ToString() : "") + ");";
return retval.CSType + " " + Name + " (" + (Signature != null ? Signature.ToString() : "") + ");";
}
}
private void GenerateDeclCommon (StreamWriter sw, ClassBase implementor)
{
if (elem.GetAttribute ("shared") == "true")
if (IsStatic)
sw.Write("static ");
sw.Write (Safety);
Method dup = null;
@ -225,16 +170,16 @@ namespace GtkSharp.Generation {
if (implementor != null)
dup = implementor.GetMethodRecursively (Name);
if (Name == "ToString" && parms == null)
if (Name == "ToString" && Parameters == null)
sw.Write("override ");
else if (Name == "GetGType" && container_type is ObjectGen)
sw.Write("new ");
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))))
else if (Modifiers == "new " || (dup != null && dup.Initialize () && ((dup.Signature != null && Signature != null && dup.Signature.ToString() == Signature.ToString()) || (dup.Signature == null && Signature == null))))
sw.Write("new ");
if (is_get || is_set) {
if (retval.CSType == "void")
sw.Write (parms.AccessorReturnType);
sw.Write (Parameters.AccessorReturnType);
else
sw.Write(retval.CSType);
sw.Write(" ");
@ -244,9 +189,9 @@ namespace GtkSharp.Generation {
sw.Write (Name);
sw.WriteLine(" { ");
} else if (IsAccessor) {
sw.Write (sig.AccessorType + " " + Name + "(" + sig.AsAccessor + ")");
sw.Write (Signature.AccessorType + " " + Name + "(" + Signature.AsAccessor + ")");
} else {
sw.Write(retval.CSType + " " + Name + "(" + (sig != null ? sig.ToString() : "") + ")");
sw.Write(retval.CSType + " " + Name + "(" + (Signature != null ? Signature.ToString() : "") + ")");
}
}
@ -255,8 +200,7 @@ namespace GtkSharp.Generation {
if (!Initialize ())
return;
if (elem.HasAttribute("shared") &&
(elem.GetAttribute("shared") == "true"))
if (IsStatic)
return;
if (is_get || is_set)
@ -290,10 +234,10 @@ 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 + "\")]");
string import_sig = IsStatic ? "" : container_type.MarshalType + " raw";
import_sig += !IsStatic && Parameters != null ? ", " : "";
import_sig += ImportSignature.ToString();
sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\")]");
if (retval.MarshalType.StartsWith ("[return:"))
sw.WriteLine("\t\t" + retval.MarshalType + " static extern " + Safety + retval.CSType + " " + CName + "(" + import_sig + ");");
else
@ -308,22 +252,21 @@ namespace GtkSharp.Generation {
if (!Initialize ())
return;
if (implementor != null && elem.HasAttribute("shared") &&
(elem.GetAttribute ("shared") == "true"))
if (implementor != null && IsStatic)
return;
/* we are generated by the get Method, if there is one */
if (is_set || is_get)
{
if (!elem.HasAttribute("new_flag") && container_type.GetPropertyRecursively (Name.Substring (3)) != null)
if (Modifiers != "new " && container_type.GetPropertyRecursively (Name.Substring (3)) != null)
return;
comp = GetComplement ();
if (comp != null && comp.Validate () && is_set && parms.AccessorReturnType == comp.ReturnType)
if (comp != null && comp.Validate () && is_set && Parameters.AccessorReturnType == comp.ReturnType)
return;
if (comp != null && is_set && parms.AccessorReturnType != comp.ReturnType)
if (comp != null && is_set && Parameters.AccessorReturnType != comp.ReturnType)
{
is_set = false;
call = "(Handle, " + body.GetCallString (false) + ")";
call = "(Handle, " + Body.GetCallString (false) + ")";
comp = null;
}
/* some setters take more than one arg */
@ -332,7 +275,7 @@ namespace GtkSharp.Generation {
}
GenerateImport (gen_info.Writer);
if (comp != null && retval.CSType == comp.parms.AccessorReturnType)
if (comp != null && retval.CSType == comp.Parameters.AccessorReturnType)
comp.GenerateImport (gen_info.Writer);
if (IsDeprecated)
@ -353,7 +296,7 @@ namespace GtkSharp.Generation {
if (is_get || is_set)
{
if (comp != null && retval.CSType == comp.parms.AccessorReturnType)
if (comp != null && retval.CSType == comp.Parameters.AccessorReturnType)
{
gen_info.Writer.WriteLine ();
gen_info.Writer.Write ("\t\t\tset");
@ -375,8 +318,8 @@ namespace GtkSharp.Generation {
StreamWriter sw = gen_info.Writer;
sw.WriteLine(" {");
if (IsAccessor)
body.InitAccessor (sw, sig, indent);
body.Initialize(gen_info, is_get, is_set, indent);
Body.InitAccessor (sw, Signature, indent);
Body.Initialize(gen_info, is_get, is_set, indent);
SymbolTable table = SymbolTable.Table;
IGeneratable ret_igen = table [retval.CType];
@ -400,22 +343,22 @@ namespace GtkSharp.Generation {
sw.WriteLine(retval.CSType + " ret = " + table.FromNativeReturn(retval.CType, raw_parms) + ";");
}
body.Finish (sw, indent);
body.HandleException (sw, indent);
Body.Finish (sw, indent);
Body.HandleException (sw, indent);
if (is_get && parms != null)
sw.WriteLine (indent + "\t\t\treturn " + parms.AccessorName + ";");
if (is_get && Parameters != null)
sw.WriteLine (indent + "\t\t\treturn " + Parameters.AccessorName + ";");
else if (retval.MarshalType != "void")
sw.WriteLine (indent + "\t\t\treturn ret;");
else if (IsAccessor)
body.FinishAccessor (sw, sig, indent);
Body.FinishAccessor (sw, Signature, indent);
sw.Write(indent + "\t\t}");
}
bool IsAccessor {
get {
return retval.CSType == "void" && sig.IsAccessor;
return retval.CSType == "void" && Signature.IsAccessor;
}
}
}

133
generator/MethodBase.cs Normal file
View File

@ -0,0 +1,133 @@
// GtkSharp.Generation.MethodBase.cs - function element base class.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2004-2005 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
namespace GtkSharp.Generation {
using System;
using System.Xml;
public abstract class MethodBase {
XmlElement elem;
protected ClassBase container_type;
Parameters parms;
bool is_static = false;
string mods = String.Empty;
protected MethodBase (XmlElement elem, ClassBase container_type)
{
this.elem = elem;
this.container_type = container_type;
XmlElement parms_elem = elem ["parameters"];
if (parms_elem != null)
parms = new Parameters (parms_elem, container_type.NS);
IsStatic = elem.GetAttribute ("shared") == "true";
if (elem.HasAttribute ("new_flag"))
mods = "new ";
}
MethodBody body;
public MethodBody Body {
get {
if (body == null)
body = new MethodBody (parms, container_type.NS);
return body;
}
}
public string CName {
get {
return elem.GetAttribute ("cname");
}
}
ImportSignature isig;
public ImportSignature ImportSignature {
get {
if (isig == null)
isig = new ImportSignature (parms, container_type.NS);
return isig;
}
}
public bool IsStatic {
get {
return is_static;
}
set {
is_static = value;
if (parms != null)
parms.Static = value;
}
}
public string LibraryName {
get {
if (elem.HasAttribute ("library"))
return elem.GetAttribute ("library");
return container_type.LibraryName;
}
}
public string Modifiers {
get {
return mods;
}
set {
mods = value;
}
}
protected Parameters Parameters {
get {
return parms;
}
}
protected string Safety {
get {
return Body.ThrowsException && !(container_type is InterfaceGen) ? "unsafe " : "";
}
}
Signature sig;
public Signature Signature {
get {
if (sig == null)
sig = new Signature (parms);
return sig;
}
}
public virtual bool Validate ()
{
if (parms != null && !parms.Validate ()) {
Console.Write("in ctor ");
Statistics.ThrottledCount++;
return false;
}
return true;
}
}
}

View File

@ -186,11 +186,8 @@ namespace GtkSharp.Generation {
sw.WriteLine ();
}
foreach (Ctor ctor in Ctors) {
ctor.ForceStatic = true;
if (ctor.Params != null)
ctor.Params.Static = true;
}
foreach (Ctor ctor in Ctors)
ctor.IsStatic = true;
base.GenCtors (gen_info);
}

View File

@ -0,0 +1,26 @@
// Gnome.CanvasPathDef.custom - Gnome CanvasPathDef class customizations
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (C) 2005 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
public static CanvasPathDef NewFromBpath (Art.Bpath bpath)
{
return new CanvasPathDef (gnome_canvas_path_def_new_from_bpath (ref bpath));
}

26
gnome/GPPath.custom Normal file
View File

@ -0,0 +1,26 @@
// Gnome.GPPath.custom - Gnome GPPath class customizations
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (C) 2005 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
public static GPPath NewFromBpath (Art.Bpath bpath)
{
return new GPPath (gp_path_new_from_bpath (ref bpath));
}

View File

@ -29,6 +29,7 @@ customs = \
CanvasGroup.custom \
CanvasItem.custom \
CanvasLine.custom \
CanvasPathDef.custom \
CanvasPixbuf.custom \
CanvasPoints.custom \
CanvasPolygon.custom \

View File

@ -114,6 +114,7 @@
<attr path="/api/namespace/object[@cname='GtkBin']/method[@name='GetChild']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkBox']/method[@name='PackEndDefaults']" name="name">PackEnd</attr>
<attr path="/api/namespace/object[@cname='GtkBox']/method[@name='PackStartDefaults']" name="name">PackStart</attr>
<attr path="/api/namespace/object[@cname='GtkButton']/constructor[@cname='gtk_button_new_with_label']" name="shared">true</attr>
<attr path="/api/namespace/object[@cname='GtkButton']/constructor[@cname='gtk_button_new_from_stock']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkButton']/method[@name='Clicked']" name="name">Click</attr>
<attr path="/api/namespace/object[@cname='GtkButton']/method[@name='Pressed']" name="name">Press</attr>