2003-10-03 Mike Kestner <mkestner@ximian.com>

* api/gtk-symbols.xml : make GtkType a uint like GType.
	* generator/CodeGenerator.cs : adopt new parser semantics
	* generator/Parser.cs : move to single parser/multiple Parse. Remove
	DoGenerate hack and let the CodeGenerator control this. Return
	generatables instead of loading symboltable.
	* generator/SymbolTable : add AddTypes method. Revamp dealiasing code.

svn path=/trunk/gtk-sharp/; revision=18570
This commit is contained in:
Mike Kestner 2003-10-03 22:11:47 +00:00
parent d54caa197a
commit c17c41c4a8
5 changed files with 103 additions and 91 deletions

View file

@ -1,3 +1,12 @@
2003-10-03 Mike Kestner <mkestner@ximian.com>
* api/gtk-symbols.xml : make GtkType a uint like GType.
* generator/CodeGenerator.cs : adopt new parser semantics
* generator/Parser.cs : move to single parser/multiple Parse. Remove
DoGenerate hack and let the CodeGenerator control this. Return
generatables instead of loading symboltable.
* generator/SymbolTable : add AddTypes method. Revamp dealiasing code.
2003-10-02 Mike Kestner <mkestner@ximian.com>
* api/gnome-api.xml : regenerated

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<api>
<symbol type="simple" cname="GtkType" name="int"/>
<symbol type="simple" cname="GtkType" name="uint"/>
</api>

View file

@ -2,7 +2,7 @@
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001 Mike Kestner
// (c) 2001-2003 Mike Kestner and Ximian Inc.
namespace GtkSharp.Generation {
@ -20,20 +20,30 @@ namespace GtkSharp.Generation {
}
bool generate = false;
bool include = false;
SymbolTable table = SymbolTable.Table;
ArrayList gens = new ArrayList ();
foreach (string arg in args) {
if (arg == "--generate") {
generate = true;
continue;
} else if (arg == "--include") {
generate = false;
continue;
}
Parser p = new Parser (arg);
p.Parse (generate);
if (arg == "--generate") {
generate = true;
include = false;
continue;
} else if (arg == "--include") {
generate = false;
include = true;
continue;
}
Parser p = new Parser ();
IGeneratable[] curr_gens = p.Parse (arg);
table.AddTypes (curr_gens);
if (generate)
gens.AddRange (curr_gens);
}
foreach (IGeneratable gen in SymbolTable.Table.Generatables) {
foreach (IGeneratable gen in gens) {
gen.DoGenerate = true;
gen.Generate ();
}
@ -42,6 +52,5 @@ namespace GtkSharp.Generation {
Statistics.Report();
return 0;
}
}
}

View file

