Browse Source

Improve generation of C# (#1466)

pull/1467/head
josetr 5 years ago committed by GitHub
parent
commit
eac78c6caf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18604
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs
  2. 356
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs
  3. 18602
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs
  4. 124
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std.cs
  5. 18604
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs
  6. 356
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs
  7. 18602
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs
  8. 140
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std.cs
  9. 18602
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs
  10. 140
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std.cs
  11. 18602
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs
  12. 124
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std.cs
  13. 46
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  14. 127
      src/Generator/Generators/CSharp/CSharpSources.cs
  15. 2
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  16. 7
      src/Generator/Generators/TypePrinter.cs
  17. 8
      src/Generator/Utils/BlockGenerator.cs
  18. 7
      src/Runtime/MarshalUtil.cs

18604
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

356
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs

File diff suppressed because it is too large Load Diff

18602
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

124
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std.cs

@ -8,6 +8,8 @@ using System; @@ -8,6 +8,8 @@ using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Runtime.CompilerServices;
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
using __IntPtr = global::System.IntPtr;
[assembly:InternalsVisibleTo("CppSharp.Parser.CSharp")]
@ -304,13 +306,13 @@ namespace Std @@ -304,13 +306,13 @@ namespace Std
public unsafe partial struct __Internal
{
[FieldOffset(0)]
internal global::System.IntPtr _Myfirst;
internal __IntPtr _Myfirst;
[FieldOffset(4)]
internal global::System.IntPtr _Mylast;
internal __IntPtr _Mylast;
[FieldOffset(8)]
internal global::System.IntPtr _Myend;
internal __IntPtr _Myend;
}
}
}
@ -626,29 +628,39 @@ namespace Std @@ -626,29 +628,39 @@ namespace Std
[StructLayout(LayoutKind.Explicit, Size = 0)]
public unsafe partial struct __Internal
{
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="??0?$allocator@D@std@@QAE@XZ")]
internal static extern global::System.IntPtr ctorc__N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "??0?$allocator@D@std@@QAE@XZ", CallingConvention = __CallingConvention.ThisCall)]
internal static extern __IntPtr ctorc__N_std_S_allocator__C(__IntPtr __instance);
}
}
public unsafe partial class Allocator<_Ty> : IDisposable
{
public global::System.IntPtr __Instance { get; protected set; }
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Ty>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Ty>>();
protected bool __ownsNativeInstance;
internal static global::Std.Allocator<_Ty> __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
internal static Allocator<_Ty> __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new global::Std.Allocator<_Ty>(native.ToPointer(), skipVTables);
return new Allocator<_Ty>(native.ToPointer(), skipVTables);
}
internal static global::Std.Allocator<_Ty> __CreateInstance(global::Std.Allocator.__Internal native, bool skipVTables = false)
internal static Allocator<_Ty> __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
return new global::Std.Allocator<_Ty>(native, skipVTables);
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (Allocator<_Ty>)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static Allocator<_Ty> __CreateInstance(global::Std.Allocator.__Internal native, bool skipVTables = false)
{
return new Allocator<_Ty>(native, skipVTables);
}
private static void* __CopyValue(global::Std.Allocator.__Internal native)
@ -669,7 +681,7 @@ namespace Std @@ -669,7 +681,7 @@ namespace Std
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
__Instance = new __IntPtr(native);
}
public Allocator()
@ -729,7 +741,7 @@ namespace Std @@ -729,7 +741,7 @@ namespace Std
public unsafe partial struct __Internal
{
[FieldOffset(0)]
internal global::System.IntPtr _Myhead;
internal __IntPtr _Myhead;
[FieldOffset(4)]
internal uint _Mysize;
@ -747,34 +759,42 @@ namespace Std @@ -747,34 +759,42 @@ namespace Std
[FieldOffset(0)]
internal global::Std.CompressedPair.__Internalc__N_std_S__Compressed_pair____N_std_S_allocator__C___N_std_S__String_val____N_std_S__Simple_types__C_Vb1 _Mypair;
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ")]
internal static extern global::System.IntPtr ctorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ", CallingConvention = __CallingConvention.ThisCall)]
internal static extern __IntPtr ctorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__IntPtr __instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ")]
internal static extern void dtorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ", CallingConvention = __CallingConvention.ThisCall)]
internal static extern void dtorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__IntPtr __instance);
}
}
public unsafe partial class BasicString<_Elem, _Traits, _Alloc> : IDisposable
{
public global::System.IntPtr __Instance { get; protected set; }
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_Elem, _Traits, _Alloc>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_Elem, _Traits, _Alloc>>();
protected bool __ownsNativeInstance;
internal static global::Std.BasicString<_Elem, _Traits, _Alloc> __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
internal static BasicString<_Elem, _Traits, _Alloc> __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new global::Std.BasicString<_Elem, _Traits, _Alloc>(native.ToPointer(), skipVTables);
return new BasicString<_Elem, _Traits, _Alloc>(native.ToPointer(), skipVTables);
}
internal static global::Std.BasicString<_Elem, _Traits, _Alloc> __CreateInstance(global::Std.BasicString.__Internalc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native, bool skipVTables = false)
internal static BasicString<_Elem, _Traits, _Alloc> __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
return new global::Std.BasicString<_Elem, _Traits, _Alloc>(native, skipVTables);
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (BasicString<_Elem, _Traits, _Alloc>)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static BasicString<_Elem, _Traits, _Alloc> __CreateInstance(global::Std.BasicString.__Internalc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native, bool skipVTables = false)
{
return new BasicString<_Elem, _Traits, _Alloc>(native, skipVTables);
}
private static void* __CopyValue(global::Std.BasicString.__Internalc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native)
@ -795,7 +815,7 @@ namespace Std @@ -795,7 +815,7 @@ namespace Std
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
__Instance = new __IntPtr(native);
}
public BasicString()
@ -867,7 +887,7 @@ namespace Std @@ -867,7 +887,7 @@ namespace Std
internal fixed sbyte _Buf[16];
[FieldOffset(0)]
internal global::System.IntPtr _Ptr;
internal __IntPtr _Ptr;
[FieldOffset(0)]
internal fixed sbyte _Alias[16];
@ -886,20 +906,32 @@ namespace Std @@ -886,20 +906,32 @@ namespace Std
public unsafe partial class CharTraits<_Elem> : IDisposable
{
public global::System.IntPtr __Instance { get; protected set; }
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_Elem>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_Elem>>();
protected bool __ownsNativeInstance;
internal static global::Std.CharTraits<_Elem> __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
internal static CharTraits<_Elem> __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CharTraits<_Elem>(native.ToPointer(), skipVTables);
}
internal static CharTraits<_Elem> __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
return new global::Std.CharTraits<_Elem>(native.ToPointer(), skipVTables);
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (CharTraits<_Elem>)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static global::Std.CharTraits<_Elem> __CreateInstance(global::Std.CharTraits.__Internal native, bool skipVTables = false)
internal static CharTraits<_Elem> __CreateInstance(global::Std.CharTraits.__Internal native, bool skipVTables = false)
{
return new global::Std.CharTraits<_Elem>(native, skipVTables);
return new CharTraits<_Elem>(native, skipVTables);
}
private static void* __CopyValue(global::Std.CharTraits.__Internal native)
@ -920,7 +952,7 @@ namespace Std @@ -920,7 +952,7 @@ namespace Std
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
__Instance = new __IntPtr(native);
}
public void Dispose()
@ -945,32 +977,24 @@ namespace Std @@ -945,32 +977,24 @@ namespace Std
[StructLayout(LayoutKind.Explicit, Size = 0)]
public partial struct __Internal
{
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@QBD@Z")]
internal static extern global::System.IntPtr Assign(global::System.IntPtr __instance, [MarshalAs(UnmanagedType.LPUTF8Str)] string _Ptr);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@QBD@Z", CallingConvention = __CallingConvention.ThisCall)]
internal static extern __IntPtr Assign(__IntPtr __instance, [MarshalAs(UnmanagedType.LPUTF8Str)] string _Ptr);
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ")]
internal static extern global::System.IntPtr Data(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ", CallingConvention = __CallingConvention.ThisCall)]
internal static extern __IntPtr Data(__IntPtr __instance);
}
public static global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> Assign(this global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> @this, string _Ptr)
{
var __arg0 = ReferenceEquals(@this, null) ? global::System.IntPtr.Zero : @this.__Instance;
var __arg0 = @this is null ? __IntPtr.Zero : @this.__Instance;
var __ret = __Internal.Assign(__arg0, _Ptr);
global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> __result0;
if (__ret == IntPtr.Zero) __result0 = null;
else if (global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.NativeToManagedMap.ContainsKey(__ret))
__result0 = (global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>) global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.NativeToManagedMap[__ret];
else __result0 = global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.__CreateInstance(__ret);
var __result0 = global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.__GetOrCreateInstance(__ret, false);
return __result0;
}
public static string Data(this global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> @this)
{
var __arg0 = ReferenceEquals(@this, null) ? global::System.IntPtr.Zero : @this.__Instance;
var __arg0 = @this is null ? __IntPtr.Zero : @this.__Instance;
var __ret = __Internal.Data(__arg0);
return CppSharp.Runtime.MarshalUtil.GetString(global::System.Text.Encoding.UTF8, __ret);
}

18604
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

356
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs

File diff suppressed because it is too large Load Diff

18602
src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

140
src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std.cs

@ -8,6 +8,8 @@ using System; @@ -8,6 +8,8 @@ using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Runtime.CompilerServices;
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
using __IntPtr = global::System.IntPtr;
[assembly:InternalsVisibleTo("CppSharp.Parser.CSharp")]
@ -20,34 +22,42 @@ namespace Std @@ -20,34 +22,42 @@ namespace Std
[StructLayout(LayoutKind.Explicit, Size = 0)]
public unsafe partial struct __Internal
{
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZNSaIcEC2Ev")]
internal static extern void ctorc__N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "_ZNSaIcEC2Ev", CallingConvention = __CallingConvention.Cdecl)]
internal static extern void ctorc__N_std_S_allocator__C(__IntPtr __instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZNSaIcED2Ev")]
internal static extern void dtorc__N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "_ZNSaIcED2Ev", CallingConvention = __CallingConvention.Cdecl)]
internal static extern void dtorc__N_std_S_allocator__C(__IntPtr __instance);
}
}
public unsafe partial class Allocator<_Tp> : IDisposable
{
public global::System.IntPtr __Instance { get; protected set; }
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>>();
protected bool __ownsNativeInstance;
internal static global::Std.Allocator<_Tp> __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
internal static Allocator<_Tp> __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new global::Std.Allocator<_Tp>(native.ToPointer(), skipVTables);
return new Allocator<_Tp>(native.ToPointer(), skipVTables);
}
internal static global::Std.Allocator<_Tp> __CreateInstance(global::Std.Allocator.__Internal native, bool skipVTables = false)
internal static Allocator<_Tp> __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
return new global::Std.Allocator<_Tp>(native, skipVTables);
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (Allocator<_Tp>)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static Allocator<_Tp> __CreateInstance(global::Std.Allocator.__Internal native, bool skipVTables = false)
{
return new Allocator<_Tp>(native, skipVTables);
}
private static void* __CopyValue(global::Std.Allocator.__Internal native)
@ -68,7 +78,7 @@ namespace Std @@ -68,7 +78,7 @@ namespace Std
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
__Instance = new __IntPtr(native);
}
public Allocator()
@ -686,13 +696,13 @@ namespace Std @@ -686,13 +696,13 @@ namespace Std
public unsafe partial struct __Internal
{
[FieldOffset(0)]
internal global::System.IntPtr _M_start;
internal __IntPtr _M_start;
[FieldOffset(8)]
internal global::System.IntPtr _M_finish;
internal __IntPtr _M_finish;
[FieldOffset(16)]
internal global::System.IntPtr _M_end_of_storage;
internal __IntPtr _M_end_of_storage;
}
}
@ -703,13 +713,13 @@ namespace Std @@ -703,13 +713,13 @@ namespace Std
public unsafe partial struct __Internal
{
[FieldOffset(0)]
internal global::System.IntPtr _M_start;
internal __IntPtr _M_start;
[FieldOffset(8)]
internal global::System.IntPtr _M_finish;
internal __IntPtr _M_finish;
[FieldOffset(16)]
internal global::System.IntPtr _M_end_of_storage;
internal __IntPtr _M_end_of_storage;
}
}
@ -768,13 +778,13 @@ namespace Std @@ -768,13 +778,13 @@ namespace Std
internal global::Std.RbTreeColor _M_color;
[FieldOffset(8)]
internal global::System.IntPtr _M_parent;
internal __IntPtr _M_parent;
[FieldOffset(16)]
internal global::System.IntPtr _M_left;
internal __IntPtr _M_left;
[FieldOffset(24)]
internal global::System.IntPtr _M_right;
internal __IntPtr _M_right;
}
}
}
@ -812,20 +822,32 @@ namespace Std @@ -812,20 +822,32 @@ namespace Std
public unsafe partial class CharTraits<_CharT> : IDisposable
{
public global::System.IntPtr __Instance { get; protected set; }
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>>();
protected bool __ownsNativeInstance;
internal static global::Std.CharTraits<_CharT> __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
internal static CharTraits<_CharT> __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new global::Std.CharTraits<_CharT>(native.ToPointer(), skipVTables);
return new CharTraits<_CharT>(native.ToPointer(), skipVTables);
}
internal static global::Std.CharTraits<_CharT> __CreateInstance(global::Std.CharTraits.__Internal native, bool skipVTables = false)
internal static CharTraits<_CharT> __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
return new global::Std.CharTraits<_CharT>(native, skipVTables);
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (CharTraits<_CharT>)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static CharTraits<_CharT> __CreateInstance(global::Std.CharTraits.__Internal native, bool skipVTables = false)
{
return new CharTraits<_CharT>(native, skipVTables);
}
private static void* __CopyValue(global::Std.CharTraits.__Internal native)
@ -846,7 +868,7 @@ namespace Std @@ -846,7 +868,7 @@ namespace Std
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
__Instance = new __IntPtr(native);
}
public void Dispose()
@ -886,15 +908,11 @@ namespace Std @@ -886,15 +908,11 @@ namespace Std
[FieldOffset(16)]
internal ulong _M_allocated_capacity;
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2Ev")]
internal static extern void ctorc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2Ev", CallingConvention = __CallingConvention.Cdecl)]
internal static extern void ctorc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__IntPtr __instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev")]
internal static extern void dtorc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev", CallingConvention = __CallingConvention.Cdecl)]
internal static extern void dtorc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__IntPtr __instance);
}
namespace AllocHider
@ -903,7 +921,7 @@ namespace Std @@ -903,7 +921,7 @@ namespace Std
public unsafe partial struct __Internal
{
[FieldOffset(0)]
internal global::System.IntPtr _M_p;
internal __IntPtr _M_p;
}
}
@ -925,20 +943,32 @@ namespace Std @@ -925,20 +943,32 @@ namespace Std
public unsafe partial class BasicString<_CharT, _Traits, _Alloc> : IDisposable
{
public global::System.IntPtr __Instance { get; protected set; }
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Alloc>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Alloc>>();
protected bool __ownsNativeInstance;
internal static global::Std.BasicString<_CharT, _Traits, _Alloc> __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
internal static BasicString<_CharT, _Traits, _Alloc> __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new BasicString<_CharT, _Traits, _Alloc>(native.ToPointer(), skipVTables);
}
internal static BasicString<_CharT, _Traits, _Alloc> __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
return new global::Std.BasicString<_CharT, _Traits, _Alloc>(native.ToPointer(), skipVTables);
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (BasicString<_CharT, _Traits, _Alloc>)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static global::Std.BasicString<_CharT, _Traits, _Alloc> __CreateInstance(global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native, bool skipVTables = false)
internal static BasicString<_CharT, _Traits, _Alloc> __CreateInstance(global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native, bool skipVTables = false)
{
return new global::Std.BasicString<_CharT, _Traits, _Alloc>(native, skipVTables);
return new BasicString<_CharT, _Traits, _Alloc>(native, skipVTables);
}
private static void* __CopyValue(global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native)
@ -959,7 +989,7 @@ namespace Std @@ -959,7 +989,7 @@ namespace Std
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
__Instance = new __IntPtr(native);
}
public BasicString()
@ -1012,32 +1042,24 @@ namespace Std @@ -1012,32 +1042,24 @@ namespace Std
[StructLayout(LayoutKind.Explicit, Size = 0)]
public partial struct __Internal
{
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6assignEPKc")]
internal static extern global::System.IntPtr Assign(global::System.IntPtr __instance, [MarshalAs(UnmanagedType.LPUTF8Str)] string __s);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6assignEPKc", CallingConvention = __CallingConvention.Cdecl)]
internal static extern __IntPtr Assign(__IntPtr __instance, [MarshalAs(UnmanagedType.LPUTF8Str)] string __s);
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4dataEv")]
internal static extern global::System.IntPtr Data(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4dataEv", CallingConvention = __CallingConvention.Cdecl)]
internal static extern __IntPtr Data(__IntPtr __instance);
}
public static global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> Assign(this global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> @this, string __s)
{
var __arg0 = ReferenceEquals(@this, null) ? global::System.IntPtr.Zero : @this.__Instance;
var __arg0 = @this is null ? __IntPtr.Zero : @this.__Instance;
var __ret = __Internal.Assign(__arg0, __s);
global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> __result0;
if (__ret == IntPtr.Zero) __result0 = null;
else if (global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.NativeToManagedMap.ContainsKey(__ret))
__result0 = (global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>) global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.NativeToManagedMap[__ret];
else __result0 = global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.__CreateInstance(__ret);
var __result0 = global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.__GetOrCreateInstance(__ret, false);
return __result0;
}
public static string Data(this global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> @this)
{
var __arg0 = ReferenceEquals(@this, null) ? global::System.IntPtr.Zero : @this.__Instance;
var __arg0 = @this is null ? __IntPtr.Zero : @this.__Instance;
var __ret = __Internal.Data(__arg0);
return CppSharp.Runtime.MarshalUtil.GetString(global::System.Text.Encoding.UTF8, __ret);
}

18602
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

140
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std.cs

@ -8,6 +8,8 @@ using System; @@ -8,6 +8,8 @@ using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Runtime.CompilerServices;
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
using __IntPtr = global::System.IntPtr;
[assembly:InternalsVisibleTo("CppSharp.Parser.CSharp")]
@ -20,34 +22,42 @@ namespace Std @@ -20,34 +22,42 @@ namespace Std
[StructLayout(LayoutKind.Explicit, Size = 0)]
public unsafe partial struct __Internal
{
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZNSaIcEC2Ev")]
internal static extern void ctorc__N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "_ZNSaIcEC2Ev", CallingConvention = __CallingConvention.Cdecl)]
internal static extern void ctorc__N_std_S_allocator__C(__IntPtr __instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZNSaIcED2Ev")]
internal static extern void dtorc__N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "_ZNSaIcED2Ev", CallingConvention = __CallingConvention.Cdecl)]
internal static extern void dtorc__N_std_S_allocator__C(__IntPtr __instance);
}
}
public unsafe partial class Allocator<_Tp> : IDisposable
{
public global::System.IntPtr __Instance { get; protected set; }
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>>();
protected bool __ownsNativeInstance;
internal static global::Std.Allocator<_Tp> __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
internal static Allocator<_Tp> __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new global::Std.Allocator<_Tp>(native.ToPointer(), skipVTables);
return new Allocator<_Tp>(native.ToPointer(), skipVTables);
}
internal static global::Std.Allocator<_Tp> __CreateInstance(global::Std.Allocator.__Internal native, bool skipVTables = false)
internal static Allocator<_Tp> __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
return new global::Std.Allocator<_Tp>(native, skipVTables);
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (Allocator<_Tp>)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static Allocator<_Tp> __CreateInstance(global::Std.Allocator.__Internal native, bool skipVTables = false)
{
return new Allocator<_Tp>(native, skipVTables);
}
private static void* __CopyValue(global::Std.Allocator.__Internal native)
@ -68,7 +78,7 @@ namespace Std @@ -68,7 +78,7 @@ namespace Std
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
__Instance = new __IntPtr(native);
}
public Allocator()
@ -686,13 +696,13 @@ namespace Std @@ -686,13 +696,13 @@ namespace Std
public unsafe partial struct __Internal
{
[FieldOffset(0)]
internal global::System.IntPtr _M_start;
internal __IntPtr _M_start;
[FieldOffset(8)]
internal global::System.IntPtr _M_finish;
internal __IntPtr _M_finish;
[FieldOffset(16)]
internal global::System.IntPtr _M_end_of_storage;
internal __IntPtr _M_end_of_storage;
}
}
@ -703,13 +713,13 @@ namespace Std @@ -703,13 +713,13 @@ namespace Std
public unsafe partial struct __Internal
{
[FieldOffset(0)]
internal global::System.IntPtr _M_start;
internal __IntPtr _M_start;
[FieldOffset(8)]
internal global::System.IntPtr _M_finish;
internal __IntPtr _M_finish;
[FieldOffset(16)]
internal global::System.IntPtr _M_end_of_storage;
internal __IntPtr _M_end_of_storage;
}
}
@ -768,13 +778,13 @@ namespace Std @@ -768,13 +778,13 @@ namespace Std
internal global::Std.RbTreeColor _M_color;
[FieldOffset(8)]
internal global::System.IntPtr _M_parent;
internal __IntPtr _M_parent;
[FieldOffset(16)]
internal global::System.IntPtr _M_left;
internal __IntPtr _M_left;
[FieldOffset(24)]
internal global::System.IntPtr _M_right;
internal __IntPtr _M_right;
}
}
}
@ -812,20 +822,32 @@ namespace Std @@ -812,20 +822,32 @@ namespace Std
public unsafe partial class CharTraits<_CharT> : IDisposable
{
public global::System.IntPtr __Instance { get; protected set; }
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>>();
protected bool __ownsNativeInstance;
internal static global::Std.CharTraits<_CharT> __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
internal static CharTraits<_CharT> __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new global::Std.CharTraits<_CharT>(native.ToPointer(), skipVTables);
return new CharTraits<_CharT>(native.ToPointer(), skipVTables);
}
internal static global::Std.CharTraits<_CharT> __CreateInstance(global::Std.CharTraits.__Internal native, bool skipVTables = false)
internal static CharTraits<_CharT> __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
return new global::Std.CharTraits<_CharT>(native, skipVTables);
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (CharTraits<_CharT>)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static CharTraits<_CharT> __CreateInstance(global::Std.CharTraits.__Internal native, bool skipVTables = false)
{
return new CharTraits<_CharT>(native, skipVTables);
}
private static void* __CopyValue(global::Std.CharTraits.__Internal native)
@ -846,7 +868,7 @@ namespace Std @@ -846,7 +868,7 @@ namespace Std
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
__Instance = new __IntPtr(native);
}
public void Dispose()
@ -877,15 +899,11 @@ namespace Std @@ -877,15 +899,11 @@ namespace Std
[FieldOffset(0)]
internal global::Std.BasicString.AllocHider.__Internal _M_dataplus;
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZNSsC2Ev")]
internal static extern void ctorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "_ZNSsC2Ev", CallingConvention = __CallingConvention.Cdecl)]
internal static extern void ctorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__IntPtr __instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZNSsD2Ev")]
internal static extern void dtorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "_ZNSsD2Ev", CallingConvention = __CallingConvention.Cdecl)]
internal static extern void dtorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__IntPtr __instance);
}
namespace AllocHider
@ -894,7 +912,7 @@ namespace Std @@ -894,7 +912,7 @@ namespace Std
public unsafe partial struct __Internal
{
[FieldOffset(0)]
internal global::System.IntPtr _M_p;
internal __IntPtr _M_p;
}
}
@ -902,20 +920,32 @@ namespace Std @@ -902,20 +920,32 @@ namespace Std
public unsafe partial class BasicString<_CharT, _Traits, _Alloc> : IDisposable
{
public global::System.IntPtr __Instance { get; protected set; }
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Alloc>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Alloc>>();
protected bool __ownsNativeInstance;
internal static global::Std.BasicString<_CharT, _Traits, _Alloc> __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
internal static BasicString<_CharT, _Traits, _Alloc> __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new BasicString<_CharT, _Traits, _Alloc>(native.ToPointer(), skipVTables);
}
internal static BasicString<_CharT, _Traits, _Alloc> __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
return new global::Std.BasicString<_CharT, _Traits, _Alloc>(native.ToPointer(), skipVTables);
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (BasicString<_CharT, _Traits, _Alloc>)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static global::Std.BasicString<_CharT, _Traits, _Alloc> __CreateInstance(global::Std.BasicString.__Internalc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native, bool skipVTables = false)
internal static BasicString<_CharT, _Traits, _Alloc> __CreateInstance(global::Std.BasicString.__Internalc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native, bool skipVTables = false)
{
return new global::Std.BasicString<_CharT, _Traits, _Alloc>(native, skipVTables);
return new BasicString<_CharT, _Traits, _Alloc>(native, skipVTables);
}
private static void* __CopyValue(global::Std.BasicString.__Internalc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native)
@ -936,7 +966,7 @@ namespace Std @@ -936,7 +966,7 @@ namespace Std
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
__Instance = new __IntPtr(native);
}
public BasicString()
@ -989,32 +1019,24 @@ namespace Std @@ -989,32 +1019,24 @@ namespace Std
[StructLayout(LayoutKind.Explicit, Size = 0)]
public partial struct __Internal
{
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZNSs6assignEPKc")]
internal static extern global::System.IntPtr Assign(global::System.IntPtr __instance, [MarshalAs(UnmanagedType.LPUTF8Str)] string __s);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "_ZNSs6assignEPKc", CallingConvention = __CallingConvention.Cdecl)]
internal static extern __IntPtr Assign(__IntPtr __instance, [MarshalAs(UnmanagedType.LPUTF8Str)] string __s);
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZNKSs4dataEv")]
internal static extern global::System.IntPtr Data(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "_ZNKSs4dataEv", CallingConvention = __CallingConvention.Cdecl)]
internal static extern __IntPtr Data(__IntPtr __instance);
}
public static global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> Assign(this global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> @this, string __s)
{
var __arg0 = ReferenceEquals(@this, null) ? global::System.IntPtr.Zero : @this.__Instance;
var __arg0 = @this is null ? __IntPtr.Zero : @this.__Instance;
var __ret = __Internal.Assign(__arg0, __s);
global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> __result0;
if (__ret == IntPtr.Zero) __result0 = null;
else if (global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.NativeToManagedMap.ContainsKey(__ret))
__result0 = (global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>) global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.NativeToManagedMap[__ret];
else __result0 = global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.__CreateInstance(__ret);
var __result0 = global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.__GetOrCreateInstance(__ret, false);
return __result0;
}
public static string Data(this global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> @this)
{
var __arg0 = ReferenceEquals(@this, null) ? global::System.IntPtr.Zero : @this.__Instance;
var __arg0 = @this is null ? __IntPtr.Zero : @this.__Instance;
var __ret = __Internal.Data(__arg0);
return CppSharp.Runtime.MarshalUtil.GetString(global::System.Text.Encoding.UTF8, __ret);
}

