Browse Source

Fixed the bodies of functions overriding indirect virtuals.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/563/head
Dimitar Dobrev 10 years ago
parent
commit
dc95c8d8c8
  1. 41
      src/AST/ClassExtensions.cs
  2. 8
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  3. 2
      src/Generator/Passes/CheckIgnoredDecls.cs
  4. 2
      src/Generator/Passes/FixDefaultParamValuesOfOverridesPass.cs
  5. 2
      src/Generator/Passes/GenerateAbstractImplementationsPass.cs
  6. 2
      src/Generator/Passes/MultipleInheritancePass.cs
  7. 2
      src/Generator/Passes/RenamePass.cs
  8. 6
      tests/Common/Common.Tests.cs
  9. 13
      tests/Common/Common.cpp
  10. 13
      tests/Common/Common.h

41
src/AST/ClassExtensions.cs

@ -54,23 +54,38 @@ namespace CppSharp.AST @@ -54,23 +54,38 @@ namespace CppSharp.AST
}
}
public static Method GetRootBaseMethod(this Class c, Method @override, bool onlyPrimaryBase = false, bool oneLevel = false)
public static Method GetBaseMethod(this Class c, Method @override, bool onlyPrimaryBase = false, bool getTopmost = false)
{
return (from @base in c.Bases
where @base.IsClass && @base.Class.OriginalClass != c && (!onlyPrimaryBase || !@base.Class.IsInterface)
let baseMethod = (
from method in @base.Class.Methods
foreach (var @base in c.Bases)
{
if (!@base.IsClass || @base.Class.OriginalClass == c || (onlyPrimaryBase && @base.Class.IsInterface))
continue;
Method baseMethod;
if (!getTopmost)
{
baseMethod = (@base.Class.GetBaseMethod(@override, onlyPrimaryBase));
if (baseMethod != null)
return baseMethod;
}
baseMethod = (from method in @base.Class.Methods
where
(method.OriginalName == @override.OriginalName &&
method.ReturnType == @override.ReturnType &&
(method.OriginalName == @override.OriginalName && method.ReturnType == @override.ReturnType &&
method.Parameters.SequenceEqual(@override.Parameters, new ParameterTypeComparer())) ||
(@override.IsDestructor && method.IsDestructor && method.IsVirtual)
select method).FirstOrDefault()
let rootBaseMethod = oneLevel
? baseMethod
: (@base.Class.GetRootBaseMethod(@override, onlyPrimaryBase) ?? baseMethod)
where rootBaseMethod != null || onlyPrimaryBase
select rootBaseMethod).FirstOrDefault();
select method).FirstOrDefault();
if (baseMethod != null)
return baseMethod;
if (getTopmost)
{
baseMethod = (@base.Class.GetBaseMethod(@override, onlyPrimaryBase));
if (baseMethod != null)
return baseMethod;
}
}
return null;
}
public static Property GetRootBaseProperty(this Class c, Property @override, bool onlyFirstBase = false)

8
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -301,7 +301,7 @@ namespace CppSharp.Generators.CSharp @@ -301,7 +301,7 @@ namespace CppSharp.Generators.CSharp
public void GenerateDebug(Declaration decl)
{
if (Options.OutputDebug && !String.IsNullOrWhiteSpace(decl.DebugText))
if (Options.OutputDebug && !string.IsNullOrWhiteSpace(decl.DebugText))
WriteLine("// DEBUG: " + decl.DebugText);
}
@ -2079,7 +2079,7 @@ namespace CppSharp.Generators.CSharp @@ -2079,7 +2079,7 @@ namespace CppSharp.Generators.CSharp
// check if overriding a function from a secondary base
Method rootBaseMethod;
var isOverride = method.IsOverride &&
(rootBaseMethod = @class.GetRootBaseMethod(method, true)) != null &&
(rootBaseMethod = @class.GetBaseMethod(method, true)) != null &&
(rootBaseMethod.IsVirtual || rootBaseMethod.IsPure);
if (method.IsVirtual && !isOverride && !method.IsOperator && !method.IsPure)
@ -2305,7 +2305,7 @@ namespace CppSharp.Generators.CSharp @@ -2305,7 +2305,7 @@ namespace CppSharp.Generators.CSharp
private static AccessSpecifier GetValidMethodAccess(Method method)
{
return method.IsOverride
? ((Class) method.Namespace).GetRootBaseMethod(method).Access
? ((Class) method.Namespace).GetBaseMethod(method).Access
: method.Access;
}
@ -2325,7 +2325,7 @@ namespace CppSharp.Generators.CSharp @@ -2325,7 +2325,7 @@ namespace CppSharp.Generators.CSharp
{
Method rootBaseMethod;
if (method.IsOverride && !method.IsPure && method.SynthKind != FunctionSynthKind.AbstractImplCall &&
(rootBaseMethod = ((Class) method.Namespace).GetRootBaseMethod(method, true, true)) != null &&
(rootBaseMethod = ((Class) method.Namespace).GetBaseMethod(method, true, true)) != null &&
!rootBaseMethod.IsPure)
{
GenerateManagedCall(method, true);

2
src/Generator/Passes/CheckIgnoredDecls.cs

@ -169,7 +169,7 @@ namespace CppSharp.Passes @@ -169,7 +169,7 @@ namespace CppSharp.Passes
if (method.IsOverride)
{
var baseOverride = @class.GetRootBaseMethod(method);
var baseOverride = @class.GetBaseMethod(method);
if (baseOverride != null && !baseOverride.IsDeclared)
{
Log.Debug(

2
src/Generator/Passes/FixDefaultParamValuesOfOverridesPass.cs

@ -8,7 +8,7 @@ namespace CppSharp.Passes @@ -8,7 +8,7 @@ namespace CppSharp.Passes
{
if (method.IsOverride && !method.IsSynthetized)
{
Method rootBaseMethod = ((Class) method.Namespace).GetRootBaseMethod(method);
Method rootBaseMethod = ((Class) method.Namespace).GetBaseMethod(method);
for (int i = 0; i < method.Parameters.Count; i++)
{
method.Parameters[i].DefaultArgument = rootBaseMethod.Parameters[i].DefaultArgument;

2
src/Generator/Passes/GenerateAbstractImplementationsPass.cs

@ -110,7 +110,7 @@ namespace CppSharp.Passes @@ -110,7 +110,7 @@ namespace CppSharp.Passes
var rootBaseMethod = abstractMethod;
do
{
rootBaseMethod = @class.GetRootBaseMethod(rootBaseMethod, false, true);
rootBaseMethod = @class.GetBaseMethod(rootBaseMethod, false, true);
if (found = (rootBaseMethod == @override))
break;
} while (rootBaseMethod != null);

2
src/Generator/Passes/MultipleInheritancePass.cs

@ -200,7 +200,7 @@ namespace CppSharp.Passes @@ -200,7 +200,7 @@ namespace CppSharp.Passes
parameterTypeComparer)))
continue;
var impl = new Method(method) { Namespace = @class };
var rootBaseMethod = @class.GetRootBaseMethod(method, true);
var rootBaseMethod = @class.GetBaseMethod(method, true);
if (rootBaseMethod != null && rootBaseMethod.IsDeclared)
impl.ExplicitInterfaceImpl = @interface;
@class.Methods.Add(impl);

2
src/Generator/Passes/RenamePass.cs

@ -46,7 +46,7 @@ namespace CppSharp.Passes @@ -46,7 +46,7 @@ namespace CppSharp.Passes
var method = decl as Method;
if (method != null && !method.IsStatic)
{
var rootBaseMethod = ((Class) method.Namespace).GetRootBaseMethod(method);
var rootBaseMethod = ((Class) method.Namespace).GetBaseMethod(method);
if (rootBaseMethod != null && rootBaseMethod != method)
{
newName = rootBaseMethod.Name;

6
tests/Common/Common.Tests.cs

@ -8,7 +8,7 @@ using Enum = CommonTest.Enum; @@ -8,7 +8,7 @@ using Enum = CommonTest.Enum;
public class CommonTests : GeneratorTestFixture
{
[Test]
public void TestUncompilableCode()
public void TestCodeGeneration()
{
Assert.That(new ChangedAccessOfInheritedProperty().Property, Is.EqualTo(2));
Foo.NestedAbstract a;
@ -17,6 +17,10 @@ public class CommonTests : GeneratorTestFixture @@ -17,6 +17,10 @@ public class CommonTests : GeneratorTestFixture
{
Bar bar = foo;
}
using (var overridesNonDirectVirtual = new OverridesNonDirectVirtual())
{
Assert.That(overridesNonDirectVirtual.retInt(), Is.EqualTo(3));
}
}
[Test]

13
tests/Common/Common.cpp

@ -537,3 +537,16 @@ int DerivedClassOverrideAbstractVirtual::retInt() @@ -537,3 +537,16 @@ int DerivedClassOverrideAbstractVirtual::retInt()
{
return 1;
}
BufferForVirtualFunction::BufferForVirtualFunction()
{
}
OverridesNonDirectVirtual::OverridesNonDirectVirtual()
{
}
int OverridesNonDirectVirtual::retInt()
{
return 3;
}

13
tests/Common/Common.h

@ -851,6 +851,19 @@ public: @@ -851,6 +851,19 @@ public:
virtual int retInt();
};
class DLL_API BufferForVirtualFunction : public BaseClassVirtual
{
public:
BufferForVirtualFunction();
};
class DLL_API OverridesNonDirectVirtual : public BufferForVirtualFunction
{
public:
OverridesNonDirectVirtual();
virtual int retInt();
};
namespace boost
{
template <class T> struct is_member_pointer_cv { static const bool value = false; };

Loading…
Cancel
Save