From 95687a22b6ae6418fc2d08d2445380a929f8f82b Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sun, 22 Sep 2013 01:35:16 +0300 Subject: [PATCH] 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 --- .../Passes/CheckOperatorsOverloads.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Generator/Passes/CheckOperatorsOverloads.cs b/src/Generator/Passes/CheckOperatorsOverloads.cs index fd570a31..c46d8898 100644 --- a/src/Generator/Passes/CheckOperatorsOverloads.cs +++ b/src/Generator/Passes/CheckOperatorsOverloads.cs @@ -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 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); + } + } + } + } } }