Browse Source

Fixed a crash when overrides change the sugaring of involved types.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/696/head
Dimitar Dobrev 9 years ago
parent
commit
e6c4bb9cc5
  1. 3
      src/AST/Function.cs
  2. 3
      src/AST/FunctionExtensions.cs
  3. 17
      src/AST/TypeExtensions.cs
  4. 2
      tests/Common/Common.cpp
  5. 3
      tests/Common/Common.h

3
src/AST/Function.cs

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using CppSharp.AST.Extensions;
namespace CppSharp.AST namespace CppSharp.AST
{ {
@ -96,7 +97,7 @@ namespace CppSharp.AST
public bool Equals(Parameter x, Parameter y) public bool Equals(Parameter x, Parameter y)
{ {
return x.QualifiedType == y.QualifiedType; return x.QualifiedType.ResolvesTo(y.QualifiedType);
} }
public int GetHashCode(Parameter obj) public int GetHashCode(Parameter obj)

3
src/AST/FunctionExtensions.cs

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using CppSharp.AST.Extensions;
namespace CppSharp.AST namespace CppSharp.AST
{ {
@ -76,7 +77,7 @@ namespace CppSharp.AST
public static bool CanOverride(this Method @override, Method method) public static bool CanOverride(this Method @override, Method method)
{ {
return (method.OriginalName == @override.OriginalName && return (method.OriginalName == @override.OriginalName &&
method.ReturnType == @override.ReturnType && method.ReturnType.ResolvesTo(@override.ReturnType) &&
method.Parameters.SequenceEqual(@override.Parameters, ParameterTypeComparer.Instance)) || method.Parameters.SequenceEqual(@override.Parameters, ParameterTypeComparer.Instance)) ||
(@override.IsDestructor && method.IsDestructor && method.IsVirtual); (@override.IsDestructor && method.IsDestructor && method.IsVirtual);
} }

17
src/AST/TypeExtensions.cs

@ -272,5 +272,22 @@
return type; return type;
} }
public static bool ResolvesTo(this QualifiedType type, QualifiedType other)
{
if (!type.Qualifiers.Equals(other.Qualifiers))
return false;
var left = type.Type.Desugar();
var right = other.Type.Desugar();
var leftPointer = left as PointerType;
var rightPointer = right as PointerType;
if (leftPointer != null && rightPointer != null)
{
return leftPointer.Modifier == rightPointer.Modifier &&
leftPointer.QualifiedPointee.ResolvesTo(rightPointer.QualifiedPointee);
}
return left.Equals(right);
}
} }
} }

2
tests/Common/Common.cpp

@ -309,7 +309,7 @@ int TestDelegates::CDecl(DelegateCDecl del)
return del(1); return del(1);
} }
int ImplementsAbstractFoo::pureFunction(int i) int ImplementsAbstractFoo::pureFunction(typedefInOverride i)
{ {
return 5; return 5;
} }

3
tests/Common/Common.h

@ -212,7 +212,8 @@ public:
class DLL_API ImplementsAbstractFoo : public AbstractFoo class DLL_API ImplementsAbstractFoo : public AbstractFoo
{ {
public: public:
virtual int pureFunction(int i = 0); typedef int typedefInOverride;
virtual int pureFunction(typedefInOverride i = 0);
virtual int pureFunction1(); virtual int pureFunction1();
virtual int pureFunction2(bool* ok = 0); virtual int pureFunction2(bool* ok = 0);
}; };

Loading…
Cancel
Save