no more submodule

This commit is contained in:
2024-09-15 22:40:48 +02:00
parent df3b8a3135
commit 0234b33671
5804 changed files with 943618 additions and 1 deletions

View File

@@ -0,0 +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) {}
}
}

View File

@@ -0,0 +1,177 @@
// GtkSharp.Generation.Parameters.cs - The Parameters Generation Class.
//
// 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.Generic;
using System.Xml;
public class ArrayParameter : Parameter {
bool null_terminated;
public ArrayParameter (XmlElement elem) : base (elem)
{
null_terminated = elem.GetAttributeAsBoolean ("null_term_array");
if (elem.HasAttribute ("array_len"))
FixedArrayLength = Int32.Parse (elem.GetAttribute ("array_len"));
}
public override string MarshalType {
get {
if (Generatable is StructBase)
return CSType;
else
return base.MarshalType;
}
}
bool NullTerminated {
get {
return null_terminated;
}
}
public int? FixedArrayLength { get; private set; }
public override string[] Prepare {
get {
if (CSType == MarshalType && !FixedArrayLength.HasValue)
return new string [0];
var result = new List<string> ();
if (FixedArrayLength.HasValue) {
result.Add (String.Format ("{0} = new {1}[{2}];", Name, MarshalType.TrimEnd ('[', ']'), FixedArrayLength));
return result.ToArray ();
}
result.Add (String.Format ("int cnt_{0} = {0} == null ? 0 : {0}.Length;", CallName));
result.Add (String.Format ("{0}[] native_{1} = new {0} [cnt_{1}" + (NullTerminated ? " + 1" : "") + "];", MarshalType.TrimEnd('[', ']'), CallName));
result.Add (String.Format ("for (int i = 0; i < cnt_{0}; i++)", CallName));
IGeneratable gen = Generatable;
if (gen is IManualMarshaler)
result.Add (String.Format ("\tnative_{0} [i] = {1};", CallName, (gen as IManualMarshaler).AllocNative (CallName + "[i]")));
else
result.Add (String.Format ("\tnative_{0} [i] = {1};", CallName, gen.CallByName (CallName + "[i]")));
if (NullTerminated)
result.Add (String.Format ("native_{0} [cnt_{0}] = IntPtr.Zero;", CallName));
return result.ToArray ();
}
}
public override string CallString {
get {
if (CSType != MarshalType)
return "native_" + CallName;
else if (FixedArrayLength.HasValue)
return base.CallString;
else
return CallName;
}
}
public override string[] Finish {
get {
if (CSType == MarshalType)
return new string [0];
IGeneratable gen = Generatable;
if (gen is IManualMarshaler) {
string [] result = new string [4];
result [0] = "for (int i = 0; i < native_" + CallName + ".Length" + (NullTerminated ? " - 1" : "") + "; i++) {";
result [1] = "\t" + CallName + " [i] = " + Generatable.FromNative ("native_" + CallName + "[i]") + ";";
result [2] = "\t" + (gen as IManualMarshaler).ReleaseNative ("native_" + CallName + "[i]") + ";";
result [3] = "}";
return result;
}
return new string [0];
}
}
}
public class ArrayCountPair : ArrayParameter {
XmlElement count_elem;
bool invert;
public ArrayCountPair (XmlElement array_elem, XmlElement count_elem, bool invert) : base (array_elem)
{
this.count_elem = count_elem;
this.invert = invert;
}
string CountNativeType {
get {
return SymbolTable.Table.GetMarshalType(count_elem.GetAttribute("type"));
}
}
string CountType {
get {
return SymbolTable.Table.GetCSType(count_elem.GetAttribute("type"));
}
}
string CountCast {
get {
if (CountType == "int")
return String.Empty;
else
return "(" + CountType + ") ";
}
}
string CountName {
get {
return SymbolTable.Table.MangleName (count_elem.GetAttribute("name"));
}
}
string CallCount (string name)
{
string result = CountCast + "(" + name + " == null ? 0 : " + name + ".Length)";
IGeneratable gen = SymbolTable.Table[count_elem.GetAttribute("type")];
return gen.CallByName (result);
}
public override string CallString {
get {
if (invert)
return CallCount (CallName) + ", " + base.CallString;
else
return base.CallString + ", " + CallCount (CallName);
}
}
public override string NativeSignature {
get {
if (invert)
return CountNativeType + " " + CountName + ", " + MarshalType + " " + Name;
else
return MarshalType + " " + Name + ", " + CountNativeType + " " + CountName;
}
}
}
}

View File

@@ -0,0 +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 = GetMethod ("Copy");
Method free = GetMethod ("Free");
Methods.Remove ("Copy");
Methods.Remove ("Free");
gen_info.CurrentType = QualifiedName;
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name, NS);
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

@@ -0,0 +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 (" + GenerationInfo.GetSizeOfExpression(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

@@ -0,0 +1,316 @@
// GtkSharp.Generation.CallbackGen.cs - The Callback Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2002-2003 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 {
using System;
using System.IO;
using System.Xml;
public class CallbackGen : GenBase, IAccessor {
private Parameters parms;
private Signature sig = null;
private ReturnValue retval;
private bool valid = true;
public CallbackGen (XmlElement ns, XmlElement elem) : base (ns, elem)
{
retval = new ReturnValue (elem ["return-type"]);
parms = new Parameters (elem ["parameters"]);
parms.HideData = true;
}
public override string DefaultValue {
get { return "null"; }
}
public override bool Validate ()
{
valid = true;
LogWriter log = new LogWriter (QualifiedName);
log.Type = QualifiedName;
if (!retval.Validate (log) || !parms.Validate (log)) {
Statistics.ThrottledCount++;
valid = false;
}
if (!String.IsNullOrEmpty (retval.CountParameterName))
retval.CountParameter = parms.GetCountParameter (retval.CountParameterName);
if (retval.CountParameterIndex >= 0)
retval.CountParameter = parms[retval.CountParameterIndex];
return valid;
}
public string InvokerName {
get {
if (!valid)
return String.Empty;
return NS + "Sharp." + Name + "Invoker";
}
}
public string WrapperName {
get {
if (!valid)
return String.Empty;
return NS + "Sharp." + Name + "Wrapper";
}
}
public override string MarshalType {
get {
if (valid)
return NS + "Sharp." + Name + "Native";
else
return "";
}
}
public override string CallByName (string var_name)
{
return var_name + ".NativeDelegate";
}
public override string FromNative (string var)
{
return NS + "Sharp." + Name + "Wrapper.GetManagedDelegate (" + var + ")";
}
public void WriteAccessors (TextWriter sw, string indent, string var)
{
sw.WriteLine (indent + "get {");
sw.WriteLine (indent + "\treturn " + FromNative (var) + ";");
sw.WriteLine (indent + "}");
}
string CastFromInt (string type)
{
return type != "int" ? "(" + type + ") " : "";
}
string InvokeString {
get {
if (parms.Count == 0)
return String.Empty;
string[] result = new string [parms.Count];
for (int i = 0; i < parms.Count; i++) {
Parameter p = parms [i];
IGeneratable igen = p.Generatable;
if (i > 0 && parms [i - 1].IsString && p.IsLength) {
string string_name = parms [i - 1].Name;
result[i] = igen.CallByName (CastFromInt (p.CSType) + "System.Text.Encoding.UTF8.GetByteCount (" + string_name + ")");
continue;
}
p.CallName = p.Name;
result [i] = p.CallString;
if (p.IsUserData)
result [i] = "__data";
}
return String.Join (", ", result);
}
}
MethodBody body;
void GenInvoker (GenerationInfo gen_info, StreamWriter sw)
{
if (sig == null)
sig = new Signature (parms);
sw.WriteLine ("\tinternal class " + Name + "Invoker {");
sw.WriteLine ();
sw.WriteLine ("\t\t" + Name + "Native native_cb;");
sw.WriteLine ("\t\tIntPtr __data;");
sw.WriteLine ("\t\tGLib.DestroyNotify __notify;");
sw.WriteLine ();
sw.WriteLine ("\t\t~" + Name + "Invoker ()");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (__notify == null)");
sw.WriteLine ("\t\t\t\treturn;");
sw.WriteLine ("\t\t\t__notify (__data);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tinternal " + Name + "Invoker (" + Name + "Native native_cb) : this (native_cb, IntPtr.Zero, null) {}");
sw.WriteLine ();
sw.WriteLine ("\t\tinternal " + Name + "Invoker (" + Name + "Native native_cb, IntPtr data) : this (native_cb, data, null) {}");
sw.WriteLine ();
sw.WriteLine ("\t\tinternal " + Name + "Invoker (" + Name + "Native native_cb, IntPtr data, GLib.DestroyNotify notify)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tthis.native_cb = native_cb;");
sw.WriteLine ("\t\t\t__data = data;");
sw.WriteLine ("\t\t\t__notify = notify;");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tinternal " + QualifiedName + " Handler {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn new " + QualifiedName + "(InvokeNative);");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\t" + retval.CSType + " InvokeNative (" + sig + ")");
sw.WriteLine ("\t\t{");
body.Initialize (gen_info);
string call = "native_cb (" + InvokeString + ")";
if (retval.IsVoid)
sw.WriteLine ("\t\t\t" + call + ";");
else
sw.WriteLine ("\t\t\t" + retval.CSType + " __result = " + retval.FromNative (call) + ";");
body.Finish (sw, String.Empty);
if (!retval.IsVoid)
sw.WriteLine ("\t\t\treturn __result;");
sw.WriteLine ("\t\t}");
sw.WriteLine ("\t}");
sw.WriteLine ();
}
public string GenWrapper (GenerationInfo gen_info)
{
string wrapper = Name + "Native";
string qualname = MarshalType;
if (!Validate ())
return String.Empty;
LogWriter log = new LogWriter (qualname);
body = new MethodBody (parms, log);
StreamWriter save_sw = gen_info.Writer;
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (qualname, NS);
sw.WriteLine ("namespace " + NS + "Sharp {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
//sw.WriteLine ("\t[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
sw.WriteLine ("\tinternal delegate " + retval.MarshalType + " " + wrapper + "(" + parms.ImportSignature + ");");
sw.WriteLine ();
GenInvoker (gen_info, sw);
sw.WriteLine ("\tinternal class " + Name + "Wrapper {");
sw.WriteLine ();
ManagedCallString call = new ManagedCallString (parms);
sw.WriteLine ("\t\tpublic " + retval.MarshalType + " NativeCallback (" + parms.ImportSignature + ")");
sw.WriteLine ("\t\t{");
string unconditional = call.Unconditional ("\t\t\t");
if (unconditional.Length > 0)
sw.WriteLine (unconditional);
sw.WriteLine ("\t\t\ttry {");
string call_setup = call.Setup ("\t\t\t\t");
if (call_setup.Length > 0)
sw.WriteLine (call_setup);
if (retval.CSType == "void")
sw.WriteLine ("\t\t\t\tmanaged ({0});", call);
else
sw.WriteLine ("\t\t\t\t{0} __ret = managed ({1});", retval.CSType, call);
string finish = call.Finish ("\t\t\t\t");
if (finish.Length > 0)
sw.WriteLine (finish);
sw.WriteLine ("\t\t\t\tif (release_on_call)\n\t\t\t\t\tgch.Free ();");
Parameter cnt = retval.CountParameter;
if (cnt != null)
sw.WriteLine ("\t\t\t\t{0} = {1}{2};", cnt.Name, cnt.CSType == "int" ? String.Empty : "(" + cnt.MarshalType + ")(" + cnt.CSType + ")", "__ret.Length");
if (retval.CSType != "void")
sw.WriteLine ("\t\t\t\treturn {0};", retval.ToNative ("__ret"));
/* If the function expects one or more "out" parameters(error parameters are excluded) or has a return value different from void and bool, exceptions
* thrown in the managed function have to be considered fatal meaning that an exception is to be thrown and the function call cannot not return
*/
bool fatal = (retval.MarshalType != "void" && retval.MarshalType != "bool") || call.HasOutParam;
sw.WriteLine ("\t\t\t} catch (Exception e) {");
sw.WriteLine ("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");");
if (fatal) {
sw.WriteLine ("\t\t\t\t// NOTREACHED: Above call does not return.");
sw.WriteLine ("\t\t\t\tthrow;");
} else if (retval.MarshalType == "bool") {
sw.WriteLine ("\t\t\t\treturn false;");
}
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tbool release_on_call = false;");
sw.WriteLine ("\t\tGCHandle gch;");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic void PersistUntilCalled ()");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\trelease_on_call = true;");
sw.WriteLine ("\t\t\tgch = GCHandle.Alloc (this);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tinternal " + wrapper + " NativeDelegate;");
sw.WriteLine ("\t\t" + NS + "." + Name + " managed;");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic " + Name + "Wrapper (" + NS + "." + Name + " managed)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tthis.managed = managed;");
sw.WriteLine ("\t\t\tif (managed != null)");
sw.WriteLine ("\t\t\t\tNativeDelegate = new " + wrapper + " (NativeCallback);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic static " + NS + "." + Name + " GetManagedDelegate (" + wrapper + " native)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (native == null)");
sw.WriteLine ("\t\t\t\treturn null;");
sw.WriteLine ("\t\t\t" + Name + "Wrapper wrapper = (" + Name + "Wrapper) native.Target;");
sw.WriteLine ("\t\t\tif (wrapper == null)");
sw.WriteLine ("\t\t\t\treturn null;");
sw.WriteLine ("\t\t\treturn wrapper.managed;");
sw.WriteLine ("\t\t}");
sw.WriteLine ("\t}");
sw.WriteLine ("#endregion");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = save_sw;
return NS + "Sharp." + Name + "Wrapper";
}
public override void Generate (GenerationInfo gen_info)
{
gen_info.CurrentType = QualifiedName;
sig = new Signature (parms);
StreamWriter sw = gen_info.OpenStream (Name, NS);
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ();
sw.WriteLine ("\t{0} delegate " + retval.CSType + " " + Name + "(" + sig.ToString() + ");", IsInternal ? "internal" : "public");
sw.WriteLine ();
sw.WriteLine ("}");
sw.Close ();
GenWrapper (gen_info);
Statistics.CBCount++;
}
}
}

View File

@@ -0,0 +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)";
}
}
}

View File

@@ -0,0 +1,607 @@
// GtkSharp.Generation.ClassBase.cs - Common code between object
// and interface wrappers
//
// Authors: Rachel Hestilow <hestilow@ximian.com>
// Mike Kestner <mkestner@speakeasy.net>
//
// Copyright (c) 2002 Rachel Hestilow
// 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.Collections.Generic;
using System.IO;
using System.Xml;
public abstract class ClassBase : GenBase {
private IDictionary<string, Property> props = new Dictionary<string, Property> ();
private IDictionary<string, ObjectField> fields = new Dictionary<string, ObjectField> ();
private IDictionary<string, Method> methods = new Dictionary<string, Method> ();
private IDictionary<string, Constant> constants = new Dictionary<string, Constant>();
protected IList<string> interfaces = new List<string>();
protected IList<string> managed_interfaces = new List<string>();
protected IList<Ctor> ctors = new List<Ctor>();
protected List<StructABIField> abi_fields = new List<StructABIField> ();
protected bool abi_fields_valid; // false if the instance structure contains a bitfield or fields of unknown types
private bool ctors_initted = false;
private Dictionary<string, Ctor> clash_map;
private bool deprecated = false;
private bool isabstract = false;
public bool nameConstructors {
get {
return Elem.GetAttributeAsBoolean("name_constructors");
}
}
public IDictionary<string, Method> Methods {
get {
return methods;
}
}
public IDictionary<string, Property> Properties {
get {
return props;
}
}
public ClassBase Parent {
get {
string parent = Elem.GetAttribute("parent");
if (parent == "")
return null;
else
return SymbolTable.Table.GetClassGen(parent);
}
}
protected ClassBase (XmlElement ns, XmlElement elem) : base (ns, elem) {
deprecated = elem.GetAttributeAsBoolean ("deprecated");
isabstract = elem.GetAttributeAsBoolean ("abstract");
abi_fields_valid = true;
string parent_type = Elem.GetAttribute("parent");
int num_abi_fields = 0;
foreach (XmlNode node in elem.ChildNodes) {
if (!(node is XmlElement)) continue;
XmlElement member = (XmlElement) node;
StructABIField abi_field = null;
// Make sure ABI fields are taken into account, even when hidden.
if (node.Name == "field") {
num_abi_fields += 1;
// Skip instance parent struct if present, taking into account
// bindinator broken behaviour concerning parent field (ie.
// marking it as pointer, somehow risky but good enough for now.)
if (num_abi_fields != 1 ||
parent_type == "" ||
(member.GetAttribute("type").Replace("*", "") != parent_type
)) {
abi_field = new StructABIField (member, this, "abi_info");
abi_fields.Add (abi_field);
}
} else if (node.Name == "union") {
abi_field = new UnionABIField (member, this, "abi_info");
abi_fields.Add (abi_field);
}
if (member.GetAttributeAsBoolean ("hidden"))
continue;
string name;
switch (node.Name) {
case "method":
name = member.GetAttribute("name");
while (methods.ContainsKey(name))
name += "mangled";
methods.Add (name, new Method (member, this));
break;
case "property":
name = member.GetAttribute("name");
while (props.ContainsKey(name))
name += "mangled";
props.Add (name, new Property (member, this));
break;
case "field":
// FIXME Generate callbacks.
if (member.GetAttributeAsBoolean ("is_callback"))
continue;
name = member.GetAttribute("name");
while (fields.ContainsKey (name))
name += "mangled";
var field = new ObjectField (member, this);
field.abi_field = abi_field;
fields.Add (name, field);
break;
case "implements":
ParseImplements (member);
break;
case "constructor":
ctors.Add (new Ctor (member, this));
break;
case "constant":
name = member.GetAttribute ("name");
constants.Add (name, new Constant (member));
break;
default:
break;
}
}
}
public virtual bool CanGenerateABIStruct(LogWriter log) {
return (abi_fields_valid);
}
bool CheckABIStructParent(LogWriter log, out string cs_parent_struct) {
cs_parent_struct = null;
if (!CanGenerateABIStruct(log))
return false;
var parent = SymbolTable.Table[Elem.GetAttribute("parent")];
string cs_parent = SymbolTable.Table.GetCSType(Elem.GetAttribute("parent"));
var parent_can_generate = true;
cs_parent_struct = null;
if (parent != null) {
// FIXME Add that information to ManualGen and use it.
if (parent.CName == "GInitiallyUnowned" || parent.CName == "GObject") {
cs_parent_struct = "GLib.Object";
} else {
parent_can_generate = false;
var _parent = parent as ClassBase;
if (_parent != null) {
string tmp;
parent_can_generate = _parent.CheckABIStructParent(log, out tmp);
}
if (parent_can_generate)
cs_parent_struct = cs_parent;
}
if (!parent_can_generate) {
log.Warn("Can't generate ABI structrure as the parent structure '" +
parent.CName + "' can't be generated.");
return false;
}
} else {
cs_parent_struct = "";
}
return parent_can_generate;
}
protected void GenerateStructureABI (GenerationInfo gen_info) {
GenerateStructureABI(gen_info, null, "abi_info", CName);
}
protected void GenerateStructureABI (GenerationInfo gen_info, List<StructABIField> _fields,
string info_name, string structname)
{
string cs_parent_struct = null;
if (_fields == null)
_fields = abi_fields;
LogWriter log = new LogWriter (QualifiedName);
if (!CheckABIStructParent (log, out cs_parent_struct))
return;
StreamWriter sw = gen_info.Writer;
var _new = "";
if (cs_parent_struct != "")
_new = "new ";
sw.WriteLine ();
sw.WriteLine ("\t\t// Internal representation of the wrapped structure ABI.");
sw.WriteLine ("\t\tstatic GLib.AbiStruct _" + info_name + " = null;");
sw.WriteLine ("\t\tstatic public unsafe " + _new + "GLib.AbiStruct " + info_name + " {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\tif (_" + info_name + " == null)");
// Generate Tests
var using_parent_fields = false;
if (_fields.Count > 0) {
sw.WriteLine ("\t\t\t\t\t_" + info_name + " = new GLib.AbiStruct (new List<GLib.AbiField>{ ");
if (gen_info.CAbiWriter != null) {
gen_info.CAbiWriter.WriteLine("\tg_print(\"\\\"sizeof({0})\\\": \\\"%\" G_GUINT64_FORMAT \"\\\"\\n\", (guint64) sizeof({0}));", structname);
gen_info.AbiWriter.WriteLine("\t\t\tConsole.WriteLine(\"\\\"sizeof({0})\\\": \\\"\" + {1}.{2}." + info_name + ".Size + \"\\\"\");", structname, NS, Name);
}
} else {
if (cs_parent_struct != "") {
sw.WriteLine ("\t\t\t\t\t_" + info_name + " = new GLib.AbiStruct ({0}.{1}.Fields);", cs_parent_struct, info_name);
using_parent_fields = true;
} else {
sw.WriteLine ("\t\t\t\t\t_" + info_name + " = new GLib.AbiStruct (new List<GLib.AbiField>{ ");
using_parent_fields = false;
}
}
StructABIField prev = null;
StructABIField next = null;
StringWriter field_alignment_structures_writer = new StringWriter();
for(int i=0; i < _fields.Count; i++) {
var field = _fields[i];
next = _fields.Count > i +1 ? _fields[i + 1] : null;
prev = field.Generate(gen_info, "\t\t\t\t\t", prev, next, cs_parent_struct,
field_alignment_structures_writer);
if (field.IsPadding)
continue;
var union = field as UnionABIField;
if (union == null && gen_info.CAbiWriter != null && !field.IsBitfield) {
gen_info.AbiWriter.WriteLine("\t\t\tConsole.WriteLine(\"\\\"{0}.{3}\\\": \\\"\" + {1}.{2}." + info_name + ".GetFieldOffset(\"{3}\") + \"\\\"\");", structname, NS, Name, field.CName);
gen_info.CAbiWriter.WriteLine("\tg_print(\"\\\"{0}.{1}\\\": \\\"%\" G_GUINT64_FORMAT \"\\\"\\n\", (guint64) G_STRUCT_OFFSET({0}, {1}));", structname, field.CName);
}
}
if (_fields.Count > 0 && gen_info.CAbiWriter != null) {
gen_info.AbiWriter.Flush();
gen_info.CAbiWriter.Flush();
}
if (!using_parent_fields)
sw.WriteLine ("\t\t\t\t\t});");
sw.WriteLine ();
sw.WriteLine ("\t\t\t\treturn _" + info_name + ";");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine (field_alignment_structures_writer.ToString());
sw.WriteLine ("\t\t// End of the ABI representation.");
sw.WriteLine ();
}
public override bool Validate ()
{
LogWriter log = new LogWriter (QualifiedName);
foreach (string iface in interfaces) {
InterfaceGen igen = SymbolTable.Table[iface] as InterfaceGen;
if (igen == null) {
log.Warn ("implements unknown GInterface " + iface);
return false;
}
if (!igen.ValidateForSubclass ()) {
log.Warn ("implements invalid GInterface " + iface);
return false;
}
}
foreach (StructABIField abi_field in abi_fields) {
if (!abi_field.Validate(log))
abi_fields_valid = false;
}
if (abi_fields_valid)
foreach (StructABIField abi_field in abi_fields) {
abi_field.SetGetOffseName();
}
ArrayList invalids = new ArrayList ();
foreach (Property prop in props.Values) {
if (!prop.Validate (log))
invalids.Add (prop);
}
foreach (Property prop in invalids)
props.Remove (prop.Name);
invalids.Clear ();
foreach (ObjectField field in fields.Values) {
if (!field.Validate (log))
invalids.Add (field);
}
foreach (ObjectField field in invalids)
fields.Remove (field.Name);
invalids.Clear ();
foreach (Method method in methods.Values) {
if (!method.Validate (log))
invalids.Add (method);
}
foreach (Method method in invalids)
methods.Remove (method.Name);
invalids.Clear ();
foreach (Constant con in constants.Values) {
if (!con.Validate (log))
invalids.Add (con);
}
foreach (Constant con in invalids)
constants.Remove (con.Name);
invalids.Clear ();
foreach (Ctor ctor in ctors) {
if (!ctor.Validate (log))
invalids.Add (ctor);
}
foreach (Ctor ctor in invalids)
ctors.Remove (ctor);
invalids.Clear ();
return true;
}
public bool IsDeprecated {
get {
return deprecated;
}
}
public bool IsAbstract {
get {
return isabstract;
}
}
public abstract string AssignToName { get; }
public abstract string CallByName ();
public override string DefaultValue {
get {
return "null";
}
}
protected virtual bool IsNodeNameHandled (string name)
{
switch (name) {
case "method":
case "property":
case "field":
case "signal":
case "implements":
case "constructor":
case "disabledefaultconstructor":
case "constant":
return true;
default:
return false;
}
}
public void GenProperties (GenerationInfo gen_info, ClassBase implementor)
{
if (props.Count == 0)
return;
foreach (Property prop in props.Values)
prop.Generate (gen_info, "\t\t", implementor);
}
protected void GenFields (GenerationInfo gen_info)
{
foreach (ObjectField field in fields.Values) {
field.Generate (gen_info, "\t\t");
}
}
protected void GenConstants (GenerationInfo gen_info)
{
foreach (Constant con in constants.Values)
con.Generate (gen_info, "\t\t");
}
private void ParseImplements (XmlElement member)
{
foreach (XmlNode node in member.ChildNodes) {
if (node.Name != "interface")
continue;
XmlElement element = (XmlElement) node;
if (element.GetAttributeAsBoolean ("hidden"))
continue;
if (element.HasAttribute ("cname"))
interfaces.Add (element.GetAttribute ("cname"));
else if (element.HasAttribute ("name"))
managed_interfaces.Add (element.GetAttribute ("name"));
}
}
protected bool IgnoreMethod (Method method, ClassBase implementor)
{
if (implementor != null && implementor.QualifiedName != this.QualifiedName && method.IsStatic)
return true;
string mname = method.Name;
return ((method.IsSetter || (method.IsGetter && mname.StartsWith("Get"))) &&
((props != null) && props.ContainsKey(mname.Substring(3)) ||
(fields != null) && fields.ContainsKey(mname.Substring(3))));
}
public void GenMethods (GenerationInfo gen_info, IDictionary<string, bool> collisions, ClassBase implementor)
{
if (methods == null)
return;
foreach (Method method in methods.Values) {
if (IgnoreMethod (method, implementor))
continue;
string oname = null, oprotection = null;
if (collisions != null && collisions.ContainsKey (method.Name)) {
oname = method.Name;
oprotection = method.Protection;
method.Name = QualifiedName + "." + method.Name;
method.Protection = "";
}
method.Generate (gen_info, implementor);
if (oname != null) {
method.Name = oname;
method.Protection = oprotection;
}
}
}
public Method GetMethod (string name)
{
Method m = null;
methods.TryGetValue (name, out m);
return m;
}
public Property GetProperty (string name)
{
Property prop = null;
props.TryGetValue (name, out prop);
return prop;
}
public Method GetMethodRecursively (string name)
{
return GetMethodRecursively (name, false);
}
public virtual Method GetMethodRecursively (string name, bool check_self)
{
Method p = null;
if (check_self)
p = GetMethod (name);
if (p == null && Parent != null)
p = Parent.GetMethodRecursively (name, true);
if (check_self && p == null) {
foreach (string iface in interfaces) {
ClassBase igen = SymbolTable.Table.GetClassGen (iface);
if (igen == null)
continue;
p = igen.GetMethodRecursively (name, true);
if (p != null)
break;
}
}
return p;
}
public virtual Property GetPropertyRecursively (string name)
{
ClassBase klass = this;
Property p = null;
while (klass != null && p == null) {
p = (Property) klass.GetProperty (name);
klass = klass.Parent;
}
if (p == null) {
foreach (string iface in interfaces) {
ClassBase igen = SymbolTable.Table.GetClassGen (iface);
if (igen == null)
continue;
p = igen.GetPropertyRecursively (name);
if (p != null)
break;
}
}
return p;
}
public bool Implements (string iface)
{
if (interfaces.Contains (iface))
return true;
else if (Parent != null)
return Parent.Implements (iface);
else
return false;
}
public IList<Ctor> Ctors { get { return ctors; } }
bool HasStaticCtor (string name)
{
if (Parent != null && Parent.HasStaticCtor (name))
return true;
foreach (Ctor ctor in Ctors)
if (ctor.StaticName == name)
return true;
return false;
}
private void InitializeCtors ()
{
if (ctors_initted)
return;
if (Parent != null)
Parent.InitializeCtors ();
var valid_ctors = new List<Ctor>();
clash_map = new Dictionary<string, Ctor>();
foreach (Ctor ctor in ctors) {
if (nameConstructors) {
ctor.IsStatic = true;
if (Parent != null && Parent.HasStaticCtor (ctor.StaticName))
ctor.Modifiers = "new ";
} else if (clash_map.ContainsKey (ctor.Signature.Types)) {
Ctor clash = clash_map [ctor.Signature.Types];
Ctor alter = ctor.Preferred ? clash : ctor;
alter.IsStatic = true;
if (Parent != null && Parent.HasStaticCtor (alter.StaticName))
alter.Modifiers = "new ";
} else
clash_map [ctor.Signature.Types] = ctor;
valid_ctors.Add (ctor);
}
ctors = valid_ctors;
ctors_initted = true;
}
protected virtual void GenCtors (GenerationInfo gen_info)
{
InitializeCtors ();
foreach (Ctor ctor in ctors)
ctor.Generate (gen_info);
}
public virtual void Finish (StreamWriter sw, string indent)
{
}
public virtual void Prepare (StreamWriter sw, string indent)
{
}
}
}

