Browse Source

Simplify searching for base properties

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1261/head
Dimitar Dobrev 7 years ago
parent
commit
499ecc3b89
  1. 37
      src/AST/ClassExtensions.cs
  2. 2
      src/Generator/Generators/CSharp/CSharpSources.cs

37
src/AST/ClassExtensions.cs

@ -56,7 +56,7 @@ namespace CppSharp.AST @@ -56,7 +56,7 @@ namespace CppSharp.AST
}
public static Property GetBaseProperty(this Class @class, Property @override,
bool onlyFirstBase = false, bool getTopmost = false)
bool onlyFirstBase = false)
{
foreach (var @base in @class.Bases)
{
@ -66,44 +66,33 @@ namespace CppSharp.AST @@ -66,44 +66,33 @@ namespace CppSharp.AST
(onlyFirstBase && @base.Class.IsInterface))
continue;
Property baseProperty;
if (!getTopmost)
{
baseProperty = @base.Class.GetBaseProperty(@override, onlyFirstBase);
if (baseProperty != null)
return baseProperty;
}
var properties = @base.Class.Properties.Concat(@base.Class.Declarations.OfType<Property>());
baseProperty = (from property in properties
where property.OriginalName == @override.OriginalName &&
property.Parameters.SequenceEqual(@override.Parameters,
ParameterTypeComparer.Instance)
select property).FirstOrDefault();
Property baseProperty = (from property in properties
where property.OriginalName == @override.OriginalName &&
property.Parameters.SequenceEqual(@override.Parameters,
ParameterTypeComparer.Instance)
select property).FirstOrDefault();
if (baseProperty != null)
return baseProperty;
if (getTopmost)
{
baseProperty = @base.Class.GetBaseProperty(@override, onlyFirstBase, true);
if (baseProperty != null)
return baseProperty;
}
baseProperty = @base.Class.GetBaseProperty(@override, onlyFirstBase);
if (baseProperty != null)
return baseProperty;
}
return null;
}
public static bool HasNonAbstractBasePropertyInPrimaryBase(this Class @class, Property property)
{
var baseProperty = @class.GetBaseProperty(property, true, true);
var baseProperty = @class.GetBaseProperty(property, true);
return baseProperty != null && !baseProperty.IsPure &&
!((Class) baseProperty.OriginalNamespace).IsInterface;
}
public static Property GetPropertyByName(this Class @class, string propertyName)
{
Property property = @class.Properties.FirstOrDefault(m => m.Name == propertyName);
Property property = @class.Properties.Find(m => m.Name == propertyName);
if (property != null)
return property;
@ -119,10 +108,10 @@ namespace CppSharp.AST @@ -119,10 +108,10 @@ namespace CppSharp.AST
public static Property GetPropertyByConstituentMethod(this Class @class, Method method)
{
var property = @class.Properties.FirstOrDefault(p => p.GetMethod == method);
var property = @class.Properties.Find(p => p.GetMethod == method);
if (property != null)
return property;
property = @class.Properties.FirstOrDefault(p => p.SetMethod == method);
property = @class.Properties.Find(p => p.SetMethod == method);
if (property != null)
return property;

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

@ -1403,7 +1403,7 @@ namespace CppSharp.Generators.CSharp @@ -1403,7 +1403,7 @@ namespace CppSharp.Generators.CSharp
// check if overriding a property from a secondary base
Property rootBaseProperty;
var isOverride = prop.IsOverride &&
(rootBaseProperty = @class.GetBaseProperty(prop, true, true)) != null &&
(rootBaseProperty = @class.GetBaseProperty(prop, true)) != null &&
(rootBaseProperty.IsVirtual || rootBaseProperty.IsPure);
if (isOverride)

Loading…
Cancel
Save