From 8d530210798e1ac64148ffad4d429a548be2e8df Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Mon, 27 Dec 2004 17:38:52 +0000 Subject: [PATCH] 2004-12-27 Mike Kestner * generator/AliasGen.cs : derive from SimpleBase. * generator/ConstStringGen.cs : derive from SimpleBase. * generator/GObjectGen.cs : kill. now uses ManualGen. * generator/GStringGen.cs : kill. now uses MarshalGen. * generator/GUnicharGen.cs : kill. now uses MarshalGen. * generator/LPGen.cs : derive from SimpleGen. * generator/Makefile.am : update source files. * generator/ManualGen : make this general for handle types. * generator/MarshalGen : new CallByName/FromNative formatter class. * generator/SymbolTable.cs : needed some reorganizing and some restructuring of types to use MarshalGen. * generator/TimeTGen.cs : kill. now uses MarshalGen. svn path=/trunk/gtk-sharp/; revision=38109 --- ChangeLog | 15 +++ generator/AliasGen.cs | 2 +- generator/ConstStringGen.cs | 2 +- generator/GObjectGen.cs | 37 -------- generator/GUnicharGen.cs | 47 ---------- generator/LPGen.cs | 2 +- generator/Makefile.am | 5 +- generator/ManualGen.cs | 25 ++--- generator/{GStringGen.cs => MarshalGen.cs} | 104 +++++++++++---------- generator/SymbolTable.cs | 78 ++++++++-------- generator/TimeTGen.cs | 48 ---------- 11 files changed, 128 insertions(+), 237 deletions(-) delete mode 100644 generator/GObjectGen.cs delete mode 100644 generator/GUnicharGen.cs rename generator/{GStringGen.cs => MarshalGen.cs} (63%) delete mode 100644 generator/TimeTGen.cs diff --git a/ChangeLog b/ChangeLog index 054c67a85..d0754c02e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-12-27 Mike Kestner + + * generator/AliasGen.cs : derive from SimpleBase. + * generator/ConstStringGen.cs : derive from SimpleBase. + * generator/GObjectGen.cs : kill. now uses ManualGen. + * generator/GStringGen.cs : kill. now uses MarshalGen. + * generator/GUnicharGen.cs : kill. now uses MarshalGen. + * generator/LPGen.cs : derive from SimpleGen. + * generator/Makefile.am : update source files. + * generator/ManualGen : make this general for handle types. + * generator/MarshalGen : new CallByName/FromNative formatter class. + * generator/SymbolTable.cs : needed some reorganizing and some + restructuring of types to use MarshalGen. + * generator/TimeTGen.cs : kill. now uses MarshalGen. + 2004-12-26 Mike Kestner * generator/Makefile.am : add new file. diff --git a/generator/AliasGen.cs b/generator/AliasGen.cs index 4a157b90e..8bfdacc5b 100644 --- a/generator/AliasGen.cs +++ b/generator/AliasGen.cs @@ -22,7 +22,7 @@ namespace GtkSharp.Generation { using System; - public class AliasGen : SimpleGen { + public class AliasGen : SimpleBase { public AliasGen (string ctype, string type) : base (ctype, type) {} } diff --git a/generator/ConstStringGen.cs b/generator/ConstStringGen.cs index 63a8784fa..6f2ae6a01 100644 --- a/generator/ConstStringGen.cs +++ b/generator/ConstStringGen.cs @@ -23,7 +23,7 @@ namespace GtkSharp.Generation { using System; - public class ConstStringGen : SimpleGen { + public class ConstStringGen : SimpleBase { public ConstStringGen (string ctype) : base (ctype, "string") { diff --git a/generator/GObjectGen.cs b/generator/GObjectGen.cs deleted file mode 100644 index 71d07298b..000000000 --- a/generator/GObjectGen.cs +++ /dev/null @@ -1,37 +0,0 @@ -// GtkSharp.Generation.GObjectGen.cs - The GObject generatable -// -// Note: This generatable only handles GObject* values. GObject subclasses -// are handled by ObjectGen. -// -// Author: Rachel Hestilow -// -// Copyright (c) 2004 Rachel Hestilow -// -// 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 { - - public class GObjectGen : ManualGen { - - public GObjectGen () : base ("GObject", "GLib.Object") {} - - public override string FromNative(string var) - { - return "GLib.Object.GetObject (" + var + ")"; - } - } -} - diff --git a/generator/GUnicharGen.cs b/generator/GUnicharGen.cs deleted file mode 100644 index 5d37a3358..000000000 --- a/generator/GUnicharGen.cs +++ /dev/null @@ -1,47 +0,0 @@ -// GtkSharp.Generation.GUnicharGen.cs - The gunichar Generatable. -// -// Author: Mike Kestner -// -// Copyright (c) 2004 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; - - public class GUnicharGen : SimpleBase { - - public GUnicharGen () : base ("gunichar", "char") {} - - public override string MarshalType { - get { - return "uint"; - } - } - - public override string CallByName (string var_name) - { - return "GLib.Marshaller.CharToGUnichar (" + var_name + ")"; - } - - public override string FromNative(string var) - { - return "GLib.Marshaller.GUnicharToChar (" + var + ")"; - } - } -} - diff --git a/generator/LPGen.cs b/generator/LPGen.cs index 430d95aa8..4b76efb50 100644 --- a/generator/LPGen.cs +++ b/generator/LPGen.cs @@ -23,7 +23,7 @@ namespace GtkSharp.Generation { using System; - public class LPGen : SimpleBase { + public class LPGen : SimpleGen { public LPGen (string ctype) : base (ctype, "long") {} diff --git a/generator/Makefile.am b/generator/Makefile.am index f2e1dcc37..567f21517 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -21,9 +21,6 @@ sources = \ Field.cs \ GenBase.cs \ GenerationInfo.cs \ - GObjectGen.cs \ - GStringGen.cs \ - GUnicharGen.cs \ IGeneratable.cs \ ImportSignature.cs \ InterfaceGen.cs \ @@ -31,6 +28,7 @@ sources = \ LPUGen.cs \ ManagedCallString.cs \ ManualGen.cs \ + MarshalGen.cs \ MethodBody.cs \ Method.cs \ ObjectGen.cs \ @@ -49,7 +47,6 @@ sources = \ StructBase.cs \ StructGen.cs \ SymbolTable.cs \ - TimeTGen.cs \ VirtualMethod.cs \ VMSignature.cs diff --git a/generator/ManualGen.cs b/generator/ManualGen.cs index 348e1d53f..3f9556f67 100644 --- a/generator/ManualGen.cs +++ b/generator/ManualGen.cs @@ -1,8 +1,9 @@ -// GtkSharp.Generation.ManualGen.cs - The Manually wrapped type Generatable. +// GtkSharp.Generation.ManualGen.cs - Ungenerated handle type Generatable. // -// Author: Mike Kestner +// Author: Mike Kestner // // Copyright (c) 2003 Mike Kestner +// Copyright (c) 2004 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 @@ -25,30 +26,32 @@ namespace GtkSharp.Generation { public class ManualGen : SimpleBase { - string handle; + string from_fmt; - public ManualGen (string ctype, string type) : this (ctype, type, "Handle") {} - - public ManualGen (string ctype, string type, string handle) : base (ctype, type) + public ManualGen (string ctype, string type) : base (ctype, type) { - this.handle = handle; + from_fmt = "new " + QualifiedName + "({0})"; + } + + public ManualGen (string ctype, string type, string from_fmt) : base (ctype, type) + { + this.from_fmt = from_fmt; } public override string MarshalType { - get - { + get { return "IntPtr"; } } public override string CallByName (string var_name) { - return var_name + "." + handle; + return var_name + ".Handle"; } public override string FromNative(string var) { - return "new " + QualifiedName + "(" + var + ")"; + return String.Format (from_fmt, var); } } } diff --git a/generator/GStringGen.cs b/generator/MarshalGen.cs similarity index 63% rename from generator/GStringGen.cs rename to generator/MarshalGen.cs index bb810d2de..01f3f128f 100644 --- a/generator/GStringGen.cs +++ b/generator/MarshalGen.cs @@ -1,48 +1,56 @@ -// GtkSharp.Generation.GStringGen.cs - The GString type Generatable. -// -// Author: Mike Kestner -// -// Copyright (c) 2004 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; - - public class GStringGen : SimpleBase { - - public GStringGen () : base ("GString", "string") {} - - public override string MarshalType { - get { - return "IntPtr"; - } - } - - public override string CallByName (string var_name) - { - return "(new GLib.GString (" + var_name + ")).Handle"; - } - - public override string FromNative (string var) - { - return "GLib.GString.PtrToString (" + var + ")"; - } - } - -} - +// GtkSharp.Generation.MarshalGen.cs - Simple marshaling Generatable. +// +// Author: Mike Kestner +// +// Copyright (c) 2004 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; + + public class MarshalGen : SimpleBase { + + string mtype; + string call_fmt; + string from_fmt; + + public MarshalGen (string ctype, string type, string mtype, string call_fmt, string from_fmt) : base (ctype, type) + { + this.mtype = mtype; + this.call_fmt = call_fmt; + this.from_fmt = from_fmt; + } + + public override string MarshalType { + get { + return mtype; + } + } + + public override string CallByName (string var) + { + return String.Format (call_fmt, var); + } + + public override string FromNative (string var) + { + return String.Format (from_fmt, var); + } + } +} + diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 3a28bb100..74d966cbf 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -42,52 +42,38 @@ namespace GtkSharp.Generation { public SymbolTable () { + // Simple easily mapped types AddType (new SimpleGen ("void", "void")); + AddType (new SimpleGen ("gpointer", "IntPtr")); AddType (new SimpleGen ("gboolean", "bool")); AddType (new SimpleGen ("gint", "int")); AddType (new SimpleGen ("guint", "uint")); + AddType (new SimpleGen ("int", "int")); AddType (new SimpleGen ("unsigned int", "uint")); AddType (new SimpleGen ("gshort", "short")); AddType (new SimpleGen ("gushort", "ushort")); - AddType (new SimpleGen ("guint32", "uint")); - AddType (new SimpleGen ("guint64", "ulong")); - // Const returned strings must be generated - // differently from memory-managed strings - AddType (new ConstStringGen ("const-gchar")); - AddType (new ConstStringGen ("const-xmlChar")); - AddType (new ConstStringGen ("const-char")); - AddType (new StringGen ("gchar")); - AddType (new SimpleGen ("gfloat", "float")); - AddType (new SimpleGen ("gdouble", "double")); + AddType (new SimpleGen ("short", "short")); + AddType (new SimpleGen ("guchar", "byte")); + AddType (new SimpleGen ("unsigned char", "byte")); + AddType (new SimpleGen ("guint1", "bool")); + AddType (new SimpleGen ("uint1", "bool")); AddType (new SimpleGen ("gint8", "sbyte")); AddType (new SimpleGen ("guint8", "byte")); AddType (new SimpleGen ("gint16", "short")); - AddType (new SimpleGen ("gint32", "int")); - AddType (new SimpleGen ("gint64", "long")); AddType (new SimpleGen ("guint16", "ushort")); - AddType (new SimpleGen ("guint1", "bool")); - AddType (new SimpleGen ("gpointer", "IntPtr")); - AddType (new SimpleGen ("guchar", "byte")); - AddType (new SimpleGen ("unsigned char", "byte")); - AddType (new SimpleGen ("short", "short")); - AddType (new SimpleGen ("GQuark", "int")); - AddType (new SimpleGen ("int", "int")); - AddType (new StringGen ("char")); - AddType (new SimpleGen ("double", "double")); + AddType (new SimpleGen ("gint32", "int")); + AddType (new SimpleGen ("guint32", "uint")); + AddType (new SimpleGen ("gint64", "long")); + AddType (new SimpleGen ("guint64", "ulong")); + AddType (new SimpleGen ("gfloat", "float")); AddType (new SimpleGen ("float", "float")); - AddType (new SimpleGen ("uint1", "bool")); - AddType (new SimpleGen ("GC", "IntPtr")); - AddType (new SimpleGen ("GPtrArray", "IntPtr[]")); - AddType (new ManualGen ("GType", "GLib.GType", "Val")); - AddType (new SimpleGen ("GError", "IntPtr")); - - // gsize is a system-specific typedef in glibconfig.h, - // but this should work for now + AddType (new SimpleGen ("gdouble", "double")); + AddType (new SimpleGen ("double", "double")); AddType (new SimpleGen ("gsize", "uint")); AddType (new SimpleGen ("gssize", "int")); - AddType (new AliasGen ("off_t", "size_t")); + AddType (new SimpleGen ("GQuark", "int")); - // system specific integer types. these will break on any + // platform specific integer types. these will break on any // platform where sizeof (long) != sizeof (pointer) AddType (new LPGen ("ssize_t")); AddType (new LPGen ("long")); @@ -95,10 +81,30 @@ namespace GtkSharp.Generation { AddType (new LPUGen ("size_t")); AddType (new LPUGen ("ulong")); AddType (new LPUGen ("gulong")); - AddType (new GUnicharGen ()); - + AddType (new AliasGen ("off_t", "size_t")); + + // string types + AddType (new ConstStringGen ("const-gchar")); + AddType (new ConstStringGen ("const-xmlChar")); + AddType (new ConstStringGen ("const-char")); + AddType (new StringGen ("gchar")); + AddType (new StringGen ("char")); + + // manually wrapped types requiring more complex marshaling + AddType (new ManualGen ("GObject", "GLib.Object", "GLib.Object.GetObject ({0})")); + AddType (new ManualGen ("GList", "GLib.List")); + AddType (new ManualGen ("GSList", "GLib.SList")); + AddType (new MarshalGen ("gunichar", "char", "uint", "GLib.Marshaller.CharToGUnichar ({0})", "GLib.Marshaller.GUnicharToChar ({0})")); + AddType (new MarshalGen ("time_t", "System.DateTime", "IntPtr", "GLib.Marshaller.DateTimeTotime_t ({0})", "GLib.Marshaller.time_tToDateTime ({0})")); + AddType (new MarshalGen ("GString", "string", "IntPtr", "new GLib.GString ({0}).Handle", "GLib.GString.PtrToString ({0})")); + AddType (new MarshalGen ("GType", "GLib.GType", "IntPtr", "{0}.Val", "new GLib.GType({0})")); + AddType (new ByRefGen ("GValue", "GLib.Value")); + // FIXME: These ought to be handled properly. + AddType (new SimpleGen ("GC", "IntPtr")); + AddType (new SimpleGen ("GError", "IntPtr")); AddType (new SimpleGen ("GMemChunk", "IntPtr")); + AddType (new SimpleGen ("GPtrArray", "IntPtr[]")); AddType (new SimpleGen ("GTimeVal", "IntPtr")); AddType (new SimpleGen ("GClosure", "IntPtr")); AddType (new SimpleGen ("GArray", "IntPtr")); @@ -112,12 +118,6 @@ namespace GtkSharp.Generation { AddType (new SimpleGen ("GParamSpec", "IntPtr")); AddType (new SimpleGen ("gconstpointer", "IntPtr")); AddType (new SimpleGen ("GDestroyNotify", "IntPtr")); - AddType (new TimeTGen ()); - AddType (new ManualGen ("GSList", "GLib.SList")); - AddType (new ManualGen ("GList", "GLib.List")); - AddType (new ByRefGen ("GValue", "GLib.Value")); - AddType (new GStringGen ()); - AddType (new GObjectGen ()); } public void AddType (IGeneratable gen) diff --git a/generator/TimeTGen.cs b/generator/TimeTGen.cs deleted file mode 100644 index 177b368c3..000000000 --- a/generator/TimeTGen.cs +++ /dev/null @@ -1,48 +0,0 @@ -// GtkSharp.Generation.TimeTGen.cs - The time_t Generatable. -// -// Author: Mike Kestner -// -// Copyright (c) 2003 Mike Kestner -// Copyright (c) 2004 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; - - public class TimeTGen : SimpleBase { - - public TimeTGen () : base ("time_t", "System.DateTime") {} - - public override string MarshalType { - get { - return "IntPtr"; - } - } - - public override string CallByName (string var_name) - { - return "GLib.Marshaller.DateTimeTotime_t (" + var_name + ")"; - } - - public override string FromNative(string var) - { - return "GLib.Marshaller.time_tToDateTime (" + var + ")"; - } - } -} -