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:
parent
6850b343ca
commit
fa32f2ec36
6 changed files with 33 additions and 23 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<string, Property> props = new Dictionary<string, Property> ();
|
||||
private IDictionary<string, ObjectField> fields = new Dictionary<string, ObjectField> ();
|
||||
private IDictionary<string, Method> methods = new Dictionary<string, Method> ();
|
||||
protected IList<string> interfaces = new List<string>();
|
||||
protected IList<string> managed_interfaces = new List<string>();
|
||||
protected IList<Ctor> ctors = new List<Ctor>();
|
||||
|
@ -43,11 +43,17 @@ namespace GtkSharp.Generation {
|
|||
private bool deprecated = false;
|
||||
private bool isabstract = false;
|
||||
|
||||
public Hashtable Methods {
|
||||
public IDictionary<string, Method> Methods {
|
||||
get {
|
||||
return methods;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IDictionary<string, Property> 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)
|
||||
|
|
|
@ -75,12 +75,12 @@ namespace GtkSharp.Generation {
|
|||
|
||||
LogWriter log = new LogWriter (QualifiedName);
|
||||
var invalids = new List<Method> ();
|
||||
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}");
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ namespace GtkSharp.Generation {
|
|||
if (method.Signature.ToString () != "")
|
||||
return null;
|
||||
|
||||
methods.Remove (method.Name);
|
||||
Methods.Remove (method.Name);
|
||||
return method;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace GtkSharp.Generation {
|
|||
|
||||
public abstract class StructBase : ClassBase, IManualMarshaler {
|
||||
|
||||
new IList<StructField> fields = new List<StructField> ();
|
||||
IList<StructField> fields = new List<StructField> ();
|
||||
bool need_read_native = false;
|
||||
|
||||
protected StructBase (XmlElement ns, XmlElement elem) : base (ns, elem)
|
||||
|
|
Loading…
Reference in a new issue