2007-09-21 Mike Kestner <mkestner@novell.com>
* 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. svn path=/trunk/gtk-sharp/; revision=86157
This commit is contained in:
parent
e18e0b7995
commit
9f780a56b2
20 changed files with 114 additions and 63 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2007-09-21 Mike Kestner <mkestner@novell.com>
|
||||||
|
|
||||||
|
* 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 <mkestner@novell.com>
|
2007-09-19 Mike Kestner <mkestner@novell.com>
|
||||||
|
|
||||||
* generator/InterfaceGen.cs: remove some dead code from a previous
|
* generator/InterfaceGen.cs: remove some dead code from a previous
|
||||||
|
|
|
@ -21,6 +21,6 @@
|
||||||
<symbol type="manual" cname="GdkEventSetting" name="Gdk.EventSetting"/>
|
<symbol type="manual" cname="GdkEventSetting" name="Gdk.EventSetting"/>
|
||||||
<symbol type="manual" cname="GdkEventVisibility" name="Gdk.EventVisibility"/>
|
<symbol type="manual" cname="GdkEventVisibility" name="Gdk.EventVisibility"/>
|
||||||
<symbol type="manual" cname="GdkEventWindowState" name="Gdk.EventWindowState"/>
|
<symbol type="manual" cname="GdkEventWindowState" name="Gdk.EventWindowState"/>
|
||||||
<symbol type="simple" cname="GdkKey" name="Gdk.Key"/>
|
<symbol type="simple" cname="GdkKey" name="Gdk.Key" default_value="Gdk.Key.VoidSymbol"/>
|
||||||
</api>
|
</api>
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public class AliasGen : SimpleBase {
|
public class AliasGen : SimpleBase {
|
||||||
|
|
||||||
public AliasGen (string ctype, string type) : base (ctype, type) {}
|
public AliasGen (string ctype, string type) : base (ctype, type, String.Empty) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public class ByRefGen : SimpleBase, IManualMarshaler {
|
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 {
|
public override string MarshalType {
|
||||||
get {
|
get {
|
||||||
|
|
|
@ -40,6 +40,10 @@ namespace GtkSharp.Generation {
|
||||||
parms.HideData = true;
|
parms.HideData = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string DefaultValue {
|
||||||
|
get { return "null"; }
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Validate ()
|
public override bool Validate ()
|
||||||
{
|
{
|
||||||
if (!retval.Validate ()) {
|
if (!retval.Validate ()) {
|
||||||
|
|
|
@ -227,6 +227,12 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public abstract string CallByName ();
|
public abstract string CallByName ();
|
||||||
|
|
||||||
|
public override string DefaultValue {
|
||||||
|
get {
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected bool IsNodeNameHandled (string name)
|
protected bool IsNodeNameHandled (string name)
|
||||||
{
|
{
|
||||||
switch (name) {
|
switch (name) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public class ConstFilenameGen : SimpleBase, IManualMarshaler {
|
public class ConstFilenameGen : SimpleBase, IManualMarshaler {
|
||||||
|
|
||||||
public ConstFilenameGen (string ctype) : base (ctype, "string") {}
|
public ConstFilenameGen (string ctype) : base (ctype, "string", "null") {}
|
||||||
|
|
||||||
public override string MarshalType {
|
public override string MarshalType {
|
||||||
get {
|
get {
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public class ConstStringGen : SimpleBase, IManualMarshaler {
|
public class ConstStringGen : SimpleBase, IManualMarshaler {
|
||||||
|
|
||||||
public ConstStringGen (string ctype) : base (ctype, "string") {}
|
public ConstStringGen (string ctype) : base (ctype, "string", "null") {}
|
||||||
|
|
||||||
public override string MarshalType {
|
public override string MarshalType {
|
||||||
get {
|
get {
|
||||||
|
|
|
@ -55,6 +55,12 @@ namespace GtkSharp.Generation {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string DefaultValue {
|
||||||
|
get {
|
||||||
|
return "(" + QualifiedName + ") 0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override string MarshalType {
|
public override string MarshalType {
|
||||||
get {
|
get {
|
||||||
return "int";
|
return "int";
|
||||||
|
|
|
@ -75,6 +75,8 @@ namespace GtkSharp.Generation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract string DefaultValue { get; }
|
||||||
|
|
||||||
public string QualifiedName {
|
public string QualifiedName {
|
||||||
get {
|
get {
|
||||||
return NS + "." + Name;
|
return NS + "." + Name;
|
||||||
|
|
|
@ -45,6 +45,11 @@ namespace GtkSharp.Generation {
|
||||||
// generatable to unmanaged code
|
// generatable to unmanaged code
|
||||||
string ToNativeReturnType {get;}
|
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
|
// Generates an expression to convert var_name to MarshalType
|
||||||
string CallByName (string var_name);
|
string CallByName (string var_name);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public class LPGen : SimpleGen, IAccessor {
|
public class LPGen : SimpleGen, IAccessor {
|
||||||
|
|
||||||
public LPGen (string ctype) : base (ctype, "long") {}
|
public LPGen (string ctype) : base (ctype, "long", "0L") {}
|
||||||
|
|
||||||
public override string MarshalType {
|
public override string MarshalType {
|
||||||
get {
|
get {
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public class LPUGen : SimpleGen, IAccessor {
|
public class LPUGen : SimpleGen, IAccessor {
|
||||||
|
|
||||||
public LPUGen (string ctype) : base (ctype, "ulong") {}
|
public LPUGen (string ctype) : base (ctype, "ulong", "0") {}
|
||||||
|
|
||||||
public override string MarshalType {
|
public override string MarshalType {
|
||||||
get {
|
get {
|
||||||
|
|
|
@ -28,12 +28,12 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
string from_fmt;
|
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})";
|
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;
|
this.from_fmt = from_fmt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace GtkSharp.Generation {
|
||||||
string call_fmt;
|
string call_fmt;
|
||||||
string from_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.mtype = mtype;
|
||||||
this.call_fmt = call_fmt;
|
this.call_fmt = call_fmt;
|
||||||
|
|
|
@ -145,9 +145,14 @@ namespace GtkSharp.Generation {
|
||||||
string name = symbol.GetAttribute ("name");
|
string name = symbol.GetAttribute ("name");
|
||||||
IGeneratable result = null;
|
IGeneratable result = null;
|
||||||
|
|
||||||
if (type == "simple")
|
if (type == "simple") {
|
||||||
result = new SimpleGen (cname, name);
|
if (symbol.HasAttribute ("default_value"))
|
||||||
else if (type == "manual")
|
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);
|
result = new ManualGen (cname, name);
|
||||||
else if (type == "alias")
|
else if (type == "alias")
|
||||||
result = new AliasGen (cname, name);
|
result = new AliasGen (cname, name);
|
||||||
|
|
|
@ -28,8 +28,9 @@ namespace GtkSharp.Generation {
|
||||||
string type;
|
string type;
|
||||||
string ctype;
|
string ctype;
|
||||||
string ns = String.Empty;
|
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('.');
|
string[] toks = type.Split('.');
|
||||||
this.ctype = ctype;
|
this.ctype = ctype;
|
||||||
|
@ -38,6 +39,7 @@ namespace GtkSharp.Generation {
|
||||||
this.ns = String.Join (".", toks, 0, toks.Length - 1);
|
this.ns = String.Join (".", toks, 0, toks.Length - 1);
|
||||||
else if (toks.Length == 2)
|
else if (toks.Length == 2)
|
||||||
this.ns = toks[0];
|
this.ns = toks[0];
|
||||||
|
this.default_value = default_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string CName {
|
public string CName {
|
||||||
|
@ -70,6 +72,12 @@ namespace GtkSharp.Generation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual string DefaultValue {
|
||||||
|
get {
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual string ToNativeReturnType {
|
public virtual string ToNativeReturnType {
|
||||||
get {
|
get {
|
||||||
return MarshalType;
|
return MarshalType;
|
||||||
|
|
|
@ -24,7 +24,8 @@ namespace GtkSharp.Generation {
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
public class SimpleGen : SimpleBase {
|
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) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,12 @@ namespace GtkSharp.Generation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string DefaultValue {
|
||||||
|
get {
|
||||||
|
return QualifiedName + ".Zero";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override string MarshalType {
|
public override string MarshalType {
|
||||||
get {
|
get {
|
||||||
return "IntPtr";
|
return "IntPtr";
|
||||||
|
|
|
@ -43,37 +43,37 @@ namespace GtkSharp.Generation {
|
||||||
public SymbolTable ()
|
public SymbolTable ()
|
||||||
{
|
{
|
||||||
// Simple easily mapped types
|
// Simple easily mapped types
|
||||||
AddType (new SimpleGen ("void", "void"));
|
AddType (new SimpleGen ("void", "void", String.Empty));
|
||||||
AddType (new SimpleGen ("gpointer", "IntPtr"));
|
AddType (new SimpleGen ("gpointer", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("gboolean", "bool"));
|
AddType (new SimpleGen ("gboolean", "bool", "false"));
|
||||||
AddType (new SimpleGen ("gint", "int"));
|
AddType (new SimpleGen ("gint", "int", "0"));
|
||||||
AddType (new SimpleGen ("guint", "uint"));
|
AddType (new SimpleGen ("guint", "uint", "0"));
|
||||||
AddType (new SimpleGen ("int", "int"));
|
AddType (new SimpleGen ("int", "int", "0"));
|
||||||
AddType (new SimpleGen ("unsigned", "uint"));
|
AddType (new SimpleGen ("unsigned", "uint", "0"));
|
||||||
AddType (new SimpleGen ("unsigned int", "uint"));
|
AddType (new SimpleGen ("unsigned int", "uint", "0"));
|
||||||
AddType (new SimpleGen ("unsigned-int", "uint"));
|
AddType (new SimpleGen ("unsigned-int", "uint", "0"));
|
||||||
AddType (new SimpleGen ("gshort", "short"));
|
AddType (new SimpleGen ("gshort", "short", "0"));
|
||||||
AddType (new SimpleGen ("gushort", "ushort"));
|
AddType (new SimpleGen ("gushort", "ushort", "0"));
|
||||||
AddType (new SimpleGen ("short", "short"));
|
AddType (new SimpleGen ("short", "short", "0"));
|
||||||
AddType (new SimpleGen ("guchar", "byte"));
|
AddType (new SimpleGen ("guchar", "byte", "0"));
|
||||||
AddType (new SimpleGen ("unsigned char", "byte"));
|
AddType (new SimpleGen ("unsigned char", "byte", "0"));
|
||||||
AddType (new SimpleGen ("unsigned-char", "byte"));
|
AddType (new SimpleGen ("unsigned-char", "byte", "0"));
|
||||||
AddType (new SimpleGen ("guint1", "bool"));
|
AddType (new SimpleGen ("guint1", "bool", "false"));
|
||||||
AddType (new SimpleGen ("uint1", "bool"));
|
AddType (new SimpleGen ("uint1", "bool", "false"));
|
||||||
AddType (new SimpleGen ("gint8", "sbyte"));
|
AddType (new SimpleGen ("gint8", "sbyte", "0"));
|
||||||
AddType (new SimpleGen ("guint8", "byte"));
|
AddType (new SimpleGen ("guint8", "byte", "0"));
|
||||||
AddType (new SimpleGen ("gint16", "short"));
|
AddType (new SimpleGen ("gint16", "short", "0"));
|
||||||
AddType (new SimpleGen ("guint16", "ushort"));
|
AddType (new SimpleGen ("guint16", "ushort", "0"));
|
||||||
AddType (new SimpleGen ("gint32", "int"));
|
AddType (new SimpleGen ("gint32", "int", "0"));
|
||||||
AddType (new SimpleGen ("guint32", "uint"));
|
AddType (new SimpleGen ("guint32", "uint", "0"));
|
||||||
AddType (new SimpleGen ("gint64", "long"));
|
AddType (new SimpleGen ("gint64", "long", "0"));
|
||||||
AddType (new SimpleGen ("guint64", "ulong"));
|
AddType (new SimpleGen ("guint64", "ulong", "0"));
|
||||||
AddType (new SimpleGen ("long long", "long"));
|
AddType (new SimpleGen ("long long", "long", "0"));
|
||||||
AddType (new SimpleGen ("gfloat", "float"));
|
AddType (new SimpleGen ("gfloat", "float", "0.0"));
|
||||||
AddType (new SimpleGen ("float", "float"));
|
AddType (new SimpleGen ("float", "float", "0.0"));
|
||||||
AddType (new SimpleGen ("gdouble", "double"));
|
AddType (new SimpleGen ("gdouble", "double", "0.0"));
|
||||||
AddType (new SimpleGen ("double", "double"));
|
AddType (new SimpleGen ("double", "double", "0.0"));
|
||||||
AddType (new SimpleGen ("GQuark", "int"));
|
AddType (new SimpleGen ("GQuark", "int", "0"));
|
||||||
|
|
||||||
// platform specific integer types. these will break on any
|
// platform specific integer types. these will break on any
|
||||||
// platform where sizeof (long) != sizeof (pointer)
|
// 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 ("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 ("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 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
|
// manually wrapped types requiring more complex marshaling
|
||||||
AddType (new ManualGen ("GInitiallyUnowned", "GLib.InitiallyUnowned", "GLib.Object.GetObject ({0})"));
|
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 ("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 MarshalGen ("GType", "GLib.GType", "IntPtr", "{0}.Val", "new GLib.GType({0})"));
|
||||||
AddType (new ByRefGen ("GValue", "GLib.Value"));
|
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.
|
// FIXME: These ought to be handled properly.
|
||||||
AddType (new SimpleGen ("GC", "IntPtr"));
|
AddType (new SimpleGen ("GC", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("GError", "IntPtr"));
|
AddType (new SimpleGen ("GError", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("GMemChunk", "IntPtr"));
|
AddType (new SimpleGen ("GMemChunk", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("GPtrArray", "IntPtr"));
|
AddType (new SimpleGen ("GPtrArray", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("GTimeVal", "IntPtr"));
|
AddType (new SimpleGen ("GTimeVal", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("GClosure", "IntPtr"));
|
AddType (new SimpleGen ("GClosure", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("GArray", "IntPtr"));
|
AddType (new SimpleGen ("GArray", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("GByteArray", "IntPtr"));
|
AddType (new SimpleGen ("GByteArray", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("GData", "IntPtr"));
|
AddType (new SimpleGen ("GData", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("GIOChannel", "IntPtr"));
|
AddType (new SimpleGen ("GIOChannel", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("GTypeModule", "GLib.Object"));
|
AddType (new SimpleGen ("GTypeModule", "GLib.Object", "null"));
|
||||||
AddType (new SimpleGen ("GHashTable", "System.IntPtr"));
|
AddType (new SimpleGen ("GHashTable", "System.IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("va_list", "IntPtr"));
|
AddType (new SimpleGen ("va_list", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("GParamSpec", "IntPtr"));
|
AddType (new SimpleGen ("GParamSpec", "IntPtr", "IntPtr.Zero"));
|
||||||
AddType (new SimpleGen ("gconstpointer", "IntPtr"));
|
AddType (new SimpleGen ("gconstpointer", "IntPtr", "IntPtr.Zero"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddType (IGeneratable gen)
|
public void AddType (IGeneratable gen)
|
||||||
|
|
Loading…
Reference in a new issue