2002-01-05 12:45:55 +00:00
|
|
|
// GtkSharp.Generation.StructBase.cs - The Structure/Object Base Class.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2001 Mike Kestner
|
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
public class StructBase {
|
|
|
|
|
|
|
|
protected String ns;
|
|
|
|
protected XmlElement elem;
|
|
|
|
|
|
|
|
public StructBase (String ns, XmlElement elem) {
|
|
|
|
|
|
|
|
this.ns = ns;
|
|
|
|
this.elem = elem;
|
|
|
|
}
|
2002-01-17 Mike Kestner <mkestner@speakeasy.net>
* generator/BoxedGen.cs : Removed Name, CName, and QualifiedName.
* generator/ObjectGen.cs : Removed Name, CName, and QualifiedName.
* generator/StructBase.cs : Add Name, CName, and QualifiedName. Add
GenCtor method. Stub GetCallString, GetImportSig, and GetSignature
methods.
* generator/StructGen.cs : Removed Name, CName, and QualifiedName.
* generator/SymbolTable.cs : Add GetDllName method.
* parser/gapi2xml.pl : Fix a couple <parameters> bugs.
svn path=/trunk/gtk-sharp/; revision=2030
2002-01-17 23:44:56 +00:00
|
|
|
|
|
|
|
public String Name {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return elem.GetAttribute("name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String QualifiedName {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return ns + "." + elem.GetAttribute("name");
|
|
|
|
}
|
|
|
|
}
|
2002-01-05 12:45:55 +00:00
|
|
|
|
2002-01-17 Mike Kestner <mkestner@speakeasy.net>
* generator/BoxedGen.cs : Removed Name, CName, and QualifiedName.
* generator/ObjectGen.cs : Removed Name, CName, and QualifiedName.
* generator/StructBase.cs : Add Name, CName, and QualifiedName. Add
GenCtor method. Stub GetCallString, GetImportSig, and GetSignature
methods.
* generator/StructGen.cs : Removed Name, CName, and QualifiedName.
* generator/SymbolTable.cs : Add GetDllName method.
* parser/gapi2xml.pl : Fix a couple <parameters> bugs.
svn path=/trunk/gtk-sharp/; revision=2030
2002-01-17 23:44:56 +00:00
|
|
|
public String CName {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return elem.GetAttribute("cname");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected bool GenCtor(XmlElement ctor, SymbolTable table, StreamWriter sw)
|
|
|
|
{
|
|
|
|
String sig, isig, call;
|
|
|
|
XmlElement parms = ctor["parameters"];
|
|
|
|
|
|
|
|
if (parms == null) {
|
|
|
|
sig = "()";
|
|
|
|
isig = call = "();";
|
|
|
|
//} else if (!GetSignature(parms, table, out sig) ||
|
|
|
|
// !GetImportSig(parms, table, out isig) ||
|
|
|
|
// !GetCallString(parms, table, out call)) {
|
|
|
|
// Console.Write("ctor ");
|
|
|
|
// return false;
|
|
|
|
} else {
|
|
|
|
Console.Write("ctor with parms ");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
String cname = ctor.GetAttribute("cname");
|
|
|
|
|
|
|
|
sw.WriteLine("\t\t[DllImport(\"" + table.GetDllName(ns) +
|
|
|
|
"\", CallingConvention=CallingConvention.Cdecl)]");
|
|
|
|
sw.WriteLine("\t\tstatic extern IntPtr " + cname + isig);
|
|
|
|
sw.WriteLine();
|
|
|
|
sw.WriteLine("\t\tpublic " + Name + sig);
|
|
|
|
sw.WriteLine("\t\t{");
|
|
|
|
sw.WriteLine("\t\t\tRawObject = " + cname + call);
|
|
|
|
sw.WriteLine("\t\t}");
|
|
|
|
sw.WriteLine();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-01-10 15:01:31 +00:00
|
|
|
protected bool GenField (XmlElement field, SymbolTable table, StreamWriter sw)
|
2002-01-05 12:45:55 +00:00
|
|
|
{
|
2002-01-06 13:33:25 +00:00
|
|
|
String c_type;
|
|
|
|
|
|
|
|
if (field.HasAttribute("bits") && (field.GetAttribute("bits") == "1")) {
|
|
|
|
c_type = "gboolean";
|
|
|
|
} else {
|
|
|
|
c_type = field.GetAttribute("type");
|
|
|
|
}
|
|
|
|
char[] ast = {'*'};
|
|
|
|
c_type = c_type.TrimEnd(ast);
|
|
|
|
String cs_type = table.GetCSType(c_type);
|
|
|
|
|
|
|
|
if (cs_type == "") {
|
2002-01-10 15:01:31 +00:00
|
|
|
Console.WriteLine ("Field has unknown Type {0}", c_type);
|
|
|
|
return false;
|
2002-01-06 13:33:25 +00:00
|
|
|
}
|
|
|
|
|
2002-01-08 20:30:29 +00:00
|
|
|
sw.Write ("\t\t public " + cs_type);
|
2002-01-06 13:33:25 +00:00
|
|
|
if (field.HasAttribute("array_len")) {
|
|
|
|
sw.Write ("[]");
|
|
|
|
}
|
|
|
|
sw.WriteLine (" " + field.GetAttribute("cname") + ";");
|
2002-01-10 15:01:31 +00:00
|
|
|
return true;
|
2002-01-05 12:45:55 +00:00
|
|
|
}
|
2002-01-17 Mike Kestner <mkestner@speakeasy.net>
* generator/BoxedGen.cs : Removed Name, CName, and QualifiedName.
* generator/ObjectGen.cs : Removed Name, CName, and QualifiedName.
* generator/StructBase.cs : Add Name, CName, and QualifiedName. Add
GenCtor method. Stub GetCallString, GetImportSig, and GetSignature
methods.
* generator/StructGen.cs : Removed Name, CName, and QualifiedName.
* generator/SymbolTable.cs : Add GetDllName method.
* parser/gapi2xml.pl : Fix a couple <parameters> bugs.
svn path=/trunk/gtk-sharp/; revision=2030
2002-01-17 23:44:56 +00:00
|
|
|
|
|
|
|
private bool GetCallString(XmlElement parms, SymbolTable table, out String call)
|
|
|
|
{
|
|
|
|
call = "(";
|
|
|
|
|
|
|
|
foreach (XmlNode parm in parms.ChildNodes) {
|
|
|
|
if (parm.Name != "parameter") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlElement elem = (XmlElement) parm;
|
|
|
|
}
|
|
|
|
|
|
|
|
call += ");";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool GetImportSig(XmlElement parms, SymbolTable table, out String isig)
|
|
|
|
{
|
|
|
|
isig = "(";
|
|
|
|
|
|
|
|
foreach (XmlNode parm in parms.ChildNodes) {
|
|
|
|
if (parm.Name != "namespace") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlElement elem = (XmlElement) parm;
|
|
|
|
}
|
|
|
|
|
|
|
|
isig += ");";
|
|
|
|
return true;
|
|
|
|
}
|
2002-01-05 12:45:55 +00:00
|
|
|
|
2002-01-17 Mike Kestner <mkestner@speakeasy.net>
* generator/BoxedGen.cs : Removed Name, CName, and QualifiedName.
* generator/ObjectGen.cs : Removed Name, CName, and QualifiedName.
* generator/StructBase.cs : Add Name, CName, and QualifiedName. Add
GenCtor method. Stub GetCallString, GetImportSig, and GetSignature
methods.
* generator/StructGen.cs : Removed Name, CName, and QualifiedName.
* generator/SymbolTable.cs : Add GetDllName method.
* parser/gapi2xml.pl : Fix a couple <parameters> bugs.
svn path=/trunk/gtk-sharp/; revision=2030
2002-01-17 23:44:56 +00:00
|
|
|
private bool GetSignature(XmlElement parms, SymbolTable table, out String sig)
|
|
|
|
{
|
|
|
|
sig = "(";
|
|
|
|
|
|
|
|
foreach (XmlNode parm in parms.ChildNodes) {
|
|
|
|
if (parm.Name != "parameter") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlElement elem = (XmlElement) parm;
|
|
|
|
}
|
|
|
|
|
|
|
|
sig += ")";
|
|
|
|
return true;
|
|
|
|
}
|
2002-01-05 12:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|