Browse Source

Simplified the generation of C# for base calls.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/904/head
Dimitar Dobrev 8 years ago
parent
commit
0c22c4deb7
  1. 7
      src/AST/ClassExtensions.cs
  2. 30
      src/Generator/Generators/CSharp/CSharpSources.cs
  3. 3
      src/Generator/Passes/GenerateAbstractImplementationsPass.cs

7
src/AST/ClassExtensions.cs

@ -72,13 +72,6 @@ namespace CppSharp.AST @@ -72,13 +72,6 @@ namespace CppSharp.AST
return null;
}
public static bool HasCallableBaseMethodInPrimaryBase(this Class @class, Method method)
{
var baseMethod = @class.GetBaseMethod(method, true, true);
return baseMethod != null && !baseMethod.IsPure && baseMethod.IsGenerated &&
!((Class) baseMethod.OriginalNamespace).IsInterface;
}
public static Property GetBaseProperty(this Class @class, Property @override,
bool onlyFirstBase = false, bool getTopmost = false)
{

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

@ -2437,37 +2437,25 @@ namespace CppSharp.Generators.CSharp @@ -2437,37 +2437,25 @@ namespace CppSharp.Generators.CSharp
if (property.IsOverride && !property.IsPure &&
method.SynthKind != FunctionSynthKind.AbstractImplCall &&
@class.HasNonAbstractBasePropertyInPrimaryBase(property))
{
WriteLine(parameters == null ?
"return base.{0};" : "base.{0} = value;", property.Name);
}
else
{
string delegateId;
GetVirtualCallDelegate(method, @class, out delegateId);
GenerateFunctionCall(delegateId, parameters ?? method.Parameters, method);
}
GenerateFunctionCall(GetVirtualCallDelegate(method, @class),
parameters ?? method.Parameters, method);
}
private void GenerateVirtualFunctionCall(Method method, Class @class,
bool forceVirtualCall = false)
{
if (!forceVirtualCall && method.IsOverride && !method.IsPure &&
method.SynthKind != FunctionSynthKind.AbstractImplCall &&
@class.HasCallableBaseMethodInPrimaryBase(method))
{
if (!forceVirtualCall && method.IsGeneratedOverride() &&
!method.BaseMethod.IsPure)
GenerateManagedCall(method, true);
}
else
{
string delegateId;
GetVirtualCallDelegate(method, @class, out delegateId);
GenerateFunctionCall(delegateId, method.Parameters, method);
}
GenerateFunctionCall(GetVirtualCallDelegate(method, @class),
method.Parameters, method);
}
private void GetVirtualCallDelegate(Method method, Class @class,
out string delegateId)
private string GetVirtualCallDelegate(Method method, Class @class)
{
Function @virtual = method;
if (method.OriginalFunction != null &&
@ -2488,11 +2476,13 @@ namespace CppSharp.Generators.CSharp @@ -2488,11 +2476,13 @@ namespace CppSharp.Generators.CSharp
}
var @delegate = GetVTableMethodDelegateName(@virtual);
delegateId = Generator.GeneratedIdentifier(@delegate);
var delegateId = Generator.GeneratedIdentifier(@delegate);
WriteLine("var {0} = ({1}) Marshal.GetDelegateForFunctionPointer(new IntPtr({2}), typeof({1}));",
delegateId, Context.Delegates[method].Signature,
Helpers.SlotIdentifier);
return delegateId;
}
private void GenerateOperator(Method method)

3
src/Generator/Passes/GenerateAbstractImplementationsPass.cs

@ -66,6 +66,7 @@ namespace CppSharp.Passes @@ -66,6 +66,7 @@ namespace CppSharp.Passes
IsPure = false,
SynthKind = FunctionSynthKind.AbstractImplCall
};
impl.OverriddenMethods.Clear();
impl.OverriddenMethods.Add(abstractMethod);
internalImpl.Methods.Add(impl);
}
@ -110,7 +111,7 @@ namespace CppSharp.Passes @@ -110,7 +111,7 @@ namespace CppSharp.Passes
var rootBaseMethod = abstractMethod;
do
{
rootBaseMethod = @class.GetBaseMethod(rootBaseMethod, false, true);
rootBaseMethod = rootBaseMethod.BaseMethod;
if (found = (rootBaseMethod == @override))
break;
} while (rootBaseMethod != null);

Loading…
Cancel
Save