2003-12-03 23:08:14 +00:00
|
|
|
// GtkSharp.Generation.MethodBody.cs - The MethodBody Generation Class.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
2004-06-25 16:35:15 +00:00
|
|
|
// 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.
|
|
|
|
|
2003-12-03 23:08:14 +00:00
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
public class MethodBody {
|
|
|
|
|
|
|
|
Parameters parameters;
|
|
|
|
|
2005-07-02 14:55:08 +00:00
|
|
|
public MethodBody (Parameters parms)
|
|
|
|
{
|
2003-12-03 23:08:14 +00:00
|
|
|
parameters = parms;
|
|
|
|
}
|
|
|
|
|
|
|
|
private string CastFromInt (string type)
|
|
|
|
{
|
|
|
|
return type != "int" ? "(" + type + ") " : "";
|
|
|
|
}
|
|
|
|
|
* generator/Parameters.cs (IsHidden): method to check if a
parameter should be hidden in the managed sig (eg, because it's
user_data, or it's the length of the preceding array/string, etc).
(VisibleCount): the number of parameters that will actually be
exposed in the managed signature.
(IsAccessor): test VisibleCount, not Count
(AccessorReturnType, AccessorName): deal with the fact that the
accessor parameter might not be the first one.
* generator/CallbackGen.cs:
* generator/Signature.cs: use Parameters.IsHidden.
* generator/Method.cs (Initialize): set is_set based on
VisibleCount, not Count.
(Validate): call base.Validate() before Initialize() so that
VisibleCount will be correct in Initialize.
* generator/MethodBody.cs (GetCallString, CallArrayLength,
Initialize): update to deal with accessors with multiple args.
* gtk/Clipboard.custom (SetText): implement as an Obsolete variant
of the Text property
* gtk/IconTheme.custom (SearchPath, SetSearchPath): obsolete
SetSearchPath, implement a setter on SearchPath instead.
* gtk/ListStore.custom (SetColumnTypes):
* gtk/TreeStore.custom (SetColumnTypes): implement as an Obsolete
variant of the ColumnTypes property.
* glade/XML.custom (CustomHandler): implement as a property
(SetCustomHandler): Mark this obsolete
* glade/Global.custom (SetCustomHandler): deprecate in favor of
XML.CustomHandler.
* gnomedb/Editor.custom (SetText): implement as an Obsolete
variant of the Text property
svn path=/trunk/gtk-sharp/; revision=43898
2005-05-02 20:10:03 +00:00
|
|
|
private string CallArrayLength (string array_name, Parameter length)
|
2003-12-03 23:08:14 +00:00
|
|
|
{
|
* generator/Parameters.cs (IsHidden): method to check if a
parameter should be hidden in the managed sig (eg, because it's
user_data, or it's the length of the preceding array/string, etc).
(VisibleCount): the number of parameters that will actually be
exposed in the managed signature.
(IsAccessor): test VisibleCount, not Count
(AccessorReturnType, AccessorName): deal with the fact that the
accessor parameter might not be the first one.
* generator/CallbackGen.cs:
* generator/Signature.cs: use Parameters.IsHidden.
* generator/Method.cs (Initialize): set is_set based on
VisibleCount, not Count.
(Validate): call base.Validate() before Initialize() so that
VisibleCount will be correct in Initialize.
* generator/MethodBody.cs (GetCallString, CallArrayLength,
Initialize): update to deal with accessors with multiple args.
* gtk/Clipboard.custom (SetText): implement as an Obsolete variant
of the Text property
* gtk/IconTheme.custom (SearchPath, SetSearchPath): obsolete
SetSearchPath, implement a setter on SearchPath instead.
* gtk/ListStore.custom (SetColumnTypes):
* gtk/TreeStore.custom (SetColumnTypes): implement as an Obsolete
variant of the ColumnTypes property.
* glade/XML.custom (CustomHandler): implement as a property
(SetCustomHandler): Mark this obsolete
* glade/Global.custom (SetCustomHandler): deprecate in favor of
XML.CustomHandler.
* gnomedb/Editor.custom (SetText): implement as an Obsolete
variant of the Text property
svn path=/trunk/gtk-sharp/; revision=43898
2005-05-02 20:10:03 +00:00
|
|
|
string result = array_name + " != null ? ";
|
|
|
|
result += CastFromInt (length.CSType) + array_name + ".Length";
|
2005-04-04 16:27:08 +00:00
|
|
|
result += ": 0";
|
2004-12-09 18:40:09 +00:00
|
|
|
return length.Generatable.CallByName (result);
|
2003-12-03 23:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public string GetCallString (bool is_set)
|
|
|
|
{
|
2005-01-26 19:17:07 +00:00
|
|
|
if (parameters.Count == 0)
|
2003-12-03 23:08:14 +00:00
|
|
|
return "";
|
|
|
|
|
|
|
|
string[] result = new string [parameters.Count];
|
|
|
|
for (int i = 0; i < parameters.Count; i++) {
|
|
|
|
Parameter p = parameters [i];
|
|
|
|
IGeneratable igen = p.Generatable;
|
2007-03-01 18:37:06 +00:00
|
|
|
bool is_prop = is_set && (i == 0 || (i == 1 && p.IsArray && parameters[0].IsCount));
|
|
|
|
string name = is_prop ? "value" : p.Name;
|
2003-12-03 23:08:14 +00:00
|
|
|
|
|
|
|
if (p.IsCount) {
|
|
|
|
if (i > 0 && parameters [i - 1].IsArray) {
|
* generator/Parameters.cs (IsHidden): method to check if a
parameter should be hidden in the managed sig (eg, because it's
user_data, or it's the length of the preceding array/string, etc).
(VisibleCount): the number of parameters that will actually be
exposed in the managed signature.
(IsAccessor): test VisibleCount, not Count
(AccessorReturnType, AccessorName): deal with the fact that the
accessor parameter might not be the first one.
* generator/CallbackGen.cs:
* generator/Signature.cs: use Parameters.IsHidden.
* generator/Method.cs (Initialize): set is_set based on
VisibleCount, not Count.
(Validate): call base.Validate() before Initialize() so that
VisibleCount will be correct in Initialize.
* generator/MethodBody.cs (GetCallString, CallArrayLength,
Initialize): update to deal with accessors with multiple args.
* gtk/Clipboard.custom (SetText): implement as an Obsolete variant
of the Text property
* gtk/IconTheme.custom (SearchPath, SetSearchPath): obsolete
SetSearchPath, implement a setter on SearchPath instead.
* gtk/ListStore.custom (SetColumnTypes):
* gtk/TreeStore.custom (SetColumnTypes): implement as an Obsolete
variant of the ColumnTypes property.
* glade/XML.custom (CustomHandler): implement as a property
(SetCustomHandler): Mark this obsolete
* glade/Global.custom (SetCustomHandler): deprecate in favor of
XML.CustomHandler.
* gnomedb/Editor.custom (SetText): implement as an Obsolete
variant of the Text property
svn path=/trunk/gtk-sharp/; revision=43898
2005-05-02 20:10:03 +00:00
|
|
|
string array_name = (i == 1 && is_set) ? "value" : parameters [i - 1].Name;
|
|
|
|
result[i] = CallArrayLength (array_name, p);
|
2003-12-03 23:08:14 +00:00
|
|
|
continue;
|
|
|
|
} else if (i < parameters.Count - 1 && parameters [i + 1].IsArray) {
|
* generator/Parameters.cs (IsHidden): method to check if a
parameter should be hidden in the managed sig (eg, because it's
user_data, or it's the length of the preceding array/string, etc).
(VisibleCount): the number of parameters that will actually be
exposed in the managed signature.
(IsAccessor): test VisibleCount, not Count
(AccessorReturnType, AccessorName): deal with the fact that the
accessor parameter might not be the first one.
* generator/CallbackGen.cs:
* generator/Signature.cs: use Parameters.IsHidden.
* generator/Method.cs (Initialize): set is_set based on
VisibleCount, not Count.
(Validate): call base.Validate() before Initialize() so that
VisibleCount will be correct in Initialize.
* generator/MethodBody.cs (GetCallString, CallArrayLength,
Initialize): update to deal with accessors with multiple args.
* gtk/Clipboard.custom (SetText): implement as an Obsolete variant
of the Text property
* gtk/IconTheme.custom (SearchPath, SetSearchPath): obsolete
SetSearchPath, implement a setter on SearchPath instead.
* gtk/ListStore.custom (SetColumnTypes):
* gtk/TreeStore.custom (SetColumnTypes): implement as an Obsolete
variant of the ColumnTypes property.
* glade/XML.custom (CustomHandler): implement as a property
(SetCustomHandler): Mark this obsolete
* glade/Global.custom (SetCustomHandler): deprecate in favor of
XML.CustomHandler.
* gnomedb/Editor.custom (SetText): implement as an Obsolete
variant of the Text property
svn path=/trunk/gtk-sharp/; revision=43898
2005-05-02 20:10:03 +00:00
|
|
|
string array_name = (i == 0 && is_set) ? "value" : parameters [i + 1].Name;
|
|
|
|
result[i] = CallArrayLength (array_name, p);
|
2003-12-03 23:08:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-12-12 22:56:28 +00:00
|
|
|
} else if (i > 0 && parameters [i - 1].IsString && p.IsLength) {
|
* generator/Parameters.cs (IsHidden): method to check if a
parameter should be hidden in the managed sig (eg, because it's
user_data, or it's the length of the preceding array/string, etc).
(VisibleCount): the number of parameters that will actually be
exposed in the managed signature.
(IsAccessor): test VisibleCount, not Count
(AccessorReturnType, AccessorName): deal with the fact that the
accessor parameter might not be the first one.
* generator/CallbackGen.cs:
* generator/Signature.cs: use Parameters.IsHidden.
* generator/Method.cs (Initialize): set is_set based on
VisibleCount, not Count.
(Validate): call base.Validate() before Initialize() so that
VisibleCount will be correct in Initialize.
* generator/MethodBody.cs (GetCallString, CallArrayLength,
Initialize): update to deal with accessors with multiple args.
* gtk/Clipboard.custom (SetText): implement as an Obsolete variant
of the Text property
* gtk/IconTheme.custom (SearchPath, SetSearchPath): obsolete
SetSearchPath, implement a setter on SearchPath instead.
* gtk/ListStore.custom (SetColumnTypes):
* gtk/TreeStore.custom (SetColumnTypes): implement as an Obsolete
variant of the ColumnTypes property.
* glade/XML.custom (CustomHandler): implement as a property
(SetCustomHandler): Mark this obsolete
* glade/Global.custom (SetCustomHandler): deprecate in favor of
XML.CustomHandler.
* gnomedb/Editor.custom (SetText): implement as an Obsolete
variant of the Text property
svn path=/trunk/gtk-sharp/; revision=43898
2005-05-02 20:10:03 +00:00
|
|
|
string string_name = (i == 1 && is_set) ? "value" : parameters [i - 1].Name;
|
2006-01-12 20:24:57 +00:00
|
|
|
result[i] = igen.CallByName (CastFromInt (p.CSType) + "System.Text.Encoding.UTF8.GetByteCount (" + string_name + ")");
|
2003-12-03 23:08:14 +00:00
|
|
|
continue;
|
2003-12-12 22:56:28 +00:00
|
|
|
} else if (p.IsArray && p.MarshalType != p.CSType) {
|
2005-03-08 21:28:08 +00:00
|
|
|
result[i] = "native_" + p.Name;
|
2003-12-12 22:56:28 +00:00
|
|
|
continue;
|
2003-12-03 23:08:14 +00:00
|
|
|
}
|
|
|
|
|
* generator/Parameters.cs (IsHidden): method to check if a
parameter should be hidden in the managed sig (eg, because it's
user_data, or it's the length of the preceding array/string, etc).
(VisibleCount): the number of parameters that will actually be
exposed in the managed signature.
(IsAccessor): test VisibleCount, not Count
(AccessorReturnType, AccessorName): deal with the fact that the
accessor parameter might not be the first one.
* generator/CallbackGen.cs:
* generator/Signature.cs: use Parameters.IsHidden.
* generator/Method.cs (Initialize): set is_set based on
VisibleCount, not Count.
(Validate): call base.Validate() before Initialize() so that
VisibleCount will be correct in Initialize.
* generator/MethodBody.cs (GetCallString, CallArrayLength,
Initialize): update to deal with accessors with multiple args.
* gtk/Clipboard.custom (SetText): implement as an Obsolete variant
of the Text property
* gtk/IconTheme.custom (SearchPath, SetSearchPath): obsolete
SetSearchPath, implement a setter on SearchPath instead.
* gtk/ListStore.custom (SetColumnTypes):
* gtk/TreeStore.custom (SetColumnTypes): implement as an Obsolete
variant of the ColumnTypes property.
* glade/XML.custom (CustomHandler): implement as a property
(SetCustomHandler): Mark this obsolete
* glade/Global.custom (SetCustomHandler): deprecate in favor of
XML.CustomHandler.
* gnomedb/Editor.custom (SetText): implement as an Obsolete
variant of the Text property
svn path=/trunk/gtk-sharp/; revision=43898
2005-05-02 20:10:03 +00:00
|
|
|
string call_parm = p.CallByName (name);
|
2003-12-03 23:08:14 +00:00
|
|
|
|
|
|
|
if (p.CType == "GError**") {
|
|
|
|
result [i] += "out ";
|
|
|
|
} else if (p.PassAs != "") {
|
2005-03-04 18:59:09 +00:00
|
|
|
result [i] += p.PassAs + " ";
|
|
|
|
|
|
|
|
if (p.CSType != p.MarshalType && !(igen is StructBase || igen is ByRefGen))
|
|
|
|
call_parm = p.Name + "_as_native";
|
2005-03-08 21:28:08 +00:00
|
|
|
} else if (igen is IManualMarshaler)
|
|
|
|
call_parm = p.Name + "_as_native";
|
2003-12-03 23:08:14 +00:00
|
|
|
|
|
|
|
if (p.CType == "GError**") {
|
|
|
|
call_parm = call_parm.Replace (p.Name, "error");
|
* parser/gapi2xml.pl (addParamsElem): change the handling of
anonymous function pointer types in method signatures. Before, we
added a <callback> child to the <parameters> node, but the
generator just ignored it. Now we add the callback (with a made-up
name) to the toplevel node, and add an ordinary <param> node
referencing it to the <parameters> node. Also, if the last param
of the callback is a gpointer, rename it from "arg#" to "data" so
it will be treated correctly (as the user data passed from the
calling method). [Fixes #66241]
* art/art-api.raw:
* gdk/gdk-api-2.4.raw:
* gdk/gdk-api-2.6.raw: Regen
* generator/Parameters.cs (IsHidden): loosen the definition of
hideable user_data; it doesn't have to occur at the end of the
parameter list, as long as there's a callback arg before it.
* generator/MethodBody.cs (GetCallString): Use Parameters.IsHidden
to decide whether or not to squash user_data params, rather than
trying to duplicate its logic. As a side effect, this also causes
a handful of methods that take non-hidden IntPtr arguments to
start actually passing those arguments to C rather than always
passing IntPtr.Zero.
* generator/Method.cs (Equals, GetHashCode): Remove unnecessary
and possibly erroneous hashing overrides.
* gtk/Gtk.metadata: Hide Gtk.Container.ForeachFull, since it's
useless and wasn't in gtk# 1.0
* gtk/Menu.custom (Popup):
* gtk/TextIter.custom (ForwardFindChar, BackwardFindChar):
* gnome/App.custom (CreateMenusInterp, InsertMenusInterp,
CreateToolbarInterp):
* gnome/Client.custom (RequestInteractionInterp):
* gnome/Popup.custom (MenuDoPopupModal, MenuDoPopup): Add
[Obsolete] compat overloads for methods that have now lost a
useless IntPtr.
svn path=/trunk/gtk-sharp/; revision=47566
2005-07-22 19:10:04 +00:00
|
|
|
} else if (p.IsUserData && parameters.IsHidden (p) && !parameters.HideData &&
|
|
|
|
(i == 0 || parameters [i - 1].Scope != "notified")) {
|
2003-12-03 23:08:14 +00:00
|
|
|
call_parm = "IntPtr.Zero";
|
|
|
|
}
|
|
|
|
|
|
|
|
result [i] += call_parm;
|
|
|
|
}
|
|
|
|
|
|
|
|
string call_string = String.Join (", ", result);
|
|
|
|
call_string = call_string.Replace ("out ref", "out");
|
2004-04-12 15:54:57 +00:00
|
|
|
call_string = call_string.Replace ("out out ", "out ");
|
2003-12-03 23:08:14 +00:00
|
|
|
call_string = call_string.Replace ("ref ref", "ref");
|
|
|
|
return call_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Initialize (GenerationInfo gen_info, bool is_get, bool is_set, string indent)
|
|
|
|
{
|
2005-01-26 19:17:07 +00:00
|
|
|
if (parameters.Count == 0)
|
2003-12-03 23:08:14 +00:00
|
|
|
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";
|
|
|
|
|
2005-03-04 18:59:09 +00:00
|
|
|
if ((is_get || p.PassAs == "out") && p.CSType != p.MarshalType && !(gen is StructBase || gen is ByRefGen))
|
|
|
|
sw.WriteLine(indent + "\t\t\t" + gen.MarshalType + " " + name + "_as_native;");
|
2005-03-08 21:28:08 +00:00
|
|
|
else if (p.IsArray && p.MarshalType != p.CSType) {
|
2005-04-04 16:27:08 +00:00
|
|
|
sw.WriteLine(indent + "\t\t\tint cnt_" + p.Name + " = {0} == null ? 0 : {0}.Length;", name);
|
* generator/Parameters.cs (IsHidden): method to check if a
parameter should be hidden in the managed sig (eg, because it's
user_data, or it's the length of the preceding array/string, etc).
(VisibleCount): the number of parameters that will actually be
exposed in the managed signature.
(IsAccessor): test VisibleCount, not Count
(AccessorReturnType, AccessorName): deal with the fact that the
accessor parameter might not be the first one.
* generator/CallbackGen.cs:
* generator/Signature.cs: use Parameters.IsHidden.
* generator/Method.cs (Initialize): set is_set based on
VisibleCount, not Count.
(Validate): call base.Validate() before Initialize() so that
VisibleCount will be correct in Initialize.
* generator/MethodBody.cs (GetCallString, CallArrayLength,
Initialize): update to deal with accessors with multiple args.
* gtk/Clipboard.custom (SetText): implement as an Obsolete variant
of the Text property
* gtk/IconTheme.custom (SearchPath, SetSearchPath): obsolete
SetSearchPath, implement a setter on SearchPath instead.
* gtk/ListStore.custom (SetColumnTypes):
* gtk/TreeStore.custom (SetColumnTypes): implement as an Obsolete
variant of the ColumnTypes property.
* glade/XML.custom (CustomHandler): implement as a property
(SetCustomHandler): Mark this obsolete
* glade/Global.custom (SetCustomHandler): deprecate in favor of
XML.CustomHandler.
* gnomedb/Editor.custom (SetText): implement as an Obsolete
variant of the Text property
svn path=/trunk/gtk-sharp/; revision=43898
2005-05-02 20:10:03 +00:00
|
|
|
sw.WriteLine(indent + "\t\t\t{0}[] native_" + p.Name + " = new {0} [cnt_{1}];", p.MarshalType.TrimEnd('[', ']'), p.Name);
|
|
|
|
sw.WriteLine(indent + "\t\t\tfor (int i = 0; i < cnt_{0}; i++)", p.Name);
|
2005-03-08 21:28:08 +00:00
|
|
|
if (gen is IManualMarshaler)
|
|
|
|
sw.WriteLine(indent + "\t\t\t\tnative_{0} [i] = {1};", p.Name, (gen as IManualMarshaler).AllocNative (name + "[i]"));
|
|
|
|
else
|
|
|
|
sw.WriteLine(indent + "\t\t\t\tnative_{0} [i] = {1};", p.Name, p.CallByName (name + "[i]"));
|
|
|
|
} else if (gen is IManualMarshaler)
|
|
|
|
sw.WriteLine(indent + "\t\t\t" + gen.MarshalType + " " + p.Name + "_as_native = " + (gen as IManualMarshaler).AllocNative (name) + ";");
|
|
|
|
|
2003-12-12 22:56:28 +00:00
|
|
|
|
2003-12-03 23:08:14 +00:00
|
|
|
if (gen is CallbackGen) {
|
|
|
|
CallbackGen cbgen = gen as CallbackGen;
|
2005-07-02 14:55:08 +00:00
|
|
|
string wrapper = cbgen.GenWrapper(gen_info);
|
2005-04-04 16:27:08 +00:00
|
|
|
switch (p.Scope) {
|
2005-05-04 11:47:25 +00:00
|
|
|
case "notified":
|
|
|
|
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper;", wrapper, name);
|
|
|
|
sw.WriteLine (indent + "\t\t\tIntPtr {0};", parameters [i + 1].Name);
|
|
|
|
sw.WriteLine (indent + "\t\t\t{0} {1};", parameters [i + 2].CSType, parameters [i + 2].Name);
|
|
|
|
sw.WriteLine (indent + "\t\t\tif ({0} == null) {{", name);
|
|
|
|
sw.WriteLine (indent + "\t\t\t\t{0}_wrapper = null;", name);
|
|
|
|
sw.WriteLine (indent + "\t\t\t\t{0} = IntPtr.Zero;", parameters [i + 1].Name);
|
|
|
|
sw.WriteLine (indent + "\t\t\t\t{0} = null;", parameters [i + 2].Name);
|
|
|
|
sw.WriteLine (indent + "\t\t\t} else {");
|
|
|
|
|
|
|
|
sw.WriteLine (indent + "\t\t\t\t{0}_wrapper = new {1} ({0});", name, wrapper);
|
|
|
|
sw.WriteLine (indent + "\t\t\t\t{0} = (IntPtr) GCHandle.Alloc ({1}_wrapper);", parameters [i + 1].Name, name);
|
2005-05-13 17:34:37 +00:00
|
|
|
sw.WriteLine (indent + "\t\t\t\t{0} = GLib.DestroyHelper.NotifyHandler;", parameters [i + 2].Name, parameters [i + 2].CSType);
|
2005-05-04 11:47:25 +00:00
|
|
|
sw.WriteLine (indent + "\t\t\t}");
|
|
|
|
break;
|
|
|
|
|
2007-01-26 20:46:09 +00:00
|
|
|
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;
|
2005-04-04 16:27:08 +00:00
|
|
|
case "call":
|
|
|
|
default:
|
|
|
|
if (p.Scope == String.Empty)
|
|
|
|
Console.WriteLine ("Defaulting " + gen.Name + " param to 'call' scope in method " + gen_info.CurrentMember);
|
* generator/Parameters.cs (IsHidden): method to check if a
parameter should be hidden in the managed sig (eg, because it's
user_data, or it's the length of the preceding array/string, etc).
(VisibleCount): the number of parameters that will actually be
exposed in the managed signature.
(IsAccessor): test VisibleCount, not Count
(AccessorReturnType, AccessorName): deal with the fact that the
accessor parameter might not be the first one.
* generator/CallbackGen.cs:
* generator/Signature.cs: use Parameters.IsHidden.
* generator/Method.cs (Initialize): set is_set based on
VisibleCount, not Count.
(Validate): call base.Validate() before Initialize() so that
VisibleCount will be correct in Initialize.
* generator/MethodBody.cs (GetCallString, CallArrayLength,
Initialize): update to deal with accessors with multiple args.
* gtk/Clipboard.custom (SetText): implement as an Obsolete variant
of the Text property
* gtk/IconTheme.custom (SearchPath, SetSearchPath): obsolete
SetSearchPath, implement a setter on SearchPath instead.
* gtk/ListStore.custom (SetColumnTypes):
* gtk/TreeStore.custom (SetColumnTypes): implement as an Obsolete
variant of the ColumnTypes property.
* glade/XML.custom (CustomHandler): implement as a property
(SetCustomHandler): Mark this obsolete
* glade/Global.custom (SetCustomHandler): deprecate in favor of
XML.CustomHandler.
* gnomedb/Editor.custom (SetText): implement as an Obsolete
variant of the Text property
svn path=/trunk/gtk-sharp/; revision=43898
2005-05-02 20:10:03 +00:00
|
|
|
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", wrapper, name);
|
2005-04-04 16:27:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-12-03 23:08:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ThrowsException)
|
|
|
|
sw.WriteLine (indent + "\t\t\tIntPtr error = IntPtr.Zero;");
|
|
|
|
}
|
|
|
|
|
2004-01-15 21:18:46 +00:00
|
|
|
public void InitAccessor (StreamWriter sw, Signature sig, string indent)
|
|
|
|
{
|
|
|
|
sw.WriteLine (indent + "\t\t\t" + sig.AccessorType + " " + sig.AccessorName + ";");
|
|
|
|
}
|
|
|
|
|
2003-12-03 23:08:14 +00:00
|
|
|
public void Finish (StreamWriter sw, string indent)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < parameters.Count; i++) {
|
|
|
|
Parameter p = parameters [i];
|
|
|
|
|
2004-12-20 22:08:43 +00:00
|
|
|
IGeneratable gen = p.Generatable;
|
|
|
|
|
2005-03-04 18:59:09 +00:00
|
|
|
if (p.PassAs == "out" && p.CSType != p.MarshalType && !(gen is StructBase || gen is ByRefGen))
|
Automatic memory management for opaque types [#49565]
* glib/Opaque.cs (Owned): new property saying whether or not gtk#
owns the memory.
(Opaque): Set Owned to true in the void ctor and false in the
IntPtr one.
(GetOpaque): add a new overload that can also create opaques, a la
GLib.Object.GetObject.
(Ref, Unref, Free): empty virtual methods to be overridden by
subclasses.
(set_Raw): Unref() and possibly Free() the old value, Ref() the
new one.
(~Opaque, Dispose): set Raw to IntPtr.Zero (triggering Free/Unref
if needed)
* parser/gapi2xml.pl (addReturnElem): if the method is named Copy
and returns a pointer, set the "owned" attribute on the
return-type.
* */*-api.raw: Regen
* generator/HandleBase.cs (FromNative): Add new
FromNative/FromNativeReturn overloads that takes a "bool owned"
param. Implement the 1-arg FromNative and FromNativeReturn in
terms of that.
* generator/ObjectBase.cs (FromNative): Implement HandleBase's new
overload. Use the two-arg version of GLib.Object.GetObject when
"owned" is true.
* generator/OpaqueGen.cs (Generate): Pull out Ref, Unref, and
Free/Destroy/Dispose methods and handle them specially by
overriding Opaque.Ref, .Unref, and .Free appropriately. (If any
of the methods are marked deprecated, output a deprecated
do-nothing method as well, to save us from having to write all
those deprecated methods by hand.)
(FromNative): use GetOpaque, passing "owned".
* generator/ReturnValue.cs (FromNative): if the value is a
HandleBase, pass Owned to its FromNative().
* generator/Parameters.cs (Owned): new property (for use on out
params)
(FromNative): Call FromNative() on the generatable, handling Owned
in the case of HandleBase.
* generator/ManagedCallString.cs:
* generator/MethodBody.cs:
* generator/Signal.cs: use param.FromNative() rather than
param.Generatable.FromNative(), to get ownership right.
* */*.metadata: Mark opaque ref/unref/free methods deprecated
(except where we were hiding them before). Add "owned" attributes
to return values and out params as needed.
* pango/AttrIterator.custom (GetFont): work around a
memory-management oddity of the underlying method.
* pango/AttrFontDesc.cs (AttrFontDesc): copy the passed-in
FontDescriptor, since the attribute will assume ownership of it.
* gtk/TreeView.custom (GetPathAtPos): set the "owned" flag on the
returned TreePaths.
* gtk/TargetList.custom: Remove refcounting stuff, which is
now handled automatically
* gtk/NodeStore.cs (GetPath): clear the Owned flag on the created
TreePath so that the underlying structure doesn't get freed when
the function returns
* gtkhtml/HTMLStream.custom (Destroy): hide this and then
reimplement it by hand to keep OpaqueGen from using it in
Dispose(), since calling it after an HTMLStream.Close() will
result in a crash.
svn path=/trunk/gtk-sharp/; revision=47928
2005-08-02 18:45:21 +00:00
|
|
|
sw.WriteLine(indent + "\t\t\t" + p.Name + " = " + p.FromNative (p.Name + "_as_native") + ";");
|
2005-03-08 21:28:08 +00:00
|
|
|
else if (p.IsArray && gen is IManualMarshaler) {
|
|
|
|
sw.WriteLine(indent + "\t\t\tfor (int i = 0; i < native_" + p.Name + ".Length; i++)");
|
|
|
|
sw.WriteLine(indent + "\t\t\t\t" + (gen as IManualMarshaler).ReleaseNative ("native_" + p.Name + "[i]") + ";");
|
|
|
|
} else if (gen is IManualMarshaler)
|
|
|
|
sw.WriteLine(indent + "\t\t\t" + (gen as IManualMarshaler).ReleaseNative (p.Name + "_as_native") + ";");
|
2003-12-03 23:08:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-15 21:18:46 +00:00
|
|
|
public void FinishAccessor (StreamWriter sw, Signature sig, string indent)
|
|
|
|
{
|
|
|
|
sw.WriteLine (indent + "\t\t\treturn " + sig.AccessorName + ";");
|
|
|
|
}
|
|
|
|
|
2003-12-03 23:08:14 +00:00
|
|
|
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 {
|
2005-01-26 19:17:07 +00:00
|
|
|
if (parameters.Count < 1)
|
2003-12-03 23:08:14 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return parameters [parameters.Count - 1].CType == "GError**";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|