using System.Collections.Generic; using System.Diagnostics; namespace CppSharp.AST { /// /// Virtual table component kind. /// public enum VTableComponentKind { VCallOffset, VBaseOffset, OffsetToTop, RTTI, FunctionPointer, CompleteDtorPointer, DeletingDtorPointer, UnusedFunctionPointer, } /// /// Represents a C++ virtual table component. /// [DebuggerDisplay("{Kind}, {Offset}, {Declaration}")] public struct VTableComponent { public VTableComponentKind Kind; public ulong Offset; public Declaration Declaration; /// Method declaration (if Kind == FunctionPointer). public Method Method { get { Debug.Assert(Kind == VTableComponentKind.FunctionPointer); return Declaration as Method; } } public bool Ignore { get { return Method != null && !Method.IsDeclared && ((Class) Method.Namespace).GetPropertyByConstituentMethod(Method) == null; } } } /// /// Represents a C++ virtual table layout. /// public class VTableLayout { public List Components { get; set; } public VTableLayout() { Components = new List(); } } /// /// Contains information about virtual function pointers. /// public struct VFTableInfo { /// If nonzero, holds the vbtable index of the virtual base with the vfptr. public ulong VBTableIndex; /// This is the offset of the vfptr from the start of the last vbase, /// or the complete type if there are no virtual bases. public long VFPtrOffset; /// This is the full offset of the vfptr from the start of the complete type. public long VFPtrFullOffset; /// Layout of the table at this pointer. public VTableLayout Layout; } // Represents ABI-specific layout details for a class. public class ClassLayout { public CppAbi ABI { get; set; } /// Virtual function tables in Microsoft mode. public List VFTables { get; set; } /// Virtual table layout in Itanium mode. public VTableLayout Layout { get; set; } public ClassLayout() { VFTables = new List(); } public ClassLayout(ClassLayout classLayout) : this() { ABI = classLayout.ABI; HasOwnVFPtr = classLayout.HasOwnVFPtr; VBPtrOffset = classLayout.VBPtrOffset; PrimaryBase = classLayout.PrimaryBase; HasVirtualBases = classLayout.HasVirtualBases; Alignment = classLayout.Alignment; Size = classLayout.Size; DataSize = classLayout.DataSize; VFTables.AddRange(classLayout.VFTables); if (classLayout.Layout != null) { Layout = new VTableLayout(); Layout.Components.AddRange(classLayout.Layout.Components); } } /// /// Does this class provide its own virtual-function table /// pointer, rather than inheriting one from a primary base /// class? If so, it is at offset zero. /// public bool HasOwnVFPtr; /// /// Get the offset for virtual base table pointer. /// This is only meaningful with the Microsoft ABI. /// public long VBPtrOffset; /// /// Primary base for this record. /// public Class PrimaryBase; public bool HasVirtualBases; public int Alignment; public int Size; public int DataSize; } }