Browse Source

Make the pass for properties more extendable

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1261/head
Dimitar Dobrev 6 years ago
parent
commit
e26206ffc7
  1. 2
      src/Generator/Driver.cs
  2. 10
      src/Generator/Generators/CSharp/CSharpSources.cs
  3. 12
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  4. 3
      src/Generator/Passes/MultipleInheritancePass.cs
  5. 2
      src/Generator/Passes/RenamePass.cs

2
src/Generator/Driver.cs

@ -216,7 +216,7 @@ namespace CppSharp
public void SetupPasses(ILibrary library) public void SetupPasses(ILibrary library)
{ {
var TranslationUnitPasses = Context.TranslationUnitPasses; var TranslationUnitPasses = Context.TranslationUnitPasses;
TranslationUnitPasses.AddPass(new ResolveIncompleteDeclsPass()); TranslationUnitPasses.AddPass(new ResolveIncompleteDeclsPass());
TranslationUnitPasses.AddPass(new IgnoreSystemDeclarationsPass()); TranslationUnitPasses.AddPass(new IgnoreSystemDeclarationsPass());
if (Options.IsCSharpGenerator) if (Options.IsCSharpGenerator)

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

@ -638,13 +638,15 @@ namespace CppSharp.Generators.CSharp
tryAddOverload(method); tryAddOverload(method);
} }
foreach (var prop in @class.Properties) foreach (var prop in @class.Properties.Where(p => p.Field == null))
{ {
if (prop.GetMethod?.Namespace == @class) if ((!prop.IsOverride || prop.GetMethod.Namespace == @class) &&
!functions.Contains(prop.GetMethod))
tryAddOverload(prop.GetMethod); tryAddOverload(prop.GetMethod);
if (prop.SetMethod?.Namespace == @class && if (prop.SetMethod != null
prop.SetMethod != prop.GetMethod) && (!prop.IsOverride || prop.SetMethod.Namespace == @class)
&& !functions.Contains(prop.SetMethod))
tryAddOverload(prop.SetMethod); tryAddOverload(prop.SetMethod);
} }
} }

12
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -66,9 +66,12 @@ namespace CppSharp.Passes
return false; return false;
} }
protected virtual IEnumerable<Property> GenerateProperties(Class @class) protected virtual List<Property> GetProperties(Class @class) =>
new List<Property>();
protected IEnumerable<Property> GenerateProperties(Class @class)
{ {
var properties = new List<Property>(); List<Property> properties = GetProperties(@class);
foreach (Method method in @class.Methods.Where( foreach (Method method in @class.Methods.Where(
m => !m.IsConstructor && !m.IsDestructor && !m.IsOperator && m.IsGenerated && m => !m.IsConstructor && !m.IsDestructor && !m.IsOperator && m.IsGenerated &&
m.SynthKind != FunctionSynthKind.DefaultValueOverload && m.SynthKind != FunctionSynthKind.DefaultValueOverload &&
@ -101,7 +104,7 @@ namespace CppSharp.Passes
for (int i = properties.Count - 1; i >= 0; i--) for (int i = properties.Count - 1; i >= 0; i--)
{ {
Property property = properties[i]; Property property = properties[i];
if (property.HasSetter) if (property.HasSetter || property.IsExplicitlyGenerated)
continue; continue;
string firstWord = GetFirstWord(property.GetMethod.Name); string firstWord = GetFirstWord(property.GetMethod.Name);
@ -173,8 +176,7 @@ namespace CppSharp.Passes
return true; return true;
} }
return property.SetMethod != null && return false;
GetPropertyNameFromSetter(property.SetMethod.Name) == name;
} }
private static string RemovePrefix(string identifier) private static string RemovePrefix(string identifier)

3
src/Generator/Passes/MultipleInheritancePass.cs

@ -193,7 +193,6 @@ namespace CppSharp.Passes
OriginalFunction = property.GetMethod, OriginalFunction = property.GetMethod,
Namespace = @namespace Namespace = @namespace
}; };
interfaceProperty.GetMethod.OverriddenMethods.Add(property.GetMethod);
} }
if (property.SetMethod != null) if (property.SetMethod != null)
{ {
@ -204,7 +203,6 @@ namespace CppSharp.Passes
OriginalFunction = property.SetMethod, OriginalFunction = property.SetMethod,
Namespace = @namespace Namespace = @namespace
}; };
interfaceProperty.SetMethod.OverriddenMethods.Add(property.SetMethod);
} }
return interfaceProperty; return interfaceProperty;
} }
@ -231,7 +229,6 @@ namespace CppSharp.Passes
OriginalNamespace = @interface, OriginalNamespace = @interface,
OriginalFunction = method.OriginalFunction OriginalFunction = method.OriginalFunction
}; };
impl.OverriddenMethods.Add((Method) method.OriginalFunction);
var rootBaseMethod = @class.GetBaseMethod(method); var rootBaseMethod = @class.GetBaseMethod(method);
if (rootBaseMethod != null && rootBaseMethod.IsDeclared) if (rootBaseMethod != null && rootBaseMethod.IsDeclared)
impl.ExplicitInterfaceImpl = @interface; impl.ExplicitInterfaceImpl = @interface;

2
src/Generator/Passes/RenamePass.cs

@ -66,7 +66,7 @@ namespace CppSharp.Passes
var property = decl as Property; var property = decl as Property;
if (property != null && !property.IsStatic) if (property != null && !property.IsStatic)
{ {
var rootBaseProperty = ((Class) property.Namespace).GetBaseProperty(property); var rootBaseProperty = ((Class) property.Namespace).GetBasePropertyByName(property);
if (rootBaseProperty != null && rootBaseProperty != property) if (rootBaseProperty != null && rootBaseProperty != property)
{ {
newName = rootBaseProperty.Name; newName = rootBaseProperty.Name;

Loading…
Cancel
Save