Browse Source

Filled in all missing v-table pointers in record layouts.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/667/head
Dimitar Dobrev 9 years ago
parent
commit
c4c2ef21ce
  1. 18
      src/AST/ClassLayout.cs
  2. 3
      src/AST/Field.cs
  3. 28
      src/AST/LayoutField.cs
  4. 11
      src/Core/Parser/ASTConverter.cs
  5. 13
      src/CppParser/AST.cpp
  6. 8
      src/CppParser/AST.h
  7. 42
      src/CppParser/Bindings/CLI/AST.cpp
  8. 24
      src/CppParser/Bindings/CLI/AST.h
  9. 93
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs
  10. 93
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs
  11. 93
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs
  12. 93
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs
  13. 93
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/AST.cs
  14. 54
      src/CppParser/Parser.cpp
  15. 1
      src/CppParser/Parser.h
  16. 17
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  17. 110
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  18. 4
      src/Generator/Passes/CheckDuplicatedNamesPass.cs
  19. 4
      src/Generator/Passes/CleanInvalidDeclNamesPass.cs

18
src/AST/ClassLayout.cs

@ -1,5 +1,7 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
namespace CppSharp.AST namespace CppSharp.AST
{ {
@ -132,5 +134,19 @@ namespace CppSharp.AST
public int Alignment; public int Alignment;
public int Size; public int Size;
public int DataSize; public int DataSize;
public IList<LayoutField> VTablePointers
{
get
{
if (vTablePointers == null)
{
vTablePointers = new List<LayoutField>(Fields.Where(f => f.IsVTablePtr));
}
return vTablePointers;
}
}
private List<LayoutField> vTablePointers;
} }
} }

3
src/AST/Field.cs

@ -10,8 +10,6 @@ namespace CppSharp.AST
public Class Class { get; set; } public Class Class { get; set; }
public Expression Expression { get; set; }
public bool IsBitField { get; set; } public bool IsBitField { get; set; }
public uint BitWidth { get; set; } public uint BitWidth { get; set; }
@ -31,7 +29,6 @@ namespace CppSharp.AST
{ {
QualifiedType = field.QualifiedType; QualifiedType = field.QualifiedType;
Class = field.Class; Class = field.Class;
Expression = field.Expression;
IsBitField = field.IsBitField; IsBitField = field.IsBitField;
BitWidth = field.BitWidth; BitWidth = field.BitWidth;
} }

28
src/AST/LayoutField.cs

@ -1,28 +1,20 @@
namespace CppSharp.AST using System;
namespace CppSharp.AST
{ {
public class LayoutField public class LayoutField
{ {
public LayoutField(uint offset, Field field) public DeclarationContext Namespace { get; set; }
{
Field = field;
Offset = offset;
}
public uint Offset { get; set; } public uint Offset { get; set; }
public QualifiedType QualifiedType { get; set; }
public string Name public string Name { get; set; }
{ public IntPtr FieldPtr { get; set; }
get { return name ?? Field.OriginalName; } public bool IsVTablePtr { get { return FieldPtr == IntPtr.Zero; } }
set { name = value; } public Expression Expression { get; set; }
}
public Field Field { get; set; }
public override string ToString() public override string ToString()
{ {
return string.Format("{0} | {1}", Offset, Field.OriginalName); return string.Format("{0} | {1}", Offset, Name);
} }
private string name;
} }
} }

11
src/Core/Parser/ASTConverter.cs

