Browse Source

Ensured generated overridden properties are as simple as possible.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/563/head
Dimitar Dobrev 10 years ago
parent
commit
784a939c66
  1. 12
      src/AST/ClassExtensions.cs
  2. 11
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

12
src/AST/ClassExtensions.cs

@ -88,6 +88,12 @@ namespace CppSharp.AST @@ -88,6 +88,12 @@ namespace CppSharp.AST
return null;
}
public static bool HasNonAbstractBaseMethod(this Class @class, Method method)
{
var baseMethod = @class.GetBaseMethod(method, true, true);
return baseMethod != null && !baseMethod.IsPure;
}
public static Property GetBaseProperty(this Class c, Property @override, bool onlyFirstBase = false, bool getTopmost = false)
{
foreach (var @base in c.Bases)
@ -121,6 +127,12 @@ namespace CppSharp.AST @@ -121,6 +127,12 @@ namespace CppSharp.AST
return null;
}
public static bool HasNonAbstractBaseProperty(this Class @class, Property property)
{
var baseProperty = @class.GetBaseProperty(property, true, true);
return baseProperty != null && !baseProperty.IsPure;
}
public static Property GetPropertyByName(this Class c, string propertyName)
{
Property property = c.Properties.FirstOrDefault(m => m.Name == propertyName);

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

@ -2327,11 +2327,9 @@ namespace CppSharp.Generators.CSharp @@ -2327,11 +2327,9 @@ namespace CppSharp.Generators.CSharp
private void GenerateVirtualPropertyCall(Function method, Class @class,
Property property, List<Parameter> parameters = null)
{
Property baseProperty;
if (property.IsOverride && !property.IsPure &&
method.SynthKind != FunctionSynthKind.AbstractImplCall &&
(baseProperty = ((Class) method.Namespace).GetBaseProperty(property, true, true)) != null &&
!baseProperty.IsPure)
@class.HasNonAbstractBaseProperty(property))
{
WriteLine(parameters == null ? "return base.{0};" : "base.{0} = value;", property.Name);
}
@ -2345,10 +2343,9 @@ namespace CppSharp.Generators.CSharp @@ -2345,10 +2343,9 @@ namespace CppSharp.Generators.CSharp
private void GenerateVirtualFunctionCall(Method method, Class @class)
{
Method baseMethod;
if (method.IsOverride && !method.IsPure && method.SynthKind != FunctionSynthKind.AbstractImplCall &&
(baseMethod = ((Class) method.Namespace).GetBaseMethod(method, true, true)) != null &&
!baseMethod.IsPure)
if (method.IsOverride && !method.IsPure &&
method.SynthKind != FunctionSynthKind.AbstractImplCall &&
@class.HasNonAbstractBaseMethod(method))
{
GenerateManagedCall(method, true);
}

Loading…
Cancel
Save