diff --git a/ChangeLog b/ChangeLog index 472517c14..87145d47b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2002-01-16 Mike Kestner + + * generator/BoxedGen.cs : New boxed type generatable. + * generator/ObjectGen.cs : Add boxed type property generation and stub + off interface properties for now. + * generator/Parser.cs : Add boxed element parsing. + * generator/SymbolTable.cs : Add IsBoxed and IsInterface methods. + * glib/Boxed.cs : New base class for deriving boxed types. + * glib/Object.cs : Add boxed GetProp/SetProp methods. + * parser/gapi2xml.pl : Add boxed type element formatting. + * parser/gapi_pp.pl : Add preprocessing of the generated sourcefiles. + Handle the builtins and make them identifiable to the xml generator. + 2002-01-11 Mike Kestner * generator/ObjectGen.cs : Add property generation. diff --git a/generator/BoxedGen.cs b/generator/BoxedGen.cs new file mode 100644 index 000000000..f47a207a2 --- /dev/null +++ b/generator/BoxedGen.cs @@ -0,0 +1,109 @@ +// GtkSharp.Generation.BoxedGen.cs - The Boxed Type Generatable. +// +// Author: Mike Kestner +// +// (c) 2001-2002 Mike Kestner + +namespace GtkSharp.Generation { + + using System; + using System.IO; + using System.Xml; + + public class BoxedGen : StructBase, IGeneratable { + + public BoxedGen (String ns, XmlElement elem) : base (ns, elem) {} + + public String Name { + get + { + return elem.GetAttribute("name"); + } + } + + public String QualifiedName { + get + { + return ns + "." + elem.GetAttribute("name"); + } + } + + public String CName { + get + { + return elem.GetAttribute("cname"); + } + } + + public String MarshalType { + get + { + return QualifiedName; + } + } + + public String CallByName (String var_name) + { + return var_name + ".Raw"; + } + + public void Generate (SymbolTable table) + { + if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) { + Directory.CreateDirectory("..\\"+ns.ToLower()+"\\generated"); + } + String filename = "..\\" + ns.ToLower() + "\\generated\\" + Name + ".cs"; + + FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write); + StreamWriter sw = new StreamWriter (stream); + + sw.WriteLine ("// Generated File. Do not modify."); + sw.WriteLine ("// 2001-2002 Mike Kestner"); + sw.WriteLine (); + + sw.WriteLine ("namespace " + ns + " {"); + sw.WriteLine (); + + sw.WriteLine ("\tusing System;"); + sw.WriteLine ("\tusing System.Collections;"); + sw.WriteLine ("\tusing System.Runtime.InteropServices;"); + sw.WriteLine (); + + sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]"); + sw.WriteLine ("\tpublic class " + Name + " : GtkSharp.Boxed {"); + sw.WriteLine (); + + foreach (XmlNode node in elem.ChildNodes) { + + XmlElement member = (XmlElement) node; + + switch (node.Name) { + case "field": + // GenField(member, table, sw); + break; + + case "callback": + break; + + case "constructor": + break; + + case "method": + break; + + default: + Console.WriteLine ("Unexpected node"); + break; + } + } + + sw.WriteLine ("\t}"); + sw.WriteLine (); + sw.WriteLine ("}"); + + sw.Flush(); + sw.Close(); + } + } +} + diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index e7f4a13e5..330afe438 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -135,6 +135,12 @@ namespace GtkSharp.Generation { if (table.IsObject(c_type)) { m_type = "GLib.Object"; + } else if (table.IsBoxed(c_type)) { + m_type = "GtkSharp.Boxed"; + } else if (table.IsInterface(c_type)) { + // FIXME: Handle interface props properly. + Console.Write("Interface property detected "); + return true; } else { m_type = table.GetMarshalType(c_type); } diff --git a/generator/Parser.cs b/generator/Parser.cs index 3498a8beb..b5349afa4 100644 --- a/generator/Parser.cs +++ b/generator/Parser.cs @@ -72,6 +72,10 @@ namespace GtkSharp.Generation { case "alias": break; + + case "boxed": + table.AddType (new BoxedGen (ns_name, elem)); + break; case "callback": table.AddType (new CallbackGen (ns_name, elem)); diff --git a/generator/StructGen.cs b/generator/StructGen.cs index cb518fcc4..094c05bf9 100644 --- a/generator/StructGen.cs +++ b/generator/StructGen.cs @@ -94,10 +94,9 @@ namespace GtkSharp.Generation { default: Console.WriteLine ("Unexpected node"); break; - } - + } } - + sw.WriteLine ("\t}"); sw.WriteLine (); sw.WriteLine ("}"); diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 92a2cdea6..ab95a9259 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -105,6 +105,28 @@ namespace GtkSharp.Generation { } } + public bool IsBoxed(String c_type) + { + if (complex_types.ContainsKey(c_type)) { + IGeneratable gen = (IGeneratable) complex_types[c_type]; + if (gen is BoxedGen) { + return true; + } + } + return false; + } + + public bool IsInterface(String c_type) + { + if (complex_types.ContainsKey(c_type)) { + IGeneratable gen = (IGeneratable) complex_types[c_type]; + if (gen is InterfaceGen) { + return true; + } + } + return false; + } + public bool IsObject(String c_type) { if (complex_types.ContainsKey(c_type)) { @@ -115,7 +137,6 @@ namespace GtkSharp.Generation { } return false; } - } } diff --git a/generator/api.xml b/generator/api.xml index 4e8a686cc..c8c517efc 100644 --- a/generator/api.xml +++ b/generator/api.xml @@ -1,2 +1,2 @@ - + diff --git a/glib/Boxed.cs b/glib/Boxed.cs new file mode 100644 index 000000000..82b08c0e0 --- /dev/null +++ b/glib/Boxed.cs @@ -0,0 +1,66 @@ +// GtkSharp.Boxed.cs - Base class for deriving marshallable structures. +// +// Author: Mike Kestner +// +// (c) 2001-2002 Mike Kestner + +namespace GtkSharp { + + using System; + using System.Runtime.InteropServices; + + /// + /// Boxed Class + /// + /// + /// + /// An abstract base class to derive structures and marshal them. + /// + + public abstract class Boxed { + + IntPtr _raw; + + // Destructor is required since we are allocating unmanaged + // heap resources. + + ~Boxed () + { + Marshal.FreeHGlobal (_raw); + } + + /// + /// Raw Property + /// + /// + /// + /// Gets a marshallable IntPtr. + /// + + public IntPtr Raw { + get { + if (_raw == IntPtr.Zero) { + // FIXME: Ugly hack. + _raw = Marshal.AllocHGlobal (128); + Marshal.StructureToPtr (this, _raw, true); + } + return _raw; + } + } + + /// + /// GetBoxed Shared Method + /// + /// + /// + /// Gets a managed class representing a raw ref. + /// + + public static Boxed GetBoxed (IntPtr raw) + { + // FIXME: Use the type manager to box the raw ref. + return null; + } + + } +} diff --git a/glib/Object.cs b/glib/Object.cs index b52b0b59c..af20cf83e 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -306,6 +306,26 @@ namespace GLib { val = GLib.Object.GetObject (obj); } + /// + /// GetProperty Method + /// + /// + /// + /// Accesses a Boxed Property. + /// + + public void GetProperty (String name, out GtkSharp.Boxed val) + { + IntPtr raw; + g_object_get (RawObject, + Marshal.StringToHGlobalAnsi (name), + out raw, new IntPtr (0)); + val = GtkSharp.Boxed.GetBoxed (raw); + } + + /// + /// GetProperty Method + /// /// /// GetProperty Method /// @@ -475,6 +495,21 @@ namespace GLib { val.Handle, new IntPtr (0)); } + /// + /// SetProperty Method + /// + /// + /// + /// Changes the value of a Boxed Property. + /// + + public void SetProperty (String name, GtkSharp.Boxed val) + { + g_object_set (RawObject, + Marshal.StringToHGlobalAnsi (name), + val.Raw, new IntPtr (0)); + } + /* [DllImport("gtk-1.3.dll")] diff --git a/parser/gapi2xml.pl b/parser/gapi2xml.pl index 741e21dee..6fd80d78c 100755 --- a/parser/gapi2xml.pl +++ b/parser/gapi2xml.pl @@ -89,6 +89,14 @@ while ($line = ) { last if ($line =~ /^}/); } $pedefs{$class} = $pedef; + } elsif ($line =~ /g_boxed_type_register_static/) { + $boxdef = $line; + while ($line !~ /;/) { + $boxdef .= ($line = ); + } + $boxdef =~ s/\n\s*//g; + $boxdef =~ /\(\"(\w+)\"/; + $boxdefs{$1} = $boxdef; } elsif ($line =~ /^(const|G_CONST_RETURN)?\s*\w+\s*\**\s*(\w+)\s*\(/) { $fname = $2; $fdef = ""; @@ -110,6 +118,10 @@ while ($line = ) { $objects{$1} .= ":$2"; } elsif ($line =~ /INSTANCE_GET_INTERFACE.*,\s*(\w+),\s*(\w+)/) { $ifaces{$1} = $2; + } elsif ($line =~ /^BUILTIN\s*\{\s*\"(\w+)\".*GTK_TYPE_BOXED/) { + $boxdefs{$1} = $line; + } elsif ($line =~ /^BUILTIN\s*\{\s*\"(\w+)\".*GTK_TYPE_(ENUM|FLAGS)/) { + # ignoring these for now. } else { print $line; } @@ -275,7 +287,11 @@ foreach $key (sort (keys (%types))) { next; } - $struct_el = addNameElem($ns_elem, 'struct', $key, $ns); + if (exists($boxdefs{$key})) { + $struct_el = addNameElem($ns_elem, 'boxed', $key, $ns); + } else { + $struct_el = addNameElem($ns_elem, 'struct', $key, $ns); + } $def =~ s/\s+/ /g; $def =~ /\{(.+)\}/; addFieldElems($struct_el, split(/;/, $1)); @@ -447,7 +463,7 @@ sub addPropElem $type = "g$type"; } elsif ($type =~ /string/) { $type = "gchar*"; - } elsif ($type =~ /enum|flags|object/) { + } elsif ($type =~ /boxed|enum|flags|object/) { $type = $params[3]; $type =~ s/TYPE_//; $type =~ s/\s+//g; diff --git a/parser/gapi_pp.pl b/parser/gapi_pp.pl index c8c7c0840..5afd23916 100755 --- a/parser/gapi_pp.pl +++ b/parser/gapi_pp.pl @@ -8,7 +8,7 @@ # 2001 Mike Kestner $eatit_regex = "^#if.*(__cplusplus|DEBUG|DISABLE_(DEPRECATED|COMPAT)|ENABLE_BROKEN|COMPILATION)"; -$ignoreit_regex = '^\s+\*|#\s*include|#\s*else|#\s*endif|#\s*undef|G_(BEGIN|END)_DECLS|extern|GDKVAR|GTKVAR|GTKMAIN_C_VAR|GTKTYPEUTILS_VAR|VARIABLE'; +$ignoreit_regex = '^\s+\*|#\s*include|#\s*else|#\s*endif|#\s*undef|G_(BEGIN|END)_DECLS|extern|GDKVAR|GTKVAR|GTKMAIN_C_VAR|GTKTYPEUTILS_VAR|VARIABLE|GTKTYPEBUILTIN'; foreach $dir (@ARGV) { @hdrs = (@hdrs, `ls $dir/*.h`); @@ -16,7 +16,7 @@ foreach $dir (@ARGV) { foreach $fname (@hdrs) { - if ($fname =~ /test|private|internals|gtktextlayout/) { + if ($fname =~ /test|private|internals|gtktextlayout|gtkmarshalers/) { @privhdrs = (@privhdrs, $fname); next; } @@ -57,12 +57,31 @@ foreach $fname (`ls $ARGV[0]/*.c`, @privhdrs) { open(INFILE, $fname) || die "Could open $fname\n"; + if ($fname =~ /builtins_ids/) { + while ($line = ) { + next if ($line !~ /\{/); + + chomp($line); + $builtin = "BUILTIN" . $line; + $builtin .= ; + print $builtin; + } + next; + } + while ($line = ) { - next if ($line !~ /^(struct|\w+_class_init)/); + next if ($line !~ /^(struct|\w+_class_init)|g_boxed_type_register_static/); if ($line =~ /^struct/) { # need some of these to parse out parent types print "private"; + } elsif ($line =~ /g_boxed_type_register_static/) { + while ($line !~ /;/) { + print $line; + $line = ; + } + print $line; + next; } do {