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 + ") " : "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public string GetCallString (bool is_set)
|
|
|
|
{
|
2005-01-26 19:17:07 +00:00
|
|
|
if (parameters.Count == 0)
|
2007-07-10 15:25:14 +00:00
|
|
|
return String.Empty;
|
2003-12-03 23:08:14 +00:00
|
|
|
|
|
|
|
string[] result = new string [parameters.Count];
|
|
|
|
for (int i = 0; i < parameters.Count; i++) {
|
|
|
|
Parameter p = parameters [i];
|
|
|
|
IGeneratable igen = p.Generatable;
|
2007-07-10 15:25:14 +00:00
|
|
|
|
|
|
|
bool is_prop = is_set && i == 0;
|
|
|
|
|
2008-03-22 01:30:42 +00:00
|
|
|
if (i > 0 && parameters [i - 1].IsString && p.IsLength && p.PassAs == String.Empty) {
|
* 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;
|
|
|
|
}
|
|
|
|
|
2007-07-10 15:25:14 +00:00
|
|
|
if (is_prop)
|
|
|
|
p.CallName = "value";
|
|
|
|
else
|
|
|
|
p.CallName = p.Name;
|
|
|
|
string call_parm = p.CallString;
|
2003-12-03 23:08:14 +00:00
|
|
|
|
2007-07-10 15:25:14 +00:00
|
|
|
if (p.IsUserData && parameters.IsHidden (p) && !parameters.HideData &&
|
* 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
|
|
|
(i == 0 || parameters [i - 1].Scope != "notified")) {
|
2003-12-03 23:08:14 +00:00
|
|
|
call_parm = "IntPtr.Zero";
|
|
|
|
}
|
|
|
|
|
|
|
|
result [i] += call_parm;
|
|
|
|
}
|
|
|
|
|
2007-08-13 18:18:12 +00:00
|
|
|
return String.Join (", ", result);
|
2003-12-03 23:08:14 +00:00
|
|
|
}
|
|
|
|
|
2007-09-11 20:34:24 +00:00
|
|
|
public void Initialize (GenerationInfo gen_info)
|
|
|
|
{
|
|
|
|
Initialize (gen_info, false, false, String.Empty);
|
|
|
|
}
|
|
|
|
|
2003-12-03 23:08:14 +00:00
|
|
|
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";
|
|
|
|
|
2007-07-10 15:25:14 +00:00
|
|
|
p.CallName = name;
|
2007-07-30 19:40:49 +00:00
|
|
|
foreach (string prep in p.Prepare)
|
2007-07-10 15:25:14 +00:00
|
|
|
sw.WriteLine (indent + "\t\t\t" + prep);
|
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)
|
|
|
|
{
|
2007-07-30 19:40:49 +00:00
|
|
|
foreach (Parameter p in parameters)
|
|
|
|
foreach (string s in p.Finish)
|
|
|
|
sw.WriteLine(indent + "\t\t\t" + s);
|
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 {
|
2007-09-11 20:34:24 +00:00
|
|
|
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;
|
2003-12-03 23:08:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|