2002-06-24 Rachel Hestilow <hestilow@ximian.com>

* glib/EnumWrapper.cs: New class which holds an enum int.

	* glib/Value.cs: Add support for glib enum types. We needed
	to use EnumWrapper for this because otherwise the int operator
	wouldn't know which glib function to use.

	* generator/BoxedGen.cs, ClassBase.cs, Ctor.cs, EnumGen.cs,
	InterfaceGen.cs, Method.cs, ObjectGen.cs, Signal.cs, StructGen.cs:
	Create more doc stubs.

	* generator/Property.cs: Generate enum values correctly.

	* generator/Ctor.cs: Refactor generation to honor metadata-specified
	collision preference.

	* parser/Gtk.metadata: Added constructor collision preferences to
	all known clashes.

	* parse/Gdk.metadata: Added (for Pixbuf clashes).

svn path=/trunk/gtk-sharp/; revision=5437
This commit is contained in:
Rachel Hestilow 2002-06-24 22:04:10 +00:00
parent b10fe35ac0
commit 1f4ff5bb86
18 changed files with 320 additions and 39 deletions

View File

@ -1,3 +1,25 @@
2002-06-24 Rachel Hestilow <hestilow@ximian.com>
* glib/EnumWrapper.cs: New class which holds an enum int.
* glib/Value.cs: Add support for glib enum types. We needed
to use EnumWrapper for this because otherwise the int operator
wouldn't know which glib function to use.
* generator/BoxedGen.cs, ClassBase.cs, Ctor.cs, EnumGen.cs,
InterfaceGen.cs, Method.cs, ObjectGen.cs, Signal.cs, StructGen.cs:
Create more doc stubs.
* generator/Property.cs: Generate enum values correctly.
* generator/Ctor.cs: Refactor generation to honor metadata-specified
collision preference.
* parser/Gtk.metadata: Added constructor collision preferences to
all known clashes.
* parse/Gdk.metadata: Added (for Pixbuf clashes).
2002-06-24 Duncan Mak <duncan@ximian.com>
* glue/fileselection.c: New file, defines accessor functions to

View File

@ -34,6 +34,10 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine("\t\t/// <summary> " + Name + " Boxed Struct</summary>");
sw.WriteLine("\t\t/// <remarks>");
sw.WriteLine("\t\t/// </remarks>");
sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
sw.WriteLine ("\tpublic class " + Name + " : GLib.Boxed {");
sw.WriteLine ();

View File

