Permalink
Browse files

Simplified the generation of C# for base calls.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Jul 27, 2017
1 parent 0ecb7fc commit 0c22c4deb7cd0fc2b8699da184cc10ef1cc12cb3
@@ -72,13 +72,6 @@ where @override.CanOverride(method)
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)
{
@@ -2437,37 +2437,25 @@ private void GenerateEqualsAndGetHashCode(Function method, Class @class)
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 @@ private void GenerateEqualsAndGetHashCode(Function method, Class @class)
}
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)
@@ -66,6 +66,7 @@ private static Class AddInternalImplementation(Class @class)
IsPure = false,
SynthKind = FunctionSynthKind.AbstractImplCall
};
impl.OverriddenMethods.Clear();
impl.OverriddenMethods.Add(abstractMethod);
internalImpl.Methods.Add(impl);
}
@@ -110,7 +111,7 @@ private static IEnumerable<Method> GetRelevantAbstractMethods(Class @class)
var rootBaseMethod = abstractMethod;
do
{
rootBaseMethod = @class.GetBaseMethod(rootBaseMethod, false, true);
rootBaseMethod = rootBaseMethod.BaseMethod;
if (found = (rootBaseMethod == @override))
break;
} while (rootBaseMethod != null);

0 comments on commit 0c22c4d

Please sign in to comment.