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.
This commit is contained in:
Bertrand Lorentz 2012-11-04 17:26:26 +01:00
parent 6850b343ca
commit fa32f2ec36
6 changed files with 33 additions and 23 deletions

View file

@ -31,10 +31,10 @@ namespace GtkSharp.Generation {
public override void Generate (GenerationInfo gen_info) public override void Generate (GenerationInfo gen_info)
{ {
Method copy = methods["Copy"] as Method; Method copy = GetMethod ("Copy");
Method free = methods["Free"] as Method; Method free = GetMethod ("Free");
methods.Remove ("Copy"); Methods.Remove ("Copy");
methods.Remove ("Free"); Methods.Remove ("Free");
gen_info.CurrentType = QualifiedName; gen_info.CurrentType = QualifiedName;

View file

@ -31,9 +31,9 @@ namespace GtkSharp.Generation {
using System.Xml; using System.Xml;
public abstract class ClassBase : GenBase { public abstract class ClassBase : GenBase {
protected Hashtable props = new Hashtable(); private IDictionary<string, Property> props = new Dictionary<string, Property> ();
protected Hashtable fields = new Hashtable(); private IDictionary<string, ObjectField> fields = new Dictionary<string, ObjectField> ();
protected Hashtable methods = new Hashtable(); private IDictionary<string, Method> methods = new Dictionary<string, Method> ();
protected IList<string> interfaces = new List<string>(); protected IList<string> interfaces = new List<string>();
protected IList<string> managed_interfaces = new List<string>(); protected IList<string> managed_interfaces = new List<string>();
protected IList<Ctor> ctors = new List<Ctor>(); protected IList<Ctor> ctors = new List<Ctor>();
@ -43,11 +43,17 @@ namespace GtkSharp.Generation {
private bool deprecated = false; private bool deprecated = false;
private bool isabstract = false; private bool isabstract = false;
public Hashtable Methods { public IDictionary<string, Method> Methods {
get { get {
return methods; return methods;
} }
} }
public IDictionary<string, Property> Properties {
get {
return props;
}
}
public ClassBase Parent { public ClassBase Parent {
get { get {
@ -267,12 +273,16 @@ namespace GtkSharp.Generation {
public Method GetMethod (string name) public Method GetMethod (string name)
{ {
return (Method) methods[name]; Method m = null;
methods.TryGetValue (name, out m);
return m;
} }
public Property GetProperty (string name) public Property GetProperty (string name)
{ {
return (Property) props[name]; Property prop = null;
props.TryGetValue (name, out prop);
return prop;
} }
public Method GetMethodRecursively (string name) public Method GetMethodRecursively (string name)

View file

@ -75,12 +75,12 @@ namespace GtkSharp.Generation {
LogWriter log = new LogWriter (QualifiedName); LogWriter log = new LogWriter (QualifiedName);
var invalids = new List<Method> (); var invalids = new List<Method> ();
foreach (Method method in methods.Values) { foreach (Method method in Methods.Values) {
if (!method.Validate (log)) if (!method.Validate (log))
invalids.Add (method); invalids.Add (method);
} }
foreach (Method method in invalids) foreach (Method method in invalids)
methods.Remove (method.Name); Methods.Remove (method.Name);
invalids.Clear (); invalids.Clear ();
return true; return true;
@ -118,7 +118,7 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\t\t\tgch.Free ();"); 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\tGLib.Object.OverrideProperty (data, \"" + prop.CName + "\");");
} }
sw.WriteLine ("\t\t}"); sw.WriteLine ("\t\t}");
@ -261,12 +261,12 @@ namespace GtkSharp.Generation {
foreach (Signal sig in sigs.Values) foreach (Signal sig in sigs.Values)
sig.GenEvent (sw, null, "GLib.Object.GetObject (Handle)"); sig.GenEvent (sw, null, "GLib.Object.GetObject (Handle)");
Method temp = methods ["GetType"] as Method; Method temp = GetMethod ("GetType");
if (temp != null) if (temp != null)
methods.Remove ("GetType"); Methods.Remove ("GetType");
GenMethods (gen_info, null, this); GenMethods (gen_info, null, this);
if (temp != null) if (temp != null)
methods ["GetType"] = temp; Methods ["GetType"] = temp;
sw.WriteLine ("#endregion"); sw.WriteLine ("#endregion");
@ -314,7 +314,7 @@ namespace GtkSharp.Generation {
vm_table.Remove (vm.Name); 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 + "\")]"); sw.WriteLine ("\t\t[GLib.Property (\"" + prop.CName + "\")]");
prop.GenerateDecl (sw, "\t\t"); prop.GenerateDecl (sw, "\t\t");
} }
@ -341,13 +341,13 @@ namespace GtkSharp.Generation {
sig.GenEventHandler (gen_info); sig.GenEventHandler (gen_info);
} }
foreach (Method method in methods.Values) { foreach (Method method in Methods.Values) {
if (IgnoreMethod (method, this)) if (IgnoreMethod (method, this))
continue; continue;
method.GenerateDecl (sw); method.GenerateDecl (sw);
} }
foreach (Property prop in props.Values) foreach (Property prop in Properties.Values)
prop.GenerateDecl (sw, "\t\t"); prop.GenerateDecl (sw, "\t\t");
sw.WriteLine ("\t}"); sw.WriteLine ("\t}");

View file

@ -127,7 +127,7 @@ namespace GtkSharp.Generation {
vm = new DefaultSignalHandler (vm_elem, this); vm = new DefaultSignalHandler (vm_elem, this);
else if (is_interface) { else if (is_interface) {
string target_name = vm_elem.HasAttribute ("target_method") ? vm_elem.GetAttribute ("target_method") : vm_elem.GetAttribute ("name"); 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 } else
vm = new GObjectVM (vm_elem, this); vm = new GObjectVM (vm_elem, this);

View file

@ -217,7 +217,7 @@ namespace GtkSharp.Generation {
if (method.Signature.ToString () != "") if (method.Signature.ToString () != "")
return null; return null;
methods.Remove (method.Name); Methods.Remove (method.Name);
return method; return method;
} }

View file

@ -30,7 +30,7 @@ namespace GtkSharp.Generation {
public abstract class StructBase : ClassBase, IManualMarshaler { public abstract class StructBase : ClassBase, IManualMarshaler {
new IList<StructField> fields = new List<StructField> (); IList<StructField> fields = new List<StructField> ();
bool need_read_native = false; bool need_read_native = false;
protected StructBase (XmlElement ns, XmlElement elem) : base (ns, elem) protected StructBase (XmlElement ns, XmlElement elem) : base (ns, elem)