View File

@@ -0,0 +1,47 @@
// GtkSharp.Generation.ClassField.cs - used in class structures
//
// Copyright (c) 2009 Christian Hoff
//
// 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 ClassField : StructField {
protected new ObjectBase container_type;
public ClassField (XmlElement elem, ObjectBase container_type) : base (elem, container_type) {
this.container_type = container_type;
}
public override bool Validate (LogWriter log)
{
if (!base.Validate (log))
return false;
if (IsBitfield) {
log.Warn ("bitfields are not supported");
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,94 @@
// 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, NS);
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 ();
GenConstants (gen_info);
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

@@ -0,0 +1,172 @@
// 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.Generic;
using System.IO;
using System.Xml;
public class CodeGenerator {
public static ulong Counter = 0;
static LogWriter log = new LogWriter ("CodeGenerator");
public static int Main (string[] args)
{
bool show_help = false;
bool all_opaque = true;
string dir = "";
string assembly_name = "";
string gapidir = "";
string abi_cs_usings = "";
string abi_cs_file = "";
string abi_c_file = "";
string glue_filename = "";
string glue_includes = "";
string gluelib_name = "";
string schema_name = "";
SymbolTable table = SymbolTable.Table;
var gens = new List<IGeneratable> ();
var filenames = new List<string> ();
var includes = new List<string> ();
var options = new OptionSet () {
{ "generate=", "Generate the C# code for this GAPI XML file.",
(string v) => { filenames.Add (v); } },
{ "I|include=", "GAPI XML file that contain symbols used in the main GAPI XML file.",
(string v) => { includes.Add (v); } },
{ "outdir=", "Directory where the C# files will be generated.",
(string v) => { dir = v; } },
{ "assembly-name=", "Name of the assembly for which the code is generated.",
(string v) => { assembly_name = v; } },
{ "gapidir=", "GAPI xml data folder.",
(string v) => { gapidir = v; } },
{ "abi-cs-filename=", "Filename for the generated CSharp ABI checker.",
(string v) => { abi_cs_file = v; } },
{ "abi-cs-usings=", "Namespaces to use in the CS ABI checker.",
(string v) => { abi_cs_usings = v; } },
{ "abi-c-filename=", "Filename for the generated C ABI checker.",
(string v) => { abi_c_file = v; } },
{ "glue-filename=", "Filename for the generated C glue code.",
(string v) => { glue_filename = v; } },
{ "glue-includes=", "Content of #include directive to add in the generated C glue code.",
(string v) => { glue_includes = v; } },
{ "gluelib-name=", "Name of the C library into which the C glue code will be compiled. " +
"Used to generated correct DllImport attributes.",
(string v) => { gluelib_name = v; } },
{ "schema=", "Validate all GAPI XML files against this XSD schema.",
(string v) => { schema_name = v; } },
{ "h|help", "Show this message and exit",
v => show_help = v != null },
};
List<string> extra;
try {
extra = options.Parse (args);
}
catch (OptionException e) {
Console.Write ("gapi-codegen: ");
Console.WriteLine (e.Message);
Console.WriteLine ("Try `gapi-codegen --help' for more information.");
return 64;
}
if (show_help) {
ShowHelp (options);
return 0;
}
if (filenames.Count == 0) {
Console.WriteLine ("You need to specify a file to process using the --generate option.");
Console.WriteLine ("Try `gapi-codegen --help' for more information.");
return 64;
}
if (extra.Exists (v => { return v.StartsWith ("--customdir"); })) {
Console.WriteLine ("Using .custom files is not supported anymore, use partial classes instead.");
return 64;
}
if (!String.IsNullOrEmpty (schema_name) && !File.Exists (schema_name)) {
Console.WriteLine ("WARNING: Could not find schema file at '{0}', no validation will be done.", schema_name);
schema_name = null;
}
Parser p = new Parser ();
foreach (string include in includes) {
log.Info("Parsing included gapi: " + include);
IGeneratable[] curr_gens = p.Parse (include, schema_name, gapidir);
table.AddTypes (curr_gens);
}
foreach (string filename in filenames) {
log.Info("Parsing included gapi: " + filename);
IGeneratable[] curr_gens = p.Parse (filename, schema_name, gapidir);
table.AddTypes (curr_gens);
gens.AddRange (curr_gens);
}
// Now that everything is loaded, validate all the to-be-
// generated generatables and then remove the invalid ones.
var invalids = new List<IGeneratable> ();
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,
abi_c_file, abi_cs_file, abi_cs_usings);
foreach (IGeneratable gen in gens) {
if (gen_info == null)
gen.Generate ();
else
gen.Generate (gen_info);
}
ObjectGen.GenerateMappers ();
if (gen_info != null)
gen_info.CloseWriters ();
Statistics.Report();
return 0;
}
static void ShowHelp (OptionSet p)
{
Console.WriteLine ("Usage: gapi-codegen [OPTIONS]+");
Console.WriteLine ();
Console.WriteLine ("Options:");
p.WriteOptionDescriptions (Console.Out);
}
}
}

View File

@@ -0,0 +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 + ")";
}
}
}

View File

@@ -0,0 +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 + ")";
}
}
}

View File

@@ -0,0 +1,87 @@
// Authors:
// Stephan Sundermann <stephansundermann@gmail.com>
//
// Copyright (c) 2013 Stephan Sundermann
//
// 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.
using System;
using System.Xml;
using System.IO;
namespace GtkSharp.Generation
{
public class Constant
{
private readonly string name;
private readonly string value;
private readonly string ctype;
public Constant (XmlElement elem)
{
this.name = elem.GetAttribute ("name");
this.value = elem.GetAttribute ("value");
this.ctype = elem.GetAttribute ("ctype");
}
public string Name {
get {
return this.name;
}
}
public string ConstType {
get {
if (IsString)
return "string";
// gir registers all integer values as gint even for numbers which do not fit into a gint
// if the number is too big for an int, try to fit it into a long
if (SymbolTable.Table.GetMarshalType (ctype) == "int" && value.Length < 20 && long.Parse (value) > Int32.MaxValue)
return "long";
return SymbolTable.Table.GetMarshalType (ctype);
}
}
public bool IsString {
get {
return (SymbolTable.Table.GetCSType (ctype) == "string");
}
}
public virtual bool Validate (LogWriter log)
{
if (ConstType == String.Empty) {
log.Warn ("{0} type is missing or wrong", Name);
return false;
}
if (SymbolTable.Table.GetMarshalType (ctype) == "int" && value.Length >= 20) {
return false;
}
return true;
}
public virtual void Generate (GenerationInfo gen_info, string indent)
{
StreamWriter sw = gen_info.Writer;
sw.WriteLine ("{0}public const {1} {2} = {3}{4}{5};",
indent,
ConstType,
Name,
IsString ? "@\"": String.Empty,
value,
IsString ? "\"": String.Empty);
}
}
}

View File

