2004-12-26 Mike Kestner <mkestner@novell.com>
* 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
This commit is contained in:
parent
adef5f7bbd
commit
d8aa13ac21
12 changed files with 78 additions and 166 deletions
|
@ -1,3 +1,9 @@
|
|||
2004-12-26 Mike Kestner <mkestner@novell.com>
|
||||
|
||||
* 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 <mkestner@novell.com>
|
||||
|
||||
* glib/ClassInitializerAttribute.cs : new attr for identifying type.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// GtkSharp.Generation.GenBase.cs - The Generatable base class.
|
||||
//
|
||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
// Author: Mike Kestner <mkestner@novell.com>
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue