Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,10 +1589,12 @@ void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethod
var remappedName = FixupNameForMultipleHits(cxxMethodDecl);
var name = GetRemappedCursorName(cxxMethodDecl);
var needsReturnFixup = false;
var needsCastToTransparentStruct = false;

if (returnType.Kind != CXTypeKind.CXType_Void)
{
needsReturnFixup = NeedsReturnFixup(cxxMethodDecl);
needsCastToTransparentStruct = _config.WithTransparentStructs.TryGetValue(returnTypeName, out var transparentStruct) && IsTransparentStructHandle(transparentStruct.Kind);
}

var desc = new FunctionOrDelegateDesc<(string Name, PInvokeGenerator This)>
Expand Down Expand Up @@ -1652,6 +1654,13 @@ void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethod
body.Write("return ");
}

if (needsCastToTransparentStruct)
{
body.Write("((");
body.Write(returnTypeName);
body.Write(")(");
}

if (needsReturnFixup)
{
body.Write('*');
Expand Down Expand Up @@ -1748,6 +1757,11 @@ void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethod
body.Write(" != 0");
}

if (needsCastToTransparentStruct)
{
body.Write("))");
}

body.WriteSemicolon();
body.WriteNewline();

Expand Down Expand Up @@ -2743,9 +2757,9 @@ private void VisitVarDecl(VarDecl varDecl)
{
flags |= ValueFlags.Copy;
}
else if (_config.WithTransparentStructs.TryGetValue(typeName, out var transparentValueTypeName))
else if (_config.WithTransparentStructs.TryGetValue(typeName, out var transparentStruct))
{
typeName = transparentValueTypeName;
typeName = transparentStruct.Name;
}
}
else if ((varDecl.StorageClass == CX_StorageClass.CX_SC_Static) || openedOutputBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,9 @@ private void VisitExplicitCastExpr(ExplicitCastExpr explicitCastExpr)
{
var cursorName = GetCursorName(varDecl);

if (cursorName.StartsWith("ClangSharpMacro_") && _config.WithTransparentStructs.TryGetValue(typeName, out var transparentValueTypeName))
if (cursorName.StartsWith("ClangSharpMacro_") && _config.WithTransparentStructs.TryGetValue(typeName, out var transparentStruct))
{
typeName = transparentValueTypeName;
typeName = transparentStruct.Name;
}
}

Expand Down
Loading