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
13 changes: 12 additions & 1 deletion sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6581,9 +6581,20 @@ private bool TryRemapOperatorName(ref string name, FunctionDecl functionDecl)
if (functionDecl is CXXConversionDecl)
{
var returnType = functionDecl.ReturnType;
var pointerIndirectionLevel = 0;
while (returnType is PointerType pointerType)
{
pointerIndirectionLevel++;
returnType = pointerType.PointeeType;
}
var returnTypeName = GetRemappedTypeName(cursor: null, context: null, returnType, out _, skipUsing: true);

name = $"To{returnTypeName}";
name = pointerIndirectionLevel switch {
0 => $"To{returnTypeName}",
1 => $"To{returnTypeName}Pointer",
2 => $"To{returnTypeName}PointerPointer",
_ => $"To{returnTypeName}{string.Concat(Enumerable.Repeat("Pointer", pointerIndirectionLevel))}"
};
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,59 @@ protected override Task ConversionTestImpl()
var inputContents = @"struct MyStruct
{
int value;

int* pointer;
int** pointer2;
int*** pointer3;
operator int()
{
return value;
}
operator int*()
{
return pointer;
}
operator int**()
{
return pointer2;
}
operator int***()
{
return pointer3;
}
};
";

var expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct
public unsafe partial struct MyStruct
{
public int value;

public int* pointer;

public int** pointer2;

public int*** pointer3;

public int ToInt32()
{
return value;
}

public int* ToInt32Pointer()
{
return pointer;
}

public int** ToInt32PointerPointer()
{
return pointer2;
}

public int*** ToInt32PointerPointerPointer()
{
return pointer3;
}
}
}
";
Expand Down