2005-02-23 17:37:33 +00:00
|
|
|
// GtkSharp.Generation.StructBase.cs - The Structure/Boxed Base Class.
|
2002-11-10 10:03:51 +00:00
|
|
|
//
|
2013-10-08 14:27:47 +00:00
|
|
|
// Authors:
|
|
|
|
// Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
// Stephan Sundermann <stephansundermann@gmail.com>
|
2002-11-10 10:03:51 +00:00
|
|
|
//
|
2004-06-25 16:35:15 +00:00
|
|
|
// Copyright (c) 2001-2003 Mike Kestner
|
2013-10-08 14:27:47 +00:00
|
|
|
// Copyright (c) 2013 Stephan Sundermann
|
2004-06-25 16:35:15 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of version 2 of the GNU General Public
|
|
|
|
// License as published by the Free Software Foundation.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public
|
|
|
|
// License along with this program; if not, write to the
|
|
|
|
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
// Boston, MA 02111-1307, USA.
|
|
|
|
|
2002-11-10 10:03:51 +00:00
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
2012-11-04 15:19:05 +00:00
|
|
|
using System.Collections.Generic;
|
2002-11-10 10:03:51 +00:00
|
|
|
using System.IO;
|
2011-10-08 02:55:26 +00:00
|
|
|
using System.Text;
|
2002-11-10 10:03:51 +00:00
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Xml;
|
|
|
|
|
2007-08-13 14:29:06 +00:00
|
|
|
public abstract class StructBase : ClassBase, IManualMarshaler {
|
2002-11-10 10:03:51 +00:00
|
|
|
|
2012-11-04 16:26:26 +00:00
|
|
|
IList<StructField> fields = new List<StructField> ();
|
2007-08-13 14:29:06 +00:00
|
|
|
bool need_read_native = false;
|
2002-11-10 10:03:51 +00:00
|
|
|
|
2004-12-26 19:33:34 +00:00
|
|
|
protected StructBase (XmlElement ns, XmlElement elem) : base (ns, elem)
|
2002-11-10 10:03:51 +00:00
|
|
|
{
|
|
|
|
foreach (XmlNode node in elem.ChildNodes) {
|
|
|
|
|
|
|
|
if (!(node is XmlElement)) continue;
|
|
|
|
XmlElement member = (XmlElement) node;
|
|
|
|
|
|
|
|
switch (node.Name) {
|
|
|
|
case "field":
|
2005-05-02 18:40:30 +00:00
|
|
|
fields.Add (new StructField (member, this));
|
2002-11-10 10:03:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "callback":
|
|
|
|
Statistics.IgnoreCount++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!IsNodeNameHandled (node.Name))
|
|
|
|
Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-21 16:37:04 +00:00
|
|
|
public override string DefaultValue {
|
|
|
|
get {
|
|
|
|
return QualifiedName + ".Zero";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-19 05:30:05 +00:00
|
|
|
public override string MarshalType {
|
2007-04-20 15:38:47 +00:00
|
|
|
get {
|
|
|
|
return "IntPtr";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-13 14:29:06 +00:00
|
|
|
public override string AssignToName {
|
|
|
|
get { throw new NotImplementedException (); }
|
2002-11-10 10:03:51 +00:00
|
|
|
}
|
|
|
|
|
2004-01-19 05:30:05 +00:00
|
|
|
public override string CallByName ()
|
2002-11-10 10:03:51 +00:00
|
|
|
{
|
2007-08-13 14:29:06 +00:00
|
|
|
return "this_as_native";
|
2002-11-10 10:03:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-13 14:29:06 +00:00
|
|
|
public override string CallByName (string var)
|
|
|
|
{
|
|
|
|
return var + "_as_native";
|
2002-11-10 10:03:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-13 14:29:06 +00:00
|
|
|
public override string FromNative (string var)
|
2002-11-10 10:03:51 +00:00
|
|
|
{
|
2007-08-13 14:29:06 +00:00
|
|
|
if (DisableNew)
|
|
|
|
return var + " == IntPtr.Zero ? " + QualifiedName + ".Zero : (" + QualifiedName + ") System.Runtime.InteropServices.Marshal.PtrToStructure (" + var + ", typeof (" + QualifiedName + "))";
|
|
|
|
else
|
|
|
|
return QualifiedName + ".New (" + var + ")";
|
2002-11-10 10:03:51 +00:00
|
|
|
}
|
2007-04-20 15:38:47 +00:00
|
|
|
|
2007-08-13 14:29:06 +00:00
|
|
|
public string AllocNative (string var)
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
{
|
2007-08-13 14:29:06 +00:00
|
|
|
return "GLib.Marshaller.StructureToPtrAlloc (" + var + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
public string ReleaseNative (string var)
|
|
|
|
{
|
|
|
|
return "Marshal.FreeHGlobal (" +var + ")";
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
}
|
|
|
|
|
2004-06-02 20:28:42 +00:00
|
|
|
private bool DisableNew {
|
|
|
|
get {
|
2012-10-21 16:10:34 +00:00
|
|
|
return Elem.GetAttributeAsBoolean ("disable_new");
|
2004-06-02 20:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-08 18:22:16 +00:00
|
|
|
public virtual bool Union {
|
|
|
|
get {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-21 16:19:50 +00:00
|
|
|
protected void GenEqualsAndHash (StreamWriter sw)
|
2011-10-08 02:55:26 +00:00
|
|
|
{
|
|
|
|
int bitfields = 0;
|
|
|
|
bool need_field = true;
|
2013-10-08 14:27:47 +00:00
|
|
|
StringBuilder hashcode = new StringBuilder ();
|
|
|
|
StringBuilder equals = new StringBuilder ();
|
2011-10-08 02:55:26 +00:00
|
|
|
|
2013-10-08 14:27:47 +00:00
|
|
|
hashcode.Append ("this.GetType ().FullName.GetHashCode ()");
|
|
|
|
equals.Append ("true");
|
2011-10-08 02:55:26 +00:00
|
|
|
|
|
|
|
foreach (StructField field in fields) {
|
2017-10-03 13:18:08 +00:00
|
|
|
if (field.IsPadding || field.Hidden)
|
2013-05-31 17:38:35 +00:00
|
|
|
continue;
|
2011-10-08 02:55:26 +00:00
|
|
|
if (field.IsBitfield) {
|
|
|
|
if (need_field) {
|
2013-10-08 14:27:47 +00:00
|
|
|
equals.Append (" && _bitfield");
|
|
|
|
equals.Append (bitfields);
|
|
|
|
equals.Append (".Equals (other._bitfield");
|
|
|
|
equals.Append (bitfields);
|
|
|
|
equals.Append (")");
|
|
|
|
hashcode.Append (" ^ ");
|
|
|
|
hashcode.Append ("_bitfield");
|
|
|
|
hashcode.Append (bitfields++);
|
|
|
|
hashcode.Append (".GetHashCode ()");
|
2011-10-08 02:55:26 +00:00
|
|
|
need_field = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
need_field = true;
|
2013-10-08 14:27:47 +00:00
|
|
|
equals.Append (" && ");
|
|
|
|
equals.Append (field.EqualityName);
|
|
|
|
equals.Append (".Equals (other.");
|
|
|
|
equals.Append (field.EqualityName);
|
|
|
|
equals.Append (")");
|
|
|
|
hashcode.Append (" ^ ");
|
|
|
|
hashcode.Append (field.EqualityName);
|
|
|
|
hashcode.Append (".GetHashCode ()");
|
2011-10-08 02:55:26 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-10 14:18:36 +00:00
|
|
|
|
|
|
|
if (!Elem.GetAttributeAsBoolean ("noequals")) {
|
|
|
|
sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
|
|
|
|
sw.WriteLine ("\t\t{");
|
|
|
|
sw.WriteLine ("\t\t\treturn {0};", equals.ToString ());
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
}
|
2011-10-08 02:55:26 +00:00
|
|
|
sw.WriteLine ("\t\tpublic override bool Equals (object other)");
|
|
|
|
sw.WriteLine ("\t\t{");
|
|
|
|
sw.WriteLine ("\t\t\treturn other is {0} && Equals (({0}) other);", Name);
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ();
|
2013-10-10 14:18:36 +00:00
|
|
|
if (Elem.GetAttributeAsBoolean ("nohash"))
|
2011-10-08 02:55:26 +00:00
|
|
|
return;
|
|
|
|
sw.WriteLine ("\t\tpublic override int GetHashCode ()");
|
|
|
|
sw.WriteLine ("\t\t{");
|
2013-10-08 14:27:47 +00:00
|
|
|
sw.WriteLine ("\t\t\treturn {0};", hashcode.ToString ());
|
2011-10-08 02:55:26 +00:00
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
* generator/StructBase.cs: update field-generation logic a bit
* generator/CodeGenerator.cs: add a --glue-includes flag
* generator/GenerationInfo.cs: Accept glue_includes value from
Main and output it to the glue_filename.
* generator/FieldBase.cs (Ignored): handle more ignorable cases.
(CheckGlue): New method to figure out what kind of glue we'll need
for a field.
(GenerateImports): generate appropriate imports per CheckGlue.
(GenerateGlue): Generate C glue for accessing a struct field;
either a fully-C-based accessor, or a method to just return the
field's offset in the struct.
(Generate): Use the generated glue to read the field.
* generator/PropertyBase.cs (CType): if the field is a single bit,
set its type to gboolean.
* generator/ObjectGen.cs (Generate):
* generator/OpaqueGen.cs (Generate): Call GenFields.
* generator/StructField.cs: Use FieldBase's glue-generation code
to handle bitfields. [#54489]
* generator/ObjectField.cs: Generates accessors for public fields
of objects and opaque structs. [#69514]
* generator/ClassBase.cs (ClassBase): Parse <fields> nodes and
create ObjectField objects.
(GenFields): Output field properties
(IgnoreMethod): Ignore Get/Set methods that duplicate fields
* generator/Makefile.am (sources): update
* {gdk,gnome,gtk,pango}/*.metadata: Mark some additional fields as
public. Rename/retype some fields for consistency with earlier
hand-coded bindings.
* {gdk,gnome,gtk,pango}/*.custom: Remove custom methods that can
now be autogenerated.
* {gdk,gnome,gtk,pango}/glue/*.c: Remove glue methods that can now
be autogenerated
* {gdk,glade,gnome,gtk,pango,vte}/Makefile.am
* {gdk,glade,gnome,gtk,pango,vte}/glue/Makefile.am
* {gdk,gnome,gtk,pango}/glue/makefile.win32: Update
svn path=/trunk/gtk-sharp/; revision=44563
2005-05-16 14:28:55 +00:00
|
|
|
protected new void GenFields (GenerationInfo gen_info)
|
2002-11-10 10:03:51 +00:00
|
|
|
{
|
* generator/StructBase.cs: update field-generation logic a bit
* generator/CodeGenerator.cs: add a --glue-includes flag
* generator/GenerationInfo.cs: Accept glue_includes value from
Main and output it to the glue_filename.
* generator/FieldBase.cs (Ignored): handle more ignorable cases.
(CheckGlue): New method to figure out what kind of glue we'll need
for a field.
(GenerateImports): generate appropriate imports per CheckGlue.
(GenerateGlue): Generate C glue for accessing a struct field;
either a fully-C-based accessor, or a method to just return the
field's offset in the struct.
(Generate): Use the generated glue to read the field.
* generator/PropertyBase.cs (CType): if the field is a single bit,
set its type to gboolean.
* generator/ObjectGen.cs (Generate):
* generator/OpaqueGen.cs (Generate): Call GenFields.
* generator/StructField.cs: Use FieldBase's glue-generation code
to handle bitfields. [#54489]
* generator/ObjectField.cs: Generates accessors for public fields
of objects and opaque structs. [#69514]
* generator/ClassBase.cs (ClassBase): Parse <fields> nodes and
create ObjectField objects.
(GenFields): Output field properties
(IgnoreMethod): Ignore Get/Set methods that duplicate fields
* generator/Makefile.am (sources): update
* {gdk,gnome,gtk,pango}/*.metadata: Mark some additional fields as
public. Rename/retype some fields for consistency with earlier
hand-coded bindings.
* {gdk,gnome,gtk,pango}/*.custom: Remove custom methods that can
now be autogenerated.
* {gdk,gnome,gtk,pango}/glue/*.c: Remove glue methods that can now
be autogenerated
* {gdk,glade,gnome,gtk,pango,vte}/Makefile.am
* {gdk,glade,gnome,gtk,pango,vte}/glue/Makefile.am
* {gdk,gnome,gtk,pango}/glue/makefile.win32: Update
svn path=/trunk/gtk-sharp/; revision=44563
2005-05-16 14:28:55 +00:00
|
|
|
int bitfields = 0;
|
2002-11-10 10:03:51 +00:00
|
|
|
bool need_field = true;
|
2013-10-08 18:22:16 +00:00
|
|
|
StreamWriter sw = gen_info.Writer;
|
* generator/StructBase.cs: update field-generation logic a bit
* generator/CodeGenerator.cs: add a --glue-includes flag
* generator/GenerationInfo.cs: Accept glue_includes value from
Main and output it to the glue_filename.
* generator/FieldBase.cs (Ignored): handle more ignorable cases.
(CheckGlue): New method to figure out what kind of glue we'll need
for a field.
(GenerateImports): generate appropriate imports per CheckGlue.
(GenerateGlue): Generate C glue for accessing a struct field;
either a fully-C-based accessor, or a method to just return the
field's offset in the struct.
(Generate): Use the generated glue to read the field.
* generator/PropertyBase.cs (CType): if the field is a single bit,
set its type to gboolean.
* generator/ObjectGen.cs (Generate):
* generator/OpaqueGen.cs (Generate): Call GenFields.
* generator/StructField.cs: Use FieldBase's glue-generation code
to handle bitfields. [#54489]
* generator/ObjectField.cs: Generates accessors for public fields
of objects and opaque structs. [#69514]
* generator/ClassBase.cs (ClassBase): Parse <fields> nodes and
create ObjectField objects.
(GenFields): Output field properties
(IgnoreMethod): Ignore Get/Set methods that duplicate fields
* generator/Makefile.am (sources): update
* {gdk,gnome,gtk,pango}/*.metadata: Mark some additional fields as
public. Rename/retype some fields for consistency with earlier
hand-coded bindings.
* {gdk,gnome,gtk,pango}/*.custom: Remove custom methods that can
now be autogenerated.
* {gdk,gnome,gtk,pango}/glue/*.c: Remove glue methods that can now
be autogenerated
* {gdk,glade,gnome,gtk,pango,vte}/Makefile.am
* {gdk,glade,gnome,gtk,pango,vte}/glue/Makefile.am
* {gdk,gnome,gtk,pango}/glue/makefile.win32: Update
svn path=/trunk/gtk-sharp/; revision=44563
2005-05-16 14:28:55 +00:00
|
|
|
|
2005-05-02 18:40:30 +00:00
|
|
|
foreach (StructField field in fields) {
|
2013-10-08 18:22:16 +00:00
|
|
|
if (Union)
|
|
|
|
sw.WriteLine ("\t\t[FieldOffset(0)]");
|
* generator/StructBase.cs: update field-generation logic a bit
* generator/CodeGenerator.cs: add a --glue-includes flag
* generator/GenerationInfo.cs: Accept glue_includes value from
Main and output it to the glue_filename.
* generator/FieldBase.cs (Ignored): handle more ignorable cases.
(CheckGlue): New method to figure out what kind of glue we'll need
for a field.
(GenerateImports): generate appropriate imports per CheckGlue.
(GenerateGlue): Generate C glue for accessing a struct field;
either a fully-C-based accessor, or a method to just return the
field's offset in the struct.
(Generate): Use the generated glue to read the field.
* generator/PropertyBase.cs (CType): if the field is a single bit,
set its type to gboolean.
* generator/ObjectGen.cs (Generate):
* generator/OpaqueGen.cs (Generate): Call GenFields.
* generator/StructField.cs: Use FieldBase's glue-generation code
to handle bitfields. [#54489]
* generator/ObjectField.cs: Generates accessors for public fields
of objects and opaque structs. [#69514]
* generator/ClassBase.cs (ClassBase): Parse <fields> nodes and
create ObjectField objects.
(GenFields): Output field properties
(IgnoreMethod): Ignore Get/Set methods that duplicate fields
* generator/Makefile.am (sources): update
* {gdk,gnome,gtk,pango}/*.metadata: Mark some additional fields as
public. Rename/retype some fields for consistency with earlier
hand-coded bindings.
* {gdk,gnome,gtk,pango}/*.custom: Remove custom methods that can
now be autogenerated.
* {gdk,gnome,gtk,pango}/glue/*.c: Remove glue methods that can now
be autogenerated
* {gdk,glade,gnome,gtk,pango,vte}/Makefile.am
* {gdk,glade,gnome,gtk,pango,vte}/glue/Makefile.am
* {gdk,gnome,gtk,pango}/glue/makefile.win32: Update
svn path=/trunk/gtk-sharp/; revision=44563
2005-05-16 14:28:55 +00:00
|
|
|
if (field.IsBitfield) {
|
|
|
|
if (need_field) {
|
|
|
|
sw.WriteLine ("\t\tprivate uint _bitfield{0};\n", bitfields++);
|
2002-11-10 10:03:51 +00:00
|
|
|
need_field = false;
|
* generator/StructBase.cs: update field-generation logic a bit
* generator/CodeGenerator.cs: add a --glue-includes flag
* generator/GenerationInfo.cs: Accept glue_includes value from
Main and output it to the glue_filename.
* generator/FieldBase.cs (Ignored): handle more ignorable cases.
(CheckGlue): New method to figure out what kind of glue we'll need
for a field.
(GenerateImports): generate appropriate imports per CheckGlue.
(GenerateGlue): Generate C glue for accessing a struct field;
either a fully-C-based accessor, or a method to just return the
field's offset in the struct.
(Generate): Use the generated glue to read the field.
* generator/PropertyBase.cs (CType): if the field is a single bit,
set its type to gboolean.
* generator/ObjectGen.cs (Generate):
* generator/OpaqueGen.cs (Generate): Call GenFields.
* generator/StructField.cs: Use FieldBase's glue-generation code
to handle bitfields. [#54489]
* generator/ObjectField.cs: Generates accessors for public fields
of objects and opaque structs. [#69514]
* generator/ClassBase.cs (ClassBase): Parse <fields> nodes and
create ObjectField objects.
(GenFields): Output field properties
(IgnoreMethod): Ignore Get/Set methods that duplicate fields
* generator/Makefile.am (sources): update
* {gdk,gnome,gtk,pango}/*.metadata: Mark some additional fields as
public. Rename/retype some fields for consistency with earlier
hand-coded bindings.
* {gdk,gnome,gtk,pango}/*.custom: Remove custom methods that can
now be autogenerated.
* {gdk,gnome,gtk,pango}/glue/*.c: Remove glue methods that can now
be autogenerated
* {gdk,glade,gnome,gtk,pango,vte}/Makefile.am
* {gdk,glade,gnome,gtk,pango,vte}/glue/Makefile.am
* {gdk,gnome,gtk,pango}/glue/makefile.win32: Update
svn path=/trunk/gtk-sharp/; revision=44563
2005-05-16 14:28:55 +00:00
|
|
|
}
|
2002-11-10 10:03:51 +00:00
|
|
|
} else
|
|
|
|
need_field = true;
|
2005-05-02 18:40:30 +00:00
|
|
|
field.Generate (gen_info, "\t\t");
|
2002-11-10 10:03:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-05 20:34:45 +00:00
|
|
|
public override bool Validate ()
|
2005-02-23 17:37:33 +00:00
|
|
|
{
|
2011-02-20 18:11:08 +00:00
|
|
|
LogWriter log = new LogWriter (QualifiedName);
|
2005-05-02 18:40:30 +00:00
|
|
|
foreach (StructField field in fields) {
|
2011-02-20 18:11:08 +00:00
|
|
|
if (!field.Validate (log)) {
|
* generator/StructBase.cs: update field-generation logic a bit
* generator/CodeGenerator.cs: add a --glue-includes flag
* generator/GenerationInfo.cs: Accept glue_includes value from
Main and output it to the glue_filename.
* generator/FieldBase.cs (Ignored): handle more ignorable cases.
(CheckGlue): New method to figure out what kind of glue we'll need
for a field.
(GenerateImports): generate appropriate imports per CheckGlue.
(GenerateGlue): Generate C glue for accessing a struct field;
either a fully-C-based accessor, or a method to just return the
field's offset in the struct.
(Generate): Use the generated glue to read the field.
* generator/PropertyBase.cs (CType): if the field is a single bit,
set its type to gboolean.
* generator/ObjectGen.cs (Generate):
* generator/OpaqueGen.cs (Generate): Call GenFields.
* generator/StructField.cs: Use FieldBase's glue-generation code
to handle bitfields. [#54489]
* generator/ObjectField.cs: Generates accessors for public fields
of objects and opaque structs. [#69514]
* generator/ClassBase.cs (ClassBase): Parse <fields> nodes and
create ObjectField objects.
(GenFields): Output field properties
(IgnoreMethod): Ignore Get/Set methods that duplicate fields
* generator/Makefile.am (sources): update
* {gdk,gnome,gtk,pango}/*.metadata: Mark some additional fields as
public. Rename/retype some fields for consistency with earlier
hand-coded bindings.
* {gdk,gnome,gtk,pango}/*.custom: Remove custom methods that can
now be autogenerated.
* {gdk,gnome,gtk,pango}/glue/*.c: Remove glue methods that can now
be autogenerated
* {gdk,glade,gnome,gtk,pango,vte}/Makefile.am
* {gdk,glade,gnome,gtk,pango,vte}/glue/Makefile.am
* {gdk,gnome,gtk,pango}/glue/makefile.win32: Update
svn path=/trunk/gtk-sharp/; revision=44563
2005-05-16 14:28:55 +00:00
|
|
|
if (!field.IsPointer)
|
|
|
|
return false;
|
2005-02-23 17:37:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-05 20:34:45 +00:00
|
|
|
return base.Validate ();
|
2005-02-23 17:37:33 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 13:18:08 +00:00
|
|
|
public override bool CanGenerateABIStruct(LogWriter log) {
|
|
|
|
log.Info("Not generating any ABI structs for managed structures");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-12-26 19:33:34 +00:00
|
|
|
public override void Generate (GenerationInfo gen_info)
|
2002-11-10 10:03:51 +00:00
|
|
|
{
|
2003-10-28 15:45:35 +00:00
|
|
|
bool need_close = false;
|
2017-10-03 13:18:08 +00:00
|
|
|
|
2003-10-28 15:45:35 +00:00
|
|
|
if (gen_info.Writer == null) {
|
2014-02-24 01:04:03 +00:00
|
|
|
gen_info.Writer = gen_info.OpenStream (Name, NS);
|
2003-10-28 15:45:35 +00:00
|
|
|
need_close = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamWriter sw = gen_info.Writer;
|
2002-11-10 10:03:51 +00:00
|
|
|
|
2003-10-05 00:20:17 +00:00
|
|
|
sw.WriteLine ("namespace " + NS + " {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\tusing System;");
|
2002-11-10 10:03:51 +00:00
|
|
|
sw.WriteLine ("\tusing System.Collections;");
|
2012-11-03 16:00:52 +00:00
|
|
|
sw.WriteLine ("\tusing System.Collections.Generic;");
|
2002-11-10 10:03:51 +00:00
|
|
|
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
2003-01-05 23:51:37 +00:00
|
|
|
sw.WriteLine ("#region Autogenerated code");
|
2005-08-11 14:13:25 +00:00
|
|
|
if (IsDeprecated)
|
|
|
|
sw.WriteLine ("\t[Obsolete]");
|
2013-10-08 18:22:16 +00:00
|
|
|
if (Union)
|
|
|
|
sw.WriteLine ("\t[StructLayout(LayoutKind.Explicit)]");
|
|
|
|
else
|
|
|
|
sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
|
2008-09-30 21:21:53 +00:00
|
|
|
string access = IsInternal ? "internal" : "public";
|
2011-10-08 02:55:26 +00:00
|
|
|
sw.WriteLine ("\t" + access + " partial struct {0} : IEquatable<{0}> {{", Name);
|
2002-11-10 10:03:51 +00:00
|
|
|
sw.WriteLine ();
|
|
|
|
|
2007-08-13 14:29:06 +00:00
|
|
|
need_read_native = false;
|
2005-05-02 18:40:30 +00:00
|
|
|
GenFields (gen_info);
|
2002-11-10 10:03:51 +00:00
|
|
|
sw.WriteLine ();
|
2003-10-05 00:20:17 +00:00
|
|
|
GenCtors (gen_info);
|
2007-08-13 14:29:06 +00:00
|
|
|
GenMethods (gen_info, null, this);
|
|
|
|
if (need_read_native)
|
|
|
|
GenReadNative (sw);
|
2011-10-08 02:55:26 +00:00
|
|
|
GenEqualsAndHash (sw);
|
2003-01-05 23:51:37 +00:00
|
|
|
|
2003-10-28 15:45:35 +00:00
|
|
|
if (!need_close)
|
|
|
|
return;
|
|
|
|
|
2003-01-05 23:51:37 +00:00
|
|
|
sw.WriteLine ("#endregion");
|
2012-08-05 16:19:32 +00:00
|
|
|
|
2002-11-10 10:03:51 +00:00
|
|
|
sw.WriteLine ("\t}");
|
2003-10-05 00:20:17 +00:00
|
|
|
sw.WriteLine ("}");
|
|
|
|
sw.Close ();
|
|
|
|
gen_info.Writer = null;
|
2002-11-10 10:03:51 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 00:20:17 +00:00
|
|
|
protected override void GenCtors (GenerationInfo gen_info)
|
2002-11-10 10:03:51 +00:00
|
|
|
{
|
2003-10-05 00:20:17 +00:00
|
|
|
StreamWriter sw = gen_info.Writer;
|
|
|
|
|
2002-11-10 10:03:51 +00:00
|
|
|
sw.WriteLine ("\t\tpublic static {0} Zero = new {0} ();", QualifiedName);
|
|
|
|
sw.WriteLine();
|
2004-06-02 20:28:42 +00:00
|
|
|
if (!DisableNew) {
|
|
|
|
sw.WriteLine ("\t\tpublic static " + QualifiedName + " New(IntPtr raw) {");
|
2007-07-12 21:23:47 +00:00
|
|
|
sw.WriteLine ("\t\t\tif (raw == IntPtr.Zero)");
|
2004-06-02 20:28:42 +00:00
|
|
|
sw.WriteLine ("\t\t\t\treturn {0}.Zero;", QualifiedName);
|
2007-07-12 21:23:47 +00:00
|
|
|
sw.WriteLine ("\t\t\treturn ({0}) Marshal.PtrToStructure (raw, typeof ({0}));", QualifiedName);
|
2004-06-02 20:28:42 +00:00
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
}
|
2002-11-10 10:03:51 +00:00
|
|
|
|
2005-01-24 18:25:02 +00:00
|
|
|
foreach (Ctor ctor in Ctors)
|
|
|
|
ctor.IsStatic = true;
|
2003-04-06 09:21:15 +00:00
|
|
|
|
2003-10-05 00:20:17 +00:00
|
|
|
base.GenCtors (gen_info);
|
2002-11-10 10:03:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-13 14:29:06 +00:00
|
|
|
void GenReadNative (StreamWriter sw)
|
|
|
|
{
|
|
|
|
sw.WriteLine ("\t\tstatic void ReadNative (IntPtr native, ref {0} target)", QualifiedName);
|
|
|
|
sw.WriteLine ("\t\t{");
|
|
|
|
sw.WriteLine ("\t\t\ttarget = New (native);");
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Prepare (StreamWriter sw, string indent)
|
|
|
|
{
|
|
|
|
sw.WriteLine (indent + "IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));");
|
|
|
|
sw.WriteLine (indent + "System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);");
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Finish (StreamWriter sw, string indent)
|
|
|
|
{
|
|
|
|
need_read_native = true;
|
|
|
|
sw.WriteLine (indent + "ReadNative (this_as_native, ref this);");
|
|
|
|
sw.WriteLine (indent + "System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);");
|
|
|
|
}
|
2002-11-10 10:03:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|