diff --git a/src/AST/ClassLayout.cs b/src/AST/ClassLayout.cs index 1377f37e..f11ac20c 100644 --- a/src/AST/ClassLayout.cs +++ b/src/AST/ClassLayout.cs @@ -85,8 +85,11 @@ namespace CppSharp.AST public ClassLayout() { VFTables = new List(); + Fields = new List(); } + public List Fields { get; private set; } + public ClassLayout(ClassLayout classLayout) : this() { diff --git a/src/AST/Field.cs b/src/AST/Field.cs index 8078fd3c..71b86c63 100644 --- a/src/AST/Field.cs +++ b/src/AST/Field.cs @@ -8,29 +8,16 @@ namespace CppSharp.AST public Type Type { get { return QualifiedType.Type; } } public QualifiedType QualifiedType { get; set; } - public uint Offset { get; set; } public Class Class { get; set; } - public uint OffsetInBytes - { - get { return Offset / (sizeof (byte) * 8); } - } - public Expression Expression { get; set; } public bool IsBitField { get; set; } public uint BitWidth { get; set; } - public string InternalName - { - get { return internalName ?? (internalName = OriginalName); } - set { internalName = value; } - } - public Field() { - Offset = 0; } public Field(string name, QualifiedType type, AccessSpecifier access) @@ -38,13 +25,11 @@ namespace CppSharp.AST Name = name; QualifiedType = type; Access = access; - Offset = 0; } public Field(Field field): base(field) { QualifiedType = field.QualifiedType; - Offset = field.Offset; Class = field.Class; Expression = field.Expression; IsBitField = field.IsBitField; @@ -55,7 +40,5 @@ namespace CppSharp.AST { return visitor.VisitFieldDecl(this); } - - private string internalName; } } \ No newline at end of file diff --git a/src/AST/LayoutField.cs b/src/AST/LayoutField.cs new file mode 100644 index 00000000..95f2bb67 --- /dev/null +++ b/src/AST/LayoutField.cs @@ -0,0 +1,28 @@ +namespace CppSharp.AST +{ + public class LayoutField + { + public LayoutField(uint offset, Field field) + { + Field = field; + Offset = offset; + } + + public uint Offset { get; set; } + + public string Name + { + get { return name ?? Field.OriginalName; } + set { name = value; } + } + + public Field Field { get; set; } + + public override string ToString() + { + return string.Format("{0} | {1}", Offset, Field.OriginalName); + } + + private string name; + } +} \ No newline at end of file diff --git a/src/Core/Parser/ASTConverter.cs b/src/Core/Parser/ASTConverter.cs index b80fca6f..4d8544c4 100644 --- a/src/Core/Parser/ASTConverter.cs +++ b/src/Core/Parser/ASTConverter.cs @@ -1255,7 +1255,6 @@ namespace CppSharp _field.QualifiedType = typeConverter.VisitQualified( decl.QualifiedType); _field.Access = VisitAccessSpecifier(decl.Access); - _field.Offset = decl.Offset; _field.Class = Visit(decl.Class) as AST.Class; _field.IsBitField = decl.IsBitField; _field.BitWidth = decl.BitWidth; @@ -1346,6 +1345,13 @@ namespace CppSharp _layout.VFTables.Add(_vftableInfo); } + for (uint i = 0; i < layout.FieldsCount; i++) + { + var field = layout.getFields(i); + _layout.Fields.Add(new AST.LayoutField(field.Offset, + (AST.Field) Visit(field.Field))); + } + return _layout; } diff --git a/src/CppParser/AST.cpp b/src/CppParser/AST.cpp index b4f82ee6..2465e815 100644 --- a/src/CppParser/AST.cpp +++ b/src/CppParser/AST.cpp @@ -189,11 +189,17 @@ VFTableInfo::VFTableInfo(const VFTableInfo& rhs) : VBTableIndex(rhs.VBTableIndex VFPtrOffset(rhs.VFPtrOffset), VFPtrFullOffset(rhs.VFPtrFullOffset), Layout(rhs.Layout) {} +LayoutField::LayoutField() {} + +LayoutField::~LayoutField() {} + ClassLayout::ClassLayout() : ABI(CppAbi::Itanium), HasOwnVFPtr(false), VBPtrOffset(0), Alignment(0), Size(0), DataSize(0) {} DEF_VECTOR(ClassLayout, VFTableInfo, VFTables) +DEF_VECTOR(ClassLayout, LayoutField, Fields) + Declaration::Declaration(DeclarationKind kind) : Kind(kind) , Access(AccessSpecifier::Public) @@ -650,7 +656,7 @@ DEF_STRING(Variable, Mangled) BaseClassSpecifier::BaseClassSpecifier() : Type(0), Offset(0) {} Field::Field() : Declaration(DeclarationKind::Field), Class(0), - IsBitField(false), BitWidth(0), Offset(0) {} + IsBitField(false), BitWidth(0) {} Field::~Field() {} diff --git a/src/CppParser/AST.h b/src/CppParser/AST.h index 25b1cbd8..ff1141d2 100644 --- a/src/CppParser/AST.h +++ b/src/CppParser/AST.h @@ -315,6 +315,17 @@ struct CS_API VFTableInfo VTableLayout Layout; }; +class Field; + +class CS_API LayoutField +{ +public: + LayoutField(); + ~LayoutField(); + unsigned Offset; + Field* Field; +}; + struct CS_API ClassLayout { ClassLayout(); @@ -326,6 +337,7 @@ struct CS_API ClassLayout int Alignment; int Size; int DataSize; + VECTOR(LayoutField, Fields) }; #pragma endregion @@ -706,7 +718,6 @@ public: DECLARE_DECL_KIND(Field, Field) ~Field(); CppSharp::CppParser::AST::QualifiedType QualifiedType; - unsigned Offset; CppSharp::CppParser::AST::Class* Class; bool IsBitField; unsigned BitWidth; diff --git a/src/CppParser/Bindings/CLI/AST.cpp b/src/CppParser/Bindings/CLI/AST.cpp index a844f153..049d89a8 100644 --- a/src/CppParser/Bindings/CLI/AST.cpp +++ b/src/CppParser/Bindings/CLI/AST.cpp @@ -1292,6 +1292,67 @@ void CppSharp::Parser::AST::VFTableInfo::Layout::set(CppSharp::Parser::AST::VTab ((::CppSharp::CppParser::AST::VFTableInfo*)NativePtr)->Layout = *(::CppSharp::CppParser::AST::VTableLayout*)value->NativePtr; } +CppSharp::Parser::AST::LayoutField::LayoutField(::CppSharp::CppParser::AST::LayoutField* native) + : __ownsNativeInstance(false) +{ + NativePtr = native; +} + +CppSharp::Parser::AST::LayoutField^ CppSharp::Parser::AST::LayoutField::__CreateInstance(::System::IntPtr native) +{ + return gcnew ::CppSharp::Parser::AST::LayoutField((::CppSharp::CppParser::AST::LayoutField*) native.ToPointer()); +} + +CppSharp::Parser::AST::LayoutField::~LayoutField() +{ + delete NativePtr; +} + +CppSharp::Parser::AST::LayoutField::LayoutField() +{ + __ownsNativeInstance = true; + NativePtr = new ::CppSharp::CppParser::AST::LayoutField(); +} + +CppSharp::Parser::AST::LayoutField::LayoutField(CppSharp::Parser::AST::LayoutField^ _0) +{ + __ownsNativeInstance = true; + if (ReferenceEquals(_0, nullptr)) + throw gcnew ::System::ArgumentNullException("_0", "Cannot be null because it is a C++ reference (&)."); + auto &__arg0 = *(::CppSharp::CppParser::AST::LayoutField*)_0->NativePtr; + NativePtr = new ::CppSharp::CppParser::AST::LayoutField(__arg0); +} + +System::IntPtr CppSharp::Parser::AST::LayoutField::__Instance::get() +{ + return System::IntPtr(NativePtr); +} + +void CppSharp::Parser::AST::LayoutField::__Instance::set(System::IntPtr object) +{ + NativePtr = (::CppSharp::CppParser::AST::LayoutField*)object.ToPointer(); +} + +unsigned int CppSharp::Parser::AST::LayoutField::Offset::get() +{ + return ((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->Offset; +} + +void CppSharp::Parser::AST::LayoutField::Offset::set(unsigned int value) +{ + ((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->Offset = value; +} + +CppSharp::Parser::AST::Field^ CppSharp::Parser::AST::LayoutField::Field::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); +} + +void CppSharp::Parser::AST::LayoutField::Field::set(CppSharp::Parser::AST::Field^ value) +{ + ((::CppSharp::CppParser::AST::LayoutField*)NativePtr)->Field = (::CppSharp::CppParser::AST::Field*)value->NativePtr; +} + CppSharp::Parser::AST::ClassLayout::ClassLayout(::CppSharp::CppParser::AST::ClassLayout* native) : __ownsNativeInstance(false) { @@ -1334,6 +1395,26 @@ void CppSharp::Parser::AST::ClassLayout::clearVFTables() ((::CppSharp::CppParser::AST::ClassLayout*)NativePtr)->clearVFTables(); } +CppSharp::Parser::AST::LayoutField^ CppSharp::Parser::AST::ClassLayout::getFields(unsigned int i) +{ + auto __ret = ((::CppSharp::CppParser::AST::ClassLayout*)NativePtr)->getFields(i); + auto ____ret = new ::CppSharp::CppParser::AST::LayoutField(__ret); + return (____ret == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::LayoutField((::CppSharp::CppParser::AST::LayoutField*)____ret); +} + +void CppSharp::Parser::AST::ClassLayout::addFields(CppSharp::Parser::AST::LayoutField^ s) +{ + if (ReferenceEquals(s, nullptr)) + throw gcnew ::System::ArgumentNullException("s", "Cannot be null because it is a C++ reference (&)."); + auto &__arg0 = *(::CppSharp::CppParser::AST::LayoutField*)s->NativePtr; + ((::CppSharp::CppParser::AST::ClassLayout*)NativePtr)->addFields(__arg0); +} + +void CppSharp::Parser::AST::ClassLayout::clearFields() +{ + ((::CppSharp::CppParser::AST::ClassLayout*)NativePtr)->clearFields(); +} + CppSharp::Parser::AST::ClassLayout::ClassLayout(CppSharp::Parser::AST::ClassLayout^ _0) { __ownsNativeInstance = true; @@ -1359,6 +1440,12 @@ unsigned int CppSharp::Parser::AST::ClassLayout::VFTablesCount::get() return __ret; } +unsigned int CppSharp::Parser::AST::ClassLayout::FieldsCount::get() +{ + auto __ret = ((::CppSharp::CppParser::AST::ClassLayout*)NativePtr)->getFieldsCount(); + return __ret; +} + CppSharp::Parser::AST::CppAbi CppSharp::Parser::AST::ClassLayout::ABI::get() { return (CppSharp::Parser::AST::CppAbi)((::CppSharp::CppParser::AST::ClassLayout*)NativePtr)->ABI; @@ -3064,16 +3151,6 @@ void CppSharp::Parser::AST::Field::QualifiedType::set(CppSharp::Parser::AST::Qua ((::CppSharp::CppParser::AST::Field*)NativePtr)->QualifiedType = *(::CppSharp::CppParser::AST::QualifiedType*)value->NativePtr; } -unsigned int CppSharp::Parser::AST::Field::Offset::get() -{ - return ((::CppSharp::CppParser::AST::Field*)NativePtr)->Offset; -} - -void CppSharp::Parser::AST::Field::Offset::set(unsigned int value) -{ - ((::CppSharp::CppParser::AST::Field*)NativePtr)->Offset = value; -} - CppSharp::Parser::AST::Class^ CppSharp::Parser::AST::Field::Class::get() { return (((::CppSharp::CppParser::AST::Field*)NativePtr)->Class == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::Class((::CppSharp::CppParser::AST::Class*)((::CppSharp::CppParser::AST::Field*)NativePtr)->Class); diff --git a/src/CppParser/Bindings/CLI/AST.h b/src/CppParser/Bindings/CLI/AST.h index 1115f1c9..87337aab 100644 --- a/src/CppParser/Bindings/CLI/AST.h +++ b/src/CppParser/Bindings/CLI/AST.h @@ -61,6 +61,7 @@ namespace CppSharp ref class InjectedClassNameType; ref class InlineCommandComment; ref class InlineContentComment; + ref class LayoutField; ref class MacroDefinition; ref class MacroExpansion; ref class MemberPointerType; @@ -165,14 +166,56 @@ namespace CppSharp Public = 2 }; - public enum struct CXXMethodKind + public enum struct RawCommentKind { - Normal = 0, - Constructor = 1, - Destructor = 2, - Conversion = 3, - Operator = 4, - UsingDirective = 5 + Invalid = 0, + OrdinaryBCPL = 1, + OrdinaryC = 2, + BCPLSlash = 3, + BCPLExcl = 4, + JavaDoc = 5, + Qt = 6, + Merged = 7 + }; + + public enum struct CommentKind + { + FullComment = 0, + BlockContentComment = 1, + BlockCommandComment = 2, + ParamCommandComment = 3, + TParamCommandComment = 4, + VerbatimBlockComment = 5, + VerbatimLineComment = 6, + ParagraphComment = 7, + HTMLTagComment = 8, + HTMLStartTagComment = 9, + HTMLEndTagComment = 10, + TextComment = 11, + InlineContentComment = 12, + InlineCommandComment = 13, + VerbatimBlockLineComment = 14 + }; + + public enum struct CppAbi + { + Itanium = 0, + Microsoft = 1, + ARM = 2, + iOS = 3, + iOS64 = 4 + }; + + public enum struct VTableComponentKind + { + VCallOffset = 0, + VBaseOffset = 1, + OffsetToTop = 2, + RTTI = 3, + FunctionPointer = 4, + CompleteDtorPointer = 5, + DeletingDtorPointer = 6, + UnusedFunctionPointer = 7 }; public enum struct CXXOperatorKind @@ -234,18 +277,6 @@ namespace CppSharp Unknown = 5 }; - public enum struct StatementClass - { - Any = 0, - BinaryOperator = 1, - CallExprClass = 2, - DeclRefExprClass = 3, - CXXConstructExprClass = 4, - CXXOperatorCallExpr = 5, - ImplicitCastExpr = 6, - ExplicitCastExpr = 7 - }; - public enum struct TemplateSpecializationKind { Undeclared = 0, @@ -255,25 +286,26 @@ namespace CppSharp ExplicitInstantiationDefinition = 4 }; - public enum struct CppAbi + public enum struct StatementClass { - Itanium = 0, - Microsoft = 1, - ARM = 2, - iOS = 3, - iOS64 = 4 + Any = 0, + BinaryOperator = 1, + CallExprClass = 2, + DeclRefExprClass = 3, + CXXConstructExprClass = 4, + CXXOperatorCallExpr = 5, + ImplicitCastExpr = 6, + ExplicitCastExpr = 7 }; - public enum struct VTableComponentKind + public enum struct CXXMethodKind { - VCallOffset = 0, - VBaseOffset = 1, - OffsetToTop = 2, - RTTI = 3, - FunctionPointer = 4, - CompleteDtorPointer = 5, - DeletingDtorPointer = 6, - UnusedFunctionPointer = 7 + Normal = 0, + Constructor = 1, + Destructor = 2, + Conversion = 3, + Operator = 4, + UsingDirective = 5 }; public enum struct PrimitiveType @@ -307,37 +339,6 @@ namespace CppSharp FunctionBody = 5 }; - public enum struct RawCommentKind - { - Invalid = 0, - OrdinaryBCPL = 1, - OrdinaryC = 2, - BCPLSlash = 3, - BCPLExcl = 4, - JavaDoc = 5, - Qt = 6, - Merged = 7 - }; - - public enum struct CommentKind - { - FullComment = 0, - BlockContentComment = 1, - BlockCommandComment = 2, - ParamCommandComment = 3, - TParamCommandComment = 4, - VerbatimBlockComment = 5, - VerbatimLineComment = 6, - ParagraphComment = 7, - HTMLTagComment = 8, - HTMLStartTagComment = 9, - HTMLEndTagComment = 10, - TextComment = 11, - InlineContentComment = 12, - InlineCommandComment = 13, - VerbatimBlockLineComment = 14 - }; - public enum struct ArchType { UnknownArch = 0, @@ -1026,6 +1027,41 @@ namespace CppSharp bool __ownsNativeInstance; }; + public ref class LayoutField : ICppInstance + { + public: + + property ::CppSharp::CppParser::AST::LayoutField* NativePtr; + property System::IntPtr __Instance + { + virtual System::IntPtr get(); + virtual void set(System::IntPtr instance); + } + + LayoutField(::CppSharp::CppParser::AST::LayoutField* native); + static LayoutField^ __CreateInstance(::System::IntPtr native); + LayoutField(); + + LayoutField(CppSharp::Parser::AST::LayoutField^ _0); + + ~LayoutField(); + + property unsigned int Offset + { + unsigned int get(); + void set(unsigned int); + } + + property CppSharp::Parser::AST::Field^ Field + { + CppSharp::Parser::AST::Field^ get(); + void set(CppSharp::Parser::AST::Field^); + } + + protected: + bool __ownsNativeInstance; + }; + public ref class ClassLayout : ICppInstance { public: @@ -1050,6 +1086,11 @@ namespace CppSharp unsigned int get(); } + property unsigned int FieldsCount + { + unsigned int get(); + } + property CppSharp::Parser::AST::CppAbi ABI { CppSharp::Parser::AST::CppAbi get(); @@ -1098,6 +1139,12 @@ namespace CppSharp void clearVFTables(); + CppSharp::Parser::AST::LayoutField^ getFields(unsigned int i); + + void addFields(CppSharp::Parser::AST::LayoutField^ s); + + void clearFields(); + protected: bool __ownsNativeInstance; }; @@ -1883,12 +1930,6 @@ namespace CppSharp void set(CppSharp::Parser::AST::QualifiedType^); } - property unsigned int Offset - { - unsigned int get(); - void set(unsigned int); - } - property CppSharp::Parser::AST::Class^ Class { CppSharp::Parser::AST::Class^ get(); diff --git a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs index ea4197fd..8242aa51 100644 --- a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs +++ b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs @@ -69,14 +69,56 @@ namespace CppSharp Public = 2 } - public enum CXXMethodKind + public enum RawCommentKind { - Normal = 0, - Constructor = 1, - Destructor = 2, - Conversion = 3, - Operator = 4, - UsingDirective = 5 + Invalid = 0, + OrdinaryBCPL = 1, + OrdinaryC = 2, + BCPLSlash = 3, + BCPLExcl = 4, + JavaDoc = 5, + Qt = 6, + Merged = 7 + } + + public enum CommentKind + { + FullComment = 0, + BlockContentComment = 1, + BlockCommandComment = 2, + ParamCommandComment = 3, + TParamCommandComment = 4, + VerbatimBlockComment = 5, + VerbatimLineComment = 6, + ParagraphComment = 7, + HTMLTagComment = 8, + HTMLStartTagComment = 9, + HTMLEndTagComment = 10, + TextComment = 11, + InlineContentComment = 12, + InlineCommandComment = 13, + VerbatimBlockLineComment = 14 + } + + public enum CppAbi + { + Itanium = 0, + Microsoft = 1, + ARM = 2, + iOS = 3, + iOS64 = 4 + } + + public enum VTableComponentKind + { + VCallOffset = 0, + VBaseOffset = 1, + OffsetToTop = 2, + RTTI = 3, + FunctionPointer = 4, + CompleteDtorPointer = 5, + DeletingDtorPointer = 6, + UnusedFunctionPointer = 7 } public enum CXXOperatorKind @@ -138,18 +180,6 @@ namespace CppSharp Unknown = 5 } - public enum StatementClass - { - Any = 0, - BinaryOperator = 1, - CallExprClass = 2, - DeclRefExprClass = 3, - CXXConstructExprClass = 4, - CXXOperatorCallExpr = 5, - ImplicitCastExpr = 6, - ExplicitCastExpr = 7 - } - public enum TemplateSpecializationKind { Undeclared = 0, @@ -159,25 +189,26 @@ namespace CppSharp ExplicitInstantiationDefinition = 4 } - public enum CppAbi + public enum StatementClass { - Itanium = 0, - Microsoft = 1, - ARM = 2, - iOS = 3, - iOS64 = 4 + Any = 0, + BinaryOperator = 1, + CallExprClass = 2, + DeclRefExprClass = 3, + CXXConstructExprClass = 4, + CXXOperatorCallExpr = 5, + ImplicitCastExpr = 6, + ExplicitCastExpr = 7 } - public enum VTableComponentKind + public enum CXXMethodKind { - VCallOffset = 0, - VBaseOffset = 1, - OffsetToTop = 2, - RTTI = 3, - FunctionPointer = 4, - CompleteDtorPointer = 5, - DeletingDtorPointer = 6, - UnusedFunctionPointer = 7 + Normal = 0, + Constructor = 1, + Destructor = 2, + Conversion = 3, + Operator = 4, + UsingDirective = 5 } public enum PrimitiveType @@ -211,37 +242,6 @@ namespace CppSharp FunctionBody = 5 } - public enum RawCommentKind - { - Invalid = 0, - OrdinaryBCPL = 1, - OrdinaryC = 2, - BCPLSlash = 3, - BCPLExcl = 4, - JavaDoc = 5, - Qt = 6, - Merged = 7 - } - - public enum CommentKind - { - FullComment = 0, - BlockContentComment = 1, - BlockCommandComment = 2, - ParamCommandComment = 3, - TParamCommandComment = 4, - VerbatimBlockComment = 5, - VerbatimLineComment = 6, - ParagraphComment = 7, - HTMLTagComment = 8, - HTMLStartTagComment = 9, - HTMLEndTagComment = 10, - TextComment = 11, - InlineContentComment = 12, - InlineCommandComment = 13, - VerbatimBlockLineComment = 14 - } - public enum ArchType { UnknownArch = 0, @@ -2985,9 +2985,137 @@ namespace CppSharp } } + public unsafe partial class LayoutField : IDisposable + { + [StructLayout(LayoutKind.Explicit, Size = 8)] + public partial struct Internal + { + [FieldOffset(0)] + public uint Offset; + + [FieldOffset(4)] + public global::System.IntPtr Field; + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldC2Ev")] + internal static extern void ctor_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldC2ERKS2_")] + internal static extern void cctor_1(global::System.IntPtr instance, global::System.IntPtr _0); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldD2Ev")] + internal static extern void dtor_0(global::System.IntPtr instance); + } + + public global::System.IntPtr __Instance { get; protected set; } + + protected int __PointerAdjustment; + public static readonly System.Collections.Concurrent.ConcurrentDictionary NativeToManagedMap = new System.Collections.Concurrent.ConcurrentDictionary(); + protected void*[] __OriginalVTables; + + protected bool __ownsNativeInstance; + + public static LayoutField __CreateInstance(global::System.IntPtr native, bool skipVTables = false) + { + return new LayoutField(native.ToPointer(), skipVTables); + } + + public static LayoutField __CreateInstance(LayoutField.Internal native, bool skipVTables = false) + { + return new LayoutField(native, skipVTables); + } + + private static void* __CopyValue(LayoutField.Internal native) + { + var ret = Marshal.AllocHGlobal(8); + *(LayoutField.Internal*) ret = native; + return ret.ToPointer(); + } + + private LayoutField(LayoutField.Internal native, bool skipVTables = false) + : this(__CopyValue(native), skipVTables) + { + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + } + + protected LayoutField(void* native, bool skipVTables = false) + { + if (native == null) + return; + __Instance = new global::System.IntPtr(native); + } + + public LayoutField() + { + __Instance = Marshal.AllocHGlobal(8); + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + Internal.ctor_0((__Instance + __PointerAdjustment)); + } + + public LayoutField(CppSharp.Parser.AST.LayoutField _0) + { + __Instance = Marshal.AllocHGlobal(8); + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + *((LayoutField.Internal*) __Instance) = *((LayoutField.Internal*) _0.__Instance); + } + + public void Dispose() + { + Dispose(disposing: true); + } + + protected virtual void Dispose(bool disposing) + { + CppSharp.Parser.AST.LayoutField __dummy; + NativeToManagedMap.TryRemove(__Instance, out __dummy); + Internal.dtor_0((__Instance + __PointerAdjustment)); + if (__ownsNativeInstance) + Marshal.FreeHGlobal(__Instance); + } + + public uint Offset + { + get + { + return ((Internal*) __Instance)->Offset; + } + + set + { + ((Internal*) __Instance)->Offset = value; + } + } + + public CppSharp.Parser.AST.Field Field + { + get + { + CppSharp.Parser.AST.Field __result0; + 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]; + else __result0 = CppSharp.Parser.AST.Field.__CreateInstance(((Internal*) __Instance)->Field); + return __result0; + } + + set + { + ((Internal*) __Instance)->Field = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance; + } + } + } + public unsafe partial class ClassLayout : IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 48)] + [StructLayout(LayoutKind.Explicit, Size = 60)] public partial struct Internal { [FieldOffset(0)] @@ -3041,10 +3169,30 @@ namespace CppSharp EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout13clearVFTablesEv")] internal static extern void clearVFTables_0(global::System.IntPtr instance); + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout9getFieldsEj")] + internal static extern void getFields_0(global::System.IntPtr @return, global::System.IntPtr instance, uint i); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout9addFieldsERNS1_11LayoutFieldE")] + internal static extern void addFields_0(global::System.IntPtr instance, global::System.IntPtr s); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout11clearFieldsEv")] + internal static extern void clearFields_0(global::System.IntPtr instance); + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout16getVFTablesCountEv")] internal static extern uint getVFTablesCount_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout14getFieldsCountEv")] + internal static extern uint getFieldsCount_0(global::System.IntPtr instance); } public global::System.IntPtr __Instance { get; protected set; } @@ -3067,7 +3215,7 @@ namespace CppSharp private static void* __CopyValue(ClassLayout.Internal native) { - var ret = Marshal.AllocHGlobal(48); + var ret = Marshal.AllocHGlobal(60); CppSharp.Parser.AST.ClassLayout.Internal.cctor_2(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); } @@ -3088,7 +3236,7 @@ namespace CppSharp public ClassLayout() { - __Instance = Marshal.AllocHGlobal(48); + __Instance = Marshal.AllocHGlobal(60); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; Internal.ctor_0((__Instance + __PointerAdjustment)); @@ -3096,7 +3244,7 @@ namespace CppSharp public ClassLayout(CppSharp.Parser.AST.ClassLayout _0) { - __Instance = Marshal.AllocHGlobal(48); + __Instance = Marshal.AllocHGlobal(60); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; if (ReferenceEquals(_0, null)) @@ -3139,6 +3287,26 @@ namespace CppSharp Internal.clearVFTables_0((__Instance + __PointerAdjustment)); } + public CppSharp.Parser.AST.LayoutField getFields(uint i) + { + var __ret = new CppSharp.Parser.AST.LayoutField.Internal(); + Internal.getFields_0(new IntPtr(&__ret), (__Instance + __PointerAdjustment), i); + return CppSharp.Parser.AST.LayoutField.__CreateInstance(__ret); + } + + public void addFields(CppSharp.Parser.AST.LayoutField s) + { + if (ReferenceEquals(s, null)) + throw new global::System.ArgumentNullException("s", "Cannot be null because it is a C++ reference (&)."); + var __arg0 = s.__Instance; + Internal.addFields_0((__Instance + __PointerAdjustment), __arg0); + } + + public void clearFields() + { + Internal.clearFields_0((__Instance + __PointerAdjustment)); + } + public uint VFTablesCount { get @@ -3148,6 +3316,15 @@ namespace CppSharp } } + public uint FieldsCount + { + get + { + var __ret = Internal.getFieldsCount_0((__Instance + __PointerAdjustment)); + return __ret; + } + } + public CppSharp.Parser.AST.CppAbi ABI { get @@ -6840,7 +7017,7 @@ namespace CppSharp public unsafe partial class Field : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 116)] + [StructLayout(LayoutKind.Explicit, Size = 112)] public new partial struct Internal { [FieldOffset(0)] @@ -6886,15 +7063,12 @@ namespace CppSharp public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType; [FieldOffset(100)] - public uint Offset; - - [FieldOffset(104)] public global::System.IntPtr Class; - [FieldOffset(108)] + [FieldOffset(104)] public byte IsBitField; - [FieldOffset(112)] + [FieldOffset(108)] public uint BitWidth; [SuppressUnmanagedCodeSecurity] @@ -6925,7 +7099,7 @@ namespace CppSharp private static void* __CopyValue(Field.Internal native) { - var ret = Marshal.AllocHGlobal(116); + var ret = Marshal.AllocHGlobal(112); CppSharp.Parser.AST.Field.Internal.cctor_1(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); } @@ -6949,7 +7123,7 @@ namespace CppSharp public Field() : this((void*) null) { - __Instance = Marshal.AllocHGlobal(116); + __Instance = Marshal.AllocHGlobal(112); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; Internal.ctor_0((__Instance + __PointerAdjustment)); @@ -6958,7 +7132,7 @@ namespace CppSharp public Field(CppSharp.Parser.AST.Field _0) : this((void*) null) { - __Instance = Marshal.AllocHGlobal(116); + __Instance = Marshal.AllocHGlobal(112); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; if (ReferenceEquals(_0, null)) @@ -6989,19 +7163,6 @@ namespace CppSharp } } - public uint Offset - { - get - { - return ((Internal*) __Instance)->Offset; - } - - set - { - ((Internal*) __Instance)->Offset = value; - } - } - public CppSharp.Parser.AST.Class Class { get diff --git a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs index 5be1c9e8..128f3a6b 100644 --- a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs +++ b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs @@ -69,14 +69,56 @@ namespace CppSharp Public = 2 } - public enum CXXMethodKind + public enum RawCommentKind { - Normal = 0, - Constructor = 1, - Destructor = 2, - Conversion = 3, - Operator = 4, - UsingDirective = 5 + Invalid = 0, + OrdinaryBCPL = 1, + OrdinaryC = 2, + BCPLSlash = 3, + BCPLExcl = 4, + JavaDoc = 5, + Qt = 6, + Merged = 7 + } + + public enum CommentKind + { + FullComment = 0, + BlockContentComment = 1, + BlockCommandComment = 2, + ParamCommandComment = 3, + TParamCommandComment = 4, + VerbatimBlockComment = 5, + VerbatimLineComment = 6, + ParagraphComment = 7, + HTMLTagComment = 8, + HTMLStartTagComment = 9, + HTMLEndTagComment = 10, + TextComment = 11, + InlineContentComment = 12, + InlineCommandComment = 13, + VerbatimBlockLineComment = 14 + } + + public enum CppAbi + { + Itanium = 0, + Microsoft = 1, + ARM = 2, + iOS = 3, + iOS64 = 4 + } + + public enum VTableComponentKind + { + VCallOffset = 0, + VBaseOffset = 1, + OffsetToTop = 2, + RTTI = 3, + FunctionPointer = 4, + CompleteDtorPointer = 5, + DeletingDtorPointer = 6, + UnusedFunctionPointer = 7 } public enum CXXOperatorKind @@ -138,18 +180,6 @@ namespace CppSharp Unknown = 5 } - public enum StatementClass - { - Any = 0, - BinaryOperator = 1, - CallExprClass = 2, - DeclRefExprClass = 3, - CXXConstructExprClass = 4, - CXXOperatorCallExpr = 5, - ImplicitCastExpr = 6, - ExplicitCastExpr = 7 - } - public enum TemplateSpecializationKind { Undeclared = 0, @@ -159,25 +189,26 @@ namespace CppSharp ExplicitInstantiationDefinition = 4 } - public enum CppAbi + public enum StatementClass { - Itanium = 0, - Microsoft = 1, - ARM = 2, - iOS = 3, - iOS64 = 4 + Any = 0, + BinaryOperator = 1, + CallExprClass = 2, + DeclRefExprClass = 3, + CXXConstructExprClass = 4, + CXXOperatorCallExpr = 5, + ImplicitCastExpr = 6, + ExplicitCastExpr = 7 } - public enum VTableComponentKind + public enum CXXMethodKind { - VCallOffset = 0, - VBaseOffset = 1, - OffsetToTop = 2, - RTTI = 3, - FunctionPointer = 4, - CompleteDtorPointer = 5, - DeletingDtorPointer = 6, - UnusedFunctionPointer = 7 + Normal = 0, + Constructor = 1, + Destructor = 2, + Conversion = 3, + Operator = 4, + UsingDirective = 5 } public enum PrimitiveType @@ -211,37 +242,6 @@ namespace CppSharp FunctionBody = 5 } - public enum RawCommentKind - { - Invalid = 0, - OrdinaryBCPL = 1, - OrdinaryC = 2, - BCPLSlash = 3, - BCPLExcl = 4, - JavaDoc = 5, - Qt = 6, - Merged = 7 - } - - public enum CommentKind - { - FullComment = 0, - BlockContentComment = 1, - BlockCommandComment = 2, - ParamCommandComment = 3, - TParamCommandComment = 4, - VerbatimBlockComment = 5, - VerbatimLineComment = 6, - ParagraphComment = 7, - HTMLTagComment = 8, - HTMLStartTagComment = 9, - HTMLEndTagComment = 10, - TextComment = 11, - InlineContentComment = 12, - InlineCommandComment = 13, - VerbatimBlockLineComment = 14 - } - public enum ArchType { UnknownArch = 0, @@ -2985,9 +2985,137 @@ namespace CppSharp } } + public unsafe partial class LayoutField : IDisposable + { + [StructLayout(LayoutKind.Explicit, Size = 8)] + public partial struct Internal + { + [FieldOffset(0)] + public uint Offset; + + [FieldOffset(4)] + public global::System.IntPtr Field; + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="??0LayoutField@AST@CppParser@CppSharp@@QAE@XZ")] + internal static extern global::System.IntPtr ctor_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="??0LayoutField@AST@CppParser@CppSharp@@QAE@ABV0123@@Z")] + internal static extern global::System.IntPtr cctor_1(global::System.IntPtr instance, global::System.IntPtr _0); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="??1LayoutField@AST@CppParser@CppSharp@@QAE@XZ")] + internal static extern void dtor_0(global::System.IntPtr instance, int delete); + } + + public global::System.IntPtr __Instance { get; protected set; } + + protected int __PointerAdjustment; + public static readonly System.Collections.Concurrent.ConcurrentDictionary NativeToManagedMap = new System.Collections.Concurrent.ConcurrentDictionary(); + protected void*[] __OriginalVTables; + + protected bool __ownsNativeInstance; + + public static LayoutField __CreateInstance(global::System.IntPtr native, bool skipVTables = false) + { + return new LayoutField(native.ToPointer(), skipVTables); + } + + public static LayoutField __CreateInstance(LayoutField.Internal native, bool skipVTables = false) + { + return new LayoutField(native, skipVTables); + } + + private static void* __CopyValue(LayoutField.Internal native) + { + var ret = Marshal.AllocHGlobal(8); + *(LayoutField.Internal*) ret = native; + return ret.ToPointer(); + } + + private LayoutField(LayoutField.Internal native, bool skipVTables = false) + : this(__CopyValue(native), skipVTables) + { + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + } + + protected LayoutField(void* native, bool skipVTables = false) + { + if (native == null) + return; + __Instance = new global::System.IntPtr(native); + } + + public LayoutField() + { + __Instance = Marshal.AllocHGlobal(8); + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + Internal.ctor_0((__Instance + __PointerAdjustment)); + } + + public LayoutField(CppSharp.Parser.AST.LayoutField _0) + { + __Instance = Marshal.AllocHGlobal(8); + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + *((LayoutField.Internal*) __Instance) = *((LayoutField.Internal*) _0.__Instance); + } + + public void Dispose() + { + Dispose(disposing: true); + } + + protected virtual void Dispose(bool disposing) + { + CppSharp.Parser.AST.LayoutField __dummy; + NativeToManagedMap.TryRemove(__Instance, out __dummy); + Internal.dtor_0((__Instance + __PointerAdjustment), 0); + if (__ownsNativeInstance) + Marshal.FreeHGlobal(__Instance); + } + + public uint Offset + { + get + { + return ((Internal*) __Instance)->Offset; + } + + set + { + ((Internal*) __Instance)->Offset = value; + } + } + + public CppSharp.Parser.AST.Field Field + { + get + { + CppSharp.Parser.AST.Field __result0; + 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]; + else __result0 = CppSharp.Parser.AST.Field.__CreateInstance(((Internal*) __Instance)->Field); + return __result0; + } + + set + { + ((Internal*) __Instance)->Field = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance; + } + } + } + public unsafe partial class ClassLayout : IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 48)] + [StructLayout(LayoutKind.Explicit, Size = 60)] public partial struct Internal { [FieldOffset(0)] @@ -3041,10 +3169,30 @@ namespace CppSharp EntryPoint="?clearVFTables@ClassLayout@AST@CppParser@CppSharp@@QAEXXZ")] internal static extern void clearVFTables_0(global::System.IntPtr instance); + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="?getFields@ClassLayout@AST@CppParser@CppSharp@@QAE?AVLayoutField@234@I@Z")] + internal static extern void getFields_0(global::System.IntPtr instance, global::System.IntPtr @return, uint i); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="?addFields@ClassLayout@AST@CppParser@CppSharp@@QAEXAAVLayoutField@234@@Z")] + internal static extern void addFields_0(global::System.IntPtr instance, global::System.IntPtr s); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="?clearFields@ClassLayout@AST@CppParser@CppSharp@@QAEXXZ")] + internal static extern void clearFields_0(global::System.IntPtr instance); + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, EntryPoint="?getVFTablesCount@ClassLayout@AST@CppParser@CppSharp@@QAEIXZ")] internal static extern uint getVFTablesCount_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="?getFieldsCount@ClassLayout@AST@CppParser@CppSharp@@QAEIXZ")] + internal static extern uint getFieldsCount_0(global::System.IntPtr instance); } public global::System.IntPtr __Instance { get; protected set; } @@ -3067,7 +3215,7 @@ namespace CppSharp private static void* __CopyValue(ClassLayout.Internal native) { - var ret = Marshal.AllocHGlobal(48); + var ret = Marshal.AllocHGlobal(60); CppSharp.Parser.AST.ClassLayout.Internal.cctor_2(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); } @@ -3088,7 +3236,7 @@ namespace CppSharp public ClassLayout() { - __Instance = Marshal.AllocHGlobal(48); + __Instance = Marshal.AllocHGlobal(60); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; Internal.ctor_0((__Instance + __PointerAdjustment)); @@ -3096,7 +3244,7 @@ namespace CppSharp public ClassLayout(CppSharp.Parser.AST.ClassLayout _0) { - __Instance = Marshal.AllocHGlobal(48); + __Instance = Marshal.AllocHGlobal(60); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; if (ReferenceEquals(_0, null)) @@ -3139,6 +3287,26 @@ namespace CppSharp Internal.clearVFTables_0((__Instance + __PointerAdjustment)); } + public CppSharp.Parser.AST.LayoutField getFields(uint i) + { + var __ret = new CppSharp.Parser.AST.LayoutField.Internal(); + Internal.getFields_0((__Instance + __PointerAdjustment), new IntPtr(&__ret), i); + return CppSharp.Parser.AST.LayoutField.__CreateInstance(__ret); + } + + public void addFields(CppSharp.Parser.AST.LayoutField s) + { + if (ReferenceEquals(s, null)) + throw new global::System.ArgumentNullException("s", "Cannot be null because it is a C++ reference (&)."); + var __arg0 = s.__Instance; + Internal.addFields_0((__Instance + __PointerAdjustment), __arg0); + } + + public void clearFields() + { + Internal.clearFields_0((__Instance + __PointerAdjustment)); + } + public uint VFTablesCount { get @@ -3148,6 +3316,15 @@ namespace CppSharp } } + public uint FieldsCount + { + get + { + var __ret = Internal.getFieldsCount_0((__Instance + __PointerAdjustment)); + return __ret; + } + } + public CppSharp.Parser.AST.CppAbi ABI { get @@ -6840,7 +7017,7 @@ namespace CppSharp public unsafe partial class Field : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 152)] + [StructLayout(LayoutKind.Explicit, Size = 148)] public new partial struct Internal { [FieldOffset(0)] @@ -6886,15 +7063,12 @@ namespace CppSharp public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType; [FieldOffset(136)] - public uint Offset; - - [FieldOffset(140)] public global::System.IntPtr Class; - [FieldOffset(144)] + [FieldOffset(140)] public byte IsBitField; - [FieldOffset(148)] + [FieldOffset(144)] public uint BitWidth; [SuppressUnmanagedCodeSecurity] @@ -6925,7 +7099,7 @@ namespace CppSharp private static void* __CopyValue(Field.Internal native) { - var ret = Marshal.AllocHGlobal(152); + var ret = Marshal.AllocHGlobal(148); CppSharp.Parser.AST.Field.Internal.cctor_1(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); } @@ -6949,7 +7123,7 @@ namespace CppSharp public Field() : this((void*) null) { - __Instance = Marshal.AllocHGlobal(152); + __Instance = Marshal.AllocHGlobal(148); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; Internal.ctor_0((__Instance + __PointerAdjustment)); @@ -6958,7 +7132,7 @@ namespace CppSharp public Field(CppSharp.Parser.AST.Field _0) : this((void*) null) { - __Instance = Marshal.AllocHGlobal(152); + __Instance = Marshal.AllocHGlobal(148); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; if (ReferenceEquals(_0, null)) @@ -6989,19 +7163,6 @@ namespace CppSharp } } - public uint Offset - { - get - { - return ((Internal*) __Instance)->Offset; - } - - set - { - ((Internal*) __Instance)->Offset = value; - } - } - public CppSharp.Parser.AST.Class Class { get diff --git a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs index 0edfe36e..3c6f020f 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs @@ -69,14 +69,56 @@ namespace CppSharp Public = 2 } - public enum CXXMethodKind + public enum RawCommentKind { - Normal = 0, - Constructor = 1, - Destructor = 2, - Conversion = 3, - Operator = 4, - UsingDirective = 5 + Invalid = 0, + OrdinaryBCPL = 1, + OrdinaryC = 2, + BCPLSlash = 3, + BCPLExcl = 4, + JavaDoc = 5, + Qt = 6, + Merged = 7 + } + + public enum CommentKind + { + FullComment = 0, + BlockContentComment = 1, + BlockCommandComment = 2, + ParamCommandComment = 3, + TParamCommandComment = 4, + VerbatimBlockComment = 5, + VerbatimLineComment = 6, + ParagraphComment = 7, + HTMLTagComment = 8, + HTMLStartTagComment = 9, + HTMLEndTagComment = 10, + TextComment = 11, + InlineContentComment = 12, + InlineCommandComment = 13, + VerbatimBlockLineComment = 14 + } + + public enum CppAbi + { + Itanium = 0, + Microsoft = 1, + ARM = 2, + iOS = 3, + iOS64 = 4 + } + + public enum VTableComponentKind + { + VCallOffset = 0, + VBaseOffset = 1, + OffsetToTop = 2, + RTTI = 3, + FunctionPointer = 4, + CompleteDtorPointer = 5, + DeletingDtorPointer = 6, + UnusedFunctionPointer = 7 } public enum CXXOperatorKind @@ -138,18 +180,6 @@ namespace CppSharp Unknown = 5 } - public enum StatementClass - { - Any = 0, - BinaryOperator = 1, - CallExprClass = 2, - DeclRefExprClass = 3, - CXXConstructExprClass = 4, - CXXOperatorCallExpr = 5, - ImplicitCastExpr = 6, - ExplicitCastExpr = 7 - } - public enum TemplateSpecializationKind { Undeclared = 0, @@ -159,25 +189,26 @@ namespace CppSharp ExplicitInstantiationDefinition = 4 } - public enum CppAbi + public enum StatementClass { - Itanium = 0, - Microsoft = 1, - ARM = 2, - iOS = 3, - iOS64 = 4 + Any = 0, + BinaryOperator = 1, + CallExprClass = 2, + DeclRefExprClass = 3, + CXXConstructExprClass = 4, + CXXOperatorCallExpr = 5, + ImplicitCastExpr = 6, + ExplicitCastExpr = 7 } - public enum VTableComponentKind + public enum CXXMethodKind { - VCallOffset = 0, - VBaseOffset = 1, - OffsetToTop = 2, - RTTI = 3, - FunctionPointer = 4, - CompleteDtorPointer = 5, - DeletingDtorPointer = 6, - UnusedFunctionPointer = 7 + Normal = 0, + Constructor = 1, + Destructor = 2, + Conversion = 3, + Operator = 4, + UsingDirective = 5 } public enum PrimitiveType @@ -211,37 +242,6 @@ namespace CppSharp FunctionBody = 5 } - public enum RawCommentKind - { - Invalid = 0, - OrdinaryBCPL = 1, - OrdinaryC = 2, - BCPLSlash = 3, - BCPLExcl = 4, - JavaDoc = 5, - Qt = 6, - Merged = 7 - } - - public enum CommentKind - { - FullComment = 0, - BlockContentComment = 1, - BlockCommandComment = 2, - ParamCommandComment = 3, - TParamCommandComment = 4, - VerbatimBlockComment = 5, - VerbatimLineComment = 6, - ParagraphComment = 7, - HTMLTagComment = 8, - HTMLStartTagComment = 9, - HTMLEndTagComment = 10, - TextComment = 11, - InlineContentComment = 12, - InlineCommandComment = 13, - VerbatimBlockLineComment = 14 - } - public enum ArchType { UnknownArch = 0, @@ -2984,9 +2984,137 @@ namespace CppSharp } } + public unsafe partial class LayoutField : IDisposable + { + [StructLayout(LayoutKind.Explicit, Size = 16)] + public partial struct Internal + { + [FieldOffset(0)] + public uint Offset; + + [FieldOffset(8)] + public global::System.IntPtr Field; + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldC2Ev")] + internal static extern void ctor_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldC2ERKS2_")] + internal static extern void cctor_1(global::System.IntPtr instance, global::System.IntPtr _0); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldD2Ev")] + internal static extern void dtor_0(global::System.IntPtr instance); + } + + public global::System.IntPtr __Instance { get; protected set; } + + protected int __PointerAdjustment; + public static readonly System.Collections.Concurrent.ConcurrentDictionary NativeToManagedMap = new System.Collections.Concurrent.ConcurrentDictionary(); + protected void*[] __OriginalVTables; + + protected bool __ownsNativeInstance; + + public static LayoutField __CreateInstance(global::System.IntPtr native, bool skipVTables = false) + { + return new LayoutField(native.ToPointer(), skipVTables); + } + + public static LayoutField __CreateInstance(LayoutField.Internal native, bool skipVTables = false) + { + return new LayoutField(native, skipVTables); + } + + private static void* __CopyValue(LayoutField.Internal native) + { + var ret = Marshal.AllocHGlobal(16); + *(LayoutField.Internal*) ret = native; + return ret.ToPointer(); + } + + private LayoutField(LayoutField.Internal native, bool skipVTables = false) + : this(__CopyValue(native), skipVTables) + { + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + } + + protected LayoutField(void* native, bool skipVTables = false) + { + if (native == null) + return; + __Instance = new global::System.IntPtr(native); + } + + public LayoutField() + { + __Instance = Marshal.AllocHGlobal(16); + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + Internal.ctor_0((__Instance + __PointerAdjustment)); + } + + public LayoutField(CppSharp.Parser.AST.LayoutField _0) + { + __Instance = Marshal.AllocHGlobal(16); + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + *((LayoutField.Internal*) __Instance) = *((LayoutField.Internal*) _0.__Instance); + } + + public void Dispose() + { + Dispose(disposing: true); + } + + protected virtual void Dispose(bool disposing) + { + CppSharp.Parser.AST.LayoutField __dummy; + NativeToManagedMap.TryRemove(__Instance, out __dummy); + Internal.dtor_0((__Instance + __PointerAdjustment)); + if (__ownsNativeInstance) + Marshal.FreeHGlobal(__Instance); + } + + public uint Offset + { + get + { + return ((Internal*) __Instance)->Offset; + } + + set + { + ((Internal*) __Instance)->Offset = value; + } + } + + public CppSharp.Parser.AST.Field Field + { + get + { + CppSharp.Parser.AST.Field __result0; + 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]; + else __result0 = CppSharp.Parser.AST.Field.__CreateInstance(((Internal*) __Instance)->Field); + return __result0; + } + + set + { + ((Internal*) __Instance)->Field = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance; + } + } + } + public unsafe partial class ClassLayout : IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 88)] + [StructLayout(LayoutKind.Explicit, Size = 112)] public partial struct Internal { [FieldOffset(0)] @@ -3040,10 +3168,30 @@ namespace CppSharp EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout13clearVFTablesEv")] internal static extern void clearVFTables_0(global::System.IntPtr instance); + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout9getFieldsEj")] + internal static extern void getFields_0(global::System.IntPtr @return, global::System.IntPtr instance, uint i); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout9addFieldsERNS1_11LayoutFieldE")] + internal static extern void addFields_0(global::System.IntPtr instance, global::System.IntPtr s); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout11clearFieldsEv")] + internal static extern void clearFields_0(global::System.IntPtr instance); + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout16getVFTablesCountEv")] internal static extern uint getVFTablesCount_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout14getFieldsCountEv")] + internal static extern uint getFieldsCount_0(global::System.IntPtr instance); } public global::System.IntPtr __Instance { get; protected set; } @@ -3066,7 +3214,7 @@ namespace CppSharp private static void* __CopyValue(ClassLayout.Internal native) { - var ret = Marshal.AllocHGlobal(88); + var ret = Marshal.AllocHGlobal(112); CppSharp.Parser.AST.ClassLayout.Internal.cctor_2(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); } @@ -3087,7 +3235,7 @@ namespace CppSharp public ClassLayout() { - __Instance = Marshal.AllocHGlobal(88); + __Instance = Marshal.AllocHGlobal(112); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; Internal.ctor_0((__Instance + __PointerAdjustment)); @@ -3095,7 +3243,7 @@ namespace CppSharp public ClassLayout(CppSharp.Parser.AST.ClassLayout _0) { - __Instance = Marshal.AllocHGlobal(88); + __Instance = Marshal.AllocHGlobal(112); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; if (ReferenceEquals(_0, null)) @@ -3138,6 +3286,26 @@ namespace CppSharp Internal.clearVFTables_0((__Instance + __PointerAdjustment)); } + public CppSharp.Parser.AST.LayoutField getFields(uint i) + { + var __ret = new CppSharp.Parser.AST.LayoutField.Internal(); + Internal.getFields_0(new IntPtr(&__ret), (__Instance + __PointerAdjustment), i); + return CppSharp.Parser.AST.LayoutField.__CreateInstance(__ret); + } + + public void addFields(CppSharp.Parser.AST.LayoutField s) + { + if (ReferenceEquals(s, null)) + throw new global::System.ArgumentNullException("s", "Cannot be null because it is a C++ reference (&)."); + var __arg0 = s.__Instance; + Internal.addFields_0((__Instance + __PointerAdjustment), __arg0); + } + + public void clearFields() + { + Internal.clearFields_0((__Instance + __PointerAdjustment)); + } + public uint VFTablesCount { get @@ -3147,6 +3315,15 @@ namespace CppSharp } } + public uint FieldsCount + { + get + { + var __ret = Internal.getFieldsCount_0((__Instance + __PointerAdjustment)); + return __ret; + } + } + public CppSharp.Parser.AST.CppAbi ABI { get @@ -6839,7 +7016,7 @@ namespace CppSharp public unsafe partial class Field : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 208)] + [StructLayout(LayoutKind.Explicit, Size = 200)] public new partial struct Internal { [FieldOffset(0)] @@ -6885,15 +7062,12 @@ namespace CppSharp public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType; [FieldOffset(184)] - public uint Offset; - - [FieldOffset(192)] public global::System.IntPtr Class; - [FieldOffset(200)] + [FieldOffset(192)] public byte IsBitField; - [FieldOffset(204)] + [FieldOffset(196)] public uint BitWidth; [SuppressUnmanagedCodeSecurity] @@ -6924,7 +7098,7 @@ namespace CppSharp private static void* __CopyValue(Field.Internal native) { - var ret = Marshal.AllocHGlobal(208); + var ret = Marshal.AllocHGlobal(200); CppSharp.Parser.AST.Field.Internal.cctor_1(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); } @@ -6948,7 +7122,7 @@ namespace CppSharp public Field() : this((void*) null) { - __Instance = Marshal.AllocHGlobal(208); + __Instance = Marshal.AllocHGlobal(200); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; Internal.ctor_0((__Instance + __PointerAdjustment)); @@ -6957,7 +7131,7 @@ namespace CppSharp public Field(CppSharp.Parser.AST.Field _0) : this((void*) null) { - __Instance = Marshal.AllocHGlobal(208); + __Instance = Marshal.AllocHGlobal(200); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; if (ReferenceEquals(_0, null)) @@ -6988,19 +7162,6 @@ namespace CppSharp } } - public uint Offset - { - get - { - return ((Internal*) __Instance)->Offset; - } - - set - { - ((Internal*) __Instance)->Offset = value; - } - } - public CppSharp.Parser.AST.Class Class { get diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs index 09ac64f2..67d6da47 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs @@ -69,14 +69,56 @@ namespace CppSharp Public = 2 } - public enum CXXMethodKind + public enum RawCommentKind { - Normal = 0, - Constructor = 1, - Destructor = 2, - Conversion = 3, - Operator = 4, - UsingDirective = 5 + Invalid = 0, + OrdinaryBCPL = 1, + OrdinaryC = 2, + BCPLSlash = 3, + BCPLExcl = 4, + JavaDoc = 5, + Qt = 6, + Merged = 7 + } + + public enum CommentKind + { + FullComment = 0, + BlockContentComment = 1, + BlockCommandComment = 2, + ParamCommandComment = 3, + TParamCommandComment = 4, + VerbatimBlockComment = 5, + VerbatimLineComment = 6, + ParagraphComment = 7, + HTMLTagComment = 8, + HTMLStartTagComment = 9, + HTMLEndTagComment = 10, + TextComment = 11, + InlineContentComment = 12, + InlineCommandComment = 13, + VerbatimBlockLineComment = 14 + } + + public enum CppAbi + { + Itanium = 0, + Microsoft = 1, + ARM = 2, + iOS = 3, + iOS64 = 4 + } + + public enum VTableComponentKind + { + VCallOffset = 0, + VBaseOffset = 1, + OffsetToTop = 2, + RTTI = 3, + FunctionPointer = 4, + CompleteDtorPointer = 5, + DeletingDtorPointer = 6, + UnusedFunctionPointer = 7 } public enum CXXOperatorKind @@ -138,18 +180,6 @@ namespace CppSharp Unknown = 5 } - public enum StatementClass - { - Any = 0, - BinaryOperator = 1, - CallExprClass = 2, - DeclRefExprClass = 3, - CXXConstructExprClass = 4, - CXXOperatorCallExpr = 5, - ImplicitCastExpr = 6, - ExplicitCastExpr = 7 - } - public enum TemplateSpecializationKind { Undeclared = 0, @@ -159,25 +189,26 @@ namespace CppSharp ExplicitInstantiationDefinition = 4 } - public enum CppAbi + public enum StatementClass { - Itanium = 0, - Microsoft = 1, - ARM = 2, - iOS = 3, - iOS64 = 4 + Any = 0, + BinaryOperator = 1, + CallExprClass = 2, + DeclRefExprClass = 3, + CXXConstructExprClass = 4, + CXXOperatorCallExpr = 5, + ImplicitCastExpr = 6, + ExplicitCastExpr = 7 } - public enum VTableComponentKind + public enum CXXMethodKind { - VCallOffset = 0, - VBaseOffset = 1, - OffsetToTop = 2, - RTTI = 3, - FunctionPointer = 4, - CompleteDtorPointer = 5, - DeletingDtorPointer = 6, - UnusedFunctionPointer = 7 + Normal = 0, + Constructor = 1, + Destructor = 2, + Conversion = 3, + Operator = 4, + UsingDirective = 5 } public enum PrimitiveType @@ -211,37 +242,6 @@ namespace CppSharp FunctionBody = 5 } - public enum RawCommentKind - { - Invalid = 0, - OrdinaryBCPL = 1, - OrdinaryC = 2, - BCPLSlash = 3, - BCPLExcl = 4, - JavaDoc = 5, - Qt = 6, - Merged = 7 - } - - public enum CommentKind - { - FullComment = 0, - BlockContentComment = 1, - BlockCommandComment = 2, - ParamCommandComment = 3, - TParamCommandComment = 4, - VerbatimBlockComment = 5, - VerbatimLineComment = 6, - ParagraphComment = 7, - HTMLTagComment = 8, - HTMLStartTagComment = 9, - HTMLEndTagComment = 10, - TextComment = 11, - InlineContentComment = 12, - InlineCommandComment = 13, - VerbatimBlockLineComment = 14 - } - public enum ArchType { UnknownArch = 0, @@ -2984,9 +2984,137 @@ namespace CppSharp } } + public unsafe partial class LayoutField : IDisposable + { + [StructLayout(LayoutKind.Explicit, Size = 16)] + public partial struct Internal + { + [FieldOffset(0)] + public uint Offset; + + [FieldOffset(8)] + public global::System.IntPtr Field; + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldC2Ev")] + internal static extern void ctor_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldC2ERKS2_")] + internal static extern void cctor_1(global::System.IntPtr instance, global::System.IntPtr _0); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11LayoutFieldD2Ev")] + internal static extern void dtor_0(global::System.IntPtr instance); + } + + public global::System.IntPtr __Instance { get; protected set; } + + protected int __PointerAdjustment; + public static readonly System.Collections.Concurrent.ConcurrentDictionary NativeToManagedMap = new System.Collections.Concurrent.ConcurrentDictionary(); + protected void*[] __OriginalVTables; + + protected bool __ownsNativeInstance; + + public static LayoutField __CreateInstance(global::System.IntPtr native, bool skipVTables = false) + { + return new LayoutField(native.ToPointer(), skipVTables); + } + + public static LayoutField __CreateInstance(LayoutField.Internal native, bool skipVTables = false) + { + return new LayoutField(native, skipVTables); + } + + private static void* __CopyValue(LayoutField.Internal native) + { + var ret = Marshal.AllocHGlobal(16); + *(LayoutField.Internal*) ret = native; + return ret.ToPointer(); + } + + private LayoutField(LayoutField.Internal native, bool skipVTables = false) + : this(__CopyValue(native), skipVTables) + { + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + } + + protected LayoutField(void* native, bool skipVTables = false) + { + if (native == null) + return; + __Instance = new global::System.IntPtr(native); + } + + public LayoutField() + { + __Instance = Marshal.AllocHGlobal(16); + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + Internal.ctor_0((__Instance + __PointerAdjustment)); + } + + public LayoutField(CppSharp.Parser.AST.LayoutField _0) + { + __Instance = Marshal.AllocHGlobal(16); + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + *((LayoutField.Internal*) __Instance) = *((LayoutField.Internal*) _0.__Instance); + } + + public void Dispose() + { + Dispose(disposing: true); + } + + protected virtual void Dispose(bool disposing) + { + CppSharp.Parser.AST.LayoutField __dummy; + NativeToManagedMap.TryRemove(__Instance, out __dummy); + Internal.dtor_0((__Instance + __PointerAdjustment)); + if (__ownsNativeInstance) + Marshal.FreeHGlobal(__Instance); + } + + public uint Offset + { + get + { + return ((Internal*) __Instance)->Offset; + } + + set + { + ((Internal*) __Instance)->Offset = value; + } + } + + public CppSharp.Parser.AST.Field Field + { + get + { + CppSharp.Parser.AST.Field __result0; + 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]; + else __result0 = CppSharp.Parser.AST.Field.__CreateInstance(((Internal*) __Instance)->Field); + return __result0; + } + + set + { + ((Internal*) __Instance)->Field = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance; + } + } + } + public unsafe partial class ClassLayout : IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 88)] + [StructLayout(LayoutKind.Explicit, Size = 112)] public partial struct Internal { [FieldOffset(0)] @@ -3040,10 +3168,30 @@ namespace CppSharp EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout13clearVFTablesEv")] internal static extern void clearVFTables_0(global::System.IntPtr instance); + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout9getFieldsEj")] + internal static extern void getFields_0(global::System.IntPtr @return, global::System.IntPtr instance, uint i); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout9addFieldsERNS1_11LayoutFieldE")] + internal static extern void addFields_0(global::System.IntPtr instance, global::System.IntPtr s); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout11clearFieldsEv")] + internal static extern void clearFields_0(global::System.IntPtr instance); + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout16getVFTablesCountEv")] internal static extern uint getVFTablesCount_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZN8CppSharp9CppParser3AST11ClassLayout14getFieldsCountEv")] + internal static extern uint getFieldsCount_0(global::System.IntPtr instance); } public global::System.IntPtr __Instance { get; protected set; } @@ -3066,7 +3214,7 @@ namespace CppSharp private static void* __CopyValue(ClassLayout.Internal native) { - var ret = Marshal.AllocHGlobal(88); + var ret = Marshal.AllocHGlobal(112); CppSharp.Parser.AST.ClassLayout.Internal.cctor_2(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); } @@ -3087,7 +3235,7 @@ namespace CppSharp public ClassLayout() { - __Instance = Marshal.AllocHGlobal(88); + __Instance = Marshal.AllocHGlobal(112); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; Internal.ctor_0((__Instance + __PointerAdjustment)); @@ -3095,7 +3243,7 @@ namespace CppSharp public ClassLayout(CppSharp.Parser.AST.ClassLayout _0) { - __Instance = Marshal.AllocHGlobal(88); + __Instance = Marshal.AllocHGlobal(112); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; if (ReferenceEquals(_0, null)) @@ -3138,6 +3286,26 @@ namespace CppSharp Internal.clearVFTables_0((__Instance + __PointerAdjustment)); } + public CppSharp.Parser.AST.LayoutField getFields(uint i) + { + var __ret = new CppSharp.Parser.AST.LayoutField.Internal(); + Internal.getFields_0(new IntPtr(&__ret), (__Instance + __PointerAdjustment), i); + return CppSharp.Parser.AST.LayoutField.__CreateInstance(__ret); + } + + public void addFields(CppSharp.Parser.AST.LayoutField s) + { + if (ReferenceEquals(s, null)) + throw new global::System.ArgumentNullException("s", "Cannot be null because it is a C++ reference (&)."); + var __arg0 = s.__Instance; + Internal.addFields_0((__Instance + __PointerAdjustment), __arg0); + } + + public void clearFields() + { + Internal.clearFields_0((__Instance + __PointerAdjustment)); + } + public uint VFTablesCount { get @@ -3147,6 +3315,15 @@ namespace CppSharp } } + public uint FieldsCount + { + get + { + var __ret = Internal.getFieldsCount_0((__Instance + __PointerAdjustment)); + return __ret; + } + } + public CppSharp.Parser.AST.CppAbi ABI { get @@ -6839,7 +7016,7 @@ namespace CppSharp public unsafe partial class Field : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 160)] + [StructLayout(LayoutKind.Explicit, Size = 152)] public new partial struct Internal { [FieldOffset(0)] @@ -6885,15 +7062,12 @@ namespace CppSharp public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType; [FieldOffset(136)] - public uint Offset; - - [FieldOffset(144)] public global::System.IntPtr Class; - [FieldOffset(152)] + [FieldOffset(144)] public byte IsBitField; - [FieldOffset(156)] + [FieldOffset(148)] public uint BitWidth; [SuppressUnmanagedCodeSecurity] @@ -6924,7 +7098,7 @@ namespace CppSharp private static void* __CopyValue(Field.Internal native) { - var ret = Marshal.AllocHGlobal(160); + var ret = Marshal.AllocHGlobal(152); CppSharp.Parser.AST.Field.Internal.cctor_1(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); } @@ -6948,7 +7122,7 @@ namespace CppSharp public Field() : this((void*) null) { - __Instance = Marshal.AllocHGlobal(160); + __Instance = Marshal.AllocHGlobal(152); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; Internal.ctor_0((__Instance + __PointerAdjustment)); @@ -6957,7 +7131,7 @@ namespace CppSharp public Field(CppSharp.Parser.AST.Field _0) : this((void*) null) { - __Instance = Marshal.AllocHGlobal(160); + __Instance = Marshal.AllocHGlobal(152); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; if (ReferenceEquals(_0, null)) @@ -6988,19 +7162,6 @@ namespace CppSharp } } - public uint Offset - { - get - { - return ((Internal*) __Instance)->Offset; - } - - set - { - ((Internal*) __Instance)->Offset = value; - } - } - public CppSharp.Parser.AST.Class Class { get diff --git a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/AST.cs b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/AST.cs index 3d783698..e7d27a39 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/AST.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/AST.cs @@ -69,14 +69,56 @@ namespace CppSharp Public = 2 } - public enum CXXMethodKind + public enum RawCommentKind { - Normal = 0, - Constructor = 1, - Destructor = 2, - Conversion = 3, - Operator = 4, - UsingDirective = 5 + Invalid = 0, + OrdinaryBCPL = 1, + OrdinaryC = 2, + BCPLSlash = 3, + BCPLExcl = 4, + JavaDoc = 5, + Qt = 6, + Merged = 7 + } + + public enum CommentKind + { + FullComment = 0, + BlockContentComment = 1, + BlockCommandComment = 2, + ParamCommandComment = 3, + TParamCommandComment = 4, + VerbatimBlockComment = 5, + VerbatimLineComment = 6, + ParagraphComment = 7, + HTMLTagComment = 8, + HTMLStartTagComment = 9, + HTMLEndTagComment = 10, + TextComment = 11, + InlineContentComment = 12, + InlineCommandComment = 13, + VerbatimBlockLineComment = 14 + } + + public enum CppAbi + { + Itanium = 0, + Microsoft = 1, + ARM = 2, + iOS = 3, + iOS64 = 4 + } + + public enum VTableComponentKind + { + VCallOffset = 0, + VBaseOffset = 1, + OffsetToTop = 2, + RTTI = 3, + FunctionPointer = 4, + CompleteDtorPointer = 5, + DeletingDtorPointer = 6, + UnusedFunctionPointer = 7 } public enum CXXOperatorKind @@ -138,18 +180,6 @@ namespace CppSharp Unknown = 5 } - public enum StatementClass - { - Any = 0, - BinaryOperator = 1, - CallExprClass = 2, - DeclRefExprClass = 3, - CXXConstructExprClass = 4, - CXXOperatorCallExpr = 5, - ImplicitCastExpr = 6, - ExplicitCastExpr = 7 - } - public enum TemplateSpecializationKind { Undeclared = 0, @@ -159,25 +189,26 @@ namespace CppSharp ExplicitInstantiationDefinition = 4 } - public enum CppAbi + public enum StatementClass { - Itanium = 0, - Microsoft = 1, - ARM = 2, - iOS = 3, - iOS64 = 4 + Any = 0, + BinaryOperator = 1, + CallExprClass = 2, + DeclRefExprClass = 3, + CXXConstructExprClass = 4, + CXXOperatorCallExpr = 5, + ImplicitCastExpr = 6, + ExplicitCastExpr = 7 } - public enum VTableComponentKind + public enum CXXMethodKind { - VCallOffset = 0, - VBaseOffset = 1, - OffsetToTop = 2, - RTTI = 3, - FunctionPointer = 4, - CompleteDtorPointer = 5, - DeletingDtorPointer = 6, - UnusedFunctionPointer = 7 + Normal = 0, + Constructor = 1, + Destructor = 2, + Conversion = 3, + Operator = 4, + UsingDirective = 5 } public enum PrimitiveType @@ -211,37 +242,6 @@ namespace CppSharp FunctionBody = 5 } - public enum RawCommentKind - { - Invalid = 0, - OrdinaryBCPL = 1, - OrdinaryC = 2, - BCPLSlash = 3, - BCPLExcl = 4, - JavaDoc = 5, - Qt = 6, - Merged = 7 - } - - public enum CommentKind - { - FullComment = 0, - BlockContentComment = 1, - BlockCommandComment = 2, - ParamCommandComment = 3, - TParamCommandComment = 4, - VerbatimBlockComment = 5, - VerbatimLineComment = 6, - ParagraphComment = 7, - HTMLTagComment = 8, - HTMLStartTagComment = 9, - HTMLEndTagComment = 10, - TextComment = 11, - InlineContentComment = 12, - InlineCommandComment = 13, - VerbatimBlockLineComment = 14 - } - public enum ArchType { UnknownArch = 0, @@ -2985,9 +2985,137 @@ namespace CppSharp } } + public unsafe partial class LayoutField : IDisposable + { + [StructLayout(LayoutKind.Explicit, Size = 16)] + public partial struct Internal + { + [FieldOffset(0)] + public uint Offset; + + [FieldOffset(8)] + public global::System.IntPtr Field; + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="??0LayoutField@AST@CppParser@CppSharp@@QEAA@XZ")] + internal static extern global::System.IntPtr ctor_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="??0LayoutField@AST@CppParser@CppSharp@@QEAA@AEBV0123@@Z")] + internal static extern global::System.IntPtr cctor_1(global::System.IntPtr instance, global::System.IntPtr _0); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="??1LayoutField@AST@CppParser@CppSharp@@QEAA@XZ")] + internal static extern void dtor_0(global::System.IntPtr instance, int delete); + } + + public global::System.IntPtr __Instance { get; protected set; } + + protected int __PointerAdjustment; + public static readonly System.Collections.Concurrent.ConcurrentDictionary NativeToManagedMap = new System.Collections.Concurrent.ConcurrentDictionary(); + protected void*[] __OriginalVTables; + + protected bool __ownsNativeInstance; + + public static LayoutField __CreateInstance(global::System.IntPtr native, bool skipVTables = false) + { + return new LayoutField(native.ToPointer(), skipVTables); + } + + public static LayoutField __CreateInstance(LayoutField.Internal native, bool skipVTables = false) + { + return new LayoutField(native, skipVTables); + } + + private static void* __CopyValue(LayoutField.Internal native) + { + var ret = Marshal.AllocHGlobal(16); + *(LayoutField.Internal*) ret = native; + return ret.ToPointer(); + } + + private LayoutField(LayoutField.Internal native, bool skipVTables = false) + : this(__CopyValue(native), skipVTables) + { + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + } + + protected LayoutField(void* native, bool skipVTables = false) + { + if (native == null) + return; + __Instance = new global::System.IntPtr(native); + } + + public LayoutField() + { + __Instance = Marshal.AllocHGlobal(16); + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + Internal.ctor_0((__Instance + __PointerAdjustment)); + } + + public LayoutField(CppSharp.Parser.AST.LayoutField _0) + { + __Instance = Marshal.AllocHGlobal(16); + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + *((LayoutField.Internal*) __Instance) = *((LayoutField.Internal*) _0.__Instance); + } + + public void Dispose() + { + Dispose(disposing: true); + } + + protected virtual void Dispose(bool disposing) + { + CppSharp.Parser.AST.LayoutField __dummy; + NativeToManagedMap.TryRemove(__Instance, out __dummy); + Internal.dtor_0((__Instance + __PointerAdjustment), 0); + if (__ownsNativeInstance) + Marshal.FreeHGlobal(__Instance); + } + + public uint Offset + { + get + { + return ((Internal*) __Instance)->Offset; + } + + set + { + ((Internal*) __Instance)->Offset = value; + } + } + + public CppSharp.Parser.AST.Field Field + { + get + { + CppSharp.Parser.AST.Field __result0; + 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]; + else __result0 = CppSharp.Parser.AST.Field.__CreateInstance(((Internal*) __Instance)->Field); + return __result0; + } + + set + { + ((Internal*) __Instance)->Field = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance; + } + } + } + public unsafe partial class ClassLayout : IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 80)] + [StructLayout(LayoutKind.Explicit, Size = 104)] public partial struct Internal { [FieldOffset(0)] @@ -3041,10 +3169,30 @@ namespace CppSharp EntryPoint="?clearVFTables@ClassLayout@AST@CppParser@CppSharp@@QEAAXXZ")] internal static extern void clearVFTables_0(global::System.IntPtr instance); + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="?getFields@ClassLayout@AST@CppParser@CppSharp@@QEAA?AVLayoutField@234@I@Z")] + internal static extern void getFields_0(global::System.IntPtr instance, global::System.IntPtr @return, uint i); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="?addFields@ClassLayout@AST@CppParser@CppSharp@@QEAAXAEAVLayoutField@234@@Z")] + internal static extern void addFields_0(global::System.IntPtr instance, global::System.IntPtr s); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="?clearFields@ClassLayout@AST@CppParser@CppSharp@@QEAAXXZ")] + internal static extern void clearFields_0(global::System.IntPtr instance); + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, EntryPoint="?getVFTablesCount@ClassLayout@AST@CppParser@CppSharp@@QEAAIXZ")] internal static extern uint getVFTablesCount_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="?getFieldsCount@ClassLayout@AST@CppParser@CppSharp@@QEAAIXZ")] + internal static extern uint getFieldsCount_0(global::System.IntPtr instance); } public global::System.IntPtr __Instance { get; protected set; } @@ -3067,7 +3215,7 @@ namespace CppSharp private static void* __CopyValue(ClassLayout.Internal native) { - var ret = Marshal.AllocHGlobal(80); + var ret = Marshal.AllocHGlobal(104); CppSharp.Parser.AST.ClassLayout.Internal.cctor_2(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); } @@ -3088,7 +3236,7 @@ namespace CppSharp public ClassLayout() { - __Instance = Marshal.AllocHGlobal(80); + __Instance = Marshal.AllocHGlobal(104); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; Internal.ctor_0((__Instance + __PointerAdjustment)); @@ -3096,7 +3244,7 @@ namespace CppSharp public ClassLayout(CppSharp.Parser.AST.ClassLayout _0) { - __Instance = Marshal.AllocHGlobal(80); + __Instance = Marshal.AllocHGlobal(104); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; if (ReferenceEquals(_0, null)) @@ -3139,6 +3287,26 @@ namespace CppSharp Internal.clearVFTables_0((__Instance + __PointerAdjustment)); } + public CppSharp.Parser.AST.LayoutField getFields(uint i) + { + var __ret = new CppSharp.Parser.AST.LayoutField.Internal(); + Internal.getFields_0((__Instance + __PointerAdjustment), new IntPtr(&__ret), i); + return CppSharp.Parser.AST.LayoutField.__CreateInstance(__ret); + } + + public void addFields(CppSharp.Parser.AST.LayoutField s) + { + if (ReferenceEquals(s, null)) + throw new global::System.ArgumentNullException("s", "Cannot be null because it is a C++ reference (&)."); + var __arg0 = s.__Instance; + Internal.addFields_0((__Instance + __PointerAdjustment), __arg0); + } + + public void clearFields() + { + Internal.clearFields_0((__Instance + __PointerAdjustment)); + } + public uint VFTablesCount { get @@ -3148,6 +3316,15 @@ namespace CppSharp } } + public uint FieldsCount + { + get + { + var __ret = Internal.getFieldsCount_0((__Instance + __PointerAdjustment)); + return __ret; + } + } + public CppSharp.Parser.AST.CppAbi ABI { get @@ -6840,7 +7017,7 @@ namespace CppSharp public unsafe partial class Field : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 232)] + [StructLayout(LayoutKind.Explicit, Size = 224)] public new partial struct Internal { [FieldOffset(0)] @@ -6886,15 +7063,12 @@ namespace CppSharp public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType; [FieldOffset(208)] - public uint Offset; - - [FieldOffset(216)] public global::System.IntPtr Class; - [FieldOffset(224)] + [FieldOffset(216)] public byte IsBitField; - [FieldOffset(228)] + [FieldOffset(220)] public uint BitWidth; [SuppressUnmanagedCodeSecurity] @@ -6925,7 +7099,7 @@ namespace CppSharp private static void* __CopyValue(Field.Internal native) { - var ret = Marshal.AllocHGlobal(232); + var ret = Marshal.AllocHGlobal(224); CppSharp.Parser.AST.Field.Internal.cctor_1(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); } @@ -6949,7 +7123,7 @@ namespace CppSharp public Field() : this((void*) null) { - __Instance = Marshal.AllocHGlobal(232); + __Instance = Marshal.AllocHGlobal(224); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; Internal.ctor_0((__Instance + __PointerAdjustment)); @@ -6958,7 +7132,7 @@ namespace CppSharp public Field(CppSharp.Parser.AST.Field _0) : this((void*) null) { - __Instance = Marshal.AllocHGlobal(232); + __Instance = Marshal.AllocHGlobal(224); __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; if (ReferenceEquals(_0, null)) @@ -6989,19 +7163,6 @@ namespace CppSharp } } - public uint Offset - { - get - { - return ((Internal*) __Instance)->Offset; - } - - set - { - ((Internal*) __Instance)->Offset = value; - } - } - public CppSharp.Parser.AST.Class Class { get diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index c91aa8c8..5a6f3bbf 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -82,6 +82,81 @@ std::string GetCurrentLibraryDir() #endif } +void Parser::ReadLayoutFields(Class* Class, const clang::RecordDecl *RD, + clang::CharUnits Offset, bool IncludeVirtualBases) +{ + using namespace clang; + + const auto &Layout = C->getASTContext().getASTRecordLayout(RD); + auto CXXRD = dyn_cast(RD); + + // Dump bases. + if (CXXRD) { + // Collect nvbases. + SmallVector Bases; + for (const CXXBaseSpecifier &Base : CXXRD->bases()) { + assert(!Base.getType()->isDependentType() && + "Cannot layout class with dependent bases."); + if (!Base.isVirtual()) + Bases.push_back(Base.getType()->getAsCXXRecordDecl()); + } + + // Sort nvbases by offset. + std::stable_sort(Bases.begin(), Bases.end(), + [&](const CXXRecordDecl *L, const CXXRecordDecl *R) { + return Layout.getBaseClassOffset(L) < Layout.getBaseClassOffset(R); + }); + + // Dump (non-virtual) bases + for (const CXXRecordDecl *Base : Bases) { + CharUnits BaseOffset = Offset + Layout.getBaseClassOffset(Base); + ReadLayoutFields(Class, Base, BaseOffset, + /*IncludeVirtualBases=*/false); + } + } + + // Dump fields. + uint64_t FieldNo = 0; + for (RecordDecl::field_iterator I = RD->field_begin(), + E = RD->field_end(); I != E; ++I, ++FieldNo) { + const FieldDecl &Field = **I; + uint64_t LocalFieldOffsetInBits = Layout.getFieldOffset(FieldNo); + CharUnits FieldOffset = + Offset + C->getASTContext().toCharUnitsFromBits(LocalFieldOffsetInBits); + + // Recursively dump fields of record type. + if (auto RT = Field.getType()->getAs()) + { + auto TU = GetTranslationUnit(RT->getDecl()); + if (TU->IsSystemHeader) + continue; + } + + auto Parent = WalkDeclaration(RD, /*IgnoreSystemDecls =*/false); + auto F = WalkFieldCXX(&Field, static_cast(Parent)); + LayoutField LayoutField; + LayoutField.Offset = FieldOffset.getQuantity(); + LayoutField.Field = F; + Class->Layout->Fields.push_back(LayoutField); + } + + // Dump virtual bases. + if (CXXRD && IncludeVirtualBases) { + const ASTRecordLayout::VBaseOffsetsMapTy &VtorDisps = + Layout.getVBaseOffsetsMap(); + + for (const CXXBaseSpecifier &Base : CXXRD->vbases()) { + assert(Base.isVirtual() && "Found non-virtual class!"); + const CXXRecordDecl *VBase = Base.getType()->getAsCXXRecordDecl(); + + CharUnits VBaseOffset = Offset + Layout.getVBaseClassOffset(VBase); + + ReadLayoutFields(Class, VBase, VBaseOffset, + /*IncludeVirtualBases=*/false); + } + } +} + static std::string GetClangResourceDir() { using namespace llvm; @@ -729,6 +804,7 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC) RC->Layout->Alignment = (int)Layout-> getAlignment().getQuantity(); RC->Layout->Size = (int)Layout->getSize().getQuantity(); RC->Layout->DataSize = (int)Layout->getDataSize().getQuantity(); + ReadLayoutFields(RC, Record, CharUnits(), true); } for(auto it = Record->decls_begin(); it != Record->decls_end(); ++it) @@ -749,11 +825,7 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC) case Decl::Field: { auto FD = cast(D); - auto Field = WalkFieldCXX(FD, RC); - - if (Layout) - Field->Offset = Layout->getFieldOffset(FD->getFieldIndex()); - + WalkFieldCXX(FD, RC); break; } case Decl::AccessSpec: @@ -1343,6 +1415,12 @@ Field* Parser::WalkFieldCXX(const clang::FieldDecl* FD, Class* Class) const auto& USR = GetDeclUSR(FD); + auto FoundField = std::find_if(Class->Fields.begin(), Class->Fields.end(), + [&](Field* Field) { return Field->USR == USR; }); + + if (FoundField != Class->Fields.end()) + return *FoundField; + auto F = new Field(); HandleDeclaration(FD, F); diff --git a/src/CppParser/Parser.h b/src/CppParser/Parser.h index 82811046..bcc0bba0 100644 --- a/src/CppParser/Parser.h +++ b/src/CppParser/Parser.h @@ -98,6 +98,7 @@ private: std::vector WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, const clang::ASTTemplateArgumentListInfo* TSTL); void WalkVTable(const clang::CXXRecordDecl* RD, Class* C); QualifiedType GetQualifiedType(clang::QualType qual, clang::TypeLoc* TL = 0); + void ReadLayoutFields(Class * Class, const clang::RecordDecl * RD, clang::CharUnits Offset, bool IncludeVirtualBases); VTableLayout WalkVTableLayout(const clang::VTableLayout& VTLayout); VTableComponent WalkVTableComponent(const clang::VTableComponent& Component); PreprocessedEntity* WalkPreprocessedEntity(Declaration* Decl, diff --git a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs index 9d7ce3f3..ad16d084 100644 --- a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs +++ b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs @@ -439,9 +439,9 @@ namespace CppSharp.Generators.CLI PushIndent(); // 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 - foreach (var field in @class.Fields.Where(f => !ASTUtils.CheckIgnoreField(f))) + foreach (var field in @class.Layout.Fields.Where(f => !ASTUtils.CheckIgnoreField(f.Field))) { - var property = @class.Properties.FirstOrDefault(p => p.Field == field); + var property = @class.Properties.FirstOrDefault(p => p.Field == field.Field); if (property != null && !property.IsInRefTypeAndBackedByValueClassField()) { GenerateField(@class, field); @@ -450,15 +450,15 @@ namespace CppSharp.Generators.CLI PopIndent(); } - private void GenerateField(Class @class, Field field) + private void GenerateField(Class @class, LayoutField layoutField) { - PushBlock(CLIBlockKind.Field, field); + PushBlock(CLIBlockKind.Field, layoutField.Field); - GenerateDeclarationCommon(field); + GenerateDeclarationCommon(layoutField.Field); if (@class.IsUnion) WriteLine("[System::Runtime::InteropServices::FieldOffset({0})]", - field.Offset); - WriteLine("{0} {1};", field.Type, field.Name); + layoutField.Offset); + WriteLine("{0} {1};", layoutField.Field.Type, layoutField.Field.Name); PopBlock(); } @@ -630,7 +630,7 @@ namespace CppSharp.Generators.CLI { if (prop.IsInRefTypeAndBackedByValueClassField()) { - GenerateField(@class, prop.Field); + GenerateField(@class, @class.Layout.Fields.Single(f => f.Field == prop.Field)); continue; } diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index b566fa37..f3b1f9b0 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -603,7 +603,8 @@ namespace CppSharp.Generators.CSharp if (@class.IsDynamic) GenerateVTablePointers(@class); - GenerateClassFields(@class, @class, GenerateClassInternalsField, true); + foreach (var field in @class.Layout.Fields) + GenerateClassInternalsField(field); if (@class.IsGenerated && !(@class is ClassTemplateSpecialization)) { var functions = GatherClassInternalFunctions(@class); @@ -790,16 +791,16 @@ namespace CppSharp.Generators.CSharp } } - private void GenerateClassInternalsField(Class owner, Field field) + private void GenerateClassInternalsField(LayoutField layoutField) { // we do not support dependent fields yet, see https://github.com/mono/CppSharp/issues/197 - Class @class; - field.Type.TryGetClass(out @class); - if ((field.Type.IsDependent && !field.Type.IsPointer() && - !(@class != null && @class.IsUnion)) || (@class != null && @class.TranslationUnit.IsSystemHeader)) + Declaration decl; + var field = layoutField.Field; + field.Type.TryGetDeclaration(out decl); + if (decl != null && decl.TranslationUnit.IsSystemHeader) return; - var safeIdentifier = Helpers.SafeIdentifier(field.InternalName); + var safeIdentifier = Helpers.SafeIdentifier(layoutField.Name); if(safeIdentifier.All(c => c.Equals('_'))) { @@ -808,8 +809,7 @@ namespace CppSharp.Generators.CSharp PushBlock(CSharpBlockKind.Field); - WriteLine("[FieldOffset({0})]", field.OffsetInBytes + - owner.ComputeNonVirtualBaseClassOffsetTo((Class) field.Namespace)); + WriteLine("[FieldOffset({0})]", layoutField.Offset); TypePrinter.PushMarshalKind(CSharpMarshalKind.NativeField); var fieldTypePrinted = field.QualifiedType.CSharpType(TypePrinter); @@ -822,7 +822,7 @@ namespace CppSharp.Generators.CSharp if (!string.IsNullOrWhiteSpace(fieldTypePrinted.NameSuffix)) fieldName += fieldTypePrinted.NameSuffix; - var access = @class != null && !@class.IsGenerated ? "internal" : "public"; + var access = decl != null && !decl.IsGenerated ? "internal" : "public"; if (field.Expression != null) { var fieldValuePrinted = field.Expression.CSharpValue(ExpressionPrinter); @@ -848,11 +848,11 @@ namespace CppSharp.Generators.CSharp Name = string.Format("{0}_{1}_{2}", Helpers.DummyIdentifier, safeIdentifier, i), QualifiedType = new QualifiedType(arrayType.Type), - Offset = (uint) (field.Offset + i * arrayType.ElementSize), - Namespace = owner + Namespace = field.Namespace }; - GenerateClassInternalsField(owner, dummy); + GenerateClassInternalsField(new LayoutField( + (uint) (layoutField.Offset + i * arrayType.ElementSize / 8), dummy)); } } } @@ -975,12 +975,13 @@ namespace CppSharp.Generators.CSharp } else { + var name = @class.Layout.Fields.First(f => f.Field == field).Name; ctx.ReturnVarName = string.Format("{0}{1}{2}", - @class.IsValueType - ? Helpers.InstanceField - : string.Format("((Internal*) {0})", Helpers.InstanceIdentifier), - @class.IsValueType ? "." : "->", - Helpers.SafeIdentifier(field.InternalName)); + @class.IsValueType + ? Helpers.InstanceField + : string.Format("((Internal*) {0})", Helpers.InstanceIdentifier), + @class.IsValueType ? "." : "->", + Helpers.SafeIdentifier(name)); } param.Visit(marshal); @@ -1026,9 +1027,9 @@ namespace CppSharp.Generators.CSharp type = originalType.ToString(); } + var name = ((Class) field.Namespace).Layout.Fields.First(f => f.Field == field).Name; WriteLine(string.Format("fixed ({0} {1} = {2}.{3})", - type, arrPtrIden, Helpers.InstanceField, - Helpers.SafeIdentifier(field.InternalName))); + type, arrPtrIden, Helpers.InstanceField, Helpers.SafeIdentifier(name))); WriteStartBraceIndent(); if (Driver.Options.MarshalCharAsManagedChar && isChar) WriteLine("var {0} = ({1}) {2};", arrPtr, originalType, arrPtrIden); @@ -1117,6 +1118,7 @@ namespace CppSharp.Generators.CSharp NewLine(); WriteStartBraceIndent(); + var name = @class.Layout.Fields.First(f => f.Field == field).Name; var ctx = new CSharpMarshalContext(Driver) { Kind = CSharpMarshalKind.NativeField, @@ -1126,7 +1128,7 @@ namespace CppSharp.Generators.CSharp ? Helpers.InstanceField : string.Format("((Internal*) {0})", Helpers.InstanceIdentifier), @class.IsValueType ? "." : "->", - Helpers.SafeIdentifier(field.InternalName)), + Helpers.SafeIdentifier(name)), ReturnType = decl.QualifiedType }; @@ -1298,9 +1300,10 @@ namespace CppSharp.Generators.CSharp ArrayType arrayType = prop.Type as ArrayType; if (arrayType != null && arrayType.Type.IsPointerToPrimitiveType() && prop.Field != null) { + var name = @class.Layout.Fields.First(f => f.Field == prop.Field).Name; GenerateClassField(prop.Field); WriteLine("private bool {0};", - GeneratedIdentifier(string.Format("{0}Initialised", prop.Field.InternalName))); + GeneratedIdentifier(string.Format("{0}Initialised", name))); } GenerateDeclarationCommon(prop); diff --git a/src/Generator/Passes/CheckDuplicatedNamesPass.cs b/src/Generator/Passes/CheckDuplicatedNamesPass.cs index e713c1ce..fc3811dd 100644 --- a/src/Generator/Passes/CheckDuplicatedNamesPass.cs +++ b/src/Generator/Passes/CheckDuplicatedNamesPass.cs @@ -152,7 +152,7 @@ namespace CppSharp.Passes public override bool VisitClassDecl(Class @class) { - if (!VisitDeclaration(@class)) + if (!base.VisitClassDecl(@class)) return false; if (@class.IsIncomplete) @@ -166,11 +166,17 @@ namespace CppSharp.Passes foreach (var function in @class.Functions) VisitFunctionDecl(function); - foreach (var fields in GetAllFields(@class).GroupBy(f => f.OriginalName).Where( - g => !string.IsNullOrEmpty(g.Key)).Select(g => g.ToList())) + if (!@class.IsDependent) { - for (var i = 1; i < fields.Count; i++) - fields[i].InternalName = fields[i].OriginalName + i; + foreach (var fields in @class.Layout.Fields.GroupBy( + f => f.Field.OriginalName).Select(g => g.ToList())) + { + for (var i = 1; i < fields.Count; i++) + { + var name = fields[i].Field.OriginalName; + fields[i].Name = (string.IsNullOrEmpty(name) ? "__" : name) + i; + } + } } foreach (var property in @class.Properties)