Browse Source

Fixed VTables.GetVTableIndex to work with base/derived overrides.

pull/552/merge
triton 10 years ago
parent
commit
24eb7cf825
  1. 12
      src/Generator/AST/VTables.cs
  2. 2
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

12
src/Generator/AST/VTables.cs

@ -72,13 +72,21 @@ namespace CppSharp.AST @@ -72,13 +72,21 @@ namespace CppSharp.AST
throw new NotSupportedException();
}
public static int GetVTableIndex(INamedDecl method, Class @class)
static bool CanOverride(Method method, Method @override)
{
return method.OriginalName == @override.OriginalName &&
method.ReturnType == @override.ReturnType &&
method.Parameters.SequenceEqual(@override.Parameters,
new ParameterTypeComparer());
}
public static int GetVTableIndex(Method method, Class @class)
{
switch (@class.Layout.ABI)
{
case CppAbi.Microsoft:
return (from table in @class.Layout.VFTables
let j = table.Layout.Components.FindIndex(m => m.Method == method)
let j = table.Layout.Components.FindIndex(m => CanOverride(m.Method, method))
where j >= 0
select j).First();
default:

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

@ -2329,7 +2329,7 @@ namespace CppSharp.Generators.CSharp @@ -2329,7 +2329,7 @@ namespace CppSharp.Generators.CSharp
out string delegateId)
{
var virtualCallBuilder = new StringBuilder();
var i = VTables.GetVTableIndex(function.OriginalFunction, @class);
var i = VTables.GetVTableIndex(function.OriginalFunction as Method, @class);
virtualCallBuilder.AppendFormat("void* slot = *(void**) ((({0}.Internal*) {1})->vfptr0 + {2} * {3});",
@class.Name, Helpers.InstanceIdentifier, i, Driver.TargetInfo.PointerWidth / 8);
virtualCallBuilder.AppendLine();

Loading…
Cancel
Save