From 4cc60bed2aa1cccc73d9ebebc1d77cf022626e29 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sun, 4 Oct 2015 23:20:47 +0300 Subject: [PATCH] Fixed the pass for multiple inheritance to keep original functions. This would be useful in many situations where the original function is required, for example when looking for indices in v-tables. Signed-off-by: Dimitar Dobrev --- src/Generator/AST/VTables.cs | 13 +++---------- .../Generators/CSharp/CSharpTextTemplate.cs | 4 ++-- src/Generator/Passes/MultipleInheritancePass.cs | 4 ++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Generator/AST/VTables.cs b/src/Generator/AST/VTables.cs index 88908a1f..b1a7f00d 100644 --- a/src/Generator/AST/VTables.cs +++ b/src/Generator/AST/VTables.cs @@ -72,26 +72,19 @@ namespace CppSharp.AST throw new NotSupportedException(); } - 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) + public static int GetVTableIndex(Function function, Class @class) { switch (@class.Layout.ABI) { case CppAbi.Microsoft: return (from table in @class.Layout.VFTables - let j = table.Layout.Components.FindIndex(m => CanOverride(m.Method, method)) + let j = table.Layout.Components.FindIndex(m => m.Method == function) where j >= 0 select j).First(); default: // ignore offset to top and RTTI - return @class.Layout.Layout.Components.FindIndex(m => m.Method == method) - 2; + return @class.Layout.Layout.Components.FindIndex(m => m.Method == function) - 2; } } diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index e8807c29..51ad1ebb 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2340,7 +2340,7 @@ namespace CppSharp.Generators.CSharp out string delegateId) { var virtualCallBuilder = new StringBuilder(); - var i = VTables.GetVTableIndex((Method) (function.OriginalFunction ?? function), @class); + var i = VTables.GetVTableIndex(function.OriginalFunction ?? function, @class); virtualCallBuilder.AppendFormat("void* {0} = *(void**) ((IntPtr) __OriginalVTables[0] + {1} * {2});", Helpers.SlotIdentifier, i, Driver.TargetInfo.PointerWidth / 8); virtualCallBuilder.AppendLine(); @@ -2436,7 +2436,7 @@ namespace CppSharp.Generators.CSharp CheckArgumentRange(function); var functionName = string.Format("Internal.{0}", - GetFunctionNativeIdentifier(function)); + GetFunctionNativeIdentifier(function.OriginalFunction ?? function)); GenerateFunctionCall(functionName, parameters, function, returnType); } diff --git a/src/Generator/Passes/MultipleInheritancePass.cs b/src/Generator/Passes/MultipleInheritancePass.cs index f1c3daa2..25ede4ed 100644 --- a/src/Generator/Passes/MultipleInheritancePass.cs +++ b/src/Generator/Passes/MultipleInheritancePass.cs @@ -153,7 +153,7 @@ namespace CppSharp.Passes @interface.Methods.AddRange( from m in @base.Methods where !m.IsConstructor && !m.IsDestructor && !m.IsStatic && m.IsDeclared && !m.IsOperator - select new Method(m) { Namespace = @interface }); + select new Method(m) { Namespace = @interface, OriginalFunction = m }); @interface.Properties.AddRange( from property in @base.Properties @@ -199,7 +199,7 @@ namespace CppSharp.Passes m.Parameters.SequenceEqual(method.Parameters.Where(p => !p.Ignore), parameterTypeComparer))) continue; - var impl = new Method(method) { Namespace = @class }; + var impl = new Method(method) { Namespace = @class, OriginalFunction = method.OriginalFunction }; var rootBaseMethod = @class.GetBaseMethod(method, true); if (rootBaseMethod != null && rootBaseMethod.IsDeclared) impl.ExplicitInterfaceImpl = @interface;