Generate entry point tables

This commit is contained in:
Stefanos A. 2013-11-24 13:54:52 +01:00
parent 8ee2152709
commit 7b93a87bb0

View file

@ -164,7 +164,7 @@ namespace Bind
sw.WriteLine("using System.Text;"); sw.WriteLine("using System.Text;");
sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Runtime.InteropServices;");
WriteWrappers(sw, wrappers, enums, Generator.CSTypes); WriteWrappers(sw, wrappers, delegates, enums, Generator.CSTypes);
sw.Unindent(); sw.Unindent();
sw.WriteLine("}"); sw.WriteLine("}");
@ -295,7 +295,9 @@ namespace Bind
#region WriteWrappers #region WriteWrappers
void WriteWrappers(BindStreamWriter sw, FunctionCollection wrappers, EnumCollection enums, IDictionary<string, string> CSTypes) void WriteWrappers(BindStreamWriter sw, FunctionCollection wrappers,
DelegateCollection delegates, EnumCollection enums,
IDictionary<string, string> CSTypes)
{ {
Trace.WriteLine(String.Format("Writing wrappers to:\t{0}.{1}", Settings.OutputNamespace, Settings.OutputClass)); Trace.WriteLine(String.Format("Writing wrappers to:\t{0}.{1}", Settings.OutputNamespace, Settings.OutputClass));
@ -307,9 +309,22 @@ namespace Bind
sw.WriteLine(); sw.WriteLine();
sw.WriteLine("partial class {0}", Settings.OutputClass); sw.WriteLine("partial class {0}", Settings.OutputClass);
sw.WriteLine("{"); sw.WriteLine("{");
sw.Indent(); sw.Indent();
//sw.WriteLine("static {0}() {1} {2}", className, "{", "}"); // Static init in GLHelper.cs
// Write constructor
sw.WriteLine("static {0}()", Settings.OutputClass);
sw.WriteLine("{");
sw.Indent();
sw.WriteLine("EntryPointNames = new string[]", delegates.Count);
sw.WriteLine("{");
sw.Indent();
foreach (var d in delegates.Values.Select(d => d.First()))
sw.WriteLine("\"{0}{1}\",", Settings.FunctionPrefix, d.Name);
sw.Unindent();
sw.WriteLine("};");
sw.WriteLine("EntryPoints = new IntPtr[EntryPointNames.Length];");
sw.Unindent();
sw.WriteLine("}");
sw.WriteLine(); sw.WriteLine();
int current = 0; int current = 0;
@ -1116,12 +1131,34 @@ namespace Bind
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.Append(Settings.DelegatesClass); if (d.ReturnType.CurrentType == "void")
sb.Append(Settings.NamespaceSeparator); {
sb.Append(Settings.FunctionPrefix); sb.AppendFormat("InteropHelper.Call");
sb.Append(d.Name); }
sb.Append(GetInvocationString(d.Parameters, respect_wrappers)); else
{
sb.Append("InteropHelper.CallReturn<");
sb.Append(d.ReturnType.CurrentType != "String" ? d.ReturnType.CurrentType : "IntPtr");
if (d.Parameters.Count > 0)
{
var parameters = String.Join(
", ",
d.Parameters.Select(p => p.IndirectionLevel != 0 ? "IntPtr" : p.CurrentType).ToArray());
sb.Append(", ");
sb.Append(parameters);
}
sb.Append(">");
}
sb.AppendFormat("(EntryPoints[{0}]", d.Slot);
var parameter_string = GetInvocationString(d.Parameters, respect_wrappers);
if (!String.IsNullOrEmpty(parameter_string))
{
sb.Append(", ");
sb.Append(parameter_string);
}
sb.Append(")");
return sb.ToString(); return sb.ToString();
} }
@ -1129,8 +1166,6 @@ namespace Bind
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.Append("(");
if (parameters.Count > 0) if (parameters.Count > 0)
{ {
foreach (Parameter p in parameters) foreach (Parameter p in parameters)
@ -1147,20 +1182,7 @@ namespace Bind
} }
else if (p.IndirectionLevel != 0) else if (p.IndirectionLevel != 0)
{ {
if (((Settings.Compatibility & Settings.Legacy.TurnVoidPointersToIntPtr) != Settings.Legacy.None) && sb.Append("(IntPtr)");
p.Pointer != 0 && p.CurrentType.Contains("void"))
{
sb.Append("(IntPtr)");
}
else
{
sb.Append("(");
sb.Append(p.QualifiedType);
for (int i = 0; i < p.IndirectionLevel; i++)
sb.Append("*");
sb.Append(")");
}
} }
else else
{ {
@ -1207,11 +1229,7 @@ namespace Bind
sb.Append(", "); sb.Append(", ");
} }
sb.Replace(", ", ")", sb.Length - 2, 2); sb.Replace(", ", "", sb.Length - 2, 2);
}
else
{
sb.Append(")");
} }
return sb.ToString(); return sb.ToString();