generator: Convert all .cs files to Unix line endings

There are no real code changes in this commit.
This commit is contained in:
Bertrand Lorentz 2012-11-03 15:20:06 +01:00
parent 4f29defd5c
commit b8b1cfa5d7
36 changed files with 5782 additions and 5782 deletions

View File

@ -1,30 +1,30 @@
// GtkSharp.Generation.AliasGen.cs - The Alias type Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2003 Mike Kestner
//
// 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;
public class AliasGen : SimpleBase {
public AliasGen (string ctype, string type) : base (ctype, type, String.Empty) {}
}
}
// GtkSharp.Generation.AliasGen.cs - The Alias type Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2003 Mike Kestner
//
// 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;
public class AliasGen : SimpleBase {
public AliasGen (string ctype, string type) : base (ctype, type, String.Empty) {}
}
}

View File

@ -1,83 +1,83 @@
// GtkSharp.Generation.BoxedGen.cs - The Boxed Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// 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.IO;
using System.Xml;
public class BoxedGen : StructBase {
public BoxedGen (XmlElement ns, XmlElement elem) : base (ns, elem) {}
public override void Generate (GenerationInfo gen_info)
{
Method copy = methods["Copy"] as Method;
Method free = methods["Free"] as Method;
methods.Remove ("Copy");
methods.Remove ("Free");
gen_info.CurrentType = QualifiedName;
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
base.Generate (gen_info);
sw.WriteLine ("\t\tpublic static explicit operator GLib.Value (" + QualifiedName + " boxed)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tGLib.Value val = GLib.Value.Empty;");
sw.WriteLine ("\t\t\tval.Init (" + QualifiedName + ".GType);");
sw.WriteLine ("\t\t\tval.Val = boxed;");
sw.WriteLine ("\t\t\treturn val;");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic static explicit operator " + QualifiedName + " (GLib.Value val)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\treturn (" + QualifiedName + ") val.Val;");
sw.WriteLine ("\t\t}");
if (copy != null && copy.IsDeprecated) {
sw.WriteLine ();
sw.WriteLine ("\t\t[Obsolete(\"This is a no-op\")]");
sw.WriteLine ("\t\tpublic " + QualifiedName + " Copy() {");
sw.WriteLine ("\t\t\treturn this;");
sw.WriteLine ("\t\t}");
}
if (free != null && free.IsDeprecated) {
sw.WriteLine ();
sw.WriteLine ("\t\t[Obsolete(\"This is a no-op\")]");
sw.WriteLine ("\t\tpublic " + QualifiedName + " Free () {");
sw.WriteLine ("\t\t\treturn this;");
sw.WriteLine ("\t\t}");
}
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
Statistics.BoxedCount++;
}
}
}
// GtkSharp.Generation.BoxedGen.cs - The Boxed Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// 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.IO;
using System.Xml;
public class BoxedGen : StructBase {
public BoxedGen (XmlElement ns, XmlElement elem) : base (ns, elem) {}
public override void Generate (GenerationInfo gen_info)
{
Method copy = methods["Copy"] as Method;
Method free = methods["Free"] as Method;
methods.Remove ("Copy");
methods.Remove ("Free");
gen_info.CurrentType = QualifiedName;
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
base.Generate (gen_info);
sw.WriteLine ("\t\tpublic static explicit operator GLib.Value (" + QualifiedName + " boxed)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tGLib.Value val = GLib.Value.Empty;");
sw.WriteLine ("\t\t\tval.Init (" + QualifiedName + ".GType);");
sw.WriteLine ("\t\t\tval.Val = boxed;");
sw.WriteLine ("\t\t\treturn val;");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic static explicit operator " + QualifiedName + " (GLib.Value val)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\treturn (" + QualifiedName + ") val.Val;");
sw.WriteLine ("\t\t}");
if (copy != null && copy.IsDeprecated) {
sw.WriteLine ();
sw.WriteLine ("\t\t[Obsolete(\"This is a no-op\")]");
sw.WriteLine ("\t\tpublic " + QualifiedName + " Copy() {");
sw.WriteLine ("\t\t\treturn this;");
sw.WriteLine ("\t\t}");
}
if (free != null && free.IsDeprecated) {
sw.WriteLine ();
sw.WriteLine ("\t\t[Obsolete(\"This is a no-op\")]");
sw.WriteLine ("\t\tpublic " + QualifiedName + " Free () {");
sw.WriteLine ("\t\t\treturn this;");
sw.WriteLine ("\t\t}");
}
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
Statistics.BoxedCount++;
}
}
}

View File

@ -1,63 +1,63 @@
// GtkSharp.Generation.ByRefGen.cs - The ByRef type Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2003 Mike Kestner
// Copyright (c) 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;
public class ByRefGen : SimpleBase, IManualMarshaler {
public ByRefGen (string ctype, string type) : base (ctype, type, type + ".Empty") {}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string CallByName (string var_name)
{
return "native_" + var_name;
}
public string AllocNative ()
{
return "Marshal.AllocHGlobal (Marshal.SizeOf (typeof (" + QualifiedName + ")))";
}
public string AllocNative (string var_name)
{
return "GLib.Marshaller.StructureToPtrAlloc (" + var_name + ")";
}
public override string FromNative (string var_name)
{
return String.Format ("({0}) Marshal.PtrToStructure ({1}, typeof ({0}))", QualifiedName, var_name);
}
public string ReleaseNative (string var_name)
{
return "Marshal.FreeHGlobal (" + var_name + ")";
}
}
}
// GtkSharp.Generation.ByRefGen.cs - The ByRef type Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2003 Mike Kestner
// Copyright (c) 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;
public class ByRefGen : SimpleBase, IManualMarshaler {
public ByRefGen (string ctype, string type) : base (ctype, type, type + ".Empty") {}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string CallByName (string var_name)
{
return "native_" + var_name;
}
public string AllocNative ()
{
return "Marshal.AllocHGlobal (Marshal.SizeOf (typeof (" + QualifiedName + ")))";
}
public string AllocNative (string var_name)
{
return "GLib.Marshaller.StructureToPtrAlloc (" + var_name + ")";
}
public override string FromNative (string var_name)
{
return String.Format ("({0}) Marshal.PtrToStructure ({1}, typeof ({0}))", QualifiedName, var_name);
}
public string ReleaseNative (string var_name)
{
return "Marshal.FreeHGlobal (" + var_name + ")";
}
}
}

View File

@ -1,45 +1,45 @@
// GtkSharp.Generation.ChildProperty.cs - GtkContainer child properties
//
// Copyright (c) 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;
using System.Xml;
public class ChildProperty : Property {
public ChildProperty (XmlElement elem, ClassBase container_type) : base (elem, container_type) {}
protected override string PropertyAttribute (string qpname) {
return "[Gtk.ChildProperty (" + qpname + ")]";
}
protected override string RawGetter (string qpname) {
return "parent.ChildGetProperty (child, " + qpname + ")";
}
protected override string RawSetter (string qpname) {
return "parent.ChildSetProperty(child, " + qpname + ", val)";
}
}
}
// GtkSharp.Generation.ChildProperty.cs - GtkContainer child properties
//
// Copyright (c) 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;
using System.Xml;
public class ChildProperty : Property {
public ChildProperty (XmlElement elem, ClassBase container_type) : base (elem, container_type) {}
protected override string PropertyAttribute (string qpname) {
return "[Gtk.ChildProperty (" + qpname + ")]";
}
protected override string RawGetter (string qpname) {
return "parent.ChildGetProperty (child, " + qpname + ")";
}
protected override string RawSetter (string qpname) {
return "parent.ChildSetProperty(child, " + qpname + ", val)";
}
}
}

View File

@ -1,93 +1,93 @@
// GtkSharp.Generation.ClassGen.cs - The Class Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001-2003 Mike Kestner
//
// 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;
using System.Text;
using System.Xml;
public class ClassGen : ClassBase {
public ClassGen (XmlElement ns, XmlElement elem) : base (ns, elem) {}
public override string AssignToName {
get {
return String.Empty;
}
}
public override string MarshalType {
get {
return String.Empty;
}
}
public override string CallByName ()
{
return String.Empty;
}
public override string CallByName (string var)
{
return String.Empty;
}
public override string FromNative (string var)
{
return String.Empty;
}
public override void Generate (GenerationInfo gen_info)
{
gen_info.CurrentType = QualifiedName;
StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name);
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
if (IsDeprecated)
sw.WriteLine ("\t[Obsolete]");
sw.Write ("\t{0} partial class " + Name, IsInternal ? "internal" : "public");
sw.WriteLine (" {");
sw.WriteLine ();
GenProperties (gen_info, null);
GenMethods (gen_info, null, null);
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
}
}
}
// GtkSharp.Generation.ClassGen.cs - The Class Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001-2003 Mike Kestner
//
// 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;
using System.Text;
using System.Xml;
public class ClassGen : ClassBase {
public ClassGen (XmlElement ns, XmlElement elem) : base (ns, elem) {}
public override string AssignToName {
get {
return String.Empty;
}
}
public override string MarshalType {
get {
return String.Empty;
}
}
public override string CallByName ()
{
return String.Empty;
}
public override string CallByName (string var)
{
return String.Empty;
}
public override string FromNative (string var)
{
return String.Empty;
}
public override void Generate (GenerationInfo gen_info)
{
gen_info.CurrentType = QualifiedName;
StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name);
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
if (IsDeprecated)
sw.WriteLine ("\t[Obsolete]");
sw.Write ("\t{0} partial class " + Name, IsInternal ? "internal" : "public");
sw.WriteLine (" {");
sw.WriteLine ();
GenProperties (gen_info, null);
GenMethods (gen_info, null, null);
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
}
}
}

View File

@ -1,121 +1,121 @@
// GtkSharp.Generation.CodeGenerator.cs - The main code generation engine.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// 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.Xml;
public class CodeGenerator {
public static int Main (string[] args)
{
if (args.Length < 2) {
Console.WriteLine ("Usage: codegen --generate <filename1...>");
return 0;
}
bool generate = false;
string dir = "";
string assembly_name = "";
string glue_filename = "";
string glue_includes = "";
string gluelib_name = "";
SymbolTable table = SymbolTable.Table;
ArrayList gens = new ArrayList ();
foreach (string arg in args) {
if (arg.StartsWith ("--customdir=")) {
Console.WriteLine ("Using .custom files is not supported anymore, use partial classes instead.");
return 0;
}
string filename = arg;
if (arg == "--generate") {
generate = true;
continue;
} else if (arg == "--include") {
generate = false;
continue;
} else if (arg.StartsWith ("-I:")) {
generate = false;
filename = filename.Substring (3);
} else if (arg.StartsWith ("--outdir=")) {
generate = false;
dir = arg.Substring (9);
continue;
} else if (arg.StartsWith ("--assembly-name=")) {
generate = false;
assembly_name = arg.Substring (16);
continue;
} else if (arg.StartsWith ("--glue-filename=")) {
generate = false;
glue_filename = arg.Substring (16);
continue;
} else if (arg.StartsWith ("--glue-includes=")) {
generate = false;
glue_includes = arg.Substring (16);
continue;
} else if (arg.StartsWith ("--gluelib-name=")) {
generate = false;
gluelib_name = arg.Substring (15);
continue;
}
Parser p = new Parser ();
IGeneratable[] curr_gens = p.Parse (filename);
table.AddTypes (curr_gens);
if (generate)
gens.AddRange (curr_gens);
}
// Now that everything is loaded, validate all the to-be-
// generated generatables and then remove the invalid ones.
ArrayList invalids = new ArrayList ();
foreach (IGeneratable gen in gens) {
if (!gen.Validate ())
invalids.Add (gen);
}
foreach (IGeneratable gen in invalids)
gens.Remove (gen);
GenerationInfo gen_info = null;
if (dir != "" || assembly_name != "" || glue_filename != "" || glue_includes != "" || gluelib_name != "")
gen_info = new GenerationInfo (dir, assembly_name, glue_filename, glue_includes, gluelib_name);
foreach (IGeneratable gen in gens) {
if (gen_info == null)
gen.Generate ();
else
gen.Generate (gen_info);
}
ObjectGen.GenerateMappers ();
if (gen_info != null)
gen_info.CloseGlueWriter ();
Statistics.Report();
return 0;
}
}
}
// GtkSharp.Generation.CodeGenerator.cs - The main code generation engine.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// 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.Xml;
public class CodeGenerator {
public static int Main (string[] args)
{
if (args.Length < 2) {
Console.WriteLine ("Usage: codegen --generate <filename1...>");
return 0;
}
bool generate = false;
string dir = "";
string assembly_name = "";
string glue_filename = "";
string glue_includes = "";
string gluelib_name = "";
SymbolTable table = SymbolTable.Table;
ArrayList gens = new ArrayList ();
foreach (string arg in args) {
if (arg.StartsWith ("--customdir=")) {
Console.WriteLine ("Using .custom files is not supported anymore, use partial classes instead.");
return 0;
}
string filename = arg;
if (arg == "--generate") {
generate = true;
continue;
} else if (arg == "--include") {
generate = false;
continue;
} else if (arg.StartsWith ("-I:")) {
generate = false;
filename = filename.Substring (3);
} else if (arg.StartsWith ("--outdir=")) {
generate = false;
dir = arg.Substring (9);
continue;
} else if (arg.StartsWith ("--assembly-name=")) {
generate = false;
assembly_name = arg.Substring (16);
continue;
} else if (arg.StartsWith ("--glue-filename=")) {
generate = false;
glue_filename = arg.Substring (16);
continue;
} else if (arg.StartsWith ("--glue-includes=")) {
generate = false;
glue_includes = arg.Substring (16);
continue;
} else if (arg.StartsWith ("--gluelib-name=")) {
generate = false;
gluelib_name = arg.Substring (15);
continue;
}
Parser p = new Parser ();
IGeneratable[] curr_gens = p.Parse (filename);
table.AddTypes (curr_gens);
if (generate)
gens.AddRange (curr_gens);
}
// Now that everything is loaded, validate all the to-be-
// generated generatables and then remove the invalid ones.
ArrayList invalids = new ArrayList ();
foreach (IGeneratable gen in gens) {
if (!gen.Validate ())
invalids.Add (gen);
}
foreach (IGeneratable gen in invalids)
gens.Remove (gen);
GenerationInfo gen_info = null;
if (dir != "" || assembly_name != "" || glue_filename != "" || glue_includes != "" || gluelib_name != "")
gen_info = new GenerationInfo (dir, assembly_name, glue_filename, glue_includes, gluelib_name);
foreach (IGeneratable gen in gens) {
if (gen_info == null)
gen.Generate ();
else
gen.Generate (gen_info);
}
ObjectGen.GenerateMappers ();
if (gen_info != null)
gen_info.CloseGlueWriter ();
Statistics.Report();
return 0;
}
}
}

View File

@ -1,52 +1,52 @@
// ConstFilenameGen.cs - The Const Filename type Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2005 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;
public class ConstFilenameGen : SimpleBase, IManualMarshaler {
public ConstFilenameGen (string ctype) : base (ctype, "string", "null") {}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string FromNative (string var)
{
return "GLib.Marshaller.FilenamePtrToString (" + var + ")";
}
public string AllocNative (string managed_var)
{
return "GLib.Marshaller.StringToFilenamePtr (" + managed_var + ")";
}
public string ReleaseNative (string native_var)
{
return "GLib.Marshaller.Free (" + native_var + ")";
}
}
}
// ConstFilenameGen.cs - The Const Filename type Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2005 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;
public class ConstFilenameGen : SimpleBase, IManualMarshaler {
public ConstFilenameGen (string ctype) : base (ctype, "string", "null") {}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string FromNative (string var)
{
return "GLib.Marshaller.FilenamePtrToString (" + var + ")";
}
public string AllocNative (string managed_var)
{
return "GLib.Marshaller.StringToFilenamePtr (" + managed_var + ")";
}
public string ReleaseNative (string native_var)
{
return "GLib.Marshaller.Free (" + native_var + ")";
}
}
}

View File

@ -1,54 +1,54 @@
// GtkSharp.Generation.ConstStringGen.cs - The Const String type Generatable.
//
// Author: Rachel Hestilow <rachel@nullenvoid.com>
// Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2003 Rachel Hestilow
// Copyright (c) 2005 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;
public class ConstStringGen : SimpleBase, IManualMarshaler {
public ConstStringGen (string ctype) : base (ctype, "string", "null") {}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string FromNative (string var)
{
return "GLib.Marshaller.Utf8PtrToString (" + var + ")";
}
public string AllocNative (string managed_var)
{
return "GLib.Marshaller.StringToPtrGStrdup (" + managed_var + ")";
}
public string ReleaseNative (string native_var)
{
return "GLib.Marshaller.Free (" + native_var + ")";
}
}
}
// GtkSharp.Generation.ConstStringGen.cs - The Const String type Generatable.
//
// Author: Rachel Hestilow <rachel@nullenvoid.com>
// Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2003 Rachel Hestilow
// Copyright (c) 2005 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;
public class ConstStringGen : SimpleBase, IManualMarshaler {
public ConstStringGen (string ctype) : base (ctype, "string", "null") {}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string FromNative (string var)
{
return "GLib.Marshaller.Utf8PtrToString (" + var + ")";
}
public string AllocNative (string managed_var)
{
return "GLib.Marshaller.StringToPtrGStrdup (" + managed_var + ")";
}
public string ReleaseNative (string native_var)
{
return "GLib.Marshaller.Free (" + native_var + ")";
}
}
}

View File

@ -1,164 +1,164 @@
// GtkSharp.Generation.Ctor.cs - The Constructor Generation Class.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2004-2005 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;
using System.Xml;
public class Ctor : MethodBase {
private bool preferred;
private string name;
private bool needs_chaining = false;
public Ctor (XmlElement elem, ClassBase implementor) : base (elem, implementor)
{
preferred = elem.GetAttributeAsBoolean ("preferred");
if (implementor is ObjectGen)
needs_chaining = true;
name = implementor.Name;
}
public bool Preferred {
get { return preferred; }
set { preferred = value; }
}
public string StaticName {
get {
if (!IsStatic)
return String.Empty;
if (Name != null && Name != String.Empty)
return Name;
string[] toks = CName.Substring(CName.IndexOf("new")).Split ('_');
string result = String.Empty;
foreach (string tok in toks)
result += tok.Substring(0,1).ToUpper() + tok.Substring(1);
return result;
}
}
void GenerateImport (StreamWriter sw)
{
sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\", CallingConvention = CallingConvention.Cdecl)]");
sw.WriteLine("\t\tstatic extern " + Safety + "IntPtr " + CName + "(" + Parameters.ImportSignature + ");");
sw.WriteLine();
}
void GenerateStatic (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
sw.WriteLine("\t\t" + Protection + " static " + Safety + Modifiers + name + " " + StaticName + "(" + Signature + ")");
sw.WriteLine("\t\t{");
Body.Initialize(gen_info, false, false, "");
sw.Write("\t\t\t" + name + " result = ");
if (container_type is StructBase)
sw.Write ("{0}.New (", name);
else
sw.Write ("new {0} (", name);
sw.WriteLine (CName + "(" + Body.GetCallString (false) + "));");
Body.Finish (sw, "");
Body.HandleException (sw, "");
sw.WriteLine ("\t\t\treturn result;");
}
public void Generate (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
gen_info.CurrentMember = CName;
GenerateImport (sw);
if (IsStatic)
GenerateStatic (gen_info);
else {
sw.WriteLine("\t\t{0} {1}{2} ({3}) {4}", Protection, Safety, name, Signature.ToString(), needs_chaining ? ": base (IntPtr.Zero)" : "");
sw.WriteLine("\t\t{");
if (needs_chaining) {
sw.WriteLine ("\t\t\tif (GetType () != typeof (" + name + ")) {");
if (Parameters.Count == 0) {
sw.WriteLine ("\t\t\t\tCreateNativeObject (new string [0], new GLib.Value[0]);");
sw.WriteLine ("\t\t\t\treturn;");
} else {
ArrayList names = new ArrayList ();
ArrayList values = new ArrayList ();
for (int i = 0; i < Parameters.Count; i++) {
Parameter p = Parameters[i];
if (container_type.GetPropertyRecursively (p.StudlyName) != null) {
names.Add (p.Name);
values.Add (p.Name);
} else if (p.PropertyName != String.Empty) {
names.Add (p.PropertyName);
values.Add (p.Name);
}
}
if (names.Count == Parameters.Count) {
sw.WriteLine ("\t\t\t\tArrayList vals = new ArrayList();");
sw.WriteLine ("\t\t\t\tArrayList names = new ArrayList();");
for (int i = 0; i < names.Count; i++) {
Parameter p = Parameters [i];
string indent = "\t\t\t\t";
if (p.Generatable is ClassBase && !(p.Generatable is StructBase)) {
sw.WriteLine (indent + "if (" + p.Name + " != null) {");
indent += "\t";
}
sw.WriteLine (indent + "names.Add (\"" + names [i] + "\");");
sw.WriteLine (indent + "vals.Add (new GLib.Value (" + values[i] + "));");
if (p.Generatable is ClassBase && !(p.Generatable is StructBase))
sw.WriteLine ("\t\t\t\t}");
}
sw.WriteLine ("\t\t\t\tCreateNativeObject ((string[])names.ToArray (typeof (string)), (GLib.Value[])vals.ToArray (typeof (GLib.Value)));");
sw.WriteLine ("\t\t\t\treturn;");
} else
sw.WriteLine ("\t\t\t\tthrow new InvalidOperationException (\"Can't override this constructor.\");");
}
sw.WriteLine ("\t\t\t}");
}
Body.Initialize(gen_info, false, false, "");
sw.WriteLine("\t\t\t{0} = {1}({2});", container_type.AssignToName, CName, Body.GetCallString (false));
Body.Finish (sw, "");
Body.HandleException (sw, "");
}
sw.WriteLine("\t\t}");
sw.WriteLine();
Statistics.CtorCount++;
}
}
}
// GtkSharp.Generation.Ctor.cs - The Constructor Generation Class.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2004-2005 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;
using System.Xml;
public class Ctor : MethodBase {
private bool preferred;
private string name;
private bool needs_chaining = false;
public Ctor (XmlElement elem, ClassBase implementor) : base (elem, implementor)
{
preferred = elem.GetAttributeAsBoolean ("preferred");
if (implementor is ObjectGen)
needs_chaining = true;
name = implementor.Name;
}
public bool Preferred {
get { return preferred; }
set { preferred = value; }
}
public string StaticName {
get {
if (!IsStatic)
return String.Empty;
if (Name != null && Name != String.Empty)
return Name;
string[] toks = CName.Substring(CName.IndexOf("new")).Split ('_');
string result = String.Empty;
foreach (string tok in toks)
result += tok.Substring(0,1).ToUpper() + tok.Substring(1);
return result;
}
}
void GenerateImport (StreamWriter sw)
{
sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\", CallingConvention = CallingConvention.Cdecl)]");
sw.WriteLine("\t\tstatic extern " + Safety + "IntPtr " + CName + "(" + Parameters.ImportSignature + ");");
sw.WriteLine();
}
void GenerateStatic (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
sw.WriteLine("\t\t" + Protection + " static " + Safety + Modifiers + name + " " + StaticName + "(" + Signature + ")");
sw.WriteLine("\t\t{");
Body.Initialize(gen_info, false, false, "");
sw.Write("\t\t\t" + name + " result = ");
if (container_type is StructBase)
sw.Write ("{0}.New (", name);
else
sw.Write ("new {0} (", name);
sw.WriteLine (CName + "(" + Body.GetCallString (false) + "));");
Body.Finish (sw, "");
Body.HandleException (sw, "");
sw.WriteLine ("\t\t\treturn result;");
}
public void Generate (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
gen_info.CurrentMember = CName;
GenerateImport (sw);
if (IsStatic)
GenerateStatic (gen_info);
else {
sw.WriteLine("\t\t{0} {1}{2} ({3}) {4}", Protection, Safety, name, Signature.ToString(), needs_chaining ? ": base (IntPtr.Zero)" : "");
sw.WriteLine("\t\t{");
if (needs_chaining) {
sw.WriteLine ("\t\t\tif (GetType () != typeof (" + name + ")) {");
if (Parameters.Count == 0) {
sw.WriteLine ("\t\t\t\tCreateNativeObject (new string [0], new GLib.Value[0]);");
sw.WriteLine ("\t\t\t\treturn;");
} else {
ArrayList names = new ArrayList ();
ArrayList values = new ArrayList ();
for (int i = 0; i < Parameters.Count; i++) {
Parameter p = Parameters[i];
if (container_type.GetPropertyRecursively (p.StudlyName) != null) {
names.Add (p.Name);
values.Add (p.Name);
} else if (p.PropertyName != String.Empty) {
names.Add (p.PropertyName);
values.Add (p.Name);
}
}
if (names.Count == Parameters.Count) {
sw.WriteLine ("\t\t\t\tArrayList vals = new ArrayList();");
sw.WriteLine ("\t\t\t\tArrayList names = new ArrayList();");
for (int i = 0; i < names.Count; i++) {
Parameter p = Parameters [i];
string indent = "\t\t\t\t";
if (p.Generatable is ClassBase && !(p.Generatable is StructBase)) {
sw.WriteLine (indent + "if (" + p.Name + " != null) {");
indent += "\t";
}
sw.WriteLine (indent + "names.Add (\"" + names [i] + "\");");
sw.WriteLine (indent + "vals.Add (new GLib.Value (" + values[i] + "));");
if (p.Generatable is ClassBase && !(p.Generatable is StructBase))
sw.WriteLine ("\t\t\t\t}");
}
sw.WriteLine ("\t\t\t\tCreateNativeObject ((string[])names.ToArray (typeof (string)), (GLib.Value[])vals.ToArray (typeof (GLib.Value)));");
sw.WriteLine ("\t\t\t\treturn;");
} else
sw.WriteLine ("\t\t\t\tthrow new InvalidOperationException (\"Can't override this constructor.\");");
}
sw.WriteLine ("\t\t\t}");
}
Body.Initialize(gen_info, false, false, "");
sw.WriteLine("\t\t\t{0} = {1}({2});", container_type.AssignToName, CName, Body.GetCallString (false));
Body.Finish (sw, "");
Body.HandleException (sw, "");
}
sw.WriteLine("\t\t}");
sw.WriteLine();
Statistics.CtorCount++;
}
}
}

