Browse Source

Simplified the generation of virtual calls.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1160/head
Dimitar Dobrev 7 years ago
parent
commit
a430d19870
  1. 3
      src/Generator/AST/VTables.cs
  2. 17
      src/Generator/Generators/CSharp/CSharpSources.cs

3
src/Generator/AST/VTables.cs

@ -55,8 +55,9 @@ namespace CppSharp.AST
return GatherVTableMethodEntries(@class.Layout.Layout); return GatherVTableMethodEntries(@class.Layout.Layout);
} }
public static int GetVTableIndex(Function function, Class @class) public static int GetVTableIndex(Function function)
{ {
var @class = (Class) function.Namespace;
switch (@class.Layout.ABI) switch (@class.Layout.ABI)
{ {
case CppAbi.Microsoft: case CppAbi.Microsoft:

17
src/Generator/Generators/CSharp/CSharpSources.cs

@ -2071,7 +2071,7 @@ namespace CppSharp.Generators.CSharp
private void GenerateDestructorCall(Method dtor) private void GenerateDestructorCall(Method dtor)
{ {
var @class = (Class) dtor.Namespace; var @class = (Class) dtor.Namespace;
GenerateVirtualFunctionCall(dtor, @class, true); GenerateVirtualFunctionCall(dtor, true);
if (@class.IsAbstract) if (@class.IsAbstract)
{ {
UnindentAndWriteCloseBrace(); UnindentAndWriteCloseBrace();
@ -2416,11 +2416,11 @@ namespace CppSharp.Generators.CSharp
} }
else if (method.SynthKind == FunctionSynthKind.AbstractImplCall) else if (method.SynthKind == FunctionSynthKind.AbstractImplCall)
{ {
GenerateVirtualFunctionCall(method, @class.BaseClass); GenerateVirtualFunctionCall(method);
} }
else if (method.IsVirtual) else if (method.IsVirtual)
{ {
GenerateVirtualFunctionCall(method, @class); GenerateVirtualFunctionCall(method);
} }
else else
{ {
@ -2548,30 +2548,31 @@ namespace CppSharp.Generators.CSharp
WriteLine(parameters == null ? WriteLine(parameters == null ?
"return base.{0};" : "base.{0} = value;", property.Name); "return base.{0};" : "base.{0} = value;", property.Name);
else else
GenerateFunctionCall(GetVirtualCallDelegate(method, @class), GenerateFunctionCall(GetVirtualCallDelegate(method),
parameters ?? method.Parameters, method, returnType); parameters ?? method.Parameters, method, returnType);
} }
private void GenerateVirtualFunctionCall(Method method, Class @class, private void GenerateVirtualFunctionCall(Method method,
bool forceVirtualCall = false) bool forceVirtualCall = false)
{ {
if (!forceVirtualCall && method.IsGeneratedOverride() && if (!forceVirtualCall && method.IsGeneratedOverride() &&
!method.BaseMethod.IsPure) !method.BaseMethod.IsPure)
GenerateManagedCall(method, true); GenerateManagedCall(method, true);
else else
GenerateFunctionCall(GetVirtualCallDelegate(method, @class), GenerateFunctionCall(GetVirtualCallDelegate(method),
method.Parameters, method); method.Parameters, method);
} }
private string GetVirtualCallDelegate(Method method, Class @class) private string GetVirtualCallDelegate(Method method)
{ {
Function @virtual = method; Function @virtual = method;
if (method.OriginalFunction != null && if (method.OriginalFunction != null &&
!((Class) method.OriginalFunction.Namespace).IsInterface) !((Class) method.OriginalFunction.Namespace).IsInterface)
@virtual = method.OriginalFunction; @virtual = method.OriginalFunction;
var i = VTables.GetVTableIndex(@virtual, @class); var i = VTables.GetVTableIndex(@virtual);
int vtableIndex = 0; int vtableIndex = 0;
var @class = (Class) method.Namespace;
if (Context.ParserOptions.IsMicrosoftAbi) if (Context.ParserOptions.IsMicrosoftAbi)
vtableIndex = @class.Layout.VFTables.IndexOf(@class.Layout.VFTables.Where( vtableIndex = @class.Layout.VFTables.IndexOf(@class.Layout.VFTables.Where(
v => v.Layout.Components.Any(c => c.Method == @virtual)).First()); v => v.Layout.Components.Any(c => c.Method == @virtual)).First());

Loading…
Cancel
Save