Browse Source

Simplified the generation of virtual calls.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1160/head
Dimitar Dobrev 6 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 @@ -55,8 +55,9 @@ namespace CppSharp.AST
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)
{
case CppAbi.Microsoft:

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

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

Loading…
Cancel
Save