diff --git a/src/Generator/AST/VTables.cs b/src/Generator/AST/VTables.cs index f910724f..e4b560f2 100644 --- a/src/Generator/AST/VTables.cs +++ b/src/Generator/AST/VTables.cs @@ -19,7 +19,7 @@ namespace CppSharp.AST throw new NotSupportedException(); } - public static List GatherVTableMethodEntries(VTableLayout layout) + private static List GatherVTableMethodEntries(VTableLayout layout) { var entries = new List(); if (layout == null) @@ -50,11 +50,6 @@ namespace CppSharp.AST return GatherVTableMethodEntries(@class.Layout.Layout); } - public static int GetVTableComponentIndex(VTableLayout layout, VTableComponent entry) - { - return layout.Components.IndexOf(entry); - } - public static int GetVTableComponentIndex(Class @class, VTableComponent entry) { switch (@class.Layout.ABI) @@ -62,13 +57,14 @@ namespace CppSharp.AST case CppAbi.Microsoft: foreach (var vfptr in @class.Layout.VFTables) { - var index = GetVTableComponentIndex(vfptr.Layout, entry); + var index = vfptr.Layout.Components.IndexOf(entry); if (index >= 0) return index; } break; case CppAbi.Itanium: - return GetVTableComponentIndex(@class.Layout.Layout, entry); + // ignore offset to top and RTTI + return @class.Layout.Layout.Components.IndexOf(entry) - 2; } throw new NotSupportedException(); diff --git a/tests/VTables/VTables.Tests.cs b/tests/VTables/VTables.Tests.cs index 29018329..de91f18c 100644 --- a/tests/VTables/VTables.Tests.cs +++ b/tests/VTables/VTables.Tests.cs @@ -19,8 +19,9 @@ public class VTablesTests : GeneratorTestFixture { var foo = new Foo(); Assert.That(foo.vfoo(), Is.EqualTo(5)); - Assert.That(foo.Vbar(), Is.EqualTo(3)); + Assert.That(foo.Vbar(), Is.EqualTo(5)); Assert.That(foo.CallFoo(), Is.EqualTo(7)); + Assert.That(foo.CallVirtualWithParameter(6514), Is.EqualTo(6514 + 1)); var foo2 = new FooDerived(); Assert.That(foo2.CallFoo(), Is.EqualTo(12)); diff --git a/tests/VTables/VTables.cpp b/tests/VTables/VTables.cpp index 249d3bd1..d80d7e88 100644 --- a/tests/VTables/VTables.cpp +++ b/tests/VTables/VTables.cpp @@ -11,7 +11,7 @@ int Foo::vfoo() int Foo::vbar() { - return 3; + return vfoo(); } int Foo::append() @@ -24,7 +24,12 @@ int Foo::append(int a) return ++a; } +int Foo::callVirtualWithParameter(int a) +{ + return append(a); +} + int FooCallFoo(Foo* foo) { return foo->vfoo() + 2; -} \ No newline at end of file +} diff --git a/tests/VTables/VTables.h b/tests/VTables/VTables.h index b72fe452..dae69f35 100644 --- a/tests/VTables/VTables.h +++ b/tests/VTables/VTables.h @@ -18,7 +18,7 @@ public: virtual int append(); virtual int append(int a); - void callVirtualWithParameter(int a); + int callVirtualWithParameter(int a); }; DLL_API int FooCallFoo(Foo* foo);