From fa32f2ec3645fc572b4e205f2a87f1317e4f1cc4 Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sun, 4 Nov 2012 17:26:26 +0100 Subject: [PATCH] generator: Refactor the member hashes in ClassBase Switch the hash tables used to store fields, properties and methods to strong-type dictionaries, and make them private. Make the necessary adjustments in the subclasses. --- generator/BoxedGen.cs | 8 ++++---- generator/ClassBase.cs | 24 +++++++++++++++++------- generator/InterfaceGen.cs | 18 +++++++++--------- generator/ObjectBase.cs | 2 +- generator/OpaqueGen.cs | 2 +- generator/StructBase.cs | 2 +- 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/generator/BoxedGen.cs b/generator/BoxedGen.cs index e85cf3f51..ef79b1c5b 100644 --- a/generator/BoxedGen.cs +++ b/generator/BoxedGen.cs @@ -31,10 +31,10 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { - Method copy = methods["Copy"] as Method; - Method free = methods["Free"] as Method; - methods.Remove ("Copy"); - methods.Remove ("Free"); + Method copy = GetMethod ("Copy"); + Method free = GetMethod ("Free"); + Methods.Remove ("Copy"); + Methods.Remove ("Free"); gen_info.CurrentType = QualifiedName; diff --git a/generator/ClassBase.cs b/generator/ClassBase.cs index 4ce6aa86b..8c77764c6 100644 --- a/generator/ClassBase.cs +++ b/generator/ClassBase.cs @@ -31,9 +31,9 @@ namespace GtkSharp.Generation { using System.Xml; public abstract class ClassBase : GenBase { - protected Hashtable props = new Hashtable(); - protected Hashtable fields = new Hashtable(); - protected Hashtable methods = new Hashtable(); + private IDictionary props = new Dictionary (); + private IDictionary fields = new Dictionary (); + private IDictionary methods = new Dictionary (); protected IList interfaces = new List(); protected IList managed_interfaces = new List(); protected IList ctors = new List(); @@ -43,11 +43,17 @@ namespace GtkSharp.Generation { private bool deprecated = false; private bool isabstract = false; - public Hashtable Methods { + public IDictionary Methods { get { return methods; } - } + } + + public IDictionary Properties { + get { + return props; + } + } public ClassBase Parent { get { @@ -267,12 +273,16 @@ namespace GtkSharp.Generation { public Method GetMethod (string name) { - return (Method) methods[name]; + Method m = null; + methods.TryGetValue (name, out m); + return m; } public Property GetProperty (string name) { - return (Property) props[name]; + Property prop = null; + props.TryGetValue (name, out prop); + return prop; } public Method GetMethodRecursively (string name) diff --git a/generator/InterfaceGen.cs b/generator/InterfaceGen.cs index 1f8c27e80..cb6d1acb1 100644 --- a/generator/InterfaceGen.cs +++ b/generator/InterfaceGen.cs @@ -75,12 +75,12 @@ namespace GtkSharp.Generation { LogWriter log = new LogWriter (QualifiedName); var invalids = new List (); - foreach (Method method in methods.Values) { + foreach (Method method in Methods.Values) { if (!method.Validate (log)) invalids.Add (method); } foreach (Method method in invalids) - methods.Remove (method.Name); + Methods.Remove (method.Name); invalids.Clear (); return true; @@ -118,7 +118,7 @@ namespace GtkSharp.Generation { sw.WriteLine ("\t\t\tgch.Free ();"); } - foreach (Property prop in props.Values) { + foreach (Property prop in Properties.Values) { sw.WriteLine ("\t\t\tGLib.Object.OverrideProperty (data, \"" + prop.CName + "\");"); } sw.WriteLine ("\t\t}"); @@ -261,12 +261,12 @@ namespace GtkSharp.Generation { foreach (Signal sig in sigs.Values) sig.GenEvent (sw, null, "GLib.Object.GetObject (Handle)"); - Method temp = methods ["GetType"] as Method; + Method temp = GetMethod ("GetType"); if (temp != null) - methods.Remove ("GetType"); + Methods.Remove ("GetType"); GenMethods (gen_info, null, this); if (temp != null) - methods ["GetType"] = temp; + Methods ["GetType"] = temp; sw.WriteLine ("#endregion"); @@ -314,7 +314,7 @@ namespace GtkSharp.Generation { vm_table.Remove (vm.Name); } } - foreach (Property prop in props.Values) { + foreach (Property prop in Properties.Values) { sw.WriteLine ("\t\t[GLib.Property (\"" + prop.CName + "\")]"); prop.GenerateDecl (sw, "\t\t"); } @@ -341,13 +341,13 @@ namespace GtkSharp.Generation { sig.GenEventHandler (gen_info); } - foreach (Method method in methods.Values) { + foreach (Method method in Methods.Values) { if (IgnoreMethod (method, this)) continue; method.GenerateDecl (sw); } - foreach (Property prop in props.Values) + foreach (Property prop in Properties.Values) prop.GenerateDecl (sw, "\t\t"); sw.WriteLine ("\t}"); diff --git a/generator/ObjectBase.cs b/generator/ObjectBase.cs index e39a3f663..1db78d59b 100644 --- a/generator/ObjectBase.cs +++ b/generator/ObjectBase.cs @@ -127,7 +127,7 @@ namespace GtkSharp.Generation { vm = new DefaultSignalHandler (vm_elem, this); else if (is_interface) { string target_name = vm_elem.HasAttribute ("target_method") ? vm_elem.GetAttribute ("target_method") : vm_elem.GetAttribute ("name"); - vm = new InterfaceVM (vm_elem, methods [target_name] as Method, this); + vm = new InterfaceVM (vm_elem, GetMethod (target_name), this); } else vm = new GObjectVM (vm_elem, this); diff --git a/generator/OpaqueGen.cs b/generator/OpaqueGen.cs index eee007652..5b71ea742 100644 --- a/generator/OpaqueGen.cs +++ b/generator/OpaqueGen.cs @@ -217,7 +217,7 @@ namespace GtkSharp.Generation { if (method.Signature.ToString () != "") return null; - methods.Remove (method.Name); + Methods.Remove (method.Name); return method; } diff --git a/generator/StructBase.cs b/generator/StructBase.cs index a01535a97..63ace754e 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -30,7 +30,7 @@ namespace GtkSharp.Generation { public abstract class StructBase : ClassBase, IManualMarshaler { - new IList fields = new List (); + IList fields = new List (); bool need_read_native = false; protected StructBase (XmlElement ns, XmlElement elem) : base (ns, elem)