Browse Source

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

pull/552/merge
triton 11 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
throw new NotSupportedException(); 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) switch (@class.Layout.ABI)
{ {
case CppAbi.Microsoft: case CppAbi.Microsoft:
return (from table in @class.Layout.VFTables 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 where j >= 0
select j).First(); select j).First();
default: default:

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

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

Loading…
Cancel
Save