From 5d67982de9aae4a346fc6bfce900e6d5504c6d47 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Fri, 21 Jun 2002 20:25:43 +0000 Subject: [PATCH] 2002-06-21 Mike Kestner * makefile : remove gdk.imaging from the build * gdk.imaging/* : kill * generated/BoxedGen.cs : XmlNode namespace handling. Use GenBase. * generated/CallbackGen.cs : XmlNode namespace handling. * generated/Ctor.cs : construct with libname not ns. * generated/EnumGen.cs : XmlNode namespace handling. * generated/GenBase.cs : XmlNode namespace handling. Make AppendCustom an instance method so it can use the private fields instead of params. * generated/InterfaceGen.cs : XmlNode namespace handling. * generated/Method.cs : construct with libname not ns. * generated/ObjectGen.cs : XmlNode namespace handling. * generated/Parser.cs : Use new XmlNode namespace ctors. * generated/Signal.cs : Lose the namespace field. * generated/StructBase.cs : derive from ClassBase * generated/StructGen.cs : XmlNode namespace handling. Use GenBase. * generated/SymbolTable.cs : nuke GetDllName method. * generator/gtkapi.xml : Add library name to namespace node. * parser/build.pl : refactor for library name param * parser/gapi2xml.pl : add libname param handling * sample/Makefile.in : build linux on make install, but don't install. svn path=/trunk/gtk-sharp/; revision=5400 --- ChangeLog | 23 +++++++++++++++++++++++ generator/BoxedGen.cs | 36 +++++------------------------------- generator/CallbackGen.cs | 2 +- generator/ClassBase.cs | 6 +++--- generator/Ctor.cs | 8 ++++---- generator/EnumGen.cs | 2 +- generator/GenBase.cs | 26 ++++++++++++++++---------- generator/InterfaceGen.cs | 2 +- generator/Method.cs | 8 ++++---- generator/ObjectGen.cs | 6 +++--- generator/Parser.cs | 12 ++++++------ generator/Signal.cs | 4 +--- generator/StructBase.cs | 37 ++++--------------------------------- generator/StructGen.cs | 31 ++++++------------------------- generator/SymbolTable.cs | 5 ----- generator/gtkapi.xml | 2 +- makefile | 2 +- parser/build.pl | 21 ++++++++------------- parser/gapi2xml.pl | 18 +++++++----------- sample/Makefile.in | 4 +++- 20 files changed, 98 insertions(+), 157 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1119b10d0..9313a41bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2002-06-21 Mike Kestner + + * makefile : remove gdk.imaging from the build + * gdk.imaging/* : kill + * generated/BoxedGen.cs : XmlNode namespace handling. Use GenBase. + * generated/CallbackGen.cs : XmlNode namespace handling. + * generated/Ctor.cs : construct with libname not ns. + * generated/EnumGen.cs : XmlNode namespace handling. + * generated/GenBase.cs : XmlNode namespace handling. Make AppendCustom + an instance method so it can use the private fields instead of params. + * generated/InterfaceGen.cs : XmlNode namespace handling. + * generated/Method.cs : construct with libname not ns. + * generated/ObjectGen.cs : XmlNode namespace handling. + * generated/Parser.cs : Use new XmlNode namespace ctors. + * generated/Signal.cs : Lose the namespace field. + * generated/StructBase.cs : derive from ClassBase + * generated/StructGen.cs : XmlNode namespace handling. Use GenBase. + * generated/SymbolTable.cs : nuke GetDllName method. + * generator/gtkapi.xml : Add library name to namespace node. + * parser/build.pl : refactor for library name param + * parser/gapi2xml.pl : add libname param handling + * sample/Makefile.in : build linux on make install, but don't install. + 2002-06-21 Rachel Hestilow * generator/ClassBase.cs: New base class for classes and interfaces. diff --git a/generator/BoxedGen.cs b/generator/BoxedGen.cs index bc9c31a81..f3d48f662 100644 --- a/generator/BoxedGen.cs +++ b/generator/BoxedGen.cs @@ -13,14 +13,7 @@ namespace GtkSharp.Generation { public class BoxedGen : StructBase, IGeneratable { - public BoxedGen (String ns, XmlElement elem) : base (ns, elem) {} - - public String MarshalType { - get - { - return "IntPtr"; - } - } + public BoxedGen (XmlElement ns, XmlElement elem) : base (ns, elem) {} public String CallByName (String var_name) { @@ -34,22 +27,7 @@ namespace GtkSharp.Generation { public void Generate () { - char sep = Path.DirectorySeparatorChar; - string dir = ".." + sep + ns.ToLower() + sep + "generated"; - if (!Directory.Exists(dir)) { - Directory.CreateDirectory(dir); - } - String filename = dir + sep + 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 (); + StreamWriter sw = CreateWriter (); sw.WriteLine ("\tusing System;"); sw.WriteLine ("\tusing System.Collections;"); @@ -65,7 +43,7 @@ namespace GtkSharp.Generation { Hashtable clash_map = new Hashtable(); - foreach (XmlNode node in elem.ChildNodes) { + foreach (XmlNode node in Elem.ChildNodes) { XmlElement member = (XmlElement) node; @@ -97,13 +75,9 @@ namespace GtkSharp.Generation { } } - GenBase.AppendCustom(ns, Name, sw); + AppendCustom(sw); sw.WriteLine ("\t}"); - sw.WriteLine (); - sw.WriteLine ("}"); - - sw.Flush(); - sw.Close(); + CloseWriter (sw); Statistics.BoxedCount++; } } diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index dd897896b..0864c7321 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -14,7 +14,7 @@ namespace GtkSharp.Generation { private Parameters parms; - public CallbackGen (String ns, XmlElement elem) : base (ns, elem) + public CallbackGen (XmlElement ns, XmlElement elem) : base (ns, elem) { if (elem ["parameters"] != null) parms = new Parameters (elem ["parameters"]); diff --git a/generator/ClassBase.cs b/generator/ClassBase.cs index 82d045f26..c850c6c94 100644 --- a/generator/ClassBase.cs +++ b/generator/ClassBase.cs @@ -18,13 +18,13 @@ namespace GtkSharp.Generation { protected Hashtable methods = new Hashtable(); protected ArrayList interfaces = null; - protected ClassBase (string ns, XmlElement elem) : base (ns, elem) { + protected ClassBase (XmlElement ns, XmlElement elem) : base (ns, elem) { foreach (XmlNode node in elem.ChildNodes) { XmlElement member = (XmlElement) node; switch (node.Name) { case "method": - methods.Add (member.GetAttribute ("name"), new Method (ns, member, this)); + methods.Add (member.GetAttribute ("name"), new Method (LibraryName, member, this)); break; case "property": @@ -32,7 +32,7 @@ namespace GtkSharp.Generation { break; case "signal": - sigs.Add (member.GetAttribute ("name"), new Signal (ns, member)); + sigs.Add (member.GetAttribute ("name"), new Signal (member)); break; case "implements": diff --git a/generator/Ctor.cs b/generator/Ctor.cs index cd0e7778d..bbca1334f 100644 --- a/generator/Ctor.cs +++ b/generator/Ctor.cs @@ -13,12 +13,12 @@ namespace GtkSharp.Generation { public class Ctor { - private string ns; + private string libname; private XmlElement elem; private Parameters parms; - public Ctor (string ns, XmlElement elem) { - this.ns = ns; + public Ctor (string libname, XmlElement elem) { + this.libname = libname; this.elem = elem; XmlElement parms_elem = elem ["parameters"]; if (parms_elem != null) @@ -67,7 +67,7 @@ namespace GtkSharp.Generation { else safety = ""; - sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) + "\")]"); + sw.WriteLine("\t\t[DllImport(\"" + libname + "\")]"); sw.WriteLine("\t\tstatic extern " + safety + "IntPtr " + cname + isig); sw.WriteLine(); diff --git a/generator/EnumGen.cs b/generator/EnumGen.cs index bd285e076..18a167e49 100644 --- a/generator/EnumGen.cs +++ b/generator/EnumGen.cs @@ -12,7 +12,7 @@ namespace GtkSharp.Generation { public class EnumGen : GenBase, IGeneratable { - public EnumGen (String ns, XmlElement elem) : base (ns, elem) {} + public EnumGen (XmlElement ns, XmlElement elem) : base (ns, elem) {} public String MarshalType { get diff --git a/generator/GenBase.cs b/generator/GenBase.cs index 154975b2d..c0cef86c9 100644 --- a/generator/GenBase.cs +++ b/generator/GenBase.cs @@ -12,10 +12,10 @@ namespace GtkSharp.Generation { public abstract class GenBase { - private string ns; + private XmlElement ns; private XmlElement elem; - protected GenBase (string ns, XmlElement elem) + protected GenBase (XmlElement ns, XmlElement elem) { this.ns = ns; this.elem = elem; @@ -33,34 +33,40 @@ namespace GtkSharp.Generation { } } + public string LibraryName { + get { + return ns.GetAttribute ("library"); + } + } + public string Name { get { return elem.GetAttribute ("name"); } } - public string Namespace { + public string NS { get { - return ns; + return ns.GetAttribute ("name"); } } public string QualifiedName { get { - return ns + "." + Name; + return NS + "." + Name; } } protected StreamWriter CreateWriter () { char sep = Path.DirectorySeparatorChar; - string dir = ".." + sep + ns.ToLower() + sep + "generated"; + string dir = ".." + sep + NS.ToLower() + sep + "generated"; if (!Directory.Exists(dir)) { Console.WriteLine ("creating " + dir); Directory.CreateDirectory(dir); } String filename = dir + sep + Name + ".cs"; - Console.WriteLine ("creating " + filename); + // Console.WriteLine ("creating " + filename); FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter (stream); @@ -68,7 +74,7 @@ namespace GtkSharp.Generation { sw.WriteLine ("// Generated File. Do not modify."); sw.WriteLine ("// 2001-2002 Mike Kestner"); sw.WriteLine (); - sw.WriteLine ("namespace " + ns + " {"); + sw.WriteLine ("namespace " + NS + " {"); sw.WriteLine (); return sw; @@ -82,10 +88,10 @@ namespace GtkSharp.Generation { sw.Close(); } - public static void AppendCustom (string ns, string name, StreamWriter sw) + public void AppendCustom (StreamWriter sw) { char sep = Path.DirectorySeparatorChar; - string custom = ".." + sep + ns.ToLower() + sep + name + ".custom"; + string custom = ".." + sep + NS.ToLower() + sep + Name + ".custom"; if (File.Exists(custom)) { FileStream custstream = new FileStream(custom, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(custstream); diff --git a/generator/InterfaceGen.cs b/generator/InterfaceGen.cs index 58ad9fe1a..a1cd7b0b8 100644 --- a/generator/InterfaceGen.cs +++ b/generator/InterfaceGen.cs @@ -12,7 +12,7 @@ namespace GtkSharp.Generation { public class InterfaceGen : ClassBase, IGeneratable { - public InterfaceGen (string ns, XmlElement elem) : base (ns, elem) {} + public InterfaceGen (XmlElement ns, XmlElement elem) : base (ns, elem) {} public void Generate () { diff --git a/generator/Method.cs b/generator/Method.cs index c661c0f99..c28c3e797 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -13,7 +13,7 @@ namespace GtkSharp.Generation { public class Method { - private string ns; + private string libname; private XmlElement elem; private Parameters parms; private ClassBase container_type; @@ -24,9 +24,9 @@ namespace GtkSharp.Generation { private string name, cname, safety; private bool is_get, is_set; - public Method (string ns, XmlElement elem, ClassBase container_type) + public Method (string libname, XmlElement elem, ClassBase container_type) { - this.ns = ns; + this.libname = libname; this.elem = elem; if (elem["parameters"] != null) parms = new Parameters (elem["parameters"]); @@ -211,7 +211,7 @@ namespace GtkSharp.Generation { protected void GenerateImport (StreamWriter sw) { - sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) + + sw.WriteLine("\t\t[DllImport(\"" + libname + "\", CallingConvention=CallingConvention.Cdecl)]"); sw.Write("\t\tstatic extern " + safety + m_ret + " " + cname + isig); sw.WriteLine(); diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index 56cbae803..103be0ccb 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -15,7 +15,7 @@ namespace GtkSharp.Generation { private ArrayList ctors = new ArrayList(); - public ObjectGen (string ns, XmlElement elem) : base (ns, elem) + public ObjectGen (XmlElement ns, XmlElement elem) : base (ns, elem) { foreach (XmlNode node in elem.ChildNodes) { @@ -28,7 +28,7 @@ namespace GtkSharp.Generation { break; case "constructor": - ctors.Add (new Ctor (ns, member)); + ctors.Add (new Ctor (LibraryName, member)); break; default: @@ -79,7 +79,7 @@ namespace GtkSharp.Generation { } } - AppendCustom(Namespace, Name, sw); + AppendCustom(sw); sw.WriteLine ("\t}"); diff --git a/generator/Parser.cs b/generator/Parser.cs index 120732a5c..b64b81e90 100644 --- a/generator/Parser.cs +++ b/generator/Parser.cs @@ -72,27 +72,27 @@ namespace GtkSharp.Generation { break; case "boxed": - SymbolTable.AddType (new BoxedGen (ns_name, elem)); + SymbolTable.AddType (new BoxedGen (ns, elem)); break; case "callback": - SymbolTable.AddType (new CallbackGen (ns_name, elem)); + SymbolTable.AddType (new CallbackGen (ns, elem)); break; case "enum": - SymbolTable.AddType (new EnumGen (ns_name, elem)); + SymbolTable.AddType (new EnumGen (ns, elem)); break; case "interface": - SymbolTable.AddType (new InterfaceGen (ns_name, elem)); + SymbolTable.AddType (new InterfaceGen (ns, elem)); break; case "object": - SymbolTable.AddType (new ObjectGen (ns_name, elem)); + SymbolTable.AddType (new ObjectGen (ns, elem)); break; case "struct": - SymbolTable.AddType (new StructGen (ns_name, elem)); + SymbolTable.AddType (new StructGen (ns, elem)); break; default: diff --git a/generator/Signal.cs b/generator/Signal.cs index ce8dab9f4..0dd6c753d 100644 --- a/generator/Signal.cs +++ b/generator/Signal.cs @@ -13,14 +13,12 @@ namespace GtkSharp.Generation { public class Signal { - private string ns; private string marsh; private string name; private XmlElement elem; - public Signal (string ns, XmlElement elem) + public Signal (XmlElement elem) { - this.ns = ns; this.elem = elem; this.name = elem.GetAttribute ("name"); } diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 4b95ecb1d..9299e41b7 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -12,38 +12,9 @@ namespace GtkSharp.Generation { using System.Text.RegularExpressions; using System.Xml; - public class StructBase { - - protected String ns; - protected XmlElement elem; - - public StructBase (String ns, XmlElement elem) { - - this.ns = ns; - this.elem = 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 class StructBase : ClassBase { + public StructBase (XmlElement ns, XmlElement elem) : base (ns, elem) {} protected bool GenCtor(XmlElement ctor, StreamWriter sw, Hashtable clash_map) { @@ -75,7 +46,7 @@ namespace GtkSharp.Generation { String cname = ctor.GetAttribute("cname"); - sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) + + sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\", CallingConvention=CallingConvention.Cdecl)]"); sw.WriteLine("\t\tstatic extern IntPtr " + cname + isig); sw.WriteLine(); @@ -178,7 +149,7 @@ namespace GtkSharp.Generation { return true; } - sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) + + sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\", CallingConvention=CallingConvention.Cdecl)]"); sw.Write("\t\tstatic extern " + m_ret + " " + cname + isig); sw.WriteLine(); diff --git a/generator/StructGen.cs b/generator/StructGen.cs index 5fd386249..ffe8f0646 100644 --- a/generator/StructGen.cs +++ b/generator/StructGen.cs @@ -12,9 +12,9 @@ namespace GtkSharp.Generation { public class StructGen : StructBase, IGeneratable { - public StructGen (String ns, XmlElement elem) : base (ns, elem) {} + public StructGen (XmlElement ns, XmlElement elem) : base (ns, elem) {} - public String MarshalType { + public new string MarshalType { get { return QualifiedName; @@ -33,23 +33,8 @@ namespace GtkSharp.Generation { public void Generate () { - char sep = Path.DirectorySeparatorChar; - string dir = ".." + sep + ns.ToLower() + sep + "generated"; - if (!Directory.Exists(dir)) { - Directory.CreateDirectory(dir); - } - String filename = dir + sep + Name + ".cs"; + StreamWriter sw = CreateWriter (); - FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write); - StreamWriter sw = new StreamWriter (stream); - - sw.WriteLine ("// Generated File. Do not modify."); - sw.WriteLine ("// 2001 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;"); @@ -59,7 +44,7 @@ namespace GtkSharp.Generation { sw.WriteLine ("\tpublic class " + Name + " {"); sw.WriteLine (); - foreach (XmlNode node in elem.ChildNodes) { + foreach (XmlNode node in Elem.ChildNodes) { XmlElement member = (XmlElement) node; @@ -87,14 +72,10 @@ namespace GtkSharp.Generation { } } - GenBase.AppendCustom(ns, Name, sw); + AppendCustom(sw); sw.WriteLine ("\t}"); - sw.WriteLine (); - sw.WriteLine ("}"); - - sw.Flush(); - sw.Close(); + CloseWriter (sw); Statistics.StructCount++; } } diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 25d960a61..348185f8a 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -162,11 +162,6 @@ namespace GtkSharp.Generation { } } - public static string GetDllName(string ns) - { - return (string) dlls[ns]; - } - public static string GetMarshalType(string c_type) { c_type = Trim(c_type); diff --git a/generator/gtkapi.xml b/generator/gtkapi.xml index b32d1b769..f655f92ee 100644 --- a/generator/gtkapi.xml +++ b/generator/gtkapi.xml @@ -1,2 +1,2 @@ - + diff --git a/makefile b/makefile index 10bfd069f..d9586f63c 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -DIRS=generator glib pango atk gdk gdk.imaging gtk sample +DIRS=generator glib pango atk gdk gtk sample ROOT=/cygdrive/$(subst \,/,$(subst :\,/,$(SYSTEMROOT))) CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe MCS=mcs diff --git a/parser/build.pl b/parser/build.pl index 81f4759a2..8d465879d 100755 --- a/parser/build.pl +++ b/parser/build.pl @@ -4,19 +4,14 @@ $file = "../generator/gtkapi.xml"; unlink ($file); -%ns = ( "Atk" => "atk-1.0.2/atk", - "Pango" => "pango-1.0.2/pango", - "Gdk" => "gtk+-2.0.3/gdk", - "Gdk.Imaging" => "gtk+-2.0.3/gdk-pixbuf", - "Gtk" => "gtk+-2.0.3/gtk"); +%srcs = ( "atk-1.0.0/atk" => "Atk:atk-1.0", + "pango-1.0.0/pango" => "Pango:pango-1.0", + "gtk+-2.0.0/gdk" => "Gdk:gdk-x11-2.0", + "gtk+-2.0.0/gdk-pixbuf" => "Gdk:gdk_pixbuf-2.0", + "gtk+-2.0.0/gtk" => "Gtk:gtk-x11-2.0"); -%c_ns = ( "Gdk.Imaging" => "Gdk"); - -foreach $key (keys %ns) { - $dir = $ns{$key}; - if (not ($c_key = $c_ns{$key})) { - $c_key = $key; - } - system ("./gapi_pp.pl $dir | ./gapi2xml.pl $c_key $file --out-ns $key"); +foreach $dir (keys %srcs) { + ($ns, $lib) = split (/:/, $srcs{$dir}); + system ("./gapi_pp.pl $dir | ./gapi2xml.pl $ns $file $lib"); } diff --git a/parser/gapi2xml.pl b/parser/gapi2xml.pl index 2cf6d92ba..50645dd3a 100755 --- a/parser/gapi2xml.pl +++ b/parser/gapi2xml.pl @@ -12,25 +12,20 @@ $debug=1; use XML::LibXML; use Metadata; -if (!$ARGV[0]) { - die "Usage: gapi_pp.pl | gapi2xml.pl [--out-ns outns]\n"; +if (!$ARGV[2]) { + die "Usage: gapi_pp.pl | gapi2xml.pl \n"; } $ns = $ARGV[0]; - -if ($ARGV[2] && $ARGV[2] eq "--out-ns") { - $out_ns = $ARGV[3]; -} else { - $out_ns = $ns; -} +$libname = $ARGV[2]; ############################################################## -# If a filename was provided see if it exists. We parse existing files into +# Check if the filename provided exists. We parse existing files into # a tree and append the namespace to the root node. If the file doesn't # exist, we create a doc tree and root node to work with. ############################################################## -if ($ARGV[1] && -e $ARGV[1]) { +if (-e $ARGV[1]) { #parse existing file and get root node. $doc = XML::LibXML->new->parse_file($ARGV[1]); $root = $doc->getDocumentElement(); @@ -41,7 +36,8 @@ if ($ARGV[1] && -e $ARGV[1]) { } $ns_elem = $doc->createElement('namespace'); -$ns_elem->setAttribute('name', $out_ns); +$ns_elem->setAttribute('name', $ns); +$ns_elem->setAttribute('library', $libname); $root->appendChild($ns_elem); ############################################################## diff --git a/sample/Makefile.in b/sample/Makefile.in index e4d8ebd12..fa9971402 100755 --- a/sample/Makefile.in +++ b/sample/Makefile.in @@ -23,5 +23,7 @@ clean: unix: @echo "'make unix' is broken for now." -install: +install: linux + @echo "Nothing to install." +