generator: fixed glue code for callbacks

This commit is contained in:
Stephan Sundermann 2013-07-18 17:05:58 +02:00 committed by Andrés G. Aragoneses
parent ddd2419151
commit 55ab3ab284
2 changed files with 27 additions and 5 deletions

View file

@ -70,6 +70,14 @@ namespace GtkSharp.Generation {
}
}
public string WrapperName {
get {
if (!valid)
return String.Empty;
return NS + "Sharp." + Name + "Wrapper";
}
}
public override string MarshalType {
get {
if (valid)

View file

@ -156,6 +156,7 @@ namespace GtkSharp.Generation {
GenerateImports (gen_info, indent);
SymbolTable table = SymbolTable.Table;
IGeneratable gen = table [CType];
StreamWriter sw = gen_info.Writer;
string modifiers = elem.GetAttributeAsBoolean ("new_flag") ? "new " : "";
bool is_struct = table.IsStruct (CType) || table.IsBoxed (CType);
@ -176,13 +177,19 @@ namespace GtkSharp.Generation {
} else if (Readable && offsetName != null) {
sw.WriteLine (indent + "\tget {");
sw.WriteLine (indent + "\t\tunsafe {");
sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(*raw_ptr)") + ";");
if (gen is CallbackGen) {
sw.WriteLine (indent + "\t\t\tIntPtr* raw_ptr = (IntPtr*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
sw.WriteLine (indent + "\t\t\t {0} del = ({0})Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof({0}));", table.GetMarshalType (CType));
sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(del)") + ";");
}
else {
sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(*raw_ptr)") + ";");
}
sw.WriteLine (indent + "\t\t}");
sw.WriteLine (indent + "\t}");
}
IGeneratable gen = table [CType];
string to_native = (gen is IManualMarshaler) ? (gen as IManualMarshaler).AllocNative ("value") : gen.CallByName ("value");
if (Setter != null) {
@ -198,8 +205,15 @@ namespace GtkSharp.Generation {
} else if (Writable && offsetName != null) {
sw.WriteLine (indent + "\tset {");
sw.WriteLine (indent + "\t\tunsafe {");
sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
sw.WriteLine (indent + "\t\t\t*raw_ptr = " + to_native + ";");
if (gen is CallbackGen) {
sw.WriteLine (indent + "\t\t\t{0} wrapper = new {0} (value);", ((CallbackGen)gen).WrapperName);
sw.WriteLine (indent + "\t\t\tIntPtr* raw_ptr = (IntPtr*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
sw.WriteLine (indent + "\t\t\t*raw_ptr = Marshal.GetFunctionPointerForDelegate (wrapper.NativeDelegate);");
}
else {
sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
sw.WriteLine (indent + "\t\t\t*raw_ptr = " + to_native + ";");
}
sw.WriteLine (indent + "\t\t}");
sw.WriteLine (indent + "\t}");
}