Browse Source

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 <dpldobrev@yahoo.com>
pull/573/head
Dimitar Dobrev 10 years ago
parent
commit
4cc60bed2a
  1. 13
      src/Generator/AST/VTables.cs
  2. 4
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  3. 4
      src/Generator/Passes/MultipleInheritancePass.cs

13
src/Generator/AST/VTables.cs

@ -72,26 +72,19 @@ namespace CppSharp.AST @@ -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;
}
}

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

@ -2340,7 +2340,7 @@ namespace CppSharp.Generators.CSharp @@ -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 @@ -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);
}

4
src/Generator/Passes/MultipleInheritancePass.cs

@ -153,7 +153,7 @@ namespace CppSharp.Passes @@ -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 @@ -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;

Loading…
Cancel
Save