mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2025-01-11 20:15:34 +00:00
02fa6a31e6
* generator/*.cs : Move into GtkSharp.Generation namespace. * generator/CodeGenerator.cs (Main): Add usage check. Add SymbolTable. * generator/EnumGen.cs (QualifiedName): New. (Generate): Add SymbolTable to signature. * generator/IGeneratable : Add QualifiedName prop and update Generate signature. * generator/Parser.cs : Switch from plain Hashtable to SymbolTable. (Parse): Replaces the Types property and returns a SymbolTable. * generator/StructBase.cs : New base class to derive struct and object types. Initial implementation of protected GenField method and ctor. * generator/StructGen.cs : New non-object struct type generatable. * generator/SymbolTable.cs : New. Manages complex types hash and a simple types hash. Will provide generic lookup interface. svn path=/trunk/gtk-sharp/; revision=1855
98 lines
1.7 KiB
C#
98 lines
1.7 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.Xml;
|
|
|
|
public class Parser {
|
|
|
|
private XmlDocument doc;
|
|
private SymbolTable table;
|
|
|
|
public Parser (String filename)
|
|
{
|
|
doc = new XmlDocument ();
|
|
|
|
try {
|
|
|
|
doc.Load (filename);
|
|
|
|
} catch (XmlException e) {
|
|
|
|
Console.WriteLine ("Invalid XML file.");
|
|
Console.WriteLine (e.ToString());
|
|
}
|
|
|
|
}
|
|
|
|
public SymbolTable Parse ()
|
|
{
|
|
if (table != null) return table;
|
|
|
|
XmlElement root = doc.DocumentElement;
|
|
|
|
if ((root == null) || !root.HasChildNodes) {
|
|
Console.WriteLine ("No Namespaces found.");
|
|
return null;
|
|
}
|
|
|
|
table = new SymbolTable ();
|
|
|
|
foreach (XmlNode ns in root.ChildNodes) {
|
|
if (ns.Name != "namespace") {
|
|
continue;
|
|
}
|
|
|
|
XmlElement elem = (XmlElement) ns;
|
|
ParseNamespace (elem);
|
|
}
|
|
|
|
return table;
|
|
}
|
|
|
|
private void ParseNamespace (XmlElement ns)
|
|
{
|
|
String ns_name = ns.GetAttribute ("name");
|
|
|
|
foreach (XmlNode def in ns.ChildNodes) {
|
|
|
|
if (def.NodeType != XmlNodeType.Element) {
|
|
continue;
|
|
}
|
|
|
|
XmlElement elem = (XmlElement) def;
|
|
|
|
switch (def.Name) {
|
|
|
|
case "alias":
|
|
break;
|
|
|
|
case "callback":
|
|
break;
|
|
|
|
case "enum":
|
|
table.AddType (new EnumGen (ns_name, elem));
|
|
break;
|
|
|
|
case "object":
|
|
break;
|
|
|
|
case "struct":
|
|
table.AddType (new StructGen (ns_name, elem));
|
|
break;
|
|
|
|
default:
|
|
Console.WriteLine ("Unexpected node.");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|