@@ -0,0 +1,179 @@
// 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.Generic;
using System.IO;
using System.Xml;
public class Ctor : MethodBase {
private bool preferred;
private bool deprecated;
private string name;
private bool needs_chaining;
public Ctor (XmlElement elem, ClassBase implementor) : base (elem, implementor)
{
preferred = elem.GetAttributeAsBoolean ("preferred");
deprecated = elem.GetAttributeAsBoolean("deprecated");
if (implementor is ObjectGen)
needs_chaining = true;
name = implementor.Name;
}
public bool Preferred {
get { return preferred; }
set { preferred = value; }
}
public bool IsDeprecated {
get {
return deprecated;
}
}
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[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
sw.WriteLine("\t\tdelegate IntPtr d_{0}({1});", CName, Parameters.ImportSignature);
sw.WriteLine("\t\tstatic d_{0} {0} = FuncLoader.LoadFunction<d_{0}>(FuncLoader.GetProcAddress(GLibrary.Load({1}), \"{0}\"));", CName, LibraryName);
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 {
if (IsDeprecated)
sw.WriteLine("\t\t[Obsolete]");
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 (Array.Empty<string> (), Array.Empty<GLib.Value> ());");
sw.WriteLine ("\t\t\t\treturn;");
} else {
var names = new List<string> ();
var values = new List<string> ();
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\tvar vals = new List<GLib.Value> ();");
sw.WriteLine ("\t\t\t\tvar names = new List<string> ();");
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 (names.ToArray (), vals.ToArray ());");
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

@@ -0,0 +1,146 @@
// GtkSharp.Generation.DefaultSignalHandler.cs - The default signal handler generatable
//
// Author: Christian Hoff <christian_hoff@gmx.net>
//
// Copyright (c) 2008 Novell Inc.
// Copyright (c) 2008-2009 Christian Hoff
//
// 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 DefaultSignalHandler : GObjectVM {
private string signal_name;
public DefaultSignalHandler (XmlElement elem, ObjectBase container_type) : base (elem, container_type)
{
signal_name = elem.GetAttribute ("cname");
}
public override string CName {
get {
return elem.GetAttribute ("field_name");
}
}
protected override bool CanGenerate (GenerationInfo gen_info, ObjectBase implementor)
{
return true;
}
protected override void GenerateOverride (GenerationInfo gen_info, ObjectBase implementor)
{
StreamWriter sw = gen_info.Writer;
if (!base.CanGenerate (gen_info, implementor)) {
GenerateOverrideBody (sw);
sw.WriteLine ("\t\t\tOverrideVirtualMethod (gtype, \"{0}\", callback);", signal_name);
sw.WriteLine ("\t\t}");
} else
base.GenerateOverride (gen_info, implementor);
}
protected override void GenerateUnmanagedInvocation (GenerationInfo gen_info, ObjectBase implementor)
{
if (!base.CanGenerate (gen_info, implementor))
GenerateChainVirtualMethod (gen_info.Writer, implementor);
else
base.GenerateUnmanagedInvocation (gen_info, implementor);
}
private void GenerateChainVirtualMethod (StreamWriter sw, ObjectBase implementor)
{
GenerateMethodBody (sw, implementor);
if (retval.IsVoid)
sw.WriteLine ("\t\t\tGLib.Value ret = GLib.Value.Empty;");
else
sw.WriteLine ("\t\t\tGLib.Value ret = new GLib.Value (" + ReturnGType + ");");
sw.WriteLine ("\t\t\tGLib.ValueArray inst_and_params = new GLib.ValueArray (" + (parms.Count + 1) + ");");
sw.WriteLine ("\t\t\tGLib.Value[] vals = new GLib.Value [" + (parms.Count + 1) + "];");
sw.WriteLine ("\t\t\tvals [0] = new GLib.Value (this);");
sw.WriteLine ("\t\t\tinst_and_params.Append (vals [0]);");
string cleanup = "";
for (int i = 0; i < parms.Count; i++) {
Parameter p = parms [i];
if (p.PassAs != "") {
if (SymbolTable.Table.IsBoxed (p.CType)) {
if (p.PassAs == "ref")
sw.WriteLine ("\t\t\tvals [" + (i + 1) + "] = new GLib.Value (" + p.Name + ");");
else
sw.WriteLine ("\t\t\tvals [" + (i + 1) + "] = new GLib.Value ((GLib.GType)typeof (" + p.CSType + "));");
cleanup += "\t\t\t" + p.Name + " = (" + p.CSType + ") vals [" + i + "];\n";
} else {
if (p.PassAs == "ref")
sw.WriteLine ("\t\t\tIntPtr " + p.Name + "_ptr = GLib.Marshaller.StructureToPtrAlloc (" + p.Generatable.CallByName (p.Name) + ");");
else
sw.WriteLine ("\t\t\tIntPtr " + p.Name + "_ptr = Marshal.AllocHGlobal (" + GenerationInfo.GetSizeOfExpression(p.MarshalType) + ");");
sw.WriteLine ("\t\t\tvals [" + (i + 1) + "] = new GLib.Value (" + p.Name + "_ptr);");
cleanup += "\t\t\t" + p.Name + " = " + p.FromNative ("(" + p.MarshalType + ") Marshal.PtrToStructure (" + p.Name + "_ptr, typeof (" + p.MarshalType + "))") + ";\n";
cleanup += "\t\t\tMarshal.FreeHGlobal (" + p.Name + "_ptr);\n";
}
} else if (p.IsLength && i > 0 && parms [i - 1].IsString)
sw.WriteLine ("\t\t\tvals [" + (i + 1) + "] = new GLib.Value (System.Text.Encoding.UTF8.GetByteCount (" + parms [i-1].Name + "));");
else
sw.WriteLine ("\t\t\tvals [" + (i + 1) + "] = new GLib.Value (" + p.Name + ");");
sw.WriteLine ("\t\t\tinst_and_params.Append (vals [" + (i + 1) + "]);");
}
sw.WriteLine ("\t\t\tg_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);");
if (cleanup != "")
sw.WriteLine (cleanup);
sw.WriteLine ("\t\t\tforeach (GLib.Value v in vals)");
sw.WriteLine ("\t\t\t\tv.Dispose ();");
if (!retval.IsVoid) {
IGeneratable igen = SymbolTable.Table [retval.CType];
sw.WriteLine ("\t\t\t" + retval.CSType + " result = (" + (igen is EnumGen ? retval.CSType + ") (Enum" : retval.CSType) + ") ret;");
sw.WriteLine ("\t\t\tret.Dispose ();");
sw.WriteLine ("\t\t\treturn result;");
}
sw.WriteLine ("\t\t}\n");
}
private string ReturnGType {
get {
IGeneratable igen = SymbolTable.Table [retval.CType];
if (igen is ObjectGen)
return "GLib.GType.Object";
if (igen is BoxedGen)
return retval.CSType + ".GType";
if (igen is EnumGen)
return retval.CSType + "GType.GType";
switch (retval.CSType) {
case "bool":
return "GLib.GType.Boolean";
case "string":
return "GLib.GType.String";
case "int":
return "GLib.GType.Int";
default:
throw new Exception (retval.CSType);
}
}
}
}
}

View File

@@ -0,0 +1,141 @@
// 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.
using System.Runtime.InteropServices;
namespace GtkSharp.Generation {
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Text.RegularExpressions;
public class EnumGen : GenBase {
string enum_type = String.Empty;
IList<string> members = new List<string> ();
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 string GenerateAlign () {
return null;
}
public override void Generate (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.OpenStream (Name, NS);
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 {");
var funcname = Elem.GetAttribute("gtype");
sw.WriteLine ("\t\t[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
sw.WriteLine ("\t\tdelegate IntPtr d_" + funcname + "();");
sw.WriteLine ("\t\tstatic d_" + funcname + " " + funcname + " = FuncLoader.LoadFunction<d_" + funcname + ">(FuncLoader.GetProcAddress(GLibrary.Load(" + LibraryName + "), \"" + funcname + "\"));");
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

@@ -0,0 +1,311 @@
// GtkSharp.Generation.FieldBase.cs - base class for struct and object
// fields
//
// 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 abstract class FieldBase : PropertyBase {
public FieldBase abi_field = null;
string getterName, setterName;
protected string getOffsetName, offsetName;
public FieldBase (XmlElement elem, ClassBase container_type) : base (elem, container_type) {}
public FieldBase (XmlElement elem, ClassBase container_type, FieldBase abi_field) : base (elem, container_type) {
this.abi_field = abi_field;
}
public virtual bool Validate (LogWriter log)
{
log.Member = Name;
if (!Ignored && !Hidden && CSType == "") {
if (Name == "Priv")
return false;
log.Warn ("field has unknown type: " + CType);
Statistics.ThrottledCount++;
return false;
}
return true;
}
internal virtual bool Readable {
get {
if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) <= 2)
return elem.GetAttribute ("readable") != "false";
return elem.HasAttribute ("readable") && elem.GetAttributeAsBoolean ("readable");
}
}
internal virtual bool Writable {
get {
if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) <= 2)
return elem.GetAttribute ("writeable") != "false";
return elem.HasAttribute ("writeable") && elem.GetAttributeAsBoolean ("writeable");
}
}
protected abstract string DefaultAccess { get; }
protected virtual string Access {
get {
return elem.HasAttribute ("access") ? elem.GetAttribute ("access") : DefaultAccess;
}
}
public bool IsArray {
get {
return elem.HasAttribute ("array_len") || elem.GetAttributeAsBoolean ("array");
}
}
public bool IsBitfield {
get {
return elem.HasAttribute("bits");
}
}
public bool Ignored {
get {
if (container_type.GetProperty (Name) != null)
return true;
if (IsArray)
return true;
if (Access == "private" && (Getter == null) && (Setter == null))
return true;
return false;
}
}
private bool UseABIStruct(GenerationInfo gen_info) {
if (!container_type.CanGenerateABIStruct(new LogWriter(container_type.CName)))
return false;
return (abi_field != null && abi_field.getOffsetName != null &&
gen_info.GlueWriter == null);
}
void CheckGlue (GenerationInfo gen_info)
{
getterName = setterName = getOffsetName = null;
if (Access != "public")
return;
if (UseABIStruct(gen_info)) {
getOffsetName = abi_field.getOffsetName;
offsetName = ((StructABIField) abi_field).abi_info_name + ".GetFieldOffset(\"" + ((StructField)abi_field).CName + "\")";
return;
}
if (gen_info.GlueWriter == null)
return;
string prefix = (container_type.NS + "Sharp_" + container_type.NS + "_" + container_type.Name).Replace(".", "__").ToLower ();
if (IsBitfield) {
if (Readable && Getter == null)
getterName = prefix + "_get_" + CName;
if (Writable && Setter == null)
setterName = prefix + "_set_" + CName;
} else {
if ((Readable && Getter == null) || (Writable && Setter == null)) {
offsetName = CName + "_offset";
getOffsetName = prefix + "_get_" + offsetName;
}
}
}
protected override void GenerateImports (GenerationInfo gen_info, string indent)
{
StreamWriter sw = gen_info.Writer;
SymbolTable table = SymbolTable.Table;
if (gen_info.GlueWriter == null) {
base.GenerateImports(gen_info, indent);
return;
}
if (getterName != null) {
sw.WriteLine (indent + "[DllImport (\"{0}\")]", gen_info.GluelibName);
sw.WriteLine (indent + "extern static {0} {1} ({2} raw);",
table.GetMarshalType (CType), getterName,
container_type.MarshalType);
}
if (setterName != null) {
sw.WriteLine (indent + "[DllImport (\"{0}\")]", gen_info.GluelibName);
sw.WriteLine (indent + "extern static void {0} ({1} raw, {2} value);",
setterName, container_type.MarshalType, table.GetMarshalType (CType));
}
if (getOffsetName != null) {
sw.WriteLine (indent + "[DllImport (\"{0}\")]", gen_info.GluelibName);
sw.WriteLine (indent + "extern static uint {0} ();", getOffsetName);
sw.WriteLine ();
sw.WriteLine (indent + "static uint " + offsetName + " = " + getOffsetName + " ();");
}
base.GenerateImports (gen_info, indent);
}
public virtual void Generate (GenerationInfo gen_info, string indent)
{
if (Ignored || Hidden)
return;
CheckGlue (gen_info);
GenerateImports (gen_info, indent);
if (Getter == null && getterName == null && offsetName == null &&
Setter == null && setterName == null) {
return;
}
SymbolTable table = SymbolTable.Table;
IGeneratable gen = table [CType];
StreamWriter sw = gen_info.Writer;
string modifiers = elem.GetAttributeAsBoolean ("new_flag") ? "new " : "";
sw.WriteLine (indent + "public " + modifiers + CSType + " " + Name + " {");
if (Getter != null) {
sw.Write (indent + "\tget ");
Getter.GenerateBody (gen_info, container_type, "\t");
sw.WriteLine ("");
} else if (getterName != null) {
sw.WriteLine (indent + "\tget {");
container_type.Prepare (sw, indent + "\t\t");
sw.WriteLine (indent + "\t\t" + CSType + " result = " + table.FromNative (ctype, getterName + " (" + container_type.CallByName () + ")") + ";");
container_type.Finish (sw, indent + "\t\t");
sw.WriteLine (indent + "\t\treturn result;");
sw.WriteLine (indent + "\t}");
} else if (Readable && offsetName != null) {
sw.WriteLine (indent + "\tget {");
sw.WriteLine (indent + "\t\tunsafe {");
if (gen is CallbackGen) {
sw.WriteLine (indent + "\t\t\tIntPtr* raw_ptr = (IntPtr*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
sw.WriteLine (indent + "\t\t\t {0} del = ({0})Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof({0}));", table.GetMarshalType (CType));
sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(del)") + ";");
}
else {
sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(*raw_ptr)") + ";");
}
sw.WriteLine (indent + "\t\t}");
sw.WriteLine (indent + "\t}");
}
string to_native = (gen is IManualMarshaler) ? (gen as IManualMarshaler).AllocNative ("value") : gen.CallByName ("value");
if (Setter != null) {
sw.Write (indent + "\tset ");
Setter.GenerateBody (gen_info, container_type, "\t");
sw.WriteLine ("");
} else if (setterName != null) {
sw.WriteLine (indent + "\tset {");
container_type.Prepare (sw, indent + "\t\t");
sw.WriteLine (indent + "\t\t" + setterName + " (" + container_type.CallByName () + ", " + to_native + ");");
container_type.Finish (sw, indent + "\t\t");
sw.WriteLine (indent + "\t}");
} else if (Writable && offsetName != null) {
sw.WriteLine (indent + "\tset {");
sw.WriteLine (indent + "\t\tunsafe {");
if (gen is CallbackGen) {
sw.WriteLine (indent + "\t\t\t{0} wrapper = new {0} (value);", ((CallbackGen)gen).WrapperName);
sw.WriteLine (indent + "\t\t\tIntPtr* raw_ptr = (IntPtr*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
sw.WriteLine (indent + "\t\t\t*raw_ptr = Marshal.GetFunctionPointerForDelegate (wrapper.NativeDelegate);");
}
else {
sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
sw.WriteLine (indent + "\t\t\t*raw_ptr = " + to_native + ";");
}
sw.WriteLine (indent + "\t\t}");
sw.WriteLine (indent + "\t}");
}
sw.WriteLine (indent + "}");
sw.WriteLine ("");
if ((getterName != null || setterName != null || getOffsetName != null) && gen_info.GlueWriter != null)
GenerateGlue (gen_info);
}
protected void GenerateGlue (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.GlueWriter;
SymbolTable table = SymbolTable.Table;
string FieldCType = CType.Replace ("-", " ");
bool byref = table[CType] is ByRefGen || table[CType] is StructGen;
string GlueCType = byref ? FieldCType + " *" : FieldCType;
string ContainerCType = container_type.CName;
string ContainerCName = container_type.Name.ToLower ();
if (getterName != null) {
sw.WriteLine ("{0} {1} ({2} *{3});",
GlueCType, getterName, ContainerCType, ContainerCName);
}
if (setterName != null) {
sw.WriteLine ("void {0} ({1} *{2}, {3} value);",
setterName, ContainerCType, ContainerCName, GlueCType);
}
if (getOffsetName != null)
sw.WriteLine ("guint {0} (void);", getOffsetName);
sw.WriteLine ("");
if (getterName != null) {
sw.WriteLine (GlueCType);
sw.WriteLine ("{0} ({1} *{2})", getterName, ContainerCType, ContainerCName);
sw.WriteLine ("{");
sw.WriteLine ("\treturn ({0}){1}{2}->{3};", GlueCType,
byref ? "&" : "", ContainerCName, CName);
sw.WriteLine ("}");
sw.WriteLine ("");
}
if (setterName != null) {
sw.WriteLine ("void");
sw.WriteLine ("{0} ({1} *{2}, {3} value)",
setterName, ContainerCType, ContainerCName, GlueCType);
sw.WriteLine ("{");
sw.WriteLine ("\t{0}->{1} = ({2}){3}value;", ContainerCName, CName,
FieldCType, byref ? "*" : "");
sw.WriteLine ("}");
sw.WriteLine ("");
}
if (getOffsetName != null) {
sw.WriteLine ("guint");
sw.WriteLine ("{0} (void)", getOffsetName);
sw.WriteLine ("{");
sw.WriteLine ("\treturn (guint)G_STRUCT_OFFSET ({0}, {1});",
ContainerCType, CName);
sw.WriteLine ("}");
sw.WriteLine ("");
}
}
}
}

View File

@@ -0,0 +1,371 @@
// GtkSharp.Generation.GObjectVM.cs - GObject specific part of VM creation
//
// Author: Christian Hoff <christian_hoff@gmx.net>
//
// Copyright (c) 2007 Novell, Inc.
// Copyright (c) 2009 Christian Hoff
//
// 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 GObjectVM : VirtualMethod
{
protected string class_struct_name;
const bool force_glue_generation = false;
public GObjectVM (XmlElement elem, ObjectBase container_type) : base (elem, container_type)
{
parms.HideData = false;
this.Protection = "protected";
class_struct_name = container_type.ClassStructName;
}
// Some types don't install headers. In that case, the glue code will not compile.
bool BlockGlue {
get {
return elem.GetAttribute ("block_glue") == "1";
}
}
protected override string CallString {
get {
return String.Format ("{0} ({1})", IsStatic ? this.CName + "_handler" : "On" + this.Name, call.ToString ());
}
}
public void Generate (GenerationInfo gen_info, ObjectBase implementor)
{
gen_info.CurrentMember = Name;
if (!CanGenerate (gen_info, implementor))
throw new NotSupportedException (String.Format ("Cannot generate virtual method {0}.{1}. Make sure a writable glue path was provided to the generator.", container_type.Name, this.CallString));
GenerateOverride (gen_info, implementor);
GenerateCallback (gen_info.Writer, implementor);
if (!IsStatic)
GenerateUnmanagedInvocation (gen_info, implementor);
}
protected virtual bool CanGenerate (GenerationInfo gen_info, ObjectBase implementor)
{
if (implementor != null || this.CName.Length == 0 || CodeType == VMCodeType.None || (CodeType == VMCodeType.Glue && !gen_info.GlueEnabled))
return false;
else
return true;
}
enum VMCodeType {
None,
Managed,
Glue
}
VMCodeType CodeType {
get {
if (!((ObjectBase)container_type).CanGenerateClassStruct || force_glue_generation) {
if (BlockGlue)
return VMCodeType.None;
else
return VMCodeType.Glue;
} else
return VMCodeType.Managed;
}
}
enum VMOverrideType {
Unspecified,
DeclaringClass,
ImplementingClass
}
/* There are basically two types of static virtual methods:
* 1. VMs overridden in the declaring class (e.g. AtkUtil vms):
* The VM is overridden in the class in which it is declared and not in the derived classes. In that case, the GAPI generates a static XYZHandler property
* in the declaring class.
* 2. VMs overridden in derived classes (e.g. GIO is_supported vms):
* As with nonstatic vms, this VM type hooks into the class structure field of derived classes. This type is currently unsupported as it is rarely used
* and we would need anonymous methods for the callback (we are using only *one* callback method; the callback does not know to which type that method call
* has to be redirected).
*/
VMOverrideType OverrideType {
get {
if (IsStatic) {
switch (elem.GetAttribute ("override_in")) {
case "declaring_class":
return VMOverrideType.DeclaringClass;
case "implementing_class":
return VMOverrideType.ImplementingClass;
default:
return VMOverrideType.Unspecified;
}
} else
return VMOverrideType.ImplementingClass;
}
}
protected virtual void GenerateOverride (GenerationInfo gen_info, ObjectBase implementor)
{
if (CodeType == VMCodeType.Glue)
GenerateOverride_glue (gen_info);
else
GenerateOverride_managed (gen_info.Writer);
}
protected virtual void GenerateUnmanagedInvocation (GenerationInfo gen_info, ObjectBase implementor)
{
if (CodeType == VMCodeType.Glue)
GenerateUnmanagedInvocation_glue (gen_info);
else
GenerateUnmanagedInvocation_managed (gen_info);
}
protected void GenerateOverrideBody (StreamWriter sw)
{
sw.WriteLine ("\t\tstatic {0}NativeDelegate {0}_cb_delegate;", Name);
sw.WriteLine ("\t\tstatic " + Name + "NativeDelegate " + Name + "VMCallback {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\tif ({0}_cb_delegate == null)", Name);
sw.WriteLine ("\t\t\t\t\t{0}_cb_delegate = new {0}NativeDelegate ({0}_cb);", Name);
sw.WriteLine ("\t\t\t\treturn {0}_cb_delegate;", Name);
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
if (IsStatic) {
sw.WriteLine ("\t\tpublic delegate {0} {1}Delegate ({2});", retval.CSType, Name, Signature.ToString ());
sw.WriteLine ("\t\tstatic {0}Delegate {1}_handler;", Name, CName);
sw.WriteLine ();
sw.WriteLine ("\t\tpublic static " + Name + "Delegate " + Name + "Handler {");
sw.WriteLine ("\t\t\tset {");
sw.WriteLine ("\t\t\t\t{0}_handler = value;", CName);
sw.WriteLine ("\t\t\t\tOverride{0} ((GLib.GType) typeof ({1}), value == null ? null : {0}VMCallback);", Name, container_type.Name);
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
} else {
sw.WriteLine ("\t\tstatic void Override{0} (GLib.GType gtype)", this.Name);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tOverride{0} (gtype, {0}VMCallback);", this.Name);
sw.WriteLine ("\t\t}");
}
sw.WriteLine ();
sw.WriteLine ("\t\tstatic void Override{0} (GLib.GType gtype, {0}NativeDelegate callback)", this.Name);
sw.WriteLine ("\t\t{");
}
protected void GenerateOverride_managed (StreamWriter sw)
{
GenerateOverrideBody (sw);
// Override VM; class_offset var is generated by object generatable
sw.WriteLine("\t\t\tunsafe {");
sw.WriteLine("\t\t\t\tIntPtr* raw_ptr = (IntPtr*)(((long) gtype.GetClassPtr()) + (long) class_abi.GetFieldOffset(\"{0}\"));", CName);
sw.WriteLine("\t\t\t\t*raw_ptr = Marshal.GetFunctionPointerForDelegate(callback);");
sw.WriteLine("\t\t\t}");
sw.WriteLine("\t\t}");
sw.WriteLine ();
}
protected void GenerateMethodBody (StreamWriter sw, ClassBase implementor)
{
sw.WriteLine ("\t\t[GLib.DefaultSignalHandler(Type=typeof(" + (implementor != null ? implementor.QualifiedName : container_type.QualifiedName) + "), ConnectionMethod=\"Override" + this.Name +"\")]");
sw.Write ("\t\t{0} ", this.Protection);
if (this.modifiers != "")
sw.Write ("{0} ", this.modifiers);
sw.WriteLine ("virtual {0} On{1} ({2})", retval.CSType, this.Name, Signature.ToString ());
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\t{0}Internal{1} ({2});", retval.IsVoid ? "" : "return ", this.Name, Signature.GetCallString (false));
sw.WriteLine ("\t\t}");
sw.WriteLine ();
// This method is to be invoked from existing VM implementations in the custom code
sw.WriteLine ("\t\tprivate {0} Internal{1} ({2})", retval.CSType, this.Name, Signature.ToString ());
sw.WriteLine ("\t\t{");
}
void GenerateUnmanagedInvocation_managed (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
string native_call = "this.Handle";
if (parms.Count > 0)
native_call += ", " + Body.GetCallString (false);
this.GenerateMethodBody (sw, null);
// Find the first unmanaged ancestor
sw.WriteLine ($"\t\t\t{Name}NativeDelegate unmanaged = class_abi.BaseOverride<{Name}NativeDelegate>(this.LookupGType(), \"{CName}\");");
sw.Write ("\t\t\tif (unmanaged == null) ");
if (parms.HasOutParam)
sw.WriteLine ("throw new InvalidOperationException (\"No base method to invoke\");");
else if (retval.IsVoid)
sw.WriteLine ("return;");
else
sw.WriteLine ("return {0};", retval.DefaultValue);
sw.WriteLine ();
Body.Initialize (gen_info);
sw.Write ("\t\t\t");
if (!retval.IsVoid)
sw.Write ("{0} __result = ", retval.MarshalType);
sw.WriteLine ("unmanaged ({0});", native_call);
Body.Finish (gen_info.Writer, "");
if(!retval.IsVoid)
sw.WriteLine ("\t\t\treturn {0};", retval.FromNative ("__result"));
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
/* old glue code. This code is to be used if
* a) the generated api file is version 1
* b) an old Mono version(< 2.4) is being used
* Punt it when we drop support for the parser version 1.
*/
private string CastFromInt (string type)
{
return type != "int" ? "(" + type + ") " : "";
}
private string GlueSignature {
get {
string[] glue_params = new string [this.IsStatic ? parms.Count + 1 : parms.Count + 2];
glue_params [0] = class_struct_name + " *class_struct";
if (!IsStatic)
glue_params [1] = container_type.CName + "* inst";
for (int i = 0; i < parms.Count; i++)
glue_params [i + (IsStatic ? 1 : 2)] = parms [i].CType.Replace ("const-", "const ") + " " + parms [i].Name;
return String.Join (", ", glue_params);
}
}
private string DefaultGlueValue {
get {
if (retval.IGen is EnumGen)
return String.Format ("({0}) 0", retval.CType);
string val = retval.DefaultValue;
switch (val) {
case "null":
return "NULL";
case "false":
return "FALSE";
case "true":
return "TRUE";
case "GLib.GType.None":
return "G_TYPE_NONE";
default:
return val;
}
}
}
void GenerateOverride_glue (GenerationInfo gen_info)
{
StreamWriter glue = gen_info.GlueWriter;
StreamWriter sw = gen_info.Writer;
string glue_name = String.Format ("{0}sharp_{1}_override_{2}", container_type.NS.ToLower ().Replace (".", "_"), container_type.Name.ToLower (), CName);
sw.WriteLine ("\t\t[DllImport (\"{0}\")]", gen_info.GluelibName);
sw.WriteLine ("\t\tstatic extern void {0} (IntPtr class_struct, {1}NativeDelegate cb);", glue_name, Name);
sw.WriteLine ();
glue.WriteLine ("void {0} ({1} *class_struct, gpointer cb);\n", glue_name, class_struct_name);
glue.WriteLine ("void\n{0} ({1} *class_struct, gpointer cb)", glue_name, class_struct_name);
glue.WriteLine ("{");
glue.WriteLine ("\tclass_struct->{0} = cb;", CName);
glue.WriteLine ("}");
glue.WriteLine ();
GenerateOverrideBody (sw);
sw.WriteLine ("\t\t\t{0} (gtype.GetClassPtr (), callback);", glue_name);
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateUnmanagedInvocation_glue (GenerationInfo gen_info)
{
StreamWriter glue = gen_info.GlueWriter;
string glue_name = String.Format ("{0}sharp_{1}_invoke_{2}", container_type.NS.ToLower ().Replace (".", "_"), container_type.Name.ToLower (), CName);
glue.WriteLine ("{0} {1} ({2});\n", retval.CType.Replace ("const-", "const "), glue_name, GlueSignature);
glue.WriteLine ("{0}\n{1} ({2})", retval.CType.Replace ("const-", "const "), glue_name, GlueSignature);
glue.WriteLine ("{");
glue.Write ("\tif (class_struct->{0})\n\t\t", CName);
if (!retval.IsVoid)
glue.Write ("return ");
string[] call_args = new string [IsStatic ? parms.Count : parms.Count + 1];
if (!IsStatic)
call_args [0] = "inst";
for (int i = 0; i < parms.Count; i++)
call_args [IsStatic ? i : i + 1] = parms[i].Name;
glue.WriteLine ("(* class_struct->{0}) ({1});", CName, String.Join (", ", call_args));
if (!retval.IsVoid)
glue.WriteLine ("\treturn " + DefaultGlueValue + ";");
glue.WriteLine ("}");
glue.WriteLine ();
StreamWriter sw = gen_info.Writer;
sw.WriteLine ("\t\t[DllImport (\"{0}\")]", gen_info.GluelibName);
sw.Write ("\t\tstatic extern {0} {1} (IntPtr class_struct", retval.MarshalType, glue_name);
if (!IsStatic)
sw.Write (", IntPtr inst");
if (parms.Count > 0)
sw.Write (", {0}", parms.ImportSignature);
sw.WriteLine (");");
sw.WriteLine ();
GenerateMethodBody (sw, null);
Body.Initialize (gen_info, false, false, String.Empty);
string glue_call_string = "this.LookupGType ().GetThresholdType ().GetClassPtr ()";
if (!IsStatic)
glue_call_string += ", Handle";
if (parms.Count > 0)
glue_call_string += ", " + Body.GetCallString (false);
sw.Write ("\t\t\t");
if (!retval.IsVoid)
sw.Write ("{0} __result = ", retval.MarshalType);
sw.WriteLine ("{0} ({1});", glue_name, glue_call_string);
Body.Finish (gen_info.Writer, "");
if(!retval.IsVoid)
sw.WriteLine ("\t\t\treturn {0};", retval.FromNative ("__result"));
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
public override bool Validate (LogWriter log)
{
if (!base.Validate (log))
return false;
bool is_valid = true;
if (this.IsStatic) {
switch (OverrideType) {
case VMOverrideType.Unspecified:
log.Warn ("Static virtual methods can only be generated if you provide info on how to override this method via the metadata ");
is_valid = false;
break;
case VMOverrideType.ImplementingClass:
log.Warn ("Overriding static virtual methods in the implementing class is not supported yet ");
is_valid = false;
break;
}
}
return is_valid;
}
}
}

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<OutputPath>..\..\..\BuildOutput\Tools</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,116 @@
// 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 virtual 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 virtual string GenerateGetSizeOf () {
return null;
}
public virtual string GenerateAlign () {
return null;
}
public void Generate ()
{
GenerationInfo geninfo = new GenerationInfo (ns);
Generate (geninfo);
}
public abstract void Generate (GenerationInfo geninfo);
}
}

View File

@@ -0,0 +1,260 @@
// 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 abiwriter = null;
StreamWriter cabiwriter = null;
StreamWriter glue_sw;
string abicfile = null;
string abicsfile = null;
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, string abi_c_file,
string abi_cs_file, string abi_cs_usings)
{
this.dir = dir;
this.assembly_name = assembly_name;
this.gluelib_name = gluelib_name;
abicfile = abi_c_file;
abicsfile = abi_cs_file;
InitializeWriters (glue_filename, glue_includes, gluelib_name, abi_cs_usings);
}
void InitializeWriters (string glue_filename, string glue_includes, string gluelib_name,
string abi_cs_usings)
{
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;
}
if (cabiwriter == null && abicfile != "" && abicsfile != "" && abi_cs_usings != "") {
var stream = new FileStream (abicfile, FileMode.Create, FileAccess.Write);
cabiwriter = new StreamWriter (stream);
cabiwriter.WriteLine ("// This file was generated by the Gtk# code generator.");
cabiwriter.WriteLine ("// Any changes made will be lost if regenerated.");
cabiwriter.WriteLine ();
if (glue_includes != "") {
foreach (string header in glue_includes.Split (new char[] {',', ' '})) {
if (header != "")
cabiwriter.WriteLine ("#include <{0}>", header);
}
cabiwriter.WriteLine ("");
}
cabiwriter.WriteLine ("int main (int argc, char *argv[]) {");
stream = new FileStream (abicsfile, FileMode.Create, FileAccess.Write);
abiwriter = new StreamWriter (stream);
abiwriter.WriteLine ("// This file was generated by the Gtk# code generator.");
abiwriter.WriteLine ("// Any changes made will be lost if regenerated.");
abiwriter.WriteLine ();
var name = "";
foreach (string _using in abi_cs_usings.Split (new char[] {',', ' '})) {
if (_using != "") {
abiwriter.WriteLine ("using {0};", _using);
if (name == "")
name = _using;
}
}
abiwriter.WriteLine ("using System;");
abiwriter.WriteLine ();
abiwriter.WriteLine ("namespace AbiTester {");
abiwriter.WriteLine ("\tclass ___" + name + " {");
abiwriter.WriteLine ("\t\tpublic static void Main (string[] args) {");
}
}
public string AssemblyName {
get {
return assembly_name;
}
}
public StreamWriter AbiWriter {
get {
return abiwriter;
}
}
public StreamWriter CAbiWriter {
get {
return cabiwriter;
}
}
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 CloseWriters ()
{
if (glue_sw != null)
glue_sw.Close ();
if (cabiwriter != null) {
cabiwriter.WriteLine ("\treturn 0;");
cabiwriter.WriteLine ("}");
cabiwriter.Close();
abiwriter.WriteLine ("\t\t}");
abiwriter.WriteLine ("\t}");
abiwriter.WriteLine ("}");
abiwriter.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, string namespce)
{
string gen_dir = Path.Combine (dir, namespce);
Directory.CreateDirectory (gen_dir);
string filename = Path.Combine (gen_dir, 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;
}
internal static string GetSizeOfExpression(string cstype)
{
// See https://docs.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types
bool isBlittable = cstype == "IntPtr"
|| cstype == "UIntPtr"
|| cstype == "ulong"
|| cstype == "long"
|| cstype == "uint"
|| cstype == "int"
|| cstype == "ushort"
|| cstype == "short"
|| cstype == "byte"
|| cstype == "sbyte"
|| cstype == "float"
|| cstype == "double";
if (isBlittable)
return "sizeof( " + cstype + " )";
return "Marshal.SizeOf<" + cstype + ">()";
}
}
}

