Browse Source

Fix FunctionToStaticMethod bug

refactor
josetr 3 years ago
parent
commit
3414294ab8
  1. 3
      src/Generator/Passes/CheckAbiParameters.cs
  2. 3
      src/Generator/Passes/MoveFunctionToClassPass.cs
  3. 10
      tests/CSharp/CSharp.Tests.cs
  4. 6
      tests/CSharp/CSharp.cpp
  5. 8
      tests/CSharp/CSharp.h

3
src/Generator/Passes/CheckAbiParameters.cs

@ -1,5 +1,6 @@
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions; using CppSharp.AST.Extensions;
using CppSharp.Extensions;
using System.Linq; using System.Linq;
namespace CppSharp.Passes namespace CppSharp.Passes
@ -32,7 +33,7 @@ namespace CppSharp.Passes
var isReturnIndirect = function.IsReturnIndirect || ( var isReturnIndirect = function.IsReturnIndirect || (
Context.ParserOptions.IsMicrosoftAbi && Context.ParserOptions.IsMicrosoftAbi &&
function is Method && function is Method m && m.IsNativeMethod() &&
!function.ReturnType.Type.Desugar().IsAddress() && !function.ReturnType.Type.Desugar().IsAddress() &&
function.ReturnType.Type.Desugar().TryGetDeclaration(out Class returnTypeDecl) && function.ReturnType.Type.Desugar().TryGetDeclaration(out Class returnTypeDecl) &&
returnTypeDecl.IsPOD && returnTypeDecl.IsPOD &&

3
src/Generator/Passes/MoveFunctionToClassPass.cs

@ -23,7 +23,8 @@ namespace CppSharp.Passes
Namespace = @class, Namespace = @class,
OperatorKind = function.OperatorKind, OperatorKind = function.OperatorKind,
OriginalFunction = null, OriginalFunction = null,
IsStatic = true Conversion = MethodConversionKind.FunctionToStaticMethod,
IsStatic = true,
}; };
if (method.IsOperator) if (method.IsOperator)

10
tests/CSharp/CSharp.Tests.cs

@ -1883,4 +1883,14 @@ public unsafe class CSharpTests
Assert.That((short)c, Is.EqualTo(100)); Assert.That((short)c, Is.EqualTo(100));
} }
} }
[Test]
public void TestFunctionToInstanceMethod()
{
Assert.That(CSharp.CSharp.TestFunctionToInstanceMethod(new FTIStruct()).A, Is.EqualTo(6));
Assert.That(CSharp.CSharp.TestFunctionToInstanceMethodStruct(new FTIStruct(), new FTIStruct() { A = 6 }), Is.EqualTo(6));
Assert.That(CSharp.CSharp.TestFunctionToInstanceMethodRefStruct(new FTIStruct(), new FTIStruct() { A = 6 }), Is.EqualTo(6));
Assert.That(CSharp.CSharp.TestFunctionToInstanceMethodConstStruct(new FTIStruct(), new FTIStruct() { A = 6 }), Is.EqualTo(6));
Assert.That(CSharp.CSharp.TestFunctionToInstanceMethodConstRefStruct(new FTIStruct(), new FTIStruct() { A = 6 }), Is.EqualTo(6));
}
} }

6
tests/CSharp/CSharp.cpp

@ -1685,3 +1685,9 @@ const unsigned StructWithEmbeddedArrayOfStructObjectAlignmentOffsets[2]
offsetof(StructWithEmbeddedArrayOfStructObjectAlignment, boolean), offsetof(StructWithEmbeddedArrayOfStructObjectAlignment, boolean),
offsetof(StructWithEmbeddedArrayOfStructObjectAlignment, embedded_struct), offsetof(StructWithEmbeddedArrayOfStructObjectAlignment, embedded_struct),
}; };
DLL_API FTIStruct TestFunctionToInstanceMethod(FTIStruct* bb) { return { 6 }; }
DLL_API int TestFunctionToInstanceMethodStruct(FTIStruct* bb, FTIStruct defaultValue) { return defaultValue.a; }
DLL_API int TestFunctionToInstanceMethodRefStruct(FTIStruct* bb, FTIStruct& defaultValue) { return defaultValue.a; }
DLL_API int TestFunctionToInstanceMethodConstStruct(FTIStruct* bb, const FTIStruct defaultValue) { return defaultValue.a; }
DLL_API int TestFunctionToInstanceMethodConstRefStruct(FTIStruct* bb, const FTIStruct& defaultValue) { return defaultValue.a; }

8
tests/CSharp/CSharp.h

@ -1526,3 +1526,11 @@ DLL_API const char* TestCSharpString(const char* in, CS_OUT const char** out);
DLL_API const wchar_t* TestCSharpStringWide(const wchar_t* in, CS_OUT const wchar_t** out); DLL_API const wchar_t* TestCSharpStringWide(const wchar_t* in, CS_OUT const wchar_t** out);
DLL_API const char16_t* TestCSharpString16(const char16_t* in, CS_OUT const char16_t** out); DLL_API const char16_t* TestCSharpString16(const char16_t* in, CS_OUT const char16_t** out);
DLL_API const char32_t* TestCSharpString32(const char32_t* in, CS_OUT const char32_t** out); DLL_API const char32_t* TestCSharpString32(const char32_t* in, CS_OUT const char32_t** out);
struct DLL_API FTIStruct { int a; };
DLL_API FTIStruct TestFunctionToInstanceMethod(FTIStruct* bb);
DLL_API int TestFunctionToInstanceMethodStruct(FTIStruct* bb, FTIStruct defaultValue);
DLL_API int TestFunctionToInstanceMethodRefStruct(FTIStruct* bb, FTIStruct& defaultValue);
DLL_API int TestFunctionToInstanceMethodConstStruct(FTIStruct* bb, const FTIStruct defaultValue);
DLL_API int TestFunctionToInstanceMethodConstRefStruct(FTIStruct* bb, const FTIStruct& defaultValue);

Loading…
Cancel
Save