refactoring to remove substantial code duplication thoughout the generator
2002-05-23 Mike Kestner <mkestner@speakeasy.net> * generator/BoxedGen.cs : Update for Static SymbolTable * generator/CallbackGen.cs : Use GenBase and Parameters classes * generator/CodeGenerator.cs : Update for Static SymbolTable * generator/Ctor.cs : code from StructBase using Parameters class * generator/EnumGen.cs : Use GenBase * generator/GenBase.cs : Abstract Stream Writer creation, stream boilerplate, and common *Name properties * generator/IGeneratable.cs : Update for Static SymbolTable * generator/InterfaceGen.cs : Use GenBase * generator/Method.cs : code from StructBase using Parameters class * generator/ObjectGen.cs : Major refactoring. Use GenBase. Build tables of Member generatables at construct time to facilitate future name collision resolution logic. * generator/Parameters.cs : new generatable to abstract duplicated parameter parsing logic. * generator/Parser.cs : Update for Static SymbolTable * generator/Property.cs : code from ObjectGen * generator/Signal.cs : code from ObjectGen * generator/SignalHandler.cs : Update for Static SymbolTable * generator/StructBase.cs : Update for Static SymbolTable * generator/StructGen.cs : Update for Static SymbolTable * generator/SymbolTable.cs : Make all methods and private members static. There is no reason to ever have multiple tables. svn path=/trunk/gtk-sharp/; revision=4895
This commit is contained in:
parent
e5db28deea
commit
6d30cf0c3e
19 changed files with 932 additions and 512 deletions
26
ChangeLog
26
ChangeLog
|
@ -1,3 +1,29 @@
|
|||
2002-05-23 Mike Kestner <mkestner@speakeasy.net>
|
||||
|
||||
* generator/BoxedGen.cs : Update for Static SymbolTable
|
||||
* generator/CallbackGen.cs : Use GenBase and Parameters classes
|
||||
* generator/CodeGenerator.cs : Update for Static SymbolTable
|
||||
* generator/Ctor.cs : code from StructBase using Parameters class
|
||||
* generator/EnumGen.cs : Use GenBase
|
||||
* generator/GenBase.cs : Abstract Stream Writer creation, stream
|
||||
boilerplate, and common *Name properties
|
||||
* generator/IGeneratable.cs : Update for Static SymbolTable
|
||||
* generator/InterfaceGen.cs : Use GenBase
|
||||
* generator/Method.cs : code from StructBase using Parameters class
|
||||
* generator/ObjectGen.cs : Major refactoring. Use GenBase. Build
|
||||
tables of Member generatables at construct time to facilitate
|
||||
future name collision resolution logic.
|
||||
* generator/Parameters.cs : new generatable to abstract duplicated
|
||||
parameter parsing logic.
|
||||
* generator/Parser.cs : Update for Static SymbolTable
|
||||
* generator/Property.cs : code from ObjectGen
|
||||
* generator/Signal.cs : code from ObjectGen
|
||||
* generator/SignalHandler.cs : Update for Static SymbolTable
|
||||
* generator/StructBase.cs : Update for Static SymbolTable
|
||||
* generator/StructGen.cs : Update for Static SymbolTable
|
||||
* generator/SymbolTable.cs : Make all methods and private members
|
||||
static. There is no reason to ever have multiple tables.
|
||||
|
||||
2002-05-13 Joe Shaw <joe@assbarn.com>
|
||||
|
||||
* sample/Makefile.in: Use -L compiler flags and specify all of the
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace GtkSharp.Generation {
|
|||
return "(" + QualifiedName + ") GLib.Boxed.FromNative(" + var + ")";
|
||||
}
|
||||
|
||||
public void Generate (SymbolTable table)
|
||||
public void Generate ()
|
||||
{
|
||||
char sep = Path.DirectorySeparatorChar;
|
||||
string dir = ".." + sep + ns.ToLower() + sep + "generated";
|
||||
|
@ -72,7 +72,7 @@ namespace GtkSharp.Generation {
|
|||
switch (node.Name) {
|
||||
case "field":
|
||||
Statistics.IgnoreCount++;
|
||||
// GenField(member, table, sw);
|
||||
// GenField(member, sw);
|
||||
break;
|
||||
|
||||
case "callback":
|
||||
|
@ -80,13 +80,13 @@ namespace GtkSharp.Generation {
|
|||
break;
|
||||
|
||||
case "constructor":
|
||||
if (!GenCtor(member, table, sw, clash_map)) {
|
||||
if (!GenCtor(member, sw, clash_map)) {
|
||||
Console.WriteLine(" in boxed " + CName);
|
||||
}
|
||||
break;
|
||||
|
||||
case "method":
|
||||
if (!GenMethod(member, table, sw)) {
|
||||
if (!GenMethod(member, sw)) {
|
||||
Console.WriteLine(" in boxed " + CName);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -10,36 +10,14 @@ namespace GtkSharp.Generation {
|
|||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
public class CallbackGen : IGeneratable {
|
||||
public class CallbackGen : GenBase, IGeneratable {
|
||||
|
||||
private String ns;
|
||||
private XmlElement elem;
|
||||
private Parameters parms;
|
||||
|
||||
public CallbackGen (String ns, XmlElement elem) {
|
||||
|
||||
this.ns = ns;
|
||||
this.elem = elem;
|
||||
}
|
||||
|
||||
public String Name {
|
||||
get
|
||||
{
|
||||
return elem.GetAttribute("name");
|
||||
}
|
||||
}
|
||||
|
||||
public String CName {
|
||||
get
|
||||
{
|
||||
return elem.GetAttribute("cname");
|
||||
}
|
||||
}
|
||||
|
||||
public String QualifiedName {
|
||||
get
|
||||
{
|
||||
return ns + "." + elem.GetAttribute("name");
|
||||
}
|
||||
public CallbackGen (String ns, XmlElement elem) : base (ns, elem)
|
||||
{
|
||||
if (elem ["parameters"] != null)
|
||||
parms = new Parameters (elem ["parameters"]);
|
||||
}
|
||||
|
||||
public String MarshalType {
|
||||
|
@ -59,98 +37,40 @@ namespace GtkSharp.Generation {
|
|||
return var;
|
||||
}
|
||||
|
||||
public void Generate (SymbolTable table)
|
||||
public void Generate ()
|
||||
{
|
||||
XmlElement ret_elem = elem["return-type"];
|
||||
XmlElement ret_elem = Elem["return-type"];
|
||||
if (ret_elem == null) {
|
||||
Console.WriteLine("Missing return type in callback " + CName);
|
||||
Console.WriteLine("No return type in callback " + CName);
|
||||
Statistics.ThrottledCount++;
|
||||
return;
|
||||
}
|
||||
|
||||
string rettype = ret_elem.GetAttribute("type");
|
||||
string s_ret = table.GetCSType(rettype);
|
||||
string s_ret = SymbolTable.GetCSType(rettype);
|
||||
if (s_ret == "") {
|
||||
Console.WriteLine("rettype: " + rettype + " in callback " + CName);
|
||||
Statistics.ThrottledCount++;
|
||||
return;
|
||||
}
|
||||
|
||||
string parmstr = "";
|
||||
XmlNode params_elem = elem["parameters"];
|
||||
if (params_elem != null) {
|
||||
|
||||
bool need_comma = false;
|
||||
foreach (XmlNode node in params_elem.ChildNodes) {
|
||||
if (node.Name != "parameter") {
|
||||
continue;
|
||||
}
|
||||
|
||||
XmlElement param = (XmlElement) node;
|
||||
string type = param.GetAttribute("type");
|
||||
string cs_type = table.GetCSType(type);
|
||||
string name = param.GetAttribute("name");
|
||||
name = MangleName(name);
|
||||
|
||||
if ((cs_type == "") || (name == "")) {
|
||||
Console.WriteLine("parmtype: " + type + " in callback " + CName);
|
||||
Statistics.ThrottledCount++;
|
||||
break;
|
||||
}
|
||||
|
||||
if (need_comma)
|
||||
parmstr += ", ";
|
||||
|
||||
parmstr += (cs_type + " " + name);
|
||||
need_comma = true;
|
||||
}
|
||||
if ((parms != null) && !parms.Validate ()) {
|
||||
Console.WriteLine(" in callback " + CName);
|
||||
Statistics.ThrottledCount++;
|
||||
return;
|
||||
}
|
||||
|
||||
char sep = Path.DirectorySeparatorChar;
|
||||
string dir = ".." + sep + ns.ToLower() + sep + "generated";
|
||||
if (!Directory.Exists(dir)) {
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
String filename = dir + sep + Name + ".cs";
|
||||
StreamWriter sw = CreateWriter ();
|
||||
|
||||
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
|
||||
StreamWriter sw = new StreamWriter (stream);
|
||||
string sig = "";
|
||||
if (parms != null)
|
||||
sig = parms.Signature;
|
||||
|
||||
sw.WriteLine ("// Generated File. Do not modify.");
|
||||
sw.WriteLine ("// <c> 2001-2002 Mike Kestner");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\tpublic delegate " + s_ret + " " + Name + "(" + sig + ");");
|
||||
|
||||
sw.WriteLine ("namespace " + ns + " {");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("\tpublic delegate " + s_ret + " " + Name + "(" + parmstr + ");");
|
||||
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("}");
|
||||
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
CloseWriter (sw);
|
||||
Statistics.CBCount++;
|
||||
}
|
||||
|
||||
|
||||
public string MangleName(string name)
|
||||
{
|
||||
switch (name) {
|
||||
case "string":
|
||||
name = "str1ng";
|
||||
break;
|
||||
case "event":
|
||||
name = "evnt";
|
||||
break;
|
||||
case "object":
|
||||
name = "objekt";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
|
||||
Parser p = new Parser (args[0]);
|
||||
SymbolTable table = p.Parse ();
|
||||
Console.WriteLine (table.Count + " types parsed.");
|
||||
p.Parse ();
|
||||
Console.WriteLine (SymbolTable.Count + " types parsed.");
|
||||
|
||||
foreach (IGeneratable gen in table.Generatables) {
|
||||
gen.Generate (table);
|
||||
foreach (IGeneratable gen in SymbolTable.Generatables) {
|
||||
gen.Generate ();
|
||||
}
|
||||
|
||||
Statistics.Report();
|
||||
|
|
90
generator/Ctor.cs
Normal file
90
generator/Ctor.cs
Normal file
|
@ -0,0 +1,90 @@
|
|||
// GtkSharp.Generation.Ctor.cs - The Constructor Generation Class.
|
||||
//
|
||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
//
|
||||
// (c) 2001-2002 Mike Kestner
|
||||
|
||||
namespace GtkSharp.Generation {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
public class Ctor {
|
||||
|
||||
private string ns;
|
||||
private XmlElement elem;
|
||||
private Parameters parms;
|
||||
|
||||
public Ctor (string ns, XmlElement elem) {
|
||||
this.ns = ns;
|
||||
this.elem = elem;
|
||||
XmlElement parms_elem = elem ["parameters"];
|
||||
if (parms_elem != null)
|
||||
parms = new Parameters (parms_elem);
|
||||
}
|
||||
|
||||
public bool Validate ()
|
||||
{
|
||||
if ((parms != null) && !parms.Validate ()) {
|
||||
Console.Write("ctor ");
|
||||
Statistics.ThrottledCount++;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Generate (StreamWriter sw, Hashtable clash_map)
|
||||
{
|
||||
string sigtypes = "";
|
||||
string sig = "()";
|
||||
string call = "()";
|
||||
string isig = "();";
|
||||
if (parms != null) {
|
||||
call = "(" + parms.CallString + ")";
|
||||
sig = "(" + parms.Signature + ")";
|
||||
isig = "(" + parms.ImportSig + ");";
|
||||
sigtypes = parms.SignatureTypes;
|
||||
}
|
||||
|
||||
bool clash = false;
|
||||
if (clash_map.ContainsKey(sigtypes)) {
|
||||
clash = true;
|
||||
} else {
|
||||
clash_map[sigtypes] = elem;
|
||||
}
|
||||
|
||||
string cname = elem.GetAttribute("cname");
|
||||
string name = ((XmlElement)elem.ParentNode).GetAttribute("name");
|
||||
|
||||
sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) + "\")]");
|
||||
sw.WriteLine("\t\tstatic extern IntPtr " + cname + isig);
|
||||
sw.WriteLine();
|
||||
|
||||
if (clash) {
|
||||
String mname = cname.Substring(cname.IndexOf("new"));
|
||||
mname = mname.Substring(0,1).ToUpper() + mname.Substring(1);
|
||||
int idx;
|
||||
while ((idx = mname.IndexOf("_")) > 0) {
|
||||
mname = mname.Substring(0, idx) + mname.Substring(idx+1, 1).ToUpper() + mname.Substring(idx+2);
|
||||
}
|
||||
|
||||
sw.WriteLine("\t\tpublic static " + name + " " + mname + sig);
|
||||
sw.WriteLine("\t\t{");
|
||||
sw.WriteLine("\t\t\treturn new " + name + "(" + cname + call + ");");
|
||||
} else {
|
||||
sw.WriteLine("\t\tpublic " + name + sig);
|
||||
sw.WriteLine("\t\t{");
|
||||
sw.WriteLine("\t\t\tRaw = " + cname + call + ";");
|
||||
}
|
||||
|
||||
sw.WriteLine("\t\t}");
|
||||
sw.WriteLine();
|
||||
|
||||
Statistics.CtorCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,37 +10,9 @@ namespace GtkSharp.Generation {
|
|||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
public class EnumGen : IGeneratable {
|
||||
public class EnumGen : GenBase, IGeneratable {
|
||||
|
||||
private String ns;
|
||||
private XmlElement elem;
|
||||
|
||||
public EnumGen (String ns, XmlElement elem) {
|
||||
|
||||
this.ns = ns;
|
||||
this.elem = elem;
|
||||
}
|
||||
|
||||
public String Name {
|
||||
get
|
||||
{
|
||||
return elem.GetAttribute("name");
|
||||
}
|
||||
}
|
||||
|
||||
public String CName {
|
||||
get
|
||||
{
|
||||
return elem.GetAttribute("cname");
|
||||
}
|
||||
}
|
||||
|
||||
public String QualifiedName {
|
||||
get
|
||||
{
|
||||
return ns + "." + elem.GetAttribute("name");
|
||||
}
|
||||
}
|
||||
public EnumGen (String ns, XmlElement elem) : base (ns, elem) {}
|
||||
|
||||
public String MarshalType {
|
||||
get
|
||||
|
@ -59,26 +31,11 @@ namespace GtkSharp.Generation {
|
|||
return "(" + QualifiedName + ")" + var;
|
||||
}
|
||||
|
||||
public void Generate (SymbolTable table)
|
||||
public void Generate ()
|
||||
{
|
||||
char sep = Path.DirectorySeparatorChar;
|
||||
string dir = ".." + sep + ns.ToLower() + sep + "generated";
|
||||
if (!Directory.Exists(dir)) {
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
String filename = dir + sep + Name + ".cs";
|
||||
StreamWriter sw = CreateWriter ();
|
||||
|
||||
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
|
||||
StreamWriter sw = new StreamWriter (stream);
|
||||
|
||||
sw.WriteLine ("// Generated File. Do not modify.");
|
||||
sw.WriteLine ("// <c> 2001 Mike Kestner");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("namespace " + ns + " {");
|
||||
sw.WriteLine ();
|
||||
|
||||
if (elem.GetAttribute("type") == "flags") {
|
||||
if (Elem.GetAttribute("type") == "flags") {
|
||||
sw.WriteLine ("\tusing System;");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t[Flags]");
|
||||
|
@ -87,7 +44,7 @@ namespace GtkSharp.Generation {
|
|||
sw.WriteLine ("\tpublic enum " + Name + " {");
|
||||
sw.WriteLine ();
|
||||
|
||||
foreach (XmlNode node in elem.ChildNodes) {
|
||||
foreach (XmlNode node in Elem.ChildNodes) {
|
||||
if (node.Name != "member") {
|
||||
continue;
|
||||
}
|
||||
|
@ -102,11 +59,7 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
|
||||
sw.WriteLine ("\t}");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("}");
|
||||
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
CloseWriter (sw);
|
||||
Statistics.EnumCount++;
|
||||
}
|
||||
|
||||
|
|
85
generator/GenBase.cs
Normal file
85
generator/GenBase.cs
Normal file
|
@ -0,0 +1,85 @@
|
|||
// GtkSharp.Generation.GenBase.cs - The Generatable base class.
|
||||
//
|
||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
//
|
||||
// (c) 2001-2002 Mike Kestner
|
||||
|
||||
namespace GtkSharp.Generation {
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
public abstract class GenBase {
|
||||
|
||||
private string ns;
|
||||
private XmlElement elem;
|
||||
|
||||
protected GenBase (string ns, XmlElement elem)
|
||||
{
|
||||
this.ns = ns;
|
||||
this.elem = elem;
|
||||
}
|
||||
|
||||
public string CName {
|
||||
get {
|
||||
return elem.GetAttribute ("cname");
|
||||
}
|
||||
}
|
||||
|
||||
public XmlElement Elem {
|
||||
get {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get {
|
||||
return elem.GetAttribute ("name");
|
||||
}
|
||||
}
|
||||
|
||||
public string Namespace {
|
||||
get {
|
||||
return ns;
|
||||
}
|
||||
}
|
||||
|
||||
public string QualifiedName {
|
||||
get {
|
||||
return ns + "." + Name;
|
||||
}
|
||||
}
|
||||
|
||||
protected StreamWriter CreateWriter ()
|
||||
{
|
||||
char sep = Path.DirectorySeparatorChar;
|
||||
string dir = ".." + sep + ns.ToLower() + sep + "generated";
|
||||
if (!Directory.Exists(dir)) {
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
String filename = dir + sep + Name + ".cs";
|
||||
|
||||
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
|
||||
StreamWriter sw = new StreamWriter (stream);
|
||||
|
||||
sw.WriteLine ("// Generated File. Do not modify.");
|
||||
sw.WriteLine ("// <c> 2001-2002 Mike Kestner");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("namespace " + ns + " {");
|
||||
sw.WriteLine ();
|
||||
|
||||
return sw;
|
||||
}
|
||||
|
||||
protected void CloseWriter (StreamWriter sw)
|
||||
{
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("}");
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,6 @@ namespace GtkSharp.Generation {
|
|||
|
||||
String FromNative (String var);
|
||||
|
||||
void Generate (SymbolTable table);
|
||||
void Generate ();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
//
|
||||
// (c) 2001 Mike Kestner
|
||||
// (c) 2001-2002 Mike Kestner
|
||||
|
||||
namespace GtkSharp.Generation {
|
||||
|
||||
|
@ -10,37 +10,9 @@ namespace GtkSharp.Generation {
|
|||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
public class InterfaceGen : IGeneratable {
|
||||
public class InterfaceGen : GenBase, IGeneratable {
|
||||
|
||||
private String ns;
|
||||
private XmlElement elem;
|
||||
|
||||
public InterfaceGen (String ns, XmlElement elem) {
|
||||
|
||||
this.ns = ns;
|
||||
this.elem = elem;
|
||||
}
|
||||
|
||||
public String Name {
|
||||
get
|
||||
{
|
||||
return elem.GetAttribute("name");
|
||||
}
|
||||
}
|
||||
|
||||
public String CName {
|
||||
get
|
||||
{
|
||||
return elem.GetAttribute("cname");
|
||||
}
|
||||
}
|
||||
|
||||
public String QualifiedName {
|
||||
get
|
||||
{
|
||||
return ns + "." + elem.GetAttribute("name");
|
||||
}
|
||||
}
|
||||
public InterfaceGen (string ns, XmlElement elem) : base (ns, elem) {}
|
||||
|
||||
public String MarshalType {
|
||||
get
|
||||
|
@ -59,31 +31,17 @@ namespace GtkSharp.Generation {
|
|||
return "";
|
||||
}
|
||||
|
||||
public void Generate (SymbolTable table)
|
||||
public void Generate ()
|
||||
{
|
||||
char sep = Path.DirectorySeparatorChar;
|
||||
string dir = ".." + sep + ns.ToLower() + sep + "generated";
|
||||
if (!Directory.Exists(dir)) {
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
String filename = dir + sep + Name + ".cs";
|
||||
StreamWriter sw = CreateWriter ();
|
||||
|
||||
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
|
||||
StreamWriter sw = new StreamWriter (stream);
|
||||
|
||||
sw.WriteLine ("// Generated File. Do not modify.");
|
||||
sw.WriteLine ("// <c> 2001 Mike Kestner");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("namespace " + ns + " {");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\tusing System;");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("\tpublic interface " + Name + " {");
|
||||
sw.WriteLine ();
|
||||
|
||||
foreach (XmlNode node in elem.ChildNodes) {
|
||||
foreach (XmlNode node in Elem.ChildNodes) {
|
||||
if (node.Name != "member") {
|
||||
continue;
|
||||
}
|
||||
|
@ -92,11 +50,7 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
|
||||
sw.WriteLine ("\t}");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("}");
|
||||
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
CloseWriter (sw);
|
||||
Statistics.IFaceCount++;
|
||||
}
|
||||
|
||||
|
|
151
generator/Method.cs
Normal file
151
generator/Method.cs
Normal file
|
@ -0,0 +1,151 @@
|
|||
// GtkSharp.Generation.Method.cs - The Method Generatable.
|
||||
//
|
||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
//
|
||||
// (c) 2001-2002 Mike Kestner
|
||||
|
||||
namespace GtkSharp.Generation {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
public class Method {
|
||||
|
||||
private string ns;
|
||||
private XmlElement elem;
|
||||
private Parameters parms;
|
||||
|
||||
public Method (string ns, XmlElement elem)
|
||||
{
|
||||
this.ns = ns;
|
||||
this.elem = elem;
|
||||
if (elem["parameters"] != null)
|
||||
parms = new Parameters (elem["parameters"]);
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get {
|
||||
return elem.GetAttribute("name");
|
||||
}
|
||||
set {
|
||||
elem.SetAttribute("name", value);
|
||||
}
|
||||
}
|
||||
|
||||
public Parameters Params {
|
||||
get {
|
||||
return parms;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals (object o)
|
||||
{
|
||||
if (!(o is Method))
|
||||
return false;
|
||||
|
||||
return (this == (Method) o);
|
||||
}
|
||||
|
||||
public static bool operator == (Method a, Method b)
|
||||
{
|
||||
if (a.Name != b.Name)
|
||||
return false;
|
||||
|
||||
if (a.Params == null)
|
||||
return b.Params == null;
|
||||
|
||||
if (b.Params == null)
|
||||
return false;
|
||||
|
||||
return (a.Params.SignatureTypes == b.Params.SignatureTypes);
|
||||
}
|
||||
|
||||
public static bool operator != (Method a, Method b)
|
||||
{
|
||||
if (a.Name == b.Name)
|
||||
return false;
|
||||
|
||||
if (a.Params == null)
|
||||
return b.Params != null;
|
||||
|
||||
if (b.Params == null)
|
||||
return true;
|
||||
|
||||
return (a.Params.SignatureTypes != b.Params.SignatureTypes);
|
||||
}
|
||||
|
||||
public bool Validate ()
|
||||
{
|
||||
XmlElement ret_elem = elem["return-type"];
|
||||
if (ret_elem == null) {
|
||||
Console.Write("Missing return type in method ");
|
||||
Statistics.ThrottledCount++;
|
||||
return false;
|
||||
}
|
||||
|
||||
string rettype = ret_elem.GetAttribute("type");
|
||||
string m_ret = SymbolTable.GetMarshalType(rettype);
|
||||
string s_ret = SymbolTable.GetCSType(rettype);
|
||||
if (m_ret == "" || s_ret == "") {
|
||||
Console.Write("rettype: " + rettype + " method ");
|
||||
Statistics.ThrottledCount++;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Params == null)
|
||||
return true;
|
||||
|
||||
return Params.Validate ();
|
||||
}
|
||||
|
||||
public void Generate (StreamWriter sw)
|
||||
{
|
||||
string sig, isig, call;
|
||||
|
||||
if (parms != null) {
|
||||
sig = "(" + parms.Signature + ")";
|
||||
isig = "(IntPtr raw, " + parms.ImportSig + ");";
|
||||
call = "(Handle, " + parms.CallString + ")";
|
||||
} else {
|
||||
sig = "()";
|
||||
isig = "(IntPtr raw);";
|
||||
call = "(Handle)";
|
||||
}
|
||||
|
||||
string rettype = elem["return-type"].GetAttribute("type");
|
||||
string m_ret = SymbolTable.GetMarshalType(rettype);
|
||||
string s_ret = SymbolTable.GetCSType(rettype);
|
||||
string cname = elem.GetAttribute("cname");
|
||||
|
||||
if (cname[0] == '_') {
|
||||
Statistics.ThrottledCount++;
|
||||
return;
|
||||
}
|
||||
|
||||
sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) +
|
||||
"\", CallingConvention=CallingConvention.Cdecl)]");
|
||||
sw.Write("\t\tstatic extern " + m_ret + " " + cname + isig);
|
||||
sw.WriteLine();
|
||||
|
||||
sw.Write("\t\tpublic ");
|
||||
if (elem.HasAttribute("new_flag"))
|
||||
sw.Write("new ");
|
||||
sw.WriteLine(s_ret + " " + Name + sig);
|
||||
sw.WriteLine("\t\t{");
|
||||
sw.Write("\t\t\t");
|
||||
if (m_ret == "void") {
|
||||
sw.WriteLine(cname + call + ";");
|
||||
} else {
|
||||
sw.WriteLine("return " + SymbolTable.FromNative(rettype, cname + call) + ";");
|
||||
}
|
||||
|
||||
sw.WriteLine("\t\t}");
|
||||
sw.WriteLine();
|
||||
|
||||
Statistics.MethodCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
//
|
||||
// (c) 2001 Mike Kestner
|
||||
// (c) 2001-2002 Mike Kestner
|
||||
|
||||
namespace GtkSharp.Generation {
|
||||
|
||||
|
@ -11,141 +11,94 @@ namespace GtkSharp.Generation {
|
|||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
public class ObjectGen : StructBase, IGeneratable {
|
||||
public class ObjectGen : GenBase, IGeneratable {
|
||||
|
||||
public ObjectGen (String ns, XmlElement elem) : base (ns, elem) {}
|
||||
private ArrayList ctors = new ArrayList();
|
||||
private Hashtable props = new Hashtable();
|
||||
private Hashtable sigs = new Hashtable();
|
||||
private Hashtable methods = new Hashtable();
|
||||
|
||||
public String MarshalType {
|
||||
get
|
||||
{
|
||||
return "IntPtr";
|
||||
}
|
||||
}
|
||||
|
||||
public String CallByName (String var_name)
|
||||
public ObjectGen (string ns, XmlElement elem) : base (ns, elem)
|
||||
{
|
||||
return var_name + ".Handle";
|
||||
}
|
||||
|
||||
public String FromNative(String var)
|
||||
{
|
||||
return "(" + QualifiedName + ") GLib.Object.GetObject(" + var + ")";
|
||||
}
|
||||
|
||||
public void Generate (SymbolTable table)
|
||||
{
|
||||
char sep = Path.DirectorySeparatorChar;
|
||||
string dir = ".." + sep + ns.ToLower() + sep + "generated";
|
||||
if (!Directory.Exists(dir)) {
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
String filename = dir + sep + Name + ".cs";
|
||||
|
||||
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
|
||||
StreamWriter sw = new StreamWriter (stream);
|
||||
|
||||
sw.WriteLine ("// Generated File. Do not modify.");
|
||||
sw.WriteLine ("// <c> 2001-2002 Mike Kestner");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("namespace " + ns + " {");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("\tusing System;");
|
||||
sw.WriteLine ("\tusing System.Collections;");
|
||||
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
|
||||
sw.WriteLine ();
|
||||
|
||||
String parent = elem.GetAttribute("parent");
|
||||
String cs_parent = table.GetCSType(parent);
|
||||
sw.Write ("\tpublic class " + Name);
|
||||
if (cs_parent == "") {
|
||||
sw.WriteLine (" {");
|
||||
Console.WriteLine ("Object " + Name + " Unknown parent " + parent);
|
||||
} else {
|
||||
sw.WriteLine (" : " + cs_parent + " {");
|
||||
}
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}");
|
||||
sw.WriteLine();
|
||||
|
||||
Hashtable clash_map = new Hashtable();
|
||||
Hashtable props = new Hashtable();
|
||||
Hashtable sigs = new Hashtable();
|
||||
ArrayList methods = new ArrayList();
|
||||
bool first_sig = true;
|
||||
|
||||
foreach (XmlNode node in elem.ChildNodes) {
|
||||
|
||||
XmlElement member = (XmlElement) node;
|
||||
|
||||
switch (node.Name) {
|
||||
case "field":
|
||||
Statistics.IgnoreCount++;
|
||||
break;
|
||||
|
||||
case "callback":
|
||||
Statistics.IgnoreCount++;
|
||||
break;
|
||||
|
||||
case "constructor":
|
||||
if (!GenCtor(member, table, sw, clash_map)) {
|
||||
Console.WriteLine("in object " + CName);
|
||||
}
|
||||
ctors.Add (new Ctor (ns, member));
|
||||
break;
|
||||
|
||||
case "method":
|
||||
methods.Add(member);
|
||||
methods.Add (member.GetAttribute ("name"), new Method (ns, member));
|
||||
break;
|
||||
|
||||
case "property":
|
||||
String pname;
|
||||
if (!GenProperty(member, table, sw, out pname)) {
|
||||
Console.WriteLine("in object " + CName);
|
||||
}
|
||||
props.Add(pname, pname);
|
||||
props.Add (member.GetAttribute ("name"), new Property (member));
|
||||
break;
|
||||
|
||||
case "signal":
|
||||
if (first_sig) {
|
||||
first_sig = false;
|
||||
sw.WriteLine("\t\tprivate Hashtable Signals = new Hashtable();");
|
||||
}
|
||||
String sname;
|
||||
if (!GenSignal(member, table, sw, out sname)) {
|
||||
Console.WriteLine("in object " + CName);
|
||||
}
|
||||
sigs.Add(sname, sname);
|
||||
sigs.Add (member.GetAttribute ("name"), new Signal (ns, member));
|
||||
break;
|
||||
|
||||
default:
|
||||
Console.WriteLine ("Unexpected node");
|
||||
Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!clash_map.ContainsKey("")) {
|
||||
sw.WriteLine("\t\tprotected " + Name + "() : base(){}");
|
||||
sw.WriteLine();
|
||||
public string MarshalType {
|
||||
get {
|
||||
return "IntPtr";
|
||||
}
|
||||
}
|
||||
|
||||
foreach (XmlElement member in methods) {
|
||||
String mname = member.GetAttribute("name");
|
||||
if ((mname.StartsWith("Set") || mname.StartsWith("Get")) &&
|
||||
props.ContainsKey(mname.Substring(3))) {
|
||||
continue;
|
||||
} else if (sigs.ContainsKey(mname)) {
|
||||
member.SetAttribute("name", "Emit" + mname);
|
||||
}
|
||||
public string CallByName (string var_name)
|
||||
{
|
||||
return var_name + ".Handle";
|
||||
}
|
||||
|
||||
if (!GenMethod(member, table, sw)) {
|
||||
Console.WriteLine("in object " + CName);
|
||||
}
|
||||
public string FromNative(string var)
|
||||
{
|
||||
return "(" + QualifiedName + ") GLib.Object.GetObject(" + var + ")";
|
||||
}
|
||||
|
||||
private ObjectGen Parent {
|
||||
get {
|
||||
string parent = Elem.GetAttribute("parent");
|
||||
return SymbolTable.GetObjectGen(parent);
|
||||
}
|
||||
}
|
||||
|
||||
string custom = ".." + sep + ns.ToLower() + sep + Name + ".custom";
|
||||
public void Generate ()
|
||||
{
|
||||
StreamWriter sw = CreateWriter ();
|
||||
|
||||
sw.WriteLine ("\tusing System;");
|
||||
sw.WriteLine ("\tusing System.Collections;");
|
||||
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.Write ("\tpublic class " + Name);
|
||||
string cs_parent = SymbolTable.GetCSType(Elem.GetAttribute("parent"));
|
||||
if (cs_parent != "")
|
||||
sw.Write (" : " + cs_parent);
|
||||
sw.WriteLine (" {");
|
||||
sw.WriteLine ();
|
||||
|
||||
GenCtors (sw);
|
||||
GenProperties (sw);
|
||||
GenSignals (sw);
|
||||
GenMethods (sw);
|
||||
|
||||
char sep = Path.DirectorySeparatorChar;
|
||||
string custom = ".." + sep + Namespace.ToLower() + sep + Name + ".custom";
|
||||
if (File.Exists(custom)) {
|
||||
FileStream custstream = new FileStream (custom, FileMode.Open, FileAccess.Read);
|
||||
StreamReader sr = new StreamReader (custstream);
|
||||
|
@ -154,115 +107,112 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
|
||||
sw.WriteLine ("\t}");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("}");
|
||||
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
CloseWriter (sw);
|
||||
Statistics.ObjectCount++;
|
||||
}
|
||||
|
||||
public bool GenProperty (XmlElement prop, SymbolTable table, StreamWriter sw, out String name)
|
||||
private bool Validate ()
|
||||
{
|
||||
String c_type = prop.GetAttribute("type");
|
||||
|
||||
char[] ast = {'*'};
|
||||
c_type = c_type.TrimEnd(ast);
|
||||
string cs_type = table.GetCSType(c_type);
|
||||
|
||||
XmlElement parent = (XmlElement) prop.ParentNode;
|
||||
name = prop.GetAttribute("name");
|
||||
if (name == parent.GetAttribute("name")) {
|
||||
name += "Prop";
|
||||
}
|
||||
|
||||
string v_type = "";
|
||||
if (table.IsEnum(c_type)) {
|
||||
v_type = "int";
|
||||
} else if (table.IsInterface(c_type)) {
|
||||
// FIXME: Handle interface props properly.
|
||||
Console.Write("Interface property detected ");
|
||||
Statistics.ThrottledCount++;
|
||||
return true;
|
||||
} else if (table.IsObject(c_type)) {
|
||||
v_type = "GLib.Object";
|
||||
}
|
||||
|
||||
if (cs_type == "") {
|
||||
Console.Write("Property has unknown Type {0} ", c_type);
|
||||
Statistics.ThrottledCount++;
|
||||
string parent = Elem.GetAttribute("parent");
|
||||
string cs_parent = SymbolTable.GetCSType(parent);
|
||||
if (cs_parent == "") {
|
||||
Console.WriteLine ("Object " + Name + " Unknown parent " + parent);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (prop.HasAttribute("construct-only") && !prop.HasAttribute("readable")) {
|
||||
return true;
|
||||
}
|
||||
if (ctors != null)
|
||||
foreach (Ctor ctor in ctors)
|
||||
if (!ctor.Validate())
|
||||
return false;
|
||||
|
||||
sw.WriteLine("\t\tpublic " + cs_type + " " + name + " {");
|
||||
if (prop.HasAttribute("readable")) {
|
||||
sw.WriteLine("\t\t\tget {");
|
||||
sw.WriteLine("\t\t\t\tGLib.Value val;");
|
||||
sw.WriteLine("\t\t\t\tGetProperty(\"" + prop.GetAttribute("cname") + "\", out val);");
|
||||
sw.Write("\t\t\t\treturn (" + cs_type + ") ");
|
||||
if (v_type != "") {
|
||||
sw.Write("(" + v_type + ") ");
|
||||
}
|
||||
sw.WriteLine("val;");
|
||||
sw.WriteLine("\t\t\t}");
|
||||
}
|
||||
if (props != null)
|
||||
foreach (Property prop in props.Values)
|
||||
if (!prop.Validate())
|
||||
return false;
|
||||
|
||||
if (prop.HasAttribute("writeable") && !prop.HasAttribute("construct-only")) {
|
||||
sw.WriteLine("\t\t\tset {");
|
||||
sw.Write("\t\t\t\tSetProperty(\"" + prop.GetAttribute("cname") + "\", new GLib.Value(");
|
||||
if (v_type != "") {
|
||||
sw.Write("(" + v_type + ") ");
|
||||
}
|
||||
sw.WriteLine("value));");
|
||||
sw.WriteLine("\t\t\t}");
|
||||
}
|
||||
if (sigs != null)
|
||||
foreach (Signal sig in sigs.Values)
|
||||
if (!sig.Validate())
|
||||
return false;
|
||||
|
||||
sw.WriteLine("\t\t}");
|
||||
sw.WriteLine();
|
||||
if (methods != null)
|
||||
foreach (Method method in methods.Values)
|
||||
if (!method.Validate())
|
||||
return false;
|
||||
|
||||
Statistics.PropCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool GenSignal (XmlElement sig, SymbolTable table, StreamWriter sw, out String name)
|
||||
private void GenCtors (StreamWriter sw)
|
||||
{
|
||||
String cname = "\"" + sig.GetAttribute("cname") + "\"";
|
||||
name = sig.GetAttribute("name");
|
||||
sw.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}");
|
||||
sw.WriteLine();
|
||||
|
||||
String marsh = SignalHandler.GetName(sig, table);
|
||||
if (marsh == "") {
|
||||
Statistics.ThrottledCount++;
|
||||
return false;
|
||||
Hashtable clash_map = new Hashtable();
|
||||
|
||||
if (ctors != null)
|
||||
foreach (Ctor ctor in ctors) {
|
||||
if (ctor.Validate ())
|
||||
ctor.Generate (sw, clash_map);
|
||||
else
|
||||
Console.WriteLine(" in Object " + Name);
|
||||
}
|
||||
|
||||
if (!clash_map.ContainsKey("")) {
|
||||
sw.WriteLine("\t\tprotected " + Name + "() : base(){}");
|
||||
sw.WriteLine();
|
||||
}
|
||||
|
||||
marsh = "GtkSharp." + marsh;
|
||||
}
|
||||
|
||||
sw.WriteLine("\t\t/// <summary> " + name + " Event </summary>");
|
||||
sw.WriteLine("\t\t/// <remarks>");
|
||||
// FIXME: Generate some signal docs
|
||||
sw.WriteLine("\t\t/// </remarks>");
|
||||
sw.WriteLine();
|
||||
sw.WriteLine("\t\tpublic event EventHandler " + name + " {");
|
||||
sw.WriteLine("\t\t\tadd {");
|
||||
sw.WriteLine("\t\t\t\tif (EventList[" + cname + "] == null)");
|
||||
sw.Write("\t\t\t\t\tSignals[" + cname + "] = new " + marsh);
|
||||
sw.WriteLine("(this, Handle, " + cname + ", value);");
|
||||
sw.WriteLine("\t\t\t\tEventList.AddHandler(" + cname + ", value);");
|
||||
sw.WriteLine("\t\t\t}");
|
||||
sw.WriteLine("\t\t\tremove {");
|
||||
sw.WriteLine("\t\t\t\tEventList.RemoveHandler(" + cname + ", value);");
|
||||
sw.WriteLine("\t\t\t\tif (EventList[" + cname + "] == null)");
|
||||
sw.WriteLine("\t\t\t\t\tSignals.Remove(" + cname + ");");
|
||||
sw.WriteLine("\t\t\t}");
|
||||
sw.WriteLine("\t\t}");
|
||||
sw.WriteLine();
|
||||
private void GenProperties (StreamWriter sw)
|
||||
{
|
||||
if (props == null)
|
||||
return;
|
||||
|
||||
Statistics.SignalCount++;
|
||||
return true;
|
||||
foreach (Property prop in props.Values) {
|
||||
if (prop.Validate ())
|
||||
prop.Generate (sw);
|
||||
else
|
||||
Console.WriteLine(" in Object " + Name);
|
||||
}
|
||||
}
|
||||
|
||||
private void GenSignals (StreamWriter sw)
|
||||
{
|
||||
if (sigs == null)
|
||||
return;
|
||||
|
||||
sw.WriteLine("\t\tprivate Hashtable Signals = new Hashtable();");
|
||||
|
||||
foreach (Signal sig in sigs.Values) {
|
||||
if (sig.Validate ())
|
||||
sig.Generate (sw);
|
||||
else
|
||||
Console.WriteLine(" in Object " + Name);
|
||||
}
|
||||
}
|
||||
|
||||
private void GenMethods (StreamWriter sw)
|
||||
{
|
||||
if (methods == null)
|
||||
return;
|
||||
|
||||
foreach (Method method in methods.Values) {
|
||||
string mname = method.Name;
|
||||
if ((mname.StartsWith("Set") || mname.StartsWith("Get")) &&
|
||||
(props != null) && props.ContainsKey(mname.Substring(3))) {
|
||||
continue;
|
||||
} else if ((sigs != null) && sigs.ContainsKey(mname)) {
|
||||
method.Name = "Emit" + mname;
|
||||
}
|
||||
|
||||
if (method.Validate ())
|
||||
method.Generate (sw);
|
||||
else
|
||||
Console.WriteLine(" in Object " + Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
112
generator/Parameters.cs
Normal file
112
generator/Parameters.cs
Normal file
|
@ -0,0 +1,112 @@
|
|||
// GtkSharp.Generation.Parameters.cs - The Parameters Generation Class.
|
||||
//
|
||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
//
|
||||
// (c) 2001-2002 Mike Kestner
|
||||
|
||||
namespace GtkSharp.Generation {
|
||||
|
||||
using System;
|
||||
using System.Xml;
|
||||
|
||||
public class Parameters {
|
||||
|
||||
private XmlElement elem;
|
||||
private string import_sig;
|
||||
private string call_string;
|
||||
private string signature;
|
||||
private string signature_types;
|
||||
|
||||
public Parameters (XmlElement elem) {
|
||||
|
||||
this.elem = elem;
|
||||
}
|
||||
|
||||
public string CallString {
|
||||
get {
|
||||
return call_string;
|
||||
}
|
||||
}
|
||||
|
||||
public string ImportSig {
|
||||
get {
|
||||
return import_sig;
|
||||
}
|
||||
}
|
||||
|
||||
public string Signature {
|
||||
get {
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
|
||||
public string SignatureTypes {
|
||||
get {
|
||||
return signature_types;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Validate ()
|
||||
{
|
||||
signature_types = signature = import_sig = call_string = "";
|
||||
bool need_sep = false;
|
||||
|
||||
foreach (XmlNode parm in elem.ChildNodes) {
|
||||
if (parm.Name != "parameter") {
|
||||
continue;
|
||||
}
|
||||
|
||||
XmlElement p_elem = (XmlElement) parm;
|
||||
string type = p_elem.GetAttribute("type");
|
||||
string cs_type = SymbolTable.GetCSType(type);
|
||||
string m_type = SymbolTable.GetMarshalType(type);
|
||||
string name = MangleName(p_elem.GetAttribute("name"));
|
||||
string call_parm = SymbolTable.CallByName(type, name);
|
||||
|
||||
if ((cs_type == "") || (name == "") ||
|
||||
(m_type == "") || (call_parm == "")) {
|
||||
Console.Write("Name: " + name + " Type: " + type + " ");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (p_elem.HasAttribute("array")) {
|
||||
cs_type += "[]";
|
||||
m_type += "[]";
|
||||
}
|
||||
|
||||
if (need_sep) {
|
||||
call_string += ", ";
|
||||
signature += ", ";
|
||||
import_sig += ", ";
|
||||
signature_types += ":";
|
||||
} else {
|
||||
need_sep = true;
|
||||
}
|
||||
|
||||
signature += (cs_type + " " + name);
|
||||
signature_types += cs_type;
|
||||
call_string += call_parm;
|
||||
import_sig += (m_type + " " + name);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private string MangleName(string name)
|
||||
{
|
||||
switch (name) {
|
||||
case "string":
|
||||
return "str1ng";
|
||||
case "event":
|
||||
return "evnt";
|
||||
case "object":
|
||||
return "objekt";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,6 @@ namespace GtkSharp.Generation {
|
|||
public class Parser {
|
||||
|
||||
private XmlDocument doc;
|
||||
private SymbolTable table;
|
||||
|
||||
public Parser (String filename)
|
||||
{
|
||||
|
@ -31,19 +30,15 @@ namespace GtkSharp.Generation {
|
|||
|
||||
}
|
||||
|
||||
public SymbolTable Parse ()
|
||||
public void Parse ()
|
||||
{
|
||||
if (table != null) return table;
|
||||
|
||||
XmlElement root = doc.DocumentElement;
|
||||
|
||||
if ((root == null) || !root.HasChildNodes) {
|
||||
Console.WriteLine ("No Namespaces found.");
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
table = new SymbolTable ();
|
||||
|
||||
foreach (XmlNode ns in root.ChildNodes) {
|
||||
if (ns.Name != "namespace") {
|
||||
continue;
|
||||
|
@ -52,8 +47,6 @@ namespace GtkSharp.Generation {
|
|||
XmlElement elem = (XmlElement) ns;
|
||||
ParseNamespace (elem);
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
private void ParseNamespace (XmlElement ns)
|
||||
|
@ -74,27 +67,27 @@ namespace GtkSharp.Generation {
|
|||
break;
|
||||
|
||||
case "boxed":
|
||||
table.AddType (new BoxedGen (ns_name, elem));
|
||||
SymbolTable.AddType (new BoxedGen (ns_name, elem));
|
||||
break;
|
||||
|
||||
case "callback":
|
||||
table.AddType (new CallbackGen (ns_name, elem));
|
||||
SymbolTable.AddType (new CallbackGen (ns_name, elem));
|
||||
break;
|
||||
|
||||
case "enum":
|
||||
table.AddType (new EnumGen (ns_name, elem));
|
||||
SymbolTable.AddType (new EnumGen (ns_name, elem));
|
||||
break;
|
||||
|
||||
case "interface":
|
||||
table.AddType (new InterfaceGen (ns_name, elem));
|
||||
SymbolTable.AddType (new InterfaceGen (ns_name, elem));
|
||||
break;
|
||||
|
||||
case "object":
|
||||
table.AddType (new ObjectGen (ns_name, elem));
|
||||
SymbolTable.AddType (new ObjectGen (ns_name, elem));
|
||||
break;
|
||||
|
||||
case "struct":
|
||||
table.AddType (new StructGen (ns_name, elem));
|
||||
SymbolTable.AddType (new StructGen (ns_name, elem));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
101
generator/Property.cs
Normal file
101
generator/Property.cs
Normal file
|
@ -0,0 +1,101 @@
|
|||
// GtkSharp.Generation.Property.cs - The Property Generatable.
|
||||
//
|
||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
//
|
||||
// (c) 2001-2002 Mike Kestner
|
||||
|
||||
namespace GtkSharp.Generation {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
public class Property {
|
||||
|
||||
private XmlElement elem;
|
||||
|
||||
public Property (XmlElement elem)
|
||||
{
|
||||
this.elem = elem;
|
||||
}
|
||||
|
||||
public bool Validate ()
|
||||
{
|
||||
string c_type = elem.GetAttribute("type");
|
||||
string cs_type = SymbolTable.GetCSType(c_type);
|
||||
|
||||
if (cs_type == "") {
|
||||
Console.Write("Property has unknown Type {0} ", c_type);
|
||||
Statistics.ThrottledCount++;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SymbolTable.IsInterface(c_type)) {
|
||||
// FIXME: Handle interface props properly.
|
||||
Console.Write("Interface property detected ");
|
||||
Statistics.ThrottledCount++;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Generate (StreamWriter sw)
|
||||
{
|
||||
string c_type = elem.GetAttribute("type");
|
||||
string cs_type = SymbolTable.GetCSType(c_type);
|
||||
|
||||
XmlElement parent = (XmlElement) elem.ParentNode;
|
||||
string name = elem.GetAttribute("name");
|
||||
if (name == parent.GetAttribute("name")) {
|
||||
name += "Prop";
|
||||
}
|
||||
|
||||
string v_type = "";
|
||||
if (SymbolTable.IsEnum(c_type)) {
|
||||
v_type = "int";
|
||||
} else if (SymbolTable.IsInterface(c_type)) {
|
||||
// FIXME: Handle interface props properly.
|
||||
Console.Write("Interface property detected ");
|
||||
Statistics.ThrottledCount++;
|
||||
return;
|
||||
} else if (SymbolTable.IsObject(c_type)) {
|
||||
v_type = "GLib.Object";
|
||||
}
|
||||
|
||||
if (elem.HasAttribute("construct-only") && !elem.HasAttribute("readable")) {
|
||||
return;
|
||||
}
|
||||
|
||||
sw.WriteLine("\t\tpublic " + cs_type + " " + name + " {");
|
||||
if (elem.HasAttribute("readable")) {
|
||||
sw.WriteLine("\t\t\tget {");
|
||||
sw.WriteLine("\t\t\t\tGLib.Value val;");
|
||||
sw.WriteLine("\t\t\t\tGetProperty(\"" + elem.GetAttribute("cname") + "\", out val);");
|
||||
sw.Write("\t\t\t\treturn (" + cs_type + ") ");
|
||||
if (v_type != "") {
|
||||
sw.Write("(" + v_type + ") ");
|
||||
}
|
||||
sw.WriteLine("val;");
|
||||
sw.WriteLine("\t\t\t}");
|
||||
}
|
||||
|
||||
if (elem.HasAttribute("writeable") && !elem.HasAttribute("construct-only")) {
|
||||
sw.WriteLine("\t\t\tset {");
|
||||
sw.Write("\t\t\t\tSetProperty(\"" + elem.GetAttribute("cname") + "\", new GLib.Value(");
|
||||
if (v_type != "") {
|
||||
sw.Write("(" + v_type + ") ");
|
||||
}
|
||||
sw.WriteLine("value));");
|
||||
sw.WriteLine("\t\t\t}");
|
||||
}
|
||||
|
||||
sw.WriteLine("\t\t}");
|
||||
sw.WriteLine();
|
||||
|
||||
Statistics.PropCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
76
generator/Signal.cs
Normal file
76
generator/Signal.cs
Normal file
|
@ -0,0 +1,76 @@
|
|||
// GtkSharp.Generation.Signal.cs - The Signal Generatable.
|
||||
//
|
||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
//
|
||||
// (c) 2001-2002 Mike Kestner
|
||||
|
||||
namespace GtkSharp.Generation {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
public class Signal {
|
||||
|
||||
private string ns;
|
||||
private string marsh;
|
||||
private XmlElement elem;
|
||||
|
||||
public Signal (string ns, XmlElement elem)
|
||||
{
|
||||
this.ns = ns;
|
||||
this.elem = elem;
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get {
|
||||
return elem.GetAttribute ("name");
|
||||
}
|
||||
}
|
||||
|
||||
public bool Validate ()
|
||||
{
|
||||
marsh = SignalHandler.GetName(elem);
|
||||
if ((Name == "") || (marsh == "")) {
|
||||
Console.Write ("bad signal " + Name);
|
||||
Statistics.ThrottledCount++;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Generate (StreamWriter sw)
|
||||
{
|
||||
string cname = "\"" + elem.GetAttribute("cname") + "\"";
|
||||
marsh = "GtkSharp." + marsh;
|
||||
|
||||
sw.WriteLine("\t\t/// <summary> " + Name + " Event </summary>");
|
||||
sw.WriteLine("\t\t/// <remarks>");
|
||||
// FIXME: Generate some signal docs
|
||||
sw.WriteLine("\t\t/// </remarks>");
|
||||
sw.WriteLine();
|
||||
sw.Write("\t\tpublic ");
|
||||
if (elem.HasAttribute("new_flag"))
|
||||
sw.Write("new ");
|
||||
sw.WriteLine("event EventHandler " + Name + " {");
|
||||
sw.WriteLine("\t\t\tadd {");
|
||||
sw.WriteLine("\t\t\t\tif (EventList[" + cname + "] == null)");
|
||||
sw.Write("\t\t\t\t\tSignals[" + cname + "] = new " + marsh);
|
||||
sw.WriteLine("(this, Handle, " + cname + ", value);");
|
||||
sw.WriteLine("\t\t\t\tEventList.AddHandler(" + cname + ", value);");
|
||||
sw.WriteLine("\t\t\t}");
|
||||
sw.WriteLine("\t\t\tremove {");
|
||||
sw.WriteLine("\t\t\t\tEventList.RemoveHandler(" + cname + ", value);");
|
||||
sw.WriteLine("\t\t\t\tif (EventList[" + cname + "] == null)");
|
||||
sw.WriteLine("\t\t\t\t\tSignals.Remove(" + cname + ");");
|
||||
sw.WriteLine("\t\t\t}");
|
||||
sw.WriteLine("\t\t}");
|
||||
sw.WriteLine();
|
||||
|
||||
Statistics.SignalCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ namespace GtkSharp.Generation {
|
|||
|
||||
private static Hashtable handlers = new Hashtable ();
|
||||
|
||||
public static String GetName(XmlElement sig, SymbolTable table)
|
||||
public static String GetName(XmlElement sig)
|
||||
{
|
||||
XmlElement ret_elem = sig["return-type"];
|
||||
if (ret_elem == null) {
|
||||
|
@ -29,8 +29,8 @@ namespace GtkSharp.Generation {
|
|||
return "";
|
||||
}
|
||||
|
||||
String s_ret = table.GetCSType(retval);
|
||||
String p_ret = table.GetMarshalType(retval);
|
||||
String s_ret = SymbolTable.GetCSType(retval);
|
||||
String p_ret = SymbolTable.GetMarshalType(retval);
|
||||
if ((s_ret == "") || (p_ret == "")) {
|
||||
Console.Write("Funky type: " + retval);
|
||||
return "";
|
||||
|
@ -38,7 +38,7 @@ namespace GtkSharp.Generation {
|
|||
|
||||
String key = retval;
|
||||
String pinv = "";
|
||||
String name = table.GetName(retval);
|
||||
String name = SymbolTable.GetName(retval);
|
||||
int pcnt = 0;
|
||||
|
||||
ArrayList parms = new ArrayList();
|
||||
|
@ -54,7 +54,7 @@ namespace GtkSharp.Generation {
|
|||
|
||||
XmlElement elem = (XmlElement) parm;
|
||||
String type = elem.GetAttribute("type");
|
||||
String ptype = table.GetMarshalType(type);
|
||||
String ptype = SymbolTable.GetMarshalType(type);
|
||||
if (ptype == "") {
|
||||
Console.Write("Funky type: " + type);
|
||||
return "";
|
||||
|
@ -65,11 +65,11 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
pinv += (ptype + " arg" + pcnt);
|
||||
parms.Add(type);
|
||||
if (table.IsObject(type)) {
|
||||
if (SymbolTable.IsObject(type)) {
|
||||
name += "Object";
|
||||
key += "Object";
|
||||
} else {
|
||||
name += table.GetName(type);
|
||||
name += SymbolTable.GetName(type);
|
||||
key += type;
|
||||
}
|
||||
pcnt++;
|
||||
|
@ -136,7 +136,7 @@ namespace GtkSharp.Generation {
|
|||
sw.WriteLine("\t\t\targs.Args = new object[" + (parms.Count-1) + "];");
|
||||
}
|
||||
for (int idx=1; idx < parms.Count; idx++) {
|
||||
if (table.IsObject((String)parms[idx])) {
|
||||
if (SymbolTable.IsObject((String)parms[idx])) {
|
||||
sw.Write("\t\t\targs.Args[" + (idx-1) + "] ");
|
||||
sw.WriteLine("= GLib.Object.GetObject(arg" + idx + ");");
|
||||
} else {
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
|
||||
|
||||
protected bool GenCtor(XmlElement ctor, SymbolTable table, StreamWriter sw, Hashtable clash_map)
|
||||
protected bool GenCtor(XmlElement ctor, StreamWriter sw, Hashtable clash_map)
|
||||
{
|
||||
String sig, isig, call, sigtypes;
|
||||
XmlElement parms = ctor["parameters"];
|
||||
|
@ -54,9 +54,9 @@ namespace GtkSharp.Generation {
|
|||
call = sig = "()";
|
||||
isig = "();";
|
||||
sigtypes = "";
|
||||
} else if (GetSignature(parms, table, out sig, out sigtypes) &&
|
||||
GetImportSig(parms, table, out isig) &&
|
||||
GetCallString(parms, table, out call)) {
|
||||
} else if (GetSignature(parms, out sig, out sigtypes) &&
|
||||
GetImportSig(parms, out isig) &&
|
||||
GetCallString(parms, out call)) {
|
||||
sig = "(" + sig + ")";
|
||||
isig = "(" + isig + ");";
|
||||
call = "(" + call + ")";
|
||||
|
@ -75,7 +75,7 @@ namespace GtkSharp.Generation {
|
|||
|
||||
String cname = ctor.GetAttribute("cname");
|
||||
|
||||
sw.WriteLine("\t\t[DllImport(\"" + table.GetDllName(ns) +
|
||||
sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) +
|
||||
"\", CallingConvention=CallingConvention.Cdecl)]");
|
||||
sw.WriteLine("\t\tstatic extern IntPtr " + cname + isig);
|
||||
sw.WriteLine();
|
||||
|
@ -104,7 +104,7 @@ namespace GtkSharp.Generation {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected bool GenField (XmlElement field, SymbolTable table, StreamWriter sw)
|
||||
protected bool GenField (XmlElement field, StreamWriter sw)
|
||||
{
|
||||
String c_type;
|
||||
|
||||
|
@ -115,7 +115,7 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
char[] ast = {'*'};
|
||||
c_type = c_type.TrimEnd(ast);
|
||||
String cs_type = table.GetCSType(c_type);
|
||||
String cs_type = SymbolTable.GetCSType(c_type);
|
||||
|
||||
if (cs_type == "") {
|
||||
Console.WriteLine ("Field has unknown Type {0}", c_type);
|
||||
|
@ -131,7 +131,7 @@ namespace GtkSharp.Generation {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected bool GenMethod(XmlElement method, SymbolTable table, StreamWriter sw)
|
||||
protected bool GenMethod(XmlElement method, StreamWriter sw)
|
||||
{
|
||||
String sig, isig, call, sigtypes;
|
||||
XmlElement parms = method["parameters"];
|
||||
|
@ -141,9 +141,9 @@ namespace GtkSharp.Generation {
|
|||
sig = "()";
|
||||
isig = "(IntPtr raw);";
|
||||
sigtypes = "";
|
||||
} else if (GetSignature(parms, table, out sig, out sigtypes) &&
|
||||
GetImportSig(parms, table, out isig) &&
|
||||
GetCallString(parms, table, out call)) {
|
||||
} else if (GetSignature(parms, out sig, out sigtypes) &&
|
||||
GetImportSig(parms, out isig) &&
|
||||
GetCallString(parms, out call)) {
|
||||
sig = "(" + sig + ")";
|
||||
isig = "(IntPtr raw, " + isig + ");";
|
||||
call = "(Handle, " + call + ")";
|
||||
|
@ -162,8 +162,8 @@ namespace GtkSharp.Generation {
|
|||
|
||||
String rettype = ret_elem.GetAttribute("type");
|
||||
|
||||
String m_ret = table.GetMarshalType(rettype);
|
||||
String s_ret = table.GetCSType(rettype);
|
||||
String m_ret = SymbolTable.GetMarshalType(rettype);
|
||||
String s_ret = SymbolTable.GetCSType(rettype);
|
||||
if (m_ret == "" || s_ret == "") {
|
||||
Console.Write("rettype: " + rettype + " method ");
|
||||
Statistics.ThrottledCount++;
|
||||
|
@ -178,7 +178,7 @@ namespace GtkSharp.Generation {
|
|||
return true;
|
||||
}
|
||||
|
||||
sw.WriteLine("\t\t[DllImport(\"" + table.GetDllName(ns) +
|
||||
sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) +
|
||||
"\", CallingConvention=CallingConvention.Cdecl)]");
|
||||
sw.Write("\t\tstatic extern " + m_ret + " " + cname + isig);
|
||||
sw.WriteLine();
|
||||
|
@ -189,7 +189,7 @@ namespace GtkSharp.Generation {
|
|||
if (m_ret == "void") {
|
||||
sw.WriteLine(cname + call + ";");
|
||||
} else {
|
||||
sw.WriteLine("return " + table.FromNative(rettype, cname + call) + ";");
|
||||
sw.WriteLine("return " + SymbolTable.FromNative(rettype, cname + call) + ";");
|
||||
}
|
||||
|
||||
sw.WriteLine("\t\t}");
|
||||
|
@ -199,7 +199,7 @@ namespace GtkSharp.Generation {
|
|||
return true;
|
||||
}
|
||||
|
||||
private bool GetCallString(XmlElement parms, SymbolTable table, out String call)
|
||||
private bool GetCallString(XmlElement parms, out String call)
|
||||
{
|
||||
call = "";
|
||||
|
||||
|
@ -215,7 +215,7 @@ namespace GtkSharp.Generation {
|
|||
String type = elem.GetAttribute("type");
|
||||
String name = elem.GetAttribute("name");
|
||||
name = MangleName(name);
|
||||
String call_parm = table.CallByName(type, name);
|
||||
String call_parm = SymbolTable.CallByName(type, name);
|
||||
|
||||
if (call_parm == "") {
|
||||
Console.Write("Name: " + name + " Type: " + type + " ");
|
||||
|
@ -233,7 +233,7 @@ namespace GtkSharp.Generation {
|
|||
return true;
|
||||
}
|
||||
|
||||
private bool GetImportSig(XmlElement parms, SymbolTable table, out String isig)
|
||||
private bool GetImportSig(XmlElement parms, out String isig)
|
||||
{
|
||||
isig = "";
|
||||
|
||||
|
@ -246,7 +246,7 @@ namespace GtkSharp.Generation {
|
|||
|
||||
XmlElement elem = (XmlElement) parm;
|
||||
String type = elem.GetAttribute("type");
|
||||
String m_type = table.GetMarshalType(type);
|
||||
String m_type = SymbolTable.GetMarshalType(type);
|
||||
String name = elem.GetAttribute("name");
|
||||
name = MangleName(name);
|
||||
|
||||
|
@ -270,7 +270,7 @@ namespace GtkSharp.Generation {
|
|||
return true;
|
||||
}
|
||||
|
||||
private bool GetSignature(XmlElement parms, SymbolTable table, out String sig, out String sigtypes)
|
||||
private bool GetSignature(XmlElement parms, out String sig, out String sigtypes)
|
||||
{
|
||||
sigtypes = sig = "";
|
||||
bool need_comma = false;
|
||||
|
@ -282,7 +282,7 @@ namespace GtkSharp.Generation {
|
|||
|
||||
XmlElement elem = (XmlElement) parm;
|
||||
String type = elem.GetAttribute("type");
|
||||
String cs_type = table.GetCSType(type);
|
||||
String cs_type = SymbolTable.GetCSType(type);
|
||||
String name = elem.GetAttribute("name");
|
||||
name = MangleName(name);
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace GtkSharp.Generation {
|
|||
return var;
|
||||
}
|
||||
|
||||
public void Generate (SymbolTable table)
|
||||
public void Generate ()
|
||||
{
|
||||
char sep = Path.DirectorySeparatorChar;
|
||||
string dir = ".." + sep + ns.ToLower() + sep + "generated";
|
||||
|
@ -66,7 +66,7 @@ namespace GtkSharp.Generation {
|
|||
switch (node.Name) {
|
||||
case "field":
|
||||
Statistics.IgnoreCount++;
|
||||
// GenField(member, table, sw);
|
||||
// GenField(member, sw);
|
||||
break;
|
||||
|
||||
case "callback":
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
//
|
||||
// (c) 2001 Mike Kestner
|
||||
// (c) 2001-2002 Mike Kestner
|
||||
|
||||
namespace GtkSharp.Generation {
|
||||
|
||||
|
@ -11,11 +11,11 @@ namespace GtkSharp.Generation {
|
|||
|
||||
public class SymbolTable {
|
||||
|
||||
private Hashtable complex_types = new Hashtable ();
|
||||
private Hashtable simple_types;
|
||||
private Hashtable dlls;
|
||||
private static Hashtable complex_types = new Hashtable ();
|
||||
private static Hashtable simple_types;
|
||||
private static Hashtable dlls;
|
||||
|
||||
public SymbolTable ()
|
||||
static SymbolTable ()
|
||||
{
|
||||
simple_types = new Hashtable ();
|
||||
simple_types.Add ("void", "void");
|
||||
|
@ -72,32 +72,32 @@ namespace GtkSharp.Generation {
|
|||
dlls.Add("Gtk", "gtk-x11-2.0");
|
||||
}
|
||||
|
||||
public void AddType (IGeneratable gen)
|
||||
public static void AddType (IGeneratable gen)
|
||||
{
|
||||
complex_types [gen.CName] = gen;
|
||||
}
|
||||
|
||||
public int Count {
|
||||
public static int Count {
|
||||
get
|
||||
{
|
||||
return complex_types.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable Generatables {
|
||||
public static IEnumerable Generatables {
|
||||
get {
|
||||
return complex_types.Values;
|
||||
}
|
||||
}
|
||||
|
||||
private string Trim(string type)
|
||||
private static string Trim(string type)
|
||||
{
|
||||
string trim_type = type.TrimEnd('*');
|
||||
if (trim_type.StartsWith("const-")) return trim_type.Substring(6);
|
||||
return trim_type;
|
||||
}
|
||||
|
||||
public string FromNative(string c_type, string val)
|
||||
public static string FromNative(string c_type, string val)
|
||||
{
|
||||
c_type = Trim(c_type);
|
||||
if (simple_types.ContainsKey(c_type)) {
|
||||
|
@ -110,7 +110,7 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
public string GetCSType(string c_type)
|
||||
public static string GetCSType(string c_type)
|
||||
{
|
||||
c_type = Trim(c_type);
|
||||
if (simple_types.ContainsKey(c_type)) {
|
||||
|
@ -123,7 +123,7 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
public string GetName(string c_type)
|
||||
public static string GetName(string c_type)
|
||||
{
|
||||
c_type = Trim(c_type);
|
||||
if (simple_types.ContainsKey(c_type)) {
|
||||
|
@ -142,12 +142,12 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
public string GetDllName(string ns)
|
||||
public static string GetDllName(string ns)
|
||||
{
|
||||
return (string) dlls[ns];
|
||||
}
|
||||
|
||||
public string GetMarshalType(string c_type)
|
||||
public static string GetMarshalType(string c_type)
|
||||
{
|
||||
c_type = Trim(c_type);
|
||||
if (simple_types.ContainsKey(c_type)) {
|
||||
|
@ -160,7 +160,7 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
public string CallByName(string c_type, string var_name)
|
||||
public static string CallByName(string c_type, string var_name)
|
||||
{
|
||||
c_type = Trim(c_type);
|
||||
if (simple_types.ContainsKey(c_type)) {
|
||||
|
@ -173,7 +173,7 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsBoxed(string c_type)
|
||||
public static bool IsBoxed(string c_type)
|
||||
{
|
||||
c_type = Trim(c_type);
|
||||
if (complex_types.ContainsKey(c_type)) {
|
||||
|
@ -185,7 +185,7 @@ namespace GtkSharp.Generation {
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool IsEnum(string c_type)
|
||||
public static bool IsEnum(string c_type)
|
||||
{
|
||||
c_type = Trim(c_type);
|
||||
if (complex_types.ContainsKey(c_type)) {
|
||||
|
@ -197,7 +197,7 @@ namespace GtkSharp.Generation {
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool IsInterface(string c_type)
|
||||
public static bool IsInterface(string c_type)
|
||||
{
|
||||
c_type = Trim(c_type);
|
||||
if (complex_types.ContainsKey(c_type)) {
|
||||
|
@ -209,7 +209,16 @@ namespace GtkSharp.Generation {
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool IsObject(string c_type)
|
||||
public static ObjectGen GetObjectGen(string c_type)
|
||||
{
|
||||
c_type = Trim(c_type);
|
||||
if (IsObject(c_type)) {
|
||||
return (ObjectGen) complex_types[c_type];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool IsObject(string c_type)
|
||||
{
|
||||
c_type = Trim(c_type);
|
||||
if (complex_types.ContainsKey(c_type)) {
|
||||
|
|
Loading…
Reference in a new issue