View File

@@ -0,0 +1,80 @@
// HandleBase.cs - Base class for Handle types
//
// Authors: 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;
using System.IO;
using System.Xml;
public abstract class HandleBase : ClassBase, IAccessor, IOwnable {
protected HandleBase (XmlElement ns, XmlElement elem) : base (ns, elem) {}
public override string AssignToName {
get {
return "Raw";
}
}
public override string GenerateGetSizeOf () {
return NS + "." + Name + ".abi_info.Size";
}
public override string GenerateAlign () {
return NS + "." + Name + ".abi_info.Align";
}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string CallByName (string name)
{
return name + " == null ? IntPtr.Zero : " + name + ".Handle";
}
public override string CallByName ()
{
return "Handle";
}
public abstract string FromNative (string var, bool owned);
public override string FromNative (string var)
{
return FromNative (var, false);
}
public void WriteAccessors (TextWriter sw, string indent, string var)
{
sw.WriteLine (indent + "get {");
sw.WriteLine (indent + "\treturn " + FromNative (var, false) + ";");
sw.WriteLine (indent + "}");
sw.WriteLine (indent + "set {");
sw.WriteLine (indent + "\t" + var + " = " + CallByName ("value") + ";");
sw.WriteLine (indent + "}");
}
}
}

View File

@@ -0,0 +1,29 @@
// IAccessor.cs - Interface to generate property accessors.
//
// 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 IAccessor {
void WriteAccessors (System.IO.TextWriter sw, string indentation, string field_name);
}
}

View File

@@ -0,0 +1,63 @@
// 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);
// Generates code to get size of the type
string GenerateGetSizeOf ();
// Generates code to get size of the type
string GenerateAlign ();
bool Validate ();
void Generate ();
void Generate (GenerationInfo gen_info);
}
}

View File

@@ -0,0 +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);
}
}

View File

@@ -0,0 +1,24 @@
// Copyright (c) 2011 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 IOwnable {
string FromNative (string var, bool owned);
}
}

View File

@@ -0,0 +1,399 @@
// GtkSharp.Generation.InterfaceGen.cs - The Interface Generatable.
//
// Authors:
// Mike Kestner <mkestner@speakeasy.net>
// Andres G. Aragoneses <knocte@gmail.com>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2004, 2007 Novell, Inc.
// Copyright (c) 2013 Andres G. Aragoneses
//
// 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.Generic;
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 string AdapterName {
get {
return base.Name + "Adapter";
}
}
public string QualifiedAdapterName {
get {
return NS + "." + AdapterName;
}
}
public string ImplementorName {
get {
return Name + "Implementor";
}
}
public override string Name {
get {
return "I" + base.Name;
}
}
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}).{1})",
var, owned ? "OwnedHandle" : "Handle", QualifiedAdapterName);
}
public override string FromNative (string var, bool owned)
{
return QualifiedAdapterName + ".GetObject (" + var + ", " + (owned ? "true" : "false") + ")";
}
public override bool ValidateForSubclass ()
{
if (!base.ValidateForSubclass ())
return false;
LogWriter log = new LogWriter (QualifiedName);
var invalids = new List<Method> ();
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 " + AdapterName + " ()");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tGLib.GType.Register (_gtype, typeof ({0}));", AdapterName);
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)
{
if (interface_vms.Count > 0) {
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}");
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;");
sw.WriteLine ();
if (!IsConsumeOnly) {
sw.WriteLine ("\t\tpublic " + AdapterName + " ()");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tInitHandler = new GLib.GInterfaceInitHandler (Initialize);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic {0} ({1} implementor)", AdapterName, ImplementorName);
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 " + AdapterName + " (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 ();
// by convention, all GTypes generated have a static GType property
sw.WriteLine ("\t\tpublic static 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 ();
// we need same property but non-static, because it is being accessed via a GInterfaceAdapter instance
sw.WriteLine ("\t\tpublic override GLib.GType GInterfaceGType {");
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 " + ImplementorName + ")");
sw.WriteLine ("\t\t\t\treturn new {0} (obj as {1});", AdapterName, ImplementorName);
}
sw.WriteLine ("\t\t\telse if (obj as " + Name + " == null)");
sw.WriteLine ("\t\t\t\treturn new {0} (obj.Handle);", AdapterName);
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 " + ImplementorName + " Implementor {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn implementor as {0};", ImplementorName);
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
void GenerateAdapter (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (AdapterName, NS);
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 " + AdapterName + " : 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 = GetMethod ("GetType");
if (temp != null)
Methods.Remove ("GetType");
GenMethods (gen_info, null, 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 (" + AdapterName + "))]");
string access = IsInternal ? "internal" : "public";
sw.WriteLine ("\t" + access + " partial interface " + ImplementorName + " : GLib.IWrapper {");
sw.WriteLine ();
var vm_table = new Dictionary<string, InterfaceVM> ();
foreach (InterfaceVM vm in interface_vms) {
vm_table [vm.Name] = vm;
}
foreach (InterfaceVM vm in interface_vms) {
if (!vm_table.ContainsKey (vm.Name)) {
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 = null;
if (vm_table.TryGetValue (cmp_name, out cmp) && (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 Properties.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, NS);
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 Properties.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

@@ -0,0 +1,101 @@
// GtkSharp.Generation.InterfaceVM.cs - interface-specific part of VM creation
//
// Author: Christian Hoff <christian_hoff@gmx.net>
//
// Copyright (c) 2009 Christian Hoff
//
// 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 InterfaceVM : VirtualMethod
{
private Method target;
public InterfaceVM (XmlElement elem, Method target, ObjectBase container_type) : base (elem, container_type)
{
this.target = target;
parms.HideData = true;
this.Protection = "public";
}
public bool IsGetter {
get {
return HasGetterName && ((!retval.IsVoid && parms.Count == 0) || (retval.IsVoid && parms.Count == 1 && parms [0].PassAs == "out"));
}
}
public bool IsSetter {
get {
if (!HasSetterName || !retval.IsVoid)
return false;
if (parms.Count == 1 || (parms.Count == 3 && parms [0].Scope == "notified"))
return true;
else
return false;
}
}
protected override string CallString {
get {
if (IsGetter)
return (target.Name.StartsWith ("Get") ? target.Name.Substring (3) : target.Name);
else if (IsSetter)
return target.Name.Substring (3) + " = " + call;
else
return target.Name + " (" + call + ")";
}
}
public void GenerateDeclaration (StreamWriter sw, InterfaceVM complement)
{
if (IsGetter) {
string name = Name.StartsWith ("Get") ? Name.Substring (3) : Name;
string type = retval.IsVoid ? parms [0].CSType : retval.CSType;
if (complement != null && complement.parms [0].CSType == type)
sw.WriteLine ("\t\t" + type + " " + name + " { get; set; }");
else {
sw.WriteLine ("\t\t" + type + " " + name + " { get; }");
if (complement != null)
sw.WriteLine ("\t\t" + complement.retval.CSType + " " + complement.Name + " (" + complement.Signature + ");");
}
} else if (IsSetter)
sw.WriteLine ("\t\t" + parms[0].CSType + " " + Name.Substring (3) + " { set; }");
else
sw.WriteLine ("\t\t" + retval.CSType + " " + Name + " (" + Signature + ");");
}
public override bool Validate (LogWriter log)
{
if (!base.Validate (log))
return false;
if (target == null && !(container_type as InterfaceGen).IsConsumeOnly) {
log.Warn ("No matching target method to invoke. Add target_method attribute with fixup.");
return false;
}
return true;
}
}
}

View File

@@ -0,0 +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 (TextWriter 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

@@ -0,0 +1,58 @@
// GtkSharp.Generation.LPUGen.cs - unsigned 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 (TextWriter 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

@@ -0,0 +1,75 @@
// Copyright (c) 2011 Novell Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System;
namespace GtkSharp.Generation {
public class LogWriter {
string type;
string member;
int level;
public LogWriter () {
var l = Environment.GetEnvironmentVariable("CODEGEN_DEBUG");
level = 1;
if (l != null) {
level = Int32.Parse(l);
}
}
public LogWriter (string type): this()
{
this.type = type;
}
public string Member {
get { return member; }
set { member = value; }
}
public string Type {
get { return type; }
set { type = value; }
}
public void Warn (string format, params object[] args)
{
Warn (String.Format (format, args));
}
public void Warn (string warning)
{
if (level > 0)
Console.WriteLine ("WARN: {0}{1} - {2}", Type, String.IsNullOrEmpty (Member) ? String.Empty : "." + Member, warning);
}
public void Info (string info)
{
if (level > 1)
Console.WriteLine ("INFO: {0}{1} - {2}", Type, String.IsNullOrEmpty (Member) ? String.Empty : "." + Member, info);
}
}
}

View File

@@ -0,0 +1,193 @@
// GtkSharp.Generation.ManagedCallString.cs - The ManagedCallString Class.
//
// 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;
using System.Collections.Generic;
using System.IO;
public class ManagedCallString {
IDictionary<Parameter, bool> parms = new Dictionary<Parameter, bool> ();
IList<Parameter> dispose_params = new List<Parameter> ();
string error_param = null;
string user_data_param = null;
string destroy_param = null;
public ManagedCallString (Parameters parms)
{
for (int i = 0; i < parms.Count; i ++) {
Parameter p = parms [i];
if (p.IsLength && i > 0 && parms [i-1].IsString)
continue;
else if (p.Scope == "notified") {
user_data_param = parms[i+1].Name;
destroy_param = parms[i+2].Name;
i += 2;
} else if ((p.IsCount || p.IsUserData) && parms.IsHidden (p)) {
user_data_param = p.Name;
continue;
} else if (p is ErrorParameter) {
error_param = p.Name;
continue;
}
bool special = false;
if (p.PassAs != String.Empty && (p.Name != p.FromNative (p.Name)))
special = true;
else if (p.Generatable is CallbackGen)
special = true;
this.parms.Add (p, special);
if (p.IsOwnable) {
dispose_params.Add (p);
}
}
}
public bool HasOutParam {
get {
foreach (Parameter p in parms.Keys) {
if (p.PassAs == "out")
return true;
}
return false;
}
}
public bool HasDisposeParam {
get { return dispose_params.Count > 0; }
}
public string Unconditional (string indent) {
string ret = "";
if (error_param != null)
ret = indent + error_param + " = IntPtr.Zero;\n";
foreach (Parameter p in dispose_params) {
ret += indent + p.CSType + " my" + p.Name + " = null;\n";
}
return ret;
}
public string Setup (string indent)
{
string ret = "";
foreach (Parameter p in parms.Keys) {
if (parms [p] == false) {
continue;
}
IGeneratable igen = p.Generatable;
if (igen is CallbackGen) {
if (user_data_param == null)
ret += indent + String.Format ("{0} {1}_invoker = new {0} ({1});\n", (igen as CallbackGen).InvokerName, p.Name);
else if (destroy_param == null)
ret += indent + String.Format ("{0} {1}_invoker = new {0} ({1}, {2});\n", (igen as CallbackGen).InvokerName, p.Name, user_data_param);
else
ret += indent + String.Format ("{0} {1}_invoker = new {0} ({1}, {2}, {3});\n", (igen as CallbackGen).InvokerName, p.Name, user_data_param, destroy_param);
} else {
ret += indent + igen.QualifiedName + " my" + p.Name;
if (p.PassAs == "ref")
ret += " = " + p.FromNative (p.Name);
ret += ";\n";
}
}
foreach (Parameter p in dispose_params) {
ret += indent + "my" + p.Name + " = " + p.FromNative (p.Name) + ";\n";
}
return ret;
}
public override string ToString ()
{
if (parms.Count < 1)
return "";
string[] result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms.Keys) {
result [i] = p.PassAs == "" ? "" : p.PassAs + " ";
if (p.Generatable is CallbackGen) {
result [i] += p.Name + "_invoker.Handler";
} else {
if (parms [p] || dispose_params.Contains(p)) {
// Parameter was declared and marshalled earlier
result [i] += "my" + p.Name;
} else {
result [i] += p.FromNative (p.Name);
}
}
i++;
}
return String.Join (", ", result);
}
public string Finish (string indent)
{
string ret = "";
foreach (Parameter p in parms.Keys) {
if (parms [p] == false) {
continue;
}
IGeneratable igen = p.Generatable;
if (igen is CallbackGen)
continue;
else if (igen is StructBase || igen is ByRefGen)
ret += indent + String.Format ("if ({0} != IntPtr.Zero) System.Runtime.InteropServices.Marshal.StructureToPtr (my{0}, {0}, false);\n", p.Name);
else if (igen is IManualMarshaler)
ret += String.Format ("{0}{1} = {2};", indent, p.Name, (igen as IManualMarshaler).AllocNative ("my" + p.Name));
else
ret += indent + p.Name + " = " + igen.CallByName ("my" + p.Name) + ";\n";
}
return ret;
}
public string DisposeParams (string indent)
{
string ret = "";
foreach (Parameter p in dispose_params) {
string name = "my" + p.Name;
string disp_name = "disposable_" + p.Name;
ret += indent + "var " + disp_name + " = " + name + " as IDisposable;\n";
ret += indent + "if (" + disp_name + " != null)\n";
ret += indent + "\t" + disp_name + ".Dispose ();\n";
}
return ret;
}
}
}

View File

@@ -0,0 +1,75 @@
// 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;
string abi_type;
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 ManualGen (string ctype, string type, string from_fmt, string abi_type) : base (ctype, type, "null")
{
this.from_fmt = from_fmt;
this.abi_type = abi_type;
}
public override string MarshalType {
get {
return "IntPtr";
}
}
public string AbiType {
get {
return abi_type;
}
}
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);
}
public override string GenerateGetSizeOf () {
return "(uint) " + GenerationInfo.GetSizeOfExpression(abi_type);
}
}
}

View File

@@ -0,0 +1,58 @@
// GtkSharp.Generation.MarshalGen.cs - Simple marshaling 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;
public class MarshalGen : SimpleBase {
string mtype;
string call_fmt;
string from_fmt;
public MarshalGen (string ctype, string type, string mtype, string call_fmt, string from_fmt, string default_value) : base (ctype, type, default_value)
{
this.mtype = mtype;
this.call_fmt = call_fmt;
this.from_fmt = from_fmt;
}
public MarshalGen (string ctype, string type, string mtype, string call_fmt, string from_fmt) : this (ctype, type, mtype, call_fmt, from_fmt, "null") { }
public override string MarshalType {
get {
return mtype;
}
}
public override string CallByName (string var)
{
return String.Format (call_fmt, var);
}
public override string FromNative (string var)
{
return String.Format (from_fmt, var);
}
}
}

View File

@@ -0,0 +1,324 @@
// 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;
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");
}
if (Name == "GetType")
Name = "GetGType";
}
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;
if (Name == String.Empty || CName == String.Empty) {
log.Warn ("Method has no name or cname.");
return false;
}
Parameters parms = Parameters;
is_get = ((parms.IsAccessor && 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 || (container_type.Parent != null && container_type.Parent.Methods.ContainsKey ("GetType"))))
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 (Name.StartsWith (container_type.Name))
Name = Name.Substring (container_type.Name.Length);
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[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
if (retval.MarshalType.StartsWith("[return:"))
sw.WriteLine("\t\tdelegate " + retval.CSType + " d_" + CName + "(" + import_sig + ");");
else
sw.WriteLine("\t\tdelegate " + retval.MarshalType + " d_" + CName + "(" + import_sig + ");");
sw.WriteLine("\t\tstatic d_" + CName + " " + CName + " = FuncLoader.LoadFunction<d_" + CName + ">(FuncLoader.GetProcAddress(GLibrary.Load(" + LibraryName + "), \"" + CName + "\"));");
sw.WriteLine();
}
public void GenerateOverloads (StreamWriter sw)
{
sw.WriteLine ();
sw.Write ("\t\tpublic ");
if (IsStatic)
sw.Write ("static ");
sw.WriteLine (retval.CSType + " " + Name + "(" + (Signature != null ? Signature.WithoutOptional () : "") + ") {");
sw.WriteLine ("\t\t\t{0}{1} ({2});", !retval.IsVoid ? "return " : String.Empty, Name, Signature.CallWithoutOptionals ());
sw.WriteLine ("\t\t}");
}
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 = "(" + (IsStatic ? "" : container_type.CallByName () + (parms.Count > 0 ? ", " : "")) + 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();
if (Parameters.HasOptional && !(is_get || is_set))
GenerateOverloads (gen_info.Writer);
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);
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

@@ -0,0 +1,56 @@
namespace GtkSharp.Generation {
using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Collections.Generic;
public class MethodABIField : StructABIField {
bool is_valid;
XmlElement Elem;
public MethodABIField (XmlElement elem, ClassBase container_type, string info_name) :
base (elem, container_type, info_name) {
Elem = elem;
is_valid = true;
}
public override string CType {
get {
return "gpointer";
}
}
public override bool IsCPointer() {
return true;
}
public new string Name {
get {
var name = elem.GetAttribute("vm");
if (name == null || name == "")
name = elem.GetAttribute("signal_vm");
return name;
}
}
public override string StudlyName {
get {
return Name;
}
}
public override string CName {
get {
if (parent_structure_name != null)
return parent_structure_name + '.' + Name;
return Name;
}
}
}
}

View File

@@ -0,0 +1,185 @@
// 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) {
LogWriter log = new LogWriter (Name);
body = new MethodBody (parms, log);
}
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

