diff --git a/ChangeLog b/ChangeLog index 6385baee1..d1d8a3bd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-09-21 Mike Kestner + + * generator/*.cs: add DefaultValue prop for obtaining a + sane value when we need to return a value but something bad has + happened such that we can't get a real value. Needed for iface + signal marshaling, among other places we're partially working + around it now. + 2007-09-19 Mike Kestner * generator/InterfaceGen.cs: remove some dead code from a previous diff --git a/gdk/gdk-symbols.xml b/gdk/gdk-symbols.xml index a97dacf04..9693f883e 100644 --- a/gdk/gdk-symbols.xml +++ b/gdk/gdk-symbols.xml @@ -21,6 +21,6 @@ - + diff --git a/generator/AliasGen.cs b/generator/AliasGen.cs index 8bfdacc5b..19911d6b6 100644 --- a/generator/AliasGen.cs +++ b/generator/AliasGen.cs @@ -24,7 +24,7 @@ namespace GtkSharp.Generation { public class AliasGen : SimpleBase { - public AliasGen (string ctype, string type) : base (ctype, type) {} + public AliasGen (string ctype, string type) : base (ctype, type, String.Empty) {} } } diff --git a/generator/ByRefGen.cs b/generator/ByRefGen.cs index 2cb3fab18..176e7aa84 100644 --- a/generator/ByRefGen.cs +++ b/generator/ByRefGen.cs @@ -26,7 +26,7 @@ namespace GtkSharp.Generation { public class ByRefGen : SimpleBase, IManualMarshaler { - public ByRefGen (string ctype, string type) : base (ctype, type) {} + public ByRefGen (string ctype, string type) : base (ctype, type, type + ".Empty") {} public override string MarshalType { get { diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index 7df090a25..f7fde7216 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -40,6 +40,10 @@ namespace GtkSharp.Generation { parms.HideData = true; } + public override string DefaultValue { + get { return "null"; } + } + public override bool Validate () { if (!retval.Validate ()) { diff --git a/generator/ClassBase.cs b/generator/ClassBase.cs index 9fd2c9dd4..7f7cdc885 100644 --- a/generator/ClassBase.cs +++ b/generator/ClassBase.cs @@ -227,6 +227,12 @@ namespace GtkSharp.Generation { public abstract string CallByName (); + public override string DefaultValue { + get { + return "null"; + } + } + protected bool IsNodeNameHandled (string name) { switch (name) { diff --git a/generator/ConstFilenameGen.cs b/generator/ConstFilenameGen.cs index 4a56f3dfc..562ab9ce1 100644 --- a/generator/ConstFilenameGen.cs +++ b/generator/ConstFilenameGen.cs @@ -25,7 +25,7 @@ namespace GtkSharp.Generation { public class ConstFilenameGen : SimpleBase, IManualMarshaler { - public ConstFilenameGen (string ctype) : base (ctype, "string") {} + public ConstFilenameGen (string ctype) : base (ctype, "string", "null") {} public override string MarshalType { get { diff --git a/generator/ConstStringGen.cs b/generator/ConstStringGen.cs index 24359b0cf..70f882ef2 100644 --- a/generator/ConstStringGen.cs +++ b/generator/ConstStringGen.cs @@ -27,7 +27,7 @@ namespace GtkSharp.Generation { public class ConstStringGen : SimpleBase, IManualMarshaler { - public ConstStringGen (string ctype) : base (ctype, "string") {} + public ConstStringGen (string ctype) : base (ctype, "string", "null") {} public override string MarshalType { get { diff --git a/generator/EnumGen.cs b/generator/EnumGen.cs index 056e4eec7..2e2a74eb4 100644 --- a/generator/EnumGen.cs +++ b/generator/EnumGen.cs @@ -55,6 +55,12 @@ namespace GtkSharp.Generation { return true; } + public override string DefaultValue { + get { + return "(" + QualifiedName + ") 0"; + } + } + public override string MarshalType { get { return "int"; diff --git a/generator/GenBase.cs b/generator/GenBase.cs index d858407d0..2bb8644e8 100644 --- a/generator/GenBase.cs +++ b/generator/GenBase.cs @@ -75,6 +75,8 @@ namespace GtkSharp.Generation { } } + public abstract string DefaultValue { get; } + public string QualifiedName { get { return NS + "." + Name; diff --git a/generator/IGeneratable.cs b/generator/IGeneratable.cs index 940e74e0c..1608fd7cd 100644 --- a/generator/IGeneratable.cs +++ b/generator/IGeneratable.cs @@ -45,6 +45,11 @@ namespace GtkSharp.Generation { // generatable to unmanaged code string ToNativeReturnType {get;} + // The value returned by callbacks that are interrupted prematurely + // by managed exceptions or other conditions where an appropriate + // value can't be otherwise obtained. + string DefaultValue {get;} + // Generates an expression to convert var_name to MarshalType string CallByName (string var_name); diff --git a/generator/LPGen.cs b/generator/LPGen.cs index 0a68615b6..3fb774ec6 100644 --- a/generator/LPGen.cs +++ b/generator/LPGen.cs @@ -26,7 +26,7 @@ namespace GtkSharp.Generation { public class LPGen : SimpleGen, IAccessor { - public LPGen (string ctype) : base (ctype, "long") {} + public LPGen (string ctype) : base (ctype, "long", "0L") {} public override string MarshalType { get { diff --git a/generator/LPUGen.cs b/generator/LPUGen.cs index 063e4f982..331b25f98 100644 --- a/generator/LPUGen.cs +++ b/generator/LPUGen.cs @@ -26,7 +26,7 @@ namespace GtkSharp.Generation { public class LPUGen : SimpleGen, IAccessor { - public LPUGen (string ctype) : base (ctype, "ulong") {} + public LPUGen (string ctype) : base (ctype, "ulong", "0") {} public override string MarshalType { get { diff --git a/generator/ManualGen.cs b/generator/ManualGen.cs index ff2868550..1d94916bb 100644 --- a/generator/ManualGen.cs +++ b/generator/ManualGen.cs @@ -28,12 +28,12 @@ namespace GtkSharp.Generation { string from_fmt; - public ManualGen (string ctype, string type) : base (ctype, type) + public ManualGen (string ctype, string type) : base (ctype, type, "null") { from_fmt = "new " + QualifiedName + "({0})"; } - public ManualGen (string ctype, string type, string from_fmt) : base (ctype, type) + public ManualGen (string ctype, string type, string from_fmt) : base (ctype, type, "null") { this.from_fmt = from_fmt; } diff --git a/generator/MarshalGen.cs b/generator/MarshalGen.cs index 01f3f128f..820961c86 100644 --- a/generator/MarshalGen.cs +++ b/generator/MarshalGen.cs @@ -29,7 +29,7 @@ namespace GtkSharp.Generation { string call_fmt; string from_fmt; - public MarshalGen (string ctype, string type, string mtype, string call_fmt, string from_fmt) : base (ctype, type) + public MarshalGen (string ctype, string type, string mtype, string call_fmt, string from_fmt) : base (ctype, type, "null") { this.mtype = mtype; this.call_fmt = call_fmt; diff --git a/generator/Parser.cs b/generator/Parser.cs index 4fcce6ae7..61e371407 100644 --- a/generator/Parser.cs +++ b/generator/Parser.cs @@ -145,9 +145,14 @@ namespace GtkSharp.Generation { string name = symbol.GetAttribute ("name"); IGeneratable result = null; - if (type == "simple") - result = new SimpleGen (cname, name); - else if (type == "manual") + if (type == "simple") { + if (symbol.HasAttribute ("default_value")) + result = new SimpleGen (cname, name, symbol.GetAttribute ("default_value")); + else { + Console.WriteLine ("Simple type element " + cname + " has no specified default value"); + result = new SimpleGen (cname, name, String.Empty); + } + } else if (type == "manual") result = new ManualGen (cname, name); else if (type == "alias") result = new AliasGen (cname, name); diff --git a/generator/SimpleBase.cs b/generator/SimpleBase.cs index b30513778..38bfbe36b 100644 --- a/generator/SimpleBase.cs +++ b/generator/SimpleBase.cs @@ -28,8 +28,9 @@ namespace GtkSharp.Generation { string type; string ctype; string ns = String.Empty; + string default_value = String.Empty; - public SimpleBase (string ctype, string type) + public SimpleBase (string ctype, string type, string default_value) { string[] toks = type.Split('.'); this.ctype = ctype; @@ -38,6 +39,7 @@ namespace GtkSharp.Generation { this.ns = String.Join (".", toks, 0, toks.Length - 1); else if (toks.Length == 2) this.ns = toks[0]; + this.default_value = default_value; } public string CName { @@ -70,6 +72,12 @@ namespace GtkSharp.Generation { } } + public virtual string DefaultValue { + get { + return default_value; + } + } + public virtual string ToNativeReturnType { get { return MarshalType; diff --git a/generator/SimpleGen.cs b/generator/SimpleGen.cs index 8acb0a6c8..b38213536 100644 --- a/generator/SimpleGen.cs +++ b/generator/SimpleGen.cs @@ -24,7 +24,8 @@ namespace GtkSharp.Generation { using System; public class SimpleGen : SimpleBase { - public SimpleGen (string ctype, string type) : base (ctype, type) {} + public SimpleGen (string ctype, string type, string default_value) : base (ctype, type, default_value) {} + } } diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 85ac26364..1b1b02235 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -56,6 +56,12 @@ namespace GtkSharp.Generation { } } + public override string DefaultValue { + get { + return QualifiedName + ".Zero"; + } + } + public override string MarshalType { get { return "IntPtr"; diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index a7795e194..d8d5e52b3 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -43,37 +43,37 @@ 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", "uint")); - AddType (new SimpleGen ("unsigned int", "uint")); - AddType (new SimpleGen ("unsigned-int", "uint")); - AddType (new SimpleGen ("gshort", "short")); - AddType (new SimpleGen ("gushort", "ushort")); - AddType (new SimpleGen ("short", "short")); - AddType (new SimpleGen ("guchar", "byte")); - AddType (new SimpleGen ("unsigned char", "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 ("guint16", "ushort")); - AddType (new SimpleGen ("gint32", "int")); - AddType (new SimpleGen ("guint32", "uint")); - AddType (new SimpleGen ("gint64", "long")); - AddType (new SimpleGen ("guint64", "ulong")); - AddType (new SimpleGen ("long long", "long")); - AddType (new SimpleGen ("gfloat", "float")); - AddType (new SimpleGen ("float", "float")); - AddType (new SimpleGen ("gdouble", "double")); - AddType (new SimpleGen ("double", "double")); - AddType (new SimpleGen ("GQuark", "int")); + AddType (new SimpleGen ("void", "void", String.Empty)); + AddType (new SimpleGen ("gpointer", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("gboolean", "bool", "false")); + AddType (new SimpleGen ("gint", "int", "0")); + AddType (new SimpleGen ("guint", "uint", "0")); + AddType (new SimpleGen ("int", "int", "0")); + AddType (new SimpleGen ("unsigned", "uint", "0")); + AddType (new SimpleGen ("unsigned int", "uint", "0")); + AddType (new SimpleGen ("unsigned-int", "uint", "0")); + AddType (new SimpleGen ("gshort", "short", "0")); + AddType (new SimpleGen ("gushort", "ushort", "0")); + AddType (new SimpleGen ("short", "short", "0")); + AddType (new SimpleGen ("guchar", "byte", "0")); + AddType (new SimpleGen ("unsigned char", "byte", "0")); + AddType (new SimpleGen ("unsigned-char", "byte", "0")); + AddType (new SimpleGen ("guint1", "bool", "false")); + AddType (new SimpleGen ("uint1", "bool", "false")); + AddType (new SimpleGen ("gint8", "sbyte", "0")); + AddType (new SimpleGen ("guint8", "byte", "0")); + AddType (new SimpleGen ("gint16", "short", "0")); + AddType (new SimpleGen ("guint16", "ushort", "0")); + AddType (new SimpleGen ("gint32", "int", "0")); + AddType (new SimpleGen ("guint32", "uint", "0")); + AddType (new SimpleGen ("gint64", "long", "0")); + AddType (new SimpleGen ("guint64", "ulong", "0")); + AddType (new SimpleGen ("long long", "long", "0")); + AddType (new SimpleGen ("gfloat", "float", "0.0")); + AddType (new SimpleGen ("float", "float", "0.0")); + AddType (new SimpleGen ("gdouble", "double", "0.0")); + AddType (new SimpleGen ("double", "double", "0.0")); + AddType (new SimpleGen ("GQuark", "int", "0")); // platform specific integer types. these will break on any // platform where sizeof (long) != sizeof (pointer) @@ -95,7 +95,7 @@ namespace GtkSharp.Generation { AddType (new MarshalGen ("gfilename", "string", "IntPtr", "GLib.Marshaller.StringToFilenamePtr({0})", "GLib.Marshaller.FilenamePtrToStringGFree({0})")); AddType (new MarshalGen ("gchar", "string", "IntPtr", "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})")); AddType (new MarshalGen ("char", "string", "IntPtr", "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})")); - AddType (new SimpleGen ("GStrv", "string[]")); + AddType (new SimpleGen ("GStrv", "string[]", "null")); // manually wrapped types requiring more complex marshaling AddType (new ManualGen ("GInitiallyUnowned", "GLib.InitiallyUnowned", "GLib.Object.GetObject ({0})")); @@ -107,24 +107,24 @@ namespace GtkSharp.Generation { 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")); - AddType (new SimpleGen ("GDestroyNotify", "GLib.DestroyNotify")); + AddType (new SimpleGen ("GDestroyNotify", "GLib.DestroyNotify", "null")); // 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")); - AddType (new SimpleGen ("GByteArray", "IntPtr")); - AddType (new SimpleGen ("GData", "IntPtr")); - AddType (new SimpleGen ("GIOChannel", "IntPtr")); - AddType (new SimpleGen ("GTypeModule", "GLib.Object")); - AddType (new SimpleGen ("GHashTable", "System.IntPtr")); - AddType (new SimpleGen ("va_list", "IntPtr")); - AddType (new SimpleGen ("GParamSpec", "IntPtr")); - AddType (new SimpleGen ("gconstpointer", "IntPtr")); + AddType (new SimpleGen ("GC", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("GError", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("GMemChunk", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("GPtrArray", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("GTimeVal", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("GClosure", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("GArray", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("GByteArray", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("GData", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("GIOChannel", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("GTypeModule", "GLib.Object", "null")); + AddType (new SimpleGen ("GHashTable", "System.IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("va_list", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("GParamSpec", "IntPtr", "IntPtr.Zero")); + AddType (new SimpleGen ("gconstpointer", "IntPtr", "IntPtr.Zero")); } public void AddType (IGeneratable gen)