From 0c22c4deb7cd0fc2b8699da184cc10ef1cc12cb3 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Fri, 28 Jul 2017 01:38:45 +0300 Subject: [PATCH] Simplified the generation of C# for base calls. Signed-off-by: Dimitar Dobrev --- src/AST/ClassExtensions.cs | 7 ----- .../Generators/CSharp/CSharpSources.cs | 30 +++++++------------ .../GenerateAbstractImplementationsPass.cs | 3 +- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/AST/ClassExtensions.cs b/src/AST/ClassExtensions.cs index 64e1b5ef..66976559 100644 --- a/src/AST/ClassExtensions.cs +++ b/src/AST/ClassExtensions.cs @@ -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) { diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 41cffb24..7c743e43 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -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 } 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) diff --git a/src/Generator/Passes/GenerateAbstractImplementationsPass.cs b/src/Generator/Passes/GenerateAbstractImplementationsPass.cs index 37aadc5c..2c1c04da 100644 --- a/src/Generator/Passes/GenerateAbstractImplementationsPass.cs +++ b/src/Generator/Passes/GenerateAbstractImplementationsPass.cs @@ -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 var rootBaseMethod = abstractMethod; do { - rootBaseMethod = @class.GetBaseMethod(rootBaseMethod, false, true); + rootBaseMethod = rootBaseMethod.BaseMethod; if (found = (rootBaseMethod == @override)) break; } while (rootBaseMethod != null);