From c2d4c12e67413b6f0de630dc12e93a090fde84dd Mon Sep 17 00:00:00 2001 From: Martin Willemoes Hansen Date: Thu, 15 Jan 2004 21:18:46 +0000 Subject: [PATCH] * generator/Method.cs: Methods which returns void and has a single out parameter like void Foobar (..., out int baz, ...) are turned into the more .NET like signature int Foobar (...), this fixes bug 46392 * generator/Signature.cs: Ditto * generator/MethodBody.cs: Ditto * gtk/ListStore.custom: Ditto * gtk/TextBuffer.custom: Ditto * gtk/TreeStore.custom: Ditto svn path=/trunk/gtk-sharp/; revision=22126 --- ChangeLog | 11 +++++++++ generator/Method.cs | 14 ++++++++++- generator/MethodBody.cs | 10 ++++++++ generator/Signature.cs | 51 +++++++++++++++++++++++++++++++++++++++++ gtk/ListStore.custom | 3 +-- gtk/TextBuffer.custom | 9 -------- gtk/TreeStore.custom | 3 +-- 7 files changed, 87 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 532d6b8c6..a91c6ff14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-01-15 Martin Willemoes Hansen + + * generator/Method.cs: Methods which returns void and has a single out parameter + like void Foobar (..., out int baz, ...) are turned into the more .NET like + signature int Foobar (...), this fixes bug 46392 + * generator/Signature.cs: Ditto + * generator/MethodBody.cs: Ditto + * gtk/ListStore.custom: Ditto + * gtk/TextBuffer.custom: Ditto + * gtk/TreeStore.custom: Ditto + 2004-01-13 Tambet Ingo * gtk-sharp.pc.in : add libdir var diff --git a/generator/Method.cs b/generator/Method.cs index 4efa871f9..6e40ba9ca 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -220,6 +220,8 @@ namespace GtkSharp.Generation { else sw.Write (Name); sw.WriteLine(" { "); + } else if (IsAccessor) { + sw.Write (sig.AccessorType + " " + Name + "(" + sig.AsAccessor + ")"); } else { sw.Write(s_ret + " " + Name + "(" + (sig != null ? sig.ToString() : "") + ")"); } @@ -342,6 +344,8 @@ namespace GtkSharp.Generation { { StreamWriter sw = gen_info.Writer; sw.WriteLine(" {"); + if (IsAccessor) + body.InitAccessor (sw, sig, indent); body.Initialize(gen_info, is_get, is_set, indent); SymbolTable table = SymbolTable.Table; @@ -366,7 +370,7 @@ namespace GtkSharp.Generation { sw.WriteLine(s_ret + " ret = " + table.FromNativeReturn(rettype, raw_parms) + ";"); } } - + body.Finish (sw, indent); body.HandleException (sw, indent); @@ -374,9 +378,17 @@ namespace GtkSharp.Generation { sw.WriteLine (indent + "\t\t\treturn " + parms.AccessorName + ";"); else if (m_ret != "void") sw.WriteLine (indent + "\t\t\treturn ret;"); + else if (IsAccessor) + body.FinishAccessor (sw, sig, indent); sw.Write(indent + "\t\t}"); } + + bool IsAccessor { + get { + return s_ret == "void" && sig.IsAccessor; + } + } } } diff --git a/generator/MethodBody.cs b/generator/MethodBody.cs index 880469188..f71c1a484 100644 --- a/generator/MethodBody.cs +++ b/generator/MethodBody.cs @@ -142,6 +142,11 @@ namespace GtkSharp.Generation { 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) { if (parameters == null) @@ -161,6 +166,11 @@ namespace GtkSharp.Generation { } } + 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) diff --git a/generator/Signature.cs b/generator/Signature.cs index e1e61faa8..dfdc2b8bc 100644 --- a/generator/Signature.cs +++ b/generator/Signature.cs @@ -70,6 +70,57 @@ namespace GtkSharp.Generation { 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); + } + } } } diff --git a/gtk/ListStore.custom b/gtk/ListStore.custom index 98c8cdfe1..00e0157e2 100644 --- a/gtk/ListStore.custom +++ b/gtk/ListStore.custom @@ -61,8 +61,7 @@ } public Gtk.TreeIter AppendValues (Array values) { - Gtk.TreeIter iter; - Append (out iter); + Gtk.TreeIter iter = Append(); int col = 0; foreach (object value in values) { diff --git a/gtk/TextBuffer.custom b/gtk/TextBuffer.custom index c447f4143..b9631afd0 100644 --- a/gtk/TextBuffer.custom +++ b/gtk/TextBuffer.custom @@ -14,15 +14,6 @@ public void Clear () Delete (StartIter, EndIter); } -public Gtk.TextIter GetIterAtOffset(int char_offset) -{ - Gtk.TextIter iter; - - gtk_text_buffer_get_iter_at_offset(Handle, out iter, char_offset); - - return iter; -} - // overload to paste clipboard contents at cursor editable by default. [DllImport("libgtk-win32-2.0-0.dll")] static extern void gtk_text_buffer_paste_clipboard (IntPtr raw, IntPtr clip, IntPtr iter, bool default_edit); diff --git a/gtk/TreeStore.custom b/gtk/TreeStore.custom index 1259e5d84..baab86bd0 100644 --- a/gtk/TreeStore.custom +++ b/gtk/TreeStore.custom @@ -148,8 +148,7 @@ } public Gtk.TreeIter AppendValues (Gtk.TreeIter parent, Array values) { - Gtk.TreeIter iter; - Append (out iter, parent); + Gtk.TreeIter iter = Append (parent); _AppendValues (iter, values); return iter; }