@@ -0,0 +1,191 @@
// 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;
LogWriter log;
public MethodBody (Parameters parms, LogWriter _log)
{
parameters = parms;
log = _log;
}
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);
int closure = i + 1;
if (p.Closure >= 0)
closure = p.Closure;
int destroyNotify = i + 2;
if (p.DestroyNotify >= 0)
destroyNotify = p.DestroyNotify;
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 [closure].Name);
sw.WriteLine (indent + "\t\t\t{0} {1};", parameters [destroyNotify].CSType, parameters [destroyNotify].Name);
sw.WriteLine (indent + "\t\t\tif ({0} == null) {{", name);
sw.WriteLine (indent + "\t\t\t\t{0} = IntPtr.Zero;", parameters [closure].Name);
sw.WriteLine (indent + "\t\t\t\t{0} = null;", parameters [destroyNotify].Name);
sw.WriteLine (indent + "\t\t\t} else {");
sw.WriteLine (indent + "\t\t\t\t{0} = (IntPtr) GCHandle.Alloc ({1}_wrapper);", parameters [closure].Name, name);
sw.WriteLine (indent + "\t\t\t\t{0} = GLib.DestroyHelper.NotifyHandler;", parameters [destroyNotify].Name, parameters [destroyNotify].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)
log.Warn (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

@@ -0,0 +1,229 @@
// Authors:
// Stephan Sundermann <stephansundermann@gmail.com>
//
// Copyright (c) 2013 Stephan Sundermann
//
// 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.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
namespace GtkSharp.Generation
{
public class NativeStructGen : HandleBase
{
IList<StructField> fields = new List<StructField> ();
public NativeStructGen (XmlElement ns, XmlElement elem) : base (ns, elem)
{
LogWriter log = new LogWriter (QualifiedName);
foreach (XmlNode node in elem.ChildNodes) {
if (!(node is XmlElement)) continue;
XmlElement member = (XmlElement) node;
switch (node.Name) {
case "field":
fields.Add (new StructField (member, this));
break;
default:
if (!IsNodeNameHandled (node.Name))
log.Warn ("Unexpected node " + node.Name + " in " + CName);
break;
}
}
}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string AssignToName {
get { return "Handle"; }
}
public override string CallByName ()
{
return "Handle";
}
public override string CallByName (string var)
{
return String.Format ("{0} == null ? IntPtr.Zero : {0}.{1}", var, "Handle");
}
public override string FromNative (string var, bool owned)
{
return "new " + QualifiedName + "( " + var + " )";
}
public override void Generate (GenerationInfo gen_info)
{
bool need_close = false;
if (gen_info.Writer == null) {
gen_info.Writer = gen_info.OpenStream (Name, NS);
need_close = true;
}
StreamWriter sw = gen_info.Writer;
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Collections;");
sw.WriteLine ("\tusing System.Collections.Generic;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
if (IsDeprecated)
sw.WriteLine ("\t[Obsolete]");
string access = IsInternal ? "internal" : "public";
sw.WriteLine ("\t" + access + " partial class {0} : {1} IEquatable<{0}> {{", Name, Parent == null ? "GLib.IWrapper," : (Parent.QualifiedName + ","));
sw.WriteLine ();
GenNativeStruct (gen_info);
GenNativeAccessor (gen_info);
GenFields (gen_info);
sw.WriteLine ();
GenCtors (gen_info);
GenMethods (gen_info, null, this);
GenEqualsAndHash (sw);
if (!need_close)
return;
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
}
private void GenNativeStruct (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
sw.WriteLine ("\t\t[StructLayout(LayoutKind.Sequential)]");
sw.WriteLine ("\t\tprivate partial struct NativeStruct {");
foreach (StructField field in fields) {
field.Generate (gen_info, "\t\t\t");
}
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
private void GenNativeAccessor (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
sw.WriteLine ("\t\tNativeStruct Native {{", QualifiedName);
sw.WriteLine ("\t\t\tget { return (NativeStruct) Marshal.PtrToStructure (Handle, typeof (NativeStruct)); }");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
protected override void GenCtors (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
if (Parent == null) {
sw.WriteLine ("\t\tpublic {0} (IntPtr raw)", Name);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tthis.Handle = raw;");
sw.WriteLine ("\t\t}");
}
else
sw.Write ("\t\tpublic {0} (IntPtr raw) : base (raw) {{}}", Name);
sw.WriteLine ();
base.GenCtors (gen_info);
}
protected new void GenFields (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
sw.WriteLine ("\t\tprivate IntPtr Raw;");
sw.WriteLine ("\t\tpublic IntPtr Handle {");
sw.WriteLine ("\t\t\tget { return Raw; }");
sw.WriteLine ("\t\t\tset { Raw = value; }");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
foreach (StructField field in fields) {
if (!field.Visible)
continue;
sw.WriteLine ("\t\tpublic {0} {1} {{", SymbolTable.Table.GetCSType (field.CType), field.StudlyName);
sw.WriteLine ("\t\t\tget {{ return Native.{0}; }}", field.StudlyName);
if (!(SymbolTable.Table [field.CType] is CallbackGen))
sw.WriteLine ("\t\t\tset {{ NativeStruct native = Native; native.{0} = value; Marshal.StructureToPtr (native, this.Handle, false); }}", field.StudlyName);
sw.WriteLine ("\t\t}");
}
}
protected void GenEqualsAndHash (StreamWriter sw)
{
StringBuilder hashcode = new StringBuilder ();
StringBuilder equals = new StringBuilder ();
sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
sw.WriteLine ("\t\t{");
hashcode.Append ("this.GetType().FullName.GetHashCode()");
equals.Append ("true");
foreach (StructField field in fields) {
if (field.IsPadding || !field.Visible || field.IsBitfield)
continue;
equals.Append (" && ");
equals.Append (field.EqualityName);
equals.Append (".Equals (other.");
equals.Append (field.EqualityName);
equals.Append (")");
hashcode.Append (" ^ ");
hashcode.Append (field.EqualityName);
hashcode.Append (".GetHashCode ()");
}
sw.WriteLine ("\t\t\treturn {0};", equals.ToString ());
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic override bool Equals (object other)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\treturn other is {0} && Equals (({0}) other);", Name);
sw.WriteLine ("\t\t}");
sw.WriteLine ();
if (Elem.GetAttribute ("nohash") == "true")
return;
sw.WriteLine ("\t\tpublic override int GetHashCode ()");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\treturn {0};", hashcode.ToString ());
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
}
}

View File

@@ -0,0 +1,372 @@
// ObjectBase.cs - Base class for Object types
//
// Authors: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2005 Novell, Inc.
// Copyright (c) 2009 Christian Hoff
//
// 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.Collections.Generic;
using System.IO;
using System.Xml;
public abstract class ObjectBase : HandleBase {
bool is_interface;
protected string class_struct_name = null;
bool class_fields_valid; // false if the class structure contains a bitfield or fields of unknown types
ArrayList class_members = new ArrayList ();
protected List<StructABIField> abi_class_members = new List<StructABIField> ();
bool class_abi_valid = true;
protected IList<ClassField> class_fields = new List<ClassField> ();
// The default handlers of these signals need to be overridden with g_signal_override_class_closure
protected IList<GObjectVM> virtual_methods = new List<GObjectVM> ();
// virtual methods that are generated as an IntPtr in the class struct
protected IList<VirtualMethod> hidden_vms = new List<VirtualMethod> ();
protected IList<InterfaceVM> interface_vms = new List<InterfaceVM> ();
protected Hashtable sigs = new Hashtable();
protected ObjectBase (XmlElement ns, XmlElement elem, bool is_interface) : base (ns, elem)
{
this.is_interface = is_interface;
XmlElement class_elem = null;
Hashtable vms = new Hashtable ();
Hashtable signal_vms = new Hashtable ();
if (this.ParserVersion == 1)
class_struct_name = this.CName + (is_interface ? "Iface" : "Class");
foreach (XmlNode node in elem.ChildNodes) {
if (!(node is XmlElement)) continue;
XmlElement member = node as XmlElement;
switch (node.Name) {
case "virtual_method":
if (this.ParserVersion == 1) {
if (is_interface) // Generating non-signal GObject virtual methods is not supported in compatibility mode
AddVM (member, false, is_interface);
} else
vms.Add (member.GetAttribute ("cname"), member);
break;
case "signal":
if (this.ParserVersion == 1 || member.GetAttribute ("field_name") == "")
AddVM (member, true, is_interface);
else
signal_vms.Add (member.GetAttribute ("field_name"), member);
if (!member.GetAttributeAsBoolean ("hidden")) {
string name = member.GetAttribute("name");
while (sigs.ContainsKey(name))
name += "mangled";
sigs.Add (name, new Signal (member, this));
}
break;
case "class_struct":
class_elem = member;
break;
}
}
if (class_elem == null) return;
if (class_elem.GetAttributeAsBoolean("private")) {
class_abi_valid = false;
return;
}
class_struct_name = class_elem.GetAttribute ("cname");
int num_abi_fields = 0;
for (int node_idx = 0; node_idx < class_elem.ChildNodes.Count; node_idx++) {
XmlNode node = class_elem.ChildNodes [node_idx];
if (!(node is XmlElement)) continue;
XmlElement member = (XmlElement) node;
// Make sure ABI fields are taken into account, even when hidden.
if (node.Name == "field") {
num_abi_fields += 1;
if (num_abi_fields != 1) { // Skip instance parent struct
abi_class_members.Add (new StructABIField (member, this, "class_abi"));
}
} else if (node.Name == "union") {
abi_class_members.Add (new UnionABIField (member, this, "class_abi"));
} else if (node.Name == "method") {
abi_class_members.Add (new MethodABIField (member, this, "class_abi"));
}
switch (member.Name) {
case "method":
string vm_name;
XmlElement vm_elem;
bool is_signal_vm = member.HasAttribute ("signal_vm");
if (is_signal_vm) {
vm_name = member.GetAttribute ("signal_vm");
vm_elem = signal_vms [vm_name] as XmlElement;
} else {
vm_name = member.GetAttribute ("vm");
vm_elem = vms [vm_name] as XmlElement;
}
AddVM (vm_elem, is_signal_vm, is_interface);
break;
case "field":
if (node_idx == 0) continue; // Parent class
ClassField field = new ClassField (member, this);
class_fields.Add (field);
class_members.Add (field);
break;
default:
Console.WriteLine ("Unexpected node " + member.Name + " in " + class_elem.GetAttribute ("cname"));
break;
}
}
}
VirtualMethod AddVM (XmlElement vm_elem, bool is_signal_vm, bool is_interface)
{
VirtualMethod vm;
if (is_signal_vm)
vm = new DefaultSignalHandler (vm_elem, this);
else if (is_interface) {
string target_name = vm_elem.HasAttribute ("target_method") ? vm_elem.GetAttribute ("target_method") : vm_elem.GetAttribute ("name");
vm = new InterfaceVM (vm_elem, GetMethod (target_name), this);
} else
vm = new GObjectVM (vm_elem, this);
if (vm_elem.GetAttributeAsBoolean ("padding") || vm_elem.GetAttributeAsBoolean ("hidden"))
hidden_vms.Add (vm);
else {
if (vm is GObjectVM) {
virtual_methods.Add ((GObjectVM)vm);
} else {
interface_vms.Add ((InterfaceVM)vm);
}
}
if (vm.CName != "")
class_members.Add (vm);
return vm;
}
protected override bool IsNodeNameHandled (string name)
{
switch (name) {
case "virtual_method":
case "signal":
case "class_struct":
return true;
default:
return base.IsNodeNameHandled (name);
}
}
public override string CallByName (string var)
{
return CallByName (var, false);
}
public abstract string CallByName (string var, bool owned);
public override string FromNative (string var, bool owned)
{
return "GLib.Object.GetObject(" + var + (owned ? ", true" : "") + ") as " + QualifiedName;
}
public string ClassStructName {
get {
return class_struct_name;
}
}
public bool CanGenerateClassStruct {
get {
/* Generation of interface class structs was already supported by version 2.12 of the GAPI parser. Their layout was determined by the order
* in which the signal and virtual_method elements appeared in the XML. However, we cannot use that approach for old GObject class structs
* as they may contain class fields which don't appear in the old (version 1) API files. There are also cases in which the order of the
* <signal> and <virtual_method> elements do not match the struct layout.
*/
return (is_interface || this.ParserVersion >= 2) && (class_abi_valid || class_struct_name == "GtkWidgetClass");
}
}
public override bool CanGenerateABIStruct(LogWriter log) {
if (!abi_fields_valid) {
log.Info(CName + " has invalid fields");
return false;
}
// No instance structure for interfaces
if (is_interface) {
log.Info(CName + " Is interface");
return false;
}
return class_struct_name != null;
}
protected void GenerateClassStruct (GenerationInfo gen_info)
{
if (class_struct_name == null || !CanGenerateClassStruct) return;
StreamWriter sw = gen_info.Writer;
sw.WriteLine ("\t\t[StructLayout (LayoutKind.Sequential)]");
sw.WriteLine ("\t\tstruct " + class_struct_name + " {");
foreach (object member in class_members) {
if (member is VirtualMethod) {
VirtualMethod vm = member as VirtualMethod;
if (hidden_vms.Contains (vm) || (is_interface && vm is DefaultSignalHandler))
sw.WriteLine ("\t\t\tIntPtr {0};", vm.Name);
else
sw.WriteLine ("\t\t\tpublic {0}NativeDelegate {0};", vm.Name);
} else if (member is ClassField) {
ClassField field = member as ClassField;
field.Generate (gen_info, "\t\t\t");
}
}
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
public Hashtable Signals {
get {
return sigs;
}
}
public Signal GetSignal (string name)
{
return sigs[name] as Signal;
}
public Signal GetSignalRecursively (string name)
{
return GetSignalRecursively (name, false);
}
public virtual Signal GetSignalRecursively (string name, bool check_self)
{
Signal p = null;
if (check_self)
p = GetSignal (name);
if (p == null && Parent != null)
p = (Parent as ObjectBase).GetSignalRecursively (name, true);
if (check_self && p == null) {
foreach (string iface in interfaces) {
InterfaceGen igen = SymbolTable.Table.GetClassGen (iface) as InterfaceGen;
if (igen == null)
continue;
p = igen.GetSignalRecursively (name, true);
if (p != null)
break;
}
}
return p;
}
public void GenSignals (GenerationInfo gen_info, ObjectBase implementor)
{
foreach (Signal sig in sigs.Values)
sig.Generate (gen_info, implementor);
}
public void GenVirtualMethods (GenerationInfo gen_info, ObjectBase implementor)
{
foreach (GObjectVM vm in virtual_methods)
vm.Generate (gen_info, implementor);
}
public override bool Validate ()
{
if (Parent != null && !(Parent as ObjectBase).ValidateForSubclass ())
return false;
LogWriter log = new LogWriter (QualifiedName);
ArrayList invalids = new ArrayList ();
foreach (GObjectVM vm in virtual_methods)
if (!vm.Validate (log))
invalids.Add (vm);
foreach (GObjectVM invalid_vm in invalids) {
virtual_methods.Remove (invalid_vm);
hidden_vms.Add (invalid_vm);
}
invalids.Clear ();
class_fields_valid = true;
foreach (ClassField field in class_fields)
if (!field.Validate (log))
class_fields_valid = false;
foreach (StructABIField field in abi_class_members)
if (!field.Validate (log))
class_abi_valid = false;
foreach (InterfaceVM vm in interface_vms)
if (!vm.Validate (log))
invalids.Add (vm);
foreach (InterfaceVM invalid_vm in invalids) {
interface_vms.Remove (invalid_vm);
hidden_vms.Add (invalid_vm);
}
invalids.Clear ();
foreach (Signal sig in sigs.Values) {
if (!sig.Validate (log))
invalids.Add (sig);
}
foreach (Signal sig in invalids)
sigs.Remove (sig.Name);
return base.Validate ();
}
public virtual bool ValidateForSubclass ()
{
LogWriter log = new LogWriter (QualifiedName);
ArrayList invalids = new ArrayList ();
foreach (Signal sig in sigs.Values) {
if (!sig.Validate (log)) {
invalids.Add (sig);
}
}
foreach (Signal sig in invalids)
sigs.Remove (sig.Name);
invalids.Clear ();
return true;
}
public override string GenerateGetSizeOf () {
return NS + "." + Name + ".abi_info.Size";
}
}
}

View File

@@ -0,0 +1,52 @@
// GtkSharp.Generation.ObjectField.cs - autogenerated field glue
//
// 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 ObjectField : FieldBase {
public ObjectField (XmlElement elem, ClassBase container_type) : base (elem, container_type){
if (CType == "char*" || CType == "gchar*")
ctype = "const-" + CType;
}
public ObjectField (XmlElement elem, ClassBase container_type, FieldBase abi_field) : base (elem, container_type) {
if (CType == "char*" || CType == "gchar*")
ctype = "const-" + CType;
}
internal override bool Writable {
get {
return elem.GetAttributeAsBoolean ("writeable");
}
}
protected override string DefaultAccess {
get {
return "private";
}
}
}
}

View File

@@ -0,0 +1,409 @@
// 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.Generic;
using System.IO;
using System.Text;
using System.Xml;
public class ObjectGen : ObjectBase {
private IList<string> custom_attrs = new List<string> ();
private IList<XmlElement> strings = new List<XmlElement> ();
private IDictionary<string, ChildProperty> childprops = new Dictionary<string, ChildProperty> ();
private static IDictionary<string, DirectoryInfo> dirs = new Dictionary<string, DirectoryInfo> ();
public ObjectGen (XmlElement ns, XmlElement elem) : base (ns, elem, false)
{
foreach (XmlNode node in elem.ChildNodes) {
XmlElement member = node as XmlElement;
if (member == null) {
continue;
}
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 (member);
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);
var invalids = new List<string> ();
foreach (string prop_name in childprops.Keys) {
if (!childprops [prop_name].Validate (log))
invalids.Add (prop_name);
}
foreach (string prop_name in invalids)
childprops.Remove (prop_name);
return base.Validate ();
}
private bool DisableVoidCtor {
get {
return Elem.GetAttributeAsBoolean ("disable_void_ctor");
}
}
private class DirectoryInfo {
public string assembly_name;
public IDictionary<string, string> objects;
public DirectoryInfo (string assembly_name)
{
this.assembly_name = assembly_name;
objects = new Dictionary<string, string> ();
}
}
private static DirectoryInfo GetDirectoryInfo (string dir, string assembly_name)
{
DirectoryInfo result;
if (dirs.ContainsKey (dir)) {
result = dirs [dir];
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, NS);
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Collections;");
sw.WriteLine ("\tusing System.Collections.Generic;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ("\tusing static GLib.AbiStructExtension;");
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);
}
GenConstants (gen_info);
GenClassMembers (gen_info, cs_parent);
GenMethods (gen_info, null, null);
if (interfaces.Count != 0) {
var all_methods = new Dictionary<string, Method> ();
foreach (Method m in Methods.Values) {
all_methods[m.Name] = m;
}
var collisions = new Dictionary<string, bool> ();
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 = null;
all_methods.TryGetValue (m.Name, out collision);
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}");
}
GenerateStructureABI (gen_info);
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;
string defaultconstructoraccess = Elem.HasAttribute ("defaultconstructoraccess") ? Elem.GetAttribute ("defaultconstructoraccess") : "public";
gen_info.Writer.WriteLine ("\t\t"+ defaultconstructoraccess + " " + 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 (Array.Empty<string> (), Array.Empty<GLib.Value> ());");
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);
GenerateStructureABI(gen_info, abi_class_members, "class_abi", ClassStructName);
}
/* 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 (IDictionary<string, string> objs, string assembly_name)
{
foreach (string key in objs.Keys) {
if (GetExpected (key) != 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];
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", "GtkSharp");
sw.WriteLine ("namespace GtkSharp." + Studlify (dir_info.assembly_name) + " {");
sw.WriteLine ();
sw.WriteLine ("\tpublic partial 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) != dir_info.objects[key]) {
sw.WriteLine ("\t\t\tGLib.GType.Register ({0}.GType, typeof ({0}));", dir_info.objects [key]);
}
}
sw.WriteLine ();
sw.WriteLine ("\t\t\tInitializeExtras();");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tstatic partial void InitializeExtras();");
sw.WriteLine ();
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
}
}
}

View File

@@ -0,0 +1,254 @@
// 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, NS);
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Collections;");
sw.WriteLine ("\tusing System.Collections.Generic;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
SymbolTable table = SymbolTable.Table;
Method ref_, unref, dispose, set_gvalue;
GetSpecialMethods (out ref_, out unref, out dispose, out set_gvalue);
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 ();
GenConstants (gen_info);
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 ("\t\t\tpublic uint timeoutHandlerId;");
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\tGLib.Timeout.Remove(timeoutHandlerId);");
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\tinfo.timeoutHandlerId = GLib.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
if (set_gvalue != null) {
sw.WriteLine("\t\tdelegate IntPtr d_{0}(ref GLib.Value val, IntPtr obj);", set_gvalue.CName);
sw.WriteLine("\t\tstatic d_{0} {0} = FuncLoader.LoadFunction<d_{0}>(FuncLoader.GetProcAddress(GLibrary.Load({1}), \"{0}\"));", set_gvalue.CName, LibraryName);
sw.WriteLine ();
sw.WriteLine ("\t\tpublic void SetGValue (ref GLib.Value val)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\t{0} (ref val, Handle);", set_gvalue.CName);
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
GenerateStructureABI(gen_info);
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, out Method set_gvalue)
{
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);
set_gvalue = GetMethod ("SetGValue");
Methods.Remove ("SetGValue");
}
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);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +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");
}
}
}

View File

@@ -0,0 +1,427 @@
// GtkSharp.Generation.Parameters.cs - The Parameters Generation Class.
//
// 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.Xml;
public class Parameter {
private XmlElement elem;
public Parameter (XmlElement e)
{
elem = e;
}
string call_name;
public string CallName {
get {
if (call_name == null)
return Name;
else
return call_name;
}
set {
call_name = value;
}
}
public string CType {
get {
string type = elem.GetAttribute("type");
if (type == "void*")
type = "gpointer";
return type;
}
}
public string CSType {
get {
string cstype = SymbolTable.Table.GetCSType( elem.GetAttribute("type"));
if (cstype == "void")
cstype = "System.IntPtr";
if (IsArray) {
if (IsParams)
cstype = "params " + cstype;
cstype += "[]";
cstype = cstype.Replace ("ref ", "");
}
return cstype;
}
}
public IGeneratable Generatable {
get {
return SymbolTable.Table[CType];
}
}
public bool IsArray {
get {
return elem.GetAttributeAsBoolean ("array") || elem.GetAttributeAsBoolean ("null_term_array");
}
}
public bool IsEllipsis {
get {
return elem.GetAttributeAsBoolean ("ellipsis");
}
}
internal bool IsOptional {
get {
return elem.GetAttributeAsBoolean ("allow-none");
}
}
bool is_count;
bool is_count_set;
public bool IsCount {
get {
if (is_count_set)
return is_count;
if (Name.StartsWith("n_"))
switch (CSType) {
case "int":
case "uint":
case "long":
case "ulong":
case "short":
case "ushort":
return true;
default:
return false;
}
else
return false;
}
set {
is_count_set = true;
is_count = value;
}
}
public bool IsDestroyNotify {
get {
return CType == "GDestroyNotify";
}
}
public bool IsLength {
get {
if (Name.EndsWith("len") || Name.EndsWith("length"))
switch (CSType) {
case "int":
case "uint":
case "long":
case "ulong":
case "short":
case "ushort":
return true;
default:
return false;
}
else
return false;
}
}
public bool IsParams {
get {
return elem.HasAttribute("params");
}
}
public bool IsString {
get {
return (CSType == "string");
}
}
public bool IsUserData {
get {
return CSType == "IntPtr" && (Name.EndsWith ("data") || Name.EndsWith ("data_or_owner"));
}
}
public virtual string MarshalType {
get {
string type = SymbolTable.Table.GetMarshalType( elem.GetAttribute("type"));
if (type == "void" || Generatable is IManualMarshaler)
type = "IntPtr";
if (IsArray) {
type += "[]";
type = type.Replace ("ref ", "");
}
return type;
}
}
public string Name {
get {
return SymbolTable.Table.MangleName (elem.GetAttribute("name"));
}
}
public bool IsOwnable {
get {
return this.Generatable is OwnableGen;
}
}
public bool Owned {
get {
return elem.GetAttribute ("owned") == "true";
}
}
public virtual string NativeSignature {
get {
string sig = MarshalType + " " + Name;
if (PassAs != String.Empty)
sig = PassAs + " " + sig;
return sig;
}
}
public string PropertyName {
get {
return elem.GetAttribute("property_name");
}
}
string pass_as;
public string PassAs {
get {
if (pass_as != null)
return pass_as;
if (elem.HasAttribute ("pass_as"))
return elem.GetAttribute ("pass_as");
if (IsArray || CSType.EndsWith ("IntPtr"))
return "";
if (CType.EndsWith ("*") && (Generatable is SimpleGen || Generatable is EnumGen))
return "out";
return "";
}
set {
pass_as = value;
}
}
string scope;
public string Scope {
get {
if (scope == null)
scope = elem.GetAttribute ("scope");
return scope;
}
set {
scope = value;
}
}
int closure = -1;
public int Closure {
get {
if(closure == -1 && elem.HasAttribute ("closure"))
closure = int.Parse(elem.GetAttribute ("closure"));
return closure;
}
set {
closure = value;
}
}
int destroynotify = -1;
public int DestroyNotify {
get {
if (destroynotify == -1 && elem.HasAttribute ("destroy"))
destroynotify = int.Parse (elem.GetAttribute ("destroy"));
return destroynotify;
}
set {
destroynotify = value;
}
}
public bool IsHidden {
get {
return elem.GetAttributeAsBoolean ("hidden");
}
}
public virtual string[] Prepare {
get {
IGeneratable gen = Generatable;
if (gen is IManualMarshaler) {
string result = "IntPtr native_" + CallName;
if (PassAs != "out")
result += " = " + (gen as IManualMarshaler).AllocNative (CallName);
return new string [] { result + ";" };
} else if (PassAs == "out" && CSType != MarshalType) {
return new string [] { gen.MarshalType + " native_" + CallName + ";" };
} else if (PassAs == "ref" && CSType != MarshalType) {
return new string [] { gen.MarshalType + " native_" + CallName + " = (" + gen.MarshalType + ") " + CallName + ";" };
} else if (gen is OpaqueGen && Owned) {
return new string [] { CallName + ".Owned = false;" };
}
return new string [0];
}
}
public virtual string CallString {
get {
string call_parm;
IGeneratable gen = Generatable;
if (gen is CallbackGen)
return SymbolTable.Table.CallByName (CType, CallName + "_wrapper");
else if (PassAs != String.Empty) {
call_parm = PassAs + " ";
if (CSType != MarshalType)
call_parm += "native_";
call_parm += CallName;
} else if (gen is IManualMarshaler)
call_parm = "native_" + CallName;
else if (gen is ObjectBase)
call_parm = (gen as ObjectBase).CallByName (CallName, Owned);
else
call_parm = gen.CallByName (CallName);
return call_parm;
}
}
public virtual string[] Finish {
get {
IGeneratable gen = Generatable;
if (gen is IManualMarshaler) {
string[] result = new string [PassAs == "ref" ? 2 : 1];
int i = 0;
if (PassAs != String.Empty)
result [i++] = CallName + " = " + Generatable.FromNative ("native_" + CallName) + ";";
if (PassAs != "out")
result [i] = (gen as IManualMarshaler).ReleaseNative ("native_" + CallName) + ";";
return result;
} else if (PassAs != String.Empty && MarshalType != CSType)
if (gen is IOwnable)
return new string [] { CallName + " = " + (gen as IOwnable).FromNative ("native_" + CallName, Owned) + ";" };
else
return new string [] { CallName + " = " + gen.FromNative ("native_" + CallName) + ";" };
return new string [0];
}
}
public string FromNative (string var)
{
if (Generatable == null)
return String.Empty;
else if (Generatable is IOwnable)
return ((IOwnable)Generatable).FromNative (var, Owned);
else
return Generatable.FromNative (var);
}
public string StudlyName {
get {
string name = elem.GetAttribute("name");
string[] segs = name.Split('_');
string studly = "";
foreach (string s in segs) {
if (s.Trim () == "")
continue;
studly += (s.Substring(0,1).ToUpper() + s.Substring(1));
}
return studly;
}
}
}
public class ErrorParameter : Parameter {
public ErrorParameter (XmlElement elem) : base (elem)
{
PassAs = "out";
}
public override string CallString {
get {
return "out error";
}
}
}
public class StructParameter : Parameter {
public StructParameter (XmlElement elem) : base (elem) {}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string[] Prepare {
get {
if (PassAs == "out")
return new string [] { "IntPtr native_" + CallName + " = Marshal.AllocHGlobal (" + GenerationInfo.GetSizeOfExpression(Generatable.QualifiedName) + ");"};
else
return new string [] { "IntPtr native_" + CallName + " = " + (Generatable as IManualMarshaler).AllocNative (CallName) + ";"};
}
}
public override string CallString {
get {
return "native_" + CallName;
}
}
public override string[] Finish {
get {
string[] result = new string [PassAs == string.Empty ? 1 : 2];
int i = 0;
if (PassAs != string.Empty) {
result [i++] = CallName + " = " + FromNative ("native_" + CallName) + ";";
}
result [i++] = (Generatable as IManualMarshaler).ReleaseNative ("native_" + CallName) + ";";
return result;
}
}
public override string NativeSignature {
get {
return "IntPtr " + CallName;
}
}
}
}

View File

@@ -0,0 +1,305 @@
// GtkSharp.Generation.Parameters.cs - The Parameters Generation Class.
//
// 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.Collections.Generic;
using System.Xml;
public class Parameters : IEnumerable<Parameter> {
IList<Parameter> param_list = new List<Parameter> ();
XmlElement elem;
bool first_is_instance;
public Parameters (XmlElement elem) : this (elem, false) { }
public Parameters (XmlElement elem, bool first_is_instance)
{
if (elem == null)
valid = true;
this.elem = elem;
this.first_is_instance = first_is_instance;
if (first_is_instance)
is_static = false;
}
public int Count {
get { return param_list.Count; }
}
// gapi assumes GError** parameters to be error parameters in version 1 and 2
private bool throws = false;
public bool Throws {
get {
if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) <= 2)
return true;
if (!throws && elem.HasAttribute ("throws"))
throws = elem.GetAttributeAsBoolean ("throws");
return throws;
}
}
public int VisibleCount {
get {
int visible = 0;
foreach (Parameter p in this) {
if (!IsHidden (p))
visible++;
}
return visible;
}
}
public Parameter this [int idx] {
get {
return param_list [idx];
}
}
public bool IsHidden (Parameter p)
{
int idx = param_list.IndexOf (p);
if (idx > 0 && p.IsLength && p.PassAs == String.Empty && this [idx - 1].IsString)
return true;
if (p.IsCount)
return true;
if (p.IsHidden)
return true;
if (p.CType == "GError**" && Throws)
return true;
if (HasCB || HideData) {
if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) >= 3) {
foreach (Parameter param in param_list) {
if (param.Closure == idx)
return true;
if (param.DestroyNotify == idx)
return true;
}
} else {
if (p.IsUserData && (idx == Count - 1))
return true;
if (p.IsUserData && (idx == Count - 2) && this [Count - 1] is ErrorParameter)
return true;
if (p.IsUserData && idx > 0 && this [idx - 1].Generatable is CallbackGen)
return true;
if (p.IsDestroyNotify && (idx == Count - 1) && this [idx - 1].IsUserData)
return true;
}
}
return false;
}
bool has_cb;
public bool HasCB {
get { return has_cb; }
set { has_cb = value; }
}
public bool HasOutParam {
get {
foreach (Parameter p in this)
if (p.PassAs == "out")
return true;
return false;
}
}
bool hide_data;
public bool HideData {
get { return hide_data; }
set { hide_data = value; }
}
bool is_static;
public bool Static {
get { return is_static; }
set { is_static = value; }
}
bool has_optional;
internal bool HasOptional {
get { return has_optional;}
}
public Parameter GetCountParameter (string param_name)
{
foreach (Parameter p in this)
if (p.Name == param_name) {
p.IsCount = true;
return p;
}
return null;
}
void Clear ()
{
elem = null;
param_list.Clear ();
param_list = null;
}
public IEnumerator<Parameter> GetEnumerator ()
{
return param_list.GetEnumerator ();
}
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
bool valid = false;
public bool Validate (LogWriter log)
{
if (valid)
return true;
if (elem == null)
return false;
for (int i = first_is_instance ? 1 : 0; i < elem.ChildNodes.Count; i++) {
XmlElement parm = elem.ChildNodes [i] as XmlElement;
if (parm == null || parm.Name != "parameter")
continue;
Parameter p = new Parameter (parm);
if (p.IsEllipsis) {
log.Warn ("Ellipsis parameter: hide and bind manually if no alternative exists. ");
Clear ();
return false;
}
if ((p.CSType == "") || (p.Name == "") ||
(p.MarshalType == "") || (SymbolTable.Table.CallByName(p.CType, p.Name) == "")) {
log.Warn ("Unknown type {1} on parameter {0}", p.Name, p.CType);
Clear ();
return false;
}
if (p.IsOptional && p.PassAs == String.Empty && p.IsUserData == false)
has_optional = true;
IGeneratable gen = p.Generatable;
if (p.IsArray) {
p = new ArrayParameter (parm);
if (i < elem.ChildNodes.Count - 1) {
XmlElement next = elem.ChildNodes [i + 1] as XmlElement;
if (next != null || next.Name == "parameter") {
Parameter c = new Parameter (next);
if (c.IsCount) {
p = new ArrayCountPair (parm, next, false);
i++;
}
}
}
} else if (p.IsCount) {
p.IsCount = false;
if (i < elem.ChildNodes.Count - 1) {
XmlElement next = elem.ChildNodes [i + 1] as XmlElement;
if (next != null && next.Name == "parameter") {
Parameter a = new Parameter (next);
if (a.IsArray) {
p = new ArrayCountPair (next, parm, true);
i++;
}
}
}
} else if (p.CType == "GError**" && Throws)
p = new ErrorParameter (parm);
else if (gen is StructBase || gen is ByRefGen) {
p = new StructParameter (parm);
} else if (gen is CallbackGen) {
has_cb = true;
}
param_list.Add (p);
}
if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) < 3 &&
has_cb && Count > 2 && this [Count - 3].Generatable is CallbackGen && this [Count - 2].IsUserData && this [Count - 1].IsDestroyNotify)
this [Count - 3].Scope = "notified";
valid = true;
return true;
}
public bool IsAccessor {
get {
return VisibleCount == 1 && AccessorParam.PassAs == "out";
}
}
public Parameter AccessorParam {
get {
foreach (Parameter p in this) {
if (!IsHidden (p))
return p;
}
return null;
}
}
public string AccessorReturnType {
get {
Parameter p = AccessorParam;
if (p != null)
return p.CSType;
else
return null;
}
}
public string AccessorName {
get {
Parameter p = AccessorParam;
if (p != null)
return p.Name;
else
return null;
}
}
public string ImportSignature {
get {
if (Count == 0)
return String.Empty;
string[] result = new string [Count];
for (int i = 0; i < Count; i++)
result [i] = this [i].NativeSignature;
return String.Join (", ", result);
}
}
}
}

View File

@@ -0,0 +1,255 @@
// 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.Generic;
using System.IO;
using System.Xml;
using System.Xml.Schema;
public class Parser {
const int curr_parser_version = 3;
private XmlDocument Load (string filename, string schema_file)
{
XmlDocument doc = new XmlDocument ();
try {
XmlReaderSettings settings = new XmlReaderSettings ();
if (!String.IsNullOrEmpty (schema_file)) {
settings.Schemas.Add (null, schema_file);
settings.ValidationType = ValidationType.Schema;
settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ValidationEventHandler += ValidationEventHandler;
}
Stream stream = File.OpenRead (filename);
XmlReader reader = XmlReader.Create (stream, settings);
doc.Load (reader);
stream.Close ();
} catch (XmlException e) {
Console.WriteLine ("Invalid XML file.");
Console.WriteLine (e);
doc = null;
}
return doc;
}
private void ValidationEventHandler(object sender, ValidationEventArgs e)
{
switch (e.Severity)
{
case XmlSeverityType.Error:
Console.WriteLine("Error: {0}", e.Message);
break;
case XmlSeverityType.Warning:
Console.WriteLine("Warning: {0}", e.Message);
break;
}
}
public IGeneratable[] Parse (string filename)
{
return Parse (filename, null);
}
public IGeneratable[] Parse (string filename, string schema_file)
{
return Parse (filename, schema_file, String.Empty);
}
public IGeneratable[] Parse (string filename, string schema_file, string gapidir)
{
XmlDocument doc = Load (filename, schema_file);
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);
var gens = new List<IGeneratable> ();
foreach (XmlNode child in root.ChildNodes) {
XmlElement elem = child as XmlElement;
if (elem == null)
continue;
switch (child.Name) {
case "include":
string xmlpath;
if (File.Exists (Path.Combine (gapidir, elem.GetAttribute ("xml"))))
xmlpath = Path.Combine (gapidir, elem.GetAttribute ("xml"));
else if (File.Exists (elem.GetAttribute ("xml")))
xmlpath = elem.GetAttribute ("xml");
else {
Console.WriteLine ("Parser: Could not find include " + elem.GetAttribute ("xml"));
break;
}
IGeneratable[] curr_gens = Parse (xmlpath);
SymbolTable.Table.AddTypes (curr_gens);
break;
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 gens.ToArray ();
}
private IList<IGeneratable> ParseNamespace (XmlElement ns)
{
var result = new List<IGeneratable> ();
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");
bool is_native_struct = elem.GetAttributeAsBoolean ("native");
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":
if (is_opaque) {
result.Add (new OpaqueGen (ns, elem));
} else {
result.Add (new BoxedGen (ns, elem));
}
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 "union":
result.Add (new UnionGen (ns, elem));
break;
case "struct":
if (is_opaque) {
result.Add (new OpaqueGen (ns, elem));
} else if (is_native_struct) {
result.Add (new NativeStructGen (ns, elem));
} else {
result.Add (new StructGen (ns, elem));
}
break;
default:
Console.WriteLine ("Parser::ParseNamespace - Unexpected node: " + def.Name);
break;
}
}
return result;
}
internal static int GetVersion (XmlElement document_element)
{
XmlElement root = document_element;
return root.HasAttribute ("parser_version") ? int.Parse (root.GetAttribute ("parser_version")) : 1;
}
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

@@ -0,0 +1,229 @@
// 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");
}
}
bool IsStyle {
get {
return elem.GetAttributeAsBoolean("style");
}
}
protected virtual string PropertyAttribute (string qpname) {
return "[GLib.Property (" + qpname + ")]";
}
protected virtual string RawGetter (string qpname) {
if (container_type is InterfaceGen)
return "implementor.GetProperty (" + qpname + ")";
return "GetProperty (" + qpname + ")";
}
protected virtual string RawSetter (string qpname) {
if (container_type is InterfaceGen)
return "implementor.SetProperty(" + qpname + ", val)";
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]");
if (!IsStyle) {
sw.WriteLine(indent + PropertyAttribute(qpname));
sw.WriteLine(indent + "public " + modifiers + CSType + " " + name + " {");
}
else {
string csType = CSType + (table.IsBoxed(CType) ? "?" : "");
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 {");
if (!IsStyle) {
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)) {
var igen = table.GetInterfaceGen(CType);
// Do we have to dispose the GLib.Object from the GLib.Value?
sw.WriteLine(indent + "\t{0} ret = {1}.GetObject ((GLib.Object) val);",
igen.QualifiedName, igen.QualifiedAdapterName);
}
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;");
}
else {
string csType = CSType + (table.IsBoxed(CType) ? "?" : "");
sw.WriteLine(indent + "\tvar val = (" + csType + ")StyleGetProperty(" + qpname + ");");
sw.WriteLine(indent + "\treturn val;");
}
sw.WriteLine(indent + "}");
}
if (Setter != null) {
sw.Write(indent + "set ");
Setter.GenerateBody(gen_info, implementor, "\t");
sw.WriteLine();
} else if (Writable) {
if (!IsStyle) { // style properties is writable only through CSS
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

@@ -0,0 +1,116 @@
// GtkSharp.Generation.PropertyBase.cs - base class for properties and
// fields
//
// 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;
using System.Xml;
public abstract class PropertyBase {
protected XmlElement elem;
public ClassBase container_type;
public PropertyBase (XmlElement elem, ClassBase container_type)
{
this.elem = elem;
this.container_type = container_type;
}
public string Name {
get {
return elem.GetAttribute ("name");
}
}
public virtual string CName {
get {
return elem.GetAttribute ("cname");
}
}
protected string ctype;
public virtual string CType {
get {
if (ctype == null) {
if (elem.GetAttribute("bits") == "1")
ctype = "gboolean";
else
ctype = elem.GetAttribute("type");
}
return ctype;
}
}
protected string cstype;
public string CSType {
get {
if (Getter != null)
return Getter.Signature.IsAccessor ? Getter.Signature.AccessorType : Getter.ReturnType;
else if (Setter != null)
return Setter.Signature.Types;
else if (cstype == null)
cstype = SymbolTable.Table.GetCSType (CType);
return cstype;
}
}
public virtual bool Hidden {
get {
return elem.GetAttributeAsBoolean ("hidden");
}
}
protected bool IsNew {
get {
return elem.GetAttributeAsBoolean ("new_flag");
}
}
protected Method Getter {
get {
Method getter = container_type.GetMethod ("Get" + Name);
if (getter != null && getter.Name == "Get" + Name && getter.IsGetter)
return getter;
else
return null;
}
}
protected Method Setter {
get {
Method setter = container_type.GetMethod ("Set" + Name);
if (setter != null && setter.Name == "Set" + Name && setter.IsSetter && (Getter == null || setter.Signature.Types == CSType))
return setter;
else
return null;
}
}
protected virtual void GenerateImports (GenerationInfo gen_info, string indent)
{
if (Getter != null)
Getter.GenerateImport (gen_info.Writer);
if (Setter != null)
Setter.GenerateImport (gen_info.Writer);
}
}
}

View File

@@ -0,0 +1,210 @@
// 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;
int array_length_param_index = -1;
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");
if (elem.HasAttribute ("array_length_param_length"))
array_length_param_index = int.Parse (elem.GetAttribute ("array_length_param_index"));
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 int CountParameterIndex {
get { return array_length_param_index; }
}
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 (!String.IsNullOrEmpty (default_value))
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;
if (is_array || is_null_term)
return "IntPtr";
return IGen.MarshalType;
}
}
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 ("GLib.Marshaller.PtrArrayToArray<{0}> ({1}, {2})", ElementType, var, args);
else if (IGen.QualifiedName == "GLib.List")
return String.Format ("GLib.Marshaller.ListPtrToArray<{0}, {1}> ({2}, {3})", ElementType, element_ctype == "gfilename*" ? "GLib.ListBase.FilenameString" : ElementType, var, args);
else if (IGen.QualifiedName == "GLib.SList" || IGen.QualifiedName == "System.IntPtr")
return String.Format ("GLib.Marshaller.SListPtrToArray<{0}, {1}> ({2}, {3})", ElementType, element_ctype == "gfilename*" ? "GLib.ListBase.FilenameString" : ElementType, var, args);
else
throw new InvalidOperationException($"Unsupported element marshalling configuration for element type {IGen.QualifiedName}");
} 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)
if (CSType == "byte[]" && IGen.QualifiedName == "byte")
return String.Format ("GLib.Marshaller.ArrayPtrToArray<{0}> ({1}, (int){2}native_{3}, true)", CSType, var, CountParameter.CSType == "int" ? String.Empty : "(" + CountParameter.CSType + ")", CountParameter.Name);
else
throw new InvalidOperationException($"Unsupported array marshalling configuration for types {IGen.QualifiedName} and {CSType}");
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.StringArrayToNullTermStrvPointer ({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

@@ -0,0 +1,359 @@
// 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.Collections.Generic;
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;
}
}
private string GenArgsInitialization (StreamWriter sw, IList<Parameter> dispose_params)
{
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 if (dispose_params.Contains (p)) {
sw.WriteLine("\t\t\t\t" + p.Name + " = " + p.FromNative ("arg" + idx) + ";");
sw.WriteLine("\t\t\t\targs.Args[" + idx + "] = " + p.Name + ";");
} 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;
}
private 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;
IList<Parameter> dispose_params = new List<Parameter> ();
foreach (Parameter p in parms) {
if (p.IsOwnable) {
dispose_params.Add (p);
}
}
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);
foreach (Parameter p in dispose_params) {
sw.WriteLine("\t\t\t{0} {1} = null;", p.CSType, p.Name);
}
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, dispose_params);
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);");
if (dispose_params.Count > 0) {
sw.WriteLine ("\t\t\t} finally {");
foreach (Parameter p in dispose_params) {
string disp_name = "disposable_" + p.Name;
sw.WriteLine ("\t\t\t\tvar " + disp_name + " = " + p.Name + " as IDisposable;");
sw.WriteLine ("\t\t\t\tif (" + disp_name + " != null)");
sw.WriteLine ("\t\t\t\t\t" + disp_name + ".Dispose ();");
}
}
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, container_type.NS);
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)) {
var igen = SymbolTable.Table.GetInterfaceGen (parms [i].CType);
sw.WriteLine ("\t\t\t\treturn {0}.GetObject (Args [{1}] as GLib.Object);", igen.QualifiedAdapterName, 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)) {
var igen = SymbolTable.Table.GetInterfaceGen (parms [i].CType);
sw.WriteLine ("\t\t\t\tArgs [{0}] = value is {1} ? (value as {1}).Implementor : value;", i, igen.AdapterName);
} 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

@@ -0,0 +1,165 @@
// 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.Generic;
using System.Xml;
public class Signature {
private IList<Parameter> parms = new List<Parameter> ();
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);
}
}
public string WithoutOptional ()
{
if (parms.Count == 0)
return String.Empty;
var result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms) {
if (p.IsOptional && p.PassAs == String.Empty)
continue;
result [i] = p.PassAs != String.Empty ? p.PassAs + " " : String.Empty;
result [i++] += p.CSType + " " + p.Name;
}
return String.Join (", ", result, 0, i);
}
public string CallWithoutOptionals ()
{
if (parms.Count == 0)
return String.Empty;
var result = new string [parms.Count];
int i = 0;
foreach (Parameter p in parms) {
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
if (p.IsOptional && p.PassAs == String.Empty) {
if (p.IsArray)
result [i++] += "null";
else
result [i++] += p.Generatable.DefaultValue;
}
else
result [i++] += p.Name;
}
return String.Join (", ", result);
}
}
}

View File

@@ -0,0 +1,107 @@
// 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)
{
}
public virtual string GenerateGetSizeOf () {
return null;
}
public virtual string GenerateAlign () {
return null;
}
}
}

View File

@@ -0,0 +1,39 @@
// 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 {
string size_of;
public SimpleGen (string ctype, string type, string default_value) : base (ctype, type, default_value) {}
public SimpleGen (string ctype, string type, string default_value, string size_of) : base (ctype, type, default_value) {
this.size_of = size_of;
}
public override string GenerateGetSizeOf () {
return size_of;
}
}
}

View File

@@ -0,0 +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();
}
}
}

View File

@@ -0,0 +1,144 @@
namespace GtkSharp.Generation {
using System;
using System.Collections;
using System.IO;
using System.Xml;
public class StructABIField : StructField {
protected new ClassBase container_type;
public string parent_structure_name;
public string abi_info_name;
public StructABIField (XmlElement elem, ClassBase container_type,
string info_name) : base (elem, container_type) {
this.container_type = container_type;
this.getOffsetName = null;
this.abi_info_name = info_name;
}
public override string CName {
get {
if (parent_structure_name != null)
return parent_structure_name + '.' + elem.GetAttribute ("cname");
return elem.GetAttribute ("cname");
}
}
public override void Generate (GenerationInfo gen_info, string indent) {
base.Generate(gen_info, indent);
}
// All field are visible and private
// as the goal is to respect the ABI
protected override string Access {
get {
return "private";
}
}
public override bool Hidden {
get {
return false;
}
}
public override bool Validate (LogWriter log)
{
string cstype = SymbolTable.Table.GetCSType(CType, true);
if (elem.GetAttributeAsBoolean("is_callback"))
return true;
if (cstype == null || cstype == "") {
log.Warn (" field \"" + CName + "\" has no cstype, can't generate ABI field.");
return false;
}
if (!base.Validate (log))
return false;
return true;
}
public void SetGetOffseName() {
this.getOffsetName = "Get" + CName + "Offset";
}
public override string GenerateGetSizeOf(string indent) {
return base.GenerateGetSizeOf(indent) + " // " + CName;
}
public virtual StructABIField Generate (GenerationInfo gen_info, string indent,
StructABIField prev_field, StructABIField next_field, string parent_name,
TextWriter structw) {
StreamWriter sw = gen_info.Writer;
IGeneratable gen = SymbolTable.Table[CType];
sw.WriteLine("{0}\tnew GLib.AbiField(\"{1}\"", indent, CName);
indent = indent + "\t\t";
if (prev_field != null) {
sw.WriteLine(indent + ", -1");
} else {
if (parent_name != "")
sw.WriteLine(indent + ", " + parent_name + "." + abi_info_name + ".Fields");
else
sw.WriteLine(indent + ", 0");
}
sw.WriteLine(indent + ", " + GenerateGetSizeOf(""));
var prev_field_name = prev_field != null ? "\"" + prev_field.CName + "\"" : "null";
sw.WriteLine(indent + ", " + prev_field_name);
var container_name = container_type.CName.Replace(".", "_");
var sanitized_name = CName.Replace(".", "_");
var alig_struct_name = container_name + "_" + sanitized_name + "Align";
var next_field_name = next_field != null ? "\"" + next_field.CName + "\"" : "null";
sw.WriteLine(indent + ", " + next_field_name);
if (structw != null) {
string min_align = gen != null ? gen.GenerateAlign() : null;
// Do not generate structs if the type is a simple pointer.
if (IsCPointer())
min_align = "(uint) sizeof(IntPtr)";
if (IsBitfield)
min_align = "1";
if (min_align == null) {
var tmpindent = "\t\t";
structw.WriteLine(tmpindent + "[StructLayout(LayoutKind.Sequential)]");
structw.WriteLine(tmpindent + "public struct " + alig_struct_name);
structw.WriteLine(tmpindent + "{");
structw.WriteLine(tmpindent + "\tsbyte f1;");
base.Generate(gen_info, tmpindent + "\t", true, structw);
structw.WriteLine(tmpindent + "}");
structw.WriteLine();
var fieldname = SymbolTable.Table.MangleName (CName).Replace(".", "_");
if (IsArray && IsNullTermArray)
fieldname += "Ptr";
sw.WriteLine(indent + ", (long) Marshal.OffsetOf<" + alig_struct_name + ">(\"" + fieldname + "\")");
} else {
sw.WriteLine(indent + ", " + min_align);
}
}
gen_info.Writer = sw;
uint bits = 0;
var bitsstr = elem.GetAttribute("bits");
if (bitsstr != null && bitsstr != "")
bits = (uint) Int32.Parse(bitsstr);
sw.WriteLine(indent + ", " + bits);
sw.WriteLine(indent + "),");
return this;
}
}
}

View File

@@ -0,0 +1,313 @@
// GtkSharp.Generation.StructBase.cs - The Structure/Boxed Base Class.
//
// Authors:
// Mike Kestner <mkestner@speakeasy.net>
// Stephan Sundermann <stephansundermann@gmail.com>
//
// Copyright (c) 2001-2003 Mike Kestner
// Copyright (c) 2013 Stephan Sundermann
//
// 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.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
public abstract class StructBase : ClassBase, IManualMarshaler {
IList<StructField> fields = new List<StructField> ();
bool need_read_native = false;
protected StructBase (XmlElement ns, XmlElement elem) : base (ns, elem)
{
foreach (XmlNode node in elem.ChildNodes) {
if (!(node is XmlElement)) continue;
XmlElement member = (XmlElement) node;
switch (node.Name) {
case "field":
fields.Add (new StructField (member, this));
break;
case "callback":
Statistics.IgnoreCount++;
break;
default:
if (!IsNodeNameHandled (node.Name))
Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
break;
}
}
}
public override string DefaultValue {
get {
return QualifiedName + ".Zero";
}
}
public override string MarshalType {
get {
return "IntPtr";
}
}
public override string AssignToName {
get { throw new NotImplementedException (); }
}
public override string CallByName ()
{
return "this_as_native";
}
public override string CallByName (string var)
{
return var + "_as_native";
}
public override string FromNative (string var)
{
if (DisableNew)
return var + " == IntPtr.Zero ? " + QualifiedName + ".Zero : (" + QualifiedName + ") System.Runtime.InteropServices.Marshal.PtrToStructure (" + var + ", typeof (" + QualifiedName + "))";
else
return QualifiedName + ".New (" + var + ")";
}
public string AllocNative (string var)
{
return "GLib.Marshaller.StructureToPtrAlloc (" + var + ")";
}
public string ReleaseNative (string var)
{
return "Marshal.FreeHGlobal (" +var + ")";
}
private bool DisableNew {
get {
return Elem.GetAttributeAsBoolean ("disable_new");
}
}
public virtual bool Union {
get {
return false;
}
}
protected void GenEqualsAndHash (StreamWriter sw)
{
int bitfields = 0;
bool need_field = true;
StringBuilder hashcode = new StringBuilder ();
StringBuilder equals = new StringBuilder ();
hashcode.Append ("this.GetType ().FullName.GetHashCode ()");
equals.Append ("true");
foreach (StructField field in fields) {
if (field.IsPadding || field.Hidden)
continue;
if (field.IsBitfield) {
if (need_field) {
equals.Append (" && _bitfield");
equals.Append (bitfields);
equals.Append (".Equals (other._bitfield");
equals.Append (bitfields);
equals.Append (")");
hashcode.Append (" ^ ");
hashcode.Append ("_bitfield");
hashcode.Append (bitfields++);
hashcode.Append (".GetHashCode ()");
need_field = false;
}
} else {
need_field = true;
equals.Append (" && ");
equals.Append (field.EqualityName);
equals.Append (".Equals (other.");
equals.Append (field.EqualityName);
equals.Append (")");
hashcode.Append (" ^ ");
hashcode.Append (field.EqualityName);
hashcode.Append (".GetHashCode ()");
}
}
if (!Elem.GetAttributeAsBoolean ("noequals")) {
sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\treturn {0};", equals.ToString ());
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
sw.WriteLine ("\t\tpublic override bool Equals (object other)");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\treturn other is {0} && Equals (({0}) other);", Name);
sw.WriteLine ("\t\t}");
sw.WriteLine ();
if (Elem.GetAttributeAsBoolean ("nohash"))
return;
sw.WriteLine ("\t\tpublic override int GetHashCode ()");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\treturn {0};", hashcode.ToString ());
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
protected new void GenFields (GenerationInfo gen_info)
{
int bitfields = 0;
bool need_field = true;
StreamWriter sw = gen_info.Writer;
foreach (StructField field in fields) {
if (Union)
sw.WriteLine ("\t\t[FieldOffset(0)]");
if (field.IsBitfield) {
if (need_field) {
sw.WriteLine ("\t\tprivate uint _bitfield{0};\n", bitfields++);
need_field = false;
}
} else
need_field = true;
field.Generate (gen_info, "\t\t");
}
}
public override bool Validate ()
{
LogWriter log = new LogWriter (QualifiedName);
foreach (StructField field in fields) {
if (!field.Validate (log)) {
if (!field.IsPointer)
return false;
}
}
return base.Validate ();
}
public override bool CanGenerateABIStruct(LogWriter log) {
log.Info("Not generating any ABI structs for managed structures");
return false;
}
public override void Generate (GenerationInfo gen_info)
{
bool need_close = false;
if (gen_info.Writer == null) {
gen_info.Writer = gen_info.OpenStream (Name, NS);
need_close = true;
}
StreamWriter sw = gen_info.Writer;
sw.WriteLine ("namespace " + NS + " {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Collections;");
sw.WriteLine ("\tusing System.Collections.Generic;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
if (IsDeprecated)
sw.WriteLine ("\t[Obsolete]");
if (Union)
sw.WriteLine ("\t[StructLayout(LayoutKind.Explicit)]");
else
sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
string access = IsInternal ? "internal" : "public";
sw.WriteLine ("\t" + access + " partial struct {0} : IEquatable<{0}> {{", Name);
sw.WriteLine ();
need_read_native = false;
GenFields (gen_info);
sw.WriteLine ();
GenCtors (gen_info);
GenMethods (gen_info, null, this);
if (need_read_native)
GenReadNative (sw);
GenEqualsAndHash (sw);
if (!need_close)
return;
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
gen_info.Writer = null;
}
protected override void GenCtors (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
sw.WriteLine ("\t\tpublic static {0} Zero = new {0} ();", QualifiedName);
sw.WriteLine();
if (!DisableNew) {
sw.WriteLine ("\t\tpublic static " + QualifiedName + " New(IntPtr raw) {");
sw.WriteLine ("\t\t\tif (raw == IntPtr.Zero)");
sw.WriteLine ("\t\t\t\treturn {0}.Zero;", QualifiedName);
sw.WriteLine ("\t\t\treturn ({0}) Marshal.PtrToStructure (raw, typeof ({0}));", QualifiedName);
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
foreach (Ctor ctor in Ctors)
ctor.IsStatic = true;
base.GenCtors (gen_info);
}
void GenReadNative (StreamWriter sw)
{
sw.WriteLine ("\t\tstatic void ReadNative (IntPtr native, ref {0} target)", QualifiedName);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\ttarget = New (native);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
public override void Prepare (StreamWriter sw, string indent)
{
sw.WriteLine (indent + "IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf<" + QualifiedName + ">());");
sw.WriteLine (indent + "System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);");
}
public override void Finish (StreamWriter sw, string indent)
{
need_read_native = true;
sw.WriteLine (indent + "ReadNative (this_as_native, ref this);");
sw.WriteLine (indent + "System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);");
}
}
}

View File

@@ -0,0 +1,275 @@
// GtkSharp.Generation.StructField.cs - The Structure Field generation
// Class.
//
// Author: Mike Kestner <mkestner@ximian.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.IO;
using System.Xml;
public class StructField : FieldBase {
public static int bitfields;
public StructField (XmlElement elem, ClassBase container_type) : base (elem, container_type) {}
protected override string DefaultAccess {
get {
if (IsPadding)
return "private";
return "public";
}
}
public int ArrayLength {
get {
if (!IsArray)
return 0;
int result;
try {
result = Int32.Parse (elem.GetAttribute("array_len"));
} catch (Exception) {
LogWriter log = new LogWriter (container_type.Name + "." + Name);
log.Warn("Non-numeric array_len: \"" + elem.GetAttribute("array_len") +
"\" incorrectly generated");
result = 0;
}
return result;
}
}
public bool IsNullTermArray {
get { return elem.GetAttributeAsBoolean ("null_term_array"); }
}
public new string CSType {
get {
string type = base.CSType;
if (IsArray)
type += "[]";
else if ((IsPointer || SymbolTable.Table.IsOpaque (CType)) && type != "string")
type = "IntPtr";
return type;
}
}
bool visible = false;
internal bool Visible {
get {
return visible;
}
}
public string EqualityName {
get {
SymbolTable table = SymbolTable.Table;
string wrapped_name = SymbolTable.Table.MangleName (CName);
IGeneratable gen = table [CType];
if (IsArray && IsNullTermArray)
return StudlyName + "Ptr";
else if (IsArray || gen is IAccessor)
return Access == "public" ? StudlyName : Name;
else if (IsBitfield)
return Name;
else if (IsPointer && (gen is StructGen || gen is BoxedGen || gen is UnionGen))
return Access != "private" ? wrapped_name : Name;
else if (IsPointer && CSType != "string")
return Name;
else
return Access == "public" ? StudlyName : Name;
}
}
bool IsFixedSizeArray() {
return IsArray && !IsNullTermArray && ArrayLength != 0;
}
public virtual bool IsCPointer() {
IGeneratable gen = SymbolTable.Table[CType];
return (CType.EndsWith("*") ||
CType.EndsWith ("pointer") ||
gen is CallbackGen ||
cstype == "string" ||
(CType == "guint8" && (IsArray && IsNullTermArray)) ||
elem.GetAttributeAsBoolean("is_callback"));
}
public virtual string GenerateGetSizeOf(string indent) {
string cstype = SymbolTable.Table.GetCSType(CType, true);
string res = "";
IGeneratable gen = SymbolTable.Table[CType];
var is_pointer = false;
if (IsCPointer()) {
is_pointer = true;
cstype = "IntPtr";
} else if (gen != null) {
res = gen.GenerateGetSizeOf();
}
if (res != null && res != "") {
if (IsFixedSizeArray())
res += " * " + ArrayLength;
return indent + res;
}
var _enum = gen as EnumGen;
if (_enum != null && !is_pointer)
res = "(uint) sizeof(" + cstype + ")";
else
res = "(uint) " + GenerationInfo.GetSizeOfExpression(cstype);
if (IsFixedSizeArray())
res += " * " + ArrayLength;
return res;
}
public bool IsPadding {
get {
if (elem.GetAttributeAsBoolean ("padding"))
return elem.GetAttributeAsBoolean ("padding");
return (elem.GetAttribute ("access") == "private" && (
CName.StartsWith ("dummy") || CName.StartsWith ("padding")));
}
}
public bool IsPointer {
get {
return IsCPointer();
}
}
public new string Name {
get {
string result = "";
if ((IsPointer || SymbolTable.Table.IsOpaque (CType)) && CSType != "string")
result = "_";
result += SymbolTable.Table.MangleName (CName);
return result;
}
}
public virtual string StudlyName {
get {
string studly = base.Name;
if (studly == "")
throw new Exception (CName + "API file must be regenerated with a current version of the GAPI parser. It is incompatible with this version of the GAPI code generator.");
return studly;
}
}
public override void Generate (GenerationInfo gen_info, string indent)
{
Generate(gen_info, indent, false, gen_info.Writer);
}
public void Generate (GenerationInfo gen_info, string indent, bool use_cnames,
TextWriter sw)
{
if (Hidden && !use_cnames)
return;
visible = Access != "private";
SymbolTable table = SymbolTable.Table;
string wrapped = table.GetCSType (CType);
string wrapped_name = SymbolTable.Table.MangleName (CName);
string name = Name;
string studly_name = StudlyName;
string cstype = CSType;
IGeneratable gen = table [CType];
if (use_cnames) {
name = studly_name = wrapped_name = SymbolTable.Table.MangleName (CName).Replace(".", "_");
var mangen = gen as ManualGen;
if (mangen != null) {
if (mangen.AbiType != null)
cstype = mangen.AbiType;
}
if (IsCPointer())
cstype = "IntPtr";
}
if (IsArray && !IsNullTermArray) {
sw.WriteLine (indent + "[MarshalAs (UnmanagedType.ByValArray, SizeConst=" + ArrayLength + ")]");
sw.WriteLine (indent + "{0} {1} {2};", Access, cstype, studly_name);
} else if (IsArray && IsNullTermArray) {
sw.WriteLine (indent + "private {0} {1};", "IntPtr", studly_name+ "Ptr");
if ((Readable || Writable) && Access == "public") {
sw.WriteLine (indent + "public {0} {1} {{", cstype, studly_name);
if (Readable)
sw.WriteLine (indent + "\tget {{ return GLib.Marshaller.StructArrayFromNullTerminatedIntPtr<{0}> ({1}); }}",
base.CSType, studly_name + "Ptr");
if (Writable)
sw.WriteLine (indent + "\tset {{ {0} = GLib.Marshaller.StructArrayToNullTerminatedStructArrayIntPtr<{1}> (value); }}",
studly_name + "Ptr", base.CSType);
sw.WriteLine (indent + "}");
}
} else if (IsBitfield) {
base.Generate (gen_info, indent);
} else if (gen is IAccessor) {
sw.WriteLine (indent + "private {0} {1};", gen.MarshalType, name);
if (Access != "private") {
IAccessor acc = table [CType] as IAccessor;
sw.WriteLine (indent + Access + " " + wrapped + " " + studly_name + " {");
acc.WriteAccessors (sw, indent + "\t", name);
sw.WriteLine (indent + "}");
}
} else if (IsPointer && (gen is StructGen || gen is BoxedGen || gen is UnionGen)) {
sw.WriteLine (indent + "private {0} {1};", cstype, name);
sw.WriteLine ();
if (Access != "private") {
sw.WriteLine (indent + Access + " " + wrapped + " " + wrapped_name + " {");
sw.WriteLine (indent + "\tget { return " + table.FromNative (CType, name) + "; }");
sw.WriteLine (indent + "}");
}
} else if (IsPointer && cstype != "string") {
// FIXME: probably some fields here which should be visible.
visible = false;
sw.WriteLine (indent + "private {0} {1};", cstype, name);
} else {
sw.WriteLine (indent + "{0} {1} {2};", Access, cstype, Access == "public" ? studly_name : name);
}
}
}
}

View File

@@ -0,0 +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, NS);
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

@@ -0,0 +1,447 @@
// 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.Generic;
public class SymbolTable {
static SymbolTable table = null;
static LogWriter log = new LogWriter ("SymbolTable");
IDictionary<string, IGeneratable> types = new Dictionary<string, IGeneratable> ();
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 ("unsigned long long", "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 gchar* const"));
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 ManualGen ("GMutex", "GLib.Mutex",
"new GLib.Mutex({0})",
"GLib.Mutex.ABI"));
AddType (new ManualGen ("GRecMutex",
"GLib.RecMutex",
"new GLib.RecMutex({0})",
"GLib.RecMutex.ABI"));
AddType (new ManualGen ("GCond", "GLib.Cond",
"new GLib.Cond({0})",
"GLib.Cond.ABI"));
AddType (new ManualGen ("GDateTime", "GLib.DateTime"));
AddType (new ManualGen ("GDate", "GLib.Date"));
AddType (new ManualGen ("GSource", "GLib.Source"));
AddType (new ManualGen ("GMainContext", "GLib.MainContext"));
AddType (new SimpleGen ("GPollFD", "GLib.PollFD", "GLib.PollFD.Zero"));
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",
"(uint) sizeof(IntPtr)"));
AddType (new SimpleGen ("GThread", "GLib.Thread", "null"));
AddType (new ManualGen ("GBytes", "GLib.Bytes"));
AddType (new SimpleGen ("GHookList", "GLib.HookList", "null",
"GLib.HookList.abi_info.Size"));
// 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"));
AddType (new SimpleGen ("GBoxedCopyFunc", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GBoxedFreeFunc", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GHookFinalizeFunc", "IntPtr", "IntPtr.Zero"));
}
public void AddType (IGeneratable gen)
{
log.Info("Adding " + gen.CName + " = " + gen);
types [gen.CName] = gen;
}
public void AddTypes (IGeneratable[] gens)
{
foreach (IGeneratable gen in gens)
AddType(gen);
}
public int Count {
get
{
return types.Count;
}
}
public IEnumerable<IGeneratable> Generatables {
get {
return types.Values;
}
}
public IGeneratable this [string ctype] {
get {
return DeAlias (ctype);
}
}
private bool IsConstString (string type)
{
switch (type) {
case "const-gchar":
case "const gchar":
case "const gchar* const":
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);
if (trim_type.StartsWith("const ")) return trim_type.Substring(6);
return trim_type;
}
private IGeneratable DeAlias (string type)
{
type = Trim (type);
IGeneratable cur_type = null;
while (types.TryGetValue (type, out cur_type) && cur_type is AliasGen) {
IGeneratable igen = cur_type as AliasGen;
IGeneratable new_type;
if (!types.TryGetValue (igen.Name, out new_type))
new_type = null;
types [type] = new_type;
type = igen.Name;
}
return cur_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, bool default_pointer)
{
IGeneratable gen = this[c_type];
if (gen == null) {
if (c_type.EndsWith("*") && default_pointer)
return "IntPtr";
return "";
}
return gen.QualifiedName;
}
public string GetCSType(string c_type)
{
return GetCSType(c_type, false);
}
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 IsUnion (string c_type)
{
if (this[c_type] is UnionGen)
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 InterfaceGen GetInterfaceGen (string c_type)
{
return this[c_type] as InterfaceGen;
}
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

@@ -0,0 +1,160 @@
namespace GtkSharp.Generation {
using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Collections.Generic;
public class UnionSubstruct {
List<StructABIField> fields;
XmlElement Elem;
bool is_valid;
bool unique_field;
public string abi_info_name;
public UnionSubstruct(XmlElement elem, ClassBase container_type, string abi_info_name) {
fields = new List<StructABIField> ();
Elem = elem;
is_valid = true;
unique_field = false;
if (Elem.Name == "struct") {
foreach (XmlElement child_field in elem.ChildNodes) {
if (child_field.Name != "field") {
is_valid = false;
continue;
}
fields.Add(new StructABIField (child_field, container_type, abi_info_name));
}
} else if (Elem.Name == "field") {
fields.Add(new StructABIField (Elem, container_type, abi_info_name));
unique_field = true;
}
}
public string GenerateGetSize(string indent) {
var size = indent += "new List<string>() {";
var is_first = true;
foreach (StructABIField field in fields) {
if (!is_first)
size += ",";
is_first = false;
size += "\"" + field.CName + "\"";
}
return size + "}";
}
public void EnsureParentStructName (string parent_name) {
var name = Elem.GetAttribute("name");
if (!unique_field) {
parent_name = parent_name + '.' + name;
}
StructABIField next_field = null;
foreach (var field in fields) {
field.parent_structure_name = parent_name;
}
}
public StructField Generate(GenerationInfo gen_info, string indent,
string parent_name, StructABIField prev_field,
StructABIField next, string struct_parent_name,
TextWriter tw)
{
StreamWriter sw = gen_info.Writer;
var name = Elem.GetAttribute("name");
var cname = Elem.GetAttribute("cname");
if (!unique_field) {
parent_name = parent_name + '.' + name;
}
StructABIField next_field = null;
sw.WriteLine(indent + "// union struct " + parent_name);
for(int i=0; i < fields.Count; i++) {
var field = fields[i];
next_field = fields.Count > i + 1 ? fields[i + 1] : null;
field.parent_structure_name = parent_name;
field.Generate(gen_info, indent, prev_field, next_field, struct_parent_name,
tw);
prev_field = field;
}
sw.WriteLine(indent + "// End " + parent_name);
sw.WriteLine();
return prev_field;
}
}
public class UnionABIField : StructABIField {
bool is_valid;
XmlElement Elem;
protected List<UnionSubstruct> substructs = new List<UnionSubstruct> ();
public UnionABIField (XmlElement elem, ClassBase container_type, string info_name) :
base (elem, container_type, info_name) {
Elem = elem;
is_valid = true;
foreach (XmlElement union_child in elem.ChildNodes) {
substructs.Add(new UnionSubstruct(union_child, container_type, abi_info_name));
}
}
public override StructABIField Generate (GenerationInfo gen_info, string indent,
StructABIField prev_field, StructABIField next_field, string parent_name,
TextWriter tw) {
StreamWriter sw = gen_info.Writer;
var name = Elem.GetAttribute("name");
var cname = Elem.GetAttribute("cname");
foreach (UnionSubstruct _struct in substructs)
_struct.EnsureParentStructName(cname);
foreach (UnionSubstruct _struct in substructs) {
_struct.Generate(gen_info, indent + "\t", cname, prev_field,
next_field, parent_name, tw);
}
base.Generate(gen_info, indent, prev_field, next_field, parent_name, null);
return this;
}
public override string GenerateGetSizeOf(string indent) {
string res = indent + "new List<List<string>>() { // union " + Elem.GetAttribute("cname") + "\n";
bool first = true;
indent += "\t\t\t";
foreach (UnionSubstruct _struct in substructs) {
if (!first)
res += ",\n";
first = false;
res += _struct.GenerateGetSize(indent + "\t\t\t");
}
res += "\n" + indent + "\t\t }";
return res;
}
public override bool Validate (LogWriter log)
{
if (!is_valid) {
log.Warn("Can't generate ABI compatible union");
}
return is_valid;
}
}
}

View File

@@ -0,0 +1,36 @@
// Authors:
// Stephan Sundermann <stephansundermann@gmail.com>
//
// Copyright (c) 2013 Stephan Sundermann
//
// 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.
using System.Xml;
namespace GtkSharp.Generation
{
public class UnionGen : StructBase {
public UnionGen (XmlElement ns, XmlElement elem) : base (ns, elem)
{
}
public override bool Union {
get {
return true;
}
}
}
}

View File

@@ -0,0 +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.Generic;
using System.Xml;
public class VMSignature {
private IList<Parameter> parms = new List<Parameter> ();
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);
}
}
}

View File

@@ -0,0 +1,157 @@
// GtkSharp.Generation.VirtualMethod.cs - The VirtualMethod Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2003-2004 Novell, Inc.
// Copyright (c) 2009 Christian Hoff
//
// 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 abstract class VirtualMethod : MethodBase {
protected ReturnValue retval;
protected ManagedCallString call;
protected string modifiers = "";
public VirtualMethod (XmlElement elem, ObjectBase container_type) : base (elem, container_type)
{
if (container_type.ParserVersion == 1) {
// The old pre 2.14 parser didn't drop the 1st parameter in all <signal> and <virtual_method> elements
parms = new Parameters (elem ["parameters"], true);
}
retval = new ReturnValue (elem ["return-type"]);
}
protected abstract string CallString {
get;
}
VMSignature signature;
protected new VMSignature Signature {
get {
if (signature == null)
signature = new VMSignature (parms);
return signature;
}
}
/* Creates a callback method which invokes the corresponding virtual method
* @implementor is the class that implements the virtual method(e.g. the class that derives from an interface) or NULL if containing and declaring type are equal
*/
public void GenerateCallback (StreamWriter sw, ClassBase implementor)
{
LogWriter log = new LogWriter ();
log.Type = container_type.QualifiedName;
if (!Validate (log))
return;
string native_signature = "";
if (!IsStatic) {
native_signature += "IntPtr inst";
if (parms.Count > 0)
native_signature += ", ";
}
if (parms.Count > 0)
native_signature += parms.ImportSignature;
sw.WriteLine ("\t\t[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
sw.WriteLine ("\t\tdelegate {0} {1}NativeDelegate ({2});", retval.ToNativeType, this.Name, native_signature);
sw.WriteLine ();
sw.WriteLine ("\t\tstatic {0} {1}_cb ({2})", retval.ToNativeType, this.Name, native_signature);
sw.WriteLine ("\t\t{");
string unconditional = call.Unconditional ("\t\t\t");
if (unconditional.Length > 0)
sw.WriteLine (unconditional);
sw.WriteLine ("\t\t\ttry {");
if (!this.IsStatic) {
string type;
if (implementor != null)
type = implementor.QualifiedName;
else if (this.container_type is InterfaceGen)
// We are in an interface/adaptor, invoke the method in the implementor class
type = (this.container_type as InterfaceGen).ImplementorName;
else
type = this.container_type.Name;
sw.WriteLine ("\t\t\t\t{0} __obj = GLib.Object.GetObject (inst, false) as {0};", type);
}
string indent = "\t\t\t\t";
if (!retval.IsVoid)
sw.WriteLine (indent + retval.CSType + " __result;");
sw.Write (call.Setup (indent));
sw.Write (indent);
if (!retval.IsVoid)
sw.Write ("__result = ");
if (!this.IsStatic)
sw.Write ("__obj.");
sw.WriteLine (this.CallString + ";");
sw.Write (call.Finish (indent));
if (!retval.IsVoid)
sw.WriteLine ("\t\t\t\treturn " + retval.ToNative ("__result") + ";");
bool fatal = parms.HasOutParam || !retval.IsVoid;
sw.WriteLine ("\t\t\t} catch (Exception e) {");
sw.WriteLine ("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");");
if (fatal) {
sw.WriteLine ("\t\t\t\t// NOTREACHED: above call does not return.");
sw.WriteLine ("\t\t\t\tthrow;");
}
if (call.HasDisposeParam) {
sw.WriteLine ("\t\t\t} finally {");
sw.Write (call.DisposeParams (indent));
}
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
enum ValidState {
Unvalidated,
Invalid,
Valid
}
ValidState vstate = ValidState.Unvalidated;
public override bool Validate (LogWriter log)
{
if (vstate != ValidState.Unvalidated)
return vstate == ValidState.Valid;
vstate = ValidState.Valid;
log.Member = Name;
if (!parms.Validate (log) || !retval.Validate (log)) {
vstate = ValidState.Invalid;
return false;
}
call = new ManagedCallString (parms);
return true;
}
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Xml;
namespace GtkSharp.Generation
{
public static class XmlElementExtensions
{
public static bool GetAttributeAsBoolean (this XmlElement elt, string name)
{
string value = elt.GetAttribute (name);
if (String.IsNullOrEmpty (value)) {
return false;
} else {
return XmlConvert.ToBoolean (value);
}
}
}
}

View File

@@ -0,0 +1,74 @@
{
"format": 1,
"restore": {
"E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiCodegen\\GapiCodegen.csproj": {}
},
"projects": {
"E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiCodegen\\GapiCodegen.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiCodegen\\GapiCodegen.csproj",
"projectName": "GapiCodegen",
"projectPath": "E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiCodegen\\GapiCodegen.csproj",
"packagesPath": "C:\\Users\\Uther\\.nuget\\packages\\",
"outputPath": "E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiCodegen\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Uther\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {},
"https://nuget.BepInEx.dev/v3/index.json": {},
"https://www.myget.org/f/umod/api/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.206/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Uther\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.9.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Uther\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]

View File

@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("GapiCodegen")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b7303616129ab5a0ca64def45649ab522d83fa4a")]
[assembly: System.Reflection.AssemblyProductAttribute("GapiCodegen")]
[assembly: System.Reflection.AssemblyTitleAttribute("GapiCodegen")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyMetadataAttribute("RepositoryUrl", "https://github.com/GtkSharp/GtkSharp")]
// Von der MSBuild WriteCodeFragment-Klasse generiert.

View File

@@ -0,0 +1 @@
f0eac8adb781a4da1fc67aba6223e38e43626da42e94cc5237f2642ac2a92f24

View File

@@ -0,0 +1,13 @@
is_global = true
build_property.TargetFramework = net8.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = GapiCodegen
build_property.ProjectDir = E:\projects\KioskApp\GtkSharp\Source\Tools\GapiCodegen\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =

View File

@@ -0,0 +1 @@
9de026a8f14cde4299fdecc22d93e75f97d6aa5b390a102e811bb184ccfcb7ba

View File

@@ -0,0 +1,15 @@
E:\projects\KioskApp\GtkSharp\BuildOutput\Tools\GapiCodegen.exe
E:\projects\KioskApp\GtkSharp\BuildOutput\Tools\GapiCodegen.deps.json
E:\projects\KioskApp\GtkSharp\BuildOutput\Tools\GapiCodegen.runtimeconfig.json
E:\projects\KioskApp\GtkSharp\BuildOutput\Tools\GapiCodegen.dll
E:\projects\KioskApp\GtkSharp\BuildOutput\Tools\GapiCodegen.pdb
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiCodegen\obj\Release\GapiCodegen.GeneratedMSBuildEditorConfig.editorconfig
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiCodegen\obj\Release\GapiCodegen.AssemblyInfoInputs.cache
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiCodegen\obj\Release\GapiCodegen.AssemblyInfo.cs
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiCodegen\obj\Release\GapiCodegen.csproj.CoreCompileInputs.cache
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiCodegen\obj\Release\GapiCodegen.sourcelink.json
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiCodegen\obj\Release\GapiCodegen.dll
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiCodegen\obj\Release\refint\GapiCodegen.dll
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiCodegen\obj\Release\GapiCodegen.pdb
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiCodegen\obj\Release\GapiCodegen.genruntimeconfig.cache
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiCodegen\obj\Release\ref\GapiCodegen.dll

View File

@@ -0,0 +1 @@
9fbad2ed82bce36f58feedabdbc081f6e4a673e9262d803763e145d940ee88f6

View File

@@ -0,0 +1 @@
{"documents":{"E:\\projects\\KioskApp\\GtkSharp\\*":"https://raw.githubusercontent.com/GtkSharp/GtkSharp/b7303616129ab5a0ca64def45649ab522d83fa4a/*"}}

View File

@@ -0,0 +1,80 @@
{
"version": 3,
"targets": {
"net8.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net8.0": []
},
"packageFolders": {
"C:\\Users\\Uther\\.nuget\\packages\\": {},
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiCodegen\\GapiCodegen.csproj",
"projectName": "GapiCodegen",
"projectPath": "E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiCodegen\\GapiCodegen.csproj",
"packagesPath": "C:\\Users\\Uther\\.nuget\\packages\\",
"outputPath": "E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiCodegen\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Uther\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {},
"https://nuget.BepInEx.dev/v3/index.json": {},
"https://www.myget.org/f/umod/api/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.206/PortableRuntimeIdentifierGraph.json"
}
}
}
}

View File

@@ -0,0 +1,8 @@
{
"version": 2,
"dgSpecHash": "Pe2bRtw7wdQvQvPjDFbWKsf5bNHIKMoQFzIUmynPXfvS7TDIqq2tbsUsGLn4xBZHSCx1Nr3QdvkF266DqiTvCw==",
"success": true,
"projectFilePath": "E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiCodegen\\GapiCodegen.csproj",
"expectedPackageFiles": [],
"logs": []
}

View File

@@ -0,0 +1,242 @@
// gapi-fixup.cs - xml alteration engine.
//
// Authors:
// Mike Kestner <mkestner@speakeasy.net>
// Stephan Sundermann <stephansundermann@gmail.com>
//
// Copyright (c) 2003 Mike Kestner
// Copyright (c) 2013 Stephan Sundermann
//
// 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.Parsing {
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
public class Fixup {
public static int Main (string[] args)
{
if (args.Length < 2) {
Console.WriteLine ("Usage: gapi-fixup --metadata=<filename> --api=<filename> --symbols=<filename>");
return 0;
}
string api_filename = "";
XmlDocument api_doc = new XmlDocument ();
XmlDocument meta_doc = new XmlDocument ();
XmlDocument symbol_doc = new XmlDocument ();
foreach (string arg in args) {
if (arg.StartsWith("--metadata=")) {
string meta_filename = arg.Substring (11);
try {
Stream stream = File.OpenRead (meta_filename);
meta_doc.Load (stream);
stream.Close ();
} catch (XmlException e) {
Console.WriteLine ("Invalid meta file.");
Console.WriteLine (e);
return 1;
}
} else if (arg.StartsWith ("--api=")) {
api_filename = arg.Substring (6);
try {
Stream stream = File.OpenRead (api_filename);
api_doc.Load (stream);
stream.Close ();
} catch (XmlException e) {
Console.WriteLine ("Invalid api file.");
Console.WriteLine (e);
return 1;
}
} else if (arg.StartsWith ("--symbols=")) {
string symbol_filename = arg.Substring (10);
try {
Stream stream = File.OpenRead (symbol_filename);
symbol_doc.Load (stream);
stream.Close ();
} catch (XmlException e) {
Console.WriteLine ("Invalid api file.");
Console.WriteLine (e);
return 1;
}
} else {
Console.WriteLine ("Usage: gapi-fixup --metadata=<filename> --api=<filename>");
return 1;
}
}
XPathNavigator meta_nav = meta_doc.CreateNavigator ();
XPathNavigator api_nav = api_doc.CreateNavigator ();
XPathNodeIterator copy_iter = meta_nav.Select ("/metadata/copy-node");
while (copy_iter.MoveNext ()) {
string path = copy_iter.Current.GetAttribute ("path", String.Empty);
XPathExpression expr = api_nav.Compile (path);
string parent = copy_iter.Current.Value;
XPathNodeIterator parent_iter = api_nav.Select (parent);
bool matched = false;
while (parent_iter.MoveNext ()) {
XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode ();
XPathNodeIterator path_iter = parent_iter.Current.Clone ().Select (expr);
while (path_iter.MoveNext ()) {
XmlNode node = ((IHasXmlNode)path_iter.Current).GetNode ();
parent_node.AppendChild (node.Clone ());
}
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <copy-node path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator rmv_iter = meta_nav.Select ("/metadata/remove-node");
while (rmv_iter.MoveNext ()) {
string path = rmv_iter.Current.GetAttribute ("path", "");
XPathNodeIterator api_iter = api_nav.Select (path);
bool matched = false;
while (api_iter.MoveNext ()) {
XmlElement api_node = ((IHasXmlNode)api_iter.Current).GetNode () as XmlElement;
api_node.ParentNode.RemoveChild (api_node);
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <remove-node path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator add_iter = meta_nav.Select ("/metadata/add-node");
while (add_iter.MoveNext ()) {
string path = add_iter.Current.GetAttribute ("path", "");
XPathNodeIterator api_iter = api_nav.Select (path);
bool matched = false;
while (api_iter.MoveNext ()) {
XmlElement api_node = ((IHasXmlNode)api_iter.Current).GetNode () as XmlElement;
foreach (XmlNode child in ((IHasXmlNode)add_iter.Current).GetNode().ChildNodes)
api_node.AppendChild (api_doc.ImportNode (child, true));
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <add-node path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator change_node_type_iter = meta_nav.Select ("/metadata/change-node-type");
while (change_node_type_iter.MoveNext ()) {
string path = change_node_type_iter.Current.GetAttribute ("path", "");
XPathNodeIterator api_iter = api_nav.Select (path);
bool matched = false;
while (api_iter.MoveNext ()) {
XmlElement node = ( (IHasXmlNode) api_iter.Current).GetNode () as XmlElement;
XmlElement parent = node.ParentNode as XmlElement;
XmlElement new_node = api_doc.CreateElement (change_node_type_iter.Current.Value);
foreach (XmlNode child in node.ChildNodes)
new_node.AppendChild (child.Clone ());
foreach (XmlAttribute attribute in node.Attributes)
new_node.Attributes.Append ( (XmlAttribute) attribute.Clone ());
parent.ReplaceChild (new_node, node);
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <change-node-type path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator attr_iter = meta_nav.Select ("/metadata/attr");
while (attr_iter.MoveNext ()) {
string path = attr_iter.Current.GetAttribute ("path", "");
string attr_name = attr_iter.Current.GetAttribute ("name", "");
XPathNodeIterator api_iter = api_nav.Select (path);
bool matched = false;
while (api_iter.MoveNext ()) {
XmlElement node = ((IHasXmlNode)api_iter.Current).GetNode () as XmlElement;
node.SetAttribute (attr_name, attr_iter.Current.Value);
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <attr path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator move_iter = meta_nav.Select ("/metadata/move-node");
while (move_iter.MoveNext ()) {
string path = move_iter.Current.GetAttribute ("path", "");
XPathExpression expr = api_nav.Compile (path);
string parent = move_iter.Current.Value;
XPathNodeIterator parent_iter = api_nav.Select (parent);
bool matched = false;
while (parent_iter.MoveNext ()) {
XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode ();
XPathNodeIterator path_iter = parent_iter.Current.Clone ().Select (expr);
while (path_iter.MoveNext ()) {
XmlNode node = ((IHasXmlNode)path_iter.Current).GetNode ();
parent_node.AppendChild (node.Clone ());
node.ParentNode.RemoveChild (node);
}
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <move-node path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator remove_attr_iter = meta_nav.Select ("/metadata/remove-attr");
while (remove_attr_iter.MoveNext ()) {
string path = remove_attr_iter.Current.GetAttribute ("path", "");
string name = remove_attr_iter.Current.GetAttribute ("name", "");
XPathNodeIterator api_iter = api_nav.Select (path);
bool matched = false;
while (api_iter.MoveNext ()) {
XmlElement node = ( (IHasXmlNode) api_iter.Current).GetNode () as XmlElement;
node.RemoveAttribute (name);
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <remove-attr path=\"{0}\"/> matched no nodes", path);
}
if (symbol_doc != null) {
XPathNavigator symbol_nav = symbol_doc.CreateNavigator ();
XPathNodeIterator iter = symbol_nav.Select ("/api/*");
while (iter.MoveNext ()) {
XmlNode sym_node = ((IHasXmlNode)iter.Current).GetNode ();
XPathNodeIterator parent_iter = api_nav.Select ("/api");
if (parent_iter.MoveNext ()) {
XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode ();
parent_node.AppendChild (api_doc.ImportNode (sym_node, true));
}
}
}
api_doc.Save (api_filename);
return 0;
}
}
}

View File

@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<OutputPath>..\..\..\BuildOutput\Tools</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,74 @@
{
"format": 1,
"restore": {
"E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiFixup\\GapiFixup.csproj": {}
},
"projects": {
"E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiFixup\\GapiFixup.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiFixup\\GapiFixup.csproj",
"projectName": "GapiFixup",
"projectPath": "E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiFixup\\GapiFixup.csproj",
"packagesPath": "C:\\Users\\Uther\\.nuget\\packages\\",
"outputPath": "E:\\projects\\KioskApp\\GtkSharp\\Source\\Tools\\GapiFixup\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Uther\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {},
"https://nuget.BepInEx.dev/v3/index.json": {},
"https://www.myget.org/f/umod/api/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.206/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Uther\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.9.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Uther\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]

View File

@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("GapiFixup")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b7303616129ab5a0ca64def45649ab522d83fa4a")]
[assembly: System.Reflection.AssemblyProductAttribute("GapiFixup")]
[assembly: System.Reflection.AssemblyTitleAttribute("GapiFixup")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyMetadataAttribute("RepositoryUrl", "https://github.com/GtkSharp/GtkSharp")]
// Von der MSBuild WriteCodeFragment-Klasse generiert.

View File

@@ -0,0 +1 @@
307417cae22af845c8acc49631410e1c192bc86382f903625e2bbcce23187fe9

View File

@@ -0,0 +1,13 @@
is_global = true
build_property.TargetFramework = net8.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = GapiFixup
build_property.ProjectDir = E:\projects\KioskApp\GtkSharp\Source\Tools\GapiFixup\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =

View File

@@ -0,0 +1 @@
01cb83b072c6634a35f3c4e9e6c46e46e5f710e9152a496241311da9d861f094

View File

@@ -0,0 +1,15 @@
E:\projects\KioskApp\GtkSharp\BuildOutput\Tools\GapiFixup.exe
E:\projects\KioskApp\GtkSharp\BuildOutput\Tools\GapiFixup.deps.json
E:\projects\KioskApp\GtkSharp\BuildOutput\Tools\GapiFixup.runtimeconfig.json
E:\projects\KioskApp\GtkSharp\BuildOutput\Tools\GapiFixup.dll
E:\projects\KioskApp\GtkSharp\BuildOutput\Tools\GapiFixup.pdb
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiFixup\obj\Release\GapiFixup.GeneratedMSBuildEditorConfig.editorconfig
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiFixup\obj\Release\GapiFixup.AssemblyInfoInputs.cache
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiFixup\obj\Release\GapiFixup.AssemblyInfo.cs
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiFixup\obj\Release\GapiFixup.csproj.CoreCompileInputs.cache
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiFixup\obj\Release\GapiFixup.sourcelink.json
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiFixup\obj\Release\GapiFixup.dll
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiFixup\obj\Release\refint\GapiFixup.dll
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiFixup\obj\Release\GapiFixup.pdb
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiFixup\obj\Release\GapiFixup.genruntimeconfig.cache
E:\projects\KioskApp\GtkSharp\Source\Tools\GapiFixup\obj\Release\ref\GapiFixup.dll

View File

@@ -0,0 +1 @@
53804402a16ee3d7ea792efde6e495e7e66dfff4a3cbb7c5a08deab5946a46af

Some files were not shown because too many files have changed in this diff Show More