Browse Source

Added two hacks: one for operators in general, one for a parser issue.

1. Visit the class as a declaration context when checking operator overloads - otherwise operators in nested types are not checked; this is, however, not the proper solution because all visiting of classes should be refactored so that this and any other methods are always called as necessary;
2. A single conversion operator in Qt misleads the parser into resolving a function pointer while it is (most probably) not; this caused a subsequent crash.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/72/head
Dimitar Dobrev 13 years ago
parent
commit
95687a22b6
  1. 27
      src/Generator/Passes/CheckOperatorsOverloads.cs

27
src/Generator/Passes/CheckOperatorsOverloads.cs

@ -20,6 +20,9 @@ namespace CppSharp.Passes @@ -20,6 +20,9 @@ namespace CppSharp.Passes
if (AlreadyVisited(@class))
return false;
if (!VisitDeclarationContext(@class))
return false;
// Check for C++ operators that cannot be represented in C#.
CheckInvalidOperators(@class);
@ -80,6 +83,30 @@ namespace CppSharp.Passes @@ -80,6 +83,30 @@ namespace CppSharp.Passes
Kind = ParameterKind.OperatorParameter
});
}
// HACK: in Qt's qobjectdefs.h we have this line:
// typedef void *Connection::*RestrictedBool;
// Our parser resolves this as a function pointer while judging by the next line of:
// operator RestrictedBool() const { return d_ptr ? &Connection::d_ptr : 0; }
// it seems not to be. So until the proper fix just use the pointee to avoid crashes
if (@operator.OperatorKind == CXXOperatorKind.Conversion)
{
var typedef = @operator.ReturnType.Type as TypedefType;
if (typedef != null)
{
var functionPointer = typedef.Desugar() as MemberPointerType;
if (functionPointer != null)
{
FunctionType functionType;
functionPointer.IsPointerTo(out functionType);
if (functionType == null)
{
@operator.ReturnType =
new QualifiedType(functionPointer.Pointee,
@operator.ReturnType.Qualifiers);
}
}
}
}
}
}

Loading…
Cancel
Save