2002-01-08 20:05:47 +00:00
|
|
|
// GtkSharp.Generation.InterfaceGen.cs - The Interface Generatable.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
2004-06-25 16:35:15 +00:00
|
|
|
// Copyright (c) 2001-2003 Mike Kestner
|
2007-09-19 18:15:55 +00:00
|
|
|
// Copyright (c) 2004, 2007 Novell, Inc.
|
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-01-08 20:05:47 +00:00
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
2004-11-18 23:04:32 +00:00
|
|
|
using System.Collections;
|
2002-01-08 20:05:47 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
2005-07-02 15:23:27 +00:00
|
|
|
public class InterfaceGen : ObjectBase {
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2004-11-18 23:04:32 +00:00
|
|
|
ArrayList vms = new ArrayList ();
|
|
|
|
ArrayList members = new ArrayList ();
|
|
|
|
|
|
|
|
public InterfaceGen (XmlElement ns, XmlElement elem) : base (ns, elem)
|
|
|
|
{
|
|
|
|
foreach (XmlNode node in elem.ChildNodes) {
|
|
|
|
switch (node.Name) {
|
|
|
|
case "virtual_method":
|
|
|
|
VirtualMethod vm = new VirtualMethod (node as XmlElement, this);
|
|
|
|
vms.Add (vm);
|
|
|
|
members.Add (vm);
|
|
|
|
break;
|
|
|
|
case "signal":
|
|
|
|
members.Add ((node as XmlElement).GetAttribute ("cname").Replace ('-', '_'));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!IsNodeNameHandled (node.Name))
|
|
|
|
Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-09 15:59:30 +00:00
|
|
|
public override bool ValidateForSubclass ()
|
|
|
|
{
|
|
|
|
ArrayList invalids = new ArrayList ();
|
|
|
|
|
|
|
|
foreach (Method method in methods.Values) {
|
|
|
|
if (!method.Validate ()) {
|
|
|
|
Console.WriteLine ("in type " + QualifiedName);
|
|
|
|
invalids.Add (method);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (Method method in invalids)
|
|
|
|
methods.Remove (method.Name);
|
|
|
|
invalids.Clear ();
|
|
|
|
|
|
|
|
return base.ValidateForSubclass ();
|
|
|
|
}
|
|
|
|
|
2004-11-18 23:04:32 +00:00
|
|
|
string IfaceName {
|
|
|
|
get {
|
|
|
|
return Name + "Iface";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenerateIfaceStruct (StreamWriter sw)
|
|
|
|
{
|
2007-09-11 20:34:24 +00:00
|
|
|
sw.WriteLine ("\t\tstatic " + IfaceName + " iface;");
|
2004-11-18 23:04:32 +00:00
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\t\tstruct " + IfaceName + " {");
|
|
|
|
sw.WriteLine ("\t\t\tpublic IntPtr gtype;");
|
|
|
|
sw.WriteLine ("\t\t\tpublic IntPtr itype;");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
foreach (object member in members) {
|
|
|
|
if (member is System.String)
|
|
|
|
sw.WriteLine ("\t\t\tpublic IntPtr " + member + ";");
|
|
|
|
else if (member is VirtualMethod) {
|
|
|
|
VirtualMethod vm = member as VirtualMethod;
|
2007-09-11 20:34:24 +00:00
|
|
|
bool has_method = methods [vm.Name] != null;
|
|
|
|
if (!has_method)
|
|
|
|
Console.WriteLine ("Interface " + QualifiedName + " virtual method " + vm.Name + " has no matching method to invoke.");
|
|
|
|
string type = has_method && vm.IsValid ? vm.Name + "Delegate" : "IntPtr";
|
|
|
|
sw.WriteLine ("\t\t\tpublic " + type + " " + vm.CName + ";");
|
2004-11-18 23:04:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
}
|
|
|
|
|
2007-09-11 20:34:24 +00:00
|
|
|
void GenerateStaticCtor (StreamWriter sw)
|
2004-11-18 23:04:32 +00:00
|
|
|
{
|
2007-09-11 20:34:24 +00:00
|
|
|
sw.WriteLine ("\t\tstatic " + Name + "Adapter ()");
|
2004-11-18 23:04:32 +00:00
|
|
|
sw.WriteLine ("\t\t{");
|
2007-09-11 20:34:24 +00:00
|
|
|
foreach (VirtualMethod vm in vms) {
|
|
|
|
bool has_method = methods [vm.Name] != null;
|
|
|
|
if (has_method && vm.IsValid)
|
|
|
|
sw.WriteLine ("\t\t\tiface.{0} = new {1}Delegate ({1}Callback);", vm.CName, vm.Name);
|
|
|
|
}
|
2004-11-18 23:04:32 +00:00
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenerateInitialize (StreamWriter sw)
|
|
|
|
{
|
2007-09-11 20:34:24 +00:00
|
|
|
sw.WriteLine ("\t\tstatic void Initialize (IntPtr ifaceptr, IntPtr data)");
|
2004-11-18 23:04:32 +00:00
|
|
|
sw.WriteLine ("\t\t{");
|
2007-09-11 20:34:24 +00:00
|
|
|
sw.WriteLine ("\t\t\t" + IfaceName + " native_iface = (" + IfaceName + ") Marshal.PtrToStructure (ifaceptr, typeof (" + IfaceName + "));");
|
2004-11-18 23:04:32 +00:00
|
|
|
foreach (VirtualMethod vm in vms)
|
2007-09-11 20:34:24 +00:00
|
|
|
sw.WriteLine ("\t\t\tnative_iface." + vm.CName + " = iface." + vm.CName + ";");
|
|
|
|
sw.WriteLine ("\t\t\tMarshal.StructureToPtr (native_iface, ifaceptr, false);");
|
|
|
|
sw.WriteLine ("\t\t\tGCHandle gch = (GCHandle) data;");
|
|
|
|
sw.WriteLine ("\t\t\tgch.Free ();");
|
2004-11-18 23:04:32 +00:00
|
|
|
sw.WriteLine ("\t\t}");
|
2007-09-11 20:34:24 +00:00
|
|
|
sw.WriteLine ();
|
2004-11-18 23:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GenerateCallbacks (StreamWriter sw)
|
|
|
|
{
|
|
|
|
foreach (VirtualMethod vm in vms) {
|
2007-09-11 20:34:24 +00:00
|
|
|
if (methods [vm.Name] == null)
|
|
|
|
continue;
|
2004-11-18 23:04:32 +00:00
|
|
|
sw.WriteLine ();
|
|
|
|
vm.GenerateCallback (sw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-11 20:34:24 +00:00
|
|
|
void GenerateCtor (StreamWriter sw)
|
|
|
|
{
|
|
|
|
sw.WriteLine ("\t\tpublic " + Name + "Adapter ()");
|
|
|
|
sw.WriteLine ("\t\t{");
|
|
|
|
sw.WriteLine ("\t\t\tInitHandler = new GLib.GInterfaceInitHandler (Initialize);");
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenerateGType (StreamWriter sw)
|
|
|
|
{
|
|
|
|
Method m = GetMethod ("GetType");
|
|
|
|
m.GenerateImport (sw);
|
|
|
|
sw.WriteLine ("\t\tpublic override GLib.GType GType {");
|
|
|
|
sw.WriteLine ("\t\t\tget {");
|
|
|
|
sw.WriteLine ("\t\t\t\treturn new GLib.GType (" + m.CName + " ());");
|
|
|
|
sw.WriteLine ("\t\t\t}");
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
}
|
|
|
|
|
2004-11-18 23:04:32 +00:00
|
|
|
void GenerateAdapter (GenerationInfo gen_info)
|
|
|
|
{
|
|
|
|
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name + "Adapter");
|
|
|
|
|
|
|
|
sw.WriteLine ("namespace " + NS + " {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\tusing System;");
|
|
|
|
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("#region Autogenerated code");
|
|
|
|
sw.WriteLine ("\tinternal class " + Name + "Adapter : GLib.GInterfaceAdapter {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
GenerateIfaceStruct (sw);
|
2007-09-11 20:34:24 +00:00
|
|
|
GenerateStaticCtor (sw);
|
2004-11-18 23:04:32 +00:00
|
|
|
GenerateCallbacks (sw);
|
2007-09-11 20:34:24 +00:00
|
|
|
GenerateInitialize (sw);
|
|
|
|
GenerateCtor (sw);
|
|
|
|
GenerateGType (sw);
|
2004-11-18 23:04:32 +00:00
|
|
|
|
|
|
|
sw.WriteLine ("\t}");
|
|
|
|
sw.WriteLine ("#endregion");
|
|
|
|
sw.WriteLine ("}");
|
|
|
|
sw.Close ();
|
|
|
|
gen_info.Writer = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenSignals (GenerationInfo gen_info)
|
|
|
|
{
|
|
|
|
if (sigs.Count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
StreamWriter sw = gen_info.Writer;
|
|
|
|
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\t\t// signals");
|
|
|
|
foreach (Signal sig in sigs.Values) {
|
2005-08-05 20:34:45 +00:00
|
|
|
sig.GenerateDecl (sw);
|
|
|
|
sig.GenEventHandler (gen_info);
|
2004-11-18 23:04:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Hashtable GenVMDecls (StreamWriter sw)
|
|
|
|
{
|
|
|
|
if (vms.Count == 0)
|
|
|
|
return new Hashtable ();
|
|
|
|
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\t\t// virtual methods");
|
|
|
|
Hashtable vm_decls = new Hashtable ();
|
|
|
|
foreach (VirtualMethod vm in vms) {
|
|
|
|
sw.WriteLine ("\t\t" + vm.Declaration);
|
|
|
|
vm_decls [vm.Declaration] = vm;
|
|
|
|
}
|
|
|
|
return vm_decls;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenMethodDecls (StreamWriter sw, Hashtable vm_decls)
|
|
|
|
{
|
|
|
|
if (methods.Count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool need_comment = true;
|
|
|
|
foreach (Method method in methods.Values) {
|
|
|
|
//if (IgnoreMethod (method))
|
|
|
|
//continue;
|
|
|
|
|
2005-08-05 20:34:45 +00:00
|
|
|
if (!vm_decls.Contains (method.Declaration) && method.Name != "GetGType") {
|
|
|
|
if (need_comment) {
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\t\t// non-virtual methods");
|
|
|
|
need_comment = false;
|
2004-11-18 23:04:32 +00:00
|
|
|
}
|
2005-08-05 20:34:45 +00:00
|
|
|
method.GenerateDecl (sw);
|
|
|
|
}
|
2004-11-18 23:04:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-26 19:33:34 +00:00
|
|
|
public override void Generate (GenerationInfo gen_info)
|
2003-10-05 00:20:17 +00:00
|
|
|
{
|
2007-09-11 20:34:24 +00:00
|
|
|
GenerateAdapter (gen_info);
|
2003-10-05 00:20:17 +00:00
|
|
|
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2003-10-05 00:20:17 +00:00
|
|
|
sw.WriteLine ("namespace " + NS + " {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\tusing System;");
|
|
|
|
sw.WriteLine ();
|
2003-01-05 23:51:37 +00:00
|
|
|
sw.WriteLine ("#region Autogenerated code");
|
2007-09-11 20:34:24 +00:00
|
|
|
sw.WriteLine ("\t[GLib.GInterface (typeof (" + Name + "Adapter))]");
|
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 17:15:19 +00:00
|
|
|
sw.WriteLine ("\tpublic interface " + Name + " : GLib.IWrapper {");
|
2002-01-08 20:05:47 +00:00
|
|
|
sw.WriteLine ();
|
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 17:15:19 +00:00
|
|
|
|
|
|
|
foreach (Signal sig in sigs.Values) {
|
2005-08-05 20:34:45 +00:00
|
|
|
sig.GenerateDecl (sw);
|
|
|
|
sig.GenEventHandler (gen_info);
|
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 17:15:19 +00:00
|
|
|
}
|
2002-05-23 23:43:25 +00:00
|
|
|
|
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 17:15:19 +00:00
|
|
|
foreach (Method method in methods.Values) {
|
2007-08-13 14:29:06 +00:00
|
|
|
if (IgnoreMethod (method, this))
|
2005-08-05 20:34:45 +00:00
|
|
|
continue;
|
|
|
|
method.GenerateDecl (sw);
|
2005-07-22 18:35:37 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 20:34:45 +00:00
|
|
|
foreach (Property prop in props.Values)
|
|
|
|
prop.GenerateDecl (sw, "\t\t");
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2003-10-05 00:20:17 +00:00
|
|
|
AppendCustom (sw, gen_info.CustomDir);
|
2002-10-08 19:14:14 +00:00
|
|
|
|
2002-01-08 20:05:47 +00:00
|
|
|
sw.WriteLine ("\t}");
|
2003-01-05 23:51:37 +00:00
|
|
|
sw.WriteLine ("#endregion");
|
2003-10-05 00:20:17 +00:00
|
|
|
sw.WriteLine ("}");
|
|
|
|
sw.Close ();
|
|
|
|
gen_info.Writer = null;
|
2002-02-19 03:12:47 +00:00
|
|
|
Statistics.IFaceCount++;
|
2002-01-08 20:05:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|