@ -687,7 +687,7 @@ namespace CppSharp
public HashSet<IDisposable> NativeObjects { get; private set; } public HashSet<IDisposable> NativeObjects { get; private set; }
public override AST.Declaration Visit(Parser.AST.Declaration decl) public override AST.Declaration Visit(Declaration decl)
{ {
if (decl == null) if (decl == null)
return null; return null;
@ -1348,8 +1348,13 @@ namespace CppSharp
for (uint i = 0; i < layout.FieldsCount; i++) for (uint i = 0; i < layout.FieldsCount; i++)
{ {
var field = layout.getFields(i); var field = layout.getFields(i);
_layout.Fields.Add(new AST.LayoutField(field.Offset, var _field = new AST.LayoutField();
(AST.Field) Visit(field.Field))); _field.Namespace = (AST.DeclarationContext) Visit(field._Namespace);
_field.Offset = field.Offset;
_field.Name = field.Name;
_field.QualifiedType = typeConverter.VisitQualified(field.QualifiedType);
_field.FieldPtr = field.FieldPtr;
_layout.Fields.Add(_field);
} }
return _layout; return _layout;

13
src/CppParser/AST.cpp

@ -189,10 +189,21 @@ VFTableInfo::VFTableInfo(const VFTableInfo& rhs) : VBTableIndex(rhs.VBTableIndex
VFPtrOffset(rhs.VFPtrOffset), VFPtrFullOffset(rhs.VFPtrFullOffset), VFPtrOffset(rhs.VFPtrOffset), VFPtrFullOffset(rhs.VFPtrFullOffset),
Layout(rhs.Layout) {} Layout(rhs.Layout) {}
LayoutField::LayoutField() {} LayoutField::LayoutField() : _Namespace(0), Offset(0), FieldPtr(0) {}
LayoutField::LayoutField(const LayoutField & other)
: _Namespace(other._Namespace)
, Offset(other.Offset)
, Name(other.Name)
, QualifiedType(other.QualifiedType)
, FieldPtr(other.FieldPtr)
{
}
LayoutField::~LayoutField() {} LayoutField::~LayoutField() {}
DEF_STRING(LayoutField, Name)
ClassLayout::ClassLayout() : ABI(CppAbi::Itanium), HasOwnVFPtr(false), ClassLayout::ClassLayout() : ABI(CppAbi::Itanium), HasOwnVFPtr(false),
VBPtrOffset(0), Alignment(0), Size(0), DataSize(0) {} VBPtrOffset(0), Alignment(0), Size(0), DataSize(0) {}

8
src/CppParser/AST.h

@ -315,15 +315,19 @@ struct CS_API VFTableInfo
VTableLayout Layout; VTableLayout Layout;
}; };
class Field; class DeclarationContext;
class CS_API LayoutField class CS_API LayoutField
{ {
public: public:
LayoutField(); LayoutField();
LayoutField(const LayoutField& other);
~LayoutField(); ~LayoutField();
DeclarationContext* _Namespace;
unsigned Offset; unsigned Offset;
Field* Field; STRING(Name)
QualifiedType QualifiedType;
void* FieldPtr;
}; };
struct CS_API ClassLayout struct CS_API ClassLayout

42
src/CppParser/Bindings/CLI/AST.cpp

@ -1333,6 +1333,30 @@ void CppSharp::Parser::AST::LayoutField::__Instance::set(System::IntPtr object)
NativePtr = (::CppSharp::CppParser::AST::LayoutField*)object.ToPointer(); NativePtr = (::CppSharp::CppParser::AST::LayoutField*)object.ToPointer();
} }
System::String^ CppSharp::Parser::AST::LayoutField::Name::get()
{
auto __ret = ((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->getName();
if (__ret == nullptr) return nullptr;
return (__ret == 0 ? nullptr : clix::marshalString<clix::E_UTF8>(__ret));
}
void CppSharp::Parser::AST::LayoutField::Name::set(System::String^ s)
{
auto ___arg0 = clix::marshalString<clix::E_UTF8>(s);
auto __arg0 = ___arg0.c_str();
((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->setName(__arg0);
}
CppSharp::Parser::AST::DeclarationContext^ CppSharp::Parser::AST::LayoutField::_Namespace::get()
{
return (((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->_Namespace == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::DeclarationContext((::CppSharp::CppParser::AST::DeclarationContext*)((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->_Namespace);
}
void CppSharp::Parser::AST::LayoutField::_Namespace::set(CppSharp::Parser::AST::DeclarationContext^ value)
{
((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->_Namespace = (::CppSharp::CppParser::AST::DeclarationContext*)value->NativePtr;
}
unsigned int CppSharp::Parser::AST::LayoutField::Offset::get() unsigned int CppSharp::Parser::AST::LayoutField::Offset::get()
{ {
return ((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->Offset; return ((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->Offset;
@ -1343,14 +1367,24 @@ void CppSharp::Parser::AST::LayoutField::Offset::set(unsigned int value)
((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->Offset = value; ((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->Offset = value;
} }
CppSharp::Parser::AST::Field^ CppSharp::Parser::AST::LayoutField::Field::get() CppSharp::Parser::AST::QualifiedType^ CppSharp::Parser::AST::LayoutField::QualifiedType::get()
{
return (&((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->QualifiedType == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::QualifiedType((::CppSharp::CppParser::AST::QualifiedType*)&((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->QualifiedType);
}
void CppSharp::Parser::AST::LayoutField::QualifiedType::set(CppSharp::Parser::AST::QualifiedType^ value)
{
((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->QualifiedType = *(::CppSharp::CppParser::AST::QualifiedType*)value->NativePtr;
}
::System::IntPtr CppSharp::Parser::AST::LayoutField::FieldPtr::get()
{ {
return (((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->Field == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::Field((::CppSharp::CppParser::AST::Field*)((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->Field); return ::System::IntPtr(((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->FieldPtr);
} }
void CppSharp::Parser::AST::LayoutField::Field::set(CppSharp::Parser::AST::Field^ value) void CppSharp::Parser::AST::LayoutField::FieldPtr::set(::System::IntPtr value)
{ {
((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->Field = (::CppSharp::CppParser::AST::Field*)value->NativePtr; ((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->FieldPtr = (void*)value;
} }
CppSharp::Parser::AST::ClassLayout::ClassLayout(::CppSharp::CppParser::AST::ClassLayout* native) CppSharp::Parser::AST::ClassLayout::ClassLayout(::CppSharp::CppParser::AST::ClassLayout* native)

24
src/CppParser/Bindings/CLI/AST.h

@ -1046,16 +1046,34 @@ namespace CppSharp
~LayoutField(); ~LayoutField();
property System::String^ Name
{
System::String^ get();
void set(System::String^);
}
property CppSharp::Parser::AST::DeclarationContext^ _Namespace
{
CppSharp::Parser::AST::DeclarationContext^ get();
void set(CppSharp::Parser::AST::DeclarationContext^);
}
property unsigned int Offset property unsigned int Offset
{ {
unsigned int get(); unsigned int get();
void set(unsigned int); void set(unsigned int);
} }
property CppSharp::Parser::AST::Field^ Field property CppSharp::Parser::AST::QualifiedType^ QualifiedType
{
CppSharp::Parser::AST::QualifiedType^ get();
void set(CppSharp::Parser::AST::QualifiedType^);
}
property ::System::IntPtr FieldPtr
{ {
CppSharp::Parser::AST::Field^ get(); ::System::IntPtr get();
void set(CppSharp::Parser::AST::Field^); void set(::System::IntPtr);
} }
protected: protected:

93
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs

@ -2987,14 +2987,20 @@ namespace CppSharp
public unsafe partial class LayoutField : IDisposable public unsafe partial class LayoutField : IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 8)] [StructLayout(LayoutKind.Explicit, Size = 32)]
public partial struct Internal public partial struct Internal
{ {
[FieldOffset(0)] [FieldOffset(0)]
public uint Offset; public global::System.IntPtr _Namespace;
[FieldOffset(4)] [FieldOffset(4)]
public global::System.IntPtr Field; public uint Offset;
[FieldOffset(20)]
public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType;
[FieldOffset(28)]
public global::System.IntPtr FieldPtr;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
@ -3010,6 +3016,16 @@ namespace CppSharp
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldD2Ev")] EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldD2Ev")]
internal static extern void dtor_0(global::System.IntPtr instance); internal static extern void dtor_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutField7getNameEv")]
internal static extern global::System.IntPtr getName_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutField7setNameEPKc")]
internal static extern void setName_0(global::System.IntPtr instance, global::System.IntPtr s);
} }
public global::System.IntPtr __Instance { get; protected set; } public global::System.IntPtr __Instance { get; protected set; }
@ -3032,8 +3048,8 @@ namespace CppSharp
private static void* __CopyValue(LayoutField.Internal native) private static void* __CopyValue(LayoutField.Internal native)
{ {
var ret = Marshal.AllocHGlobal(8); var ret = Marshal.AllocHGlobal(32);
*(LayoutField.Internal*) ret = native; CppSharp.Parser.AST.LayoutField.Internal.cctor_1(ret, new global::System.IntPtr(&native));
return ret.ToPointer(); return ret.ToPointer();
} }
@ -3053,7 +3069,7 @@ namespace CppSharp
public LayoutField() public LayoutField()
{ {
__Instance = Marshal.AllocHGlobal(8); __Instance = Marshal.AllocHGlobal(32);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
Internal.ctor_0((__Instance + __PointerAdjustment)); Internal.ctor_0((__Instance + __PointerAdjustment));
@ -3061,10 +3077,13 @@ namespace CppSharp
public LayoutField(CppSharp.Parser.AST.LayoutField _0) public LayoutField(CppSharp.Parser.AST.LayoutField _0)
{ {
__Instance = Marshal.AllocHGlobal(8); __Instance = Marshal.AllocHGlobal(32);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
*((LayoutField.Internal*) __Instance) = *((LayoutField.Internal*) _0.__Instance); if (ReferenceEquals(_0, null))
throw new global::System.ArgumentNullException("_0", "Cannot be null because it is a C++ reference (&).");
var __arg0 = _0.__Instance;
Internal.cctor_1((__Instance + __PointerAdjustment), __arg0);
} }
public void Dispose() public void Dispose()
@ -3081,6 +3100,40 @@ namespace CppSharp
Marshal.FreeHGlobal(__Instance); Marshal.FreeHGlobal(__Instance);
} }
public string Name
{
get
{
var __ret = Internal.getName_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
}
set
{
var __arg0 = Marshal.StringToHGlobalAnsi(value);
Internal.setName_0((__Instance + __PointerAdjustment), __arg0);
Marshal.FreeHGlobal(__arg0);
}
}
public CppSharp.Parser.AST.DeclarationContext _Namespace
{
get
{
CppSharp.Parser.AST.DeclarationContext __result0;
if (((Internal*) __Instance)->_Namespace == IntPtr.Zero) __result0 = null;
else if (CppSharp.Parser.AST.DeclarationContext.NativeToManagedMap.ContainsKey(((Internal*) __Instance)->_Namespace))
__result0 = (CppSharp.Parser.AST.DeclarationContext) CppSharp.Parser.AST.DeclarationContext.NativeToManagedMap[((Internal*) __Instance)->_Namespace];
else __result0 = CppSharp.Parser.AST.DeclarationContext.__CreateInstance(((Internal*) __Instance)->_Namespace);
return __result0;
}
set
{
((Internal*) __Instance)->_Namespace = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance;
}
}
public uint Offset public uint Offset
{ {
get get
@ -3094,21 +3147,29 @@ namespace CppSharp
} }
} }
public CppSharp.Parser.AST.Field Field public CppSharp.Parser.AST.QualifiedType QualifiedType
{ {
get get
{ {
CppSharp.Parser.AST.Field __result0; return CppSharp.Parser.AST.QualifiedType.__CreateInstance(((Internal*) __Instance)->QualifiedType);
if (((Internal*) __Instance)->Field == IntPtr.Zero) __result0 = null; }
else if (CppSharp.Parser.AST.Field.NativeToManagedMap.ContainsKey(((Internal*) __Instance)->Field))
__result0 = (CppSharp.Parser.AST.Field) CppSharp.Parser.AST.Field.NativeToManagedMap[((Internal*) __Instance)->Field]; set
else __result0 = CppSharp.Parser.AST.Field.__CreateInstance(((Internal*) __Instance)->Field); {
return __result0; ((Internal*) __Instance)->QualifiedType = ReferenceEquals(value, null) ? new CppSharp.Parser.AST.QualifiedType.Internal() : *(CppSharp.Parser.AST.QualifiedType.Internal*) (value.__Instance);
}
}
public global::System.IntPtr FieldPtr
{
get
{
return ((Internal*) __Instance)->FieldPtr;
} }
set set
{ {
((Internal*) __Instance)->Field = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance; ((Internal*) __Instance)->FieldPtr = (global::System.IntPtr) value;
} }
} }
} }

93
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs

@ -2987,14 +2987,20 @@ namespace CppSharp
public unsafe partial class LayoutField : IDisposable public unsafe partial class LayoutField : IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 8)] [StructLayout(LayoutKind.Explicit, Size = 44)]
public partial struct Internal public partial struct Internal
{ {
[FieldOffset(0)] [FieldOffset(0)]
public uint Offset; public global::System.IntPtr _Namespace;
[FieldOffset(4)] [FieldOffset(4)]
public global::System.IntPtr Field; public uint Offset;
[FieldOffset(32)]
public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType;
[FieldOffset(40)]
public global::System.IntPtr FieldPtr;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
@ -3010,6 +3016,16 @@ namespace CppSharp
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="??1LayoutField@AST@CppParser@CppSharp@@QAE@XZ")] EntryPoint="??1LayoutField@AST@CppParser@CppSharp@@QAE@XZ")]
internal static extern void dtor_0(global::System.IntPtr instance, int delete); internal static extern void dtor_0(global::System.IntPtr instance, int delete);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?getName@LayoutField@AST@CppParser@CppSharp@@QAEPBDXZ")]
internal static extern global::System.IntPtr getName_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?setName@LayoutField@AST@CppParser@CppSharp@@QAEXPBD@Z")]
internal static extern void setName_0(global::System.IntPtr instance, global::System.IntPtr s);
} }
public global::System.IntPtr __Instance { get; protected set; } public global::System.IntPtr __Instance { get; protected set; }
@ -3032,8 +3048,8 @@ namespace CppSharp
private static void* __CopyValue(LayoutField.Internal native) private static void* __CopyValue(LayoutField.Internal native)
{ {
var ret = Marshal.AllocHGlobal(8); var ret = Marshal.AllocHGlobal(44);
*(LayoutField.Internal*) ret = native; CppSharp.Parser.AST.LayoutField.Internal.cctor_1(ret, new global::System.IntPtr(&native));
return ret.ToPointer(); return ret.ToPointer();
} }
@ -3053,7 +3069,7 @@ namespace CppSharp
public LayoutField() public LayoutField()
{ {
__Instance = Marshal.AllocHGlobal(8); __Instance = Marshal.AllocHGlobal(44);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
Internal.ctor_0((__Instance + __PointerAdjustment)); Internal.ctor_0((__Instance + __PointerAdjustment));
@ -3061,10 +3077,13 @@ namespace CppSharp
public LayoutField(CppSharp.Parser.AST.LayoutField _0) public LayoutField(CppSharp.Parser.AST.LayoutField _0)
{ {
__Instance = Marshal.AllocHGlobal(8); __Instance = Marshal.AllocHGlobal(44);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
*((LayoutField.Internal*) __Instance) = *((LayoutField.Internal*) _0.__Instance); if (ReferenceEquals(_0, null))
throw new global::System.ArgumentNullException("_0", "Cannot be null because it is a C++ reference (&).");
var __arg0 = _0.__Instance;
Internal.cctor_1((__Instance + __PointerAdjustment), __arg0);
} }
public void Dispose() public void Dispose()
@ -3081,6 +3100,40 @@ namespace CppSharp
Marshal.FreeHGlobal(__Instance); Marshal.FreeHGlobal(__Instance);
} }
public string Name
{
get
{
var __ret = Internal.getName_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
}
set
{
var __arg0 = Marshal.StringToHGlobalAnsi(value);
Internal.setName_0((__Instance + __PointerAdjustment), __arg0);
Marshal.FreeHGlobal(__arg0);
}
}
public CppSharp.Parser.AST.DeclarationContext _Namespace
{
get
{
CppSharp.Parser.AST.DeclarationContext __result0;
if (((Internal*) __Instance)->_Namespace == IntPtr.Zero) __result0 = null;
else if (CppSharp.Parser.AST.DeclarationContext.NativeToManagedMap.ContainsKey(((Internal*) __Instance)->_Namespace))
__result0 = (CppSharp.Parser.AST.DeclarationContext) CppSharp.Parser.AST.DeclarationContext.NativeToManagedMap[((Internal*) __Instance)->_Namespace];
else __result0 = CppSharp.Parser.AST.DeclarationContext.__CreateInstance(((Internal*) __Instance)->_Namespace);
return __result0;
}
set
{
((Internal*) __Instance)->_Namespace = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance;
}
}
public uint Offset public uint Offset
{ {
get get
@ -3094,21 +3147,29 @@ namespace CppSharp
} }
} }
public CppSharp.Parser.AST.Field Field public CppSharp.Parser.AST.QualifiedType QualifiedType
{ {
get get
{ {
CppSharp.Parser.AST.Field __result0; return CppSharp.Parser.AST.QualifiedType.__CreateInstance(((Internal*) __Instance)->QualifiedType);
if (((Internal*) __Instance)->Field == IntPtr.Zero) __result0 = null; }
else if (CppSharp.Parser.AST.Field.NativeToManagedMap.ContainsKey(((Internal*) __Instance)->Field))
__result0 = (CppSharp.Parser.AST.Field) CppSharp.Parser.AST.Field.NativeToManagedMap[((Internal*) __Instance)->Field]; set
else __result0 = CppSharp.Parser.AST.Field.__CreateInstance(((Internal*) __Instance)->Field); {
return __result0; ((Internal*) __Instance)->QualifiedType = ReferenceEquals(value, null) ? new CppSharp.Parser.AST.QualifiedType.Internal() : *(CppSharp.Parser.AST.QualifiedType.Internal*) (value.__Instance);
}
}
public global::System.IntPtr FieldPtr
{
get
{
return ((Internal*) __Instance)->FieldPtr;
} }
set set
{ {
((Internal*) __Instance)->Field = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance; ((Internal*) __Instance)->FieldPtr = (global::System.IntPtr) value;
} }
} }
} }

93
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs

@ -2986,14 +2986,20 @@ namespace CppSharp
public unsafe partial class LayoutField : IDisposable public unsafe partial class LayoutField : IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 16)] [StructLayout(LayoutKind.Explicit, Size = 64)]
public partial struct Internal public partial struct Internal
{ {
[FieldOffset(0)] [FieldOffset(0)]
public uint Offset; public global::System.IntPtr _Namespace;
[FieldOffset(8)] [FieldOffset(8)]
public global::System.IntPtr Field; public uint Offset;
[FieldOffset(40)]
public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType;
[FieldOffset(56)]
public global::System.IntPtr FieldPtr;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
@ -3009,6 +3015,16 @@ namespace CppSharp
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldD2Ev")] EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldD2Ev")]
internal static extern void dtor_0(global::System.IntPtr instance); internal static extern void dtor_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutField7getNameEv")]
internal static extern global::System.IntPtr getName_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutField7setNameEPKc")]
internal static extern void setName_0(global::System.IntPtr instance, global::System.IntPtr s);
} }
public global::System.IntPtr __Instance { get; protected set; } public global::System.IntPtr __Instance { get; protected set; }
@ -3031,8 +3047,8 @@ namespace CppSharp
private static void* __CopyValue(LayoutField.Internal native) private static void* __CopyValue(LayoutField.Internal native)
{ {
var ret = Marshal.AllocHGlobal(16); var ret = Marshal.AllocHGlobal(64);
*(LayoutField.Internal*) ret = native; CppSharp.Parser.AST.LayoutField.Internal.cctor_1(ret, new global::System.IntPtr(&native));
return ret.ToPointer(); return ret.ToPointer();
} }
@ -3052,7 +3068,7 @@ namespace CppSharp
public LayoutField() public LayoutField()
{ {
__Instance = Marshal.AllocHGlobal(16); __Instance = Marshal.AllocHGlobal(64);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
Internal.ctor_0((__Instance + __PointerAdjustment)); Internal.ctor_0((__Instance + __PointerAdjustment));
@ -3060,10 +3076,13 @@ namespace CppSharp
public LayoutField(CppSharp.Parser.AST.LayoutField _0) public LayoutField(CppSharp.Parser.AST.LayoutField _0)
{ {
__Instance = Marshal.AllocHGlobal(16); __Instance = Marshal.AllocHGlobal(64);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
*((LayoutField.Internal*) __Instance) = *((LayoutField.Internal*) _0.__Instance); if (ReferenceEquals(_0, null))
throw new global::System.ArgumentNullException("_0", "Cannot be null because it is a C++ reference (&).");
var __arg0 = _0.__Instance;
Internal.cctor_1((__Instance + __PointerAdjustment), __arg0);
} }
public void Dispose() public void Dispose()
@ -3080,6 +3099,40 @@ namespace CppSharp
Marshal.FreeHGlobal(__Instance); Marshal.FreeHGlobal(__Instance);
} }
public string Name
{
get
{
var __ret = Internal.getName_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
}
set
{
var __arg0 = Marshal.StringToHGlobalAnsi(value);
Internal.setName_0((__Instance + __PointerAdjustment), __arg0);
Marshal.FreeHGlobal(__arg0);
}
}
public CppSharp.Parser.AST.DeclarationContext _Namespace
{
get
{
CppSharp.Parser.AST.DeclarationContext __result0;
if (((Internal*) __Instance)->_Namespace == IntPtr.Zero) __result0 = null;
else if (CppSharp.Parser.AST.DeclarationContext.NativeToManagedMap.ContainsKey(((Internal*) __Instance)->_Namespace))
__result0 = (CppSharp.Parser.AST.DeclarationContext) CppSharp.Parser.AST.DeclarationContext.NativeToManagedMap[((Internal*) __Instance)->_Namespace];
else __result0 = CppSharp.Parser.AST.DeclarationContext.__CreateInstance(((Internal*) __Instance)->_Namespace);
return __result0;
}
set
{
((Internal*) __Instance)->_Namespace = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance;
}
}
public uint Offset public uint Offset
{ {
get get
@ -3093,21 +3146,29 @@ namespace CppSharp
} }
} }
public CppSharp.Parser.AST.Field Field public CppSharp.Parser.AST.QualifiedType QualifiedType
{ {
get get
{ {
CppSharp.Parser.AST.Field __result0; return CppSharp.Parser.AST.QualifiedType.__CreateInstance(((Internal*) __Instance)->QualifiedType);
if (((Internal*) __Instance)->Field == IntPtr.Zero) __result0 = null; }
else if (CppSharp.Parser.AST.Field.NativeToManagedMap.ContainsKey(((Internal*) __Instance)->Field))
__result0 = (CppSharp.Parser.AST.Field) CppSharp.Parser.AST.Field.NativeToManagedMap[((Internal*) __Instance)->Field]; set
else __result0 = CppSharp.Parser.AST.Field.__CreateInstance(((Internal*) __Instance)->Field); {
return __result0; ((Internal*) __Instance)->QualifiedType = ReferenceEquals(value, null) ? new CppSharp.Parser.AST.QualifiedType.Internal() : *(CppSharp.Parser.AST.QualifiedType.Internal*) (value.__Instance);
}
}
public global::System.IntPtr FieldPtr
{
get
{
return ((Internal*) __Instance)->FieldPtr;
} }
set set
{ {
((Internal*) __Instance)->Field = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance; ((Internal*) __Instance)->FieldPtr = (global::System.IntPtr) value;
} }
} }
} }

93
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs

@ -2986,14 +2986,20 @@ namespace CppSharp
public unsafe partial class LayoutField : IDisposable public unsafe partial class LayoutField : IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 16)] [StructLayout(LayoutKind.Explicit, Size = 48)]
public partial struct Internal public partial struct Internal
{ {
[FieldOffset(0)] [FieldOffset(0)]
public uint Offset; public global::System.IntPtr _Namespace;
[FieldOffset(8)] [FieldOffset(8)]
public global::System.IntPtr Field; public uint Offset;
[FieldOffset(24)]
public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType;
[FieldOffset(40)]
public global::System.IntPtr FieldPtr;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
@ -3009,6 +3015,16 @@ namespace CppSharp
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldD2Ev")] EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldD2Ev")]
internal static extern void dtor_0(global::System.IntPtr instance); internal static extern void dtor_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutField7getNameEv")]
internal static extern global::System.IntPtr getName_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutField7setNameEPKc")]
internal static extern void setName_0(global::System.IntPtr instance, global::System.IntPtr s);
} }
public global::System.IntPtr __Instance { get; protected set; } public global::System.IntPtr __Instance { get; protected set; }
@ -3031,8 +3047,8 @@ namespace CppSharp
private static void* __CopyValue(LayoutField.Internal native) private static void* __CopyValue(LayoutField.Internal native)
{ {
var ret = Marshal.AllocHGlobal(16); var ret = Marshal.AllocHGlobal(48);
*(LayoutField.Internal*) ret = native; CppSharp.Parser.AST.LayoutField.Internal.cctor_1(ret, new global::System.IntPtr(&native));
return ret.ToPointer(); return ret.ToPointer();
} }
@ -3052,7 +3068,7 @@ namespace CppSharp
public LayoutField() public LayoutField()
{ {
__Instance = Marshal.AllocHGlobal(16); __Instance = Marshal.AllocHGlobal(48);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
Internal.ctor_0((__Instance + __PointerAdjustment)); Internal.ctor_0((__Instance + __PointerAdjustment));
@ -3060,10 +3076,13 @@ namespace CppSharp
public LayoutField(CppSharp.Parser.AST.LayoutField _0) public LayoutField(CppSharp.Parser.AST.LayoutField _0)
{ {
__Instance = Marshal.AllocHGlobal(16); __Instance = Marshal.AllocHGlobal(48);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
*((LayoutField.Internal*) __Instance) = *((LayoutField.Internal*) _0.__Instance); if (ReferenceEquals(_0, null))
throw new global::System.ArgumentNullException("_0", "Cannot be null because it is a C++ reference (&).");
var __arg0 = _0.__Instance;
Internal.cctor_1((__Instance + __PointerAdjustment), __arg0);
} }
public void Dispose() public void Dispose()
@ -3080,6 +3099,40 @@ namespace CppSharp
Marshal.FreeHGlobal(__Instance); Marshal.FreeHGlobal(__Instance);
} }
public string Name
{
get
{
var __ret = Internal.getName_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
}
set
{
var __arg0 = Marshal.StringToHGlobalAnsi(value);
Internal.setName_0((__Instance + __PointerAdjustment), __arg0);
Marshal.FreeHGlobal(__arg0);
}
}
public CppSharp.Parser.AST.DeclarationContext _Namespace
{
get
{
CppSharp.Parser.AST.DeclarationContext __result0;
if (((Internal*) __Instance)->_Namespace == IntPtr.Zero) __result0 = null;
else if (CppSharp.Parser.AST.DeclarationContext.NativeToManagedMap.ContainsKey(((Internal*) __Instance)->_Namespace))
__result0 = (CppSharp.Parser.AST.DeclarationContext) CppSharp.Parser.AST.DeclarationContext.NativeToManagedMap[((Internal*) __Instance)->_Namespace];
else __result0 = CppSharp.Parser.AST.DeclarationContext.__CreateInstance(((Internal*) __Instance)->_Namespace);
return __result0;
}
set
{
((Internal*) __Instance)->_Namespace = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance;
}
}
public uint Offset public uint Offset
{ {
get get
@ -3093,21 +3146,29 @@ namespace CppSharp
} }
} }
public CppSharp.Parser.AST.Field Field public CppSharp.Parser.AST.QualifiedType QualifiedType
{ {
get get
{ {
CppSharp.Parser.AST.Field __result0; return CppSharp.Parser.AST.QualifiedType.__CreateInstance(((Internal*) __Instance)->QualifiedType);
if (((Internal*) __Instance)->Field == IntPtr.Zero) __result0 = null; }
else if (CppSharp.Parser.AST.Field.NativeToManagedMap.ContainsKey(((Internal*) __Instance)->Field))
__result0 = (CppSharp.Parser.AST.Field) CppSharp.Parser.AST.Field.NativeToManagedMap[((Internal*) __Instance)->Field]; set
else __result0 = CppSharp.Parser.AST.Field.__CreateInstance(((Internal*) __Instance)->Field); {
return __result0; ((Internal*) __Instance)->QualifiedType = ReferenceEquals(value, null) ? new CppSharp.Parser.AST.QualifiedType.Internal() : *(CppSharp.Parser.AST.QualifiedType.Internal*) (value.__Instance);
}
}
public global::System.IntPtr FieldPtr
{
get
{
return ((Internal*) __Instance)->FieldPtr;
} }
set set
{ {
((Internal*) __Instance)->Field = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance; ((Internal*) __Instance)->FieldPtr = (global::System.IntPtr) value;
} }
} }
} }

93
src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/AST.cs

@ -2987,14 +2987,20 @@ namespace CppSharp
public unsafe partial class LayoutField : IDisposable public unsafe partial class LayoutField : IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 16)] [StructLayout(LayoutKind.Explicit, Size = 72)]
public partial struct Internal public partial struct Internal
{ {
[FieldOffset(0)] [FieldOffset(0)]
public uint Offset; public global::System.IntPtr _Namespace;
[FieldOffset(8)] [FieldOffset(8)]
public global::System.IntPtr Field; public uint Offset;
[FieldOffset(48)]
public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType;
[FieldOffset(64)]
public global::System.IntPtr FieldPtr;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
@ -3010,6 +3016,16 @@ namespace CppSharp
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="??1LayoutField@AST@CppParser@CppSharp@@QEAA@XZ")] EntryPoint="??1LayoutField@AST@CppParser@CppSharp@@QEAA@XZ")]
internal static extern void dtor_0(global::System.IntPtr instance, int delete); internal static extern void dtor_0(global::System.IntPtr instance, int delete);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="?getName@LayoutField@AST@CppParser@CppSharp@@QEAAPEBDXZ")]
internal static extern global::System.IntPtr getName_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="?setName@LayoutField@AST@CppParser@CppSharp@@QEAAXPEBD@Z")]
internal static extern void setName_0(global::System.IntPtr instance, global::System.IntPtr s);
} }
public global::System.IntPtr __Instance { get; protected set; } public global::System.IntPtr __Instance { get; protected set; }
@ -3032,8 +3048,8 @@ namespace CppSharp
private static void* __CopyValue(LayoutField.Internal native) private static void* __CopyValue(LayoutField.Internal native)
{ {
var ret = Marshal.AllocHGlobal(16); var ret = Marshal.AllocHGlobal(72);
*(LayoutField.Internal*) ret = native; CppSharp.Parser.AST.LayoutField.Internal.cctor_1(ret, new global::System.IntPtr(&native));
return ret.ToPointer(); return ret.ToPointer();
} }
@ -3053,7 +3069,7 @@ namespace CppSharp
public LayoutField() public LayoutField()
{ {
__Instance = Marshal.AllocHGlobal(16); __Instance = Marshal.AllocHGlobal(72);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
Internal.ctor_0((__Instance + __PointerAdjustment)); Internal.ctor_0((__Instance + __PointerAdjustment));
@ -3061,10 +3077,13 @@ namespace CppSharp
public LayoutField(CppSharp.Parser.AST.LayoutField _0) public LayoutField(CppSharp.Parser.AST.LayoutField _0)
{ {
__Instance = Marshal.AllocHGlobal(16); __Instance = Marshal.AllocHGlobal(72);
__ownsNativeInstance = true; __ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this; NativeToManagedMap[__Instance] = this;
*((LayoutField.Internal*) __Instance) = *((LayoutField.Internal*) _0.__Instance); if (ReferenceEquals(_0, null))
throw new global::System.ArgumentNullException("_0", "Cannot be null because it is a C++ reference (&).");
var __arg0 = _0.__Instance;
Internal.cctor_1((__Instance + __PointerAdjustment), __arg0);
} }
public void Dispose() public void Dispose()
@ -3081,6 +3100,40 @@ namespace CppSharp
Marshal.FreeHGlobal(__Instance); Marshal.FreeHGlobal(__Instance);
} }
public string Name
{
get
{
var __ret = Internal.getName_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
}
set
{
var __arg0 = Marshal.StringToHGlobalAnsi(value);
Internal.setName_0((__Instance + __PointerAdjustment), __arg0);
Marshal.FreeHGlobal(__arg0);
}
}
public CppSharp.Parser.AST.DeclarationContext _Namespace
{
get
{
CppSharp.Parser.AST.DeclarationContext __result0;
if (((Internal*) __Instance)->_Namespace == IntPtr.Zero) __result0 = null;
else if (CppSharp.Parser.AST.DeclarationContext.NativeToManagedMap.ContainsKey(((Internal*) __Instance)->_Namespace))
__result0 = (CppSharp.Parser.AST.DeclarationContext) CppSharp.Parser.AST.DeclarationContext.NativeToManagedMap[((Internal*) __Instance)->_Namespace];
else __result0 = CppSharp.Parser.AST.DeclarationContext.__CreateInstance(((Internal*) __Instance)->_Namespace);
return __result0;
}
set
{
((Internal*) __Instance)->_Namespace = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance;
}
}
public uint Offset public uint Offset
{ {
get get
@ -3094,21 +3147,29 @@ namespace CppSharp
} }
} }
public CppSharp.Parser.AST.Field Field public CppSharp.Parser.AST.QualifiedType QualifiedType
{ {
get get
{ {
CppSharp.Parser.AST.Field __result0; return CppSharp.Parser.AST.QualifiedType.__CreateInstance(((Internal*) __Instance)->QualifiedType);
if (((Internal*) __Instance)->Field == IntPtr.Zero) __result0 = null; }
else if (CppSharp.Parser.AST.Field.NativeToManagedMap.ContainsKey(((Internal*) __Instance)->Field))
__result0 = (CppSharp.Parser.AST.Field) CppSharp.Parser.AST.Field.NativeToManagedMap[((Internal*) __Instance)->Field]; set
else __result0 = CppSharp.Parser.AST.Field.__CreateInstance(((Internal*) __Instance)->Field); {
return __result0; ((Internal*) __Instance)->QualifiedType = ReferenceEquals(value, null) ? new CppSharp.Parser.AST.QualifiedType.Internal() : *(CppSharp.Parser.AST.QualifiedType.Internal*) (value.__Instance);
}
}
public global::System.IntPtr FieldPtr
{
get
{
return ((Internal*) __Instance)->FieldPtr;
} }
set set
{ {
((Internal*) __Instance)->Field = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance; ((Internal*) __Instance)->FieldPtr = (global::System.IntPtr) value;
} }
} }
} }

