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
return null; 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, public static Property GetBaseProperty(this Class @class, Property @override,
bool onlyFirstBase = false, bool getTopmost = false) bool onlyFirstBase = false, bool getTopmost = false)
{ {

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

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

3
src/Generator/Passes/GenerateAbstractImplementationsPass.cs

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

Loading…
Cancel
Save