From 554450a33ad5c6df1024eaa61e4bb520aae754cb Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Mon, 24 Feb 2003 03:13:08 +0000 Subject: [PATCH] 2003-02-23 Mike Kestner * generator/CallbackGen.cs : suppress len params from string/len pairs. * generator/Parameters.cs : begin the refactoring to use Parameter class. Suppress len params from string/len pairs. */*.custom : remove all overrides of string/len pairs */*.cs : ditto. Thanks to Alp Toker for the foundation patch that this change was built upon. svn path=/trunk/gtk-sharp/; revision=11913 --- ChangeLog | 10 +++ generator/CallbackGen.cs | 5 ++ generator/Parameters.cs | 173 ++++++++++++++++++++------------------- gtk/Clipboard.custom | 6 -- gtk/Entry.custom | 2 +- pango/GlyphString.custom | 20 ----- pango/Layout.custom | 10 --- 7 files changed, 105 insertions(+), 121 deletions(-) delete mode 100644 pango/GlyphString.custom diff --git a/ChangeLog b/ChangeLog index 88b3bdda3..8684de6c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2003-02-23 Mike Kestner + + * generator/CallbackGen.cs : suppress len params from + string/len pairs. + * generator/Parameters.cs : begin the refactoring to use + Parameter class. Suppress len params from string/len pairs. + */*.custom : remove all overrides of string/len pairs + */*.cs : ditto. Thanks to Alp Toker for the foundation + patch that this change was built upon. + 2003-02-22 Mike Kestner * sources/makefile : patch from Charles Krempeaux to add diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index 3d9236fe7..6edb3f69a 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -103,8 +103,13 @@ namespace GtkSharp.Generation { { string parm_name = parms[i].Name; string ctype = parms[i].CType; + + if (i > 0 && parms[i].IsLength && parms[i-1].IsString) + continue; + if ((i == count - 1) && ctype == "gpointer" && (parm_name.EndsWith ("data") || parm_name.EndsWith ("data_or_owner"))) continue; + string cstype = parms[i].CSType; // FIXME: Too much code copy/pasted here. Refactor? ClassBase parm_wrapper = SymbolTable.GetClassGen (ctype); diff --git a/generator/Parameters.cs b/generator/Parameters.cs index 17dc4b276..d6a9e2961 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -33,39 +33,73 @@ namespace GtkSharp.Generation { string cstype = SymbolTable.GetCSType( elem.GetAttribute("type")); if (cstype == "void") cstype = "System.IntPtr"; - if (elem.HasAttribute("array")) + if (elem.HasAttribute("array")) { cstype += "[]"; + cstype = cstype.Replace ("ref ", ""); + } return cstype; } } + public bool IsLength { + get { + return (CSType == "int" && + (Name.EndsWith("len") || Name.EndsWith("length"))); + } + } + + public bool IsString { + get { + return (CSType == "string"); + } + } + public string MarshalType { get { string type = SymbolTable.GetMarshalType( elem.GetAttribute("type")); if (type == "void") type = "System.IntPtr"; + if (elem.HasAttribute("array")) { + type += "[]"; + type = type.Replace ("ref ", ""); + } return type; } } public string Name { get { - string name = elem.GetAttribute("name"); - switch (name) { - case "string": - return "str1ng"; - case "event": - return "evnt"; - case "object": - return "objekt"; - default: - break; - } - - return name; + return MangleName (elem.GetAttribute("name")); } } + private 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"; + default: + break; + } + + return name; + } public string StudlyName { get { string name = elem.GetAttribute("name"); @@ -149,15 +183,11 @@ namespace GtkSharp.Generation { return false; } - string type = p_elem.GetAttribute("type"); - string cs_type = SymbolTable.GetCSType(type); - string m_type = SymbolTable.GetMarshalType(type); - string name = MangleName(p_elem.GetAttribute("name")); - string call_parm = SymbolTable.CallByName(type, name); + Parameter p = new Parameter (p_elem); - if ((cs_type == "") || (name == "") || - (m_type == "") || (call_parm == "")) { - Console.Write("Name: " + name + " Type: " + type + " "); + if ((p.CSType == "") || (p.Name == "") || + (p.MarshalType == "") || (SymbolTable.CallByName(p.CType, p.Name) == "")) { + Console.Write("Name: " + p.Name + " Type: " + p.CType + " "); return false; } } @@ -172,10 +202,9 @@ namespace GtkSharp.Generation { bool has_callback = hide_data; bool last_was_user_data = false; bool has_user_data = false; - string callback_type = ""; int len = 0; - XmlElement last_param = null; + Parameter last_param = null; foreach (XmlNode parm in elem.ChildNodes) { if (parm.Name != "parameter") { continue; @@ -184,51 +213,49 @@ namespace GtkSharp.Generation { if (p_elem.GetAttribute("type") == "gpointer" && (p_elem.GetAttribute("name").EndsWith ("data") || p_elem.GetAttribute("name").EndsWith ("data_or_owner"))) has_user_data = true; len++; - last_param = (XmlElement) parm; + last_param = new Parameter ((XmlElement) parm); } int i = 0; + Parameter prev = null; + foreach (XmlNode parm in elem.ChildNodes) { if (parm.Name != "parameter") { continue; } XmlElement p_elem = (XmlElement) parm; - string type = p_elem.GetAttribute("type"); - string cs_type = SymbolTable.GetCSType(type); - if (cs_type == "void") - cs_type = "System.IntPtr"; - string m_type = SymbolTable.GetMarshalType(type); - if (m_type == "void") - m_type = "System.IntPtr"; - string name = MangleName(p_elem.GetAttribute("name")); - string call_parm, call_parm_name; + Parameter curr = new Parameter (p_elem); - if (SymbolTable.IsCallback (type)) { - has_callback = true; + string type = curr.CType; + string cs_type = curr.CSType; + string m_type = curr.MarshalType; + string name = curr.Name; + + if (prev != null && prev.IsString && curr.IsLength) { + call_string += ", " + prev.Name + ".Length"; + import_sig += ", " + m_type + " " + name; + prev = curr; + i++; + continue; } - + + string call_parm_name = name; if (is_set && i == 0) call_parm_name = "value"; - else - call_parm_name = name; + string call_parm; if (SymbolTable.IsCallback (type)) { + has_callback = true; call_parm = SymbolTable.CallByName (type, call_parm_name + "_wrapper"); - callback_type = type.Replace(".", "Sharp.") + "Wrapper"; } else call_parm = SymbolTable.CallByName(type, call_parm_name); if (p_elem.HasAttribute ("null_ok") && cs_type != "IntPtr" && cs_type != "System.IntPtr" && !SymbolTable.IsStruct (type)) call_parm = String.Format ("({0} != null) ? {1} : {2}", call_parm_name, call_parm, SymbolTable.IsCallback (type) ? "null" : "IntPtr.Zero"); - if (p_elem.HasAttribute("array")) { - cs_type += "[]"; - m_type += "[]"; - cs_type = cs_type.Replace ("ref ", ""); - m_type = m_type.Replace ("ref ", ""); + if (p_elem.HasAttribute("array")) call_parm = call_parm.Replace ("ref ", ""); - } if (IsVarArgs && i == (len - 1) && VAType == "length_param") { cs_type = "params " + cs_type + "[]"; @@ -268,7 +295,7 @@ namespace GtkSharp.Generation { if (IsVarArgs && i == (len - 2) && VAType == "length_param") { - call_string += MangleName(last_param.GetAttribute("name")) + ".Length"; + call_string += last_param.Name + ".Length"; last_was_user_data = false; } else @@ -289,6 +316,7 @@ namespace GtkSharp.Generation { call_string += call_parm; } import_sig += (m_type + " " + name); + prev = curr; i++; } @@ -313,14 +341,15 @@ namespace GtkSharp.Generation { } XmlElement p_elem = (XmlElement) parm; + Parameter p = new Parameter (p_elem); - string c_type = p_elem.GetAttribute ("type"); - string type = SymbolTable.GetCSType(c_type); + string c_type = p.CType; + string type = p.CSType; if (is_set) { name = "value"; } else { - name = MangleName(p_elem.GetAttribute("name")); + name = p.Name; } if (is_get) { @@ -345,14 +374,15 @@ namespace GtkSharp.Generation { } XmlElement p_elem = (XmlElement) parm; + Parameter p = new Parameter (p_elem); - string c_type = p_elem.GetAttribute ("type"); - string type = SymbolTable.GetCSType(c_type); + string c_type = p.CType; + string type = p.CSType; if (is_set) { name = "value"; } else { - name = MangleName(p_elem.GetAttribute("name")); + name = p.Name; } if (SymbolTable.IsCallback (c_type)) { @@ -377,9 +407,10 @@ namespace GtkSharp.Generation { } XmlElement p_elem = (XmlElement) parm; - string c_type = p_elem.GetAttribute ("type"); - string name = MangleName(p_elem.GetAttribute("name")); - string type = SymbolTable.GetCSType(c_type); + Parameter p = new Parameter (p_elem); + string c_type = p.CType; + string name = p.Name; + string type = p.CSType; if (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out" && SymbolTable.IsEnum (c_type)) { sw.WriteLine(indent + "\t\t\t" + name + " = (" + type + ") " + name + "_as_int;"); @@ -476,39 +507,13 @@ namespace GtkSharp.Generation { if (parm.Name != "parameter") continue; XmlElement p_elem = (XmlElement) parm; - return MangleName (p_elem.GetAttribute("name")); + Parameter p = new Parameter (p_elem); + return p.Name; } return null; } } - private 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"; - default: - break; - } - - return name; - } } } diff --git a/gtk/Clipboard.custom b/gtk/Clipboard.custom index afb1162f9..85ef5e058 100644 --- a/gtk/Clipboard.custom +++ b/gtk/Clipboard.custom @@ -51,9 +51,3 @@ return ret; } - public void SetText (string new_text) - { - SetText (new_text, new_text.Length); - } - - diff --git a/gtk/Entry.custom b/gtk/Entry.custom index 65ac28a51..8b61b7df1 100644 --- a/gtk/Entry.custom +++ b/gtk/Entry.custom @@ -8,7 +8,7 @@ public int InsertText (string new_text) { int position = 0; - InsertText (new_text, new_text.Length, ref position); + InsertText (new_text, ref position); return position; } diff --git a/pango/GlyphString.custom b/pango/GlyphString.custom deleted file mode 100644 index 808775df7..000000000 --- a/pango/GlyphString.custom +++ /dev/null @@ -1,20 +0,0 @@ -// -// Pango.GlyphString.custom - Allow customization of values in the GtkAdjustment -// -// This code is inserted after the automatically generated code. -// - -public void GetLogicalWidths (string text, int embedding_level, int logical_widths) -{ - pango_glyph_string_get_logical_widths(ref this, text, text.Length, embedding_level, logical_widths); -} - -public void XToIndex (string text, Pango.Analysis analysis, int x_pos, int index, int trailing) -{ - pango_glyph_string_x_to_index(ref this, text, text.Length, ref analysis, x_pos, index, trailing); -} - -public void IndexToX (string text, Pango.Analysis analysis, int index, bool trailing, int x_pos) -{ - pango_glyph_string_index_to_x(ref this, text, text.Length, ref analysis, index, trailing, x_pos); -} diff --git a/pango/Layout.custom b/pango/Layout.custom index 9ec5b8939..921496749 100644 --- a/pango/Layout.custom +++ b/pango/Layout.custom @@ -15,13 +15,3 @@ public System.Drawing.Size Size { } } -/// SetText Method, overloaded to not having to calculate string length -public void SetText(string text) { - SetText(text, text.Length); -} - -/// SetMarkup Method, overloaded to not having to calculate string length -public void SetMarkup(string markup) { - SetText(markup, markup.Length); -} -