2002-01-16 Mike Kestner <mkestner@speakeasy.net>

* 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.

svn path=/trunk/gtk-sharp/; revision=2012
This commit is contained in:
Mike Kestner 2002-01-17 00:26:46 +00:00
parent 9fcf82d28e
commit 88175147cf
11 changed files with 298 additions and 10 deletions

View file

@ -1,3 +1,16 @@
2002-01-16 Mike Kestner <mkestner@speakeasy.net>
* 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 <mkestner@speakeasy.net>
* generator/ObjectGen.cs : Add property generation.

109
generator/BoxedGen.cs Normal file
View file

@ -0,0 +1,109 @@
// GtkSharp.Generation.BoxedGen.cs - The Boxed Type Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (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 ("// <c> 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();
}
}
}

View file

@ -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);
}

View file

@ -73,6 +73,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));
break;

View file

@ -95,7 +95,6 @@ namespace GtkSharp.Generation {
Console.WriteLine ("Unexpected node");
break;
}
}
sw.WriteLine ("\t}");

View file

@ -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;
}
}
}

File diff suppressed because one or more lines are too long

66
glib/Boxed.cs Normal file
View file

@ -0,0 +1,66 @@
// GtkSharp.Boxed.cs - Base class for deriving marshallable structures.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001-2002 Mike Kestner
namespace GtkSharp {
using System;
using System.Runtime.InteropServices;
/// <summary>
/// Boxed Class
/// </summary>
///
/// <remarks>
/// An abstract base class to derive structures and marshal them.
/// </remarks>
public abstract class Boxed {
IntPtr _raw;
// Destructor is required since we are allocating unmanaged
// heap resources.
~Boxed ()
{
Marshal.FreeHGlobal (_raw);
}
/// <summary>
/// Raw Property
/// </summary>
///
/// <remarks>
/// Gets a marshallable IntPtr.
/// </remarks>
public IntPtr Raw {
get {
if (_raw == IntPtr.Zero) {
// FIXME: Ugly hack.
_raw = Marshal.AllocHGlobal (128);
Marshal.StructureToPtr (this, _raw, true);
}
return _raw;
}
}
/// <summary>
/// GetBoxed Shared Method
/// </summary>
///
/// <remarks>
/// Gets a managed class representing a raw ref.
/// </remarks>
public static Boxed GetBoxed (IntPtr raw)
{
// FIXME: Use the type manager to box the raw ref.
return null;
}
}
}

View file

@ -306,6 +306,26 @@ namespace GLib {
val = GLib.Object.GetObject (obj);
}
/// <summary>
/// GetProperty Method
/// </summary>
///
/// <remarks>
/// Accesses a Boxed Property.
/// </remarks>
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);
}
/// <summary>
/// GetProperty Method
/// </summary>
/// <summary>
/// GetProperty Method
/// </summary>
@ -475,6 +495,21 @@ namespace GLib {
val.Handle, new IntPtr (0));
}
/// <summary>
/// SetProperty Method
/// </summary>
///
/// <remarks>
/// Changes the value of a Boxed Property.
/// </remarks>
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")]

View file

@ -89,6 +89,14 @@ while ($line = <STDIN>) {
last if ($line =~ /^}/);
}
$pedefs{$class} = $pedef;
} elsif ($line =~ /g_boxed_type_register_static/) {
$boxdef = $line;
while ($line !~ /;/) {
$boxdef .= ($line = <STDIN>);
}
$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 = <STDIN>) {
$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;

View file

@ -8,7 +8,7 @@
# <c> 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 = <INFILE>) {
next if ($line !~ /\{/);
chomp($line);
$builtin = "BUILTIN" . $line;
$builtin .= <INFILE>;
print $builtin;
}
next;
}
while ($line = <INFILE>) {
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 = <INFILE>;
}
print $line;
next;
}
do {