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

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

@ -638,13 +638,15 @@ namespace CppSharp.Generators.CSharp @@ -638,13 +638,15 @@ namespace CppSharp.Generators.CSharp
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);
if (prop.SetMethod?.Namespace == @class &&
prop.SetMethod != prop.GetMethod)
if (prop.SetMethod != null
&& (!prop.IsOverride || prop.SetMethod.Namespace == @class)
&& !functions.Contains(prop.SetMethod))
tryAddOverload(prop.SetMethod);
}
}

12
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -66,9 +66,12 @@ namespace CppSharp.Passes @@ -66,9 +66,12 @@ namespace CppSharp.Passes
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(
m => !m.IsConstructor && !m.IsDestructor && !m.IsOperator && m.IsGenerated &&
m.SynthKind != FunctionSynthKind.DefaultValueOverload &&
@ -101,7 +104,7 @@ namespace CppSharp.Passes @@ -101,7 +104,7 @@ namespace CppSharp.Passes
for (int i = properties.Count - 1; i >= 0; i--)
{
Property property = properties[i];
if (property.HasSetter)
if (property.HasSetter || property.IsExplicitlyGenerated)
continue;
string firstWord = GetFirstWord(property.GetMethod.Name);
@ -173,8 +176,7 @@ namespace CppSharp.Passes @@ -173,8 +176,7 @@ namespace CppSharp.Passes
return true;
}
return property.SetMethod != null &&
GetPropertyNameFromSetter(property.SetMethod.Name) == name;
return false;
}
private static string RemovePrefix(string identifier)

3
src/Generator/Passes/MultipleInheritancePass.cs

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

2
src/Generator/Passes/RenamePass.cs

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

Loading…
Cancel
Save