@ -2,7 +2,7 @@
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001 Mike Kestner
// (c) 2001-2003 Mike Kestner and Ximian Inc.
namespace GtkSharp.Generation {
@ -13,132 +13,129 @@ namespace GtkSharp.Generation {
public class Parser {
private XmlDocument doc;
public Parser (String filename)
private XmlDocument Load (string filename)
{
doc = new XmlDocument ();
XmlDocument 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());
Console.WriteLine (e);
doc = null;
}
return doc;
}
public void Parse (bool generate)
public IGeneratable[] Parse (string filename)
{
XmlDocument doc = Load (filename);
if (doc == null)
return null;
XmlElement root = doc.DocumentElement;
if ((root == null) || !root.HasChildNodes) {
Console.WriteLine ("No Namespaces found.");
return;
Console.WriteLine ("No Namespaces found.");
return null;
}
foreach (XmlNode ns in root.ChildNodes) {
XmlElement elem = ns as XmlElement;
ArrayList gens = new ArrayList ();
foreach (XmlNode child in root.ChildNodes) {
XmlElement elem = child as XmlElement;
if (elem == null)
continue;
if (ns.Name == "namespace")
ParseNamespace (elem, generate);
else if (ns.Name == "symbol")
ParseSymbol (elem);
switch (child.Name) {
case "namespace":
gens.AddRange (ParseNamespace (elem));
break;
case "symbol":
gens.Add (ParseSymbol (elem));
break;
default:
Console.WriteLine ("Parser::Parse - Unexpected child node: " + child.Name);
break;
}
}
return (IGeneratable[]) gens.ToArray (typeof (IGeneratable));
}
private void ParseNamespace (XmlElement ns, bool generate)
private ArrayList ParseNamespace (XmlElement ns)
{
String ns_name = ns.GetAttribute ("name");
ArrayList result = new ArrayList ();
foreach (XmlNode def in ns.ChildNodes) {
if (def.NodeType != XmlNodeType.Element) {
XmlElement elem = def as XmlElement;
if (elem == null)
continue;
}
XmlElement elem = (XmlElement) def;
IGeneratable igen = null;
if (elem.HasAttribute("hidden"))
continue;
switch (def.Name) {
bool is_opaque = false;
if (elem.HasAttribute ("opaque"))
is_opaque = true;
switch (def.Name) {
case "alias":
string aname = elem.GetAttribute("cname");
string atype = elem.GetAttribute("type");
if ((aname == "") || (atype == ""))
continue;
SymbolTable.Table.AddAlias (aname, atype);
result.Add (new AliasGen (aname, atype));
break;
case "boxed":
if (elem.HasAttribute ("opaque"))
igen = new OpaqueGen (ns, elem);
else
igen = new BoxedGen (ns, elem);
result.Add (is_opaque ? new OpaqueGen (ns, elem) as object : new BoxedGen (ns, elem) as object);
break;
case "callback":
igen = new CallbackGen (ns, elem);
result.Add (new CallbackGen (ns, elem));
break;
case "enum":
igen = new EnumGen (ns, elem);
result.Add (new EnumGen (ns, elem));
break;
case "interface":
igen = new InterfaceGen (ns, elem);
result.Add (new InterfaceGen (ns, elem));
break;
case "object":
igen = new ObjectGen (ns, elem);
result.Add (new ObjectGen (ns, elem));
break;
case "class":
igen = new ClassGen (ns, elem);
result.Add (new ClassGen (ns, elem));
break;
case "struct":
if (elem.HasAttribute ("opaque"))
igen = new OpaqueGen (ns, elem);
else
igen = new StructGen (ns, elem);
result.Add (is_opaque ? new OpaqueGen (ns, elem) as object : new StructGen (ns, elem) as object);
break;
default:
Console.WriteLine ("Unexpected node named " + def.Name);
Console.WriteLine ("Parser::ParseNamespace - Unexpected node: " + def.Name);
break;
}
if (igen != null) {
igen.DoGenerate = generate;
SymbolTable.Table.AddType (igen);
}
}
return result;
}
private void ParseSymbol (XmlElement symbol)
private IGeneratable ParseSymbol (XmlElement symbol)
{
string type = symbol.GetAttribute ("type");
string cname = symbol.GetAttribute ("cname");
string name = symbol.GetAttribute ("name");
IGeneratable result = null;
if (type == "simple")
SymbolTable.Table.AddType (new SimpleGen (cname, name));
result = new SimpleGen (cname, name);
else if (type == "manual")
SymbolTable.Table.AddType (new ManualGen (cname, name));
result = new ManualGen (cname, name);
else
Console.WriteLine ("Unexpected symbol type " + type);
Console.WriteLine ("Parser::ParseSymbol - Unexpected symbol type " + type);
return result;
}
}
}

View file

@ -93,17 +93,17 @@ namespace GtkSharp.Generation {
AddType (new ManualGen ("GObject", "GLib", "Object"));
}
public void AddAlias (string name, string type)
{
type = type.TrimEnd(' ', '\t');
alias [name] = type;
}
public void AddType (IGeneratable gen)
{
types [gen.CName] = gen;
}
public void AddTypes (IGeneratable[] gens)
{
foreach (IGeneratable gen in gens)
types [gen.CName] = gen;
}
public int Count {
get
{
@ -119,8 +119,7 @@ namespace GtkSharp.Generation {
public IGeneratable this [string ctype] {
get {
ctype = DeAlias (ctype);
return types [ctype] as IGeneratable;
return DeAlias (ctype) as IGeneratable;
}
}
@ -139,13 +138,16 @@ namespace GtkSharp.Generation {
return trim_type;
}
private string DeAlias (string type)
private object DeAlias (string type)
{
type = Trim (type);
while (alias.ContainsKey(type))
type = (string) alias[type];
while (types [type] is AliasGen) {
IGeneratable igen = types [type] as AliasGen;
types [type] = types [igen.Name];
type = igen.Name;
}
return type;
return types [type];
}
public string FromNativeReturn(string c_type, string val)
@ -246,13 +248,8 @@ namespace GtkSharp.Generation {
public bool IsEnumFlags(string c_type)
{
c_type = Trim(c_type);
c_type = DeAlias(c_type);
if (types.ContainsKey(c_type)) {
EnumGen gen = types[c_type] as EnumGen;
return (gen != null && gen.Elem.GetAttribute ("type") == "flags");
}
return false;
EnumGen gen = this [c_type] as EnumGen;
return (gen != null && gen.Elem.GetAttribute ("type") == "flags");
}
public bool IsInterface(string c_type)