2007-07-30 Mike Kestner <mkestner@novell.com>

* generator/MethodBody.cs : refactor finish logic into parameter.
	* generator/Parameters.cs : refactor finish logic into parameter and
	fix some failures to marshal ref params post call.

svn path=/trunk/gtk-sharp/; revision=83020
This commit is contained in:
Mike Kestner 2007-07-30 19:40:49 +00:00
parent 4bbe8a8faf
commit 0f6cac6623
3 changed files with 64 additions and 37 deletions

View file

@ -1,3 +1,9 @@
2007-07-30 Mike Kestner <mkestner@novell.com>
* generator/MethodBody.cs : refactor finish logic into parameter.
* generator/Parameters.cs : refactor finish logic into parameter and
fix some failures to marshal ref params post call.
2007-07-27 Mike Kestner <mkestner@novell.com> 2007-07-27 Mike Kestner <mkestner@novell.com>
* generator/OpaqueGen.cs : only generate Copy override for methods * generator/OpaqueGen.cs : only generate Copy override for methods

View file

@ -94,7 +94,7 @@ namespace GtkSharp.Generation {
name = "value"; name = "value";
p.CallName = name; p.CallName = name;
foreach (string prep in p.CallPreparation) foreach (string prep in p.Prepare)
sw.WriteLine (indent + "\t\t\t" + prep); sw.WriteLine (indent + "\t\t\t" + prep);
if (gen is CallbackGen) { if (gen is CallbackGen) {
@ -143,19 +143,9 @@ namespace GtkSharp.Generation {
public void Finish (StreamWriter sw, string indent) public void Finish (StreamWriter sw, string indent)
{ {
for (int i = 0; i < parameters.Count; i++) { foreach (Parameter p in parameters)
Parameter p = parameters [i]; foreach (string s in p.Finish)
sw.WriteLine(indent + "\t\t\t" + s);
IGeneratable gen = p.Generatable;
if (p.PassAs == "out" && p.CSType != p.MarshalType && !(gen is StructBase || gen is ByRefGen))
sw.WriteLine(indent + "\t\t\t" + p.Name + " = " + p.FromNative (p.Name + "_as_native") + ";");
else if (p.IsArray && gen is IManualMarshaler) {
sw.WriteLine(indent + "\t\t\tfor (int i = 0; i < native_" + p.CallName + ".Length; i++)");
sw.WriteLine(indent + "\t\t\t\t" + (gen as IManualMarshaler).ReleaseNative ("native_" + p.CallName + "[i]") + ";");
} else if (gen is IManualMarshaler)
sw.WriteLine(indent + "\t\t\t" + (gen as IManualMarshaler).ReleaseNative (p.CallName + "_as_native") + ";");
}
} }
public void FinishAccessor (StreamWriter sw, Signature sig, string indent) public void FinishAccessor (StreamWriter sw, Signature sig, string indent)

View file

@ -239,13 +239,16 @@ namespace GtkSharp.Generation {
} }
} }
public virtual string[] CallPreparation { public virtual string[] Prepare {
get { get {
IGeneratable gen = Generatable; IGeneratable gen = Generatable;
if (PassAs == "out" && CSType != MarshalType && !(gen is StructBase || gen is ByRefGen)) if (gen is IManualMarshaler) {
return new string [] { gen.MarshalType + " " + CallName + "_as_native;" }; string result = " IntPtr native_" + CallName;
else if (gen is IManualMarshaler) if (PassAs != "out")
return new string [] { gen.MarshalType + " " + CallName + "_as_native = " + (gen as IManualMarshaler).AllocNative (CallName) + ";" }; result += " = " + (gen as IManualMarshaler).AllocNative (CallName);
return new string [] { result + ";" };
} else if (PassAs == "out" && CSType != MarshalType && !(gen is StructBase || gen is ByRefGen))
return new string [] { gen.MarshalType + " native_" + CallName + ";" };
return new string [0]; return new string [0];
} }
@ -253,30 +256,42 @@ namespace GtkSharp.Generation {
public virtual string CallString { public virtual string CallString {
get { get {
if (IsArray && MarshalType != CSType)
return "native_" + CallName;
string call_parm; string call_parm;
IGeneratable gen = Generatable; IGeneratable gen = Generatable;
if (gen is CallbackGen) if (gen is CallbackGen)
call_parm = SymbolTable.Table.CallByName (CType, CallName + "_wrapper"); return SymbolTable.Table.CallByName (CType, CallName + "_wrapper");
else if (PassAs != String.Empty) { else if (PassAs != String.Empty) {
call_parm = PassAs + " " + CallName; call_parm = PassAs + " ";
if (CSType != MarshalType && !(gen is StructBase || gen is ByRefGen)) if (CSType != MarshalType && !(gen is StructBase || gen is ByRefGen))
call_parm += "_as_native"; call_parm += "native_";
call_parm += CallName;
} else if (gen is IManualMarshaler) } else if (gen is IManualMarshaler)
call_parm = CallName + "_as_native"; call_parm = "native_" + CallName;
else else
call_parm = SymbolTable.Table.CallByName(CType, CallName); call_parm = SymbolTable.Table.CallByName(CType, CallName);
if (IsArray)
call_parm = call_parm.Replace ("ref ", "");
return call_parm; return call_parm;
} }
} }
public virtual string[] Finish {
get {
IGeneratable gen = Generatable;
if (gen is IManualMarshaler) {
string[] result = new string [PassAs == "ref" ? 2 : 1];
int i = 0;
if (PassAs != String.Empty)
result [i++] = CallName + " = " + Generatable.FromNative ("native_" + CallName) + ";";
if (PassAs != "out")
result [i] = (gen as IManualMarshaler).ReleaseNative ("native_" + CallName) + ";";
return result;
} else if (PassAs != String.Empty && MarshalType != CSType && !(gen is StructBase || gen is ByRefGen))
return new string [] { CallName + " = " + gen.FromNative ("native_" + CallName) + ";" };
return new string [0];
}
}
public string FromNative (string var) public string FromNative (string var)
{ {
if (Generatable is HandleBase) if (Generatable is HandleBase)
@ -305,21 +320,21 @@ namespace GtkSharp.Generation {
public ArrayParameter (XmlElement elem) : base (elem) {} public ArrayParameter (XmlElement elem) : base (elem) {}
public override string[] CallPreparation { public override string[] Prepare {
get { get {
if (CSType == MarshalType) if (CSType == MarshalType)
return new string [0]; return new string [0];
string[] result = new string [4]; ArrayList result = new ArrayList ();
result [0] = String.Format ("int cnt_{0} = {0} == null ? 0 : {0}.Length;", CallName); result.Add (String.Format ("int cnt_{0} = {0} == null ? 0 : {0}.Length;", CallName));
result [1] = String.Format ("{0}[] native_{1} = new {0} [cnt_{1}];", MarshalType.TrimEnd('[', ']'), CallName); result.Add (String.Format ("{0}[] native_{1} = new {0} [cnt_{1}];", MarshalType.TrimEnd('[', ']'), CallName));
result [2] = String.Format ("for (int i = 0; i < cnt_{0}; i++)", CallName); result.Add (String.Format ("for (int i = 0; i < cnt_{0}; i++)", CallName));
IGeneratable gen = Generatable; IGeneratable gen = Generatable;
if (gen is IManualMarshaler) if (gen is IManualMarshaler)
result [3] = String.Format ("\tnative_{0} [i] = {1};", CallName, (gen as IManualMarshaler).AllocNative (CallName + "[i]")); result.Add (String.Format ("\tnative_{0} [i] = {1};", CallName, (gen as IManualMarshaler).AllocNative (CallName + "[i]")));
else else
result [3] = String.Format ("\tnative_{0} [i] = {1};", CallName, gen.CallByName (CallName + "[i]")); result.Add (String.Format ("\tnative_{0} [i] = {1};", CallName, gen.CallByName (CallName + "[i]")));
return result; return (string[]) result.ToArray (typeof (string));
} }
} }
@ -331,6 +346,22 @@ namespace GtkSharp.Generation {
return CallName; return CallName;
} }
} }
public override string[] Finish {
get {
IGeneratable gen = Generatable;
if (gen is IManualMarshaler) {
string [] result = new string [4];
result [0] = "for (int i = 0; i < native_" + CallName + ".Length; i++) {";
result [1] = "\t" + CallName + " [i] = " + Generatable.FromNative ("native_" + CallName + "[i]") + ";";
result [2] = "\t" + (gen as IManualMarshaler).ReleaseNative ("native_" + CallName + "[i]") + ";";
result [3] = "}";
return result;
}
return new string [0];
}
}
} }
public class ArrayCountPair : ArrayParameter { public class ArrayCountPair : ArrayParameter {