Browse Source

Equalised the access of overrides and their base methods.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/902/head
Dimitar Dobrev 9 years ago
parent
commit
cece243a06
  1. 10
      src/Generator/Driver.cs
  2. 23
      src/Generator/Generators/CSharp/CSharpSources.cs
  3. 44
      src/Generator/Passes/EqualiseAccessOfOverrideAndBasePass.cs
  4. 18
      tests/Common/Common.cpp
  5. 5
      tests/Common/Common.h

10
src/Generator/Driver.cs

@ -311,6 +311,7 @@ namespace CppSharp @@ -311,6 +311,7 @@ namespace CppSharp
TranslationUnitPasses.AddPass(new CheckIgnoredDeclsPass());
TranslationUnitPasses.AddPass(new CheckFlagEnumsPass());
TranslationUnitPasses.AddPass(new CheckDuplicatedNamesPass());
if (Options.IsCSharpGenerator)
{
TranslationUnitPasses.AddPass(new GenerateAbstractImplementationsPass());
@ -319,16 +320,11 @@ namespace CppSharp @@ -319,16 +320,11 @@ namespace CppSharp
TranslationUnitPasses.AddPass(new FixDefaultParamValuesOfOverridesPass());
TranslationUnitPasses.AddPass(new HandleDefaultParamValuesPass());
}
}
if (Options.IsCSharpGenerator)
{
TranslationUnitPasses.AddPass(new MultipleInheritancePass());
TranslationUnitPasses.AddPass(new ParamTypeToInterfacePass());
}
if (Options.IsCSharpGenerator)
TranslationUnitPasses.AddPass(new DelegatesPass());
TranslationUnitPasses.AddPass(new EqualiseAccessOfOverrideAndBasePass());
}
TranslationUnitPasses.AddPass(new GetterSetterToPropertyPass());
TranslationUnitPasses.AddPass(new StripUnusedSystemTypesPass());

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

@ -1238,7 +1238,7 @@ namespace CppSharp.Generators.CSharp @@ -1238,7 +1238,7 @@ namespace CppSharp.Generators.CSharp
var printedType = prop.Type.Visit(TypePrinter);
if (prop.ExplicitInterfaceImpl == null)
{
Write(Helpers.GetAccess(GetValidPropertyAccess(prop)));
Write(Helpers.GetAccess(prop.Access));
if (prop.IsStatic)
Write("static ");
@ -2227,7 +2227,7 @@ namespace CppSharp.Generators.CSharp @@ -2227,7 +2227,7 @@ namespace CppSharp.Generators.CSharp
if (method.ExplicitInterfaceImpl == null)
{
Write(Helpers.GetAccess(GetValidMethodAccess(method)));
Write(Helpers.GetAccess(method.Access));
}
GenerateMethodSpecifier(method, @class);
@ -2431,25 +2431,6 @@ namespace CppSharp.Generators.CSharp @@ -2431,25 +2431,6 @@ namespace CppSharp.Generators.CSharp
}
}
private static AccessSpecifier GetValidMethodAccess(Method method)
{
if (!method.IsOverride)
return method.Access;
var baseMethod = ((Class) method.Namespace).GetBaseMethod(method);
return baseMethod.IsGenerated ? baseMethod.Access : method.Access;
}
private static AccessSpecifier GetValidPropertyAccess(Property property)
{
if (property.Access == AccessSpecifier.Public)
return AccessSpecifier.Public;
if (!property.IsOverride)
return property.Access;
var baseProperty = ((Class) property.Namespace).GetBaseProperty(property);
// access can be changed from private to other while overriding in C++
return baseProperty != null ? baseProperty.Access : property.Access;
}
private void GenerateVirtualPropertyCall(Method method, Class @class,
Property property, List<Parameter> parameters = null)
{

44
src/Generator/Passes/EqualiseAccessOfOverrideAndBasePass.cs

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
using System.Collections.Generic;
using System.Linq;
using CppSharp.AST;
namespace CppSharp.Passes
{
public class EqualiseAccessOfOverrideAndBasePass : TranslationUnitPass
{
public override bool VisitASTContext(ASTContext context)
{
var result = base.VisitASTContext(context);
foreach (var baseOverride in basesOverrides)
{
var access = baseOverride.Value.Max(o => o.Access);
foreach (var @override in baseOverride.Value)
@override.Access = access;
}
return result;
}
public override bool VisitMethodDecl(Method method)
{
if (!base.VisitMethodDecl(method) || !method.IsOverride)
return false;
var baseMethod = ((Class) method.Namespace).GetBaseMethod(method);
if (!baseMethod.IsGenerated)
return false;
HashSet<Method> overrides;
if (basesOverrides.ContainsKey(baseMethod))
overrides = basesOverrides[baseMethod];
else
overrides = basesOverrides[baseMethod] = new HashSet<Method> { baseMethod };
overrides.Add(method);
return true;
}
private Dictionary<Method, HashSet<Method>> basesOverrides = new Dictionary<Method, HashSet<Method>>();
}
}

18
tests/Common/Common.cpp

@ -592,6 +592,15 @@ void HasVirtualProperty::setProperty(int target) @@ -592,6 +592,15 @@ void HasVirtualProperty::setProperty(int target)
{
}
int HasVirtualProperty::getProtectedProperty()
{
return 2;
}
void HasVirtualProperty::setProtectedProperty(int value)
{
}
ChangedAccessOfInheritedProperty::ChangedAccessOfInheritedProperty()
{
}
@ -605,6 +614,15 @@ void ChangedAccessOfInheritedProperty::setProperty(int value) @@ -605,6 +614,15 @@ void ChangedAccessOfInheritedProperty::setProperty(int value)
{
}
int ChangedAccessOfInheritedProperty::getProtectedProperty()
{
return 3;
}
void ChangedAccessOfInheritedProperty::setProtectedProperty(int value)
{
}
Empty ReturnsEmpty::getEmpty()
{
return Empty();

5
tests/Common/Common.h

@ -901,12 +901,17 @@ class DLL_API HasVirtualProperty @@ -901,12 +901,17 @@ class DLL_API HasVirtualProperty
public:
virtual int getProperty();
virtual void setProperty(int target);
protected:
virtual int getProtectedProperty();
virtual void setProtectedProperty(int value);
};
class DLL_API ChangedAccessOfInheritedProperty : public HasVirtualProperty
{
public:
ChangedAccessOfInheritedProperty();
int getProtectedProperty();
void setProtectedProperty(int value);
protected:
int getProperty();
void setProperty(int value);

Loading…
Cancel
Save