Skip to content

Commit a430d19

Browse files
committed
Simplified the generation of virtual calls.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent b0db304 commit a430d19

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/Generator/AST/VTables.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ public static List<VTableComponent> GatherVTableMethodsItanium(Class @class)
5555
return GatherVTableMethodEntries(@class.Layout.Layout);
5656
}
5757

58-
public static int GetVTableIndex(Function function, Class @class)
58+
public static int GetVTableIndex(Function function)
5959
{
60+
var @class = (Class) function.Namespace;
6061
switch (@class.Layout.ABI)
6162
{
6263
case CppAbi.Microsoft:

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,7 @@ c is ClassTemplateSpecialization ?
20712071
private void GenerateDestructorCall(Method dtor)
20722072
{
20732073
var @class = (Class) dtor.Namespace;
2074-
GenerateVirtualFunctionCall(dtor, @class, true);
2074+
GenerateVirtualFunctionCall(dtor, true);
20752075
if (@class.IsAbstract)
20762076
{
20772077
UnindentAndWriteCloseBrace();
@@ -2416,11 +2416,11 @@ private void GenerateMethodBody(Class @class, Method method,
24162416
}
24172417
else if (method.SynthKind == FunctionSynthKind.AbstractImplCall)
24182418
{
2419-
GenerateVirtualFunctionCall(method, @class.BaseClass);
2419+
GenerateVirtualFunctionCall(method);
24202420
}
24212421
else if (method.IsVirtual)
24222422
{
2423-
GenerateVirtualFunctionCall(method, @class);
2423+
GenerateVirtualFunctionCall(method);
24242424
}
24252425
else
24262426
{
@@ -2548,30 +2548,31 @@ private void GenerateVirtualPropertyCall(Method method, Class @class,
25482548
WriteLine(parameters == null ?
25492549
"return base.{0};" : "base.{0} = value;", property.Name);
25502550
else
2551-
GenerateFunctionCall(GetVirtualCallDelegate(method, @class),
2551+
GenerateFunctionCall(GetVirtualCallDelegate(method),
25522552
parameters ?? method.Parameters, method, returnType);
25532553
}
25542554

2555-
private void GenerateVirtualFunctionCall(Method method, Class @class,
2555+
private void GenerateVirtualFunctionCall(Method method,
25562556
bool forceVirtualCall = false)
25572557
{
25582558
if (!forceVirtualCall && method.IsGeneratedOverride() &&
25592559
!method.BaseMethod.IsPure)
25602560
GenerateManagedCall(method, true);
25612561
else
2562-
GenerateFunctionCall(GetVirtualCallDelegate(method, @class),
2562+
GenerateFunctionCall(GetVirtualCallDelegate(method),
25632563
method.Parameters, method);
25642564
}
25652565

2566-
private string GetVirtualCallDelegate(Method method, Class @class)
2566+
private string GetVirtualCallDelegate(Method method)
25672567
{
25682568
Function @virtual = method;
25692569
if (method.OriginalFunction != null &&
25702570
!((Class) method.OriginalFunction.Namespace).IsInterface)
25712571
@virtual = method.OriginalFunction;
25722572

2573-
var i = VTables.GetVTableIndex(@virtual, @class);
2573+
var i = VTables.GetVTableIndex(@virtual);
25742574
int vtableIndex = 0;
2575+
var @class = (Class) method.Namespace;
25752576
if (Context.ParserOptions.IsMicrosoftAbi)
25762577
vtableIndex = @class.Layout.VFTables.IndexOf(@class.Layout.VFTables.Where(
25772578
v => v.Layout.Components.Any(c => c.Method == @virtual)).First());

0 commit comments

Comments
 (0)