2002-05-23 23:43:25 +00:00
|
|
|
// GtkSharp.Generation.Parameters.cs - The Parameters Generation Class.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
2004-06-25 16:35:15 +00:00
|
|
|
// 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.
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
2003-09-11 06:10:03 +00:00
|
|
|
using System.Collections;
|
2002-06-10 12:34:09 +00:00
|
|
|
using System.IO;
|
2002-05-23 23:43:25 +00:00
|
|
|
using System.Xml;
|
|
|
|
|
2002-07-16 23:14:35 +00:00
|
|
|
public class Parameter {
|
|
|
|
|
|
|
|
private XmlElement elem;
|
|
|
|
|
|
|
|
public Parameter (XmlElement e)
|
|
|
|
{
|
|
|
|
elem = e;
|
|
|
|
}
|
|
|
|
|
2002-08-28 20:58:01 +00:00
|
|
|
public string CType {
|
|
|
|
get {
|
2002-10-11 00:27:46 +00:00
|
|
|
string type = elem.GetAttribute("type");
|
|
|
|
if (type == "void*")
|
|
|
|
type = "gpointer";
|
|
|
|
return type;
|
2002-08-28 20:58:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-16 23:14:35 +00:00
|
|
|
public string CSType {
|
|
|
|
get {
|
2003-05-19 02:45:17 +00:00
|
|
|
string cstype = SymbolTable.Table.GetCSType( elem.GetAttribute("type"));
|
2002-10-11 00:27:46 +00:00
|
|
|
if (cstype == "void")
|
|
|
|
cstype = "System.IntPtr";
|
2003-09-12 06:38:29 +00:00
|
|
|
if (IsArray) {
|
2003-12-03 23:08:14 +00:00
|
|
|
if (IsParams)
|
|
|
|
cstype = "params " + cstype;
|
2002-08-28 20:58:01 +00:00
|
|
|
cstype += "[]";
|
2003-02-24 03:13:08 +00:00
|
|
|
cstype = cstype.Replace ("ref ", "");
|
|
|
|
}
|
2002-08-28 20:58:01 +00:00
|
|
|
return cstype;
|
2002-07-16 23:14:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-14 17:30:32 +00:00
|
|
|
public IGeneratable Generatable {
|
|
|
|
get {
|
|
|
|
return SymbolTable.Table[CType];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-12 06:38:29 +00:00
|
|
|
public bool IsArray {
|
|
|
|
get {
|
|
|
|
return elem.HasAttribute("array");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-11 06:10:03 +00:00
|
|
|
public bool IsEllipsis {
|
|
|
|
get {
|
|
|
|
return elem.HasAttribute("ellipsis");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-17 03:44:32 +00:00
|
|
|
public bool IsCount {
|
|
|
|
get {
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-24 03:13:08 +00:00
|
|
|
public bool IsLength {
|
|
|
|
get {
|
2003-09-11 05:11:18 +00:00
|
|
|
|
|
|
|
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;
|
2003-02-24 03:13:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-03 23:08:14 +00:00
|
|
|
public bool IsParams {
|
|
|
|
get {
|
|
|
|
return elem.HasAttribute("params");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-24 03:13:08 +00:00
|
|
|
public bool IsString {
|
|
|
|
get {
|
|
|
|
return (CSType == "string");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-12 06:38:29 +00:00
|
|
|
public bool IsUserData {
|
|
|
|
get {
|
2003-12-03 23:08:14 +00:00
|
|
|
return CSType == "IntPtr" && (Name.EndsWith ("data") || Name.EndsWith ("data_or_owner"));
|
2003-09-12 06:38:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-04 04:23:13 +00:00
|
|
|
public string MarshalType {
|
|
|
|
get {
|
2003-05-19 02:45:17 +00:00
|
|
|
string type = SymbolTable.Table.GetMarshalType( elem.GetAttribute("type"));
|
2002-10-11 00:27:46 +00:00
|
|
|
if (type == "void")
|
|
|
|
type = "System.IntPtr";
|
2003-09-12 06:38:29 +00:00
|
|
|
if (IsArray) {
|
2003-02-24 03:13:08 +00:00
|
|
|
type += "[]";
|
|
|
|
type = type.Replace ("ref ", "");
|
|
|
|
}
|
2002-10-11 00:27:46 +00:00
|
|
|
return type;
|
2002-08-04 04:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-16 23:14:35 +00:00
|
|
|
public string Name {
|
|
|
|
get {
|
2003-08-28 16:49:29 +00:00
|
|
|
return SymbolTable.Table.MangleName (elem.GetAttribute("name"));
|
2002-07-16 23:14:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-14 17:30:32 +00:00
|
|
|
public bool NullOk {
|
|
|
|
get {
|
|
|
|
return elem.HasAttribute ("null_ok");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-07 13:42:59 +00:00
|
|
|
public string PropertyName {
|
|
|
|
get {
|
|
|
|
return elem.GetAttribute("property_name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-14 17:30:32 +00:00
|
|
|
public string PassAs {
|
|
|
|
get {
|
2003-10-13 21:53:40 +00:00
|
|
|
if (elem.HasAttribute ("pass_as"))
|
|
|
|
return elem.GetAttribute ("pass_as");
|
|
|
|
|
|
|
|
if (IsArray)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
if (Generatable is SimpleGen && !(Generatable is ConstStringGen) && CType.EndsWith ("*") && !CSType.EndsWith ("IntPtr"))
|
|
|
|
return "out";
|
|
|
|
|
2003-10-17 23:06:37 +00:00
|
|
|
if (Generatable is EnumGen && CType.EndsWith ("*"))
|
|
|
|
return "out";
|
|
|
|
|
2003-10-13 21:53:40 +00:00
|
|
|
return "";
|
2003-06-14 17:30:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-03 23:08:14 +00:00
|
|
|
public string CallByName (string call_parm_name)
|
|
|
|
{
|
|
|
|
string call_parm;
|
|
|
|
if (Generatable is CallbackGen)
|
|
|
|
call_parm = SymbolTable.Table.CallByName (CType, call_parm_name + "_wrapper");
|
|
|
|
else
|
|
|
|
call_parm = SymbolTable.Table.CallByName(CType, call_parm_name);
|
|
|
|
|
|
|
|
if (NullOk && !CSType.EndsWith ("IntPtr") && !(Generatable is StructBase))
|
|
|
|
call_parm = String.Format ("({0} != null) ? {1} : {2}", call_parm_name, call_parm, Generatable is CallbackGen ? "null" : "IntPtr.Zero");
|
2004-01-27 19:58:59 +00:00
|
|
|
|
2003-12-03 23:08:14 +00:00
|
|
|
if (IsArray)
|
|
|
|
call_parm = call_parm.Replace ("ref ", "");
|
|
|
|
|
|
|
|
return call_parm;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-07-16 23:14:35 +00:00
|
|
|
public string StudlyName {
|
|
|
|
get {
|
|
|
|
string name = elem.GetAttribute("name");
|
|
|
|
string[] segs = name.Split('_');
|
|
|
|
string studly = "";
|
|
|
|
foreach (string s in segs) {
|
2003-07-15 05:52:09 +00:00
|
|
|
if (s.Trim () == "")
|
|
|
|
continue;
|
2002-07-16 23:14:35 +00:00
|
|
|
studly += (s.Substring(0,1).ToUpper() + s.Substring(1));
|
|
|
|
}
|
|
|
|
return studly;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
public class Parameters {
|
|
|
|
|
2003-09-11 06:10:03 +00:00
|
|
|
private ArrayList param_list;
|
2002-05-23 23:43:25 +00:00
|
|
|
private XmlElement elem;
|
2003-06-14 17:30:32 +00:00
|
|
|
private string impl_ns;
|
2002-08-28 20:58:01 +00:00
|
|
|
private bool hide_data;
|
2003-04-06 09:21:15 +00:00
|
|
|
private bool is_static;
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2003-06-14 17:30:32 +00:00
|
|
|
public Parameters (XmlElement elem, string impl_ns) {
|
2002-05-23 23:43:25 +00:00
|
|
|
|
|
|
|
this.elem = elem;
|
2003-06-14 17:30:32 +00:00
|
|
|
this.impl_ns = impl_ns;
|
2003-09-11 06:10:03 +00:00
|
|
|
param_list = new ArrayList ();
|
|
|
|
foreach (XmlNode node in elem.ChildNodes) {
|
|
|
|
XmlElement parm = node as XmlElement;
|
|
|
|
if (parm != null && parm.Name == "parameter")
|
|
|
|
param_list.Add (new Parameter (parm));
|
|
|
|
}
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
2003-09-11 06:10:03 +00:00
|
|
|
public int Count {
|
|
|
|
get {
|
|
|
|
return param_list.Count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-16 23:14:35 +00:00
|
|
|
public Parameter this [int idx] {
|
|
|
|
get {
|
2003-09-11 06:10:03 +00:00
|
|
|
return param_list [idx] as Parameter;
|
2002-07-16 23:14:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-28 20:58:01 +00:00
|
|
|
public bool HideData {
|
|
|
|
get { return hide_data; }
|
|
|
|
set { hide_data = value; }
|
|
|
|
}
|
|
|
|
|
2003-04-06 09:21:15 +00:00
|
|
|
public bool Static {
|
2003-12-03 23:08:14 +00:00
|
|
|
get { return is_static; }
|
2003-04-06 09:21:15 +00:00
|
|
|
set { is_static = value; }
|
|
|
|
}
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
public bool Validate ()
|
|
|
|
{
|
2003-09-11 06:10:03 +00:00
|
|
|
foreach (Parameter p in param_list) {
|
|
|
|
|
|
|
|
if (p.IsEllipsis) {
|
2002-07-20 14:43:48 +00:00
|
|
|
Console.Write("Ellipsis parameter ");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-02-24 03:13:08 +00:00
|
|
|
if ((p.CSType == "") || (p.Name == "") ||
|
2003-05-19 02:45:17 +00:00
|
|
|
(p.MarshalType == "") || (SymbolTable.Table.CallByName(p.CType, p.Name) == "")) {
|
2003-02-24 03:13:08 +00:00
|
|
|
Console.Write("Name: " + p.Name + " Type: " + p.CType + " ");
|
2002-05-23 23:43:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-06-21 Rachel Hestilow <hestilow@ximian.com>
* generator/ClassBase.cs: New base class for classes and interfaces.
* generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations.
* generator/ObjectGen.cs: Move half of this into ClassBase.
* generator/Method.cs: Turn all applicable Get/Set functions into .NET
accessors. Remove redundant == overload and move into Equals, as
it was confusing "!= null".
* generator/Parameters.cs: Alter signature creation to accept "is_set"
option, add support for variable arguments. Add properties "Count",
"IsVarArgs", "VAType".
* generator/Ctor.cs: Fixup for changes in Parameters (indenting,
signature creation).
* generator/Signal.cs: Support generating declarations.
* generator/SymbolTable: Change GetObjectGen to GetClassGen.
* glib/IWrapper.cs: Move "Handle" declaration to here, so
both classes and interfaces can benefit from it.
* glib/Object.cs: Inherit from IWrapper.cs
* parser/Metadata.pm: Support attribute changes on constructors,
methods, signals, and paramater lists.
* parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_"
functions here.
* parser/gapi_pp.pl: Remove boxed_type_register check, as it will
be caught in the init funcs.
* parser/Atk.metadata: Added.
* parser/Gtk.metadata: Add all needed signal/method collision
renames. Rename GtkEditable.Editable accessors to IsEditable,
as .NET does not like accessors with the same name as their
declaring type. Tag TreeStore constructor as varargs.
* samples/ButtonApp.cs: s/EmitAdd/Add.
* samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated.
svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-06-10 12:34:09 +00:00
|
|
|
public bool IsAccessor {
|
|
|
|
get {
|
2003-09-11 06:10:03 +00:00
|
|
|
return Count == 1 && this [0].PassAs == "out";
|
2002-06-10 12:34:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string AccessorReturnType {
|
|
|
|
get {
|
2003-09-11 06:10:03 +00:00
|
|
|
if (Count > 0)
|
|
|
|
return this [0].CSType;
|
|
|
|
else
|
|
|
|
return null;
|
2002-06-10 12:34:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string AccessorName {
|
|
|
|
get {
|
2003-09-11 06:10:03 +00:00
|
|
|
if (Count > 0)
|
|
|
|
return this [0].Name;
|
|
|
|
else
|
|
|
|
return null;
|
2002-06-10 12:34:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|