Browse Source

Fix FunctionToInstanceMethod

pull/1698/head
josetr 3 years ago
parent
commit
567a0df8c7
  1. 8
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 4
      tests/CSharp/CSharp.Gen.cs
  3. 7
      tests/CSharp/CSharp.Tests.cs
  4. 3
      tests/CSharp/CSharp.cpp
  5. 5
      tests/CSharp/CSharp.h

8
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -728,14 +728,6 @@ namespace CppSharp.Generators.CSharp
private void MarshalRefClass(Class @class) private void MarshalRefClass(Class @class)
{ {
var method = Context.Function as Method; var method = Context.Function as Method;
if (method != null
&& method.Conversion == MethodConversionKind.FunctionToInstanceMethod
&& Context.ParameterIndex == 0)
{
Context.Return.Write("{0}", Helpers.InstanceIdentifier);
return;
}
string param = Context.Parameter.Name; string param = Context.Parameter.Name;
Type type = Context.Parameter.Type.Desugar(resolveTemplateSubstitution: false); Type type = Context.Parameter.Type.Desugar(resolveTemplateSubstitution: false);
string paramInstance; string paramInstance;

4
tests/CSharp/CSharp.Gen.cs

@ -31,6 +31,10 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver) public override void SetupPasses(Driver driver)
{ {
driver.Context.TranslationUnitPasses.AddPass(new TestAttributesPass()); driver.Context.TranslationUnitPasses.AddPass(new TestAttributesPass());
var moveFunctionToClassPass = driver.Context.TranslationUnitPasses.FindPass<MoveFunctionToClassPass>();
driver.Context.TranslationUnitPasses.RemovePass(moveFunctionToClassPass);
driver.Context.TranslationUnitPasses.AddPass(new FunctionToInstanceMethodPass());
driver.Context.TranslationUnitPasses.AddPass(new MoveFunctionToClassPass());
driver.Options.MarshalCharAsManagedChar = true; driver.Options.MarshalCharAsManagedChar = true;
driver.Options.GenerateDefaultValuesForArguments = true; driver.Options.GenerateDefaultValuesForArguments = true;
driver.Options.GenerateClassTemplates = true; driver.Options.GenerateClassTemplates = true;

7
tests/CSharp/CSharp.Tests.cs

@ -1894,6 +1894,13 @@ public unsafe class CSharpTests
Assert.That(CSharp.CSharp.TestFunctionToStaticMethodConstRefStruct(new FTIStruct(), new FTIStruct() { A = 6 }), Is.EqualTo(6)); Assert.That(CSharp.CSharp.TestFunctionToStaticMethodConstRefStruct(new FTIStruct(), new FTIStruct() { A = 6 }), Is.EqualTo(6));
} }
[Test]
public void TestFunctionToInstanceMethod()
{
Assert.That(new TestClass().FunctionToInstanceMethod(5), Is.EqualTo(25));
Assert.That(new TestClass().FunctionToInstanceMethod(new FTIStruct() { A = 5 }), Is.EqualTo(25));
}
[TestCase(typeof(FTIStruct), ExpectedResult = true)] [TestCase(typeof(FTIStruct), ExpectedResult = true)]
[TestCase(typeof(ClassWithoutNativeToManaged), ExpectedResult = false)] [TestCase(typeof(ClassWithoutNativeToManaged), ExpectedResult = false)]
public bool TestClassGenerateNativeToManaged(Type type) public bool TestClassGenerateNativeToManaged(Type type)

3
tests/CSharp/CSharp.cpp

@ -1692,6 +1692,9 @@ DLL_API int TestFunctionToStaticMethodRefStruct(FTIStruct* bb, FTIStruct& defaul
DLL_API int TestFunctionToStaticMethodConstStruct(FTIStruct* bb, const FTIStruct defaultValue) { return defaultValue.a; } DLL_API int TestFunctionToStaticMethodConstStruct(FTIStruct* bb, const FTIStruct defaultValue) { return defaultValue.a; }
DLL_API int TestFunctionToStaticMethodConstRefStruct(FTIStruct* bb, const FTIStruct& defaultValue) { return defaultValue.a; } DLL_API int TestFunctionToStaticMethodConstRefStruct(FTIStruct* bb, const FTIStruct& defaultValue) { return defaultValue.a; }
DLL_API int TestClassFunctionToInstanceMethod(TestClass* bb, int value) { return value * value; }
DLL_API int TestClassFunctionToInstanceMethod(TestClass* bb, FTIStruct& value) { return value.a * value.a; }
int RuleOfThreeTester::constructorCalls = 0; int RuleOfThreeTester::constructorCalls = 0;
int RuleOfThreeTester::destructorCalls = 0; int RuleOfThreeTester::destructorCalls = 0;
int RuleOfThreeTester::copyConstructorCalls = 0; int RuleOfThreeTester::copyConstructorCalls = 0;

5
tests/CSharp/CSharp.h

@ -1535,6 +1535,11 @@ DLL_API int TestFunctionToStaticMethodRefStruct(FTIStruct* bb, FTIStruct& defaul
DLL_API int TestFunctionToStaticMethodConstStruct(FTIStruct* bb, const FTIStruct defaultValue); DLL_API int TestFunctionToStaticMethodConstStruct(FTIStruct* bb, const FTIStruct defaultValue);
DLL_API int TestFunctionToStaticMethodConstRefStruct(FTIStruct* bb, const FTIStruct& defaultValue); DLL_API int TestFunctionToStaticMethodConstRefStruct(FTIStruct* bb, const FTIStruct& defaultValue);
class DLL_API TestClass { int a; };
DLL_API int TestClassFunctionToInstanceMethod(TestClass* bb, int value);
DLL_API int TestClassFunctionToInstanceMethod(TestClass* bb, FTIStruct& cc);
class ClassWithoutNativeToManaged { }; class ClassWithoutNativeToManaged { };
struct DLL_API ClassWithIntValue { struct DLL_API ClassWithIntValue {

Loading…
Cancel
Save