From 1d72136dd82d57fdc69d891701f30ed6c466f781 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Sun, 26 Dec 2004 21:22:50 +0000 Subject: [PATCH] 2004-12-26 Mike Kestner * generator/Makefile.am : add new file. * generator/SimpleBase.cs : new class for non-generated type mappers. * generator/*Gen.cs : first refactoring of "Simple" generatable types. Derive them all from SimpleBase. More to come. svn path=/trunk/gtk-sharp/; revision=38097 --- ChangeLog | 7 +++ generator/ByRefGen.cs | 78 +++++----------------------- generator/GStringGen.cs | 58 +++------------------ generator/GUnicharGen.cs | 56 ++------------------ generator/LPGen.cs | 63 ++--------------------- generator/LPUGen.cs | 65 ++--------------------- generator/Makefile.am | 1 + generator/ManualGen.cs | 73 ++------------------------ generator/SimpleBase.cs | 108 +++++++++++++++++++++++++++++++++++++++ generator/SimpleGen.cs | 81 +---------------------------- generator/TimeTGen.cs | 70 +++---------------------- 11 files changed, 163 insertions(+), 497 deletions(-) create mode 100644 generator/SimpleBase.cs diff --git a/ChangeLog b/ChangeLog index d5ed96cec..054c67a85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-12-26 Mike Kestner + + * generator/Makefile.am : add new file. + * generator/SimpleBase.cs : new class for non-generated type mappers. + * generator/*Gen.cs : first refactoring of "Simple" generatable types. + Derive them all from SimpleBase. More to come. + 2004-12-26 Mike Kestner * generator/CustomMarshalerGen.cs : kill bad idea unused class. diff --git a/generator/ByRefGen.cs b/generator/ByRefGen.cs index a50266d7b..a60d7ea82 100644 --- a/generator/ByRefGen.cs +++ b/generator/ByRefGen.cs @@ -1,8 +1,9 @@ // GtkSharp.Generation.ByRefGen.cs - The ByRef 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 @@ -23,92 +24,37 @@ namespace GtkSharp.Generation { using System; - public class ByRefGen : IGeneratable { + public class ByRefGen : SimpleBase { - string type; - string ctype; - string ns = ""; - - public ByRefGen (string ctype, string type) - { - string[] toks = type.Split('.'); - this.ctype = ctype; - this.type = toks[toks.Length - 1]; - if (toks.Length > 2) - this.ns = String.Join (".", toks, 0, toks.Length - 2); - else if (toks.Length == 2) - this.ns = toks[0]; - } + public ByRefGen (string ctype, string type) : base (ctype, type) {} - public string CName { - get - { - return ctype; - } - } - - public string Name { - get - { - return type; - } - } - - public string QualifiedName { - get - { - return ns + "." + type; - } - } - - public string MarshalType { - get - { + public override string MarshalType { + get { return "ref " + QualifiedName; } } - public virtual string MarshalReturnType { - get - { + public override string MarshalReturnType { + get { return QualifiedName; } } - public virtual string ToNativeReturnType { - get - { + public override string ToNativeReturnType { + get { return QualifiedName; } } - public string CallByName (string var_name) + public override string CallByName (string var_name) { return "ref " + var_name; } - public string FromNative(string var) + public override string ToNativeReturn(string var) { return var; } - - public virtual string FromNativeReturn(string var) - { - return var; - } - - public virtual string ToNativeReturn(string var) - { - return var; - } - - public void Generate () - { - } - - public void Generate (GenerationInfo gen_info) - { - } } } diff --git a/generator/GStringGen.cs b/generator/GStringGen.cs index 9a6efc95c..bb810d2de 100644 --- a/generator/GStringGen.cs +++ b/generator/GStringGen.cs @@ -1,6 +1,6 @@ // GtkSharp.Generation.GStringGen.cs - The GString type Generatable. // -// Author: Mike Kestner +// Author: Mike Kestner // // Copyright (c) 2004 Novell, Inc. // @@ -23,71 +23,25 @@ namespace GtkSharp.Generation { using System; - public class GStringGen : IGeneratable { + public class GStringGen : SimpleBase { - public string CName { - get { - return "GString"; - } - } + public GStringGen () : base ("GString", "string") {} - public string Name { - get { - return "string"; - } - } - - public string QualifiedName { - get { - return "string"; - } - } - - public string MarshalType { + public override string MarshalType { get { return "IntPtr"; } } - public string CallByName (string var_name) + public override string CallByName (string var_name) { return "(new GLib.GString (" + var_name + ")).Handle"; } - public string FromNative (string var) + public override string FromNative (string var) { return "GLib.GString.PtrToString (" + var + ")"; } - - public string FromNativeReturn (string var) - { - return FromNative (var); - } - - public string ToNativeReturn (string var) - { - return CallByName (var); - } - - public string MarshalReturnType { - get { - return "IntPtr"; - } - } - - public string ToNativeReturnType { - get { - return "IntPtr"; - } - } - - public void Generate () - { - } - - public void Generate (GenerationInfo gen_info) - { - } } } diff --git a/generator/GUnicharGen.cs b/generator/GUnicharGen.cs index c555396f7..5d37a3358 100644 --- a/generator/GUnicharGen.cs +++ b/generator/GUnicharGen.cs @@ -23,71 +23,25 @@ namespace GtkSharp.Generation { using System; - public class GUnicharGen : IGeneratable { + public class GUnicharGen : SimpleBase { - public string CName { - get { - return "gunichar"; - } - } + public GUnicharGen () : base ("gunichar", "char") {} - public string Name { - get { - return "char"; - } - } - - public string QualifiedName { - get { - return "char"; - } - } - - public string MarshalType { + public override string MarshalType { get { return "uint"; } } - public string MarshalReturnType { - get { - return MarshalType; - } - } - - public string ToNativeReturnType { - get { - return MarshalType; - } - } - - public string CallByName (string var_name) + public override string CallByName (string var_name) { return "GLib.Marshaller.CharToGUnichar (" + var_name + ")"; } - public virtual string FromNative(string var) + public override string FromNative(string var) { return "GLib.Marshaller.GUnicharToChar (" + var + ")"; } - - public virtual string FromNativeReturn(string var) - { - return FromNative (var); - } - - public virtual string ToNativeReturn(string var) - { - return CallByName (var); - } - - public void Generate () - { - } - - public void Generate (GenerationInfo gen_info) - { - } } } diff --git a/generator/LPGen.cs b/generator/LPGen.cs index e34923012..430d95aa8 100644 --- a/generator/LPGen.cs +++ b/generator/LPGen.cs @@ -23,78 +23,25 @@ namespace GtkSharp.Generation { using System; - public class LPGen : IGeneratable { + public class LPGen : SimpleBase { - string ctype; + public LPGen (string ctype) : base (ctype, "long") {} - public LPGen (string ctype) - { - this.ctype = ctype; - } - - public string CName { - get { - return ctype; - } - } - - public string Name { - get { - return "long"; - } - } - - public string QualifiedName { - get { - return "long"; - } - } - - public string MarshalType { + public override string MarshalType { get { return "IntPtr"; } } - public string MarshalReturnType { - get { - return MarshalType; - } - } - - public string ToNativeReturnType { - get { - return MarshalType; - } - } - - public string CallByName (string var_name) + public override string CallByName (string var_name) { return "new IntPtr (" + var_name + ")"; } - public virtual string FromNative(string var) + public override string FromNative(string var) { return "(long) " + var; } - - public virtual string FromNativeReturn(string var) - { - return FromNative (var); - } - - public virtual string ToNativeReturn(string var) - { - return CallByName (var); - } - - public void Generate () - { - } - - public void Generate (GenerationInfo gen_info) - { - } } } diff --git a/generator/LPUGen.cs b/generator/LPUGen.cs index 3e5b8ce3c..bae32204e 100644 --- a/generator/LPUGen.cs +++ b/generator/LPUGen.cs @@ -23,80 +23,25 @@ namespace GtkSharp.Generation { using System; - public class LPUGen : IGeneratable { + public class LPUGen : SimpleGen { - string ctype; + public LPUGen (string ctype) : base (ctype, "ulong") {} - public LPUGen (string ctype) - { - this.ctype = ctype; - } - - public string CName { - get { - return ctype; - } - } - - public string Name { - get { - return "ulong"; - } - } - - public string QualifiedName { - get { - return "ulong"; - } - } - - public string MarshalType { + public override string MarshalType { get { return "UIntPtr"; } } - public string MarshalReturnType { - get - { - return MarshalType; - } - } - - public string ToNativeReturnType { - get - { - return MarshalType; - } - } - - public string CallByName (string var_name) + public override string CallByName (string var_name) { return "new UIntPtr (" + var_name + ")"; } - public virtual string FromNative(string var) + public override string FromNative(string var) { return "(ulong) " + var; } - - public virtual string FromNativeReturn(string var) - { - return FromNative (var); - } - - public virtual string ToNativeReturn(string var) - { - return CallByName (var); - } - - public void Generate () - { - } - - public void Generate (GenerationInfo gen_info) - { - } } } diff --git a/generator/Makefile.am b/generator/Makefile.am index 46fc61e95..f2e1dcc37 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -42,6 +42,7 @@ sources = \ Signal.cs \ SignalHandler.cs \ Signature.cs \ + SimpleBase.cs \ SimpleGen.cs \ Statistics.cs \ StringGen.cs \ diff --git a/generator/ManualGen.cs b/generator/ManualGen.cs index be59c06af..348e1d53f 100644 --- a/generator/ManualGen.cs +++ b/generator/ManualGen.cs @@ -23,96 +23,33 @@ namespace GtkSharp.Generation { using System; - public class ManualGen : IGeneratable { + public class ManualGen : SimpleBase { string handle; - string ctype; - string type; - string ns = ""; public ManualGen (string ctype, string type) : this (ctype, type, "Handle") {} - public ManualGen (string ctype, string type, string handle) + public ManualGen (string ctype, string type, string handle) : base (ctype, type) { - string[] toks = type.Split('.'); this.handle = handle; - this.ctype = ctype; - this.type = toks[toks.Length - 1]; - if (toks.Length > 2) - this.ns = String.Join (".", toks, 0, toks.Length - 2); - else if (toks.Length == 2) - this.ns = toks[0]; } - public string CName { - get - { - return ctype; - } - } - - public string Name { - get - { - return type; - } - } - - public string QualifiedName { - get - { - return ns + "." + type; - } - } - - public string MarshalType { + public override string MarshalType { get { return "IntPtr"; } } - public string MarshalReturnType { - get - { - return "IntPtr"; - } - } - - public string ToNativeReturnType { - get - { - return "IntPtr"; - } - } - - public string CallByName (string var_name) + public override string CallByName (string var_name) { return var_name + "." + handle; } - public virtual string FromNative(string var) + public override string FromNative(string var) { return "new " + QualifiedName + "(" + var + ")"; } - - public virtual string FromNativeReturn(string var) - { - return FromNative (var); - } - - public virtual string ToNativeReturn(string var) - { - return CallByName (var); - } - - public void Generate () - { - } - - public void Generate (GenerationInfo gen_info) - { - } } } diff --git a/generator/SimpleBase.cs b/generator/SimpleBase.cs new file mode 100644 index 000000000..ae3a3f983 --- /dev/null +++ b/generator/SimpleBase.cs @@ -0,0 +1,108 @@ +// GtkSharp.Generation.SimpleBase.cs - base class for marshaling non-generated types. +// +// 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 SimpleBase : IGeneratable { + + string type; + string ctype; + string ns = String.Empty; + + public SimpleBase (string ctype, string type) + { + string[] toks = type.Split('.'); + this.ctype = ctype; + this.type = toks[toks.Length - 1]; + if (toks.Length > 2) + this.ns = String.Join (".", toks, 0, toks.Length - 2); + else if (toks.Length == 2) + this.ns = toks[0]; + } + + public string CName { + get { + return ctype; + } + } + + public string Name { + get { + return type; + } + } + + public string QualifiedName { + get { + return ns == String.Empty ? type : ns + "." + type; + } + } + + public virtual string MarshalType { + get { + return QualifiedName; + } + } + + public virtual string MarshalReturnType { + get { + return MarshalType; + } + } + + public virtual string ToNativeReturnType { + get { + return MarshalType; + } + } + + public virtual string CallByName (string var) + { + return var; + } + + public virtual string FromNative(string var) + { + return var; + } + + public virtual string FromNativeReturn(string var) + { + return FromNative (var); + } + + public virtual string ToNativeReturn(string var) + { + return CallByName (var); + } + + public void Generate () + { + } + + public void Generate (GenerationInfo gen_info) + { + } + } +} + diff --git a/generator/SimpleGen.cs b/generator/SimpleGen.cs index 0ab73c7e1..8acb0a6c8 100644 --- a/generator/SimpleGen.cs +++ b/generator/SimpleGen.cs @@ -23,85 +23,8 @@ namespace GtkSharp.Generation { using System; - public class SimpleGen : IGeneratable { - - string type; - string ctype; - - public SimpleGen (string ctype, string type) - { - this.ctype = ctype; - this.type = type; - } - - public string CName { - get - { - return ctype; - } - } - - public string Name { - get - { - return type; - } - } - - public string QualifiedName { - get - { - return type; - } - } - - public string MarshalType { - get - { - return type; - } - } - public virtual string MarshalReturnType { - get - { - return type; - } - } - - public virtual string ToNativeReturnType { - get - { - return type; - } - } - - public string CallByName (string var_name) - { - return var_name; - } - - public string FromNative(string var) - { - return var; - } - - public virtual string FromNativeReturn(string var) - { - return var; - } - - public virtual string ToNativeReturn(string var) - { - return var; - } - - public void Generate () - { - } - - public void Generate (GenerationInfo gen_info) - { - } + public class SimpleGen : SimpleBase { + public SimpleGen (string ctype, string type) : base (ctype, type) {} } } diff --git a/generator/TimeTGen.cs b/generator/TimeTGen.cs index 62495bf1b..177b368c3 100644 --- a/generator/TimeTGen.cs +++ b/generator/TimeTGen.cs @@ -1,6 +1,6 @@ // GtkSharp.Generation.TimeTGen.cs - The time_t Generatable. // -// Author: Mike Kestner +// Author: Mike Kestner // // Copyright (c) 2003 Mike Kestner // Copyright (c) 2004 Novell, Inc. @@ -24,81 +24,25 @@ namespace GtkSharp.Generation { using System; - public class TimeTGen : IGeneratable { + public class TimeTGen : SimpleBase { - string ctype; - string type; - string ns = ""; + public TimeTGen () : base ("time_t", "System.DateTime") {} - public string CName { - get - { - return "time_t"; - } - } - - public string Name { - get - { - return "DateTime"; - } - } - - public string QualifiedName { - get - { - return "System.DateTime"; - } - } - - public string MarshalType { - get - { + public override string MarshalType { + get { return "IntPtr"; } } - public string MarshalReturnType { - get - { - return "IntPtr"; - } - } - - public string ToNativeReturnType { - get - { - return "IntPtr"; - } - } - - public string CallByName (string var_name) + public override string CallByName (string var_name) { return "GLib.Marshaller.DateTimeTotime_t (" + var_name + ")"; } - public virtual string FromNative(string var) + public override string FromNative(string var) { return "GLib.Marshaller.time_tToDateTime (" + var + ")"; } - - public virtual string FromNativeReturn(string var) - { - return FromNative (var); - } - - public virtual string ToNativeReturn(string var) - { - return CallByName (var); - } - - public void Generate () - { - } - - public void Generate (GenerationInfo gen_info) - { - } } }