From 7d66303ed18d4703903e1e87761ce0e14cc39bba Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sun, 11 Oct 2015 03:34:11 +0300 Subject: [PATCH] Extracted a constant and deleted a no longer used method. Signed-off-by: Dimitar Dobrev --- src/Generator/AST/VTables.cs | 25 +++---------------- .../Generators/CSharp/CSharpTextTemplate.cs | 7 +++--- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/Generator/AST/VTables.cs b/src/Generator/AST/VTables.cs index b1a7f00d..b16a8e13 100644 --- a/src/Generator/AST/VTables.cs +++ b/src/Generator/AST/VTables.cs @@ -6,6 +6,8 @@ namespace CppSharp.AST { public static class VTables { + public const int ItaniumOffsetToTopAndRTTI = 2; + public static List GatherVTableMethodEntries(Class @class) { switch (@class.Layout.ABI) @@ -52,26 +54,6 @@ namespace CppSharp.AST return GatherVTableMethodEntries(@class.Layout.Layout); } - public static int GetVTableComponentIndex(Class @class, VTableComponent entry) - { - switch (@class.Layout.ABI) - { - case CppAbi.Microsoft: - foreach (var vfptr in @class.Layout.VFTables) - { - var index = vfptr.Layout.Components.IndexOf(entry); - if (index >= 0) - return index; - } - break; - default: - // ignore offset to top and RTTI - return @class.Layout.Layout.Components.IndexOf(entry) - 2; - } - - throw new NotSupportedException(); - } - public static int GetVTableIndex(Function function, Class @class) { @@ -83,8 +65,7 @@ namespace CppSharp.AST where j >= 0 select j).First(); default: - // ignore offset to top and RTTI - return @class.Layout.Layout.Components.FindIndex(m => m.Method == function) - 2; + return @class.Layout.Layout.Components.FindIndex(m => m.Method == function) - ItaniumOffsetToTopAndRTTI; } } diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 4f2b481c..6a85684c 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1407,8 +1407,7 @@ namespace CppSharp.Generators.CSharp var pointerSize = Driver.TargetInfo.PointerWidth / 8; WriteLine("var vtptr = Marshal.AllocHGlobal({0} * {1});", size, pointerSize); - const int offsetToTopAndRTTI = 2; - WriteLine("var vfptr0 = vtptr + {0} * {1};", offsetToTopAndRTTI, pointerSize); + WriteLine("var vfptr0 = vtptr + {0} * {1};", VTables.ItaniumOffsetToTopAndRTTI, pointerSize); WriteLine("__ManagedVTables[0] = vfptr0.ToPointer();"); AllocateNewVTableEntries(@class.Layout.Layout.Components, @@ -1423,12 +1422,12 @@ namespace CppSharp.Generators.CSharp private void AllocateNewVTableEntries(IList entries, IList wrappedEntries, int tableIndex) { - const int offsetToTopAndRTTI = 2; var pointerSize = Driver.TargetInfo.PointerWidth / 8; for (int i = 0; i < entries.Count; i++) { var entry = entries[i]; - var offsetInBytes = (i - (Options.IsMicrosoftAbi ? 0 : offsetToTopAndRTTI)) * pointerSize; + var offsetInBytes = pointerSize + * (i - (Options.IsMicrosoftAbi ? 0 : VTables.ItaniumOffsetToTopAndRTTI)); if ((entry.Kind == VTableComponentKind.FunctionPointer || entry.Kind == VTableComponentKind.DeletingDtorPointer) &&