Browse Source

Fixed a possible ambiguity when generating properties.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/661/head
Dimitar Dobrev 10 years ago
parent
commit
18406b8c53
  1. 76
      src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs
  2. 7
      tests/CSharp/CSharp.h

76
src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

@ -135,46 +135,46 @@ namespace CppSharp.Passes
private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null) private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null)
{ {
var type = (Class) context; var type = (Class) context;
if (type.Properties.All(p => getter.Name != p.Name || var name = GetPropertyName(getter.Name);
p.ExplicitInterfaceImpl != getter.ExplicitInterfaceImpl)) if (type.Properties.Any(p => p.Name == name &&
p.ExplicitInterfaceImpl == getter.ExplicitInterfaceImpl))
return;
var property = new Property
{ {
var property = new Property Access = getter.Access == AccessSpecifier.Public ||
{ (setter != null && setter.Access == AccessSpecifier.Public) ?
Access = getter.Access == AccessSpecifier.Public || AccessSpecifier.Public : AccessSpecifier.Protected,
(setter != null && setter.Access == AccessSpecifier.Public) Name = name,
? AccessSpecifier.Public Namespace = type,
: AccessSpecifier.Protected, QualifiedType = getter.OriginalReturnType,
Name = GetPropertyName(getter.Name), OriginalNamespace = getter.OriginalNamespace
Namespace = type, };
QualifiedType = getter.OriginalReturnType, if (getter.IsOverride || (setter != null && setter.IsOverride))
OriginalNamespace = getter.OriginalNamespace {
}; var baseVirtualProperty = type.GetBaseProperty(property, getTopmost: true);
if (getter.IsOverride || (setter != null && setter.IsOverride)) if (baseVirtualProperty == null && type.GetBaseMethod(getter, getTopmost: true).IsGenerated)
{ throw new Exception(string.Format(
var baseVirtualProperty = type.GetBaseProperty(property, getTopmost: true); "Property {0} has a base property null but its getter has a generated base method.",
if (baseVirtualProperty == null && type.GetBaseMethod(getter, getTopmost: true).IsGenerated) getter.QualifiedOriginalName));
throw new Exception(string.Format( if (baseVirtualProperty != null && baseVirtualProperty.SetMethod == null)
"Property {0} has a base property null but its getter has a generated base method.", setter = null;
getter.QualifiedOriginalName)); }
if (baseVirtualProperty != null && baseVirtualProperty.SetMethod == null) property.GetMethod = getter;
setter = null; property.SetMethod = setter;
} property.ExplicitInterfaceImpl = getter.ExplicitInterfaceImpl;
property.GetMethod = getter; if (property.ExplicitInterfaceImpl == null && setter != null)
property.SetMethod = setter; {
property.ExplicitInterfaceImpl = getter.ExplicitInterfaceImpl; property.ExplicitInterfaceImpl = setter.ExplicitInterfaceImpl;
if (property.ExplicitInterfaceImpl == null && setter != null) }
{ if (getter.Comment != null)
property.ExplicitInterfaceImpl = setter.ExplicitInterfaceImpl; {
} property.Comment = CombineComments(getter, setter);
if (getter.Comment != null)
{
property.Comment = CombineComments(getter, setter);
}
type.Properties.Add(property);
getter.GenerationKind = GenerationKind.Internal;
if (setter != null)
setter.GenerationKind = GenerationKind.Internal;
} }
type.Properties.Add(property);
getter.GenerationKind = GenerationKind.Internal;
if (setter != null)
setter.GenerationKind = GenerationKind.Internal;
} }
private static RawComment CombineComments(Declaration getter, Declaration setter) private static RawComment CombineComments(Declaration getter, Declaration setter)

7
tests/CSharp/CSharp.h

@ -913,3 +913,10 @@ protected:
private: private:
virtual int property(); virtual int property();
}; };
class HasConflictWithProperty
{
public:
int conflictWithProperty();
int getConflictWithProperty();
};

Loading…
Cancel
Save