Browse Source

Extracted a constant and deleted a no longer used method.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/1132/head
Dimitar Dobrev 10 years ago
parent
commit
7d66303ed1
  1. 25
      src/Generator/AST/VTables.cs
  2. 7
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

25
src/Generator/AST/VTables.cs

@ -6,6 +6,8 @@ namespace CppSharp.AST
{ {
public static class VTables public static class VTables
{ {
public const int ItaniumOffsetToTopAndRTTI = 2;
public static List<VTableComponent> GatherVTableMethodEntries(Class @class) public static List<VTableComponent> GatherVTableMethodEntries(Class @class)
{ {
switch (@class.Layout.ABI) switch (@class.Layout.ABI)
@ -52,26 +54,6 @@ namespace CppSharp.AST
return GatherVTableMethodEntries(@class.Layout.Layout); 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) public static int GetVTableIndex(Function function, Class @class)
{ {
@ -83,8 +65,7 @@ namespace CppSharp.AST
where j >= 0 where j >= 0
select j).First(); select j).First();
default: default:
// ignore offset to top and RTTI return @class.Layout.Layout.Components.FindIndex(m => m.Method == function) - ItaniumOffsetToTopAndRTTI;
return @class.Layout.Layout.Components.FindIndex(m => m.Method == function) - 2;
} }
} }

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

@ -1407,8 +1407,7 @@ namespace CppSharp.Generators.CSharp
var pointerSize = Driver.TargetInfo.PointerWidth / 8; var pointerSize = Driver.TargetInfo.PointerWidth / 8;
WriteLine("var vtptr = Marshal.AllocHGlobal({0} * {1});", size, pointerSize); WriteLine("var vtptr = Marshal.AllocHGlobal({0} * {1});", size, pointerSize);
const int offsetToTopAndRTTI = 2; WriteLine("var vfptr0 = vtptr + {0} * {1};", VTables.ItaniumOffsetToTopAndRTTI, pointerSize);
WriteLine("var vfptr0 = vtptr + {0} * {1};", offsetToTopAndRTTI, pointerSize);
WriteLine("__ManagedVTables[0] = vfptr0.ToPointer();"); WriteLine("__ManagedVTables[0] = vfptr0.ToPointer();");
AllocateNewVTableEntries(@class.Layout.Layout.Components, AllocateNewVTableEntries(@class.Layout.Layout.Components,
@ -1423,12 +1422,12 @@ namespace CppSharp.Generators.CSharp
private void AllocateNewVTableEntries(IList<VTableComponent> entries, private void AllocateNewVTableEntries(IList<VTableComponent> entries,
IList<VTableComponent> wrappedEntries, int tableIndex) IList<VTableComponent> wrappedEntries, int tableIndex)
{ {
const int offsetToTopAndRTTI = 2;
var pointerSize = Driver.TargetInfo.PointerWidth / 8; var pointerSize = Driver.TargetInfo.PointerWidth / 8;
for (int i = 0; i < entries.Count; i++) for (int i = 0; i < entries.Count; i++)
{ {
var entry = entries[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 || if ((entry.Kind == VTableComponentKind.FunctionPointer ||
entry.Kind == VTableComponentKind.DeletingDtorPointer) && entry.Kind == VTableComponentKind.DeletingDtorPointer) &&

Loading…
Cancel
Save