Browse Source

Fixed the generation of properties by considering value and read-only pointer types the same for complex types. Fixed the counting of parameters to consider indirect ones.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/94/head
Dimitar Dobrev 12 years ago
parent
commit
ff14f39ed4
  1. 20
      src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

20
src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

@ -6,6 +6,7 @@ using System.Linq; @@ -6,6 +6,7 @@ using System.Linq;
using System.Reflection;
using System.Text;
using CppSharp.AST;
using Type = CppSharp.AST.Type;
namespace CppSharp.Passes
{
@ -94,7 +95,8 @@ namespace CppSharp.Passes @@ -94,7 +95,8 @@ namespace CppSharp.Passes
{
string name = GetPropertyName(getter.Name);
if (string.Compare(name, afterSet, StringComparison.OrdinalIgnoreCase) == 0 &&
getter.OriginalReturnType == setter.Parameters[0].QualifiedType &&
GetUnderlyingType(getter.OriginalReturnType).Equals(
GetUnderlyingType(setter.Parameters[0].QualifiedType)) &&
!type.Methods.Any(
m =>
m != getter &&
@ -132,6 +134,17 @@ namespace CppSharp.Passes @@ -132,6 +134,17 @@ namespace CppSharp.Passes
}
}
private static Type GetUnderlyingType(QualifiedType type)
{
TagType tagType = type.Type as TagType;
if (tagType != null)
return type.Type;
if (!type.Qualifiers.IsConst)
return type.Type;
PointerType pointerType = type.Type as PointerType;
return pointerType != null ? pointerType.Pointee : type.Type;
}
private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null)
{
Class type = (Class) context;
@ -148,7 +161,8 @@ namespace CppSharp.Passes @@ -148,7 +161,8 @@ namespace CppSharp.Passes
Property baseVirtualProperty = type.GetRootBaseProperty(property);
if (baseVirtualProperty.SetMethod == null)
setter = null;
foreach (Method method in type.Methods.Where(m => m.Name == property.Name && m.Parameters.Count > 0))
foreach (Method method in type.Methods.Where(m => m.Name == property.Name &&
m.Parameters.Any(p => p.Kind != ParameterKind.IndirectReturnType)))
method.Name = "get" + method.Name;
}
property.GetMethod = getter;
@ -215,7 +229,7 @@ namespace CppSharp.Passes @@ -215,7 +229,7 @@ namespace CppSharp.Passes
{
if (IsGetter(method))
getters.Add(method);
if (method.Parameters.Count == 0)
if (method.Parameters.All(p => p.Kind == ParameterKind.IndirectReturnType))
nonSetters.Add(method);
}
}

Loading…
Cancel
Save