2002-06-21 Mike Kestner <mkestner@speakeasy.net>

* 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
This commit is contained in:
Mike Kestner 2002-06-21 20:25:43 +00:00
parent 6857128f07
commit 5d67982de9
20 changed files with 98 additions and 157 deletions

View File

@ -1,3 +1,26 @@
2002-06-21 Mike Kestner <mkestner@speakeasy.net>
* 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 <hestilow@ximian.com>
* generator/ClassBase.cs: New base class for classes and interfaces.

View File

@ -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 ("// <c> 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++;
}
}

View File

@ -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"]);

View File

@ -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":

View File

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

View File

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

View File

@ -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 ("// <c> 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);

View File

@ -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 ()
{

View File

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

View File

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

View File

@ -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:

View File

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

View File

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

View File

@ -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 ("// <c> 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++;
}
}

View File

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

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

@ -12,25 +12,20 @@ $debug=1;
use XML::LibXML;
use Metadata;
if (!$ARGV[0]) {
die "Usage: gapi_pp.pl <srcdir> | gapi2xml.pl <namespace> <outfile> [--out-ns outns]\n";
if (!$ARGV[2]) {
die "Usage: gapi_pp.pl <srcdir> | gapi2xml.pl <namespace> <outfile> <libname>\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);
##############################################################

View File

@ -23,5 +23,7 @@ clean:
unix:
@echo "'make unix' is broken for now."
install:
install: linux
@echo "Nothing to install."