generator: Rework data structures used by ManagedCallString

Use a single dictionary to hold the parameters and mark them as special,
instead of maintaining two lists in parallel.
This commit is contained in:
Bertrand Lorentz 2012-11-04 16:25:00 +01:00
parent 82a957bc9d
commit 15c5820cd8

View file

@ -22,13 +22,12 @@
namespace GtkSharp.Generation { namespace GtkSharp.Generation {
using System; using System;
using System.Collections; using System.Collections.Generic;
using System.IO; using System.IO;
public class ManagedCallString { public class ManagedCallString {
ArrayList parms = new ArrayList (); IDictionary<Parameter, bool> parms = new Dictionary<Parameter, bool> ();
ArrayList special = new ArrayList ();
string error_param = null; string error_param = null;
string user_data_param = null; string user_data_param = null;
string destroy_param = null; string destroy_param = null;
@ -50,20 +49,20 @@ namespace GtkSharp.Generation {
error_param = p.Name; error_param = p.Name;
continue; continue;
} }
this.parms.Add (p);
bool special = false;
if (p.PassAs != String.Empty && (p.Name != p.FromNative (p.Name))) if (p.PassAs != String.Empty && (p.Name != p.FromNative (p.Name)))
this.special.Add (true); special = true;
else if (p.Generatable is CallbackGen) else if (p.Generatable is CallbackGen)
this.special.Add (true); special = true;
else
this.special.Add (false); this.parms.Add (p, special);
} }
} }
public bool HasOutParam { public bool HasOutParam {
get { get {
foreach (Parameter p in parms) { foreach (Parameter p in parms.Keys) {
if (p.PassAs == "out") if (p.PassAs == "out")
return true; return true;
} }
@ -82,11 +81,11 @@ namespace GtkSharp.Generation {
{ {
string ret = ""; string ret = "";
for (int i = 0; i < parms.Count; i ++) { foreach (Parameter p in parms.Keys) {
if ((bool)special[i] == false) if (parms [p] == false) {
continue; continue;
}
Parameter p = parms [i] as Parameter;
IGeneratable igen = p.Generatable; IGeneratable igen = p.Generatable;
if (igen is CallbackGen) { if (igen is CallbackGen) {
@ -114,13 +113,15 @@ namespace GtkSharp.Generation {
string[] result = new string [parms.Count]; string[] result = new string [parms.Count];
for (int i = 0; i < parms.Count; i ++) { int i = 0;
Parameter p = parms [i] as Parameter; foreach (Parameter p in parms.Keys) {
result [i] = p.PassAs == "" ? "" : p.PassAs + " "; result [i] = p.PassAs == "" ? "" : p.PassAs + " ";
if (p.Generatable is CallbackGen) if (p.Generatable is CallbackGen) {
result [i] += p.Name + "_invoker.Handler"; result [i] += p.Name + "_invoker.Handler";
else } else {
result [i] += ((bool)special[i]) ? "my" + p.Name : p.FromNative (p.Name); result [i] += (parms [p]) ? "my" + p.Name : p.FromNative (p.Name);
}
i++;
} }
return String.Join (", ", result); return String.Join (", ", result);
@ -130,11 +131,11 @@ namespace GtkSharp.Generation {
{ {
string ret = ""; string ret = "";
for (int i = 0; i < parms.Count; i ++) { foreach (Parameter p in parms.Keys) {
if ((bool)special[i] == false) if (parms [p] == false) {
continue; continue;
}
Parameter p = parms [i] as Parameter;
IGeneratable igen = p.Generatable; IGeneratable igen = p.Generatable;
if (igen is CallbackGen) if (igen is CallbackGen)