18602
src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

124
src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std.cs

@ -8,6 +8,8 @@ using System; @@ -8,6 +8,8 @@ using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Runtime.CompilerServices;
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
using __IntPtr = global::System.IntPtr;
[assembly:InternalsVisibleTo("CppSharp.Parser.CSharp")]
@ -304,13 +306,13 @@ namespace Std @@ -304,13 +306,13 @@ namespace Std
public unsafe partial struct __Internal
{
[FieldOffset(0)]
internal global::System.IntPtr _Myfirst;
internal __IntPtr _Myfirst;
[FieldOffset(8)]
internal global::System.IntPtr _Mylast;
internal __IntPtr _Mylast;
[FieldOffset(16)]
internal global::System.IntPtr _Myend;
internal __IntPtr _Myend;
}
}
}
@ -626,29 +628,39 @@ namespace Std @@ -626,29 +628,39 @@ namespace Std
[StructLayout(LayoutKind.Explicit, Size = 0)]
public unsafe partial struct __Internal
{
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="??0?$allocator@D@std@@QEAA@XZ")]
internal static extern global::System.IntPtr ctorc__N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "??0?$allocator@D@std@@QEAA@XZ", CallingConvention = __CallingConvention.Cdecl)]
internal static extern __IntPtr ctorc__N_std_S_allocator__C(__IntPtr __instance);
}
}
public unsafe partial class Allocator<_Ty> : IDisposable
{
public global::System.IntPtr __Instance { get; protected set; }
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Ty>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Ty>>();
protected bool __ownsNativeInstance;
internal static global::Std.Allocator<_Ty> __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
internal static Allocator<_Ty> __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new global::Std.Allocator<_Ty>(native.ToPointer(), skipVTables);
return new Allocator<_Ty>(native.ToPointer(), skipVTables);
}
internal static global::Std.Allocator<_Ty> __CreateInstance(global::Std.Allocator.__Internal native, bool skipVTables = false)
internal static Allocator<_Ty> __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
return new global::Std.Allocator<_Ty>(native, skipVTables);
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (Allocator<_Ty>)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static Allocator<_Ty> __CreateInstance(global::Std.Allocator.__Internal native, bool skipVTables = false)
{
return new Allocator<_Ty>(native, skipVTables);
}
private static void* __CopyValue(global::Std.Allocator.__Internal native)
@ -669,7 +681,7 @@ namespace Std @@ -669,7 +681,7 @@ namespace Std
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
__Instance = new __IntPtr(native);
}
public Allocator()
@ -729,7 +741,7 @@ namespace Std @@ -729,7 +741,7 @@ namespace Std
public unsafe partial struct __Internal
{
[FieldOffset(0)]
internal global::System.IntPtr _Myhead;
internal __IntPtr _Myhead;
[FieldOffset(8)]
internal ulong _Mysize;
@ -747,34 +759,42 @@ namespace Std @@ -747,34 +759,42 @@ namespace Std
[FieldOffset(0)]
internal global::Std.CompressedPair.__Internalc__N_std_S__Compressed_pair____N_std_S_allocator__C___N_std_S__String_val____N_std_S__Simple_types__C_Vb1 _Mypair;
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ")]
internal static extern global::System.IntPtr ctorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ", CallingConvention = __CallingConvention.Cdecl)]
internal static extern __IntPtr ctorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__IntPtr __instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ")]
internal static extern void dtorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ", CallingConvention = __CallingConvention.Cdecl)]
internal static extern void dtorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__IntPtr __instance);
}
}
public unsafe partial class BasicString<_Elem, _Traits, _Alloc> : IDisposable
{
public global::System.IntPtr __Instance { get; protected set; }
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_Elem, _Traits, _Alloc>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_Elem, _Traits, _Alloc>>();
protected bool __ownsNativeInstance;
internal static global::Std.BasicString<_Elem, _Traits, _Alloc> __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
internal static BasicString<_Elem, _Traits, _Alloc> __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new global::Std.BasicString<_Elem, _Traits, _Alloc>(native.ToPointer(), skipVTables);
return new BasicString<_Elem, _Traits, _Alloc>(native.ToPointer(), skipVTables);
}
internal static global::Std.BasicString<_Elem, _Traits, _Alloc> __CreateInstance(global::Std.BasicString.__Internalc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native, bool skipVTables = false)
internal static BasicString<_Elem, _Traits, _Alloc> __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
return new global::Std.BasicString<_Elem, _Traits, _Alloc>(native, skipVTables);
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (BasicString<_Elem, _Traits, _Alloc>)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static BasicString<_Elem, _Traits, _Alloc> __CreateInstance(global::Std.BasicString.__Internalc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native, bool skipVTables = false)
{
return new BasicString<_Elem, _Traits, _Alloc>(native, skipVTables);
}
private static void* __CopyValue(global::Std.BasicString.__Internalc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native)
@ -795,7 +815,7 @@ namespace Std @@ -795,7 +815,7 @@ namespace Std
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
__Instance = new __IntPtr(native);
}
public BasicString()
@ -867,7 +887,7 @@ namespace Std @@ -867,7 +887,7 @@ namespace Std
internal fixed sbyte _Buf[16];
[FieldOffset(0)]
internal global::System.IntPtr _Ptr;
internal __IntPtr _Ptr;
[FieldOffset(0)]
internal fixed sbyte _Alias[16];
@ -886,20 +906,32 @@ namespace Std @@ -886,20 +906,32 @@ namespace Std
public unsafe partial class CharTraits<_Elem> : IDisposable
{
public global::System.IntPtr __Instance { get; protected set; }
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_Elem>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_Elem>>();
protected bool __ownsNativeInstance;
internal static global::Std.CharTraits<_Elem> __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
internal static CharTraits<_Elem> __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CharTraits<_Elem>(native.ToPointer(), skipVTables);
}
internal static CharTraits<_Elem> __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
return new global::Std.CharTraits<_Elem>(native.ToPointer(), skipVTables);
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (CharTraits<_Elem>)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static global::Std.CharTraits<_Elem> __CreateInstance(global::Std.CharTraits.__Internal native, bool skipVTables = false)
internal static CharTraits<_Elem> __CreateInstance(global::Std.CharTraits.__Internal native, bool skipVTables = false)
{
return new global::Std.CharTraits<_Elem>(native, skipVTables);
return new CharTraits<_Elem>(native, skipVTables);
}
private static void* __CopyValue(global::Std.CharTraits.__Internal native)
@ -920,7 +952,7 @@ namespace Std @@ -920,7 +952,7 @@ namespace Std
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
__Instance = new __IntPtr(native);
}
public void Dispose()
@ -945,32 +977,24 @@ namespace Std @@ -945,32 +977,24 @@ namespace Std
[StructLayout(LayoutKind.Explicit, Size = 0)]
public partial struct __Internal
{
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@QEBD@Z")]
internal static extern global::System.IntPtr Assign(global::System.IntPtr __instance, [MarshalAs(UnmanagedType.LPUTF8Str)] string _Ptr);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@QEBD@Z", CallingConvention = __CallingConvention.Cdecl)]
internal static extern __IntPtr Assign(__IntPtr __instance, [MarshalAs(UnmanagedType.LPUTF8Str)] string _Ptr);
[SuppressUnmanagedCodeSecurity]
[DllImport("Std-symbols", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ")]
internal static extern global::System.IntPtr Data(global::System.IntPtr __instance);
[SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ", CallingConvention = __CallingConvention.Cdecl)]
internal static extern __IntPtr Data(__IntPtr __instance);
}
public static global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> Assign(this global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> @this, string _Ptr)
{
var __arg0 = ReferenceEquals(@this, null) ? global::System.IntPtr.Zero : @this.__Instance;
var __arg0 = @this is null ? __IntPtr.Zero : @this.__Instance;
var __ret = __Internal.Assign(__arg0, _Ptr);
global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> __result0;
if (__ret == IntPtr.Zero) __result0 = null;
else if (global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.NativeToManagedMap.ContainsKey(__ret))
__result0 = (global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>) global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.NativeToManagedMap[__ret];
else __result0 = global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.__CreateInstance(__ret);
var __result0 = global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.__GetOrCreateInstance(__ret, false);
return __result0;
}
public static string Data(this global::Std.BasicString<sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>> @this)
{
var __arg0 = ReferenceEquals(@this, null) ? global::System.IntPtr.Zero : @this.__Instance;
var __arg0 = @this is null ? __IntPtr.Zero : @this.__Instance;
var __ret = __Internal.Data(__arg0);
return CppSharp.Runtime.MarshalUtil.GetString(global::System.Text.Encoding.UTF8, __ret);
}

46
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -344,34 +344,22 @@ namespace CppSharp.Generators.CSharp @@ -344,34 +344,22 @@ namespace CppSharp.Generators.CSharp
{
var originalClass = @class.OriginalClass ?? @class;
var ret = Generator.GeneratedIdentifier("result") + Context.ParameterIndex;
var qualifiedIdentifier = @class.Visit(typePrinter);
Context.Before.WriteLine("{0} {1};", qualifiedIdentifier, ret);
Context.Before.WriteLine("if ({0} == IntPtr.Zero) {1} = {2};", Context.ReturnVarName, ret,
originalClass.IsRefType ? "null" : string.Format("new {0}()", qualifiedClass));
if (originalClass.IsRefType)
{
Context.Before.WriteLine(
"else if ({0}.NativeToManagedMap.TryGetValue({1}, out var {2}))", qualifiedClass, Context.ReturnVarName, ret + "Object");
Context.Before.WriteLineIndent("{0} = ({1}) {2};",
ret, qualifiedIdentifier, ret + "Object");
var dtor = originalClass.Destructors.FirstOrDefault();
if (dtor != null && dtor.IsVirtual)
{
Context.Before.WriteLine("else {0}{1} = ({2}) {3}.{4}({5}{6});",
Context.Parameter != null
? string.Empty
: string.Format("{0}.NativeToManagedMap[{1}] = ", qualifiedClass, Context.ReturnVarName),
ret, qualifiedIdentifier, qualifiedClass, Helpers.CreateInstanceIdentifier, Context.ReturnVarName,
Context.Parameter != null ? ", skipVTables: true" : string.Empty);
}
else
{
Context.Before.WriteLine("else {0} = {1}.{2}({3});", ret, qualifiedClass,
Helpers.CreateInstanceIdentifier, Context.ReturnVarName);
}
var dtorVirtual = (dtor != null && dtor.IsVirtual);
var cache = dtorVirtual && Context.Parameter == null;
var skipVTables = dtorVirtual && Context.Parameter != null;
Context.Before.WriteLine("var {0} = {1}.__GetOrCreateInstance({2}, {3}{4});",
ret, qualifiedClass, Context.ReturnVarName, cache ? "true" : "false", skipVTables ? ", skipVTables: true" : string.Empty);
}
else
{
var qualifiedIdentifier = @class.Visit(typePrinter);
Context.Before.WriteLine("{0} {1};", qualifiedIdentifier, ret);
Context.Before.WriteLine("if ({0} == IntPtr.Zero) {1} = {2};", Context.ReturnVarName, ret,
originalClass.IsRefType ? "null" : string.Format("new {0}()", qualifiedClass));
Context.Before.WriteLine("else {0} = {1}.{2}({3});", ret, qualifiedClass,
Helpers.CreateInstanceIdentifier, Context.ReturnVarName);
}
@ -394,7 +382,7 @@ namespace CppSharp.Generators.CSharp @@ -394,7 +382,7 @@ namespace CppSharp.Generators.CSharp
Context.Before.WriteLine($"{intermediateArrayType}[] {intermediateArray};");
Context.Before.WriteLine($"if (ReferenceEquals({Context.ReturnVarName}, null))");
Context.Before.WriteLine($"if ({Context.ReturnVarName} is null)");
Context.Before.WriteLineIndent($"{intermediateArray} = null;");
Context.Before.WriteLine("else");
@ -764,7 +752,7 @@ namespace CppSharp.Generators.CSharp @@ -764,7 +752,7 @@ namespace CppSharp.Generators.CSharp
Context.Return.Write("{0}{1}",
method != null && method.OperatorKind == CXXOperatorKind.EqualEqual
? string.Empty
: $"ReferenceEquals({param}, null) ? global::System.IntPtr.Zero : ",
: $"{param} is null ? {typePrinter.IntPtrType}.Zero : ",
paramInstance);
}
return;
@ -872,7 +860,7 @@ namespace CppSharp.Generators.CSharp @@ -872,7 +860,7 @@ namespace CppSharp.Generators.CSharp
Context.Before.WriteLine($"{intermediateArrayType}[] {intermediateArray};");
Context.Before.WriteLine($"if (ReferenceEquals({Context.Parameter.Name}, null))");
Context.Before.WriteLine($"if ({Context.Parameter.Name} is null)");
Context.Before.WriteLineIndent($"{intermediateArray} = null;");
Context.Before.WriteLine("else");
@ -887,12 +875,12 @@ namespace CppSharp.Generators.CSharp @@ -887,12 +875,12 @@ namespace CppSharp.Generators.CSharp
if (elementType.IsAddress())
{
var intPtrZero = $"{typePrinter.IntPtrType}.Zero";
Context.Before.WriteLine($@"{intermediateArray}[i] = ReferenceEquals({
element}, null) ? {intPtrZero} : {element}.{Helpers.InstanceIdentifier};");
Context.Before.WriteLine($@"{intermediateArray}[i] = {
element} is null ? {intPtrZero} : {element}.{Helpers.InstanceIdentifier};");
}
else
Context.Before.WriteLine($@"{intermediateArray}[i] = ReferenceEquals({
element}, null) ? new {intermediateArrayType}() : *({
Context.Before.WriteLine($@"{intermediateArray}[i] = {
element} is null ? new {intermediateArrayType}() : *({
intermediateArrayType}*) {element}.{Helpers.InstanceIdentifier};");
Context.Before.UnindentAndWriteCloseBrace();

127
src/Generator/Generators/CSharp/CSharpSources.cs

@ -164,6 +164,10 @@ namespace CppSharp.Generators.CSharp @@ -164,6 +164,10 @@ namespace CppSharp.Generators.CSharp
foreach (var customUsingStatement in Options.DependentNameSpaces)
WriteLine("using {0};", customUsingStatement);
WriteLine("using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;");
WriteLine("using __IntPtr = global::System.IntPtr;");
PopBlock(NewLineKind.BeforeNextBlock);
foreach (var library in internalsVisibleTo)
@ -940,8 +944,12 @@ namespace CppSharp.Generators.CSharp @@ -940,8 +944,12 @@ namespace CppSharp.Generators.CSharp
f => f.FieldPtr == field.OriginalPtr).Name;
if (@class.IsValueType)
returnVar = $"{Helpers.InstanceField}.{name}";
else
returnVar = $"(({TypePrinter.PrintNative(@class)}*){Helpers.InstanceIdentifier})->{name}";
else {
var typeName = TypePrinter.PrintNative(@class);
if (IsInternalClassNested(field.Class))
typeName.RemoveNamespace();
returnVar = $"(({typeName}*){Helpers.InstanceIdentifier})->{name}";
}
}
var param = new Parameter
@ -992,6 +1000,11 @@ namespace CppSharp.Generators.CSharp @@ -992,6 +1000,11 @@ namespace CppSharp.Generators.CSharp
UnindentAndWriteCloseBrace();
}
private static bool IsInternalClassNested(Class @class)
{
return !(@class is ClassTemplateSpecialization) && !(@class.Namespace is ClassTemplateSpecialization);
}
private string HandleValueArray(ArrayType arrayType, Field field)
{
var originalType = new PointerType(new QualifiedType(arrayType.Type));
@ -1280,7 +1293,10 @@ namespace CppSharp.Generators.CSharp @@ -1280,7 +1293,10 @@ namespace CppSharp.Generators.CSharp
}
else
{
returnVar = $"(({TypePrinter.PrintNative(@class)}*) {Helpers.InstanceIdentifier})->{name}";
var typeName = TypePrinter.PrintNative(@class);
if (IsInternalClassNested(field.Class))
typeName.RemoveNamespace();
returnVar = $"(({typeName}*){Helpers.InstanceIdentifier})->{name}";
// Class field getter should return a reference object instead of a copy. Wrapping `returnVar` in
// IntPtr ensures that non-copying object constructor is invoked.
Class typeClass;
@ -1909,14 +1925,8 @@ namespace CppSharp.Generators.CSharp @@ -1909,14 +1925,8 @@ namespace CppSharp.Generators.CSharp
string.Join(", ", @params));
WriteOpenBraceAndIndent();
WriteLine($"if (!NativeToManagedMap.TryGetValue({Helpers.InstanceField}, out var {Helpers.TargetIdentifier}Object))");
WriteLineIndent("throw new global::System.Exception(\"No managed instance was found\");");
NewLine();
var printedClass = @class.Visit(TypePrinter);
WriteLine($@"var {Helpers.TargetIdentifier} = ({printedClass}){Helpers.TargetIdentifier}Object;");
WriteLine("if ({0}.{1})", Helpers.TargetIdentifier, Helpers.OwnsNativeInstanceIdentifier);
WriteLineIndent("{0}.SetupVTables();", Helpers.TargetIdentifier);
WriteLine($@"var {Helpers.TargetIdentifier} = {printedClass}.__GetInstance({Helpers.InstanceField});");
GenerateVTableManagedCall(method);
UnindentAndWriteCloseBrace();
@ -1934,6 +1944,11 @@ namespace CppSharp.Generators.CSharp @@ -1934,6 +1944,11 @@ namespace CppSharp.Generators.CSharp
return string.Format("_{0}Delegate", nativeId);
}
public bool HasVirtualTables(Class @class)
{
return @class.IsGenerated && @class.IsDynamic && GetUniqueVTableMethodEntries(@class).Count > 0;
}
#endregion
#region Events
@ -1952,7 +1967,7 @@ namespace CppSharp.Generators.CSharp @@ -1952,7 +1967,7 @@ namespace CppSharp.Generators.CSharp
var delegateName = delegateInstance + "Delegate";
var delegateRaise = delegateInstance + "RaiseInstance";
WriteLine("[UnmanagedFunctionPointer(global::System.Runtime.InteropServices.CallingConvention.Cdecl)]");
WriteLine("[UnmanagedFunctionPointer(__CallingConvention.Cdecl)]");
WriteLine("delegate void {0}({1});", delegateName, args);
WriteLine("{0} {1};", delegateName, delegateRaise);
NewLine();
@ -2147,7 +2162,7 @@ namespace CppSharp.Generators.CSharp @@ -2147,7 +2162,7 @@ namespace CppSharp.Generators.CSharp
ClassLayout layout = (@class.IsDependent ? @class.Specializations[0] : @class).Layout;
for (var i = 0; i < layout.VTablePointers.Count; i++)
WriteLine($@"(({classInternal}*) {Helpers.InstanceIdentifier})->{
layout.VTablePointers[i].Name} = new global::System.IntPtr(__OriginalVTables[{i}]);");
layout.VTablePointers[i].Name} = new {TypePrinter.IntPtrType}(__OriginalVTables[{i}]);");
}
}
@ -2213,15 +2228,53 @@ namespace CppSharp.Generators.CSharp @@ -2213,15 +2228,53 @@ namespace CppSharp.Generators.CSharp
{
PushBlock(BlockKind.Method);
TypePrinterResult printedClass = @class.Visit(TypePrinter);
WriteLine("internal static {0}{1} {2}(global::System.IntPtr native, bool skipVTables = false)",
printedClass.RemoveNamespace();
WriteLine("internal static {0}{1} {2}({3} native, bool skipVTables = false)",
@class.NeedsBase && !@class.BaseClass.IsInterface ? "new " : string.Empty,
printedClass, Helpers.CreateInstanceIdentifier);
printedClass, Helpers.CreateInstanceIdentifier, TypePrinter.IntPtrType);
WriteOpenBraceAndIndent();
var suffix = @class.IsAbstract ? "Internal" : string.Empty;
var ctorCall = $"{printedClass.Type}{suffix}{printedClass.NameSuffix}";
WriteLine("return new {0}(native.ToPointer(), skipVTables);", ctorCall);
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
if (@class.IsRefType)
{
var @new = @class.HasBase && @class.HasRefBase();
WriteLines($@"
internal static{(@new ? " new" : string.Empty)} {printedClass} __GetOrCreateInstance({TypePrinter.IntPtrType} native, bool saveInstance = false, bool skipVTables = false)
{{
if (native == {TypePrinter.IntPtrType}.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return ({printedClass})managed;
var result = {Helpers.CreateInstanceIdentifier}(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}}");
NewLine();
if (HasVirtualTables(@class))
{
@new = @class.HasBase;
WriteLines($@"
internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({TypePrinter.IntPtrType} native)
{{
if (!NativeToManagedMap.TryGetValue(native, out var managed))
throw new System.Exception(""No managed instance was found"");
var result = ({printedClass})managed;
if (result.{Helpers.OwnsNativeInstanceIdentifier})
result.SetupVTables();
return result;
}}");
NewLine();
}
}
}
this.GenerateNativeConstructorsByValue(@class);
@ -2248,7 +2301,7 @@ namespace CppSharp.Generators.CSharp @@ -2248,7 +2301,7 @@ namespace CppSharp.Generators.CSharp
WriteLine("if (native == null)");
WriteLineIndent("return;");
if (!hasBaseClass)
WriteLine($"{Helpers.InstanceIdentifier} = new global::System.IntPtr(native);");
WriteLine($"{Helpers.InstanceIdentifier} = new {TypePrinter.IntPtrType}(native);");
}
var dtor = @class.Destructors.FirstOrDefault();
var setupVTables = !@class.IsAbstractImpl && hasVTables && dtor?.IsVirtual == true;
@ -2272,9 +2325,13 @@ namespace CppSharp.Generators.CSharp @@ -2272,9 +2325,13 @@ namespace CppSharp.Generators.CSharp
public void GenerateNativeConstructorByValue(Class @class, TypePrinterResult returnType)
{
var @internal = TypePrinter.PrintNative(@class.IsAbstractImpl ? @class.BaseClass : @class);
if (IsInternalClassNested(@class))
@internal.RemoveNamespace();
if (!@class.IsAbstractImpl)
{
returnType.RemoveNamespace();
PushBlock(BlockKind.Method);
WriteLine("internal static {0} {1}({2} native, bool skipVTables = false)",
returnType, Helpers.CreateInstanceIdentifier, @internal);
@ -2298,7 +2355,7 @@ namespace CppSharp.Generators.CSharp @@ -2298,7 +2355,7 @@ namespace CppSharp.Generators.CSharp
// Allocate memory for a new native object and call the ctor.
WriteLine($"var ret = Marshal.AllocHGlobal(sizeof({@internal}));");
var printed = TypePrinter.PrintNative(@class);
WriteLine($"{printed}.{GetFunctionNativeIdentifier(copyCtorMethod)}(ret, new global::System.IntPtr(&native));",
WriteLine($"{printed}.{GetFunctionNativeIdentifier(copyCtorMethod)}(ret, new {TypePrinter.IntPtrType}(&native));",
printed, GetFunctionNativeIdentifier(copyCtorMethod));
WriteLine("return ret.ToPointer();");
}
@ -2639,8 +2696,8 @@ namespace CppSharp.Generators.CSharp @@ -2639,8 +2696,8 @@ namespace CppSharp.Generators.CSharp
private void GenerateGetHashCode(Class @class)
{
WriteLine($"if ({Helpers.InstanceIdentifier} == global::System.IntPtr.Zero)");
WriteLineIndent("return global::System.IntPtr.Zero.GetHashCode();");
WriteLine($"if ({Helpers.InstanceIdentifier} == {TypePrinter.IntPtrType}.Zero)");
WriteLineIndent($"return {TypePrinter.IntPtrType}.Zero.GetHashCode();");
WriteLine($@"return (*({TypePrinter.PrintNative(@class)}*) {
Helpers.InstanceIdentifier}).GetHashCode();");
}
@ -2674,23 +2731,19 @@ namespace CppSharp.Generators.CSharp @@ -2674,23 +2731,19 @@ namespace CppSharp.Generators.CSharp
vtableIndex = @class.Layout.VFTables.IndexOf(@class.Layout.VFTables.First(
v => v.Layout.Components.Any(c => c.Method == @virtual)));
WriteLine($@"var {Helpers.SlotIdentifier} = *(void**) ((IntPtr) {
(thisParam != null ? $"{thisParam.Name}."
: string.Empty)}__OriginalVTables[{vtableIndex}] + {i} * {
Context.TargetInfo.PointerWidth / 8});");
var vtables = $@"{ (thisParam != null ? $"{thisParam.Name}." : string.Empty)}__OriginalVTables";
var @delegate = GetVTableMethodDelegateName(@virtual);
var delegateId = Generator.GeneratedIdentifier(@delegate);
WriteLine("var {0} = CppSharp.Runtime.MarshalUtil.GetDelegate<{1}>({2}, {3}, {4});",
delegateId, method.FunctionType.ToString(), vtables, vtableIndex, i);
if (method.IsDestructor && @class.IsAbstract)
{
WriteLine("if ({0} != null)", Helpers.SlotIdentifier);
WriteLine("if ({0} != null)", delegateId);
WriteOpenBraceAndIndent();
}
var @delegate = GetVTableMethodDelegateName(@virtual);
var delegateId = Generator.GeneratedIdentifier(@delegate);
WriteLine("var {0} = ({1}) Marshal.GetDelegateForFunctionPointer(new IntPtr({2}), typeof({1}));",
delegateId, method.FunctionType.ToString(),
Helpers.SlotIdentifier);
return delegateId;
}
@ -2895,7 +2948,7 @@ namespace CppSharp.Generators.CSharp @@ -2895,7 +2948,7 @@ namespace CppSharp.Generators.CSharp
if (needsFixedThis)
{
names.Insert(instanceIndex, "new global::System.IntPtr(__instancePtr)");
names.Insert(instanceIndex, $"new {TypePrinter.IntPtrType}(__instancePtr)");
}
else
{
@ -3125,7 +3178,7 @@ namespace CppSharp.Generators.CSharp @@ -3125,7 +3178,7 @@ namespace CppSharp.Generators.CSharp
else
WriteLine(
"[SuppressUnmanagedCodeSecurity, " +
"UnmanagedFunctionPointer(global::System.Runtime.InteropServices.CallingConvention.{0})]",
"UnmanagedFunctionPointer(__CallingConvention.{0})]",
interopCallConv);
if (functionType.ReturnType.Type.Desugar().IsPrimitiveType(PrimitiveType.Bool))
@ -3251,14 +3304,12 @@ namespace CppSharp.Generators.CSharp @@ -3251,14 +3304,12 @@ namespace CppSharp.Generators.CSharp
return;
PushBlock(BlockKind.InternalsClassMethod);
WriteLine("[SuppressUnmanagedCodeSecurity]");
Write("[DllImport(\"{0}\", ", GetLibraryOf(function));
var callConv = function.CallingConvention.ToInteropCallConv();
WriteLine("CallingConvention = global::System.Runtime.InteropServices.CallingConvention.{0},",
callConv);
WriteLineIndent("EntryPoint=\"{0}\")]", function.Mangled);
WriteLine("[SuppressUnmanagedCodeSecurity, DllImport(\"{0}\", EntryPoint = \"{1}\", CallingConvention = __CallingConvention.{2})]",
GetLibraryOf(function),
function.Mangled,
callConv);
if (function.ReturnType.Type.IsPrimitiveType(PrimitiveType.Bool))
WriteLine("[return: MarshalAs(UnmanagedType.I1)]");

2
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -13,7 +13,7 @@ namespace CppSharp.Generators.CSharp @@ -13,7 +13,7 @@ namespace CppSharp.Generators.CSharp
{
public class CSharpTypePrinter : TypePrinter
{
public string IntPtrType => QualifiedType("System.IntPtr");
public string IntPtrType => "__IntPtr";
public BindingContext Context { get; set; }

7
src/Generator/Generators/TypePrinter.cs

@ -20,6 +20,13 @@ namespace CppSharp.Generators @@ -20,6 +20,13 @@ namespace CppSharp.Generators
NameSuffix.Append(nameSuffix);
}
public void RemoveNamespace()
{
var index = Type.LastIndexOf('.');
if (index != -1)
Type = Type.Substring(index + 1);
}
public static implicit operator TypePrinterResult(string type) =>
new TypePrinterResult { Type = type };

8
src/Generator/Utils/BlockGenerator.cs

@ -239,6 +239,8 @@ namespace CppSharp @@ -239,6 +239,8 @@ namespace CppSharp
public abstract class BlockGenerator : ITextGenerator
{
private static string[] LineBreakSequences = new[] { "\r\n", "\r", "\n" };
public Block RootBlock { get; }
public Block ActiveBlock { get; private set; }
public uint CurrentIndentation => ActiveBlock.Text.CurrentIndentation;
@ -311,6 +313,12 @@ namespace CppSharp @@ -311,6 +313,12 @@ namespace CppSharp
ActiveBlock.WriteLine(msg, args);
}
public void WriteLines(string msg)
{
foreach(var line in msg.TrimStart().Split(LineBreakSequences, StringSplitOptions.None))
WriteLine(line);
}
public void WriteLineIndent(string msg, params object[] args)
{
ActiveBlock.WriteLineIndent(msg, args);

7
src/Runtime/MarshalUtil.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace CppSharp.Runtime
@ -55,5 +56,11 @@ namespace CppSharp.Runtime @@ -55,5 +56,11 @@ namespace CppSharp.Runtime
{
return GetArray<IntPtr>(array, size);
}
public static T GetDelegate<T>(void*[] vtables, short table, int i) where T : class
{
var slot = *(void**)((IntPtr)vtables[table] + i * sizeof(IntPtr));
return Marshal.GetDelegateForFunctionPointer<T>(new IntPtr(slot));
}
}
}

Loading…
Cancel
Save