mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-26 20:05:38 +00:00
4a6b18ee0f
* generator/Parser.cs: use XmlDocument.Load (Stream). The one using (String) expects an uri. * generator/Signal.cs: always remove the delegate from the signal callback (prior to this, the last handler was not being removed). Dispose the callback (ie, disconnect from the signal) when there are no registered delegates to handle it. * generator/SignalHandler.cs: added 2 new fields to hold the instance and the handler ID. The finalization is now done in Dispose and disconnects the signal handler when no delegate will handle the signal. Changed gobject-2.0 to libgobject-2.0-0.dll. * glib/SignalCallback.cs: implemented IDisposable interface. svn path=/trunk/gtk-sharp/; revision=11976
140 lines
3 KiB
C#
140 lines
3 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.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 "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.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.AddSimpleType (cname, name);
|
|
else if (type == "manual")
|
|
SymbolTable.AddManualType (cname, name);
|
|
else
|
|
Console.WriteLine ("Unexpected symbol type " + type);
|
|
}
|
|
}
|
|
}
|