Ryujinx-GtkSharp/generator/ObjectGen.cs

418 lines
13 KiB
C#
Raw Normal View History

// GtkSharp.Generation.ObjectGen.cs - The Object Generatable.
//
// Author: Mike Kestner <mkestner@ximian.com>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2003-2004 Novell, Inc.
//
// 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.
namespace GtkSharp.Generation {
using System;
using System.Collections;
using System.IO;
2002-08-19 Rachel Hestilow <hestilow@ximian.com> * art/Makefile.in (clean): Change to avoid bugging out on generated/CVS. * glib/ObjectManager.cs: Added. Used to be auto-generated, but now it can infer names, and relies on per-namespace ObjectManager classes to inform it of oddly-named classes. * generator/IGeneratable.cs, GenBase.cs: New "DoGenerate" property. * generator/*Gen.cs: Honor DoGenerate. * generator/CodeGenerator.cs: Support including dependency files which will not be generated. * generator/ObjectGen.cs: Generate mapping file per-namespace, as one that calls back to the one in glib. Only generate if the name does not follow the normal conventions, otherwise, GtkSharp.ObjectManager can infer the name. * generator/Parser.cs: Accept 'generate' flag to pass on to the IGeneratables. Parse a new toplevel element, "symbol", which adds a type to the SymbolTable (instead of hard-coding it). * generator/SignalHandler.cs: Do not optimize signal handler creation, instead creating them in their own namespaces. Do not generate if the calling Signal told us not to. * generator/Signal.cs: Do not generate handlers if container's DoGenerate is false. Adjust to the marshaller name being in a sub-namespace. * generator/SymbolTable.cs (AddSimpleType, AddManualType): Used to add simple and manually wrapped types at runtime instead of compile-time. (FromNative): Remove hard-coded cases for manually wrapped types, use a generic case instead. * api: Added. Move api files and generation targets here. * source: Added. Move source parsing here. * generator/makefile: Move actual generation to api/. * glib/Makefile.in: Remove generated/* target. * glue/Makefile.am: Fix to include canvas-marshal. Move canvas stuff to GNOME target. * gnome/CanvasProxy.cs: Update to work with SignalHandlers being namespace-specific. * parser/Metadata.pm: Moved to GAPI/Metadata.pm, renamed, etc. * parser/gapi2xml.pl: Use GAPI::Metadata. * parser/makefile: Install scripts, remove source parse build target. Rename formatXML to gapi_format_xml. svn path=/trunk/gtk-sharp/; revision=6818
2002-08-20 21:56:18 +02:00
using System.Text;
using System.Xml;
public class ObjectGen : ObjectBase {
private ArrayList custom_attrs = new ArrayList();
private ArrayList strings = new ArrayList();
private Hashtable childprops = new Hashtable();
private static Hashtable dirs = new Hashtable ();
public ObjectGen (XmlElement ns, XmlElement elem) : base (ns, elem, false)
{
foreach (XmlNode node in elem.ChildNodes) {
if (!(node is XmlElement)) continue;
XmlElement member = (XmlElement) node;
if (member.GetAttributeAsBoolean ("hidden"))
continue;
switch (node.Name) {
case "callback":
Statistics.IgnoreCount++;
break;
case "custom-attribute":
custom_attrs.Add (member.InnerXml);
break;
case "static-string":
strings.Add (node);
break;
case "childprop":
string name = member.GetAttribute ("name");
while (childprops.ContainsKey (name))
name += "mangled";
childprops.Add (name, new ChildProperty (member, this));
break;
default:
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 19:15:19 +02:00
if (!IsNodeNameHandled (node.Name))
Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
break;
}
}
}
public override string CallByName (string var, bool owned)
{
return String.Format ("{0} == null ? IntPtr.Zero : {0}.{1}", var, owned ? "OwnedHandle" : "Handle");
}
public override bool Validate ()
{
LogWriter log = new LogWriter (QualifiedName);
ArrayList invalids = new ArrayList ();
foreach (ChildProperty prop in childprops.Values) {
if (!prop.Validate (log))
invalids.Add (prop);
}
foreach (ChildProperty prop in invalids)
childprops.Remove (prop);
return base.Validate ();
}
private bool DisableVoidCtor {
get {
return Elem.GetAttributeAsBoolean ("disable_void_ctor");
}
}
private class DirectoryInfo {
public string assembly_name;
public Hashtable objects;
public DirectoryInfo (string assembly_name) {
this.assembly_name = assembly_name;
objects = new Hashtable ();
}
}
private static DirectoryInfo GetDirectoryInfo (string dir, string assembly_name)
{
DirectoryInfo result;
if (dirs.ContainsKey (dir)) {
result = dirs [dir] as DirectoryInfo;
if (result.assembly_name != assembly_name) {
Console.WriteLine ("Can't put multiple assemblies in one directory.");
return null;
}
return result;
}
result = new DirectoryInfo (assembly_name);
dirs.Add (dir, result);
return result;
}
public override void Generate (GenerationInfo gen_info)
2003-10-05 02:20:17 +02:00
{
gen_info.CurrentType = QualifiedName;
string asm_name = gen_info.AssemblyName.Length == 0 ? NS.ToLower () + "-sharp" : gen_info.AssemblyName;
DirectoryInfo di = GetDirectoryInfo (gen_info.Dir, asm_name);
2003-10-05 02:20:17 +02:00
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
2003-10-05 02:20:17 +02:00
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Collections;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
SymbolTable table = SymbolTable.Table;
sw.WriteLine ("#region Autogenerated code");
if (IsDeprecated)
sw.WriteLine ("\t[Obsolete]");
foreach (string attr in custom_attrs)
sw.WriteLine ("\t" + attr);
sw.Write ("\t{0} {1}partial class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : "");
string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));
if (cs_parent != "") {
di.objects.Add (CName, QualifiedName);
sw.Write (" : " + cs_parent);
}
foreach (string iface in interfaces) {
if (Parent != null && Parent.Implements (iface))
continue;
sw.Write (", " + table.GetCSType (iface));
}
foreach (string iface in managed_interfaces) {
if (Parent != null && Parent.Implements (iface))
continue;
sw.Write (", " + iface);
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 19:15:19 +02:00
}
sw.WriteLine (" {");
sw.WriteLine ();
2003-10-05 02:20:17 +02:00
GenCtors (gen_info);
GenProperties (gen_info, null);
* 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 16:28:55 +02:00
GenFields (gen_info);
GenChildProperties (gen_info);
bool has_sigs = (sigs != null && sigs.Count > 0);
if (!has_sigs) {
foreach (string iface in interfaces) {
InterfaceGen igen = table.GetClassGen (iface) as InterfaceGen;
if (igen != null && igen.Signals != null) {
has_sigs = true;
break;
}
}
}
if (has_sigs && Elem.HasAttribute("parent")) {
2003-10-05 02:20:17 +02:00
GenSignals (gen_info, null);
}
GenClassMembers (gen_info, cs_parent);
2003-10-05 02:20:17 +02:00
GenMethods (gen_info, null, null);
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 19:15:19 +02:00
if (interfaces.Count != 0) {
Hashtable all_methods = new Hashtable ();
foreach (Method m in Methods.Values)
all_methods[m.Name] = m;
Hashtable collisions = new Hashtable ();
foreach (string iface in interfaces) {
ClassBase igen = table.GetClassGen (iface);
foreach (Method m in igen.Methods.Values) {
if (m.Name.StartsWith ("Get") || m.Name.StartsWith ("Set")) {
if (GetProperty (m.Name.Substring (3)) != null) {
collisions[m.Name] = true;
continue;
}
}
Method collision = all_methods[m.Name] as Method;
if (collision != null && collision.Signature.Types == m.Signature.Types)
collisions[m.Name] = true;
else
all_methods[m.Name] = m;
}
}
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 19:15:19 +02:00
foreach (string iface in interfaces) {
if (Parent != null && Parent.Implements (iface))
continue;
InterfaceGen igen = table.GetClassGen (iface) as InterfaceGen;
2003-10-05 02:20:17 +02:00
igen.GenMethods (gen_info, collisions, this);
igen.GenProperties (gen_info, this);
2003-10-05 02:20:17 +02:00
igen.GenSignals (gen_info, this);
igen.GenVirtualMethods (gen_info, this);
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 19:15:19 +02:00
}
}
foreach (XmlElement str in strings) {
sw.Write ("\t\tpublic static string " + str.GetAttribute ("name"));
sw.WriteLine (" {\n\t\t\t get { return \"" + str.GetAttribute ("value") + "\"; }\n\t\t}");
}
if (cs_parent != String.Empty && GetExpected (CName) != QualifiedName) {
sw.WriteLine ();
sw.WriteLine ("\t\tstatic " + Name + " ()");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tGtkSharp." + Studlify (asm_name) + ".ObjectManager.Initialize ();");
sw.WriteLine ("\t\t}");
}
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
2003-10-05 02:20:17 +02:00
sw.WriteLine ("}");
2003-10-05 02:20:17 +02:00
sw.Close ();
gen_info.Writer = null;
Statistics.ObjectCount++;
}
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 19:15:19 +02:00
2003-10-05 02:20:17 +02:00
protected override void GenCtors (GenerationInfo gen_info)
{
if (!Elem.HasAttribute("parent"))
return;
2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 08:08:52 +02:00
2003-10-05 02:20:17 +02:00
gen_info.Writer.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}");
if (ctors.Count == 0 && !DisableVoidCtor) {
gen_info.Writer.WriteLine();
gen_info.Writer.WriteLine("\t\tprotected " + Name + "() : base(IntPtr.Zero)");
gen_info.Writer.WriteLine("\t\t{");
gen_info.Writer.WriteLine("\t\t\tCreateNativeObject (new string [0], new GLib.Value [0]);");
gen_info.Writer.WriteLine("\t\t}");
}
2003-10-05 02:20:17 +02:00
gen_info.Writer.WriteLine();
2003-10-05 02:20:17 +02:00
base.GenCtors (gen_info);
}
protected void GenChildProperties (GenerationInfo gen_info)
{
if (childprops.Count == 0)
return;
StreamWriter sw = gen_info.Writer;
ObjectGen child_ancestor = Parent as ObjectGen;
while (child_ancestor.CName != "GtkContainer" &&
child_ancestor.childprops.Count == 0)
child_ancestor = child_ancestor.Parent as ObjectGen;
sw.WriteLine ("\t\tpublic class " + Name + "Child : " + child_ancestor.NS + "." + child_ancestor.Name + "." + child_ancestor.Name + "Child {");
sw.WriteLine ("\t\t\tprotected internal " + Name + "Child (Gtk.Container parent, Gtk.Widget child) : base (parent, child) {}");
sw.WriteLine ("");
foreach (ChildProperty prop in childprops.Values)
prop.Generate (gen_info, "\t\t\t", null);
sw.WriteLine ("\t\t}");
sw.WriteLine ("");
sw.WriteLine ("\t\tpublic override Gtk.Container.ContainerChild this [Gtk.Widget child] {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn new " + Name + "Child (this, child);");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ("");
}
void GenClassMembers (GenerationInfo gen_info, string cs_parent)
{
GenVirtualMethods (gen_info, null);
if (class_struct_name == null || !CanGenerateClassStruct) return;
StreamWriter sw = gen_info.Writer;
GenerateClassStruct (gen_info);
if (cs_parent == "")
sw.WriteLine ("\t\tstatic uint class_offset = 0;");
else
sw.WriteLine ("\t\tstatic uint class_offset = ((GLib.GType) typeof ({0})).GetClassSize ();", cs_parent);
sw.WriteLine ("\t\tstatic Hashtable class_structs;");
sw.WriteLine ();
sw.WriteLine ("\t\tstatic {0} GetClassStruct (GLib.GType gtype, bool use_cache)", class_struct_name);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (class_structs == null)");
sw.WriteLine ("\t\t\t\tclass_structs = new Hashtable ();");
sw.WriteLine ();
sw.WriteLine ("\t\t\tif (use_cache && class_structs.Contains (gtype))");
sw.WriteLine ("\t\t\t\treturn ({0}) class_structs [gtype];", class_struct_name);
sw.WriteLine ("\t\t\telse {");
sw.WriteLine ("\t\t\t\tIntPtr class_ptr = new IntPtr (gtype.GetClassPtr ().ToInt64 () + class_offset);");
sw.WriteLine ("\t\t\t\t{0} class_struct = ({0}) Marshal.PtrToStructure (class_ptr, typeof ({0}));", class_struct_name);
sw.WriteLine ("\t\t\t\tif (use_cache)");
sw.WriteLine ("\t\t\t\t\tclass_structs.Add (gtype, class_struct);");
sw.WriteLine ("\t\t\t\treturn class_struct;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tstatic void OverrideClassStruct (GLib.GType gtype, {0} class_struct)", class_struct_name);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tIntPtr class_ptr = new IntPtr (gtype.GetClassPtr ().ToInt64 () + class_offset);");
sw.WriteLine ("\t\t\tMarshal.StructureToPtr (class_struct, class_ptr, false);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
* parser/gapi2xml.pl: make note of _get_type methods for enums * */*-api.xml: Regen, adding gtype="..." to many enum types * generator/EnumGen.cs (Generate): if the enum has the "gtype" property, add a GTypeAttribute pointing to an internal FooGType class whose GType property can be used to get the enum's GType. * generator/ObjectGen.cs: s/ObjectManager.RegisterType/GType.Register/ * glib/GTypeAttribute.cs: attribute for indicating a property that will return the GType of a type (particularly for enums, which can't have GType properties added to them). * glib/GType.cs: renamed from Type.cs to match the type name (public static readonly GType ...): add a few missing types. (Register): moved from ObjectManager.RegisterType (LookupGType): moved from TypeConverter.LookupType and extended to handle GTypeAttribute. Also, fix mappings for sbyte/byte/char, and return specific GTypes for Object subclasses rather than always returning GType.Object. [Fixes #74699] (LookupType): moved from ObjectWrapper.LookupType (ToString): return the type name * glib/Object.cs (RegisterGType): s/ObjectManager.Register/GType.Register/ (LookupGType): Make this protected internal so GType can access it. * glib/ObjectManager.cs (RegisterType): deprecate in favor of GType.Register. (LookupType): moved to GType * glib/TypeConverter.cs (LookupType): now a deprecated wrapper around GType.LookupGType. * glib/Value.cs: Use GType casts rather than TypeConverter * gtk/NodeStore.cs (ScanType): * gtk/ListStore.custom (ListStore): * gtk/TreeStore.custom (TreeStore): Use (GType) cast rather than TypeConverter. Remove the error check and exception, since the cast never returns GType.Invalid. (The check probably predates GLib.ManagedValue.) * gnome/PanelAppletFactory.cs (Register): Use a GType cast rather than GLib.Object.LookupGType (which is no longer accessible after an mcs bugfix) * sample/GtkDemo/DemoIconView.cs (CreateStore): use the Type[] constructor rather than the GType[] constructor, since it translates typeof(Gdk.Pixbuf) correctly now. svn path=/trunk/gtk-sharp/; revision=44038
2005-05-04 18:54:24 +02:00
/* Keep this in sync with the one in glib/GType.cs */
private static string GetExpected (string cname)
{
for (int i = 1; i < cname.Length; i++) {
if (Char.IsUpper (cname[i])) {
if (i == 1 && cname[0] == 'G')
return "GLib." + cname.Substring (1);
else
return cname.Substring (0, i) + "." + cname.Substring (i);
2002-08-19 Rachel Hestilow <hestilow@ximian.com> * art/Makefile.in (clean): Change to avoid bugging out on generated/CVS. * glib/ObjectManager.cs: Added. Used to be auto-generated, but now it can infer names, and relies on per-namespace ObjectManager classes to inform it of oddly-named classes. * generator/IGeneratable.cs, GenBase.cs: New "DoGenerate" property. * generator/*Gen.cs: Honor DoGenerate. * generator/CodeGenerator.cs: Support including dependency files which will not be generated. * generator/ObjectGen.cs: Generate mapping file per-namespace, as one that calls back to the one in glib. Only generate if the name does not follow the normal conventions, otherwise, GtkSharp.ObjectManager can infer the name. * generator/Parser.cs: Accept 'generate' flag to pass on to the IGeneratables. Parse a new toplevel element, "symbol", which adds a type to the SymbolTable (instead of hard-coding it). * generator/SignalHandler.cs: Do not optimize signal handler creation, instead creating them in their own namespaces. Do not generate if the calling Signal told us not to. * generator/Signal.cs: Do not generate handlers if container's DoGenerate is false. Adjust to the marshaller name being in a sub-namespace. * generator/SymbolTable.cs (AddSimpleType, AddManualType): Used to add simple and manually wrapped types at runtime instead of compile-time. (FromNative): Remove hard-coded cases for manually wrapped types, use a generic case instead. * api: Added. Move api files and generation targets here. * source: Added. Move source parsing here. * generator/makefile: Move actual generation to api/. * glib/Makefile.in: Remove generated/* target. * glue/Makefile.am: Fix to include canvas-marshal. Move canvas stuff to GNOME target. * gnome/CanvasProxy.cs: Update to work with SignalHandlers being namespace-specific. * parser/Metadata.pm: Moved to GAPI/Metadata.pm, renamed, etc. * parser/gapi2xml.pl: Use GAPI::Metadata. * parser/makefile: Install scripts, remove source parse build target. Rename formatXML to gapi_format_xml. svn path=/trunk/gtk-sharp/; revision=6818
2002-08-20 21:56:18 +02:00
}
}
throw new ArgumentException ("cname doesn't follow the NamespaceType capitalization style: " + cname);
2002-08-19 Rachel Hestilow <hestilow@ximian.com> * art/Makefile.in (clean): Change to avoid bugging out on generated/CVS. * glib/ObjectManager.cs: Added. Used to be auto-generated, but now it can infer names, and relies on per-namespace ObjectManager classes to inform it of oddly-named classes. * generator/IGeneratable.cs, GenBase.cs: New "DoGenerate" property. * generator/*Gen.cs: Honor DoGenerate. * generator/CodeGenerator.cs: Support including dependency files which will not be generated. * generator/ObjectGen.cs: Generate mapping file per-namespace, as one that calls back to the one in glib. Only generate if the name does not follow the normal conventions, otherwise, GtkSharp.ObjectManager can infer the name. * generator/Parser.cs: Accept 'generate' flag to pass on to the IGeneratables. Parse a new toplevel element, "symbol", which adds a type to the SymbolTable (instead of hard-coding it). * generator/SignalHandler.cs: Do not optimize signal handler creation, instead creating them in their own namespaces. Do not generate if the calling Signal told us not to. * generator/Signal.cs: Do not generate handlers if container's DoGenerate is false. Adjust to the marshaller name being in a sub-namespace. * generator/SymbolTable.cs (AddSimpleType, AddManualType): Used to add simple and manually wrapped types at runtime instead of compile-time. (FromNative): Remove hard-coded cases for manually wrapped types, use a generic case instead. * api: Added. Move api files and generation targets here. * source: Added. Move source parsing here. * generator/makefile: Move actual generation to api/. * glib/Makefile.in: Remove generated/* target. * glue/Makefile.am: Fix to include canvas-marshal. Move canvas stuff to GNOME target. * gnome/CanvasProxy.cs: Update to work with SignalHandlers being namespace-specific. * parser/Metadata.pm: Moved to GAPI/Metadata.pm, renamed, etc. * parser/gapi2xml.pl: Use GAPI::Metadata. * parser/makefile: Install scripts, remove source parse build target. Rename formatXML to gapi_format_xml. svn path=/trunk/gtk-sharp/; revision=6818
2002-08-20 21:56:18 +02:00
}
private static bool NeedsMap (Hashtable objs, string assembly_name)
2002-08-19 Rachel Hestilow <hestilow@ximian.com> * art/Makefile.in (clean): Change to avoid bugging out on generated/CVS. * glib/ObjectManager.cs: Added. Used to be auto-generated, but now it can infer names, and relies on per-namespace ObjectManager classes to inform it of oddly-named classes. * generator/IGeneratable.cs, GenBase.cs: New "DoGenerate" property. * generator/*Gen.cs: Honor DoGenerate. * generator/CodeGenerator.cs: Support including dependency files which will not be generated. * generator/ObjectGen.cs: Generate mapping file per-namespace, as one that calls back to the one in glib. Only generate if the name does not follow the normal conventions, otherwise, GtkSharp.ObjectManager can infer the name. * generator/Parser.cs: Accept 'generate' flag to pass on to the IGeneratables. Parse a new toplevel element, "symbol", which adds a type to the SymbolTable (instead of hard-coding it). * generator/SignalHandler.cs: Do not optimize signal handler creation, instead creating them in their own namespaces. Do not generate if the calling Signal told us not to. * generator/Signal.cs: Do not generate handlers if container's DoGenerate is false. Adjust to the marshaller name being in a sub-namespace. * generator/SymbolTable.cs (AddSimpleType, AddManualType): Used to add simple and manually wrapped types at runtime instead of compile-time. (FromNative): Remove hard-coded cases for manually wrapped types, use a generic case instead. * api: Added. Move api files and generation targets here. * source: Added. Move source parsing here. * generator/makefile: Move actual generation to api/. * glib/Makefile.in: Remove generated/* target. * glue/Makefile.am: Fix to include canvas-marshal. Move canvas stuff to GNOME target. * gnome/CanvasProxy.cs: Update to work with SignalHandlers being namespace-specific. * parser/Metadata.pm: Moved to GAPI/Metadata.pm, renamed, etc. * parser/gapi2xml.pl: Use GAPI::Metadata. * parser/makefile: Install scripts, remove source parse build target. Rename formatXML to gapi_format_xml. svn path=/trunk/gtk-sharp/; revision=6818
2002-08-20 21:56:18 +02:00
{
foreach (string key in objs.Keys)
if (GetExpected (key) != ((string) objs[key]))
return true;
return false;
}
private static string Studlify (string name)
{
string result = "";
string[] subs = name.Split ('-');
foreach (string sub in subs)
result += Char.ToUpper (sub[0]) + sub.Substring (1);
return result;
}
public static void GenerateMappers ()
{
foreach (string dir in dirs.Keys) {
DirectoryInfo di = dirs[dir] as DirectoryInfo;
if (!NeedsMap (di.objects, di.assembly_name))
2002-08-19 Rachel Hestilow <hestilow@ximian.com> * art/Makefile.in (clean): Change to avoid bugging out on generated/CVS. * glib/ObjectManager.cs: Added. Used to be auto-generated, but now it can infer names, and relies on per-namespace ObjectManager classes to inform it of oddly-named classes. * generator/IGeneratable.cs, GenBase.cs: New "DoGenerate" property. * generator/*Gen.cs: Honor DoGenerate. * generator/CodeGenerator.cs: Support including dependency files which will not be generated. * generator/ObjectGen.cs: Generate mapping file per-namespace, as one that calls back to the one in glib. Only generate if the name does not follow the normal conventions, otherwise, GtkSharp.ObjectManager can infer the name. * generator/Parser.cs: Accept 'generate' flag to pass on to the IGeneratables. Parse a new toplevel element, "symbol", which adds a type to the SymbolTable (instead of hard-coding it). * generator/SignalHandler.cs: Do not optimize signal handler creation, instead creating them in their own namespaces. Do not generate if the calling Signal told us not to. * generator/Signal.cs: Do not generate handlers if container's DoGenerate is false. Adjust to the marshaller name being in a sub-namespace. * generator/SymbolTable.cs (AddSimpleType, AddManualType): Used to add simple and manually wrapped types at runtime instead of compile-time. (FromNative): Remove hard-coded cases for manually wrapped types, use a generic case instead. * api: Added. Move api files and generation targets here. * source: Added. Move source parsing here. * generator/makefile: Move actual generation to api/. * glib/Makefile.in: Remove generated/* target. * glue/Makefile.am: Fix to include canvas-marshal. Move canvas stuff to GNOME target. * gnome/CanvasProxy.cs: Update to work with SignalHandlers being namespace-specific. * parser/Metadata.pm: Moved to GAPI/Metadata.pm, renamed, etc. * parser/gapi2xml.pl: Use GAPI::Metadata. * parser/makefile: Install scripts, remove source parse build target. Rename formatXML to gapi_format_xml. svn path=/trunk/gtk-sharp/; revision=6818
2002-08-20 21:56:18 +02:00
continue;
GenerationInfo gen_info = new GenerationInfo (dir, di.assembly_name);
GenerateMapper (di, gen_info);
}
}
private static void GenerateMapper (DirectoryInfo dir_info, GenerationInfo gen_info)
{
StreamWriter sw = gen_info.OpenStream ("ObjectManager");
sw.WriteLine ("namespace GtkSharp." + Studlify (dir_info.assembly_name) + " {");
sw.WriteLine ();
sw.WriteLine ("\tpublic class ObjectManager {");
sw.WriteLine ();
sw.WriteLine ("\t\tstatic bool initialized = false;");
sw.WriteLine ("\t\t// Call this method from the appropriate module init function.");
sw.WriteLine ("\t\tpublic static void Initialize ()");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (initialized)");
sw.WriteLine ("\t\t\t\treturn;");
sw.WriteLine ("");
sw.WriteLine ("\t\t\tinitialized = true;");
2002-08-19 Rachel Hestilow <hestilow@ximian.com> * art/Makefile.in (clean): Change to avoid bugging out on generated/CVS. * glib/ObjectManager.cs: Added. Used to be auto-generated, but now it can infer names, and relies on per-namespace ObjectManager classes to inform it of oddly-named classes. * generator/IGeneratable.cs, GenBase.cs: New "DoGenerate" property. * generator/*Gen.cs: Honor DoGenerate. * generator/CodeGenerator.cs: Support including dependency files which will not be generated. * generator/ObjectGen.cs: Generate mapping file per-namespace, as one that calls back to the one in glib. Only generate if the name does not follow the normal conventions, otherwise, GtkSharp.ObjectManager can infer the name. * generator/Parser.cs: Accept 'generate' flag to pass on to the IGeneratables. Parse a new toplevel element, "symbol", which adds a type to the SymbolTable (instead of hard-coding it). * generator/SignalHandler.cs: Do not optimize signal handler creation, instead creating them in their own namespaces. Do not generate if the calling Signal told us not to. * generator/Signal.cs: Do not generate handlers if container's DoGenerate is false. Adjust to the marshaller name being in a sub-namespace. * generator/SymbolTable.cs (AddSimpleType, AddManualType): Used to add simple and manually wrapped types at runtime instead of compile-time. (FromNative): Remove hard-coded cases for manually wrapped types, use a generic case instead. * api: Added. Move api files and generation targets here. * source: Added. Move source parsing here. * generator/makefile: Move actual generation to api/. * glib/Makefile.in: Remove generated/* target. * glue/Makefile.am: Fix to include canvas-marshal. Move canvas stuff to GNOME target. * gnome/CanvasProxy.cs: Update to work with SignalHandlers being namespace-specific. * parser/Metadata.pm: Moved to GAPI/Metadata.pm, renamed, etc. * parser/gapi2xml.pl: Use GAPI::Metadata. * parser/makefile: Install scripts, remove source parse build target. Rename formatXML to gapi_format_xml. svn path=/trunk/gtk-sharp/; revision=6818
2002-08-20 21:56:18 +02:00
foreach (string key in dir_info.objects.Keys) {
if (GetExpected(key) != ((string) dir_info.objects[key]))
* parser/gapi2xml.pl: make note of _get_type methods for enums * */*-api.xml: Regen, adding gtype="..." to many enum types * generator/EnumGen.cs (Generate): if the enum has the "gtype" property, add a GTypeAttribute pointing to an internal FooGType class whose GType property can be used to get the enum's GType. * generator/ObjectGen.cs: s/ObjectManager.RegisterType/GType.Register/ * glib/GTypeAttribute.cs: attribute for indicating a property that will return the GType of a type (particularly for enums, which can't have GType properties added to them). * glib/GType.cs: renamed from Type.cs to match the type name (public static readonly GType ...): add a few missing types. (Register): moved from ObjectManager.RegisterType (LookupGType): moved from TypeConverter.LookupType and extended to handle GTypeAttribute. Also, fix mappings for sbyte/byte/char, and return specific GTypes for Object subclasses rather than always returning GType.Object. [Fixes #74699] (LookupType): moved from ObjectWrapper.LookupType (ToString): return the type name * glib/Object.cs (RegisterGType): s/ObjectManager.Register/GType.Register/ (LookupGType): Make this protected internal so GType can access it. * glib/ObjectManager.cs (RegisterType): deprecate in favor of GType.Register. (LookupType): moved to GType * glib/TypeConverter.cs (LookupType): now a deprecated wrapper around GType.LookupGType. * glib/Value.cs: Use GType casts rather than TypeConverter * gtk/NodeStore.cs (ScanType): * gtk/ListStore.custom (ListStore): * gtk/TreeStore.custom (TreeStore): Use (GType) cast rather than TypeConverter. Remove the error check and exception, since the cast never returns GType.Invalid. (The check probably predates GLib.ManagedValue.) * gnome/PanelAppletFactory.cs (Register): Use a GType cast rather than GLib.Object.LookupGType (which is no longer accessible after an mcs bugfix) * sample/GtkDemo/DemoIconView.cs (CreateStore): use the Type[] constructor rather than the GType[] constructor, since it translates typeof(Gdk.Pixbuf) correctly now. svn path=/trunk/gtk-sharp/; revision=44038
2005-05-04 18:54:24 +02:00
sw.WriteLine ("\t\t\tGLib.GType.Register ({0}.GType, typeof ({0}));", dir_info.objects [key]);
}
2002-08-19 Rachel Hestilow <hestilow@ximian.com> * art/Makefile.in (clean): Change to avoid bugging out on generated/CVS. * glib/ObjectManager.cs: Added. Used to be auto-generated, but now it can infer names, and relies on per-namespace ObjectManager classes to inform it of oddly-named classes. * generator/IGeneratable.cs, GenBase.cs: New "DoGenerate" property. * generator/*Gen.cs: Honor DoGenerate. * generator/CodeGenerator.cs: Support including dependency files which will not be generated. * generator/ObjectGen.cs: Generate mapping file per-namespace, as one that calls back to the one in glib. Only generate if the name does not follow the normal conventions, otherwise, GtkSharp.ObjectManager can infer the name. * generator/Parser.cs: Accept 'generate' flag to pass on to the IGeneratables. Parse a new toplevel element, "symbol", which adds a type to the SymbolTable (instead of hard-coding it). * generator/SignalHandler.cs: Do not optimize signal handler creation, instead creating them in their own namespaces. Do not generate if the calling Signal told us not to. * generator/Signal.cs: Do not generate handlers if container's DoGenerate is false. Adjust to the marshaller name being in a sub-namespace. * generator/SymbolTable.cs (AddSimpleType, AddManualType): Used to add simple and manually wrapped types at runtime instead of compile-time. (FromNative): Remove hard-coded cases for manually wrapped types, use a generic case instead. * api: Added. Move api files and generation targets here. * source: Added. Move source parsing here. * generator/makefile: Move actual generation to api/. * glib/Makefile.in: Remove generated/* target. * glue/Makefile.am: Fix to include canvas-marshal. Move canvas stuff to GNOME target. * gnome/CanvasProxy.cs: Update to work with SignalHandlers being namespace-specific. * parser/Metadata.pm: Moved to GAPI/Metadata.pm, renamed, etc. * parser/gapi2xml.pl: Use GAPI::Metadata. * parser/makefile: Install scripts, remove source parse build target. Rename formatXML to gapi_format_xml. svn path=/trunk/gtk-sharp/; revision=6818
2002-08-20 21:56:18 +02:00
sw.WriteLine ("\t\t}");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
}
}
}