@ -101,14 +101,14 @@ namespace GtkSharp.Generation {
}
}
public void GenSignals (StreamWriter sw)
public void GenSignals (StreamWriter sw, bool gen_docs)
{
if (sigs == null)
return;
foreach (Signal sig in sigs.Values) {
if (sig.Validate ())
sig.Generate (sw);
sig.Generate (sw, gen_docs);
else
Console.WriteLine(" in Object " + Name);
}
@ -135,7 +135,7 @@ namespace GtkSharp.Generation {
(props != null) && props.ContainsKey(mname.Substring(3)));
}
public void GenMethods (StreamWriter sw, Hashtable collisions)
public void GenMethods (StreamWriter sw, Hashtable collisions, bool gen_docs)
{
if (methods == null)
return;
@ -154,7 +154,7 @@ namespace GtkSharp.Generation {
method.Name = Name + "." + method.Name;
method.Protection = "";
}
method.Generate (sw);
method.Generate (sw, gen_docs);
if (oname != null)
{
method.Name = oname;

View File

@ -16,13 +16,21 @@ namespace GtkSharp.Generation {
private string libname;
private XmlElement elem;
private Parameters parms;
private bool preferred;
public bool Preferred {
get { return preferred; }
set { preferred = value; }
}
public Ctor (string libname, XmlElement elem) {
this.libname = libname;
this.elem = elem;
XmlElement parms_elem = elem ["parameters"];
if (parms_elem != null)
parms = new Parameters (parms_elem);
if (elem.HasAttribute ("preferred"))
preferred = true;
}
public bool Validate ()
@ -39,6 +47,18 @@ namespace GtkSharp.Generation {
return true;
}
public void InitClashMap (Hashtable clash_map)
{
string sigtypes = (parms != null) ? parms.SignatureTypes : "";
if (clash_map.ContainsKey (sigtypes)) {
int num = (int) clash_map[sigtypes];
clash_map[sigtypes] = ++num;
Console.WriteLine ("CLASH: {0} {1}", elem.GetAttribute ("cname"), num);
}
else
clash_map[sigtypes] = 0;
}
public void Generate (StreamWriter sw, Hashtable clash_map)
{
string sigtypes = "";
@ -52,12 +72,7 @@ namespace GtkSharp.Generation {
sigtypes = parms.SignatureTypes;
}
bool clash = false;
if (clash_map.ContainsKey(sigtypes)) {
clash = true;
} else {
clash_map[sigtypes] = elem;
}
int clashes = (int) clash_map[sigtypes];
string cname = elem.GetAttribute("cname");
string name = ((XmlElement)elem.ParentNode).GetAttribute("name");
@ -71,7 +86,7 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\tstatic extern " + safety + "IntPtr " + cname + isig);
sw.WriteLine();
if (clash) {
if (clashes > 0 && !Preferred) {
String mname = cname.Substring(cname.IndexOf("new"));
mname = mname.Substring(0,1).ToUpper() + mname.Substring(1);
int idx;

View File

@ -38,9 +38,15 @@ namespace GtkSharp.Generation {
if (Elem.GetAttribute("type") == "flags") {
sw.WriteLine ("\tusing System;");
sw.WriteLine ();
sw.WriteLine ("\t[Flags]");
}
sw.WriteLine("\t\t/// <summary> " + Name + " enumeration </summary>");
sw.WriteLine("\t\t/// <remarks>");
sw.WriteLine("\t\t/// </remarks>");
if (Elem.GetAttribute("type") == "flags")
sw.WriteLine ("\t[Flags]");
sw.WriteLine ("\tpublic enum " + Name + " {");
sw.WriteLine ();
@ -50,6 +56,11 @@ namespace GtkSharp.Generation {
}
XmlElement member = (XmlElement) node;
sw.WriteLine("\t\t/// <summary />");
sw.WriteLine("\t\t/// <remarks>");
sw.WriteLine("\t\t/// </remarks>");
sw.Write ("\t\t" + member.GetAttribute("name"));
if (member.HasAttribute("value")) {
sw.WriteLine (" = " + member.GetAttribute("value") + ",");

View File

@ -21,6 +21,10 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\tusing System;");
sw.WriteLine ();
sw.WriteLine("\t\t/// <summary> " + Name + " Interface</summary>");
sw.WriteLine("\t\t/// <remarks>");
sw.WriteLine("\t\t/// </remarks>");
sw.WriteLine ("\tpublic interface " + Name + " : GLib.IWrapper {");
sw.WriteLine ();

View File

@ -190,6 +190,8 @@ namespace GtkSharp.Generation {
if (!Initialize ())
return;
GenerateComments (sw);
if (is_get || is_set)
{
Method comp = GetComplement ();
@ -219,6 +221,21 @@ namespace GtkSharp.Generation {
Statistics.MethodCount++;
}
void GenerateComments (StreamWriter sw)
{
string summary, sname;
sw.WriteLine();
if (is_get || is_set) {
summary = "Property";
sname = Name.Substring (3);
} else {
summary = "Method";
sname = Name;
}
sw.WriteLine("\t\t/// <summary> " + sname + " " + summary + " </summary>");
sw.WriteLine("\t\t/// <remarks> To be completed </remarks>");
}
protected void GenerateImport (StreamWriter sw)
{
sw.WriteLine("\t\t[DllImport(\"" + libname + "\")]");
@ -227,6 +244,11 @@ namespace GtkSharp.Generation {
}
public void Generate (StreamWriter sw)
{
Generate (sw, true);
}
public void Generate (StreamWriter sw, bool gen_docs)
{
Method comp = null;
@ -255,12 +277,8 @@ namespace GtkSharp.Generation {
if (comp != null && s_ret == comp.parms.AccessorReturnType)
comp.GenerateImport (sw);
if (!(is_set || is_get))
{
sw.WriteLine("\t\t/// <summary> " + Name + " Method </summary>");
sw.WriteLine("\t\t/// <remarks> To be completed </remarks>");
sw.WriteLine();
}
if (gen_docs)
GenerateComments (sw);
sw.Write("\t\t");
if (protection != "")

View File

@ -55,6 +55,9 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine("\t\t/// <summary> " + Name + " Class</summary>");
sw.WriteLine("\t\t/// <remarks>");
sw.WriteLine("\t\t/// </remarks>");
sw.Write ("\tpublic class " + Name);
string cs_parent = SymbolTable.GetCSType(Elem.GetAttribute("parent"));
if (cs_parent != "")
@ -84,10 +87,10 @@ namespace GtkSharp.Generation {
if (has_sigs)
{
sw.WriteLine("\t\tprivate Hashtable Signals = new Hashtable();");
GenSignals (sw);
GenSignals (sw, true);
}
GenMethods (sw, null);
GenMethods (sw, null, true);
if (interfaces != null) {
Hashtable all_methods = new Hashtable ();
@ -104,8 +107,8 @@ namespace GtkSharp.Generation {
foreach (string iface in interfaces) {
ClassBase igen = SymbolTable.GetClassGen (iface);
igen.GenMethods (sw, collisions);
igen.GenSignals (sw);
igen.GenMethods (sw, collisions, false);
igen.GenSignals (sw, false);
}
}
@ -159,13 +162,26 @@ namespace GtkSharp.Generation {
Hashtable clash_map = new Hashtable();
if (ctors != null)
if (ctors != null) {
bool has_preferred = false;
foreach (Ctor ctor in ctors) {
if (ctor.Validate ())
ctor.Generate (sw, clash_map);
if (ctor.Validate ()) {
ctor.InitClashMap (clash_map);
if (ctor.Preferred)
has_preferred = true;
}
else
Console.WriteLine(" in Object " + Name);
}
if (!has_preferred && ctors.Count > 0)
((Ctor) ctors[0]).Preferred = true;
foreach (Ctor ctor in ctors) {
if (ctor.Validate ())
ctor.Generate (sw, clash_map);
}
}
if (!clash_map.ContainsKey("")) {
sw.WriteLine("\t\tprotected " + Name + "() : base(){}");

View File

@ -55,22 +55,27 @@ namespace GtkSharp.Generation {
string v_type = "";
if (SymbolTable.IsEnum(c_type)) {
v_type = "int";
v_type = "(int) (GLib.EnumWrapper)";
} else if (SymbolTable.IsInterface(c_type)) {
// FIXME: Handle interface props properly.
Console.Write("Interface property detected ");
Statistics.ThrottledCount++;
return;
} else if (SymbolTable.IsObject(c_type)) {
v_type = "GLib.Object";
v_type = "(GLib.Object)";
} else if (SymbolTable.IsBoxed (c_type)) {
v_type = "GLib.Boxed";
v_type = "(GLib.Boxed)";
}
if (elem.HasAttribute("construct-only") && !elem.HasAttribute("readable")) {
return;
}
sw.WriteLine();
sw.WriteLine("\t\t/// <summary> " + name + " Property </summary>");
sw.WriteLine("\t\t/// <remarks>");
sw.WriteLine("\t\t/// </remarks>");
sw.WriteLine("\t\tpublic " + cs_type + " " + name + " {");
if (elem.HasAttribute("readable")) {
sw.WriteLine("\t\t\tget {");
@ -78,7 +83,7 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\t\t\tGetProperty(" + cname + ", val);");
sw.Write("\t\t\t\treturn (" + cs_type + ") ");
if (v_type != "") {
sw.Write("(" + v_type + ") ");
sw.Write(v_type + " ");
}
sw.WriteLine("val;");
sw.WriteLine("\t\t\t}");
@ -87,10 +92,14 @@ namespace GtkSharp.Generation {
if (elem.HasAttribute("writeable") && !elem.HasAttribute("construct-only")) {
sw.WriteLine("\t\t\tset {");
sw.Write("\t\t\t\tSetProperty(" + cname + ", new GLib.Value(");
if (v_type != "") {
sw.Write("(" + v_type + ") ");
if (SymbolTable.IsEnum(c_type)) {
sw.WriteLine("Handle, " + cname + ", new GLib.EnumWrapper ((int) value)));");
} else {
if (v_type != "") {
sw.Write(v_type + " ");
}
sw.WriteLine("value));");
}
sw.WriteLine("value));");
sw.WriteLine("\t\t\t}");
}

View File

@ -46,21 +46,28 @@ namespace GtkSharp.Generation {
public void GenerateDecl (StreamWriter sw)
{
GenComments (sw);
if (elem.HasAttribute("new_flag"))
sw.Write("new ");
sw.WriteLine ("\t\tevent EventHandler " + Name + ";");
}
public void Generate (StreamWriter sw)
public void GenComments (StreamWriter sw)
{
string cname = "\"" + elem.GetAttribute("cname") + "\"";
marsh = "GtkSharp." + marsh;
sw.WriteLine();
sw.WriteLine("\t\t/// <summary> " + Name + " Event </summary>");
sw.WriteLine("\t\t/// <remarks>");
// FIXME: Generate some signal docs
sw.WriteLine("\t\t/// </remarks>");
sw.WriteLine();
}
public void Generate (StreamWriter sw, bool gen_docs)
{
string cname = "\"" + elem.GetAttribute("cname") + "\"";
marsh = "GtkSharp." + marsh;
if (gen_docs)
GenComments (sw);
sw.Write("\t\tpublic ");
if (elem.HasAttribute("new_flag"))
sw.Write("new ");

View File

@ -40,6 +40,10 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine("\t\t/// <summary> " + Name + " Struct </summary>");
sw.WriteLine("\t\t/// <remarks>");
sw.WriteLine("\t\t/// </remarks>");
sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
sw.WriteLine ("\tpublic class " + Name + " {");
sw.WriteLine ();

File diff suppressed because one or more lines are too long

26
glib/EnumWrapper.cs Normal file
View File

@ -0,0 +1,26 @@
// EnumWrapper.cs - Class to hold arbitrary glib enums
//
// Author: Rachel Hestilow <hestilow@ximian.com>
//
// (c) 2002 Rachel Hestilow
namespace GLib {
using System;
using System.Runtime.InteropServices;
// <summary> Enum wrapping class </summary>
// <remarks> </remarks>
public class EnumWrapper {
int val;
public EnumWrapper (int val) {
this.val = val;
}
public static explicit operator int (EnumWrapper wrap) {
return wrap.val;
}
}
}

View File

@ -219,6 +219,23 @@ namespace GLib {
g_value_set_uint (_val, val);
}
[DllImport("gobject-2.0")]
static extern void g_value_set_enum (IntPtr val, int data);
/// <summary>
/// Value Constructor
/// </summary>
///
/// <remarks>
/// Constructs a Value from a specified enum wrapper.
/// </remarks>
public Value (IntPtr obj, string prop_name, EnumWrapper wrap)
{
_val = gtksharp_value_create_from_property (obj, prop_name);
g_value_set_enum (_val, (int) wrap);
}
[DllImport("gobject-2.0")]
static extern bool g_value_get_boolean (IntPtr val);
@ -400,6 +417,26 @@ namespace GLib {
return g_value_get_uint (val._val);
}
[DllImport("gobject-2.0")]
static extern int g_value_get_enum (IntPtr val);
/// <summary>
/// Value to Enum Conversion
/// </summary>
///
/// <remarks>
/// Extracts an enum from a Value. Note, this method
/// will produce an exception if the Value does not hold an
/// enum value.
/// </remarks>
public static explicit operator EnumWrapper (Value val)
{
// FIXME: Insert an appropriate exception here if
// _val.type indicates an error.
return new EnumWrapper (g_value_get_enum (val._val));
}
/// <summary>
/// Handle Property
/// </summary>

17
parser/Gdk.metadata Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<metadata>
<!-- constructor collision hints -->
<rule>
<class name="GdkPixbuf">
<constructor>gdk_pixbuf_new_from_file</constructor>
</class>
<data>
<attribute target="method">
<name>preferred</name>
<value>1</value>
</attribute>
</data>
</rule>
</metadata>

View File

@ -56,6 +56,43 @@
</data>
</rule>
<!-- constructor collision hints -->
<rule>
<class name="GtkButton">
<constructor>gtk_button_new_with_mnemonic</constructor>
</class>
<class name="GtkCheckButton">
<constructor>gtk_check_button_new_with_mnemonic</constructor>
</class>
<class name="GtkRadioButton">
<constructor>gtk_radio_button_new_with_mnemonic</constructor>
</class>
<class name="GtkToggleButton">
<constructor>gtk_toggle_button_new_with_mnemonic</constructor>
</class>
<class name="GtkLabel">
<constructor>gtk_label_new_with_mnemonic</constructor>
</class>
<class name="GtkMenuItem">
<constructor>gtk_menu_item_new_with_mnemonic</constructor>
</class>
<class name="GtkCheckMenuItem">
<constructor>gtk_check_menu_item_new_with_mnemonic</constructor>
</class>
<class name="GtkRadioMenuItem">
<constructor>gtk_radio_menu_item_new_with_mnemonic</constructor>
</class>
<class name="GtkImageMenuItem">
<constructor>gtk_image_menu_item_new_with_mnemonic</constructor>
</class>
<data>
<attribute target="method">
<name>preferred</name>
<value>1</value>
</attribute>
</data>
</rule>
<!-- renames -->
<rule>
<class name="GtkEditable">

17
sources/Gdk.metadata Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<metadata>
<!-- constructor collision hints -->
<rule>
<class name="GdkPixbuf">
<constructor>gdk_pixbuf_new_from_file</constructor>
</class>
<data>
<attribute target="method">
<name>preferred</name>
<value>1</value>
</attribute>
</data>
</rule>
</metadata>

View File

@ -56,6 +56,43 @@
</data>
</rule>
<!-- constructor collision hints -->
<rule>
<class name="GtkButton">
<constructor>gtk_button_new_with_mnemonic</constructor>
</class>
<class name="GtkCheckButton">
<constructor>gtk_check_button_new_with_mnemonic</constructor>
</class>
<class name="GtkRadioButton">
<constructor>gtk_radio_button_new_with_mnemonic</constructor>
</class>
<class name="GtkToggleButton">
<constructor>gtk_toggle_button_new_with_mnemonic</constructor>
</class>
<class name="GtkLabel">
<constructor>gtk_label_new_with_mnemonic</constructor>
</class>
<class name="GtkMenuItem">
<constructor>gtk_menu_item_new_with_mnemonic</constructor>
</class>
<class name="GtkCheckMenuItem">
<constructor>gtk_check_menu_item_new_with_mnemonic</constructor>
</class>
<class name="GtkRadioMenuItem">
<constructor>gtk_radio_menu_item_new_with_mnemonic</constructor>
</class>
<class name="GtkImageMenuItem">
<constructor>gtk_image_menu_item_new_with_mnemonic</constructor>
</class>
<data>
<attribute target="method">
<name>preferred</name>
<value>1</value>
</attribute>
</data>
</rule>
<!-- renames -->
<rule>
<class name="GtkEditable">