View File

@ -1,133 +1,133 @@
// GtkSharp.Generation.EnumGen.cs - The Enumeration Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001 Mike Kestner
//
// 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;
using System.Xml;
using System.Text.RegularExpressions;
public class EnumGen : GenBase {
string enum_type = String.Empty;
ArrayList members = new ArrayList ();
public EnumGen (XmlElement ns, XmlElement elem) : base (ns, elem)
{
foreach (XmlElement member in elem.ChildNodes) {
if (member.Name != "member")
continue;
string result = "\t\t" + member.GetAttribute("name");
if (member.HasAttribute ("value")) {
string value = member.GetAttribute ("value").Trim ();
foreach (Match match in Regex.Matches (value, "[0-9]+([UL]{1,2})", RegexOptions.IgnoreCase)) {
switch (match.Groups[1].Value.ToUpper ()) {
case "U": enum_type = " : uint"; break;
case "L": enum_type = " : long"; break;
case "UL": enum_type = " : ulong"; break;
}
}
result += " = " + value;
}
members.Add (result + ",");
}
if (elem.HasAttribute ("enum_type"))
enum_type = " : " + elem.GetAttribute ("enum_type");
}
public override bool Validate ()
{
return true;
}
public override string DefaultValue {
get {
return "(" + QualifiedName + ") 0";
}
}
public override string MarshalType {
get {
return "int";
}
}
public override string CallByName (string var_name)
{
return "(int) " + var_name;
}
public override string FromNative(string var)
{
return "(" + QualifiedName + ") " + var;
}
public override void Generate (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.OpenStream (Name);
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
if (Elem.GetAttribute("type") == "flags")
sw.WriteLine ("\t[Flags]");
if (Elem.HasAttribute("gtype"))
sw.WriteLine ("\t[GLib.GType (typeof (" + NS + "." + Name + "GType))]");
string access = IsInternal ? "internal" : "public";
sw.WriteLine ("\t" + access + " enum " + Name + enum_type + " {");
sw.WriteLine ();
foreach (string member in members)
sw.WriteLine (member);
sw.WriteLine ("\t}");
if (Elem.HasAttribute ("gtype")) {
sw.WriteLine ();
sw.WriteLine ("\tinternal class " + Name + "GType {");
sw.WriteLine ("\t\t[DllImport (\"" + LibraryName + "\", CallingConvention = CallingConvention.Cdecl)]");
sw.WriteLine ("\t\tstatic extern IntPtr " + Elem.GetAttribute ("gtype") + " ();");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic static GLib.GType GType {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn new GLib.GType (" + Elem.GetAttribute ("gtype") + " ());");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ("\t}");
}
sw.WriteLine ("#endregion");
sw.WriteLine ("}");
sw.Close ();
Statistics.EnumCount++;
}
}
}
// GtkSharp.Generation.EnumGen.cs - The Enumeration Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001 Mike Kestner
//
// 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;
using System.Xml;
using System.Text.RegularExpressions;
public class EnumGen : GenBase {
string enum_type = String.Empty;
ArrayList members = new ArrayList ();
public EnumGen (XmlElement ns, XmlElement elem) : base (ns, elem)
{
foreach (XmlElement member in elem.ChildNodes) {
if (member.Name != "member")
continue;
string result = "\t\t" + member.GetAttribute("name");
if (member.HasAttribute ("value")) {
string value = member.GetAttribute ("value").Trim ();
foreach (Match match in Regex.Matches (value, "[0-9]+([UL]{1,2})", RegexOptions.IgnoreCase)) {
switch (match.Groups[1].Value.ToUpper ()) {
case "U": enum_type = " : uint"; break;
case "L": enum_type = " : long"; break;
case "UL": enum_type = " : ulong"; break;
}
}
result += " = " + value;
}
members.Add (result + ",");
}
if (elem.HasAttribute ("enum_type"))
enum_type = " : " + elem.GetAttribute ("enum_type");
}
public override bool Validate ()
{
return true;
}
public override string DefaultValue {
get {
return "(" + QualifiedName + ") 0";
}
}
public override string MarshalType {
get {
return "int";
}
}
public override string CallByName (string var_name)
{
return "(int) " + var_name;
}
public override string FromNative(string var)
{
return "(" + QualifiedName + ") " + var;
}
public override void Generate (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.OpenStream (Name);
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
if (Elem.GetAttribute("type") == "flags")
sw.WriteLine ("\t[Flags]");
if (Elem.HasAttribute("gtype"))
sw.WriteLine ("\t[GLib.GType (typeof (" + NS + "." + Name + "GType))]");
string access = IsInternal ? "internal" : "public";
sw.WriteLine ("\t" + access + " enum " + Name + enum_type + " {");
sw.WriteLine ();
foreach (string member in members)
sw.WriteLine (member);
sw.WriteLine ("\t}");
if (Elem.HasAttribute ("gtype")) {
sw.WriteLine ();
sw.WriteLine ("\tinternal class " + Name + "GType {");
sw.WriteLine ("\t\t[DllImport (\"" + LibraryName + "\", CallingConvention = CallingConvention.Cdecl)]");
sw.WriteLine ("\t\tstatic extern IntPtr " + Elem.GetAttribute ("gtype") + " ();");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic static GLib.GType GType {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn new GLib.GType (" + Elem.GetAttribute ("gtype") + " ());");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ("\t}");
}
sw.WriteLine ("#endregion");
sw.WriteLine ("}");
sw.Close ();
Statistics.EnumCount++;
}
}
}

View File

@ -1,108 +1,108 @@
// GtkSharp.Generation.GenBase.cs - The Generatable base class.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2001-2002 Mike Kestner
// Copyright (c) 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.IO;
using System.Xml;
public abstract class GenBase : IGeneratable {
private XmlElement ns;
private XmlElement elem;
protected GenBase (XmlElement ns, XmlElement elem)
{
this.ns = ns;
this.elem = elem;
}
public string CName {
get {
return elem.GetAttribute ("cname");
}
}
public XmlElement Elem {
get {
return elem;
}
}
public int ParserVersion {
get {
XmlElement root = elem.OwnerDocument.DocumentElement;
return root.HasAttribute ("parser_version") ? int.Parse (root.GetAttribute ("parser_version")) : 1;
}
}
public bool IsInternal {
get {
return elem.GetAttributeAsBoolean ("internal");
}
}
public string LibraryName {
get {
return ns.GetAttribute ("library");
}
}
public abstract string MarshalType { get; }
public string Name {
get {
return elem.GetAttribute ("name");
}
}
public string NS {
get {
return ns.GetAttribute ("name");
}
}
public abstract string DefaultValue { get; }
public string QualifiedName {
get {
return NS + "." + Name;
}
}
public abstract string CallByName (string var);
public abstract string FromNative (string var);
public abstract bool Validate ();
public void Generate ()
{
GenerationInfo geninfo = new GenerationInfo (ns);
Generate (geninfo);
}
public abstract void Generate (GenerationInfo geninfo);
}
}
// GtkSharp.Generation.GenBase.cs - The Generatable base class.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2001-2002 Mike Kestner
// Copyright (c) 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.IO;
using System.Xml;
public abstract class GenBase : IGeneratable {
private XmlElement ns;
private XmlElement elem;
protected GenBase (XmlElement ns, XmlElement elem)
{
this.ns = ns;
this.elem = elem;
}
public string CName {
get {
return elem.GetAttribute ("cname");
}
}
public XmlElement Elem {
get {
return elem;
}
}
public int ParserVersion {
get {
XmlElement root = elem.OwnerDocument.DocumentElement;
return root.HasAttribute ("parser_version") ? int.Parse (root.GetAttribute ("parser_version")) : 1;
}
}
public bool IsInternal {
get {
return elem.GetAttributeAsBoolean ("internal");
}
}
public string LibraryName {
get {
return ns.GetAttribute ("library");
}
}
public abstract string MarshalType { get; }
public string Name {
get {
return elem.GetAttribute ("name");
}
}
public string NS {
get {
return ns.GetAttribute ("name");
}
}
public abstract string DefaultValue { get; }
public string QualifiedName {
get {
return NS + "." + Name;
}
}
public abstract string CallByName (string var);
public abstract string FromNative (string var);
public abstract bool Validate ();
public void Generate ()
{
GenerationInfo geninfo = new GenerationInfo (ns);
Generate (geninfo);
}
public abstract void Generate (GenerationInfo geninfo);
}
}

View File

@ -1,167 +1,167 @@
// GtkSharp.Generation.GenerationInfo.cs - Generation information class.
//
// Author: Mike Kestner <mkestner@ximian.com>
//
// Copyright (c) 2003-2008 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;
using System.Xml;
public class GenerationInfo {
string dir;
string assembly_name;
string gluelib_name;
bool glue_enabled;
StreamWriter sw;
StreamWriter glue_sw;
public GenerationInfo (XmlElement ns)
{
string ns_name = ns.GetAttribute ("name");
char sep = Path.DirectorySeparatorChar;
dir = ".." + sep + ns_name.ToLower () + sep + "generated";
assembly_name = ns_name.ToLower () + "-sharp";
}
public GenerationInfo (string dir, string assembly_name) : this (dir, assembly_name, "", "", "") {}
public GenerationInfo (string dir, string assembly_name, string glue_filename, string glue_includes, string gluelib_name)
{
this.dir = dir;
this.assembly_name = assembly_name;
this.gluelib_name = gluelib_name;
InitializeGlue (glue_filename, glue_includes, gluelib_name);
}
void InitializeGlue (string glue_filename, string glue_includes, string gluelib_name)
{
if (gluelib_name != String.Empty && glue_filename != String.Empty) {
FileStream stream;
try {
stream = new FileStream (glue_filename, FileMode.Create, FileAccess.Write);
} catch (Exception) {
Console.Error.WriteLine ("Unable to create specified glue file. Glue will not be generated.");
return;
}
glue_sw = new StreamWriter (stream);
glue_sw.WriteLine ("// This file was generated by the Gtk# code generator.");
glue_sw.WriteLine ("// Any changes made will be lost if regenerated.");
glue_sw.WriteLine ();
if (glue_includes != "") {
foreach (string header in glue_includes.Split (new char[] {',', ' '})) {
if (header != "")
glue_sw.WriteLine ("#include <{0}>", header);
}
glue_sw.WriteLine ("");
}
glue_enabled = true;
}
}
public string AssemblyName {
get {
return assembly_name;
}
}
public string Dir {
get {
return dir;
}
}
public string GluelibName {
get {
return gluelib_name;
}
}
public bool GlueEnabled {
get {
return glue_enabled;
}
}
public StreamWriter GlueWriter {
get {
return glue_sw;
}
}
public StreamWriter Writer {
get {
return sw;
}
set {
sw = value;
}
}
public void CloseGlueWriter ()
{
if (glue_sw != null)
glue_sw.Close ();
}
string member;
public string CurrentMember {
get {
return typename + "." + member;
}
set {
member = value;
}
}
string typename;
public string CurrentType {
get {
return typename;
}
set {
typename = value;
}
}
public StreamWriter OpenStream (string name)
{
char sep = Path.DirectorySeparatorChar;
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
string filename = dir + sep + name + ".cs";
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter (stream);
sw.WriteLine ("// This file was generated by the Gtk# code generator.");
sw.WriteLine ("// Any changes made will be lost if regenerated.");
sw.WriteLine ();
return sw;
}
}
}
// GtkSharp.Generation.GenerationInfo.cs - Generation information class.
//
// Author: Mike Kestner <mkestner@ximian.com>
//
// Copyright (c) 2003-2008 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;
using System.Xml;
public class GenerationInfo {
string dir;
string assembly_name;
string gluelib_name;
bool glue_enabled;
StreamWriter sw;
StreamWriter glue_sw;
public GenerationInfo (XmlElement ns)
{
string ns_name = ns.GetAttribute ("name");
char sep = Path.DirectorySeparatorChar;
dir = ".." + sep + ns_name.ToLower () + sep + "generated";
assembly_name = ns_name.ToLower () + "-sharp";
}
public GenerationInfo (string dir, string assembly_name) : this (dir, assembly_name, "", "", "") {}
public GenerationInfo (string dir, string assembly_name, string glue_filename, string glue_includes, string gluelib_name)
{
this.dir = dir;
this.assembly_name = assembly_name;
this.gluelib_name = gluelib_name;
InitializeGlue (glue_filename, glue_includes, gluelib_name);
}
void InitializeGlue (string glue_filename, string glue_includes, string gluelib_name)
{
if (gluelib_name != String.Empty && glue_filename != String.Empty) {
FileStream stream;
try {
stream = new FileStream (glue_filename, FileMode.Create, FileAccess.Write);
} catch (Exception) {
Console.Error.WriteLine ("Unable to create specified glue file. Glue will not be generated.");
return;
}
glue_sw = new StreamWriter (stream);
glue_sw.WriteLine ("// This file was generated by the Gtk# code generator.");
glue_sw.WriteLine ("// Any changes made will be lost if regenerated.");
glue_sw.WriteLine ();
if (glue_includes != "") {
foreach (string header in glue_includes.Split (new char[] {',', ' '})) {
if (header != "")
glue_sw.WriteLine ("#include <{0}>", header);
}
glue_sw.WriteLine ("");
}
glue_enabled = true;
}
}
public string AssemblyName {
get {
return assembly_name;
}
}
public string Dir {
get {
return dir;
}
}
public string GluelibName {
get {
return gluelib_name;
}
}
public bool GlueEnabled {
get {
return glue_enabled;
}
}
public StreamWriter GlueWriter {
get {
return glue_sw;
}
}
public StreamWriter Writer {
get {
return sw;
}
set {
sw = value;
}
}
public void CloseGlueWriter ()
{
if (glue_sw != null)
glue_sw.Close ();
}
string member;
public string CurrentMember {
get {
return typename + "." + member;
}
set {
member = value;
}
}
string typename;
public string CurrentType {
get {
return typename;
}
set {
typename = value;
}
}
public StreamWriter OpenStream (string name)
{
char sep = Path.DirectorySeparatorChar;
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
string filename = dir + sep + name + ".cs";
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter (stream);
sw.WriteLine ("// This file was generated by the Gtk# code generator.");
sw.WriteLine ("// Any changes made will be lost if regenerated.");
sw.WriteLine ();
return sw;
}
}
}

View File

@ -1,57 +1,57 @@
// GtkSharp.Generation.IGeneratable.cs - Interface to generate code for a type.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2001 Mike Kestner
// Copyright (c) 2007 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 {
public interface IGeneratable {
// The C name of the generatable
string CName {get;}
// The (short) C# name of the generatable
string Name {get;}
// The fully-qualified C# name of the generatable
string QualifiedName {get;}
// The type (possibly including "ref" or "out") to use in the import
// signature when passing this generatable to unmanaged code
string MarshalType {get;}
// The value returned by callbacks that are interrupted prematurely
// by managed exceptions or other conditions where an appropriate
// value can't be otherwise obtained.
string DefaultValue {get;}
// Generates an expression to convert var_name to MarshalType
string CallByName (string var_name);
// Generates an expression to convert var from MarshalType
string FromNative (string var);
bool Validate ();
void Generate ();
void Generate (GenerationInfo gen_info);
}
}
// GtkSharp.Generation.IGeneratable.cs - Interface to generate code for a type.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2001 Mike Kestner
// Copyright (c) 2007 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 {
public interface IGeneratable {
// The C name of the generatable
string CName {get;}
// The (short) C# name of the generatable
string Name {get;}
// The fully-qualified C# name of the generatable
string QualifiedName {get;}
// The type (possibly including "ref" or "out") to use in the import
// signature when passing this generatable to unmanaged code
string MarshalType {get;}
// The value returned by callbacks that are interrupted prematurely
// by managed exceptions or other conditions where an appropriate
// value can't be otherwise obtained.
string DefaultValue {get;}
// Generates an expression to convert var_name to MarshalType
string CallByName (string var_name);
// Generates an expression to convert var from MarshalType
string FromNative (string var);
bool Validate ();
void Generate ();
void Generate (GenerationInfo gen_info);
}
}

View File

@ -1,32 +1,32 @@
// GtkSharp.Generation.IManualMarshaler.cs - Interface for manual marshaling.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2005 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 {
public interface IManualMarshaler {
string AllocNative (string managed_var);
string ReleaseNative (string native_var);
}
}
// GtkSharp.Generation.IManualMarshaler.cs - Interface for manual marshaling.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2005 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 {
public interface IManualMarshaler {
string AllocNative (string managed_var);
string ReleaseNative (string native_var);
}
}

View File

