Browse Source

CSharp and CLI backend use same function to convert the calling convention.

pull/234/head
Elias Holzer 11 years ago committed by triton
parent
commit
2736088957
  1. 19
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  2. 31
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  3. 27
      src/Generator/Generators/ExtensionMethods.cs

19
src/Generator/Generators/CLI/CLIHeadersTemplate.cs

@ -716,23 +716,8 @@ namespace CppSharp.Generators.CLI @@ -716,23 +716,8 @@ namespace CppSharp.Generators.CLI
var insideClass = typedef.Namespace is Class;
string callingConvention = null;
switch (function.CallingConvention)
{
case CallingConvention.C:
callingConvention = "Cdecl";
break;
case CallingConvention.StdCall:
callingConvention = "StdCall";
break;
case CallingConvention.ThisCall:
callingConvention = "ThisCall";
break;
case CallingConvention.FastCall:
callingConvention = "FastCall";
break;
}
if (callingConvention != null)
var callingConvention = function.CallingConvention.ToInteropCallConv();
if (callingConvention != System.Runtime.InteropServices.CallingConvention.Winapi)
{
WriteLine("[{0}({1}::{2})] ",
"System::Runtime::InteropServices::UnmanagedFunctionPointer",

31
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -43,25 +43,6 @@ namespace CppSharp.Generators.CSharp @@ -43,25 +43,6 @@ namespace CppSharp.Generators.CSharp
return new string(id.Select(c => char.IsLetterOrDigit(c) ? c : '_').ToArray());
}
public static string ToCSharpCallConv(CallingConvention convention)
{
switch (convention)
{
case CallingConvention.Default:
return "Winapi";
case CallingConvention.C:
return "Cdecl";
case CallingConvention.StdCall:
return "StdCall";
case CallingConvention.ThisCall:
return "ThisCall";
case CallingConvention.FastCall:
return "FastCall";
}
return "Winapi";
}
public const string InstanceIdentifier = "__Instance";
public static string GetAccess(AccessSpecifier accessSpecifier)
@ -1608,7 +1589,7 @@ namespace CppSharp.Generators.CSharp @@ -1608,7 +1589,7 @@ namespace CppSharp.Generators.CSharp
}
WriteLine("[SuppressUnmanagedCodeSecurity]");
WriteLine("[UnmanagedFunctionPointerAttribute(global::System.Runtime.InteropServices.CallingConvention.{0})]",
Helpers.ToCSharpCallConv(method.CallingConvention));
method.CallingConvention.ToInteropCallConv());
CSharpTypePrinterResult retType;
var @params = GatherInternalParams(method, out retType);
@ -2562,8 +2543,8 @@ namespace CppSharp.Generators.CSharp @@ -2562,8 +2543,8 @@ namespace CppSharp.Generators.CSharp
else if (typedef.Type.IsPointerTo(out functionType))
{
PushBlock(CSharpBlockKind.Typedef);
WriteLine("[UnmanagedFunctionPointerAttribute(global::System.Runtime.InteropServices.CallingConvention.{0})]",
Helpers.ToCSharpCallConv(functionType.CallingConvention));
WriteLine("[UnmanagedFunctionPointerAttribute(global::System.Runtime.InteropServices.CallingConvention.{0})]",
functionType.CallingConvention.ToInteropCallConv());
TypePrinter.PushContext(CSharpTypePrinterContextKind.Native);
WriteLine("{0}unsafe {1};",
Helpers.GetAccess(typedef.Access),
@ -2697,9 +2678,9 @@ namespace CppSharp.Generators.CSharp @@ -2697,9 +2678,9 @@ namespace CppSharp.Generators.CSharp
if (Options.GenerateInternalImports)
libName = "__Internal";
Write("[DllImport(\"{0}\", ", libName);
var callConv = Helpers.ToCSharpCallConv(function.CallingConvention);
Write("[DllImport(\"{0}\", ", libName);
var callConv = function.CallingConvention.ToInteropCallConv();
WriteLine("CallingConvention = global::System.Runtime.InteropServices.CallingConvention.{0},",
callConv);

27
src/Generator/Generators/ExtensionMethods.cs

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
using CppSharp.AST;
using Interop = System.Runtime.InteropServices;
namespace CppSharp.Generators
{
public static class ExtensionMethods
{
public static Interop.CallingConvention ToInteropCallConv(this CallingConvention convention)
{
switch (convention)
{
case CallingConvention.Default:
return Interop.CallingConvention.Winapi;
case CallingConvention.C:
return Interop.CallingConvention.Cdecl;
case CallingConvention.StdCall:
return Interop.CallingConvention.StdCall;
case CallingConvention.ThisCall:
return Interop.CallingConvention.ThisCall;
case CallingConvention.FastCall:
return Interop.CallingConvention.FastCall;
}
return Interop.CallingConvention.Winapi;
}
}
}
Loading…
Cancel
Save