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;
|
2002-02-03 03:44:10 +00:00
|
|
|
using System.Collections;
|
2002-01-05 12:45:55 +00:00
|
|
|
using System.IO;
|
2002-02-03 03:44:10 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2002-01-05 12:45:55 +00:00
|
|
|
using System.Xml;
|
|
|
|
|
2002-06-21 20:25:43 +00:00
|
|
|
public class StructBase : ClassBase {
|
2002-07-30 23:02:12 +00:00
|
|
|
|
|
|
|
ArrayList fields = new ArrayList ();
|
|
|
|
uint bitfields;
|
|
|
|
|
|
|
|
public StructBase (XmlElement ns, XmlElement elem) : base (ns, elem)
|
|
|
|
{
|
|
|
|
hasDefaultConstructor = false;
|
|
|
|
|
|
|
|
foreach (XmlNode node in elem.ChildNodes) {
|
|
|
|
|
|
|
|
if (!(node is XmlElement)) continue;
|
|
|
|
XmlElement member = (XmlElement) node;
|
|
|
|
|
|
|
|
switch (node.Name) {
|
|
|
|
case "field":
|
|
|
|
fields.Add (member);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "callback":
|
|
|
|
Statistics.IgnoreCount++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!IsNodeNameHandled (node.Name))
|
|
|
|
Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2002-07-26 06:08:52 +00:00
|
|
|
public override String MarshalType {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return "ref " + QualifiedName;
|
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
|
|
|
}
|
2002-07-26 06:08:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override String MarshalReturnType {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return "IntPtr";
|
2002-02-03 03:44:10 +00:00
|
|
|
}
|
2002-07-26 06:08:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override String CallByName (String var_name)
|
|
|
|
{
|
|
|
|
return "ref " + var_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override String CallByName ()
|
|
|
|
{
|
|
|
|
return "ref this";
|
|
|
|
}
|
|
|
|
|
2002-07-30 23:02:12 +00:00
|
|
|
public override String AssignToName {
|
|
|
|
get { return "raw"; }
|
|
|
|
}
|
|
|
|
|
2002-07-26 06:08:52 +00:00
|
|
|
public override String FromNative(String var)
|
|
|
|
{
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override String FromNativeReturn(String var)
|
|
|
|
{
|
2002-07-30 23:02:12 +00:00
|
|
|
return QualifiedName + ".New (" + var + ")";
|
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
|
|
|
}
|
|
|
|
|
2002-07-30 23:02:12 +00:00
|
|
|
bool IsBit (XmlElement field)
|
2002-01-05 12:45:55 +00:00
|
|
|
{
|
2002-07-30 23:02:12 +00:00
|
|
|
return (field.HasAttribute("bits") && (field.GetAttribute("bits") == "1"));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsPointer (XmlElement field)
|
|
|
|
{
|
|
|
|
string c_type = field.GetAttribute("type");
|
|
|
|
return (c_type[c_type.Length - 1] == '*');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void GenFields (StreamWriter sw)
|
|
|
|
{
|
|
|
|
bitfields = 0;
|
|
|
|
bool need_field = true;
|
|
|
|
foreach (XmlElement field in fields) {
|
|
|
|
if (IsBit (field)) {
|
|
|
|
if (need_field)
|
|
|
|
need_field = false;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
need_field = true;
|
|
|
|
GenField (field, sw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-02 22:35:23 +00:00
|
|
|
protected bool GetFieldInfo (XmlElement field, out string c_type, out string type, out string name)
|
2002-07-30 23:02:12 +00:00
|
|
|
{
|
|
|
|
name = "";
|
2002-08-02 22:35:23 +00:00
|
|
|
c_type = field.GetAttribute ("type");
|
2002-07-31 19:18:37 +00:00
|
|
|
type = SymbolTable.GetCSType (c_type);
|
|
|
|
if (IsBit (field)) {
|
2002-07-30 23:02:12 +00:00
|
|
|
type = "uint";
|
2002-09-08 01:29:07 +00:00
|
|
|
} else if ((IsPointer (field) || SymbolTable.IsOpaque (c_type)) && type != "string") {
|
2002-07-30 23:02:12 +00:00
|
|
|
type = "IntPtr";
|
|
|
|
name = "_";
|
2002-07-31 19:18:37 +00:00
|
|
|
} else if (SymbolTable.IsCallback (c_type)) {
|
|
|
|
type = "IntPtr";
|
2002-01-06 13:33:25 +00:00
|
|
|
} else {
|
2002-07-30 23:02:12 +00:00
|
|
|
if (type == "") {
|
|
|
|
Console.WriteLine ("Field has unknown Type {0}", c_type);
|
|
|
|
Statistics.ThrottledCount++;
|
|
|
|
return false;
|
|
|
|
}
|
2002-01-06 13:33:25 +00:00
|
|
|
}
|
|
|
|
|
2002-08-03 22:24:37 +00:00
|
|
|
// FIXME: marshalling not implemented here in mono
|
2002-07-30 23:02:12 +00:00
|
|
|
if (field.HasAttribute("array_len"))
|
2002-08-03 22:24:37 +00:00
|
|
|
type = "IntPtr";
|
2002-07-30 23:02:12 +00:00
|
|
|
|
|
|
|
if (IsBit (field))
|
|
|
|
name = String.Format ("_bitfield{0}", bitfields++);
|
|
|
|
else
|
|
|
|
name += MangleName (field.GetAttribute ("cname"));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected bool GenField (XmlElement field, StreamWriter sw)
|
|
|
|
{
|
2002-08-02 22:35:23 +00:00
|
|
|
string c_type, type, name;
|
|
|
|
if (!GetFieldInfo (field, out c_type, out type, out name))
|
2002-01-10 15:01:31 +00:00
|
|
|
return false;
|
2002-07-30 23:02:12 +00:00
|
|
|
sw.WriteLine ("\t\tpublic {0} {1};", type, name);
|
2002-08-02 22:35:23 +00:00
|
|
|
|
|
|
|
if (field.HasAttribute("array_len"))
|
|
|
|
Console.WriteLine ("warning: array field {0}.{1} probably incorrectly generated", QualifiedName, name);
|
|
|
|
|
|
|
|
string wrapped = SymbolTable.GetCSType (c_type);
|
|
|
|
string wrapped_name = MangleName (field.GetAttribute ("cname"));
|
2002-09-12 05:21:16 +00:00
|
|
|
if (SymbolTable.IsObject (c_type)) {
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {");
|
|
|
|
sw.WriteLine ("\t\t\tget { ");
|
|
|
|
sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + SymbolTable.FromNativeReturn(c_type, name) + ";");
|
|
|
|
sw.WriteLine ("\t\t\t\tret.Ref ();");
|
|
|
|
sw.WriteLine ("\t\t\t\treturn ret;");
|
|
|
|
sw.WriteLine ("\t\t\t}");
|
|
|
|
sw.WriteLine ("\t\t\tset { " + name + " = " + SymbolTable.CallByName (c_type, "value") + "; }");
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
} else if (SymbolTable.IsOpaque (c_type)) {
|
2002-08-02 22:35:23 +00:00
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {");
|
|
|
|
sw.WriteLine ("\t\t\tget { ");
|
|
|
|
sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + SymbolTable.FromNativeReturn(c_type, name) + ";");
|
|
|
|
sw.WriteLine ("\t\t\t\tif (ret == null) ret = new " + wrapped + "(" + name + ");");
|
|
|
|
sw.WriteLine ("\t\t\t\treturn ret;");
|
|
|
|
sw.WriteLine ("\t\t\t}");
|
|
|
|
|
|
|
|
sw.WriteLine ("\t\t\tset { " + name + " = " + SymbolTable.CallByName (c_type, "value") + "; }");
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
} else if (IsPointer (field) && (SymbolTable.IsStruct (c_type) || SymbolTable.IsBoxed (c_type))) {
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {");
|
|
|
|
sw.WriteLine ("\t\t\tget { return " + SymbolTable.FromNativeReturn (c_type, name) + "; }");
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2002-07-26 06:08:52 +00:00
|
|
|
private String MangleName(String name)
|
2002-02-08 23:56:27 +00:00
|
|
|
{
|
2002-07-26 06:08:52 +00:00
|
|
|
if (name == "string") {
|
|
|
|
return "str1ng";
|
|
|
|
} else if (name == "event") {
|
|
|
|
return "evnt";
|
|
|
|
} else if (name == "object") {
|
|
|
|
return "objekt";
|
|
|
|
} else if (name == "in") {
|
|
|
|
return "inn";
|
2002-02-08 23:56:27 +00:00
|
|
|
} else {
|
2002-07-26 06:08:52 +00:00
|
|
|
return name;
|
2002-02-08 23:56:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-26 06:08:52 +00:00
|
|
|
public virtual void Generate ()
|
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
|
|
|
{
|
2002-07-26 06:08:52 +00:00
|
|
|
StreamWriter sw = CreateWriter ();
|
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
|
|
|
|
2002-07-26 06:08:52 +00:00
|
|
|
sw.WriteLine ("\tusing System;");
|
|
|
|
sw.WriteLine ("\tusing System.Collections;");
|
|
|
|
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
|
|
|
|
sw.WriteLine ();
|
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
|
|
|
|
2002-07-26 06:08:52 +00:00
|
|
|
sw.WriteLine("\t\t/// <summary> " + Name + " Struct </summary>");
|
|
|
|
sw.WriteLine("\t\t/// <remarks>");
|
|
|
|
sw.WriteLine("\t\t/// </remarks>");
|
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
|
|
|
|
2002-07-26 06:08:52 +00:00
|
|
|
sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
|
|
|
|
sw.WriteLine ("\tpublic struct " + Name + " {");
|
|
|
|
sw.WriteLine ();
|
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
|
|
|
|
2002-07-30 23:02:12 +00:00
|
|
|
GenFields (sw);
|
|
|
|
sw.WriteLine ();
|
2002-07-26 06:08:52 +00:00
|
|
|
GenCtors (sw);
|
2002-07-30 23:02:12 +00:00
|
|
|
GenMethods (sw, null, null, true);
|
2002-07-26 06:08:52 +00:00
|
|
|
AppendCustom(sw);
|
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
|
|
|
|
2002-07-26 06:08:52 +00:00
|
|
|
sw.WriteLine ("\t}");
|
|
|
|
CloseWriter (sw);
|
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
|
|
|
}
|
2002-02-03 03:44:10 +00:00
|
|
|
|
2002-07-26 06:08:52 +00:00
|
|
|
protected override void GenCtors (StreamWriter sw)
|
2002-02-03 03:44:10 +00:00
|
|
|
{
|
2002-07-30 23:02:12 +00:00
|
|
|
sw.WriteLine ("\t\tbool _is_null;");
|
|
|
|
sw.WriteLine ("\t\tpublic bool IsNull {");
|
|
|
|
sw.WriteLine ("\t\t\tget { return _is_null; }");
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ("\t\tpublic void _Initialize () {");
|
|
|
|
sw.WriteLine ("\t\t\t_is_null = false;");
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine();
|
|
|
|
sw.WriteLine ("\t\tpublic static " + QualifiedName + " New(IntPtr raw) {");
|
|
|
|
sw.WriteLine ("\t\t\t{0} self = new {0}();", QualifiedName);
|
|
|
|
sw.WriteLine ("\t\t\tif (raw == IntPtr.Zero) {");
|
|
|
|
sw.WriteLine ("\t\t\t\tself._is_null = true;");
|
|
|
|
sw.WriteLine ("\t\t\t} else {");
|
|
|
|
sw.WriteLine ("\t\t\t\tself = ({0}) Marshal.PtrToStructure (raw, self.GetType ());", QualifiedName);
|
|
|
|
sw.WriteLine ("\t\t\t\tself._is_null = false;");
|
|
|
|
sw.WriteLine ("\t\t\t}");
|
|
|
|
sw.WriteLine ("\t\t\treturn self;");
|
|
|
|
sw.WriteLine ("\t\t}");
|
2002-07-26 06:08:52 +00:00
|
|
|
sw.WriteLine();
|
2002-07-30 23:02:12 +00:00
|
|
|
|
|
|
|
foreach (Ctor ctor in Ctors) {
|
|
|
|
ctor.ForceStatic = true;
|
|
|
|
}
|
|
|
|
base.GenCtors (sw);
|
2002-02-03 03:44:10 +00:00
|
|
|
}
|
2002-07-26 06:08:52 +00:00
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|