@ -1,363 +1,363 @@
// GtkSharp.Generation.InterfaceGen.cs - The Interface Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2004, 2007 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;
using System.Xml;
public class InterfaceGen : ObjectBase {
bool consume_only;
public InterfaceGen (XmlElement ns, XmlElement elem) : base (ns, elem, true)
{
consume_only = elem.GetAttributeAsBoolean ("consume_only");
foreach (XmlNode node in elem.ChildNodes) {
if (!(node is XmlElement)) continue;
XmlElement member = (XmlElement) node;
switch (member.Name) {
case "signal":
object sig = sigs [member.GetAttribute ("name")];
if (sig == null)
sig = new Signal (node as XmlElement, this);
break;
default:
if (!base.IsNodeNameHandled (node.Name))
new LogWriter (QualifiedName).Warn ("Unexpected node " + node.Name);
break;
}
}
}
public bool IsConsumeOnly {
get {
return consume_only;
}
}
public override string CallByName (string var, bool owned)
{
return String.Format ("{0} == null ? IntPtr.Zero : (({0} is GLib.Object) ? ({0} as GLib.Object).{1} : ({0} as {2}Adapter).{1})", var, owned ? "OwnedHandle" : "Handle", QualifiedName);
}
public override string FromNative (string var, bool owned)
{
return QualifiedName + "Adapter.GetObject (" + var + ", " + (owned ? "true" : "false") + ")";
}
public override bool ValidateForSubclass ()
{
if (!base.ValidateForSubclass ())
return false;
LogWriter log = new LogWriter (QualifiedName);
ArrayList invalids = new ArrayList ();
foreach (Method method in methods.Values) {
if (!method.Validate (log))
invalids.Add (method);
}
foreach (Method method in invalids)
methods.Remove (method.Name);
invalids.Clear ();
return true;
}
void GenerateStaticCtor (StreamWriter sw)
{
sw.WriteLine ("\t\tstatic {0} iface;", class_struct_name);
sw.WriteLine ();
sw.WriteLine ("\t\tstatic " + Name + "Adapter ()");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tGLib.GType.Register (_gtype, typeof({0}Adapter));", Name);
foreach (InterfaceVM vm in interface_vms) {
if (vm.Validate (new LogWriter (QualifiedName)))
sw.WriteLine ("\t\t\tiface.{0} = new {0}NativeDelegate ({0}_cb);", vm.Name);
}
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateInitialize (StreamWriter sw)
{
sw.WriteLine ("\t\tstatic int class_offset = 2 * IntPtr.Size;"); // Class size of GTypeInterface struct
sw.WriteLine ();
sw.WriteLine ("\t\tstatic void Initialize (IntPtr ptr, IntPtr data)");
sw.WriteLine ("\t\t{");
if (interface_vms.Count > 0) {
sw.WriteLine ("\t\t\tIntPtr ifaceptr = new IntPtr (ptr.ToInt64 () + class_offset);");
sw.WriteLine ("\t\t\t{0} native_iface = ({0}) Marshal.PtrToStructure (ifaceptr, typeof ({0}));", class_struct_name);
foreach (InterfaceVM vm in interface_vms) {
sw.WriteLine ("\t\t\tnative_iface." + vm.Name + " = iface." + vm.Name + ";");
}
sw.WriteLine ("\t\t\tMarshal.StructureToPtr (native_iface, ifaceptr, false);");
sw.WriteLine ("\t\t\tGCHandle gch = (GCHandle) data;");
sw.WriteLine ("\t\t\tgch.Free ();");
}
foreach (Property prop in props.Values) {
sw.WriteLine ("\t\t\tGLib.Object.OverrideProperty (data, \"" + prop.CName + "\");");
}
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateCallbacks (StreamWriter sw)
{
foreach (InterfaceVM vm in interface_vms) {
vm.GenerateCallback (sw, null);
}
}
void GenerateCtors (StreamWriter sw)
{
// Native GObjects do not implement the *Implementor interfaces
sw.WriteLine ("\t\tGLib.Object implementor;", Name);
sw.WriteLine ();
if (!IsConsumeOnly) {
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 ();
sw.WriteLine ("\t\tpublic {0}Adapter ({0}Implementor implementor)", Name);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (implementor == null)");
sw.WriteLine ("\t\t\t\tthrow new ArgumentNullException (\"implementor\");");
sw.WriteLine ("\t\t\telse if (!(implementor is GLib.Object))");
sw.WriteLine ("\t\t\t\tthrow new ArgumentException (\"implementor must be a subclass of GLib.Object\");");
sw.WriteLine ("\t\t\tthis.implementor = implementor as GLib.Object;");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
sw.WriteLine ("\t\tpublic " + Name + "Adapter (IntPtr handle)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (!_gtype.IsInstance (handle))");
sw.WriteLine ("\t\t\t\tthrow new ArgumentException (\"The gobject doesn't implement the GInterface of this adapter\", \"handle\");");
sw.WriteLine ("\t\t\timplementor = GLib.Object.GetObject (handle);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateGType (StreamWriter sw)
{
Method m = GetMethod ("GetType");
if (m == null)
throw new Exception ("Interface " + QualifiedName + " missing GetType method.");
m.GenerateImport (sw);
sw.WriteLine ("\t\tprivate static GLib.GType _gtype = new GLib.GType ({0} ());", m.CName);
sw.WriteLine ();
sw.WriteLine ("\t\tpublic override GLib.GType GType {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn _gtype;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateHandleProp (StreamWriter sw)
{
sw.WriteLine ("\t\tpublic override IntPtr Handle {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn implementor.Handle;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic IntPtr OwnedHandle {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn implementor.OwnedHandle;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateGetObject (StreamWriter sw)
{
sw.WriteLine ("\t\tpublic static " + Name + " GetObject (IntPtr handle, bool owned)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tGLib.Object obj = GLib.Object.GetObject (handle, owned);");
sw.WriteLine ("\t\t\treturn GetObject (obj);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic static " + Name + " GetObject (GLib.Object obj)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (obj == null)");
sw.WriteLine ("\t\t\t\treturn null;");
if (!IsConsumeOnly) {
sw.WriteLine ("\t\t\telse if (obj is " + Name + "Implementor)");
sw.WriteLine ("\t\t\t\treturn new {0}Adapter (obj as {0}Implementor);", Name);
}
sw.WriteLine ("\t\t\telse if (obj as " + Name + " == null)");
sw.WriteLine ("\t\t\t\treturn new {0}Adapter (obj.Handle);", Name);
sw.WriteLine ("\t\t\telse");
sw.WriteLine ("\t\t\t\treturn obj as {0};", Name);
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateImplementorProp (StreamWriter sw)
{
sw.WriteLine ("\t\tpublic " + Name + "Implementor Implementor {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn implementor as {0}Implementor;", Name);
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
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 ("\tpublic partial class " + Name + "Adapter : GLib.GInterfaceAdapter, " + QualifiedName + " {");
sw.WriteLine ();
if (!IsConsumeOnly) {
GenerateClassStruct (gen_info);
GenerateStaticCtor (sw);
GenerateCallbacks (sw);
GenerateInitialize (sw);
}
GenerateCtors (sw);
GenerateGType (sw);
GenerateHandleProp (sw);
GenerateGetObject (sw);
if (!IsConsumeOnly)
GenerateImplementorProp (sw);
GenProperties (gen_info, null);
foreach (Signal sig in sigs.Values)
sig.GenEvent (sw, null, "GLib.Object.GetObject (Handle)");
Method temp = methods ["GetType"] as Method;
if (temp != null)
methods.Remove ("GetType");
GenMethods (gen_info, new Hashtable (), this);
if (temp != null)
methods ["GetType"] = temp;
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
}
void GenerateImplementorIface (GenerationInfo gen_info)
{
if (IsConsumeOnly)
return;
StreamWriter sw = gen_info.Writer;
sw.WriteLine ();
sw.WriteLine ("\t[GLib.GInterface (typeof (" + Name + "Adapter))]");
string access = IsInternal ? "internal" : "public";
sw.WriteLine ("\t" + access + " partial interface " + Name + "Implementor : GLib.IWrapper {");
sw.WriteLine ();
Hashtable vm_table = new Hashtable ();
foreach (InterfaceVM vm in interface_vms) {
vm_table [vm.Name] = vm;
}
foreach (InterfaceVM vm in interface_vms) {
if (vm_table [vm.Name] == null)
continue;
else if (!vm.Validate (new LogWriter (QualifiedName))) {
vm_table.Remove (vm.Name);
continue;
} else if (vm.IsGetter || vm.IsSetter) {
string cmp_name = (vm.IsGetter ? "Set" : "Get") + vm.Name.Substring (3);
InterfaceVM cmp = vm_table [cmp_name] as InterfaceVM;
if (cmp != null && (cmp.IsGetter || cmp.IsSetter)) {
if (vm.IsSetter)
cmp.GenerateDeclaration (sw, vm);
else
vm.GenerateDeclaration (sw, cmp);
vm_table.Remove (cmp.Name);
} else
vm.GenerateDeclaration (sw, null);
vm_table.Remove (vm.Name);
} else {
vm.GenerateDeclaration (sw, null);
vm_table.Remove (vm.Name);
}
}
foreach (Property prop in props.Values) {
sw.WriteLine ("\t\t[GLib.Property (\"" + prop.CName + "\")]");
prop.GenerateDecl (sw, "\t\t");
}
sw.WriteLine ("\t}");
}
public override void Generate (GenerationInfo gen_info)
{
GenerateAdapter (gen_info);
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
string access = IsInternal ? "internal" : "public";
sw.WriteLine ("\t" + access + " partial interface " + Name + " : GLib.IWrapper {");
sw.WriteLine ();
foreach (Signal sig in sigs.Values) {
sig.GenerateDecl (sw);
sig.GenEventHandler (gen_info);
}
foreach (Method method in methods.Values) {
if (IgnoreMethod (method, this))
continue;
method.GenerateDecl (sw);
}
foreach (Property prop in props.Values)
prop.GenerateDecl (sw, "\t\t");
sw.WriteLine ("\t}");
GenerateImplementorIface (gen_info);
sw.WriteLine ("#endregion");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
Statistics.IFaceCount++;
}
}
}
// GtkSharp.Generation.InterfaceGen.cs - The Interface Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2004, 2007 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;
using System.Xml;
public class InterfaceGen : ObjectBase {
bool consume_only;
public InterfaceGen (XmlElement ns, XmlElement elem) : base (ns, elem, true)
{
consume_only = elem.GetAttributeAsBoolean ("consume_only");
foreach (XmlNode node in elem.ChildNodes) {
if (!(node is XmlElement)) continue;
XmlElement member = (XmlElement) node;
switch (member.Name) {
case "signal":
object sig = sigs [member.GetAttribute ("name")];
if (sig == null)
sig = new Signal (node as XmlElement, this);
break;
default:
if (!base.IsNodeNameHandled (node.Name))
new LogWriter (QualifiedName).Warn ("Unexpected node " + node.Name);
break;
}
}
}
public bool IsConsumeOnly {
get {
return consume_only;
}
}
public override string CallByName (string var, bool owned)
{
return String.Format ("{0} == null ? IntPtr.Zero : (({0} is GLib.Object) ? ({0} as GLib.Object).{1} : ({0} as {2}Adapter).{1})", var, owned ? "OwnedHandle" : "Handle", QualifiedName);
}
public override string FromNative (string var, bool owned)
{
return QualifiedName + "Adapter.GetObject (" + var + ", " + (owned ? "true" : "false") + ")";
}
public override bool ValidateForSubclass ()
{
if (!base.ValidateForSubclass ())
return false;
LogWriter log = new LogWriter (QualifiedName);
ArrayList invalids = new ArrayList ();
foreach (Method method in methods.Values) {
if (!method.Validate (log))
invalids.Add (method);
}
foreach (Method method in invalids)
methods.Remove (method.Name);
invalids.Clear ();
return true;
}
void GenerateStaticCtor (StreamWriter sw)
{
sw.WriteLine ("\t\tstatic {0} iface;", class_struct_name);
sw.WriteLine ();
sw.WriteLine ("\t\tstatic " + Name + "Adapter ()");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tGLib.GType.Register (_gtype, typeof({0}Adapter));", Name);
foreach (InterfaceVM vm in interface_vms) {
if (vm.Validate (new LogWriter (QualifiedName)))
sw.WriteLine ("\t\t\tiface.{0} = new {0}NativeDelegate ({0}_cb);", vm.Name);
}
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateInitialize (StreamWriter sw)
{
sw.WriteLine ("\t\tstatic int class_offset = 2 * IntPtr.Size;"); // Class size of GTypeInterface struct
sw.WriteLine ();
sw.WriteLine ("\t\tstatic void Initialize (IntPtr ptr, IntPtr data)");
sw.WriteLine ("\t\t{");
if (interface_vms.Count > 0) {
sw.WriteLine ("\t\t\tIntPtr ifaceptr = new IntPtr (ptr.ToInt64 () + class_offset);");
sw.WriteLine ("\t\t\t{0} native_iface = ({0}) Marshal.PtrToStructure (ifaceptr, typeof ({0}));", class_struct_name);
foreach (InterfaceVM vm in interface_vms) {
sw.WriteLine ("\t\t\tnative_iface." + vm.Name + " = iface." + vm.Name + ";");
}
sw.WriteLine ("\t\t\tMarshal.StructureToPtr (native_iface, ifaceptr, false);");
sw.WriteLine ("\t\t\tGCHandle gch = (GCHandle) data;");
sw.WriteLine ("\t\t\tgch.Free ();");
}
foreach (Property prop in props.Values) {
sw.WriteLine ("\t\t\tGLib.Object.OverrideProperty (data, \"" + prop.CName + "\");");
}
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateCallbacks (StreamWriter sw)
{
foreach (InterfaceVM vm in interface_vms) {
vm.GenerateCallback (sw, null);
}
}
void GenerateCtors (StreamWriter sw)
{
// Native GObjects do not implement the *Implementor interfaces
sw.WriteLine ("\t\tGLib.Object implementor;", Name);
sw.WriteLine ();
if (!IsConsumeOnly) {
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 ();
sw.WriteLine ("\t\tpublic {0}Adapter ({0}Implementor implementor)", Name);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (implementor == null)");
sw.WriteLine ("\t\t\t\tthrow new ArgumentNullException (\"implementor\");");
sw.WriteLine ("\t\t\telse if (!(implementor is GLib.Object))");
sw.WriteLine ("\t\t\t\tthrow new ArgumentException (\"implementor must be a subclass of GLib.Object\");");
sw.WriteLine ("\t\t\tthis.implementor = implementor as GLib.Object;");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
sw.WriteLine ("\t\tpublic " + Name + "Adapter (IntPtr handle)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (!_gtype.IsInstance (handle))");
sw.WriteLine ("\t\t\t\tthrow new ArgumentException (\"The gobject doesn't implement the GInterface of this adapter\", \"handle\");");
sw.WriteLine ("\t\t\timplementor = GLib.Object.GetObject (handle);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateGType (StreamWriter sw)
{
Method m = GetMethod ("GetType");
if (m == null)
throw new Exception ("Interface " + QualifiedName + " missing GetType method.");
m.GenerateImport (sw);
sw.WriteLine ("\t\tprivate static GLib.GType _gtype = new GLib.GType ({0} ());", m.CName);
sw.WriteLine ();
sw.WriteLine ("\t\tpublic override GLib.GType GType {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn _gtype;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateHandleProp (StreamWriter sw)
{
sw.WriteLine ("\t\tpublic override IntPtr Handle {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn implementor.Handle;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic IntPtr OwnedHandle {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn implementor.OwnedHandle;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateGetObject (StreamWriter sw)
{
sw.WriteLine ("\t\tpublic static " + Name + " GetObject (IntPtr handle, bool owned)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tGLib.Object obj = GLib.Object.GetObject (handle, owned);");
sw.WriteLine ("\t\t\treturn GetObject (obj);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic static " + Name + " GetObject (GLib.Object obj)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (obj == null)");
sw.WriteLine ("\t\t\t\treturn null;");
if (!IsConsumeOnly) {
sw.WriteLine ("\t\t\telse if (obj is " + Name + "Implementor)");
sw.WriteLine ("\t\t\t\treturn new {0}Adapter (obj as {0}Implementor);", Name);
}
sw.WriteLine ("\t\t\telse if (obj as " + Name + " == null)");
sw.WriteLine ("\t\t\t\treturn new {0}Adapter (obj.Handle);", Name);
sw.WriteLine ("\t\t\telse");
sw.WriteLine ("\t\t\t\treturn obj as {0};", Name);
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateImplementorProp (StreamWriter sw)
{
sw.WriteLine ("\t\tpublic " + Name + "Implementor Implementor {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn implementor as {0}Implementor;", Name);
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
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 ("\tpublic partial class " + Name + "Adapter : GLib.GInterfaceAdapter, " + QualifiedName + " {");
sw.WriteLine ();
if (!IsConsumeOnly) {
GenerateClassStruct (gen_info);
GenerateStaticCtor (sw);
GenerateCallbacks (sw);
GenerateInitialize (sw);
}
GenerateCtors (sw);
GenerateGType (sw);
GenerateHandleProp (sw);
GenerateGetObject (sw);
if (!IsConsumeOnly)
GenerateImplementorProp (sw);
GenProperties (gen_info, null);
foreach (Signal sig in sigs.Values)
sig.GenEvent (sw, null, "GLib.Object.GetObject (Handle)");
Method temp = methods ["GetType"] as Method;
if (temp != null)
methods.Remove ("GetType");
GenMethods (gen_info, new Hashtable (), this);
if (temp != null)
methods ["GetType"] = temp;
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
}
void GenerateImplementorIface (GenerationInfo gen_info)
{
if (IsConsumeOnly)
return;
StreamWriter sw = gen_info.Writer;
sw.WriteLine ();
sw.WriteLine ("\t[GLib.GInterface (typeof (" + Name + "Adapter))]");
string access = IsInternal ? "internal" : "public";
sw.WriteLine ("\t" + access + " partial interface " + Name + "Implementor : GLib.IWrapper {");
sw.WriteLine ();
Hashtable vm_table = new Hashtable ();
foreach (InterfaceVM vm in interface_vms) {
vm_table [vm.Name] = vm;
}
foreach (InterfaceVM vm in interface_vms) {
if (vm_table [vm.Name] == null)
continue;
else if (!vm.Validate (new LogWriter (QualifiedName))) {
vm_table.Remove (vm.Name);
continue;
} else if (vm.IsGetter || vm.IsSetter) {
string cmp_name = (vm.IsGetter ? "Set" : "Get") + vm.Name.Substring (3);
InterfaceVM cmp = vm_table [cmp_name] as InterfaceVM;
if (cmp != null && (cmp.IsGetter || cmp.IsSetter)) {
if (vm.IsSetter)
cmp.GenerateDeclaration (sw, vm);
else
vm.GenerateDeclaration (sw, cmp);
vm_table.Remove (cmp.Name);
} else
vm.GenerateDeclaration (sw, null);
vm_table.Remove (vm.Name);
} else {
vm.GenerateDeclaration (sw, null);
vm_table.Remove (vm.Name);
}
}
foreach (Property prop in props.Values) {
sw.WriteLine ("\t\t[GLib.Property (\"" + prop.CName + "\")]");
prop.GenerateDecl (sw, "\t\t");
}
sw.WriteLine ("\t}");
}
public override void Generate (GenerationInfo gen_info)
{
GenerateAdapter (gen_info);
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
string access = IsInternal ? "internal" : "public";
sw.WriteLine ("\t" + access + " partial interface " + Name + " : GLib.IWrapper {");
sw.WriteLine ();
foreach (Signal sig in sigs.Values) {
sig.GenerateDecl (sw);
sig.GenEventHandler (gen_info);
}
foreach (Method method in methods.Values) {
if (IgnoreMethod (method, this))
continue;
method.GenerateDecl (sw);
}
foreach (Property prop in props.Values)
prop.GenerateDecl (sw, "\t\t");
sw.WriteLine ("\t}");
GenerateImplementorIface (gen_info);
sw.WriteLine ("#endregion");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
Statistics.IFaceCount++;
}
}
}

View File

@ -1,58 +1,58 @@
// GtkSharp.Generation.LPGen.cs - long/pointer Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 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.IO;
public class LPGen : SimpleGen, IAccessor {
public LPGen (string ctype) : base (ctype, "long", "0L") {}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string CallByName (string var_name)
{
return "new IntPtr (" + var_name + ")";
}
public override string FromNative(string var)
{
return "(long) " + var;
}
public void WriteAccessors (StreamWriter sw, string indent, string var)
{
sw.WriteLine (indent + "get {");
sw.WriteLine (indent + "\treturn " + FromNative (var) + ";");
sw.WriteLine (indent + "}");
sw.WriteLine (indent + "set {");
sw.WriteLine (indent + "\t" + var + " = " + CallByName ("value") + ";");
sw.WriteLine (indent + "}");
}
}
}
// GtkSharp.Generation.LPGen.cs - long/pointer Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 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.IO;
public class LPGen : SimpleGen, IAccessor {
public LPGen (string ctype) : base (ctype, "long", "0L") {}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string CallByName (string var_name)
{
return "new IntPtr (" + var_name + ")";
}
public override string FromNative(string var)
{
return "(long) " + var;
}
public void WriteAccessors (StreamWriter sw, string indent, string var)
{
sw.WriteLine (indent + "get {");
sw.WriteLine (indent + "\treturn " + FromNative (var) + ";");
sw.WriteLine (indent + "}");
sw.WriteLine (indent + "set {");
sw.WriteLine (indent + "\t" + var + " = " + CallByName ("value") + ";");
sw.WriteLine (indent + "}");
}
}
}

View File

@ -1,58 +1,58 @@
// GtkSharp.Generation.LPUGen.cs - unsugned long/pointer generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 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.IO;
public class LPUGen : SimpleGen, IAccessor {
public LPUGen (string ctype) : base (ctype, "ulong", "0") {}
public override string MarshalType {
get {
return "UIntPtr";
}
}
public override string CallByName (string var_name)
{
return "new UIntPtr (" + var_name + ")";
}
public override string FromNative(string var)
{
return "(ulong) " + var;
}
public void WriteAccessors (StreamWriter sw, string indent, string var)
{
sw.WriteLine (indent + "get {");
sw.WriteLine (indent + "\treturn " + FromNative (var) + ";");
sw.WriteLine (indent + "}");
sw.WriteLine (indent + "set {");
sw.WriteLine (indent + "\t" + var + " = " + CallByName ("value") + ";");
sw.WriteLine (indent + "}");
}
}
}
// GtkSharp.Generation.LPUGen.cs - unsugned long/pointer generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 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.IO;
public class LPUGen : SimpleGen, IAccessor {
public LPUGen (string ctype) : base (ctype, "ulong", "0") {}
public override string MarshalType {
get {
return "UIntPtr";
}
}
public override string CallByName (string var_name)
{
return "new UIntPtr (" + var_name + ")";
}
public override string FromNative(string var)
{
return "(ulong) " + var;
}
public void WriteAccessors (StreamWriter sw, string indent, string var)
{
sw.WriteLine (indent + "get {");
sw.WriteLine (indent + "\treturn " + FromNative (var) + ";");
sw.WriteLine (indent + "}");
sw.WriteLine (indent + "set {");
sw.WriteLine (indent + "\t" + var + " = " + CallByName ("value") + ";");
sw.WriteLine (indent + "}");
}
}
}

View File

@ -1,58 +1,58 @@
// GtkSharp.Generation.ManualGen.cs - Ungenerated handle type Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2003 Mike Kestner
// Copyright (c) 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;
public class ManualGen : SimpleBase {
string from_fmt;
public ManualGen (string ctype, string type) : base (ctype, type, "null")
{
from_fmt = "new " + QualifiedName + "({0})";
}
public ManualGen (string ctype, string type, string from_fmt) : base (ctype, type, "null")
{
this.from_fmt = from_fmt;
}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string CallByName (string var_name)
{
return var_name + " == null ? IntPtr.Zero : " + var_name + ".Handle";
}
public override string FromNative(string var)
{
return String.Format (from_fmt, var);
}
}
}
// GtkSharp.Generation.ManualGen.cs - Ungenerated handle type Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2003 Mike Kestner
// Copyright (c) 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;
public class ManualGen : SimpleBase {
string from_fmt;
public ManualGen (string ctype, string type) : base (ctype, type, "null")
{
from_fmt = "new " + QualifiedName + "({0})";
}
public ManualGen (string ctype, string type, string from_fmt) : base (ctype, type, "null")
{
this.from_fmt = from_fmt;
}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string CallByName (string var_name)
{
return var_name + " == null ? IntPtr.Zero : " + var_name + ".Handle";
}
public override string FromNative(string var)
{
return String.Format (from_fmt, var);
}
}
}

View File

@ -1,334 +1,334 @@
// GtkSharp.Generation.Method.cs - The Method Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// 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;
using System.Xml;
public class Method : MethodBase {
private ReturnValue retval;
private string call;
private bool is_get, is_set;
private bool deprecated = false;
private bool win32_utf8_variant = false;
public Method (XmlElement elem, ClassBase container_type) : base (elem, container_type)
{
this.retval = new ReturnValue (elem["return-type"]);
if (!container_type.IsDeprecated) {
deprecated = elem.GetAttributeAsBoolean ("deprecated");
}
win32_utf8_variant = elem.GetAttributeAsBoolean ("win32_utf8_variant");
if (Name == "GetType")
Name = "GetGType";
}
public bool HasWin32Utf8Variant {
get { return win32_utf8_variant; }
}
public bool IsDeprecated {
get {
return deprecated;
}
}
public bool IsGetter {
get {
return is_get;
}
}
public bool IsSetter {
get {
return is_set;
}
}
public string ReturnType {
get {
return retval.CSType;
}
}
public override bool Validate (LogWriter log)
{
log.Member = Name;
if (!retval.Validate (log) || !base.Validate (log))
return false;
Parameters parms = Parameters;
is_get = ((((parms.IsAccessor && retval.IsVoid) || (parms.Count == 0 && !retval.IsVoid)) || (parms.Count == 0 && !retval.IsVoid)) && HasGetterName);
is_set = ((parms.IsAccessor || (parms.VisibleCount == 1 && retval.IsVoid)) && HasSetterName);
call = "(" + (IsStatic ? "" : container_type.CallByName () + (parms.Count > 0 ? ", " : "")) + Body.GetCallString (is_set) + ")";
return true;
}
private Method GetComplement ()
{
char complement;
if (is_get)
complement = 'S';
else
complement = 'G';
return container_type.GetMethod (complement + BaseName.Substring (1));
}
public string Declaration {
get {
return retval.CSType + " " + Name + " (" + (Signature != null ? Signature.ToString() : "") + ");";
}
}
private void GenerateDeclCommon (StreamWriter sw, ClassBase implementor)
{
if (IsStatic)
sw.Write("static ");
sw.Write (Safety);
Method dup = null;
if (container_type != null)
dup = container_type.GetMethodRecursively (Name);
if (implementor != null)
dup = implementor.GetMethodRecursively (Name);
if (Name == "ToString" && Parameters.Count == 0 && (!(container_type is InterfaceGen)|| implementor != null))
sw.Write("override ");
else if (Name == "GetGType" && container_type is ObjectGen)
sw.Write("new ");
else if (Modifiers == "new " || (dup != null && ((dup.Signature != null && Signature != null && dup.Signature.ToString() == Signature.ToString()) || (dup.Signature == null && Signature == null))))
sw.Write("new ");
if (is_get || is_set) {
if (retval.IsVoid)
sw.Write (Parameters.AccessorReturnType);
else
sw.Write(retval.CSType);
sw.Write(" ");
if (Name.StartsWith ("Get") || Name.StartsWith ("Set"))
sw.Write (Name.Substring (3));
else {
int dot = Name.LastIndexOf ('.');
if (dot != -1 && (Name.Substring (dot + 1, 3) == "Get" || Name.Substring (dot + 1, 3) == "Set"))
sw.Write (Name.Substring (0, dot + 1) + Name.Substring (dot + 4));
else
sw.Write (Name);
}
sw.WriteLine(" { ");
} else if (IsAccessor) {
sw.Write (Signature.AccessorType + " " + Name + "(" + Signature.AsAccessor + ")");
} else {
sw.Write(retval.CSType + " " + Name + "(" + (Signature != null ? Signature.ToString() : "") + ")");
}
}
public void GenerateDecl (StreamWriter sw)
{
if (IsStatic)
return;
if (is_get || is_set)
{
Method comp = GetComplement ();
if (comp != null && is_set)
return;
sw.Write("\t\t");
GenerateDeclCommon (sw, null);
sw.Write("\t\t\t");
sw.Write ((is_get) ? "get;" : "set;");
if (comp != null && comp.is_set)
sw.WriteLine (" set;");
else
sw.WriteLine ();
sw.WriteLine ("\t\t}");
}
else
{
sw.Write("\t\t");
GenerateDeclCommon (sw, null);
sw.WriteLine (";");
}
Statistics.MethodCount++;
}
public void GenerateImport (StreamWriter sw)
{
string import_sig = IsStatic ? "" : container_type.MarshalType + " raw";
import_sig += !IsStatic && Parameters.Count > 0 ? ", " : "";
import_sig += Parameters.ImportSignature.ToString();
sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\", CallingConvention = CallingConvention.Cdecl)]");
if (retval.MarshalType.StartsWith ("[return:"))
sw.WriteLine("\t\t" + retval.MarshalType + " static extern " + Safety + retval.CSType + " " + CName + "(" + import_sig + ");");
else
sw.WriteLine("\t\tstatic extern " + Safety + retval.MarshalType + " " + CName + "(" + import_sig + ");");
sw.WriteLine();
if (HasWin32Utf8Variant) {
sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\")]");
if (retval.MarshalType.StartsWith ("[return:"))
sw.WriteLine("\t\t" + retval.MarshalType + " static extern " + Safety + retval.CSType + " " + CName + "_utf8(" + import_sig + ");");
else
sw.WriteLine("\t\tstatic extern " + Safety + retval.MarshalType + " " + CName + "_utf8(" + import_sig + ");");
sw.WriteLine();
}
}
public void Generate (GenerationInfo gen_info, ClassBase implementor)
{
Method comp = null;
gen_info.CurrentMember = Name;
/* we are generated by the get Method, if there is one */
if (is_set || is_get)
{
if (Modifiers != "new " && container_type.GetPropertyRecursively (Name.Substring (3)) != null)
return;
comp = GetComplement ();
if (comp != null && is_set) {
if (Parameters.AccessorReturnType == comp.ReturnType)
return;
else {
is_set = false;
call = "(Handle, " + Body.GetCallString (false) + ")";
comp = null;
}
}
/* some setters take more than one arg */
if (comp != null && !comp.is_set)
comp = null;
}
GenerateImport (gen_info.Writer);
if (comp != null && retval.CSType == comp.Parameters.AccessorReturnType)
comp.GenerateImport (gen_info.Writer);
if (IsDeprecated)
gen_info.Writer.WriteLine("\t\t[Obsolete]");
gen_info.Writer.Write("\t\t");
if (Protection != "")
gen_info.Writer.Write("{0} ", Protection);
GenerateDeclCommon (gen_info.Writer, implementor);
if (is_get || is_set)
{
gen_info.Writer.Write ("\t\t\t");
gen_info.Writer.Write ((is_get) ? "get" : "set");
GenerateBody (gen_info, implementor, "\t");
}
else
GenerateBody (gen_info, implementor, "");
if (is_get || is_set)
{
if (comp != null && retval.CSType == comp.Parameters.AccessorReturnType)
{
gen_info.Writer.WriteLine ();
gen_info.Writer.Write ("\t\t\tset");
comp.GenerateBody (gen_info, implementor, "\t");
}
gen_info.Writer.WriteLine ();
gen_info.Writer.WriteLine ("\t\t}");
}
else
gen_info.Writer.WriteLine();
gen_info.Writer.WriteLine();
Statistics.MethodCount++;
}
public void GenerateBody (GenerationInfo gen_info, ClassBase implementor, string indent)
{
StreamWriter sw = gen_info.Writer;
sw.WriteLine(" {");
if (!IsStatic && implementor != null)
implementor.Prepare (sw, indent + "\t\t\t");
if (IsAccessor)
Body.InitAccessor (sw, Signature, indent);
Body.Initialize(gen_info, is_get, is_set, indent);
if (HasWin32Utf8Variant) {
if (!retval.IsVoid)
sw.WriteLine(indent + "\t\t\t" + retval.MarshalType + " raw_ret;");
sw.WriteLine(indent + "\t\t\t" + "if (Environment.OSVersion.Platform == PlatformID.Win32NT ||");
sw.WriteLine(indent + "\t\t\t" + " Environment.OSVersion.Platform == PlatformID.Win32S ||");
sw.WriteLine(indent + "\t\t\t" + " Environment.OSVersion.Platform == PlatformID.Win32Windows ||");
sw.WriteLine(indent + "\t\t\t" + " Environment.OSVersion.Platform == PlatformID.WinCE)");
if (retval.IsVoid) {
sw.WriteLine(indent + "\t\t\t\t" + CName + "_utf8" + call + ";");
sw.WriteLine(indent + "\t\t\t" + "else");
sw.WriteLine(indent + "\t\t\t\t" + CName + call + ";");
} else {
sw.WriteLine(indent + "\t\t\t\traw_ret = " + CName + "_utf8" + call + ";");
sw.WriteLine(indent + "\t\t\t" + "else");
sw.WriteLine(indent + "\t\t\t\traw_ret = " + CName + call + ";");
sw.WriteLine(indent + "\t\t\t" + retval.CSType + " ret = " + retval.FromNative ("raw_ret") + ";");
}
} else {
sw.Write(indent + "\t\t\t");
if (retval.IsVoid)
sw.WriteLine(CName + call + ";");
else {
sw.WriteLine(retval.MarshalType + " raw_ret = " + CName + call + ";");
sw.WriteLine(indent + "\t\t\t" + retval.CSType + " ret = " + retval.FromNative ("raw_ret") + ";");
}
}
if (!IsStatic && implementor != null)
implementor.Finish (sw, indent + "\t\t\t");
Body.Finish (sw, indent);
Body.HandleException (sw, indent);
if (is_get && Parameters.Count > 0)
sw.WriteLine (indent + "\t\t\treturn " + Parameters.AccessorName + ";");
else if (!retval.IsVoid)
sw.WriteLine (indent + "\t\t\treturn ret;");
else if (IsAccessor)
Body.FinishAccessor (sw, Signature, indent);
sw.Write(indent + "\t\t}");
}
bool IsAccessor {
get {
return retval.IsVoid && Signature.IsAccessor;
}
}
}
}
// GtkSharp.Generation.Method.cs - The Method Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// 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;
using System.Xml;
public class Method : MethodBase {
private ReturnValue retval;
private string call;
private bool is_get, is_set;
private bool deprecated = false;
private bool win32_utf8_variant = false;
public Method (XmlElement elem, ClassBase container_type) : base (elem, container_type)
{
this.retval = new ReturnValue (elem["return-type"]);
if (!container_type.IsDeprecated) {
deprecated = elem.GetAttributeAsBoolean ("deprecated");
}
win32_utf8_variant = elem.GetAttributeAsBoolean ("win32_utf8_variant");
if (Name == "GetType")
Name = "GetGType";
}
public bool HasWin32Utf8Variant {
get { return win32_utf8_variant; }
}
public bool IsDeprecated {
get {
return deprecated;
}
}
public bool IsGetter {
get {
return is_get;
}
}
public bool IsSetter {
get {
return is_set;
}
}
public string ReturnType {
get {
return retval.CSType;
}
}
public override bool Validate (LogWriter log)
{
log.Member = Name;
if (!retval.Validate (log) || !base.Validate (log))
return false;
Parameters parms = Parameters;
is_get = ((((parms.IsAccessor && retval.IsVoid) || (parms.Count == 0 && !retval.IsVoid)) || (parms.Count == 0 && !retval.IsVoid)) && HasGetterName);
is_set = ((parms.IsAccessor || (parms.VisibleCount == 1 && retval.IsVoid)) && HasSetterName);
call = "(" + (IsStatic ? "" : container_type.CallByName () + (parms.Count > 0 ? ", " : "")) + Body.GetCallString (is_set) + ")";
return true;
}
private Method GetComplement ()
{
char complement;
if (is_get)
complement = 'S';
else
complement = 'G';
return container_type.GetMethod (complement + BaseName.Substring (1));
}
public string Declaration {
get {
return retval.CSType + " " + Name + " (" + (Signature != null ? Signature.ToString() : "") + ");";
}
}
private void GenerateDeclCommon (StreamWriter sw, ClassBase implementor)
{
if (IsStatic)
sw.Write("static ");
sw.Write (Safety);
Method dup = null;
if (container_type != null)
dup = container_type.GetMethodRecursively (Name);
if (implementor != null)
dup = implementor.GetMethodRecursively (Name);
if (Name == "ToString" && Parameters.Count == 0 && (!(container_type is InterfaceGen)|| implementor != null))
sw.Write("override ");
else if (Name == "GetGType" && container_type is ObjectGen)
sw.Write("new ");
else if (Modifiers == "new " || (dup != null && ((dup.Signature != null && Signature != null && dup.Signature.ToString() == Signature.ToString()) || (dup.Signature == null && Signature == null))))
sw.Write("new ");
if (is_get || is_set) {
if (retval.IsVoid)
sw.Write (Parameters.AccessorReturnType);
else
sw.Write(retval.CSType);
sw.Write(" ");
if (Name.StartsWith ("Get") || Name.StartsWith ("Set"))
sw.Write (Name.Substring (3));
else {
int dot = Name.LastIndexOf ('.');
if (dot != -1 && (Name.Substring (dot + 1, 3) == "Get" || Name.Substring (dot + 1, 3) == "Set"))
sw.Write (Name.Substring (0, dot + 1) + Name.Substring (dot + 4));
else
sw.Write (Name);
}
sw.WriteLine(" { ");
} else if (IsAccessor) {
sw.Write (Signature.AccessorType + " " + Name + "(" + Signature.AsAccessor + ")");
} else {
sw.Write(retval.CSType + " " + Name + "(" + (Signature != null ? Signature.ToString() : "") + ")");
}
}
public void GenerateDecl (StreamWriter sw)
{
if (IsStatic)
return;
if (is_get || is_set)
{
Method comp = GetComplement ();
if (comp != null && is_set)
return;
sw.Write("\t\t");
GenerateDeclCommon (sw, null);
sw.Write("\t\t\t");
sw.Write ((is_get) ? "get;" : "set;");
if (comp != null && comp.is_set)
sw.WriteLine (" set;");
else
sw.WriteLine ();
sw.WriteLine ("\t\t}");
}
else
{
sw.Write("\t\t");
GenerateDeclCommon (sw, null);
sw.WriteLine (";");
}
Statistics.MethodCount++;
}
public void GenerateImport (StreamWriter sw)
{
string import_sig = IsStatic ? "" : container_type.MarshalType + " raw";
import_sig += !IsStatic && Parameters.Count > 0 ? ", " : "";
import_sig += Parameters.ImportSignature.ToString();
sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\", CallingConvention = CallingConvention.Cdecl)]");
if (retval.MarshalType.StartsWith ("[return:"))
sw.WriteLine("\t\t" + retval.MarshalType + " static extern " + Safety + retval.CSType + " " + CName + "(" + import_sig + ");");
else
sw.WriteLine("\t\tstatic extern " + Safety + retval.MarshalType + " " + CName + "(" + import_sig + ");");
sw.WriteLine();
if (HasWin32Utf8Variant) {
sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\")]");
if (retval.MarshalType.StartsWith ("[return:"))
sw.WriteLine("\t\t" + retval.MarshalType + " static extern " + Safety + retval.CSType + " " + CName + "_utf8(" + import_sig + ");");
else
sw.WriteLine("\t\tstatic extern " + Safety + retval.MarshalType + " " + CName + "_utf8(" + import_sig + ");");
sw.WriteLine();
}
}
public void Generate (GenerationInfo gen_info, ClassBase implementor)
{
Method comp = null;
gen_info.CurrentMember = Name;
/* we are generated by the get Method, if there is one */
if (is_set || is_get)
{
if (Modifiers != "new " && container_type.GetPropertyRecursively (Name.Substring (3)) != null)
return;
comp = GetComplement ();
if (comp != null && is_set) {
if (Parameters.AccessorReturnType == comp.ReturnType)
return;
else {
is_set = false;
call = "(Handle, " + Body.GetCallString (false) + ")";
comp = null;
}
}
/* some setters take more than one arg */
if (comp != null && !comp.is_set)
comp = null;
}
GenerateImport (gen_info.Writer);
if (comp != null && retval.CSType == comp.Parameters.AccessorReturnType)
comp.GenerateImport (gen_info.Writer);
if (IsDeprecated)
gen_info.Writer.WriteLine("\t\t[Obsolete]");
gen_info.Writer.Write("\t\t");
if (Protection != "")
gen_info.Writer.Write("{0} ", Protection);
GenerateDeclCommon (gen_info.Writer, implementor);
if (is_get || is_set)
{
gen_info.Writer.Write ("\t\t\t");
gen_info.Writer.Write ((is_get) ? "get" : "set");
GenerateBody (gen_info, implementor, "\t");
}
else
GenerateBody (gen_info, implementor, "");
if (is_get || is_set)
{
if (comp != null && retval.CSType == comp.Parameters.AccessorReturnType)
{
gen_info.Writer.WriteLine ();
gen_info.Writer.Write ("\t\t\tset");
comp.GenerateBody (gen_info, implementor, "\t");
}
gen_info.Writer.WriteLine ();
gen_info.Writer.WriteLine ("\t\t}");
}
else
gen_info.Writer.WriteLine();
gen_info.Writer.WriteLine();
Statistics.MethodCount++;
}
public void GenerateBody (GenerationInfo gen_info, ClassBase implementor, string indent)
{
StreamWriter sw = gen_info.Writer;
sw.WriteLine(" {");
if (!IsStatic && implementor != null)
implementor.Prepare (sw, indent + "\t\t\t");
if (IsAccessor)
Body.InitAccessor (sw, Signature, indent);
Body.Initialize(gen_info, is_get, is_set, indent);
if (HasWin32Utf8Variant) {
if (!retval.IsVoid)
sw.WriteLine(indent + "\t\t\t" + retval.MarshalType + " raw_ret;");
sw.WriteLine(indent + "\t\t\t" + "if (Environment.OSVersion.Platform == PlatformID.Win32NT ||");
sw.WriteLine(indent + "\t\t\t" + " Environment.OSVersion.Platform == PlatformID.Win32S ||");
sw.WriteLine(indent + "\t\t\t" + " Environment.OSVersion.Platform == PlatformID.Win32Windows ||");
sw.WriteLine(indent + "\t\t\t" + " Environment.OSVersion.Platform == PlatformID.WinCE)");
if (retval.IsVoid) {
sw.WriteLine(indent + "\t\t\t\t" + CName + "_utf8" + call + ";");
sw.WriteLine(indent + "\t\t\t" + "else");
sw.WriteLine(indent + "\t\t\t\t" + CName + call + ";");
} else {
sw.WriteLine(indent + "\t\t\t\traw_ret = " + CName + "_utf8" + call + ";");
sw.WriteLine(indent + "\t\t\t" + "else");
sw.WriteLine(indent + "\t\t\t\traw_ret = " + CName + call + ";");
sw.WriteLine(indent + "\t\t\t" + retval.CSType + " ret = " + retval.FromNative ("raw_ret") + ";");
}
} else {
sw.Write(indent + "\t\t\t");
if (retval.IsVoid)
sw.WriteLine(CName + call + ";");
else {
sw.WriteLine(retval.MarshalType + " raw_ret = " + CName + call + ";");
sw.WriteLine(indent + "\t\t\t" + retval.CSType + " ret = " + retval.FromNative ("raw_ret") + ";");
}
}
if (!IsStatic && implementor != null)
implementor.Finish (sw, indent + "\t\t\t");
Body.Finish (sw, indent);
Body.HandleException (sw, indent);
if (is_get && Parameters.Count > 0)
sw.WriteLine (indent + "\t\t\treturn " + Parameters.AccessorName + ";");
else if (!retval.IsVoid)
sw.WriteLine (indent + "\t\t\treturn ret;");
else if (IsAccessor)
Body.FinishAccessor (sw, Signature, indent);
sw.Write(indent + "\t\t}");
}
bool IsAccessor {
get {
return retval.IsVoid && Signature.IsAccessor;
}
}
}
}

View File

@ -1,183 +1,183 @@
// GtkSharp.Generation.MethodBase.cs - function element base class.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2004-2005 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.Xml;
public abstract class MethodBase {
protected XmlElement elem;
protected ClassBase container_type;
protected Parameters parms;
string mods = String.Empty;
string name;
private string protection = "public";
protected MethodBase (XmlElement elem, ClassBase container_type)
{
this.elem = elem;
this.container_type = container_type;
this.name = elem.GetAttribute ("name");
parms = new Parameters (elem ["parameters"]);
IsStatic = elem.GetAttribute ("shared") == "true";
if (elem.GetAttributeAsBoolean ("new_flag"))
mods = "new ";
if (elem.HasAttribute ("accessibility")) {
string attr = elem.GetAttribute ("accessibility");
switch (attr) {
case "public":
case "protected":
case "internal":
case "private":
case "protected internal":
protection = attr;
break;
}
}
}
protected string BaseName {
get {
string name = Name;
int idx = Name.LastIndexOf (".");
if (idx > 0)
name = Name.Substring (idx + 1);
return name;
}
}
MethodBody body;
public MethodBody Body {
get {
if (body == null)
body = new MethodBody (parms);
return body;
}
}
public virtual string CName {
get {
return SymbolTable.Table.MangleName (elem.GetAttribute ("cname"));
}
}
protected bool HasGetterName {
get {
string name = BaseName;
if (name.Length <= 3)
return false;
if (name.StartsWith ("Get") || name.StartsWith ("Has"))
return Char.IsUpper (name [3]);
else if (name.StartsWith ("Is"))
return Char.IsUpper (name [2]);
else
return false;
}
}
protected bool HasSetterName {
get {
string name = BaseName;
if (name.Length <= 3)
return false;
return name.StartsWith ("Set") && Char.IsUpper (name [3]);
}
}
public bool IsStatic {
get {
return parms.Static;
}
set {
parms.Static = value;
}
}
public string LibraryName {
get {
if (elem.HasAttribute ("library"))
return elem.GetAttribute ("library");
return container_type.LibraryName;
}
}
public string Modifiers {
get {
return mods;
}
set {
mods = value;
}
}
public string Name {
get {
return name;
}
set {
name = value;
}
}
public Parameters Parameters {
get {
return parms;
}
}
public string Protection {
get { return protection; }
set { protection = value; }
}
protected string Safety {
get {
return Body.ThrowsException && !(container_type is InterfaceGen) ? "unsafe " : "";
}
}
Signature sig;
public Signature Signature {
get {
if (sig == null)
sig = new Signature (parms);
return sig;
}
}
public virtual bool Validate (LogWriter log)
{
log.Member = Name;
if (!parms.Validate (log)) {
Statistics.ThrottledCount++;
return false;
}
return true;
}
}
}
// GtkSharp.Generation.MethodBase.cs - function element base class.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2004-2005 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.Xml;
public abstract class MethodBase {
protected XmlElement elem;
protected ClassBase container_type;
protected Parameters parms;
string mods = String.Empty;
string name;
private string protection = "public";
protected MethodBase (XmlElement elem, ClassBase container_type)
{
this.elem = elem;
this.container_type = container_type;
this.name = elem.GetAttribute ("name");
parms = new Parameters (elem ["parameters"]);
IsStatic = elem.GetAttribute ("shared") == "true";
if (elem.GetAttributeAsBoolean ("new_flag"))
mods = "new ";
if (elem.HasAttribute ("accessibility")) {
string attr = elem.GetAttribute ("accessibility");
switch (attr) {
case "public":
case "protected":
case "internal":
case "private":
case "protected internal":
protection = attr;
break;
}
}
}
protected string BaseName {
get {
string name = Name;
int idx = Name.LastIndexOf (".");
if (idx > 0)
name = Name.Substring (idx + 1);
return name;
}
}
MethodBody body;
public MethodBody Body {
get {
if (body == null)
body = new MethodBody (parms);
return body;
}
}
public virtual string CName {
get {
return SymbolTable.Table.MangleName (elem.GetAttribute ("cname"));
}
}
protected bool HasGetterName {
get {
string name = BaseName;
if (name.Length <= 3)
return false;
if (name.StartsWith ("Get") || name.StartsWith ("Has"))
return Char.IsUpper (name [3]);
else if (name.StartsWith ("Is"))
return Char.IsUpper (name [2]);
else
return false;
}
}
protected bool HasSetterName {
get {
string name = BaseName;
if (name.Length <= 3)
return false;
return name.StartsWith ("Set") && Char.IsUpper (name [3]);
}
}
public bool IsStatic {
get {
return parms.Static;
}
set {
parms.Static = value;
}
}
public string LibraryName {
get {
if (elem.HasAttribute ("library"))
return elem.GetAttribute ("library");
return container_type.LibraryName;
}
}
public string Modifiers {
get {
return mods;
}
set {
mods = value;
}
}
public string Name {
get {
return name;
}
set {
name = value;
}
}
public Parameters Parameters {
get {
return parms;
}
}
public string Protection {
get { return protection; }
set { protection = value; }
}
protected string Safety {
get {
return Body.ThrowsException && !(container_type is InterfaceGen) ? "unsafe " : "";
}
}
Signature sig;
public Signature Signature {
get {
if (sig == null)
sig = new Signature (parms);
return sig;
}
}
public virtual bool Validate (LogWriter log)
{
log.Member = Name;
if (!parms.Validate (log)) {
Statistics.ThrottledCount++;
return false;
}
return true;
}
}
}

View File

@ -1,180 +1,180 @@
// GtkSharp.Generation.MethodBody.cs - The MethodBody Generation Class.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// 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;
public class MethodBody {
Parameters parameters;
public MethodBody (Parameters parms)
{
parameters = parms;
}
private string CastFromInt (string type)
{
return type != "int" ? "(" + type + ") " : "";
}
public string GetCallString (bool is_set)
{
if (parameters.Count == 0)
return String.Empty;
string[] result = new string [parameters.Count];
for (int i = 0; i < parameters.Count; i++) {
Parameter p = parameters [i];
IGeneratable igen = p.Generatable;
bool is_prop = is_set && i == 0;
if (i > 0 && parameters [i - 1].IsString && p.IsLength && p.PassAs == String.Empty) {
string string_name = (i == 1 && is_set) ? "value" : parameters [i - 1].Name;
result[i] = igen.CallByName (CastFromInt (p.CSType) + "System.Text.Encoding.UTF8.GetByteCount (" + string_name + ")");
continue;
}
if (is_prop)
p.CallName = "value";
else
p.CallName = p.Name;
string call_parm = p.CallString;
if (p.IsUserData && parameters.IsHidden (p) && !parameters.HideData &&
(i == 0 || parameters [i - 1].Scope != "notified")) {
call_parm = "IntPtr.Zero";
}
result [i] += call_parm;
}
return String.Join (", ", result);
}
public void Initialize (GenerationInfo gen_info)
{
Initialize (gen_info, false, false, String.Empty);
}
public void Initialize (GenerationInfo gen_info, bool is_get, bool is_set, string indent)
{
if (parameters.Count == 0)
return;
StreamWriter sw = gen_info.Writer;
for (int i = 0; i < parameters.Count; i++) {
Parameter p = parameters [i];
IGeneratable gen = p.Generatable;
string name = p.Name;
if (is_set)
name = "value";
p.CallName = name;
foreach (string prep in p.Prepare)
sw.WriteLine (indent + "\t\t\t" + prep);
if (gen is CallbackGen) {
CallbackGen cbgen = gen as CallbackGen;
string wrapper = cbgen.GenWrapper(gen_info);
switch (p.Scope) {
case "notified":
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", wrapper, name);
sw.WriteLine (indent + "\t\t\tIntPtr {0};", parameters [i + 1].Name);
sw.WriteLine (indent + "\t\t\t{0} {1};", parameters [i + 2].CSType, parameters [i + 2].Name);
sw.WriteLine (indent + "\t\t\tif ({0} == null) {{", name);
sw.WriteLine (indent + "\t\t\t\t{0} = IntPtr.Zero;", parameters [i + 1].Name);
sw.WriteLine (indent + "\t\t\t\t{0} = null;", parameters [i + 2].Name);
sw.WriteLine (indent + "\t\t\t} else {");
sw.WriteLine (indent + "\t\t\t\t{0} = (IntPtr) GCHandle.Alloc ({1}_wrapper);", parameters [i + 1].Name, name);
sw.WriteLine (indent + "\t\t\t\t{0} = GLib.DestroyHelper.NotifyHandler;", parameters [i + 2].Name, parameters [i + 2].CSType);
sw.WriteLine (indent + "\t\t\t}");
break;
case "async":
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", wrapper, name);
sw.WriteLine (indent + "\t\t\t{0}_wrapper.PersistUntilCalled ();", name);
break;
case "call":
default:
if (p.Scope == String.Empty)
Console.WriteLine (gen_info.CurrentMember + " - defaulting " + gen.Name + " param to 'call' scope. Specify callback scope (call|async|notified) attribute with fixup.");
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", wrapper, name);
break;
}
}
}
if (ThrowsException)
sw.WriteLine (indent + "\t\t\tIntPtr error = IntPtr.Zero;");
}
public void InitAccessor (StreamWriter sw, Signature sig, string indent)
{
sw.WriteLine (indent + "\t\t\t" + sig.AccessorType + " " + sig.AccessorName + ";");
}
public void Finish (StreamWriter sw, string indent)
{
foreach (Parameter p in parameters) {
if (parameters.IsHidden (p))
continue;
foreach (string s in p.Finish)
sw.WriteLine(indent + "\t\t\t" + s);
}
}
public void FinishAccessor (StreamWriter sw, Signature sig, string indent)
{
sw.WriteLine (indent + "\t\t\treturn " + sig.AccessorName + ";");
}
public void HandleException (StreamWriter sw, string indent)
{
if (!ThrowsException)
return;
sw.WriteLine (indent + "\t\t\tif (error != IntPtr.Zero) throw new GLib.GException (error);");
}
public bool ThrowsException {
get {
int idx = parameters.Count - 1;
while (idx >= 0) {
if (parameters [idx].IsUserData)
idx--;
else if (parameters [idx].CType == "GError**")
return true;
else
break;
}
return false;
}
}
}
}
// GtkSharp.Generation.MethodBody.cs - The MethodBody Generation Class.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// 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;
public class MethodBody {
Parameters parameters;
public MethodBody (Parameters parms)
{
parameters = parms;
}
private string CastFromInt (string type)
{
return type != "int" ? "(" + type + ") " : "";
}
public string GetCallString (bool is_set)
{
if (parameters.Count == 0)
return String.Empty;
string[] result = new string [parameters.Count];
for (int i = 0; i < parameters.Count; i++) {
Parameter p = parameters [i];
IGeneratable igen = p.Generatable;
bool is_prop = is_set && i == 0;
if (i > 0 && parameters [i - 1].IsString && p.IsLength && p.PassAs == String.Empty) {
string string_name = (i == 1 && is_set) ? "value" : parameters [i - 1].Name;
result[i] = igen.CallByName (CastFromInt (p.CSType) + "System.Text.Encoding.UTF8.GetByteCount (" + string_name + ")");
continue;
}
if (is_prop)
p.CallName = "value";
else
p.CallName = p.Name;
string call_parm = p.CallString;
if (p.IsUserData && parameters.IsHidden (p) && !parameters.HideData &&
(i == 0 || parameters [i - 1].Scope != "notified")) {
call_parm = "IntPtr.Zero";
}
result [i] += call_parm;
}
return String.Join (", ", result);
}
public void Initialize (GenerationInfo gen_info)
{
Initialize (gen_info, false, false, String.Empty);
}
public void Initialize (GenerationInfo gen_info, bool is_get, bool is_set, string indent)
{
if (parameters.Count == 0)
return;
StreamWriter sw = gen_info.Writer;
for (int i = 0; i < parameters.Count; i++) {
Parameter p = parameters [i];
IGeneratable gen = p.Generatable;
string name = p.Name;
if (is_set)
name = "value";
p.CallName = name;
foreach (string prep in p.Prepare)
sw.WriteLine (indent + "\t\t\t" + prep);
if (gen is CallbackGen) {
CallbackGen cbgen = gen as CallbackGen;
string wrapper = cbgen.GenWrapper(gen_info);
switch (p.Scope) {
case "notified":
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", wrapper, name);
sw.WriteLine (indent + "\t\t\tIntPtr {0};", parameters [i + 1].Name);
sw.WriteLine (indent + "\t\t\t{0} {1};", parameters [i + 2].CSType, parameters [i + 2].Name);
sw.WriteLine (indent + "\t\t\tif ({0} == null) {{", name);
sw.WriteLine (indent + "\t\t\t\t{0} = IntPtr.Zero;", parameters [i + 1].Name);
sw.WriteLine (indent + "\t\t\t\t{0} = null;", parameters [i + 2].Name);
sw.WriteLine (indent + "\t\t\t} else {");
sw.WriteLine (indent + "\t\t\t\t{0} = (IntPtr) GCHandle.Alloc ({1}_wrapper);", parameters [i + 1].Name, name);
sw.WriteLine (indent + "\t\t\t\t{0} = GLib.DestroyHelper.NotifyHandler;", parameters [i + 2].Name, parameters [i + 2].CSType);
sw.WriteLine (indent + "\t\t\t}");
break;
case "async":
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", wrapper, name);
sw.WriteLine (indent + "\t\t\t{0}_wrapper.PersistUntilCalled ();", name);
break;
case "call":
default:
if (p.Scope == String.Empty)
Console.WriteLine (gen_info.CurrentMember + " - defaulting " + gen.Name + " param to 'call' scope. Specify callback scope (call|async|notified) attribute with fixup.");
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", wrapper, name);
break;
}
}
}
if (ThrowsException)
sw.WriteLine (indent + "\t\t\tIntPtr error = IntPtr.Zero;");
}
public void InitAccessor (StreamWriter sw, Signature sig, string indent)
{
sw.WriteLine (indent + "\t\t\t" + sig.AccessorType + " " + sig.AccessorName + ";");
}
public void Finish (StreamWriter sw, string indent)
{
foreach (Parameter p in parameters) {
if (parameters.IsHidden (p))
continue;
foreach (string s in p.Finish)
sw.WriteLine(indent + "\t\t\t" + s);
}
}
public void FinishAccessor (StreamWriter sw, Signature sig, string indent)
{
sw.WriteLine (indent + "\t\t\treturn " + sig.AccessorName + ";");
}
public void HandleException (StreamWriter sw, string indent)
{
if (!ThrowsException)
return;
sw.WriteLine (indent + "\t\t\tif (error != IntPtr.Zero) throw new GLib.GException (error);");
}
public bool ThrowsException {
get {
int idx = parameters.Count - 1;
while (idx >= 0) {
if (parameters [idx].IsUserData)
idx--;
else if (parameters [idx].CType == "GError**")
return true;
else
break;
}
return false;
}
}
}
}

View File

@ -1,417 +1,417 @@
// 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;
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:
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)
{
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);
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
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);
}
sw.WriteLine (" {");
sw.WriteLine ();
GenCtors (gen_info);
GenProperties (gen_info, null);
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")) {
GenSignals (gen_info, null);
}
GenClassMembers (gen_info, cs_parent);
GenMethods (gen_info, null, null);
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;
}
}
foreach (string iface in interfaces) {
if (Parent != null && Parent.Implements (iface))
continue;
InterfaceGen igen = table.GetClassGen (iface) as InterfaceGen;
igen.GenMethods (gen_info, collisions, this);
igen.GenProperties (gen_info, this);
igen.GenSignals (gen_info, this);
igen.GenVirtualMethods (gen_info, this);
}
}
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}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
Statistics.ObjectCount++;
}
protected override void GenCtors (GenerationInfo gen_info)
{
if (!Elem.HasAttribute("parent"))
return;
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}");
}
gen_info.Writer.WriteLine();
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 ();
}
/* 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);
}
}
throw new ArgumentException ("cname doesn't follow the NamespaceType capitalization style: " + cname);
}
private static bool NeedsMap (Hashtable objs, string assembly_name)
{
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))
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;");
foreach (string key in dir_info.objects.Keys) {
if (GetExpected(key) != ((string) dir_info.objects[key]))
sw.WriteLine ("\t\t\tGLib.GType.Register ({0}.GType, typeof ({0}));", dir_info.objects [key]);
}
sw.WriteLine ("\t\t}");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
}
}
}
// 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;
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:
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)
{
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);
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
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);
}
sw.WriteLine (" {");
sw.WriteLine ();
GenCtors (gen_info);
GenProperties (gen_info, null);
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")) {
GenSignals (gen_info, null);
}
GenClassMembers (gen_info, cs_parent);
GenMethods (gen_info, null, null);
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;
}
}
foreach (string iface in interfaces) {
if (Parent != null && Parent.Implements (iface))
continue;
InterfaceGen igen = table.GetClassGen (iface) as InterfaceGen;
igen.GenMethods (gen_info, collisions, this);
igen.GenProperties (gen_info, this);
igen.GenSignals (gen_info, this);
igen.GenVirtualMethods (gen_info, this);
}
}
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}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
Statistics.ObjectCount++;
}
protected override void GenCtors (GenerationInfo gen_info)
{
if (!Elem.HasAttribute("parent"))
return;
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}");
}
gen_info.Writer.WriteLine();
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 ();
}
/* 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);
}
}
throw new ArgumentException ("cname doesn't follow the NamespaceType capitalization style: " + cname);
}
private static bool NeedsMap (Hashtable objs, string assembly_name)
{
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))
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;");
foreach (string key in dir_info.objects.Keys) {
if (GetExpected(key) != ((string) dir_info.objects[key]))
sw.WriteLine ("\t\t\tGLib.GType.Register ({0}.GType, typeof ({0}));", dir_info.objects [key]);
}
sw.WriteLine ("\t\t}");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
}
}
}

View File

@ -1,235 +1,235 @@
// GtkSharp.Generation.OpaqueGen.cs - The Opaque Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001-2003 Mike Kestner
//
// 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;
using System.Xml;
public class OpaqueGen : HandleBase {
public OpaqueGen (XmlElement ns, XmlElement elem) : base (ns, elem) {}
public override string FromNative(string var, bool owned)
{
return var + " == IntPtr.Zero ? null : (" + QualifiedName + ") GLib.Opaque.GetOpaque (" + var + ", typeof (" + QualifiedName + "), " + (owned ? "true" : "false") + ")";
}
private bool DisableRawCtor {
get {
return Elem.GetAttributeAsBoolean ("disable_raw_ctor");
}
}
public override void Generate (GenerationInfo gen_info)
{
gen_info.CurrentType = QualifiedName;
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Collections;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
SymbolTable table = SymbolTable.Table;
Method ref_, unref, dispose;
GetSpecialMethods (out ref_, out unref, out dispose);
if (IsDeprecated)
sw.WriteLine ("\t[Obsolete]");
sw.Write ("\t{0} partial {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : String.Empty);
string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));
if (cs_parent != "")
sw.Write (" : " + cs_parent);
else
sw.Write (" : GLib.Opaque");
foreach (string iface in managed_interfaces) {
if (Parent != null && Parent.Implements (iface))
continue;
sw.Write (", " + iface);
}
sw.WriteLine (" {");
sw.WriteLine ();
GenFields (gen_info);
GenMethods (gen_info, null, null);
GenCtors (gen_info);
if (ref_ != null) {
ref_.GenerateImport (sw);
sw.WriteLine ("\t\tprotected override void Ref (IntPtr raw)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (!Owned) {");
sw.WriteLine ("\t\t\t\t" + ref_.CName + " (raw);");
sw.WriteLine ("\t\t\t\tOwned = true;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
if (ref_.IsDeprecated) {
sw.WriteLine ("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
if (ref_.ReturnType == "void")
sw.WriteLine ("\t\tpublic void Ref () {}");
else
sw.WriteLine ("\t\tpublic " + Name + " Ref () { return this; }");
sw.WriteLine ();
}
}
bool finalizer_needed = false;
if (unref != null) {
unref.GenerateImport (sw);
sw.WriteLine ("\t\tprotected override void Unref (IntPtr raw)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (Owned) {");
sw.WriteLine ("\t\t\t\t" + unref.CName + " (raw);");
sw.WriteLine ("\t\t\t\tOwned = false;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
if (unref.IsDeprecated) {
sw.WriteLine ("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
sw.WriteLine ("\t\tpublic void Unref () {}");
sw.WriteLine ();
}
finalizer_needed = true;
}
if (dispose != null) {
dispose.GenerateImport (sw);
sw.WriteLine ("\t\tprotected override void Free (IntPtr raw)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\t" + dispose.CName + " (raw);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
if (dispose.IsDeprecated) {
sw.WriteLine ("\t\t[Obsolete(\"" + QualifiedName + " is now freed automatically\")]");
sw.WriteLine ("\t\tpublic void " + dispose.Name + " () {}");
sw.WriteLine ();
}
finalizer_needed = true;
}
if (finalizer_needed) {
sw.WriteLine ("\t\tclass FinalizerInfo {");
sw.WriteLine ("\t\t\tIntPtr handle;");
sw.WriteLine ();
sw.WriteLine ("\t\t\tpublic FinalizerInfo (IntPtr handle)");
sw.WriteLine ("\t\t\t{");
sw.WriteLine ("\t\t\t\tthis.handle = handle;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\t\tpublic bool Handler ()");
sw.WriteLine ("\t\t\t{");
if (dispose != null)
sw.WriteLine ("\t\t\t\t{0} (handle);", dispose.CName);
else if (unref != null)
sw.WriteLine ("\t\t\t\t{0} (handle);", unref.CName);
sw.WriteLine ("\t\t\t\treturn false;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\t~{0} ()", Name);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (!Owned)");
sw.WriteLine ("\t\t\t\treturn;");
sw.WriteLine ("\t\t\tFinalizerInfo info = new FinalizerInfo (Handle);");
sw.WriteLine ("\t\t\tGLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
#if false
Method copy = Methods ["Copy"] as Method;
if (copy != null && copy.Parameters.Count == 0) {
sw.WriteLine ("\t\tprotected override GLib.Opaque Copy (IntPtr raw)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tGLib.Opaque result = new " + QualifiedName + " (" + copy.CName + " (raw));");
sw.WriteLine ("\t\t\tresult.Owned = true;");
sw.WriteLine ("\t\t\treturn result;");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
#endif
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
Statistics.OpaqueCount++;
}
void GetSpecialMethods (out Method ref_, out Method unref, out Method dispose)
{
ref_ = CheckSpecialMethod (GetMethod ("Ref"));
unref = CheckSpecialMethod (GetMethod ("Unref"));
dispose = GetMethod ("Free");
if (dispose == null) {
dispose = GetMethod ("Destroy");
if (dispose == null)
dispose = GetMethod ("Dispose");
}
dispose = CheckSpecialMethod (dispose);
}
Method CheckSpecialMethod (Method method)
{
if (method == null)
return null;
if (method.ReturnType != "void" &&
method.ReturnType != QualifiedName)
return null;
if (method.Signature.ToString () != "")
return null;
methods.Remove (method.Name);
return method;
}
protected override void GenCtors (GenerationInfo gen_info)
{
if (!DisableRawCtor) {
gen_info.Writer.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}");
gen_info.Writer.WriteLine();
}
base.GenCtors (gen_info);
}
}
}
// GtkSharp.Generation.OpaqueGen.cs - The Opaque Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001-2003 Mike Kestner
//
// 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;
using System.Xml;
public class OpaqueGen : HandleBase {
public OpaqueGen (XmlElement ns, XmlElement elem) : base (ns, elem) {}
public override string FromNative(string var, bool owned)
{
return var + " == IntPtr.Zero ? null : (" + QualifiedName + ") GLib.Opaque.GetOpaque (" + var + ", typeof (" + QualifiedName + "), " + (owned ? "true" : "false") + ")";
}
private bool DisableRawCtor {
get {
return Elem.GetAttributeAsBoolean ("disable_raw_ctor");
}
}
public override void Generate (GenerationInfo gen_info)
{
gen_info.CurrentType = QualifiedName;
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Collections;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
SymbolTable table = SymbolTable.Table;
Method ref_, unref, dispose;
GetSpecialMethods (out ref_, out unref, out dispose);
if (IsDeprecated)
sw.WriteLine ("\t[Obsolete]");
sw.Write ("\t{0} partial {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : String.Empty);
string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));
if (cs_parent != "")
sw.Write (" : " + cs_parent);
else
sw.Write (" : GLib.Opaque");
foreach (string iface in managed_interfaces) {
if (Parent != null && Parent.Implements (iface))
continue;
sw.Write (", " + iface);
}
sw.WriteLine (" {");
sw.WriteLine ();
GenFields (gen_info);
GenMethods (gen_info, null, null);
GenCtors (gen_info);
if (ref_ != null) {
ref_.GenerateImport (sw);
sw.WriteLine ("\t\tprotected override void Ref (IntPtr raw)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (!Owned) {");
sw.WriteLine ("\t\t\t\t" + ref_.CName + " (raw);");
sw.WriteLine ("\t\t\t\tOwned = true;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
if (ref_.IsDeprecated) {
sw.WriteLine ("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
if (ref_.ReturnType == "void")
sw.WriteLine ("\t\tpublic void Ref () {}");
else
sw.WriteLine ("\t\tpublic " + Name + " Ref () { return this; }");
sw.WriteLine ();
}
}
bool finalizer_needed = false;
if (unref != null) {
unref.GenerateImport (sw);
sw.WriteLine ("\t\tprotected override void Unref (IntPtr raw)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (Owned) {");
sw.WriteLine ("\t\t\t\t" + unref.CName + " (raw);");
sw.WriteLine ("\t\t\t\tOwned = false;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
if (unref.IsDeprecated) {
sw.WriteLine ("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
sw.WriteLine ("\t\tpublic void Unref () {}");
sw.WriteLine ();
}
finalizer_needed = true;
}
if (dispose != null) {
dispose.GenerateImport (sw);
sw.WriteLine ("\t\tprotected override void Free (IntPtr raw)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\t" + dispose.CName + " (raw);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
if (dispose.IsDeprecated) {
sw.WriteLine ("\t\t[Obsolete(\"" + QualifiedName + " is now freed automatically\")]");
sw.WriteLine ("\t\tpublic void " + dispose.Name + " () {}");
sw.WriteLine ();
}
finalizer_needed = true;
}
if (finalizer_needed) {
sw.WriteLine ("\t\tclass FinalizerInfo {");
sw.WriteLine ("\t\t\tIntPtr handle;");
sw.WriteLine ();
sw.WriteLine ("\t\t\tpublic FinalizerInfo (IntPtr handle)");
sw.WriteLine ("\t\t\t{");
sw.WriteLine ("\t\t\t\tthis.handle = handle;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\t\tpublic bool Handler ()");
sw.WriteLine ("\t\t\t{");
if (dispose != null)
sw.WriteLine ("\t\t\t\t{0} (handle);", dispose.CName);
else if (unref != null)
sw.WriteLine ("\t\t\t\t{0} (handle);", unref.CName);
sw.WriteLine ("\t\t\t\treturn false;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\t~{0} ()", Name);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (!Owned)");
sw.WriteLine ("\t\t\t\treturn;");
sw.WriteLine ("\t\t\tFinalizerInfo info = new FinalizerInfo (Handle);");
sw.WriteLine ("\t\t\tGLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
#if false
Method copy = Methods ["Copy"] as Method;
if (copy != null && copy.Parameters.Count == 0) {
sw.WriteLine ("\t\tprotected override GLib.Opaque Copy (IntPtr raw)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tGLib.Opaque result = new " + QualifiedName + " (" + copy.CName + " (raw));");
sw.WriteLine ("\t\t\tresult.Owned = true;");
sw.WriteLine ("\t\t\treturn result;");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
#endif
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
Statistics.OpaqueCount++;
}
void GetSpecialMethods (out Method ref_, out Method unref, out Method dispose)
{
ref_ = CheckSpecialMethod (GetMethod ("Ref"));
unref = CheckSpecialMethod (GetMethod ("Unref"));
dispose = GetMethod ("Free");
if (dispose == null) {
dispose = GetMethod ("Destroy");
if (dispose == null)
dispose = GetMethod ("Dispose");
}
dispose = CheckSpecialMethod (dispose);
}
Method CheckSpecialMethod (Method method)
{
if (method == null)
return null;
if (method.ReturnType != "void" &&
method.ReturnType != QualifiedName)
return null;
if (method.Signature.ToString () != "")
return null;
methods.Remove (method.Name);
return method;
}
protected override void GenCtors (GenerationInfo gen_info)
{
if (!DisableRawCtor) {
gen_info.Writer.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}");
gen_info.Writer.WriteLine();
}
base.GenCtors (gen_info);
}
}
}

View File

@ -1,51 +1,51 @@
// GtkSharp.Generation.ManualGen.cs - Ungenerated handle type Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2003 Mike Kestner
// Copyright (c) 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;
public class OwnableGen : SimpleBase, IOwnable {
public OwnableGen (string ctype, string type) : base (ctype, type, "null") {}
public override string MarshalType {
get { return "IntPtr"; }
}
public override string CallByName (string var_name)
{
return var_name + " == null ? IntPtr.Zero : " + var_name + ".Handle";
}
public override string FromNative (string var)
{
return String.Format ("new {0} ({1})", QualifiedName, var);
}
public string FromNative (string var, bool owned)
{
return String.Format ("new {0} ({1}, {2})", QualifiedName, var, owned ? "true" : "false");
}
}
}
// GtkSharp.Generation.ManualGen.cs - Ungenerated handle type Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2003 Mike Kestner
// Copyright (c) 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;
public class OwnableGen : SimpleBase, IOwnable {
public OwnableGen (string ctype, string type) : base (ctype, type, "null") {}
public override string MarshalType {
get { return "IntPtr"; }
}
public override string CallByName (string var_name)
{
return var_name + " == null ? IntPtr.Zero : " + var_name + ".Handle";
}
public override string FromNative (string var)
{
return String.Format ("new {0} ({1})", QualifiedName, var);
}
public string FromNative (string var, bool owned)
{
return String.Format ("new {0} ({1}, {2})", QualifiedName, var, owned ? "true" : "false");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,186 +1,186 @@
// GtkSharp.Generation.Parser.cs - The XML Parsing engine.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2003 Ximian 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;
using System.Xml;
public class Parser {
const int curr_parser_version = 2;
private XmlDocument Load (string filename)
{
XmlDocument doc = new XmlDocument ();
try {
Stream stream = File.OpenRead (filename);
doc.Load (stream);
stream.Close ();
} catch (XmlException e) {
Console.WriteLine ("Invalid XML file.");
Console.WriteLine (e);
doc = null;
}
return doc;
}
public IGeneratable[] Parse (string filename)
{
XmlDocument doc = Load (filename);
if (doc == null)
return null;
XmlElement root = doc.DocumentElement;
if ((root == null) || !root.HasChildNodes) {
Console.WriteLine ("No Namespaces found.");
return null;
}
int parser_version;
if (root.HasAttribute ("parser_version")) {
try {
parser_version = int.Parse (root.GetAttribute ("parser_version"));
} catch {
Console.WriteLine ("ERROR: Unable to parse parser_version attribute value \"{0}\" to a number. Input file {1} will be ignored", root.GetAttribute ("parser_version"), filename);
return null;
}
} else
parser_version = 1;
if (parser_version > curr_parser_version)
Console.WriteLine ("WARNING: The input file {0} was created by a parser that was released after this version of the generator. Consider updating the code generator if you experience problems.", filename);
ArrayList gens = new ArrayList ();
foreach (XmlNode child in root.ChildNodes) {
XmlElement elem = child as XmlElement;
if (elem == null)
continue;
switch (child.Name) {
case "namespace":
gens.AddRange (ParseNamespace (elem));
break;
case "symbol":
gens.Add (ParseSymbol (elem));
break;
default:
Console.WriteLine ("Parser::Parse - Unexpected child node: " + child.Name);
break;
}
}
return (IGeneratable[]) gens.ToArray (typeof (IGeneratable));
}
private ArrayList ParseNamespace (XmlElement ns)
{
ArrayList result = new ArrayList ();
foreach (XmlNode def in ns.ChildNodes) {
XmlElement elem = def as XmlElement;
if (elem == null)
continue;
if (elem.GetAttributeAsBoolean ("hidden"))
continue;
bool is_opaque = elem.GetAttributeAsBoolean ("opaque");
switch (def.Name) {
case "alias":
string aname = elem.GetAttribute("cname");
string atype = elem.GetAttribute("type");
if ((aname == "") || (atype == ""))
continue;
result.Add (new AliasGen (aname, atype));
break;
case "boxed":
result.Add (is_opaque ? new OpaqueGen (ns, elem) as object : new BoxedGen (ns, elem) as object);
break;
case "callback":
result.Add (new CallbackGen (ns, elem));
break;
case "enum":
result.Add (new EnumGen (ns, elem));
break;
case "interface":
result.Add (new InterfaceGen (ns, elem));
break;
case "object":
result.Add (new ObjectGen (ns, elem));
break;
case "class":
result.Add (new ClassGen (ns, elem));
break;
case "struct":
result.Add (is_opaque ? new OpaqueGen (ns, elem) as object : new StructGen (ns, elem) as object);
break;
default:
Console.WriteLine ("Parser::ParseNamespace - Unexpected node: " + def.Name);
break;
}
}
return result;
}
private IGeneratable ParseSymbol (XmlElement symbol)
{
string type = symbol.GetAttribute ("type");
string cname = symbol.GetAttribute ("cname");
string name = symbol.GetAttribute ("name");
IGeneratable result = null;
if (type == "simple") {
if (symbol.HasAttribute ("default_value"))
result = new SimpleGen (cname, name, symbol.GetAttribute ("default_value"));
else {
Console.WriteLine ("Simple type element " + cname + " has no specified default value");
result = new SimpleGen (cname, name, String.Empty);
}
} else if (type == "manual")
result = new ManualGen (cname, name);
else if (type == "ownable")
result = new OwnableGen (cname, name);
else if (type == "alias")
result = new AliasGen (cname, name);
else if (type == "marshal") {
string mtype = symbol.GetAttribute ("marshal_type");
string call = symbol.GetAttribute ("call_fmt");
string from = symbol.GetAttribute ("from_fmt");
result = new MarshalGen (cname, name, mtype, call, from);
} else if (type == "struct") {
result = new ByRefGen (symbol.GetAttribute ("cname"), symbol.GetAttribute ("name"));
} else
Console.WriteLine ("Parser::ParseSymbol - Unexpected symbol type " + type);
return result;
}
}
}
// GtkSharp.Generation.Parser.cs - The XML Parsing engine.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2003 Ximian 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;
using System.Xml;
public class Parser {
const int curr_parser_version = 2;
private XmlDocument Load (string filename)
{
XmlDocument doc = new XmlDocument ();
try {
Stream stream = File.OpenRead (filename);
doc.Load (stream);
stream.Close ();
} catch (XmlException e) {
Console.WriteLine ("Invalid XML file.");
Console.WriteLine (e);
doc = null;
}
return doc;
}
public IGeneratable[] Parse (string filename)
{
XmlDocument doc = Load (filename);
if (doc == null)
return null;
XmlElement root = doc.DocumentElement;
if ((root == null) || !root.HasChildNodes) {
Console.WriteLine ("No Namespaces found.");
return null;
}
int parser_version;
if (root.HasAttribute ("parser_version")) {
try {
parser_version = int.Parse (root.GetAttribute ("parser_version"));
} catch {
Console.WriteLine ("ERROR: Unable to parse parser_version attribute value \"{0}\" to a number. Input file {1} will be ignored", root.GetAttribute ("parser_version"), filename);
return null;
}
} else
parser_version = 1;
if (parser_version > curr_parser_version)
Console.WriteLine ("WARNING: The input file {0} was created by a parser that was released after this version of the generator. Consider updating the code generator if you experience problems.", filename);
ArrayList gens = new ArrayList ();
foreach (XmlNode child in root.ChildNodes) {
XmlElement elem = child as XmlElement;
if (elem == null)
continue;
switch (child.Name) {
case "namespace":
gens.AddRange (ParseNamespace (elem));
break;
case "symbol":
gens.Add (ParseSymbol (elem));
break;
default:
Console.WriteLine ("Parser::Parse - Unexpected child node: " + child.Name);
break;
}
}
return (IGeneratable[]) gens.ToArray (typeof (IGeneratable));
}
private ArrayList ParseNamespace (XmlElement ns)
{
ArrayList result = new ArrayList ();
foreach (XmlNode def in ns.ChildNodes) {
XmlElement elem = def as XmlElement;
if (elem == null)
continue;
if (elem.GetAttributeAsBoolean ("hidden"))
continue;
bool is_opaque = elem.GetAttributeAsBoolean ("opaque");
switch (def.Name) {
case "alias":
string aname = elem.GetAttribute("cname");
string atype = elem.GetAttribute("type");
if ((aname == "") || (atype == ""))
continue;
result.Add (new AliasGen (aname, atype));
break;
case "boxed":
result.Add (is_opaque ? new OpaqueGen (ns, elem) as object : new BoxedGen (ns, elem) as object);
break;
case "callback":
result.Add (new CallbackGen (ns, elem));
break;
case "enum":
result.Add (new EnumGen (ns, elem));
break;
case "interface":
result.Add (new InterfaceGen (ns, elem));
break;
case "object":
result.Add (new ObjectGen (ns, elem));
break;
case "class":
result.Add (new ClassGen (ns, elem));
break;
case "struct":
result.Add (is_opaque ? new OpaqueGen (ns, elem) as object : new StructGen (ns, elem) as object);
break;
default:
Console.WriteLine ("Parser::ParseNamespace - Unexpected node: " + def.Name);
break;
}
}
return result;
}
private IGeneratable ParseSymbol (XmlElement symbol)
{
string type = symbol.GetAttribute ("type");
string cname = symbol.GetAttribute ("cname");
string name = symbol.GetAttribute ("name");
IGeneratable result = null;
if (type == "simple") {
if (symbol.HasAttribute ("default_value"))
result = new SimpleGen (cname, name, symbol.GetAttribute ("default_value"));
else {
Console.WriteLine ("Simple type element " + cname + " has no specified default value");
result = new SimpleGen (cname, name, String.Empty);
}
} else if (type == "manual")
result = new ManualGen (cname, name);
else if (type == "ownable")
result = new OwnableGen (cname, name);
else if (type == "alias")
result = new AliasGen (cname, name);
else if (type == "marshal") {
string mtype = symbol.GetAttribute ("marshal_type");
string call = symbol.GetAttribute ("call_fmt");
string from = symbol.GetAttribute ("from_fmt");
result = new MarshalGen (cname, name, mtype, call, from);
} else if (type == "struct") {
result = new ByRefGen (symbol.GetAttribute ("cname"), symbol.GetAttribute ("name"));
} else
Console.WriteLine ("Parser::ParseSymbol - Unexpected symbol type " + type);
return result;
}
}
}

View File

@ -1,193 +1,193 @@
// GtkSharp.Generation.Property.cs - The Property Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 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;
using System.Xml;
public class Property : PropertyBase {
public Property (XmlElement elem, ClassBase container_type) : base (elem, container_type) {}
public bool Validate (LogWriter log)
{
if (CSType == "" && !Hidden) {
log.Member = Name;
log.Warn ("property has unknown type '{0}' ", CType);
Statistics.ThrottledCount++;
return false;
}
return true;
}
bool Readable {
get {
return elem.GetAttributeAsBoolean ("readable");
}
}
bool Writable {
get {
return elem.GetAttributeAsBoolean ("writeable") &&
!elem.GetAttributeAsBoolean ("construct-only");
}
}
bool IsDeprecated {
get {
return !container_type.IsDeprecated &&
elem.GetAttributeAsBoolean ("deprecated");
}
}
protected virtual string PropertyAttribute (string qpname) {
return "[GLib.Property (" + qpname + ")]";
}
protected virtual string RawGetter (string qpname) {
return "GetProperty (" + qpname + ")";
}
protected virtual string RawSetter (string qpname) {
return "SetProperty(" + qpname + ", val)";
}
public void GenerateDecl (StreamWriter sw, string indent)
{
if (Hidden || (!Readable && !Writable))
return;
string name = Name;
if (name == container_type.Name)
name += "Prop";
sw.WriteLine (indent + CSType + " " + name + " {");
sw.Write (indent + "\t");
if (Readable || Getter != null)
sw.Write ("get; ");
if (Writable || Setter != null)
sw.Write ("set;");
sw.WriteLine ();
sw.WriteLine (indent + "}");
}
public void Generate (GenerationInfo gen_info, string indent, ClassBase implementor)
{
SymbolTable table = SymbolTable.Table;
StreamWriter sw = gen_info.Writer;
if (Hidden || (!Readable && !Writable))
return;
string modifiers = "";
if (IsNew || (container_type.Parent != null && container_type.Parent.GetPropertyRecursively (Name) != null))
modifiers = "new ";
else if (implementor != null && implementor.Parent != null && implementor.Parent.GetPropertyRecursively (Name) != null)
modifiers = "new ";
string name = Name;
if (name == container_type.Name) {
name += "Prop";
}
string qpname = "\"" + CName + "\"";
string v_type = "";
if (table.IsInterface (CType)) {
v_type = "(GLib.Object)";
} else if (table.IsOpaque (CType)) {
v_type = "(GLib.Opaque)";
} else if (table.IsEnum (CType)) {
v_type = "(Enum)";
}
GenerateImports (gen_info, indent);
if (IsDeprecated ||
(Getter != null && Getter.IsDeprecated) ||
(Setter != null && Setter.IsDeprecated))
sw.WriteLine (indent + "[Obsolete]");
sw.WriteLine (indent + PropertyAttribute (qpname));
sw.WriteLine (indent + "public " + modifiers + CSType + " " + name + " {");
indent += "\t";
if (Getter != null) {
sw.Write(indent + "get ");
Getter.GenerateBody(gen_info, implementor, "\t");
sw.WriteLine();
} else if (Readable) {
sw.WriteLine(indent + "get {");
sw.WriteLine(indent + "\tGLib.Value val = " + RawGetter (qpname) + ";");
if (table.IsOpaque (CType) || table.IsBoxed (CType)) {
sw.WriteLine(indent + "\t" + CSType + " ret = (" + CSType + ") val;");
} else if (table.IsInterface (CType)) {
// Do we have to dispose the GLib.Object from the GLib.Value?
sw.WriteLine (indent + "\t{0} ret = {0}Adapter.GetObject ((GLib.Object) val);", CSType);
} else {
sw.Write(indent + "\t" + CSType + " ret = ");
sw.Write ("(" + CSType + ") ");
if (v_type != "") {
sw.Write(v_type + " ");
}
sw.WriteLine("val;");
}
sw.WriteLine(indent + "\tval.Dispose ();");
sw.WriteLine(indent + "\treturn ret;");
sw.WriteLine(indent + "}");
}
if (Setter != null) {
sw.Write(indent + "set ");
Setter.GenerateBody(gen_info, implementor, "\t");
sw.WriteLine();
} else if (Writable) {
sw.WriteLine(indent + "set {");
sw.Write(indent + "\tGLib.Value val = ");
if (table.IsBoxed (CType)) {
sw.WriteLine("(GLib.Value) value;");
} else if (table.IsOpaque (CType)) {
sw.WriteLine("new GLib.Value(value, \"{0}\");", CType);
} else {
sw.Write("new GLib.Value(");
if (v_type != "" && !(table.IsObject (CType) || table.IsInterface (CType) || table.IsOpaque (CType))) {
sw.Write(v_type + " ");
}
sw.WriteLine("value);");
}
sw.WriteLine(indent + "\t" + RawSetter (qpname) + ";");
sw.WriteLine(indent + "\tval.Dispose ();");
sw.WriteLine(indent + "}");
}
sw.WriteLine(indent.Substring (1) + "}");
sw.WriteLine();
Statistics.PropCount++;
}
}
}
// GtkSharp.Generation.Property.cs - The Property Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 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;
using System.Xml;
public class Property : PropertyBase {
public Property (XmlElement elem, ClassBase container_type) : base (elem, container_type) {}
public bool Validate (LogWriter log)
{
if (CSType == "" && !Hidden) {
log.Member = Name;
log.Warn ("property has unknown type '{0}' ", CType);
Statistics.ThrottledCount++;
return false;
}
return true;
}
bool Readable {
get {
return elem.GetAttributeAsBoolean ("readable");
}
}
bool Writable {
get {
return elem.GetAttributeAsBoolean ("writeable") &&
!elem.GetAttributeAsBoolean ("construct-only");
}
}
bool IsDeprecated {
get {
return !container_type.IsDeprecated &&
elem.GetAttributeAsBoolean ("deprecated");
}
}
protected virtual string PropertyAttribute (string qpname) {
return "[GLib.Property (" + qpname + ")]";
}
protected virtual string RawGetter (string qpname) {
return "GetProperty (" + qpname + ")";
}
protected virtual string RawSetter (string qpname) {
return "SetProperty(" + qpname + ", val)";
}
public void GenerateDecl (StreamWriter sw, string indent)
{
if (Hidden || (!Readable && !Writable))
return;
string name = Name;
if (name == container_type.Name)
name += "Prop";
sw.WriteLine (indent + CSType + " " + name + " {");
sw.Write (indent + "\t");
if (Readable || Getter != null)
sw.Write ("get; ");
if (Writable || Setter != null)
sw.Write ("set;");
sw.WriteLine ();
sw.WriteLine (indent + "}");
}
public void Generate (GenerationInfo gen_info, string indent, ClassBase implementor)
{
SymbolTable table = SymbolTable.Table;
StreamWriter sw = gen_info.Writer;
if (Hidden || (!Readable && !Writable))
return;
string modifiers = "";
if (IsNew || (container_type.Parent != null && container_type.Parent.GetPropertyRecursively (Name) != null))
modifiers = "new ";
else if (implementor != null && implementor.Parent != null && implementor.Parent.GetPropertyRecursively (Name) != null)
modifiers = "new ";
string name = Name;
if (name == container_type.Name) {
name += "Prop";
}
string qpname = "\"" + CName + "\"";
string v_type = "";
if (table.IsInterface (CType)) {
v_type = "(GLib.Object)";
} else if (table.IsOpaque (CType)) {
v_type = "(GLib.Opaque)";
} else if (table.IsEnum (CType)) {
v_type = "(Enum)";
}
GenerateImports (gen_info, indent);
if (IsDeprecated ||
(Getter != null && Getter.IsDeprecated) ||
(Setter != null && Setter.IsDeprecated))
sw.WriteLine (indent + "[Obsolete]");
sw.WriteLine (indent + PropertyAttribute (qpname));
sw.WriteLine (indent + "public " + modifiers + CSType + " " + name + " {");
indent += "\t";
if (Getter != null) {
sw.Write(indent + "get ");
Getter.GenerateBody(gen_info, implementor, "\t");
sw.WriteLine();
} else if (Readable) {
sw.WriteLine(indent + "get {");
sw.WriteLine(indent + "\tGLib.Value val = " + RawGetter (qpname) + ";");
if (table.IsOpaque (CType) || table.IsBoxed (CType)) {
sw.WriteLine(indent + "\t" + CSType + " ret = (" + CSType + ") val;");
} else if (table.IsInterface (CType)) {
// Do we have to dispose the GLib.Object from the GLib.Value?
sw.WriteLine (indent + "\t{0} ret = {0}Adapter.GetObject ((GLib.Object) val);", CSType);
} else {
sw.Write(indent + "\t" + CSType + " ret = ");
sw.Write ("(" + CSType + ") ");
if (v_type != "") {
sw.Write(v_type + " ");
}
sw.WriteLine("val;");
}
sw.WriteLine(indent + "\tval.Dispose ();");
sw.WriteLine(indent + "\treturn ret;");
sw.WriteLine(indent + "}");
}
if (Setter != null) {
sw.Write(indent + "set ");
Setter.GenerateBody(gen_info, implementor, "\t");
sw.WriteLine();
} else if (Writable) {
sw.WriteLine(indent + "set {");
sw.Write(indent + "\tGLib.Value val = ");
if (table.IsBoxed (CType)) {
sw.WriteLine("(GLib.Value) value;");
} else if (table.IsOpaque (CType)) {
sw.WriteLine("new GLib.Value(value, \"{0}\");", CType);
} else {
sw.Write("new GLib.Value(");
if (v_type != "" && !(table.IsObject (CType) || table.IsInterface (CType) || table.IsOpaque (CType))) {
sw.Write(v_type + " ");
}
sw.WriteLine("value);");
}
sw.WriteLine(indent + "\t" + RawSetter (qpname) + ";");
sw.WriteLine(indent + "\tval.Dispose ();");
sw.WriteLine(indent + "}");
}
sw.WriteLine(indent.Substring (1) + "}");
sw.WriteLine();
Statistics.PropCount++;
}
}
}

View File

@ -1,194 +1,194 @@
// GtkSharp.Generation.ReturnValue.cs - The ReturnValue Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2004-2005 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.Xml;
public class ReturnValue {
bool is_null_term;
bool is_array;
bool elements_owned;
bool owned;
string array_length_param = String.Empty;
string ctype = String.Empty;
string default_value = String.Empty;
string element_ctype = String.Empty;
Parameter count_param;
public ReturnValue (XmlElement elem)
{
if (elem != null) {
is_null_term = elem.GetAttributeAsBoolean ("null_term_array");
is_array = elem.GetAttributeAsBoolean ("array") || elem.HasAttribute ("array_length_param");
array_length_param = elem.GetAttribute ("array_length_param");
elements_owned = elem.GetAttributeAsBoolean ("elements_owned");
owned = elem.GetAttributeAsBoolean ("owned");
ctype = elem.GetAttribute("type");
default_value = elem.GetAttribute ("default_value");
element_ctype = elem.GetAttribute ("element_type");
}
}
public Parameter CountParameter {
get { return count_param; }
set { count_param = value; }
}
public string CountParameterName {
get { return array_length_param; }
}
public string CType {
get {
return ctype;
}
}
public string CSType {
get {
if (IGen == null)
return String.Empty;
if (ElementType != String.Empty)
return ElementType + "[]";
return IGen.QualifiedName + (is_array || is_null_term ? "[]" : String.Empty);
}
}
public string DefaultValue {
get {
if (default_value != null && default_value.Length > 0)
return default_value;
if (IGen == null)
return String.Empty;
return IGen.DefaultValue;
}
}
string ElementType {
get {
if (element_ctype.Length > 0)
return SymbolTable.Table.GetCSType (element_ctype);
return String.Empty;
}
}
IGeneratable igen;
public IGeneratable IGen {
get {
if (igen == null)
igen = SymbolTable.Table [CType];
return igen;
}
}
public bool IsVoid {
get {
return CSType == "void";
}
}
public string MarshalType {
get {
if (IGen == null)
return String.Empty;
else if (is_array || is_null_term)
return "IntPtr";
return IGen.MarshalType;
}
}
public string ToNativeType {
get {
if (IGen == null)
return String.Empty;
return IGen.MarshalType + (is_array || is_null_term ? "[]" : String.Empty);
}
}
public string FromNative (string var)
{
if (IGen == null)
return String.Empty;
if (ElementType != String.Empty) {
string args = (owned ? "true" : "false") + ", " + (elements_owned ? "true" : "false");
if (IGen.QualifiedName == "GLib.PtrArray")
return String.Format ("({0}[]) GLib.Marshaller.PtrArrayToArray ({1}, {2}, typeof({0}))", ElementType, var, args);
else
return String.Format ("({0}[]) GLib.Marshaller.ListPtrToArray ({1}, typeof({2}), {3}, typeof({4}))", ElementType, var, IGen.QualifiedName, args, element_ctype == "gfilename*" ? "GLib.ListBase.FilenameString" : ElementType);
} else if (IGen is IOwnable)
return ((IOwnable)IGen).FromNative (var, owned);
else if (is_null_term)
return String.Format ("GLib.Marshaller.NullTermPtrToStringArray ({0}, {1})", var, owned ? "true" : "false");
else if (is_array)
return String.Format ("({0}) GLib.Marshaller.ArrayPtrToArray ({1}, typeof ({2}), (int){3}native_{4}, true)", CSType, var, IGen.QualifiedName, CountParameter.CSType == "int" ? String.Empty : "(" + CountParameter.CSType + ")", CountParameter.Name);
else
return IGen.FromNative (var);
}
public string ToNative (string var)
{
if (IGen == null)
return String.Empty;
if (ElementType.Length > 0) {
string args = ", typeof (" + ElementType + "), " + (owned ? "true" : "false") + ", " + (elements_owned ? "true" : "false");
var = "new " + IGen.QualifiedName + "(" + var + args + ")";
} else if (is_null_term)
return String.Format ("GLib.Marshaller.StringArrayToNullTermPointer ({0})", var);
else if (is_array)
return String.Format ("GLib.Marshaller.ArrayToArrayPtr ({0})", var);
if (IGen is IManualMarshaler)
return (IGen as IManualMarshaler).AllocNative (var);
else if (IGen is ObjectGen && owned)
return var + " == null ? IntPtr.Zero : " + var + ".OwnedHandle";
else if (IGen is OpaqueGen && owned)
return var + " == null ? IntPtr.Zero : " + var + ".OwnedCopy";
else
return IGen.CallByName (var);
}
public bool Validate (LogWriter log)
{
if (MarshalType == "" || CSType == "") {
log.Warn ("Unknown return type: {0}", CType);
return false;
} else if ((CSType == "GLib.List" || CSType == "GLib.SList") && String.IsNullOrEmpty (ElementType))
log.Warn ("Returns {0} with unknown element type. Add element_type attribute with gapi-fixup.", CType);
if (is_array && !is_null_term && String.IsNullOrEmpty (array_length_param)) {
log.Warn ("Returns an array with undeterminable length. Add null_term_array or array_length_param attribute with gapi-fixup.");
return false;
}
return true;
}
}
}
// GtkSharp.Generation.ReturnValue.cs - The ReturnValue Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2004-2005 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.Xml;
public class ReturnValue {
bool is_null_term;
bool is_array;
bool elements_owned;
bool owned;
string array_length_param = String.Empty;
string ctype = String.Empty;
string default_value = String.Empty;
string element_ctype = String.Empty;
Parameter count_param;
public ReturnValue (XmlElement elem)
{
if (elem != null) {
is_null_term = elem.GetAttributeAsBoolean ("null_term_array");
is_array = elem.GetAttributeAsBoolean ("array") || elem.HasAttribute ("array_length_param");
array_length_param = elem.GetAttribute ("array_length_param");
elements_owned = elem.GetAttributeAsBoolean ("elements_owned");
owned = elem.GetAttributeAsBoolean ("owned");
ctype = elem.GetAttribute("type");
default_value = elem.GetAttribute ("default_value");
element_ctype = elem.GetAttribute ("element_type");
}
}
public Parameter CountParameter {
get { return count_param; }
set { count_param = value; }
}
public string CountParameterName {
get { return array_length_param; }
}
public string CType {
get {
return ctype;
}
}
public string CSType {
get {
if (IGen == null)
return String.Empty;
if (ElementType != String.Empty)
return ElementType + "[]";
return IGen.QualifiedName + (is_array || is_null_term ? "[]" : String.Empty);
}
}
public string DefaultValue {
get {
if (default_value != null && default_value.Length > 0)
return default_value;
if (IGen == null)
return String.Empty;
return IGen.DefaultValue;
}
}
string ElementType {
get {
if (element_ctype.Length > 0)
return SymbolTable.Table.GetCSType (element_ctype);
return String.Empty;
}
}
IGeneratable igen;
public IGeneratable IGen {
get {
if (igen == null)
igen = SymbolTable.Table [CType];
return igen;
}
}
public bool IsVoid {
get {
return CSType == "void";
}
}
public string MarshalType {
get {
if (IGen == null)
return String.Empty;
else if (is_array || is_null_term)
return "IntPtr";
return IGen.MarshalType;
}
}
public string ToNativeType {
get {
if (IGen == null)
return String.Empty;
return IGen.MarshalType + (is_array || is_null_term ? "[]" : String.Empty);
}
}
public string FromNative (string var)
{
if (IGen == null)
return String.Empty;
if (ElementType != String.Empty) {
string args = (owned ? "true" : "false") + ", " + (elements_owned ? "true" : "false");
if (IGen.QualifiedName == "GLib.PtrArray")
return String.Format ("({0}[]) GLib.Marshaller.PtrArrayToArray ({1}, {2}, typeof({0}))", ElementType, var, args);
else
return String.Format ("({0}[]) GLib.Marshaller.ListPtrToArray ({1}, typeof({2}), {3}, typeof({4}))", ElementType, var, IGen.QualifiedName, args, element_ctype == "gfilename*" ? "GLib.ListBase.FilenameString" : ElementType);
} else if (IGen is IOwnable)
return ((IOwnable)IGen).FromNative (var, owned);
else if (is_null_term)
return String.Format ("GLib.Marshaller.NullTermPtrToStringArray ({0}, {1})", var, owned ? "true" : "false");
else if (is_array)
return String.Format ("({0}) GLib.Marshaller.ArrayPtrToArray ({1}, typeof ({2}), (int){3}native_{4}, true)", CSType, var, IGen.QualifiedName, CountParameter.CSType == "int" ? String.Empty : "(" + CountParameter.CSType + ")", CountParameter.Name);
else
return IGen.FromNative (var);
}
public string ToNative (string var)
{
if (IGen == null)
return String.Empty;
if (ElementType.Length > 0) {
string args = ", typeof (" + ElementType + "), " + (owned ? "true" : "false") + ", " + (elements_owned ? "true" : "false");
var = "new " + IGen.QualifiedName + "(" + var + args + ")";
} else if (is_null_term)
return String.Format ("GLib.Marshaller.StringArrayToNullTermPointer ({0})", var);
else if (is_array)
return String.Format ("GLib.Marshaller.ArrayToArrayPtr ({0})", var);
if (IGen is IManualMarshaler)
return (IGen as IManualMarshaler).AllocNative (var);
else if (IGen is ObjectGen && owned)
return var + " == null ? IntPtr.Zero : " + var + ".OwnedHandle";
else if (IGen is OpaqueGen && owned)
return var + " == null ? IntPtr.Zero : " + var + ".OwnedCopy";
else
return IGen.CallByName (var);
}
public bool Validate (LogWriter log)
{
if (MarshalType == "" || CSType == "") {
log.Warn ("Unknown return type: {0}", CType);
return false;
} else if ((CSType == "GLib.List" || CSType == "GLib.SList") && String.IsNullOrEmpty (ElementType))
log.Warn ("Returns {0} with unknown element type. Add element_type attribute with gapi-fixup.", CType);
if (is_array && !is_null_term && String.IsNullOrEmpty (array_length_param)) {
log.Warn ("Returns an array with undeterminable length. Add null_term_array or array_length_param attribute with gapi-fixup.");
return false;
}
return true;
}
}
}

View File

@ -1,330 +1,330 @@
// GtkSharp.Generation.Signal.cs - The Signal Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2003-2005 Novell, Inc.
// Copyright (c) 2007 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;
using System.Xml;
public class Signal {
bool marshaled;
string name;
XmlElement elem;
ReturnValue retval;
Parameters parms;
ObjectBase container_type;
public Signal (XmlElement elem, ObjectBase container_type)
{
this.elem = elem;
name = elem.GetAttribute ("name");
marshaled = elem.GetAttribute ("manual") == "true";
retval = new ReturnValue (elem ["return-type"]);
parms = new Parameters (elem["parameters"], container_type.ParserVersion == 1 ? true : false);
this.container_type = container_type;
}
bool Marshaled {
get { return marshaled; }
}
public string Name {
get {
return name;
}
set {
name = value;
}
}
public bool Validate (LogWriter log)
{
log.Member = Name;
if (Name == "") {
log.Warn ("Nameless signal found. Add name attribute with fixup.");
Statistics.ThrottledCount++;
return false;
} else if (!parms.Validate (log) || !retval.Validate (log)) {
Statistics.ThrottledCount++;
return false;
}
return true;
}
public void GenerateDecl (StreamWriter sw)
{
if (elem.GetAttributeAsBoolean ("new_flag") || (container_type != null && container_type.GetSignalRecursively (Name) != null))
sw.Write("new ");
sw.WriteLine ("\t\tevent " + EventHandlerQualifiedName + " " + Name + ";");
}
public string CName {
get {
return "\"" + elem.GetAttribute("cname") + "\"";
}
}
string CallbackSig {
get {
string result = "";
for (int i = 0; i < parms.Count; i++) {
if (i > 0)
result += ", ";
Parameter p = parms [i];
if (p.PassAs != "" && !(p.Generatable is StructBase))
result += p.PassAs + " ";
result += (p.MarshalType + " arg" + i);
}
return result;
}
}
string CallbackName {
get { return Name + "SignalCallback"; }
}
string DelegateName {
get { return Name + "SignalDelegate"; }
}
private string EventArgsName {
get {
if (IsEventHandler)
return "EventArgs";
else
return Name + "Args";
}
}
private string EventArgsQualifiedName {
get {
if (IsEventHandler)
return "System.EventArgs";
else
return container_type.NS + "." + Name + "Args";
}
}
private string EventHandlerName {
get {
if (IsEventHandler)
return "EventHandler";
else if (SymbolTable.Table [container_type.NS + Name + "Handler"] != null)
return Name + "EventHandler";
else
return Name + "Handler";
}
}
private string EventHandlerQualifiedName {
get {
if (IsEventHandler)
return "System.EventHandler";
else
return container_type.NS + "." + EventHandlerName;
}
}
private bool IsEventHandler {
get {
return retval.CSType == "void" && parms.Count == 0;
}
}
public string GenArgsInitialization (StreamWriter sw)
{
if (parms.Count > 0)
sw.WriteLine("\t\t\t\targs.Args = new object[" + parms.Count + "];");
string finish = "";
for (int idx = 0; idx < parms.Count; idx++) {
Parameter p = parms [idx];
IGeneratable igen = p.Generatable;
if (p.PassAs != "out") {
if (igen is ManualGen) {
sw.WriteLine("\t\t\t\tif (arg{0} == IntPtr.Zero)", idx);
sw.WriteLine("\t\t\t\t\targs.Args[{0}] = null;", idx);
sw.WriteLine("\t\t\t\telse {");
sw.WriteLine("\t\t\t\t\targs.Args[" + idx + "] = " + p.FromNative ("arg" + idx) + ";");
sw.WriteLine("\t\t\t\t}");
} else
sw.WriteLine("\t\t\t\targs.Args[" + idx + "] = " + p.FromNative ("arg" + idx) + ";");
}
if ((igen is StructBase || igen is ByRefGen) && p.PassAs != "")
finish += "\t\t\t\tif (arg" + idx + " != IntPtr.Zero) System.Runtime.InteropServices.Marshal.StructureToPtr (args.Args[" + idx + "], arg" + idx + ", false);\n";
else if (igen is IManualMarshaler && p.PassAs != "")
finish += String.Format ("\t\t\t\targ{0} = {1};\n", idx, (igen as IManualMarshaler).AllocNative ("args.Args[" + idx + "]"));
else if (p.PassAs != "")
finish += "\t\t\t\targ" + idx + " = " + igen.CallByName ("((" + p.CSType + ")args.Args[" + idx + "])") + ";\n";
}
return finish;
}
public void GenArgsCleanup (StreamWriter sw, string finish)
{
if (retval.IsVoid && finish.Length == 0)
return;
sw.WriteLine("\n\t\t\ttry {");
sw.Write (finish);
if (!retval.IsVoid) {
if (retval.CSType == "bool") {
sw.WriteLine ("\t\t\t\tif (args.RetVal == null)");
sw.WriteLine ("\t\t\t\t\treturn false;");
}
sw.WriteLine ("\t\t\t\treturn {0};", retval.ToNative (String.Format ("(({0}) args.RetVal)", retval.CSType)));
}
sw.WriteLine("\t\t\t} catch (Exception) {");
sw.WriteLine ("\t\t\t\tException ex = new Exception (\"args.RetVal or 'out' property unset or set to incorrect type in " + EventHandlerQualifiedName + " callback\");");
sw.WriteLine("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (ex, true);");
sw.WriteLine ("\t\t\t\t// NOTREACHED: above call doesn't return.");
sw.WriteLine ("\t\t\t\tthrow ex;");
sw.WriteLine("\t\t\t}");
}
public void GenCallback (StreamWriter sw)
{
if (IsEventHandler)
return;
string native_signature = "IntPtr inst";
if (parms.Count > 0)
native_signature += ", " + CallbackSig;
native_signature += ", IntPtr gch";
sw.WriteLine ("\t\t[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
sw.WriteLine ("\t\tdelegate {0} {1} ({2});", retval.ToNativeType, DelegateName, native_signature);
sw.WriteLine ();
sw.WriteLine ("\t\tstatic {0} {1} ({2})", retval.ToNativeType, CallbackName, native_signature);
sw.WriteLine("\t\t{");
sw.WriteLine("\t\t\t{0} args = new {0} ();", EventArgsQualifiedName);
sw.WriteLine("\t\t\ttry {");
sw.WriteLine("\t\t\t\tGLib.Signal sig = ((GCHandle) gch).Target as GLib.Signal;");
sw.WriteLine("\t\t\t\tif (sig == null)");
sw.WriteLine("\t\t\t\t\tthrow new Exception(\"Unknown signal GC handle received \" + gch);");
sw.WriteLine();
string finish = GenArgsInitialization (sw);
sw.WriteLine("\t\t\t\t{0} handler = ({0}) sig.Handler;", EventHandlerQualifiedName);
sw.WriteLine("\t\t\t\thandler (GLib.Object.GetObject (inst), args);");
sw.WriteLine("\t\t\t} catch (Exception e) {");
sw.WriteLine("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, false);");
sw.WriteLine("\t\t\t}");
GenArgsCleanup (sw, finish);
sw.WriteLine("\t\t}");
sw.WriteLine();
}
private bool NeedNew (ObjectBase implementor)
{
return elem.GetAttributeAsBoolean ("new_flag") ||
(container_type != null && container_type.GetSignalRecursively (Name) != null) ||
(implementor != null && implementor.GetSignalRecursively (Name) != null);
}
public void GenEventHandler (GenerationInfo gen_info)
{
if (IsEventHandler)
return;
string ns = container_type.NS;
StreamWriter sw = gen_info.OpenStream (EventHandlerName);
sw.WriteLine ("namespace " + ns + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ();
sw.WriteLine ("\tpublic delegate void " + EventHandlerName + "(object o, " + EventArgsName + " args);");
sw.WriteLine ();
sw.WriteLine ("\tpublic class " + EventArgsName + " : GLib.SignalArgs {");
for (int i = 0; i < parms.Count; i++) {
sw.WriteLine ("\t\tpublic " + parms[i].CSType + " " + parms[i].StudlyName + "{");
if (parms[i].PassAs != "out") {
sw.WriteLine ("\t\t\tget {");
if (SymbolTable.Table.IsInterface (parms [i].CType))
sw.WriteLine ("\t\t\t\treturn {0}Adapter.GetObject (Args [{1}] as GLib.Object);", parms [i].CSType, i);
else
sw.WriteLine ("\t\t\t\treturn ({0}) Args [{1}];", parms [i].CSType, i);
sw.WriteLine ("\t\t\t}");
}
if (parms[i].PassAs != "") {
sw.WriteLine ("\t\t\tset {");
if (SymbolTable.Table.IsInterface (parms [i].CType))
sw.WriteLine ("\t\t\t\tArgs [{0}] = value is {1}Adapter ? (value as {1}Adapter).Implementor : value;", i, parms [i].CSType);
else
sw.WriteLine ("\t\t\t\tArgs[" + i + "] = (" + parms[i].CSType + ")value;");
sw.WriteLine ("\t\t\t}");
}
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
}
public void GenEvent (StreamWriter sw, ObjectBase implementor, string target)
{
string args_type = IsEventHandler ? "" : ", typeof (" + EventArgsQualifiedName + ")";
if (Marshaled) {
GenCallback (sw);
args_type = ", new " + DelegateName + "(" + CallbackName + ")";
}
sw.WriteLine("\t\t[GLib.Signal("+ CName + ")]");
sw.Write("\t\tpublic ");
if (NeedNew (implementor))
sw.Write("new ");
sw.WriteLine("event " + EventHandlerQualifiedName + " " + Name + " {");
sw.WriteLine("\t\t\tadd {");
sw.WriteLine("\t\t\t\t{0}.AddSignalHandler ({1}, value{2});", target, CName, args_type);
sw.WriteLine("\t\t\t}");
sw.WriteLine("\t\t\tremove {");
sw.WriteLine("\t\t\t\t{0}.RemoveSignalHandler ({1}, value);", target, CName);
sw.WriteLine("\t\t\t}");
sw.WriteLine("\t\t}");
sw.WriteLine();
}
public void Generate (GenerationInfo gen_info, ObjectBase implementor)
{
StreamWriter sw = gen_info.Writer;
if (implementor == null)
GenEventHandler (gen_info);
GenEvent (sw, implementor, "this");
Statistics.SignalCount++;
}
}
}
// GtkSharp.Generation.Signal.cs - The Signal Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2003-2005 Novell, Inc.
// Copyright (c) 2007 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;
using System.Xml;
public class Signal {
bool marshaled;
string name;
XmlElement elem;
ReturnValue retval;
Parameters parms;
ObjectBase container_type;
public Signal (XmlElement elem, ObjectBase container_type)
{
this.elem = elem;
name = elem.GetAttribute ("name");
marshaled = elem.GetAttribute ("manual") == "true";
retval = new ReturnValue (elem ["return-type"]);
parms = new Parameters (elem["parameters"], container_type.ParserVersion == 1 ? true : false);
this.container_type = container_type;
}
bool Marshaled {
get { return marshaled; }
}
public string Name {
get {
return name;
}
set {
name = value;
}
}
public bool Validate (LogWriter log)
{
log.Member = Name;
if (Name == "") {
log.Warn ("Nameless signal found. Add name attribute with fixup.");
Statistics.ThrottledCount++;
return false;
} else if (!parms.Validate (log) || !retval.Validate (log)) {
Statistics.ThrottledCount++;
return false;
}
return true;
}
public void GenerateDecl (StreamWriter sw)
{
if (elem.GetAttributeAsBoolean ("new_flag") || (container_type != null && container_type.GetSignalRecursively (Name) != null))
sw.Write("new ");
sw.WriteLine ("\t\tevent " + EventHandlerQualifiedName + " " + Name + ";");
}
public string CName {
get {
return "\"" + elem.GetAttribute("cname") + "\"";
}
}
string CallbackSig {
get {
string result = "";
for (int i = 0; i < parms.Count; i++) {
if (i > 0)
result += ", ";
Parameter p = parms [i];
if (p.PassAs != "" && !(p.Generatable is StructBase))
result += p.PassAs + " ";
result += (p.MarshalType + " arg" + i);
}
return result;
}
}
string CallbackName {
get { return Name + "SignalCallback"; }
}
string DelegateName {
get { return Name + "SignalDelegate"; }
}
private string EventArgsName {
get {
if (IsEventHandler)
return "EventArgs";
else
return Name + "Args";
}
}
private string EventArgsQualifiedName {
get {
if (IsEventHandler)
return "System.EventArgs";
else
return container_type.NS + "." + Name + "Args";
}
}
private string EventHandlerName {
get {
if (IsEventHandler)
return "EventHandler";
else if (SymbolTable.Table [container_type.NS + Name + "Handler"] != null)
return Name + "EventHandler";
else
return Name + "Handler";
}
}
private string EventHandlerQualifiedName {
get {
if (IsEventHandler)
return "System.EventHandler";
else
return container_type.NS + "." + EventHandlerName;
}
}
private bool IsEventHandler {
get {
return retval.CSType == "void" && parms.Count == 0;
}
}
public string GenArgsInitialization (StreamWriter sw)
{
if (parms.Count > 0)
sw.WriteLine("\t\t\t\targs.Args = new object[" + parms.Count + "];");
string finish = "";
for (int idx = 0; idx < parms.Count; idx++) {
Parameter p = parms [idx];
IGeneratable igen = p.Generatable;
if (p.PassAs != "out") {
if (igen is ManualGen) {
sw.WriteLine("\t\t\t\tif (arg{0} == IntPtr.Zero)", idx);
sw.WriteLine("\t\t\t\t\targs.Args[{0}] = null;", idx);
sw.WriteLine("\t\t\t\telse {");
sw.WriteLine("\t\t\t\t\targs.Args[" + idx + "] = " + p.FromNative ("arg" + idx) + ";");
sw.WriteLine("\t\t\t\t}");
} else
sw.WriteLine("\t\t\t\targs.Args[" + idx + "] = " + p.FromNative ("arg" + idx) + ";");
}
if ((igen is StructBase || igen is ByRefGen) && p.PassAs != "")
finish += "\t\t\t\tif (arg" + idx + " != IntPtr.Zero) System.Runtime.InteropServices.Marshal.StructureToPtr (args.Args[" + idx + "], arg" + idx + ", false);\n";
else if (igen is IManualMarshaler && p.PassAs != "")
finish += String.Format ("\t\t\t\targ{0} = {1};\n", idx, (igen as IManualMarshaler).AllocNative ("args.Args[" + idx + "]"));
else if (p.PassAs != "")
finish += "\t\t\t\targ" + idx + " = " + igen.CallByName ("((" + p.CSType + ")args.Args[" + idx + "])") + ";\n";
}
return finish;
}
public void GenArgsCleanup (StreamWriter sw, string finish)
{
if (retval.IsVoid && finish.Length == 0)
return;
sw.WriteLine("\n\t\t\ttry {");
sw.Write (finish);
if (!retval.IsVoid) {
if (retval.CSType == "bool") {
sw.WriteLine ("\t\t\t\tif (args.RetVal == null)");
sw.WriteLine ("\t\t\t\t\treturn false;");
}
sw.WriteLine ("\t\t\t\treturn {0};", retval.ToNative (String.Format ("(({0}) args.RetVal)", retval.CSType)));
}
sw.WriteLine("\t\t\t} catch (Exception) {");
sw.WriteLine ("\t\t\t\tException ex = new Exception (\"args.RetVal or 'out' property unset or set to incorrect type in " + EventHandlerQualifiedName + " callback\");");
sw.WriteLine("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (ex, true);");
sw.WriteLine ("\t\t\t\t// NOTREACHED: above call doesn't return.");
sw.WriteLine ("\t\t\t\tthrow ex;");
sw.WriteLine("\t\t\t}");
}
public void GenCallback (StreamWriter sw)
{
if (IsEventHandler)
return;
string native_signature = "IntPtr inst";
if (parms.Count > 0)
native_signature += ", " + CallbackSig;
native_signature += ", IntPtr gch";
sw.WriteLine ("\t\t[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
sw.WriteLine ("\t\tdelegate {0} {1} ({2});", retval.ToNativeType, DelegateName, native_signature);
sw.WriteLine ();
sw.WriteLine ("\t\tstatic {0} {1} ({2})", retval.ToNativeType, CallbackName, native_signature);
sw.WriteLine("\t\t{");
sw.WriteLine("\t\t\t{0} args = new {0} ();", EventArgsQualifiedName);
sw.WriteLine("\t\t\ttry {");
sw.WriteLine("\t\t\t\tGLib.Signal sig = ((GCHandle) gch).Target as GLib.Signal;");
sw.WriteLine("\t\t\t\tif (sig == null)");
sw.WriteLine("\t\t\t\t\tthrow new Exception(\"Unknown signal GC handle received \" + gch);");
sw.WriteLine();
string finish = GenArgsInitialization (sw);
sw.WriteLine("\t\t\t\t{0} handler = ({0}) sig.Handler;", EventHandlerQualifiedName);
sw.WriteLine("\t\t\t\thandler (GLib.Object.GetObject (inst), args);");
sw.WriteLine("\t\t\t} catch (Exception e) {");
sw.WriteLine("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, false);");
sw.WriteLine("\t\t\t}");
GenArgsCleanup (sw, finish);
sw.WriteLine("\t\t}");
sw.WriteLine();
}
private bool NeedNew (ObjectBase implementor)
{
return elem.GetAttributeAsBoolean ("new_flag") ||
(container_type != null && container_type.GetSignalRecursively (Name) != null) ||
(implementor != null && implementor.GetSignalRecursively (Name) != null);
}
public void GenEventHandler (GenerationInfo gen_info)
{
if (IsEventHandler)
return;
string ns = container_type.NS;
StreamWriter sw = gen_info.OpenStream (EventHandlerName);
sw.WriteLine ("namespace " + ns + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ();
sw.WriteLine ("\tpublic delegate void " + EventHandlerName + "(object o, " + EventArgsName + " args);");
sw.WriteLine ();
sw.WriteLine ("\tpublic class " + EventArgsName + " : GLib.SignalArgs {");
for (int i = 0; i < parms.Count; i++) {
sw.WriteLine ("\t\tpublic " + parms[i].CSType + " " + parms[i].StudlyName + "{");
if (parms[i].PassAs != "out") {
sw.WriteLine ("\t\t\tget {");
if (SymbolTable.Table.IsInterface (parms [i].CType))
sw.WriteLine ("\t\t\t\treturn {0}Adapter.GetObject (Args [{1}] as GLib.Object);", parms [i].CSType, i);
else
sw.WriteLine ("\t\t\t\treturn ({0}) Args [{1}];", parms [i].CSType, i);
sw.WriteLine ("\t\t\t}");
}
if (parms[i].PassAs != "") {
sw.WriteLine ("\t\t\tset {");
if (SymbolTable.Table.IsInterface (parms [i].CType))
sw.WriteLine ("\t\t\t\tArgs [{0}] = value is {1}Adapter ? (value as {1}Adapter).Implementor : value;", i, parms [i].CSType);
else
sw.WriteLine ("\t\t\t\tArgs[" + i + "] = (" + parms[i].CSType + ")value;");
sw.WriteLine ("\t\t\t}");
}
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
}
public void GenEvent (StreamWriter sw, ObjectBase implementor, string target)
{
string args_type = IsEventHandler ? "" : ", typeof (" + EventArgsQualifiedName + ")";
if (Marshaled) {
GenCallback (sw);
args_type = ", new " + DelegateName + "(" + CallbackName + ")";
}
sw.WriteLine("\t\t[GLib.Signal("+ CName + ")]");
sw.Write("\t\tpublic ");
if (NeedNew (implementor))
sw.Write("new ");
sw.WriteLine("event " + EventHandlerQualifiedName + " " + Name + " {");
sw.WriteLine("\t\t\tadd {");
sw.WriteLine("\t\t\t\t{0}.AddSignalHandler ({1}, value{2});", target, CName, args_type);
sw.WriteLine("\t\t\t}");
sw.WriteLine("\t\t\tremove {");
sw.WriteLine("\t\t\t\t{0}.RemoveSignalHandler ({1}, value);", target, CName);
sw.WriteLine("\t\t\t}");
sw.WriteLine("\t\t}");
sw.WriteLine();
}
public void Generate (GenerationInfo gen_info, ObjectBase implementor)
{
StreamWriter sw = gen_info.Writer;
if (implementor == null)
GenEventHandler (gen_info);
GenEvent (sw, implementor, "this");
Statistics.SignalCount++;
}
}
}

View File

@ -1,123 +1,123 @@
// GtkSharp.Generation.Signature.cs - The Signature Generation Class.
//
// Author: Mike Kestner <mkestner@ximian.com>
//
// 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.Xml;
public class Signature {
private ArrayList parms = new ArrayList ();
public Signature (Parameters parms)
{
foreach (Parameter p in parms) {
if (!parms.IsHidden (p))
this.parms.Add (p);
}
}
public override string ToString ()
{
if (parms.Count == 0)
return "";
string[] result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms) {
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
result [i++] += p.CSType + " " + p.Name;
}
return String.Join (", ", result);
}
public string Types {
get {
if (parms.Count == 0)
return "";
string[] result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms)
result [i++] = p.CSType;
return String.Join (":", result);
}
}
public bool IsAccessor {
get {
int count = 0;
foreach (Parameter p in parms) {
if (p.PassAs == "out")
count++;
if (count > 1)
return false;
}
return count == 1;
}
}
public string AccessorType {
get {
foreach (Parameter p in parms)
if (p.PassAs == "out")
return p.CSType;
return null;
}
}
public string AccessorName {
get {
foreach (Parameter p in parms)
if (p.PassAs == "out")
return p.Name;
return null;
}
}
public string AsAccessor {
get {
string[] result = new string [parms.Count - 1];
int i = 0;
foreach (Parameter p in parms) {
if (p.PassAs == "out")
continue;
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
result [i++] += p.CSType + " " + p.Name;
}
return String.Join (", ", result);
}
}
}
}
// GtkSharp.Generation.Signature.cs - The Signature Generation Class.
//
// Author: Mike Kestner <mkestner@ximian.com>
//
// 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.Xml;
public class Signature {
private ArrayList parms = new ArrayList ();
public Signature (Parameters parms)
{
foreach (Parameter p in parms) {
if (!parms.IsHidden (p))
this.parms.Add (p);
}
}
public override string ToString ()
{
if (parms.Count == 0)
return "";
string[] result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms) {
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
result [i++] += p.CSType + " " + p.Name;
}
return String.Join (", ", result);
}
public string Types {
get {
if (parms.Count == 0)
return "";
string[] result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms)
result [i++] = p.CSType;
return String.Join (":", result);
}
}
public bool IsAccessor {
get {
int count = 0;
foreach (Parameter p in parms) {
if (p.PassAs == "out")
count++;
if (count > 1)
return false;
}
return count == 1;
}
}
public string AccessorType {
get {
foreach (Parameter p in parms)
if (p.PassAs == "out")
return p.CSType;
return null;
}
}
public string AccessorName {
get {
foreach (Parameter p in parms)
if (p.PassAs == "out")
return p.Name;
return null;
}
}
public string AsAccessor {
get {
string[] result = new string [parms.Count - 1];
int i = 0;
foreach (Parameter p in parms) {
if (p.PassAs == "out")
continue;
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
result [i++] += p.CSType + " " + p.Name;
}
return String.Join (", ", result);
}
}
}
}

View File

@ -1,99 +1,99 @@
// GtkSharp.Generation.SimpleBase.cs - base class for marshaling non-generated types.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 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;
public abstract class SimpleBase : IGeneratable {
string type;
string ctype;
string ns = String.Empty;
string default_value = String.Empty;
public SimpleBase (string ctype, string type, string default_value)
{
string[] toks = type.Split('.');
this.ctype = ctype;
this.type = toks[toks.Length - 1];
if (toks.Length > 2)
this.ns = String.Join (".", toks, 0, toks.Length - 1);
else if (toks.Length == 2)
this.ns = toks[0];
this.default_value = default_value;
}
public string CName {
get {
return ctype;
}
}
public string Name {
get {
return type;
}
}
public string QualifiedName {
get {
return ns == String.Empty ? type : ns + "." + type;
}
}
public virtual string MarshalType {
get {
return QualifiedName;
}
}
public virtual string DefaultValue {
get {
return default_value;
}
}
public virtual string CallByName (string var)
{
return var;
}
public virtual string FromNative(string var)
{
return var;
}
public bool Validate ()
{
return true;
}
public void Generate ()
{
}
public void Generate (GenerationInfo gen_info)
{
}
}
}
// GtkSharp.Generation.SimpleBase.cs - base class for marshaling non-generated types.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 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;
public abstract class SimpleBase : IGeneratable {
string type;
string ctype;
string ns = String.Empty;
string default_value = String.Empty;
public SimpleBase (string ctype, string type, string default_value)
{
string[] toks = type.Split('.');
this.ctype = ctype;
this.type = toks[toks.Length - 1];
if (toks.Length > 2)
this.ns = String.Join (".", toks, 0, toks.Length - 1);
else if (toks.Length == 2)
this.ns = toks[0];
this.default_value = default_value;
}
public string CName {
get {
return ctype;
}
}
public string Name {
get {
return type;
}
}
public string QualifiedName {
get {
return ns == String.Empty ? type : ns + "." + type;
}
}
public virtual string MarshalType {
get {
return QualifiedName;
}
}
public virtual string DefaultValue {
get {
return default_value;
}
}
public virtual string CallByName (string var)
{
return var;
}
public virtual string FromNative(string var)
{
return var;
}
public bool Validate ()
{
return true;
}
public void Generate ()
{
}
public void Generate (GenerationInfo gen_info)
{
}
}
}

View File

@ -1,31 +1,31 @@
// GtkSharp.Generation.SimpleGen.cs - The Simple type Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2003 Mike Kestner
//
// 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;
public class SimpleGen : SimpleBase {
public SimpleGen (string ctype, string type, string default_value) : base (ctype, type, default_value) {}
}
}
// GtkSharp.Generation.SimpleGen.cs - The Simple type Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2003 Mike Kestner
//
// 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;
public class SimpleGen : SimpleBase {
public SimpleGen (string ctype, string type, string default_value) : base (ctype, type, default_value) {}
}
}

View File

@ -1,197 +1,197 @@
// Statistics.cs : Generation statistics class implementation
//
// Author: Mike Kestner <mkestner@ximian.com>
//
// Copyright (c) 2002 Mike Kestner
// Copyright (c) 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;
public class Statistics {
static int cbs = 0;
static int enums = 0;
static int objects = 0;
static int structs = 0;
static int boxed = 0;
static int opaques = 0;
static int interfaces = 0;
static int methods = 0;
static int ctors = 0;
static int props = 0;
static int sigs = 0;
static int throttled = 0;
static int ignored = 0;
static bool vm_ignored = false;
public static int CBCount {
get {
return cbs;
}
set {
cbs = value;
}
}
public static int EnumCount {
get {
return enums;
}
set {
enums = value;
}
}
public static int ObjectCount {
get {
return objects;
}
set {
objects = value;
}
}
public static int StructCount {
get {
return structs;
}
set {
structs = value;
}
}
public static int BoxedCount {
get {
return boxed;
}
set {
boxed = value;
}
}
public static int OpaqueCount {
get {
return opaques;
}
set {
opaques = value;
}
}
public static int CtorCount {
get {
return ctors;
}
set {
ctors = value;
}
}
public static int MethodCount {
get {
return methods;
}
set {
methods = value;
}
}
public static int PropCount {
get {
return props;
}
set {
props = value;
}
}
public static int SignalCount {
get {
return sigs;
}
set {
sigs = value;
}
}
public static int IFaceCount {
get {
return interfaces;
}
set {
interfaces = value;
}
}
public static int ThrottledCount {
get {
return throttled;
}
set {
throttled = value;
}
}
public static int IgnoreCount {
get {
return ignored;
}
set {
ignored = value;
}
}
public static bool VMIgnored {
get {
return vm_ignored;
}
set {
if (value)
vm_ignored = value;
}
}
public static void Report()
{
if (VMIgnored) {
Console.WriteLine();
Console.WriteLine("Warning: Generation throttled for Virtual Methods.");
Console.WriteLine(" Consider regenerating with --gluelib-name and --glue-filename.");
}
Console.WriteLine();
Console.WriteLine("Generation Summary:");
Console.Write(" Enums: " + enums);
Console.Write(" Structs: " + structs);
Console.Write(" Boxed: " + boxed);
Console.Write(" Opaques: " + opaques);
Console.Write(" Interfaces: " + interfaces);
Console.Write(" Objects: " + objects);
Console.WriteLine(" Callbacks: " + cbs);
Console.Write(" Properties: " + props);
Console.Write(" Signals: " + sigs);
Console.Write(" Methods: " + methods);
Console.Write(" Constructors: " + ctors);
Console.WriteLine(" Throttled: " + throttled);
Console.WriteLine("Total Nodes: " + (enums+structs+boxed+opaques+interfaces+cbs+objects+props+sigs+methods+ctors+throttled));
Console.WriteLine();
}
}
}
// Statistics.cs : Generation statistics class implementation
//
// Author: Mike Kestner <mkestner@ximian.com>
//
// Copyright (c) 2002 Mike Kestner
// Copyright (c) 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;
public class Statistics {
static int cbs = 0;
static int enums = 0;
static int objects = 0;
static int structs = 0;
static int boxed = 0;
static int opaques = 0;
static int interfaces = 0;
static int methods = 0;
static int ctors = 0;
static int props = 0;
static int sigs = 0;
static int throttled = 0;
static int ignored = 0;
static bool vm_ignored = false;
public static int CBCount {
get {
return cbs;
}
set {
cbs = value;
}
}
public static int EnumCount {
get {
return enums;
}
set {
enums = value;
}
}
public static int ObjectCount {
get {
return objects;
}
set {
objects = value;
}
}
public static int StructCount {
get {
return structs;
}
set {
structs = value;
}
}
public static int BoxedCount {
get {
return boxed;
}
set {
boxed = value;
}
}
public static int OpaqueCount {
get {
return opaques;
}
set {
opaques = value;
}
}
public static int CtorCount {
get {
return ctors;
}
set {
ctors = value;
}
}
public static int MethodCount {
get {
return methods;
}
set {
methods = value;
}
}
public static int PropCount {
get {
return props;
}
set {
props = value;
}
}
public static int SignalCount {
get {
return sigs;
}
set {
sigs = value;
}
}
public static int IFaceCount {
get {
return interfaces;
}
set {
interfaces = value;
}
}
public static int ThrottledCount {
get {
return throttled;
}
set {
throttled = value;
}
}
public static int IgnoreCount {
get {
return ignored;
}
set {
ignored = value;
}
}
public static bool VMIgnored {
get {
return vm_ignored;
}
set {
if (value)
vm_ignored = value;
}
}
public static void Report()
{
if (VMIgnored) {
Console.WriteLine();
Console.WriteLine("Warning: Generation throttled for Virtual Methods.");
Console.WriteLine(" Consider regenerating with --gluelib-name and --glue-filename.");
}
Console.WriteLine();
Console.WriteLine("Generation Summary:");
Console.Write(" Enums: " + enums);
Console.Write(" Structs: " + structs);
Console.Write(" Boxed: " + boxed);
Console.Write(" Opaques: " + opaques);
Console.Write(" Interfaces: " + interfaces);
Console.Write(" Objects: " + objects);
Console.WriteLine(" Callbacks: " + cbs);
Console.Write(" Properties: " + props);
Console.Write(" Signals: " + sigs);
Console.Write(" Methods: " + methods);
Console.Write(" Constructors: " + ctors);
Console.WriteLine(" Throttled: " + throttled);
Console.WriteLine("Total Nodes: " + (enums+structs+boxed+opaques+interfaces+cbs+objects+props+sigs+methods+ctors+throttled));
Console.WriteLine();
}
}
}

View File

@ -1,52 +1,52 @@
// GtkSharp.Generation.StructGen.cs - The Structure Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001 Mike Kestner
//
// 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.IO;
using System.Xml;
public class StructGen : StructBase {
public StructGen (XmlElement ns, XmlElement elem) : base (ns, elem) {}
public override void Generate (GenerationInfo gen_info)
{
gen_info.CurrentType = QualifiedName;
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
base.Generate (gen_info);
if (GetMethod ("GetType") == null && GetMethod ("GetGType") == null) {
sw.WriteLine ("\t\tprivate static GLib.GType GType {");
sw.WriteLine ("\t\t\tget { return GLib.GType.Pointer; }");
sw.WriteLine ("\t\t}");
}
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
Statistics.StructCount++;
}
}
}
// GtkSharp.Generation.StructGen.cs - The Structure Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2001 Mike Kestner
//
// 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.IO;
using System.Xml;
public class StructGen : StructBase {
public StructGen (XmlElement ns, XmlElement elem) : base (ns, elem) {}
public override void Generate (GenerationInfo gen_info)
{
gen_info.CurrentType = QualifiedName;
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
base.Generate (gen_info);
if (GetMethod ("GetType") == null && GetMethod ("GetGType") == null) {
sw.WriteLine ("\t\tprivate static GLib.GType GType {");
sw.WriteLine ("\t\t\tget { return GLib.GType.Pointer; }");
sw.WriteLine ("\t\t}");
}
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
Statistics.StructCount++;
}
}
}

View File

@ -1,388 +1,388 @@
// GtkSharp.Generation.SymbolTable.cs - The Symbol Table Class.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2004-2005 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;
public class SymbolTable {
static SymbolTable table = null;
Hashtable types = new Hashtable ();
public static SymbolTable Table {
get {
if (table == null)
table = new SymbolTable ();
return table;
}
}
public SymbolTable ()
{
// Simple easily mapped types
AddType (new SimpleGen ("void", "void", String.Empty));
AddType (new SimpleGen ("gpointer", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("AtkFunction", "IntPtr", "IntPtr.Zero")); // function definition used for padding
AddType (new SimpleGen ("gboolean", "bool", "false"));
AddType (new SimpleGen ("gint", "int", "0"));
AddType (new SimpleGen ("guint", "uint", "0"));
AddType (new SimpleGen ("int", "int", "0"));
AddType (new SimpleGen ("unsigned", "uint", "0"));
AddType (new SimpleGen ("unsigned int", "uint", "0"));
AddType (new SimpleGen ("unsigned-int", "uint", "0"));
AddType (new SimpleGen ("gshort", "short", "0"));
AddType (new SimpleGen ("gushort", "ushort", "0"));
AddType (new SimpleGen ("short", "short", "0"));
AddType (new SimpleGen ("guchar", "byte", "0"));
AddType (new SimpleGen ("unsigned char", "byte", "0"));
AddType (new SimpleGen ("unsigned-char", "byte", "0"));
AddType (new SimpleGen ("guint1", "bool", "false"));
AddType (new SimpleGen ("uint1", "bool", "false"));
AddType (new SimpleGen ("gint8", "sbyte", "0"));
AddType (new SimpleGen ("guint8", "byte", "0"));
AddType (new SimpleGen ("gint16", "short", "0"));
AddType (new SimpleGen ("guint16", "ushort", "0"));
AddType (new SimpleGen ("gint32", "int", "0"));
AddType (new SimpleGen ("guint32", "uint", "0"));
AddType (new SimpleGen ("gint64", "long", "0"));
AddType (new SimpleGen ("guint64", "ulong", "0"));
AddType (new SimpleGen ("long long", "long", "0"));
AddType (new SimpleGen ("gfloat", "float", "0.0"));
AddType (new SimpleGen ("float", "float", "0.0"));
AddType (new SimpleGen ("gdouble", "double", "0.0"));
AddType (new SimpleGen ("double", "double", "0.0"));
AddType (new SimpleGen ("goffset", "long", "0"));
AddType (new SimpleGen ("GQuark", "int", "0"));
// platform specific integer types.
#if WIN64LONGS
AddType (new SimpleGen ("long", "int", "0"));
AddType (new SimpleGen ("glong", "int", "0"));
AddType (new SimpleGen ("ulong", "uint", "0"));
AddType (new SimpleGen ("gulong", "uint", "0"));
AddType (new SimpleGen ("unsigned long", "uint", "0"));
AddType (new SimpleGen ("gintptr", "int", "0"));
AddType (new SimpleGen ("guintptr", "uint", "0"));
#else
AddType (new LPGen ("long"));
AddType (new LPGen ("glong"));
AddType (new LPGen ("gintptr"));
AddType (new LPUGen ("ulong"));
AddType (new LPUGen ("gulong"));
AddType (new LPUGen ("unsigned long"));
AddType (new LPUGen ("guintptr"));
#endif
AddType (new LPGen ("ssize_t"));
AddType (new LPGen ("gssize"));
AddType (new LPUGen ("size_t"));
AddType (new LPUGen ("gsize"));
#if OFF_T_8
AddType (new AliasGen ("off_t", "long"));
#else
AddType (new LPGen ("off_t"));
#endif
// string types
AddType (new ConstStringGen ("const-gchar"));
AddType (new ConstStringGen ("const-xmlChar"));
AddType (new ConstStringGen ("const-char"));
AddType (new ConstFilenameGen ("const-gfilename"));
AddType (new MarshalGen ("gfilename", "string", "IntPtr", "GLib.Marshaller.StringToFilenamePtr({0})", "GLib.Marshaller.FilenamePtrToStringGFree({0})"));
AddType (new MarshalGen ("gchar", "string", "IntPtr", "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})"));
AddType (new MarshalGen ("char", "string", "IntPtr", "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})"));
AddType (new SimpleGen ("GStrv", "string[]", "null"));
// manually wrapped types requiring more complex marshaling
AddType (new ManualGen ("GInitiallyUnowned", "GLib.InitiallyUnowned", "GLib.Object.GetObject ({0})"));
AddType (new ManualGen ("GObject", "GLib.Object", "GLib.Object.GetObject ({0})"));
AddType (new ManualGen ("GList", "GLib.List"));
AddType (new ManualGen ("GPtrArray", "GLib.PtrArray"));
AddType (new ManualGen ("GSList", "GLib.SList"));
AddType (new ManualGen ("GVariant", "GLib.Variant"));
AddType (new ManualGen ("GVariantType", "GLib.VariantType"));
AddType (new ManualGen ("GValueArray", "GLib.ValueArray"));
AddType (new MarshalGen ("gunichar", "char", "uint", "GLib.Marshaller.CharToGUnichar ({0})", "GLib.Marshaller.GUnicharToChar ({0})"));
AddType (new MarshalGen ("time_t", "System.DateTime", "IntPtr", "GLib.Marshaller.DateTimeTotime_t ({0})", "GLib.Marshaller.time_tToDateTime ({0})"));
AddType (new MarshalGen ("GString", "string", "IntPtr", "new GLib.GString ({0}).Handle", "GLib.GString.PtrToString ({0})"));
AddType (new MarshalGen ("GType", "GLib.GType", "IntPtr", "{0}.Val", "new GLib.GType({0})", "GLib.GType.None"));
AddType (new ByRefGen ("GValue", "GLib.Value"));
AddType (new SimpleGen ("GDestroyNotify", "GLib.DestroyNotify", "null"));
// FIXME: These ought to be handled properly.
AddType (new SimpleGen ("GC", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GError", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GMemChunk", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GTimeVal", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GClosure", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GArray", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GByteArray", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GData", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GIOChannel", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GTypeModule", "GLib.Object", "null"));
AddType (new SimpleGen ("GHashTable", "System.IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("va_list", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GParamSpec", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("gconstpointer", "IntPtr", "IntPtr.Zero"));
}
public void AddType (IGeneratable gen)
{
types [gen.CName] = gen;
}
public void AddTypes (IGeneratable[] gens)
{
foreach (IGeneratable gen in gens)
types [gen.CName] = gen;
}
public int Count {
get
{
return types.Count;
}
}
public IEnumerable Generatables {
get {
return types.Values;
}
}
public IGeneratable this [string ctype] {
get {
return DeAlias (ctype) as IGeneratable;
}
}
private bool IsConstString (string type)
{
switch (type) {
case "const-gchar":
case "const-char":
case "const-xmlChar":
case "const-gfilename":
return true;
default:
return false;
}
}
private string Trim(string type)
{
// HACK: If we don't detect this here, there is no
// way of indicating it in the symbol table
if (type == "void*" || type == "const-void*") return "gpointer";
string trim_type = type.TrimEnd('*');
if (IsConstString (trim_type))
return trim_type;
if (trim_type.StartsWith("const-")) return trim_type.Substring(6);
return trim_type;
}
private object DeAlias (string type)
{
type = Trim (type);
while (types [type] is AliasGen) {
IGeneratable igen = types [type] as AliasGen;
types [type] = types [igen.Name];
type = igen.Name;
}
return types [type];
}
public string FromNative(string c_type, string val)
{
IGeneratable gen = this[c_type];
if (gen == null)
return "";
return gen.FromNative (val);
}
public string GetCSType(string c_type)
{
IGeneratable gen = this[c_type];
if (gen == null)
return "";
return gen.QualifiedName;
}
public string GetName(string c_type)
{
IGeneratable gen = this[c_type];
if (gen == null)
return "";
return gen.Name;
}
public string GetMarshalType(string c_type)
{
IGeneratable gen = this[c_type];
if (gen == null)
return "";
return gen.MarshalType;
}
public string CallByName(string c_type, string var_name)
{
IGeneratable gen = this[c_type];
if (gen == null)
return "";
return gen.CallByName(var_name);
}
public bool IsOpaque(string c_type)
{
if (this[c_type] is OpaqueGen)
return true;
return false;
}
public bool IsBoxed(string c_type)
{
if (this[c_type] is BoxedGen)
return true;
return false;
}
public bool IsStruct(string c_type)
{
if (this[c_type] is StructGen)
return true;
return false;
}
public bool IsEnum(string c_type)
{
if (this[c_type] is EnumGen)
return true;
return false;
}
public bool IsEnumFlags(string c_type)
{
EnumGen gen = this [c_type] as EnumGen;
return (gen != null && gen.Elem.GetAttribute ("type") == "flags");
}
public bool IsInterface(string c_type)
{
if (this[c_type] is InterfaceGen)
return true;
return false;
}
public ClassBase GetClassGen(string c_type)
{
return this[c_type] as ClassBase;
}
public bool IsObject(string c_type)
{
if (this[c_type] is ObjectGen)
return true;
return false;
}
public bool IsCallback(string c_type)
{
if (this[c_type] is CallbackGen)
return true;
return false;
}
public bool IsManuallyWrapped(string c_type)
{
if (this[c_type] is ManualGen)
return true;
return false;
}
public string MangleName(string name)
{
switch (name) {
case "string":
return "str1ng";
case "event":
return "evnt";
case "null":
return "is_null";
case "object":
return "objekt";
case "params":
return "parms";
case "ref":
return "reference";
case "in":
return "in_param";
case "out":
return "out_param";
case "fixed":
return "mfixed";
case "byte":
return "_byte";
case "new":
return "_new";
case "base":
return "_base";
case "lock":
return "_lock";
case "callback":
return "cb";
case "readonly":
return "read_only";
case "interface":
return "iface";
case "internal":
return "_internal";
case "where":
return "wh3r3";
case "foreach":
return "for_each";
case "remove":
return "_remove";
default:
break;
}
return name;
}
}
}
// GtkSharp.Generation.SymbolTable.cs - The Symbol Table Class.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2004-2005 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;
public class SymbolTable {
static SymbolTable table = null;
Hashtable types = new Hashtable ();
public static SymbolTable Table {
get {
if (table == null)
table = new SymbolTable ();
return table;
}
}
public SymbolTable ()
{
// Simple easily mapped types
AddType (new SimpleGen ("void", "void", String.Empty));
AddType (new SimpleGen ("gpointer", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("AtkFunction", "IntPtr", "IntPtr.Zero")); // function definition used for padding
AddType (new SimpleGen ("gboolean", "bool", "false"));
AddType (new SimpleGen ("gint", "int", "0"));
AddType (new SimpleGen ("guint", "uint", "0"));
AddType (new SimpleGen ("int", "int", "0"));
AddType (new SimpleGen ("unsigned", "uint", "0"));
AddType (new SimpleGen ("unsigned int", "uint", "0"));
AddType (new SimpleGen ("unsigned-int", "uint", "0"));
AddType (new SimpleGen ("gshort", "short", "0"));
AddType (new SimpleGen ("gushort", "ushort", "0"));
AddType (new SimpleGen ("short", "short", "0"));
AddType (new SimpleGen ("guchar", "byte", "0"));
AddType (new SimpleGen ("unsigned char", "byte", "0"));
AddType (new SimpleGen ("unsigned-char", "byte", "0"));
AddType (new SimpleGen ("guint1", "bool", "false"));
AddType (new SimpleGen ("uint1", "bool", "false"));
AddType (new SimpleGen ("gint8", "sbyte", "0"));
AddType (new SimpleGen ("guint8", "byte", "0"));
AddType (new SimpleGen ("gint16", "short", "0"));
AddType (new SimpleGen ("guint16", "ushort", "0"));
AddType (new SimpleGen ("gint32", "int", "0"));
AddType (new SimpleGen ("guint32", "uint", "0"));
AddType (new SimpleGen ("gint64", "long", "0"));
AddType (new SimpleGen ("guint64", "ulong", "0"));
AddType (new SimpleGen ("long long", "long", "0"));
AddType (new SimpleGen ("gfloat", "float", "0.0"));
AddType (new SimpleGen ("float", "float", "0.0"));
AddType (new SimpleGen ("gdouble", "double", "0.0"));
AddType (new SimpleGen ("double", "double", "0.0"));
AddType (new SimpleGen ("goffset", "long", "0"));
AddType (new SimpleGen ("GQuark", "int", "0"));
// platform specific integer types.
#if WIN64LONGS
AddType (new SimpleGen ("long", "int", "0"));
AddType (new SimpleGen ("glong", "int", "0"));
AddType (new SimpleGen ("ulong", "uint", "0"));
AddType (new SimpleGen ("gulong", "uint", "0"));
AddType (new SimpleGen ("unsigned long", "uint", "0"));
AddType (new SimpleGen ("gintptr", "int", "0"));
AddType (new SimpleGen ("guintptr", "uint", "0"));
#else
AddType (new LPGen ("long"));
AddType (new LPGen ("glong"));
AddType (new LPGen ("gintptr"));
AddType (new LPUGen ("ulong"));
AddType (new LPUGen ("gulong"));
AddType (new LPUGen ("unsigned long"));
AddType (new LPUGen ("guintptr"));
#endif
AddType (new LPGen ("ssize_t"));
AddType (new LPGen ("gssize"));
AddType (new LPUGen ("size_t"));
AddType (new LPUGen ("gsize"));
#if OFF_T_8
AddType (new AliasGen ("off_t", "long"));
#else
AddType (new LPGen ("off_t"));
#endif
// string types
AddType (new ConstStringGen ("const-gchar"));
AddType (new ConstStringGen ("const-xmlChar"));
AddType (new ConstStringGen ("const-char"));
AddType (new ConstFilenameGen ("const-gfilename"));
AddType (new MarshalGen ("gfilename", "string", "IntPtr", "GLib.Marshaller.StringToFilenamePtr({0})", "GLib.Marshaller.FilenamePtrToStringGFree({0})"));
AddType (new MarshalGen ("gchar", "string", "IntPtr", "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})"));
AddType (new MarshalGen ("char", "string", "IntPtr", "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})"));
AddType (new SimpleGen ("GStrv", "string[]", "null"));
// manually wrapped types requiring more complex marshaling
AddType (new ManualGen ("GInitiallyUnowned", "GLib.InitiallyUnowned", "GLib.Object.GetObject ({0})"));
AddType (new ManualGen ("GObject", "GLib.Object", "GLib.Object.GetObject ({0})"));
AddType (new ManualGen ("GList", "GLib.List"));
AddType (new ManualGen ("GPtrArray", "GLib.PtrArray"));
AddType (new ManualGen ("GSList", "GLib.SList"));
AddType (new ManualGen ("GVariant", "GLib.Variant"));
AddType (new ManualGen ("GVariantType", "GLib.VariantType"));
AddType (new ManualGen ("GValueArray", "GLib.ValueArray"));
AddType (new MarshalGen ("gunichar", "char", "uint", "GLib.Marshaller.CharToGUnichar ({0})", "GLib.Marshaller.GUnicharToChar ({0})"));
AddType (new MarshalGen ("time_t", "System.DateTime", "IntPtr", "GLib.Marshaller.DateTimeTotime_t ({0})", "GLib.Marshaller.time_tToDateTime ({0})"));
AddType (new MarshalGen ("GString", "string", "IntPtr", "new GLib.GString ({0}).Handle", "GLib.GString.PtrToString ({0})"));
AddType (new MarshalGen ("GType", "GLib.GType", "IntPtr", "{0}.Val", "new GLib.GType({0})", "GLib.GType.None"));
AddType (new ByRefGen ("GValue", "GLib.Value"));
AddType (new SimpleGen ("GDestroyNotify", "GLib.DestroyNotify", "null"));
// FIXME: These ought to be handled properly.
AddType (new SimpleGen ("GC", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GError", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GMemChunk", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GTimeVal", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GClosure", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GArray", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GByteArray", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GData", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GIOChannel", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GTypeModule", "GLib.Object", "null"));
AddType (new SimpleGen ("GHashTable", "System.IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("va_list", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GParamSpec", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("gconstpointer", "IntPtr", "IntPtr.Zero"));
}
public void AddType (IGeneratable gen)
{
types [gen.CName] = gen;
}
public void AddTypes (IGeneratable[] gens)
{
foreach (IGeneratable gen in gens)
types [gen.CName] = gen;
}
public int Count {
get
{
return types.Count;
}
}
public IEnumerable Generatables {
get {
return types.Values;
}
}
public IGeneratable this [string ctype] {
get {
return DeAlias (ctype) as IGeneratable;
}
}
private bool IsConstString (string type)
{
switch (type) {
case "const-gchar":
case "const-char":
case "const-xmlChar":
case "const-gfilename":
return true;
default:
return false;
}
}
private string Trim(string type)
{
// HACK: If we don't detect this here, there is no
// way of indicating it in the symbol table
if (type == "void*" || type == "const-void*") return "gpointer";
string trim_type = type.TrimEnd('*');
if (IsConstString (trim_type))
return trim_type;
if (trim_type.StartsWith("const-")) return trim_type.Substring(6);
return trim_type;
}
private object DeAlias (string type)
{
type = Trim (type);
while (types [type] is AliasGen) {
IGeneratable igen = types [type] as AliasGen;
types [type] = types [igen.Name];
type = igen.Name;
}
return types [type];
}
public string FromNative(string c_type, string val)
{
IGeneratable gen = this[c_type];
if (gen == null)
return "";
return gen.FromNative (val);
}
public string GetCSType(string c_type)
{
IGeneratable gen = this[c_type];
if (gen == null)
return "";
return gen.QualifiedName;
}
public string GetName(string c_type)
{
IGeneratable gen = this[c_type];
if (gen == null)
return "";
return gen.Name;
}
public string GetMarshalType(string c_type)
{
IGeneratable gen = this[c_type];
if (gen == null)
return "";
return gen.MarshalType;
}
public string CallByName(string c_type, string var_name)
{
IGeneratable gen = this[c_type];
if (gen == null)
return "";
return gen.CallByName(var_name);
}
public bool IsOpaque(string c_type)
{
if (this[c_type] is OpaqueGen)
return true;
return false;
}
public bool IsBoxed(string c_type)
{
if (this[c_type] is BoxedGen)
return true;
return false;
}
public bool IsStruct(string c_type)
{
if (this[c_type] is StructGen)
return true;
return false;
}
public bool IsEnum(string c_type)
{
if (this[c_type] is EnumGen)
return true;
return false;
}
public bool IsEnumFlags(string c_type)
{
EnumGen gen = this [c_type] as EnumGen;
return (gen != null && gen.Elem.GetAttribute ("type") == "flags");
}
public bool IsInterface(string c_type)
{
if (this[c_type] is InterfaceGen)
return true;
return false;
}
public ClassBase GetClassGen(string c_type)
{
return this[c_type] as ClassBase;
}
public bool IsObject(string c_type)
{
if (this[c_type] is ObjectGen)
return true;
return false;
}
public bool IsCallback(string c_type)
{
if (this[c_type] is CallbackGen)
return true;
return false;
}
public bool IsManuallyWrapped(string c_type)
{
if (this[c_type] is ManualGen)
return true;
return false;
}
public string MangleName(string name)
{
switch (name) {
case "string":
return "str1ng";
case "event":
return "evnt";
case "null":
return "is_null";
case "object":
return "objekt";
case "params":
return "parms";
case "ref":
return "reference";
case "in":
return "in_param";
case "out":
return "out_param";
case "fixed":
return "mfixed";
case "byte":
return "_byte";
case "new":
return "_new";
case "base":
return "_base";
case "lock":
return "_lock";
case "callback":
return "cb";
case "readonly":
return "read_only";
case "interface":
return "iface";
case "internal":
return "_internal";
case "where":
return "wh3r3";
case "foreach":
return "for_each";
case "remove":
return "_remove";
default:
break;
}
return name;
}
}
}

View File

@ -1,91 +1,91 @@
// GtkSharp.Generation.VMSignature.cs - The Virtual Method Signature Generation Class.
//
// Author: Mike Kestner <mkestner@ximian.com>
//
// 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.Xml;
public class VMSignature {
private ArrayList parms = new ArrayList ();
public VMSignature (Parameters parms)
{
bool has_cb = parms.HideData;
for (int i = 0; i < parms.Count; i++) {
Parameter p = parms [i];
if (i > 0 && p.IsLength && parms [i - 1].IsString)
continue;
if (p.IsCount && ((i > 0 && parms [i - 1].IsArray) || (i < parms.Count - 1 && parms [i + 1].IsArray)))
continue;
has_cb = has_cb || p.Generatable is CallbackGen;
if (p.IsUserData && has_cb)
continue;
if (p.CType == "GError**")
continue;
if (p.Scope == "notified")
i += 2;
this.parms.Add (p);
}
}
public string GetCallString (bool use_place_holders)
{
if (parms.Count == 0)
return "";
string[] result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms) {
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
result [i] += use_place_holders ? "{" + i + "}" : p.Name;
i++;
}
return String.Join (", ", result);
}
public override string ToString ()
{
if (parms.Count == 0)
return "";
string[] result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms) {
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
result [i++] += p.CSType + " " + p.Name;
}
return String.Join (", ", result);
}
}
}
// GtkSharp.Generation.VMSignature.cs - The Virtual Method Signature Generation Class.
//
// Author: Mike Kestner <mkestner@ximian.com>
//
// 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.Xml;
public class VMSignature {
private ArrayList parms = new ArrayList ();
public VMSignature (Parameters parms)
{
bool has_cb = parms.HideData;
for (int i = 0; i < parms.Count; i++) {
Parameter p = parms [i];
if (i > 0 && p.IsLength && parms [i - 1].IsString)
continue;
if (p.IsCount && ((i > 0 && parms [i - 1].IsArray) || (i < parms.Count - 1 && parms [i + 1].IsArray)))
continue;
has_cb = has_cb || p.Generatable is CallbackGen;
if (p.IsUserData && has_cb)
continue;
if (p.CType == "GError**")
continue;
if (p.Scope == "notified")
i += 2;
this.parms.Add (p);
}
}
public string GetCallString (bool use_place_holders)
{
if (parms.Count == 0)
return "";
string[] result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms) {
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
result [i] += use_place_holders ? "{" + i + "}" : p.Name;
i++;
}
return String.Join (", ", result);
}
public override string ToString ()
{
if (parms.Count == 0)
return "";
string[] result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms) {
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
result [i++] += p.CSType + " " + p.Name;
}
return String.Join (", ", result);
}
}
}