From d8aa13ac21994ef43405c24676260c74bc31c6e8 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Sun, 26 Dec 2004 19:33:34 +0000 Subject: [PATCH] 2004-12-26 Mike Kestner * generator/*Gen.cs : implement IGeneratable fully on GenBase with abstract methods where necessary to refactor a ton of redundant code. svn path=/trunk/gtk-sharp/; revision=38091 --- ChangeLog | 6 ++++++ generator/BoxedGen.cs | 8 +------ generator/CallbackGen.cs | 43 ++++++------------------------------- generator/ClassBase.cs | 35 +++++------------------------- generator/ClassGen.cs | 10 ++------- generator/EnumGen.cs | 45 ++++++--------------------------------- generator/GenBase.cs | 44 ++++++++++++++++++++++++++++++++++---- generator/InterfaceGen.cs | 10 ++------- generator/ObjectGen.cs | 10 ++------- generator/OpaqueGen.cs | 19 +++-------------- generator/StructBase.cs | 6 +++--- generator/StructGen.cs | 8 +------ 12 files changed, 78 insertions(+), 166 deletions(-) diff --git a/ChangeLog b/ChangeLog index 92fdbec57..5e5e50aaf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-12-26 Mike Kestner + + * generator/*Gen.cs : implement IGeneratable fully on GenBase + with abstract methods where necessary to refactor a ton of redundant + code. + 2004-12-23 Mike Kestner * glib/ClassInitializerAttribute.cs : new attr for identifying type. diff --git a/generator/BoxedGen.cs b/generator/BoxedGen.cs index c4906bd55..ce60b8904 100644 --- a/generator/BoxedGen.cs +++ b/generator/BoxedGen.cs @@ -25,16 +25,10 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public class BoxedGen : StructBase, IGeneratable { + public class BoxedGen : StructBase { public BoxedGen (XmlElement ns, XmlElement elem) : base (ns, elem) {} - public void Generate () - { - GenerationInfo gen_info = new GenerationInfo (NSElem); - Generate (gen_info); - } - public override void Generate (GenerationInfo gen_info) { StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index 0add44178..69cac6418 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -25,7 +25,7 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public class CallbackGen : GenBase, IGeneratable { + public class CallbackGen : GenBase { private Parameters parms; private Signature sig = null; @@ -39,47 +39,22 @@ namespace GtkSharp.Generation { } } - public string MarshalType { - get - { + public override string MarshalType { + get { return NS + "Sharp." + Name + "Native"; } } - 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 var_name + ".NativeDelegate"; } - public string FromNative(string var) + public override string FromNative(string var) { return var; } - public string FromNativeReturn(string var) - { - return FromNative (var); - } - - public virtual string ToNativeReturn(string var) - { - return CallByName (var); - } - public string GenWrapper (string ns, GenerationInfo gen_info) { string wrapper = Name + "Native"; @@ -204,13 +179,7 @@ namespace GtkSharp.Generation { return ns + "Sharp." + Name + "Wrapper"; } - public void Generate () - { - GenerationInfo gen_info = new GenerationInfo (NSElem); - Generate (gen_info); - } - - public void Generate (GenerationInfo gen_info) + public override void Generate (GenerationInfo gen_info) { XmlElement ret_elem = Elem["return-type"]; if (ret_elem == null) { diff --git a/generator/ClassBase.cs b/generator/ClassBase.cs index 1d66759a1..26c07bf15 100644 --- a/generator/ClassBase.cs +++ b/generator/ClassBase.cs @@ -29,7 +29,7 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public class ClassBase : GenBase { + public abstract class ClassBase : GenBase { protected Hashtable props = new Hashtable(); protected Hashtable sigs = new Hashtable(); protected Hashtable methods = new Hashtable(); @@ -142,28 +142,13 @@ namespace GtkSharp.Generation { } } - public virtual string MarshalType { - get - { + public override string MarshalType { + get { return "IntPtr"; } } - public virtual string MarshalReturnType { - get - { - return "IntPtr"; - } - } - - public virtual string ToNativeReturnType { - get - { - return "IntPtr"; - } - } - - public virtual string CallByName (string var_name) + public override string CallByName (string var_name) { return var_name + ".Handle"; } @@ -177,21 +162,11 @@ namespace GtkSharp.Generation { get { return "Raw"; } } - public virtual string FromNative(string var) + public override string FromNative(string var) { return "(" + QualifiedName + ") GLib.Object.GetObject(" + var + ")"; } - public virtual string FromNativeReturn(string var) - { - return FromNative (var); - } - - public virtual string ToNativeReturn(string var) - { - return CallByName (var); - } - protected void GenProperties (GenerationInfo gen_info) { if (props.Count == 0) diff --git a/generator/ClassGen.cs b/generator/ClassGen.cs index e22e1d891..641475ebc 100644 --- a/generator/ClassGen.cs +++ b/generator/ClassGen.cs @@ -27,20 +27,14 @@ namespace GtkSharp.Generation { using System.Text; using System.Xml; - public class ClassGen : ClassBase, IGeneratable { + public class ClassGen : ClassBase { private ArrayList strings = new ArrayList(); private static Hashtable namespaces = new Hashtable (); public ClassGen (XmlElement ns, XmlElement elem) : base (ns, elem) {} - public void Generate () - { - GenerationInfo gen_info = new GenerationInfo (NSElem); - Generate (gen_info); - } - - public void Generate (GenerationInfo gen_info) + public override void Generate (GenerationInfo gen_info) { StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name); diff --git a/generator/EnumGen.cs b/generator/EnumGen.cs index 82b487585..a884bda9c 100644 --- a/generator/EnumGen.cs +++ b/generator/EnumGen.cs @@ -25,58 +25,27 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public class EnumGen : GenBase, IGeneratable { + public class EnumGen : GenBase { public EnumGen (XmlElement ns, XmlElement elem) : base (ns, elem) {} - public string MarshalType { - get - { + public override string MarshalType { + get { return "int"; } } - 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 "(int) " + var_name; } - public string FromNative(string var) + public override string FromNative(string var) { - return "(" + QualifiedName + ")" + var; + return "(" + QualifiedName + ") " + var; } - public string FromNativeReturn(string var) - { - return FromNative (var); - } - - public virtual string ToNativeReturn(string var) - { - return CallByName (var); - } - - public void Generate () - { - GenerationInfo gen_info = new GenerationInfo (NSElem); - Generate (gen_info); - } - - public void Generate (GenerationInfo gen_info) + public override void Generate (GenerationInfo gen_info) { StreamWriter sw = gen_info.OpenStream (Name); diff --git a/generator/GenBase.cs b/generator/GenBase.cs index 3e7702d99..62d9a1ba6 100644 --- a/generator/GenBase.cs +++ b/generator/GenBase.cs @@ -1,6 +1,6 @@ // GtkSharp.Generation.GenBase.cs - The Generatable base class. // -// Author: Mike Kestner +// Author: Mike Kestner // // Copyright (c) 2001-2002 Mike Kestner // Copyright (c) 2004 Novell, Inc. @@ -26,7 +26,7 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public abstract class GenBase { + public abstract class GenBase : IGeneratable { private XmlElement ns; private XmlElement elem; @@ -55,6 +55,14 @@ namespace GtkSharp.Generation { } } + public virtual string MarshalReturnType { + get { + return MarshalType; + } + } + + public abstract string MarshalType { get; } + public string Name { get { return elem.GetAttribute ("name"); @@ -67,7 +75,7 @@ namespace GtkSharp.Generation { } } - public XmlElement NSElem { + private XmlElement NSElem { get { return ns; } @@ -79,7 +87,13 @@ namespace GtkSharp.Generation { } } - public void AppendCustom (StreamWriter sw, string custom_dir) + public virtual string ToNativeReturnType { + get { + return MarshalType; + } + } + + protected void AppendCustom (StreamWriter sw, string custom_dir) { char sep = Path.DirectorySeparatorChar; string custom = custom_dir + sep + Name + ".custom"; @@ -93,6 +107,28 @@ namespace GtkSharp.Generation { sr.Close (); } } + + public abstract string CallByName (string var); + + public abstract string FromNative (string var); + + public virtual string FromNativeReturn (string var) + { + return FromNative (var); + } + + public virtual string ToNativeReturn (string var) + { + return CallByName (var); + } + + public void Generate () + { + GenerationInfo geninfo = new GenerationInfo (ns); + Generate (geninfo); + } + + public abstract void Generate (GenerationInfo geninfo); } } diff --git a/generator/InterfaceGen.cs b/generator/InterfaceGen.cs index 33c6f9fdf..8f3ade4a1 100644 --- a/generator/InterfaceGen.cs +++ b/generator/InterfaceGen.cs @@ -27,7 +27,7 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public class InterfaceGen : ClassBase, IGeneratable { + public class InterfaceGen : ClassBase { ArrayList vms = new ArrayList (); ArrayList members = new ArrayList (); @@ -258,13 +258,7 @@ namespace GtkSharp.Generation { GenerateInterface (gen_info); } - public void Generate () - { - GenerationInfo gen_info = new GenerationInfo (NSElem); - Generate (gen_info); - } - - public void Generate (GenerationInfo gen_info) + public override void Generate (GenerationInfo gen_info) { StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index f42df0f31..a4a31c091 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -28,7 +28,7 @@ namespace GtkSharp.Generation { using System.Text; using System.Xml; - public class ObjectGen : ClassBase, IGeneratable { + public class ObjectGen : ClassBase { private ArrayList strings = new ArrayList(); private ArrayList vm_nodes = new ArrayList(); @@ -114,13 +114,7 @@ namespace GtkSharp.Generation { return result; } - public void Generate () - { - GenerationInfo gen_info = new GenerationInfo (NSElem); - Generate (gen_info); - } - - public void Generate (GenerationInfo gen_info) + public override void Generate (GenerationInfo gen_info) { DirectoryInfo di = GetDirectoryInfo (gen_info.Dir, gen_info.AssemblyName); di.objects.Add (CName, QualifiedName); diff --git a/generator/OpaqueGen.cs b/generator/OpaqueGen.cs index 92f96c2b9..86027cd52 100644 --- a/generator/OpaqueGen.cs +++ b/generator/OpaqueGen.cs @@ -26,35 +26,22 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public class OpaqueGen : ClassBase, IGeneratable { + public class OpaqueGen : ClassBase { - public OpaqueGen (XmlElement ns, XmlElement elem) : base (ns, elem) - { - } + public OpaqueGen (XmlElement ns, XmlElement elem) : base (ns, elem) {} public override string FromNative(string var) { return "new " + QualifiedName + "(" + var + ")"; } - public override string FromNativeReturn(string var) - { - return FromNative (var); - } - private bool DisableRawCtor { get { return Elem.HasAttribute ("disable_raw_ctor"); } } - public void Generate () - { - GenerationInfo gen_info = new GenerationInfo (NSElem); - Generate (gen_info); - } - - public void Generate (GenerationInfo gen_info) + public override void Generate (GenerationInfo gen_info) { StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); diff --git a/generator/StructBase.cs b/generator/StructBase.cs index d3bed785d..e52a45728 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -27,11 +27,11 @@ namespace GtkSharp.Generation { using System.Text.RegularExpressions; using System.Xml; - public class StructBase : ClassBase { + public abstract class StructBase : ClassBase { ArrayList fields = new ArrayList (); - public StructBase (XmlElement ns, XmlElement elem) : base (ns, elem) + protected StructBase (XmlElement ns, XmlElement elem) : base (ns, elem) { foreach (XmlNode node in elem.ChildNodes) { @@ -129,7 +129,7 @@ namespace GtkSharp.Generation { } } - public virtual void Generate (GenerationInfo gen_info) + public override void Generate (GenerationInfo gen_info) { bool need_close = false; if (gen_info.Writer == null) { diff --git a/generator/StructGen.cs b/generator/StructGen.cs index 1162a8b23..63635a384 100644 --- a/generator/StructGen.cs +++ b/generator/StructGen.cs @@ -25,16 +25,10 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public class StructGen : StructBase, IGeneratable { + public class StructGen : StructBase { public StructGen (XmlElement ns, XmlElement elem) : base (ns, elem) {} - public void Generate () - { - GenerationInfo gen_info = new GenerationInfo (NSElem); - Generate (gen_info); - } - public override void Generate (GenerationInfo gen_info) { StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);