54
src/CppParser/Parser.cpp

@ -82,6 +82,17 @@ std::string GetCurrentLibraryDir()
#endif #endif
} }
LayoutField Parser::WalkVTablePointer(Class* Class,
const clang::CharUnits& Offset, const std::string& prefix)
{
LayoutField LayoutField;
LayoutField.Offset = Offset.getQuantity();
LayoutField._Namespace = Class;
LayoutField.Name = prefix + "_" + Class->Name;
LayoutField.QualifiedType = GetQualifiedType(C->getASTContext().VoidPtrTy);
return LayoutField;
}
void Parser::ReadLayoutFields(Class* Class, const clang::RecordDecl* RD, void Parser::ReadLayoutFields(Class* Class, const clang::RecordDecl* RD,
clang::CharUnits Offset, bool IncludeVirtualBases) clang::CharUnits Offset, bool IncludeVirtualBases)
{ {
@ -90,8 +101,26 @@ void Parser::ReadLayoutFields(Class* Class, const clang::RecordDecl *RD,
const auto &Layout = C->getASTContext().getASTRecordLayout(RD); const auto &Layout = C->getASTContext().getASTRecordLayout(RD);
auto CXXRD = dyn_cast<CXXRecordDecl>(RD); auto CXXRD = dyn_cast<CXXRecordDecl>(RD);
auto Parent = static_cast<AST::Class*>(
WalkDeclaration(RD, /*IgnoreSystemDecls =*/false));
// Dump bases. // Dump bases.
if (CXXRD) { if (CXXRD) {
const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
bool HasOwnVFPtr = Layout.hasOwnVFPtr();
bool HasOwnVBPtr = Layout.hasOwnVBPtr();
// Vtable pointer.
if (CXXRD->isDynamicClass() && !PrimaryBase &&
!C->getASTContext().getTargetInfo().getCXXABI().isMicrosoft()) {
auto VPtr = WalkVTablePointer(Parent, Offset, "vptr");
Class->Layout->Fields.push_back(VPtr);
}
else if (HasOwnVFPtr) {
auto VTPtr = WalkVTablePointer(Parent, Offset, "vfptr");
Class->Layout->Fields.push_back(VTPtr);
}
// Collect nvbases. // Collect nvbases.
SmallVector<const CXXRecordDecl *, 4> Bases; SmallVector<const CXXRecordDecl *, 4> Bases;
for (const CXXBaseSpecifier &Base : CXXRD->bases()) { for (const CXXBaseSpecifier &Base : CXXRD->bases()) {
@ -113,30 +142,39 @@ void Parser::ReadLayoutFields(Class* Class, const clang::RecordDecl *RD,
ReadLayoutFields(Class, Base, BaseOffset, ReadLayoutFields(Class, Base, BaseOffset,
/*IncludeVirtualBases=*/false); /*IncludeVirtualBases=*/false);
} }
// vbptr (for Microsoft C++ ABI)
if (HasOwnVBPtr) {
auto VBPtr = WalkVTablePointer(Parent,
Offset + Layout.getVBPtrOffset(), "vbptr");
Class->Layout->Fields.push_back(VBPtr);
}
} }
// Dump fields. // Dump fields.
uint64_t FieldNo = 0; uint64_t FieldNo = 0;
for (RecordDecl::field_iterator I = RD->field_begin(), for (RecordDecl::field_iterator I = RD->field_begin(),
E = RD->field_end(); I != E; ++I, ++FieldNo) { E = RD->field_end(); I != E; ++I, ++FieldNo) {
const FieldDecl &Field = **I; auto Field = *I;
uint64_t LocalFieldOffsetInBits = Layout.getFieldOffset(FieldNo); uint64_t LocalFieldOffsetInBits = Layout.getFieldOffset(FieldNo);
CharUnits FieldOffset = CharUnits FieldOffset =
Offset + C->getASTContext().toCharUnitsFromBits(LocalFieldOffsetInBits); Offset + C->getASTContext().toCharUnitsFromBits(LocalFieldOffsetInBits);
// Recursively dump fields of record type. // Recursively dump fields of record type.
if (auto RT = Field.getType()->getAs<RecordType>()) if (auto RT = Field->getType()->getAs<RecordType>())
{ {
auto TU = GetTranslationUnit(RT->getDecl()); auto TU = GetTranslationUnit(RT->getDecl());
if (TU->IsSystemHeader) if (TU->IsSystemHeader)
continue; continue;
} }
auto Parent = WalkDeclaration(RD, /*IgnoreSystemDecls =*/false); auto F = WalkFieldCXX(Field, Parent);
auto F = WalkFieldCXX(&Field, static_cast<AST::Class*>(Parent));
LayoutField LayoutField; LayoutField LayoutField;
LayoutField._Namespace = F->_Namespace;
LayoutField.Offset = FieldOffset.getQuantity(); LayoutField.Offset = FieldOffset.getQuantity();
LayoutField.Field = F; LayoutField.Name = F->Name;
LayoutField.QualifiedType = GetQualifiedType(Field->getType());
LayoutField.FieldPtr = (void*)Field;
Class->Layout->Fields.push_back(LayoutField); Class->Layout->Fields.push_back(LayoutField);
} }
@ -151,6 +189,12 @@ void Parser::ReadLayoutFields(Class* Class, const clang::RecordDecl *RD,
CharUnits VBaseOffset = Offset + Layout.getVBaseClassOffset(VBase); CharUnits VBaseOffset = Offset + Layout.getVBaseClassOffset(VBase);
if (VtorDisps.find(VBase)->second.hasVtorDisp()) {
auto VtorDisp = WalkVTablePointer(Parent,
VBaseOffset - CharUnits::fromQuantity(4), "vtordisp");
Class->Layout->Fields.push_back(VtorDisp);
}
ReadLayoutFields(Class, VBase, VBaseOffset, ReadLayoutFields(Class, VBase, VBaseOffset,
/*IncludeVirtualBases=*/false); /*IncludeVirtualBases=*/false);
} }

1
src/CppParser/Parser.h

@ -99,6 +99,7 @@ private:
void WalkVTable(const clang::CXXRecordDecl* RD, Class* C); void WalkVTable(const clang::CXXRecordDecl* RD, Class* C);
QualifiedType GetQualifiedType(clang::QualType qual, clang::TypeLoc* TL = 0); QualifiedType GetQualifiedType(clang::QualType qual, clang::TypeLoc* TL = 0);
void ReadLayoutFields(Class* Class, const clang::RecordDecl* RD, clang::CharUnits Offset, bool IncludeVirtualBases); void ReadLayoutFields(Class* Class, const clang::RecordDecl* RD, clang::CharUnits Offset, bool IncludeVirtualBases);
LayoutField WalkVTablePointer(Class* Class, const clang::CharUnits& Offset, const std::string& prefix);
VTableLayout WalkVTableLayout(const clang::VTableLayout& VTLayout); VTableLayout WalkVTableLayout(const clang::VTableLayout& VTLayout);
VTableComponent WalkVTableComponent(const clang::VTableComponent& Component); VTableComponent WalkVTableComponent(const clang::VTableComponent& Component);
PreprocessedEntity* WalkPreprocessedEntity(Declaration* Decl, PreprocessedEntity* WalkPreprocessedEntity(Declaration* Decl,

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

@ -439,9 +439,9 @@ namespace CppSharp.Generators.CLI
PushIndent(); PushIndent();
// check for value types because some of the ignored fields may back properties; // check for value types because some of the ignored fields may back properties;
// not the case for ref types because the NativePtr pattern is used there // not the case for ref types because the NativePtr pattern is used there
foreach (var field in @class.Layout.Fields.Where(f => !ASTUtils.CheckIgnoreField(f.Field))) foreach (var field in @class.Fields.Where(f => !ASTUtils.CheckIgnoreField(f)))
{ {
var property = @class.Properties.FirstOrDefault(p => p.Field == field.Field); var property = @class.Properties.FirstOrDefault(p => p.Field == field);
if (property != null && !property.IsInRefTypeAndBackedByValueClassField()) if (property != null && !property.IsInRefTypeAndBackedByValueClassField())
{ {
GenerateField(@class, field); GenerateField(@class, field);
@ -450,15 +450,16 @@ namespace CppSharp.Generators.CLI
PopIndent(); PopIndent();
} }
private void GenerateField(Class @class, LayoutField layoutField) private void GenerateField(Class @class, Field field)
{ {
PushBlock(CLIBlockKind.Field, layoutField.Field); PushBlock(CLIBlockKind.Field, field);
GenerateDeclarationCommon(layoutField.Field); GenerateDeclarationCommon(field);
if (@class.IsUnion) if (@class.IsUnion)
WriteLine("[System::Runtime::InteropServices::FieldOffset({0})]", WriteLine("[System::Runtime::InteropServices::FieldOffset({0})]",
layoutField.Offset); @class.Layout.Fields.Single(
WriteLine("{0} {1};", layoutField.Field.Type, layoutField.Field.Name); f => f.Namespace == @class && f.FieldPtr == field.OriginalPtr).Offset);
WriteLine("{0} {1};", field.Type, field.Name);
PopBlock(); PopBlock();
} }
@ -630,7 +631,7 @@ namespace CppSharp.Generators.CLI
{ {
if (prop.IsInRefTypeAndBackedByValueClassField()) if (prop.IsInRefTypeAndBackedByValueClassField())
{ {
GenerateField(@class, @class.Layout.Fields.Single(f => f.Field == prop.Field)); GenerateField(@class, prop.Field);
continue; continue;
} }

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

@ -601,8 +601,6 @@ namespace CppSharp.Generators.CSharp
TypePrinter.PushContext(CSharpTypePrinterContextKind.Native); TypePrinter.PushContext(CSharpTypePrinterContextKind.Native);
if (@class.IsDynamic)
GenerateVTablePointers(@class);
foreach (var field in @class.Layout.Fields) foreach (var field in @class.Layout.Fields)
GenerateClassInternalsField(field); GenerateClassInternalsField(field);
if (@class.IsGenerated && !(@class is ClassTemplateSpecialization)) if (@class.IsGenerated && !(@class is ClassTemplateSpecialization))
@ -791,16 +789,15 @@ namespace CppSharp.Generators.CSharp
} }
} }
private void GenerateClassInternalsField(LayoutField layoutField) private void GenerateClassInternalsField(LayoutField field)
{ {
// we do not support dependent fields yet, see https://github.com/mono/CppSharp/issues/197 // we do not support dependent fields yet, see https://github.com/mono/CppSharp/issues/197
Declaration decl; Declaration decl;
var field = layoutField.Field; field.QualifiedType.Type.TryGetDeclaration(out decl);
field.Type.TryGetDeclaration(out decl);
if (decl != null && decl.TranslationUnit.IsSystemHeader) if (decl != null && decl.TranslationUnit.IsSystemHeader)
return; return;
var safeIdentifier = Helpers.SafeIdentifier(layoutField.Name); var safeIdentifier = Helpers.SafeIdentifier(field.Name);
if(safeIdentifier.All(c => c.Equals('_'))) if(safeIdentifier.All(c => c.Equals('_')))
{ {
@ -809,13 +806,13 @@ namespace CppSharp.Generators.CSharp
PushBlock(CSharpBlockKind.Field); PushBlock(CSharpBlockKind.Field);
WriteLine("[FieldOffset({0})]", layoutField.Offset); WriteLine("[FieldOffset({0})]", field.Offset);
TypePrinter.PushMarshalKind(CSharpMarshalKind.NativeField); TypePrinter.PushMarshalKind(CSharpMarshalKind.NativeField);
var fieldTypePrinted = field.QualifiedType.CSharpType(TypePrinter); var fieldTypePrinted = field.QualifiedType.CSharpType(TypePrinter);
TypePrinter.PopMarshalKind(); TypePrinter.PopMarshalKind();
var fieldType = field.Type.Desugar().IsAddress() ? var fieldType = field.QualifiedType.Type.Desugar().IsAddress() ?
CSharpTypePrinter.IntPtrType : fieldTypePrinted.Type; CSharpTypePrinter.IntPtrType : fieldTypePrinted.Type;
var fieldName = safeIdentifier; var fieldName = safeIdentifier;
@ -837,22 +834,23 @@ namespace CppSharp.Generators.CSharp
// Workaround a bug in Mono when handling fixed arrays in P/Invoke declarations. // Workaround a bug in Mono when handling fixed arrays in P/Invoke declarations.
// https://bugzilla.xamarin.com/show_bug.cgi?id=33571 // https://bugzilla.xamarin.com/show_bug.cgi?id=33571
var arrayType = field.Type.Desugar() as ArrayType; var arrayType = field.QualifiedType.Type.Desugar() as ArrayType;
if (arrayType != null && arrayType.SizeType == ArrayType.ArraySize.Constant && if (arrayType != null && arrayType.SizeType == ArrayType.ArraySize.Constant &&
arrayType.Size > 0) arrayType.Size > 0)
{ {
for (var i = 1; i < arrayType.Size; ++i) for (var i = 1; i < arrayType.Size; ++i)
{ {
var dummy = new Field var dummy = new LayoutField
{ {
Namespace = field.Namespace,
Offset = (uint) (field.Offset + i * arrayType.ElementSize / 8),
QualifiedType = new QualifiedType(arrayType.Type),
Name = string.Format("{0}_{1}_{2}", Helpers.DummyIdentifier, Name = string.Format("{0}_{1}_{2}", Helpers.DummyIdentifier,
safeIdentifier, i), safeIdentifier, i),
QualifiedType = new QualifiedType(arrayType.Type), FieldPtr = field.FieldPtr
Namespace = field.Namespace
}; };
GenerateClassInternalsField(new LayoutField( GenerateClassInternalsField(dummy);
(uint) (layoutField.Offset + i * arrayType.ElementSize / 8), dummy));
} }
} }
} }
@ -975,7 +973,7 @@ namespace CppSharp.Generators.CSharp
} }
else else
{ {
var name = @class.Layout.Fields.First(f => f.Field == field).Name; var name = @class.Layout.Fields.First(f => f.FieldPtr == field.OriginalPtr).Name;
ctx.ReturnVarName = string.Format("{0}{1}{2}", ctx.ReturnVarName = string.Format("{0}{1}{2}",
@class.IsValueType @class.IsValueType
? Helpers.InstanceField ? Helpers.InstanceField
@ -1027,7 +1025,8 @@ namespace CppSharp.Generators.CSharp
type = originalType.ToString(); type = originalType.ToString();
} }
var name = ((Class) field.Namespace).Layout.Fields.First(f => f.Field == field).Name; var name = ((Class) field.Namespace).Layout.Fields.First(
f => f.FieldPtr == field.OriginalPtr).Name;
WriteLine(string.Format("fixed ({0} {1} = {2}.{3})", WriteLine(string.Format("fixed ({0} {1} = {2}.{3})",
type, arrPtrIden, Helpers.InstanceField, Helpers.SafeIdentifier(name))); type, arrPtrIden, Helpers.InstanceField, Helpers.SafeIdentifier(name)));
WriteStartBraceIndent(); WriteStartBraceIndent();
@ -1118,7 +1117,7 @@ namespace CppSharp.Generators.CSharp
NewLine(); NewLine();
WriteStartBraceIndent(); WriteStartBraceIndent();
var name = @class.Layout.Fields.First(f => f.Field == field).Name; var name = @class.Layout.Fields.First(f => f.FieldPtr == field.OriginalPtr).Name;
var ctx = new CSharpMarshalContext(Driver) var ctx = new CSharpMarshalContext(Driver)
{ {
Kind = CSharpMarshalKind.NativeField, Kind = CSharpMarshalKind.NativeField,
@ -1300,7 +1299,7 @@ namespace CppSharp.Generators.CSharp
ArrayType arrayType = prop.Type as ArrayType; ArrayType arrayType = prop.Type as ArrayType;
if (arrayType != null && arrayType.Type.IsPointerToPrimitiveType() && prop.Field != null) if (arrayType != null && arrayType.Type.IsPointerToPrimitiveType() && prop.Field != null)
{ {
var name = @class.Layout.Fields.First(f => f.Field == prop.Field).Name; var name = @class.Layout.Fields.First(f => f.FieldPtr == prop.Field.OriginalPtr).Name;
GenerateClassField(prop.Field); GenerateClassField(prop.Field);
WriteLine("private bool {0};", WriteLine("private bool {0};",
GeneratedIdentifier(string.Format("{0}Initialised", name))); GeneratedIdentifier(string.Format("{0}Initialised", name)));
@ -1443,7 +1442,7 @@ namespace CppSharp.Generators.CSharp
WriteLine("var native = (Internal*) {0}.ToPointer();", Helpers.InstanceIdentifier); WriteLine("var native = (Internal*) {0}.ToPointer();", Helpers.InstanceIdentifier);
NewLine(); NewLine();
SaveOriginalVTablePointers(@class.Layout.VFTables); SaveOriginalVTablePointers(@class.Layout.VTablePointers);
NewLine(); NewLine();
@ -1510,13 +1509,16 @@ namespace CppSharp.Generators.CSharp
AllocateNewVTablesItanium(@class, wrappedEntries, destructorOnly); AllocateNewVTablesItanium(@class, wrappedEntries, destructorOnly);
} }
private void SaveOriginalVTablePointers(IEnumerable<VFTableInfo> vfTables) private void SaveOriginalVTablePointers(IList<LayoutField> vTablePtrs)
{ {
if (Driver.Options.IsMicrosoftAbi) if (Driver.Options.IsMicrosoftAbi)
WriteLine("__OriginalVTables = new void*[] {{ {0} }};", WriteLine("__OriginalVTables = new void*[] {{ {0} }};",
string.Join(", ", vfTables.Select((v, i) => string.Format("((Internal*) native)->vfptr{0}.ToPointer()", i)))); string.Join(", ",
vTablePtrs.Select(v => string.Format("((Internal*) native)->{0}.ToPointer()", v.Name))));
else else
WriteLine("__OriginalVTables = new void*[] { ((Internal*) native)->vfptr0.ToPointer() };"); WriteLine(
"__OriginalVTables = new void*[] {{ ((Internal*) native)->{0}.ToPointer() }};",
vTablePtrs[0].Name);
} }
private void AllocateNewVTablesMS(Class @class, IList<VTableComponent> wrappedEntries, private void AllocateNewVTablesMS(Class @class, IList<VTableComponent> wrappedEntries,
@ -1525,23 +1527,24 @@ namespace CppSharp.Generators.CSharp
var managedVTables = destructorOnly ? "__ManagedVTablesDtorOnly" : "__ManagedVTables"; var managedVTables = destructorOnly ? "__ManagedVTablesDtorOnly" : "__ManagedVTables";
WriteLine("{0} = new void*[{1}];", managedVTables, @class.Layout.VFTables.Count); WriteLine("{0} = new void*[{1}];", managedVTables, @class.Layout.VFTables.Count);
for (int tableIndex = 0; tableIndex < @class.Layout.VFTables.Count; tableIndex++) for (int i = 0; i < @class.Layout.VFTables.Count; i++)
{ {
var vfptr = @class.Layout.VFTables[tableIndex]; var vfptr = @class.Layout.VFTables[i];
var size = vfptr.Layout.Components.Count; var size = vfptr.Layout.Components.Count;
WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});", WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});",
tableIndex, size, Driver.TargetInfo.PointerWidth / 8); i, size, Driver.TargetInfo.PointerWidth / 8);
WriteLine("{0}[{1}] = vfptr{1}.ToPointer();", managedVTables, tableIndex); WriteLine("{0}[{1}] = vfptr{1}.ToPointer();", managedVTables, i);
AllocateNewVTableEntries(vfptr.Layout.Components, wrappedEntries, tableIndex, AllocateNewVTableEntries(vfptr.Layout.Components, wrappedEntries,
destructorOnly); @class.Layout.VTablePointers[i].Name, i, destructorOnly);
} }
WriteCloseBraceIndent(); WriteCloseBraceIndent();
NewLine(); NewLine();
for (var i = 0; i < @class.Layout.VFTables.Count; i++) for (int i = 0; i < @class.Layout.VTablePointers.Count; i++)
WriteLine("native->vfptr{0} = new IntPtr({1}[{0}]);", i, managedVTables); WriteLine("native->{0} = new IntPtr({1}[{2}]);",
@class.Layout.VTablePointers[i].Name, managedVTables, i);
} }
private void AllocateNewVTablesItanium(Class @class, IList<VTableComponent> wrappedEntries, private void AllocateNewVTablesItanium(Class @class, IList<VTableComponent> wrappedEntries,
@ -1558,16 +1561,17 @@ namespace CppSharp.Generators.CSharp
WriteLine("{0}[0] = vfptr0.ToPointer();", managedVTables); WriteLine("{0}[0] = vfptr0.ToPointer();", managedVTables);
AllocateNewVTableEntries(@class.Layout.Layout.Components, AllocateNewVTableEntries(@class.Layout.Layout.Components,
wrappedEntries, 0, destructorOnly); wrappedEntries, @class.Layout.VTablePointers[0].Name, 0, destructorOnly);
WriteCloseBraceIndent(); WriteCloseBraceIndent();
NewLine(); NewLine();
WriteLine("native->vfptr0 = new IntPtr({0}[0]);", managedVTables); WriteLine("native->{0} = new IntPtr({1}[0]);",
@class.Layout.VTablePointers[0].Name, managedVTables);
} }
private void AllocateNewVTableEntries(IList<VTableComponent> entries, private void AllocateNewVTableEntries(IList<VTableComponent> entries,
IList<VTableComponent> wrappedEntries, int tableIndex, bool destructorOnly) IList<VTableComponent> wrappedEntries, string vptr, int tableIndex, bool destructorOnly)
{ {
var pointerSize = Driver.TargetInfo.PointerWidth / 8; var pointerSize = Driver.TargetInfo.PointerWidth / 8;
for (var i = 0; i < entries.Count; i++) for (var i = 0; i < entries.Count; i++)
@ -1576,7 +1580,7 @@ namespace CppSharp.Generators.CSharp
var offset = pointerSize var offset = pointerSize
* (i - (Options.IsMicrosoftAbi ? 0 : VTables.ItaniumOffsetToTopAndRTTI)); * (i - (Options.IsMicrosoftAbi ? 0 : VTables.ItaniumOffsetToTopAndRTTI));
var nativeVftableEntry = string.Format("*(void**)(native->vfptr{0} + {1})", tableIndex, offset); var nativeVftableEntry = string.Format("*(void**)(native->{0} + {1})", vptr, offset);
var managedVftableEntry = string.Format("*(void**)(vfptr{0} + {1})", tableIndex, offset); var managedVftableEntry = string.Format("*(void**)(vfptr{0} + {1})", tableIndex, offset);
if ((entry.Kind == VTableComponentKind.FunctionPointer || if ((entry.Kind == VTableComponentKind.FunctionPointer ||
@ -1761,32 +1765,6 @@ namespace CppSharp.Generators.CSharp
return string.Format("_{0}Delegate", nativeId); return string.Format("_{0}Delegate", nativeId);
} }
public void GenerateVTablePointers(Class @class)
{
if (Options.IsMicrosoftAbi)
{
var index = 0;
foreach (var info in @class.Layout.VFTables)
{
PushBlock(CSharpBlockKind.InternalsClassField);
WriteLine("[FieldOffset({0})]", info.VFPtrFullOffset);
WriteLine("public global::System.IntPtr vfptr{0};", index++);
PopBlock(NewLineKind.BeforeNextBlock);
}
}
else
{
PushBlock(CSharpBlockKind.InternalsClassField);
WriteLine("[FieldOffset(0)]");
WriteLine("public global::System.IntPtr vfptr0;");
PopBlock(NewLineKind.BeforeNextBlock);
}
}
#endregion #endregion
#region Events #region Events
@ -1994,12 +1972,12 @@ namespace CppSharp.Generators.CSharp
if (@class.IsDynamic && GetUniqueVTableMethodEntries(@class).Count != 0) if (@class.IsDynamic && GetUniqueVTableMethodEntries(@class).Count != 0)
{ {
if (Options.IsMicrosoftAbi) if (Options.IsMicrosoftAbi)
for (var i = 0; i < @class.Layout.VFTables.Count; i++) for (var i = 0; i < @class.Layout.VTablePointers.Count; i++)
WriteLine("((Internal*) {0})->vfptr{1} = new global::System.IntPtr(__OriginalVTables[{1}]);", WriteLine("((Internal*) {0})->{1} = new global::System.IntPtr(__OriginalVTables[{2}]);",
Helpers.InstanceIdentifier, i); Helpers.InstanceIdentifier, @class.Layout.VTablePointers[i].Name, i);
else else
WriteLine("((Internal*) {0})->vfptr0 = new global::System.IntPtr(__OriginalVTables[0]);", WriteLine("((Internal*) {0})->{1} = new global::System.IntPtr(__OriginalVTables[0]);",
Helpers.InstanceIdentifier); Helpers.InstanceIdentifier, @class.Layout.VTablePointers[0].Name);
} }
} }
@ -2095,7 +2073,7 @@ namespace CppSharp.Generators.CSharp
} }
if (@class.IsAbstractImpl || hasVTables) if (@class.IsAbstractImpl || hasVTables)
SaveOriginalVTablePointers(@class.Layout.VFTables); SaveOriginalVTablePointers(@class.Layout.VTablePointers);
if (setupVTables) if (setupVTables)
{ {

4
src/Generator/Passes/CheckDuplicatedNamesPass.cs

@ -169,11 +169,11 @@ namespace CppSharp.Passes
if (!@class.IsDependent) if (!@class.IsDependent)
{ {
foreach (var fields in @class.Layout.Fields.GroupBy( foreach (var fields in @class.Layout.Fields.GroupBy(
f => f.Field.OriginalName).Select(g => g.ToList())) f => f.Name).Select(g => g.ToList()))
{ {
for (var i = 1; i < fields.Count; i++) for (var i = 1; i < fields.Count; i++)
{ {
var name = fields[i].Field.OriginalName; var name = fields[i].Name;
fields[i].Name = (string.IsNullOrEmpty(name) ? "__" : name) + i; fields[i].Name = (string.IsNullOrEmpty(name) ? "__" : name) + i;
} }
} }

4
src/Generator/Passes/CleanInvalidDeclNamesPass.cs

@ -63,6 +63,10 @@ namespace CppSharp.Passes
base.VisitClassDecl(@class); base.VisitClassDecl(@class);
uniqueName = currentUniqueName; uniqueName = currentUniqueName;
if (!@class.IsDependent)
foreach (var field in @class.Layout.Fields.Where(f => string.IsNullOrEmpty(f.Name)))
field.Name = @class.Name == "_" ? "__" : "_";
if (@class is ClassTemplateSpecialization && if (@class is ClassTemplateSpecialization &&
!(from c in @class.Namespace.Classes !(from c in @class.Namespace.Classes
where c.Name == @class.Name && !(@class is ClassTemplateSpecialization) && where c.Name == @class.Name && !(@class is ClassTemplateSpecialization) &&

Loading…
Cancel
Save