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:
parent
d54caa197a
commit
c17c41c4a8
5 changed files with 103 additions and 91 deletions
|
@ -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>
|
2003-10-02 Mike Kestner <mkestner@ximian.com>
|
||||||
|
|
||||||
* api/gnome-api.xml : regenerated
|
* api/gnome-api.xml : regenerated
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<api>
|
<api>
|
||||||
<symbol type="simple" cname="GtkType" name="int"/>
|
<symbol type="simple" cname="GtkType" name="uint"/>
|
||||||
</api>
|
</api>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||||
//
|
//
|
||||||
// (c) 2001 Mike Kestner
|
// (c) 2001-2003 Mike Kestner and Ximian Inc.
|
||||||
|
|
||||||
namespace GtkSharp.Generation {
|
namespace GtkSharp.Generation {
|
||||||
|
|
||||||
|
@ -20,20 +20,30 @@ namespace GtkSharp.Generation {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool generate = false;
|
bool generate = false;
|
||||||
|
bool include = false;
|
||||||
|
|
||||||
|
SymbolTable table = SymbolTable.Table;
|
||||||
|
ArrayList gens = new ArrayList ();
|
||||||
foreach (string arg in args) {
|
foreach (string arg in args) {
|
||||||
if (arg == "--generate") {
|
if (arg == "--generate") {
|
||||||
generate = true;
|
generate = true;
|
||||||
|
include = false;
|
||||||
continue;
|
continue;
|
||||||
} else if (arg == "--include") {
|
} else if (arg == "--include") {
|
||||||
generate = false;
|
generate = false;
|
||||||
|
include = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Parser p = new Parser (arg);
|
Parser p = new Parser ();
|
||||||
p.Parse (generate);
|
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 ();
|
gen.Generate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +52,5 @@ namespace GtkSharp.Generation {
|
||||||
Statistics.Report();
|
Statistics.Report();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||||
//
|
//
|
||||||
// (c) 2001 Mike Kestner
|
// (c) 2001-2003 Mike Kestner and Ximian Inc.
|
||||||
|
|
||||||
namespace GtkSharp.Generation {
|
namespace GtkSharp.Generation {
|
||||||
|
|
||||||
|
@ -13,132 +13,129 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public class Parser {
|
public class Parser {
|
||||||
|
|
||||||
private XmlDocument doc;
|
private XmlDocument Load (string filename)
|
||||||
|
|
||||||
public Parser (String filename)
|
|
||||||
{
|
{
|
||||||
doc = new XmlDocument ();
|
XmlDocument doc = new XmlDocument ();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Stream stream = File.OpenRead (filename);
|
Stream stream = File.OpenRead (filename);
|
||||||
doc.Load (stream);
|
doc.Load (stream);
|
||||||
stream.Close ();
|
stream.Close ();
|
||||||
|
|
||||||
} catch (XmlException e) {
|
} catch (XmlException e) {
|
||||||
|
|
||||||
Console.WriteLine ("Invalid XML file.");
|
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;
|
XmlElement root = doc.DocumentElement;
|
||||||
|
|
||||||
if ((root == null) || !root.HasChildNodes) {
|
if ((root == null) || !root.HasChildNodes) {
|
||||||
Console.WriteLine ("No Namespaces found.");
|
Console.WriteLine ("No Namespaces found.");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (XmlNode ns in root.ChildNodes) {
|
ArrayList gens = new ArrayList ();
|
||||||
XmlElement elem = ns as XmlElement;
|
|
||||||
|
foreach (XmlNode child in root.ChildNodes) {
|
||||||
|
XmlElement elem = child as XmlElement;
|
||||||
if (elem == null)
|
if (elem == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (ns.Name == "namespace")
|
switch (child.Name) {
|
||||||
ParseNamespace (elem, generate);
|
case "namespace":
|
||||||
else if (ns.Name == "symbol")
|
gens.AddRange (ParseNamespace (elem));
|
||||||
ParseSymbol (elem);
|
break;
|
||||||
|
case "symbol":
|
||||||
|
gens.Add (ParseSymbol (elem));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Console.WriteLine ("Parser::Parse - Unexpected child node: " + child.Name);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParseNamespace (XmlElement ns, bool generate)
|
return (IGeneratable[]) gens.ToArray (typeof (IGeneratable));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList ParseNamespace (XmlElement ns)
|
||||||
{
|
{
|
||||||
String ns_name = ns.GetAttribute ("name");
|
ArrayList result = new ArrayList ();
|
||||||
|
|
||||||
foreach (XmlNode def in ns.ChildNodes) {
|
foreach (XmlNode def in ns.ChildNodes) {
|
||||||
|
|
||||||
if (def.NodeType != XmlNodeType.Element) {
|
XmlElement elem = def as XmlElement;
|
||||||
|
if (elem == null)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
XmlElement elem = (XmlElement) def;
|
|
||||||
IGeneratable igen = null;
|
|
||||||
|
|
||||||
if (elem.HasAttribute("hidden"))
|
if (elem.HasAttribute("hidden"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch (def.Name) {
|
bool is_opaque = false;
|
||||||
|
if (elem.HasAttribute ("opaque"))
|
||||||
|
is_opaque = true;
|
||||||
|
|
||||||
|
switch (def.Name) {
|
||||||
case "alias":
|
case "alias":
|
||||||
string aname = elem.GetAttribute("cname");
|
string aname = elem.GetAttribute("cname");
|
||||||
string atype = elem.GetAttribute("type");
|
string atype = elem.GetAttribute("type");
|
||||||
if ((aname == "") || (atype == ""))
|
if ((aname == "") || (atype == ""))
|
||||||
continue;
|
continue;
|
||||||
SymbolTable.Table.AddAlias (aname, atype);
|
result.Add (new AliasGen (aname, atype));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "boxed":
|
case "boxed":
|
||||||
if (elem.HasAttribute ("opaque"))
|
result.Add (is_opaque ? new OpaqueGen (ns, elem) as object : new BoxedGen (ns, elem) as object);
|
||||||
igen = new OpaqueGen (ns, elem);
|
|
||||||
else
|
|
||||||
igen = new BoxedGen (ns, elem);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "callback":
|
case "callback":
|
||||||
igen = new CallbackGen (ns, elem);
|
result.Add (new CallbackGen (ns, elem));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "enum":
|
case "enum":
|
||||||
igen = new EnumGen (ns, elem);
|
result.Add (new EnumGen (ns, elem));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "interface":
|
case "interface":
|
||||||
igen = new InterfaceGen (ns, elem);
|
result.Add (new InterfaceGen (ns, elem));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "object":
|
case "object":
|
||||||
igen = new ObjectGen (ns, elem);
|
result.Add (new ObjectGen (ns, elem));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "class":
|
case "class":
|
||||||
igen = new ClassGen (ns, elem);
|
result.Add (new ClassGen (ns, elem));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "struct":
|
case "struct":
|
||||||
if (elem.HasAttribute ("opaque"))
|
result.Add (is_opaque ? new OpaqueGen (ns, elem) as object : new StructGen (ns, elem) as object);
|
||||||
igen = new OpaqueGen (ns, elem);
|
|
||||||
else
|
|
||||||
igen = new StructGen (ns, elem);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Console.WriteLine ("Unexpected node named " + def.Name);
|
Console.WriteLine ("Parser::ParseNamespace - Unexpected node: " + def.Name);
|
||||||
break;
|
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 type = symbol.GetAttribute ("type");
|
||||||
string cname = symbol.GetAttribute ("cname");
|
string cname = symbol.GetAttribute ("cname");
|
||||||
string name = symbol.GetAttribute ("name");
|
string name = symbol.GetAttribute ("name");
|
||||||
|
IGeneratable result = null;
|
||||||
|
|
||||||
if (type == "simple")
|
if (type == "simple")
|
||||||
SymbolTable.Table.AddType (new SimpleGen (cname, name));
|
result = new SimpleGen (cname, name);
|
||||||
else if (type == "manual")
|
else if (type == "manual")
|
||||||
SymbolTable.Table.AddType (new ManualGen (cname, name));
|
result = new ManualGen (cname, name);
|
||||||
else
|
else
|
||||||
Console.WriteLine ("Unexpected symbol type " + type);
|
Console.WriteLine ("Parser::ParseSymbol - Unexpected symbol type " + type);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,17 +93,17 @@ namespace GtkSharp.Generation {
|
||||||
AddType (new ManualGen ("GObject", "GLib", "Object"));
|
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)
|
public void AddType (IGeneratable gen)
|
||||||
{
|
{
|
||||||
types [gen.CName] = gen;
|
types [gen.CName] = gen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddTypes (IGeneratable[] gens)
|
||||||
|
{
|
||||||
|
foreach (IGeneratable gen in gens)
|
||||||
|
types [gen.CName] = gen;
|
||||||
|
}
|
||||||
|
|
||||||
public int Count {
|
public int Count {
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@ -119,8 +119,7 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public IGeneratable this [string ctype] {
|
public IGeneratable this [string ctype] {
|
||||||
get {
|
get {
|
||||||
ctype = DeAlias (ctype);
|
return DeAlias (ctype) as IGeneratable;
|
||||||
return types [ctype] as IGeneratable;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,13 +138,16 @@ namespace GtkSharp.Generation {
|
||||||
return trim_type;
|
return trim_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string DeAlias (string type)
|
private object DeAlias (string type)
|
||||||
{
|
{
|
||||||
type = Trim (type);
|
type = Trim (type);
|
||||||
while (alias.ContainsKey(type))
|
while (types [type] is AliasGen) {
|
||||||
type = (string) alias[type];
|
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)
|
public string FromNativeReturn(string c_type, string val)
|
||||||
|
@ -246,14 +248,9 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public bool IsEnumFlags(string c_type)
|
public bool IsEnumFlags(string c_type)
|
||||||
{
|
{
|
||||||
c_type = Trim(c_type);
|
EnumGen gen = this [c_type] as EnumGen;
|
||||||
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 (gen != null && gen.Elem.GetAttribute ("type") == "flags");
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsInterface(string c_type)
|
public bool IsInterface(string c_type)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue