GtkSharp/generator/Parser.cs
Mike Kestner 3ff827ed69 2003-07-10 Mike Kestner <mkestner@speakeasy.net>
* api/*-api.xml : regenerated
	* gdk/Threads.cs : killed since the methods are now gen'd
	* generator/ClassGen.cs : new, static class generatable
	* generator/Parameters.cs : mangle new and byte as param names
	* generator/Parser.cs : parse new <class> elements
	* generator/SymbolTable.cs : add GC SimpleGen
	* parser/gapi2xml.pl : static class element fixes
	* parser/GAPI/Metadata.pm : add class element
	* sources/Art.metadata: new, rename Affine.ToString method
	* sources/Atk.metadata: rename State class
	* sources/Gdk.metadata: hide Pixbuf static class for now. rename
	Event and Pango static classes to avoid collisions.
	* sources/Gnome.metadata: rename Gtk and Gdk static classes to
	avoid collisions.
	* sources/GnomeDb.metadata: rename Stock static class to
	avoid collisions.
	* sources/Gtk.metadata: rename Stock static class to
	avoid collisions. Hide Idle class.

svn path=/trunk/gtk-sharp/; revision=16115
2003-07-11 02:00:13 +00:00

145 lines
3.1 KiB
C#

// GtkSharp.Generation.Parser.cs - The XML Parsing engine.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001 Mike Kestner
namespace GtkSharp.Generation {
using System;
using System.Collections;
using System.IO;
using System.Xml;
public class Parser {
private XmlDocument doc;
public Parser (String filename)
{
doc = new XmlDocument ();
try {
Stream stream = File.OpenRead (filename);
doc.Load (stream);
stream.Close ();
} catch (XmlException e) {
Console.WriteLine ("Invalid XML file.");
Console.WriteLine (e.ToString());
}
}
public void Parse (bool generate)
{
XmlElement root = doc.DocumentElement;
if ((root == null) || !root.HasChildNodes) {
Console.WriteLine ("No Namespaces found.");
return;
}
foreach (XmlNode ns in root.ChildNodes) {
XmlElement elem = ns as XmlElement;
if (elem == null)
continue;
if (ns.Name == "namespace")
ParseNamespace (elem, generate);
else if (ns.Name == "symbol")
ParseSymbol (elem);
}
}
private void ParseNamespace (XmlElement ns, bool generate)
{
String ns_name = ns.GetAttribute ("name");
foreach (XmlNode def in ns.ChildNodes) {
if (def.NodeType != XmlNodeType.Element) {
continue;
}
XmlElement elem = (XmlElement) def;
IGeneratable igen = null;
if (elem.HasAttribute("hidden"))
continue;
switch (def.Name) {
case "alias":
string aname = elem.GetAttribute("cname");
string atype = elem.GetAttribute("type");
if ((aname == "") || (atype == ""))
continue;
SymbolTable.Table.AddAlias (aname, atype);
break;
case "boxed":
if (elem.HasAttribute ("opaque"))
igen = new OpaqueGen (ns, elem);
else
igen = new BoxedGen (ns, elem);
break;
case "callback":
igen = new CallbackGen (ns, elem);
break;
case "enum":
igen = new EnumGen (ns, elem);
break;
case "interface":
igen = new InterfaceGen (ns, elem);
break;
case "object":
igen = new ObjectGen (ns, elem);
break;
case "class":
igen = new ClassGen (ns, elem);
break;
case "struct":
if (elem.HasAttribute ("opaque"))
igen = new OpaqueGen (ns, elem);
else
igen = new StructGen (ns, elem);
break;
default:
Console.WriteLine ("Unexpected node named " + def.Name);
break;
}
if (igen != null) {
igen.DoGenerate = generate;
SymbolTable.Table.AddType (igen);
}
}
}
private void ParseSymbol (XmlElement symbol)
{
string type = symbol.GetAttribute ("type");
string cname = symbol.GetAttribute ("cname");
string name = symbol.GetAttribute ("name");
if (type == "simple")
SymbolTable.Table.AddType (new SimpleGen (cname, name));
else if (type == "manual")
SymbolTable.Table.AddType (new ManualGen (cname, name));
else
Console.WriteLine ("Unexpected symbol type " + type);
}
}
}